#include "services/device/wake_lock/power_save_blocker/power_save_blocker.h"
#include <stdint.h>
#include <memory>
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h"
#include "base/synchronization/lock.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "dbus/bus.h"
#include "dbus/message.h"
#include "dbus/object_path.h"
#include "dbus/object_proxy.h"
#include "ui/display/screen.h"
#include "ui/gfx/switches.h"
namespace device {
namespace {
enum DBusAPI { … };
enum GnomeAPIInhibitFlags { … };
const char kGnomeAPIServiceName[] = …;
const char kGnomeAPIInterfaceName[] = …;
const char kGnomeAPIObjectPath[] = …;
const char kFreeDesktopAPIPowerServiceName[] = …;
const char kFreeDesktopAPIPowerInterfaceName[] = …;
const char kFreeDesktopAPIPowerObjectPath[] = …;
const char kFreeDesktopAPIScreenServiceName[] = …;
const char kFreeDesktopAPIScreenInterfaceName[] = …;
const char kFreeDesktopAPIScreenObjectPath[] = …;
const char kDbusMethodNameHasOwnerMethod[] = …;
bool ServiceNameHasOwner(dbus::Bus* bus, const char* service_name) { … }
bool ShouldPreventDisplaySleep(mojom::WakeLockType type) { … }
const char* GetUninhibitMethodName(DBusAPI api) { … }
void GetDbusStringsForApi(DBusAPI api,
const char** service_name,
const char** interface_name,
const char** object_path) { … }
}
class PowerSaveBlocker::Delegate
: public base::RefCountedThreadSafe<PowerSaveBlocker::Delegate> { … };
PowerSaveBlocker::Delegate::Delegate(
mojom::WakeLockType type,
const std::string& description,
scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner)
: … { … }
void PowerSaveBlocker::Delegate::Init() { … }
void PowerSaveBlocker::Delegate::CleanUp() { … }
bool PowerSaveBlocker::Delegate::ShouldBlock() const { … }
void PowerSaveBlocker::Delegate::ApplyBlock() { … }
void PowerSaveBlocker::Delegate::RemoveBlock() { … }
bool PowerSaveBlocker::Delegate::Inhibit(DBusAPI api) { … }
void PowerSaveBlocker::Delegate::Uninhibit(
const InhibitCookie& inhibit_cookie) { … }
void PowerSaveBlocker::Delegate::SetScreenSaverSuspended(bool suspend) { … }
PowerSaveBlocker::PowerSaveBlocker(
mojom::WakeLockType type,
mojom::WakeLockReason reason,
const std::string& description,
scoped_refptr<base::SequencedTaskRunner> ui_task_runner,
scoped_refptr<base::SingleThreadTaskRunner> blocking_task_runner)
: … { … }
PowerSaveBlocker::~PowerSaveBlocker() { … }
}