Chromium Code Reviews| Index: chrome/browser/signin/easy_unlock_service.cc |
| diff --git a/chrome/browser/signin/easy_unlock_service.cc b/chrome/browser/signin/easy_unlock_service.cc |
| index 31afa1123cd9895dfea2107e8b1adf0056a71e38..455db59028910cbb20d4112aa3f14e4befbdca6a 100644 |
| --- a/chrome/browser/signin/easy_unlock_service.cc |
| +++ b/chrome/browser/signin/easy_unlock_service.cc |
| @@ -32,6 +32,8 @@ |
| #if defined(OS_CHROMEOS) |
| #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| +#include "chromeos/dbus/dbus_thread_manager.h" |
| +#include "chromeos/dbus/power_manager_client.h" |
| #include "components/user_manager/user_manager.h" |
| #endif |
| @@ -106,6 +108,42 @@ class EasyUnlockService::BluetoothDetector |
| DISALLOW_COPY_AND_ASSIGN(BluetoothDetector); |
| }; |
| +#if defined(OS_CHROMEOS) |
| +class EasyUnlockService::PowerMonitor : |
| + public chromeos::PowerManagerClient::Observer { |
| + public: |
| + explicit PowerMonitor(EasyUnlockService* service) : service_(service) { |
| + chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| + AddObserver(this); |
| + } |
| + |
| + virtual ~PowerMonitor() { |
| + chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> |
| + RemoveObserver(this); |
| + } |
| + |
| + private: |
| + // chromeos::PowerManagerClient::Observer: |
| + virtual void SuspendImminent() OVERRIDE { |
| + service_->UnloadApp(); |
|
tbarzic
2014/09/03 21:40:37
you could add screenlock_state_handler_.reset() to
Tim Song
2014/09/03 21:53:39
Done.
|
| + EasyUnlockScreenlockStateHandler* screenlock_state_handler = |
| + service_->GetScreenlockStateHandler(); |
| + if (screenlock_state_handler) { |
| + screenlock_state_handler->ChangeState( |
| + EasyUnlockScreenlockStateHandler::STATE_INACTIVE); |
| + } |
| + } |
| + |
| + virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE { |
| + service_->LoadApp(); |
| + } |
| + |
| + EasyUnlockService* service_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(PowerMonitor); |
| +}; |
| +#endif |
| + |
| EasyUnlockService::EasyUnlockService(Profile* profile) |
| : profile_(profile), |
| bluetooth_detector_(new BluetoothDetector(this)), |
| @@ -334,11 +372,20 @@ void EasyUnlockService::UnloadApp() { |
| void EasyUnlockService::UpdateAppState() { |
| if (IsAllowed()) { |
| LoadApp(); |
| + |
| +#if defined(OS_CHROMEOS) |
| + if (!power_monitor_) |
| + power_monitor_.reset(new PowerMonitor(this)); |
| +#endif |
| } else { |
| UnloadApp(); |
| // Reset the screenlock state handler to make sure Screenlock state set |
| // by Easy Unlock app is reset. |
| screenlock_state_handler_.reset(); |
| + |
| +#if defined(OS_CHROMEOS) |
| + power_monitor_.reset(); |
| +#endif |
| } |
| } |