Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(123)

Side by Side Diff: chrome/browser/signin/easy_unlock_service.cc

Issue 528423002: Unload Easy Unlock app when ChromeOS suspends and reload on wake up. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: in file Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/signin/easy_unlock_service.h" 5 #include "chrome/browser/signin/easy_unlock_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/ref_counted.h" 10 #include "base/memory/ref_counted.h"
(...skipping 14 matching lines...) Expand all
25 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
26 #include "components/pref_registry/pref_registry_syncable.h" 26 #include "components/pref_registry/pref_registry_syncable.h"
27 #include "device/bluetooth/bluetooth_adapter.h" 27 #include "device/bluetooth/bluetooth_adapter.h"
28 #include "device/bluetooth/bluetooth_adapter_factory.h" 28 #include "device/bluetooth/bluetooth_adapter_factory.h"
29 #include "extensions/browser/extension_system.h" 29 #include "extensions/browser/extension_system.h"
30 #include "extensions/common/one_shot_event.h" 30 #include "extensions/common/one_shot_event.h"
31 #include "grit/browser_resources.h" 31 #include "grit/browser_resources.h"
32 32
33 #if defined(OS_CHROMEOS) 33 #if defined(OS_CHROMEOS)
34 #include "chrome/browser/chromeos/profiles/profile_helper.h" 34 #include "chrome/browser/chromeos/profiles/profile_helper.h"
35 #include "chromeos/dbus/dbus_thread_manager.h"
36 #include "chromeos/dbus/power_manager_client.h"
35 #include "components/user_manager/user_manager.h" 37 #include "components/user_manager/user_manager.h"
36 #endif 38 #endif
37 39
38 namespace { 40 namespace {
39 41
40 // Key name of the local device permit record dictonary in kEasyUnlockPairing. 42 // Key name of the local device permit record dictonary in kEasyUnlockPairing.
41 const char kKeyPermitAccess[] = "permitAccess"; 43 const char kKeyPermitAccess[] = "permitAccess";
42 44
43 // Key name of the remote device list in kEasyUnlockPairing. 45 // Key name of the remote device list in kEasyUnlockPairing.
44 const char kKeyDevices[] = "devices"; 46 const char kKeyDevices[] = "devices";
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 } 101 }
100 102
101 // Owner of this class and should out-live this class. 103 // Owner of this class and should out-live this class.
102 EasyUnlockService* service_; 104 EasyUnlockService* service_;
103 scoped_refptr<device::BluetoothAdapter> adapter_; 105 scoped_refptr<device::BluetoothAdapter> adapter_;
104 base::WeakPtrFactory<BluetoothDetector> weak_ptr_factory_; 106 base::WeakPtrFactory<BluetoothDetector> weak_ptr_factory_;
105 107
106 DISALLOW_COPY_AND_ASSIGN(BluetoothDetector); 108 DISALLOW_COPY_AND_ASSIGN(BluetoothDetector);
107 }; 109 };
108 110
111 #if defined(OS_CHROMEOS)
112 class EasyUnlockService::PowerMonitor :
113 public chromeos::PowerManagerClient::Observer {
114 public:
115 explicit PowerMonitor(EasyUnlockService* service) : service_(service) {
116 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
117 AddObserver(this);
118 }
119
120 virtual ~PowerMonitor() {
121 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->
122 RemoveObserver(this);
123 }
124
125 private:
126 // chromeos::PowerManagerClient::Observer:
127 virtual void SuspendImminent() OVERRIDE {
128 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.
129 EasyUnlockScreenlockStateHandler* screenlock_state_handler =
130 service_->GetScreenlockStateHandler();
131 if (screenlock_state_handler) {
132 screenlock_state_handler->ChangeState(
133 EasyUnlockScreenlockStateHandler::STATE_INACTIVE);
134 }
135 }
136
137 virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE {
138 service_->LoadApp();
139 }
140
141 EasyUnlockService* service_;
142
143 DISALLOW_COPY_AND_ASSIGN(PowerMonitor);
144 };
145 #endif
146
109 EasyUnlockService::EasyUnlockService(Profile* profile) 147 EasyUnlockService::EasyUnlockService(Profile* profile)
110 : profile_(profile), 148 : profile_(profile),
111 bluetooth_detector_(new BluetoothDetector(this)), 149 bluetooth_detector_(new BluetoothDetector(this)),
112 turn_off_flow_status_(IDLE), 150 turn_off_flow_status_(IDLE),
113 weak_ptr_factory_(this) { 151 weak_ptr_factory_(this) {
114 extensions::ExtensionSystem::Get(profile_)->ready().Post( 152 extensions::ExtensionSystem::Get(profile_)->ready().Post(
115 FROM_HERE, 153 FROM_HERE,
116 base::Bind(&EasyUnlockService::Initialize, 154 base::Bind(&EasyUnlockService::Initialize,
117 weak_ptr_factory_.GetWeakPtr())); 155 weak_ptr_factory_.GetWeakPtr()));
118 } 156 }
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 365
328 void EasyUnlockService::UnloadApp() { 366 void EasyUnlockService::UnloadApp() {
329 extensions::ComponentLoader* loader = GetComponentLoader(profile_); 367 extensions::ComponentLoader* loader = GetComponentLoader(profile_);
330 if (loader->Exists(extension_misc::kEasyUnlockAppId)) 368 if (loader->Exists(extension_misc::kEasyUnlockAppId))
331 loader->Remove(extension_misc::kEasyUnlockAppId); 369 loader->Remove(extension_misc::kEasyUnlockAppId);
332 } 370 }
333 371
334 void EasyUnlockService::UpdateAppState() { 372 void EasyUnlockService::UpdateAppState() {
335 if (IsAllowed()) { 373 if (IsAllowed()) {
336 LoadApp(); 374 LoadApp();
375
376 #if defined(OS_CHROMEOS)
377 if (!power_monitor_)
378 power_monitor_.reset(new PowerMonitor(this));
379 #endif
337 } else { 380 } else {
338 UnloadApp(); 381 UnloadApp();
339 // Reset the screenlock state handler to make sure Screenlock state set 382 // Reset the screenlock state handler to make sure Screenlock state set
340 // by Easy Unlock app is reset. 383 // by Easy Unlock app is reset.
341 screenlock_state_handler_.reset(); 384 screenlock_state_handler_.reset();
385
386 #if defined(OS_CHROMEOS)
387 power_monitor_.reset();
388 #endif
342 } 389 }
343 } 390 }
344 391
345 void EasyUnlockService::OnPrefsChanged() { 392 void EasyUnlockService::OnPrefsChanged() {
346 UpdateAppState(); 393 UpdateAppState();
347 } 394 }
348 395
349 void EasyUnlockService::OnBluetoothAdapterPresentChanged() { 396 void EasyUnlockService::OnBluetoothAdapterPresentChanged() {
350 UpdateAppState(); 397 UpdateAppState();
351 } 398 }
(...skipping 18 matching lines...) Expand all
370 // Make sure lock screen state set by the extension gets reset. 417 // Make sure lock screen state set by the extension gets reset.
371 screenlock_state_handler_.reset(); 418 screenlock_state_handler_.reset();
372 419
373 if (GetComponentLoader(profile_)->Exists(extension_misc::kEasyUnlockAppId)) { 420 if (GetComponentLoader(profile_)->Exists(extension_misc::kEasyUnlockAppId)) {
374 extensions::ExtensionSystem* extension_system = 421 extensions::ExtensionSystem* extension_system =
375 extensions::ExtensionSystem::Get(profile_); 422 extensions::ExtensionSystem::Get(profile_);
376 extension_system->extension_service()->ReloadExtension( 423 extension_system->extension_service()->ReloadExtension(
377 extension_misc::kEasyUnlockAppId); 424 extension_misc::kEasyUnlockAppId);
378 } 425 }
379 } 426 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698