fixup! Implement powerMonitor 'shutdown' event for Linux
This commit is contained in:
parent
45763c0afb
commit
f0e210360f
2 changed files with 10 additions and 5 deletions
|
@ -70,10 +70,10 @@ void PowerObserverLinux::OnLoginServiceAvailable(bool service_available) {
|
||||||
base::Bind(&PowerObserverLinux::OnSignalConnected,
|
base::Bind(&PowerObserverLinux::OnSignalConnected,
|
||||||
weak_ptr_factory_.GetWeakPtr()));
|
weak_ptr_factory_.GetWeakPtr()));
|
||||||
// Take sleep inhibit lock
|
// Take sleep inhibit lock
|
||||||
TakeSleepLock();
|
BlockSleep();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PowerObserverLinux::TakeSleepLock() {
|
void PowerObserverLinux::BlockSleep() {
|
||||||
dbus::MethodCall sleep_inhibit_call(kLogindManagerInterface, "Inhibit");
|
dbus::MethodCall sleep_inhibit_call(kLogindManagerInterface, "Inhibit");
|
||||||
dbus::MessageWriter inhibit_writer(&sleep_inhibit_call);
|
dbus::MessageWriter inhibit_writer(&sleep_inhibit_call);
|
||||||
inhibit_writer.AppendString("sleep"); // what
|
inhibit_writer.AppendString("sleep"); // what
|
||||||
|
@ -88,6 +88,10 @@ void PowerObserverLinux::TakeSleepLock() {
|
||||||
weak_ptr_factory_.GetWeakPtr(), &sleep_lock_));
|
weak_ptr_factory_.GetWeakPtr(), &sleep_lock_));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PowerObserverLinux::UnblockSleep() {
|
||||||
|
sleep_lock_.reset();
|
||||||
|
}
|
||||||
|
|
||||||
void PowerObserverLinux::BlockShutdown() {
|
void PowerObserverLinux::BlockShutdown() {
|
||||||
if (shutdown_lock.is_valid()) {
|
if (shutdown_lock.is_valid()) {
|
||||||
LOG(WARNING) << "Trying to subscribe to shutdown multiple times";
|
LOG(WARNING) << "Trying to subscribe to shutdown multiple times";
|
||||||
|
@ -129,9 +133,9 @@ void PowerObserverLinux::OnPrepareForSleep(dbus::Signal* signal) {
|
||||||
}
|
}
|
||||||
if (suspending) {
|
if (suspending) {
|
||||||
OnSuspend();
|
OnSuspend();
|
||||||
sleep_lock_.reset();
|
UnblockSleep();
|
||||||
} else {
|
} else {
|
||||||
TakeSleepLock();
|
BlockSleep();
|
||||||
OnResume();
|
OnResume();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,12 +20,13 @@ class PowerObserverLinux : public base::PowerObserver {
|
||||||
public:
|
public:
|
||||||
PowerObserverLinux();
|
PowerObserverLinux();
|
||||||
|
|
||||||
|
void BlockSleep();
|
||||||
|
void UnblockSleep();
|
||||||
void BlockShutdown();
|
void BlockShutdown();
|
||||||
void UnblockShutdown();
|
void UnblockShutdown();
|
||||||
virtual bool OnShutdown() { return false; }
|
virtual bool OnShutdown() { return false; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void TakeSleepLock();
|
|
||||||
void OnLoginServiceAvailable(bool available);
|
void OnLoginServiceAvailable(bool available);
|
||||||
void OnInhibitResponse(base::ScopedFD* scoped_fd, dbus::Response* response);
|
void OnInhibitResponse(base::ScopedFD* scoped_fd, dbus::Response* response);
|
||||||
void OnPrepareForSleep(dbus::Signal* signal);
|
void OnPrepareForSleep(dbus::Signal* signal);
|
||||||
|
|
Loading…
Add table
Reference in a new issue