electron/shell/browser/lib/power_observer_linux.h

56 lines
1.6 KiB
C
Raw Normal View History

// Copyright (c) 2017 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
2019-06-19 20:56:58 +00:00
#ifndef SHELL_BROWSER_LIB_POWER_OBSERVER_LINUX_H_
#define SHELL_BROWSER_LIB_POWER_OBSERVER_LINUX_H_
#include <string>
2020-03-24 16:03:29 +00:00
#include "base/callback.h"
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "base/power_monitor/power_observer.h"
#include "dbus/bus.h"
#include "dbus/message.h"
#include "dbus/object_proxy.h"
namespace electron {
2020-03-24 16:03:29 +00:00
class PowerObserverLinux {
public:
2020-03-24 16:03:29 +00:00
explicit PowerObserverLinux(base::PowerObserver* observer);
~PowerObserverLinux();
2020-03-24 16:03:29 +00:00
void SetShutdownHandler(base::Callback<bool()> should_shutdown);
private:
void BlockSleep();
void UnblockSleep();
void BlockShutdown();
void UnblockShutdown();
void OnLoginServiceAvailable(bool available);
void OnInhibitResponse(base::ScopedFD* scoped_fd, dbus::Response* response);
void OnPrepareForSleep(dbus::Signal* signal);
void OnPrepareForShutdown(dbus::Signal* signal);
void OnSignalConnected(const std::string& interface,
const std::string& signal,
bool success);
2020-03-24 16:03:29 +00:00
base::RepeatingCallback<bool()> should_shutdown_;
base::PowerObserver* observer_;
scoped_refptr<dbus::ObjectProxy> logind_;
std::string lock_owner_name_;
base::ScopedFD sleep_lock_;
base::ScopedFD shutdown_lock_;
2020-03-24 16:03:29 +00:00
base::WeakPtrFactory<PowerObserverLinux> weak_ptr_factory_{this};
DISALLOW_COPY_AND_ASSIGN(PowerObserverLinux);
};
} // namespace electron
2019-06-19 20:56:58 +00:00
#endif // SHELL_BROWSER_LIB_POWER_OBSERVER_LINUX_H_