fixup! Implement powerMonitor 'shutdown' event for Linux

This commit is contained in:
Thiago de Arruda 2017-12-21 07:49:54 -03:00 коммит произвёл Cheng Zhao
Родитель 45763c0afb
Коммит f0e210360f
2 изменённых файлов: 10 добавлений и 5 удалений

Просмотреть файл

@ -70,10 +70,10 @@ void PowerObserverLinux::OnLoginServiceAvailable(bool service_available) {
base::Bind(&PowerObserverLinux::OnSignalConnected,
weak_ptr_factory_.GetWeakPtr()));
// Take sleep inhibit lock
TakeSleepLock();
BlockSleep();
}
void PowerObserverLinux::TakeSleepLock() {
void PowerObserverLinux::BlockSleep() {
dbus::MethodCall sleep_inhibit_call(kLogindManagerInterface, "Inhibit");
dbus::MessageWriter inhibit_writer(&sleep_inhibit_call);
inhibit_writer.AppendString("sleep"); // what
@ -88,6 +88,10 @@ void PowerObserverLinux::TakeSleepLock() {
weak_ptr_factory_.GetWeakPtr(), &sleep_lock_));
}
void PowerObserverLinux::UnblockSleep() {
sleep_lock_.reset();
}
void PowerObserverLinux::BlockShutdown() {
if (shutdown_lock.is_valid()) {
LOG(WARNING) << "Trying to subscribe to shutdown multiple times";
@ -129,9 +133,9 @@ void PowerObserverLinux::OnPrepareForSleep(dbus::Signal* signal) {
}
if (suspending) {
OnSuspend();
sleep_lock_.reset();
UnblockSleep();
} else {
TakeSleepLock();
BlockSleep();
OnResume();
}
}

Просмотреть файл

@ -20,12 +20,13 @@ class PowerObserverLinux : public base::PowerObserver {
public:
PowerObserverLinux();
void BlockSleep();
void UnblockSleep();
void BlockShutdown();
void UnblockShutdown();
virtual bool OnShutdown() { return false; }
private:
void TakeSleepLock();
void OnLoginServiceAvailable(bool available);
void OnInhibitResponse(base::ScopedFD* scoped_fd, dbus::Response* response);
void OnPrepareForSleep(dbus::Signal* signal);