OLD | NEW |
---|---|
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" |
11 #include "base/metrics/field_trial.h" | 11 #include "base/metrics/field_trial.h" |
12 #include "base/prefs/pref_service.h" | 12 #include "base/prefs/pref_service.h" |
13 #include "base/prefs/scoped_user_pref_update.h" | 13 #include "base/prefs/scoped_user_pref_update.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "chrome/browser/extensions/component_loader.h" | 15 #include "chrome/browser/extensions/component_loader.h" |
16 #include "chrome/browser/extensions/extension_service.h" | 16 #include "chrome/browser/extensions/extension_service.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" | 18 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" |
19 #include "chrome/browser/signin/easy_unlock_service_factory.h" | 19 #include "chrome/browser/signin/easy_unlock_service_factory.h" |
20 #include "chrome/browser/signin/easy_unlock_service_observer.h" | 20 #include "chrome/browser/signin/easy_unlock_service_observer.h" |
21 #include "chrome/browser/signin/easy_unlock_toggle_flow.h" | 21 #include "chrome/browser/signin/easy_unlock_toggle_flow.h" |
22 #include "chrome/browser/signin/screenlock_bridge.h" | 22 #include "chrome/browser/signin/screenlock_bridge.h" |
23 #include "chrome/browser/ui/extensions/application_launch.h" | 23 #include "chrome/browser/ui/extensions/application_launch.h" |
24 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
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_registry.h" | |
29 #include "extensions/browser/extension_system.h" | 30 #include "extensions/browser/extension_system.h" |
30 #include "extensions/common/one_shot_event.h" | 31 #include "extensions/common/one_shot_event.h" |
31 #include "grit/browser_resources.h" | 32 #include "grit/browser_resources.h" |
32 | 33 |
33 #if defined(OS_CHROMEOS) | 34 #if defined(OS_CHROMEOS) |
34 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 35 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
36 #include "chromeos/dbus/dbus_thread_manager.h" | |
37 #include "chromeos/dbus/power_manager_client.h" | |
35 #include "components/user_manager/user_manager.h" | 38 #include "components/user_manager/user_manager.h" |
36 #endif | 39 #endif |
37 | 40 |
38 namespace { | 41 namespace { |
39 | 42 |
40 // Key name of the local device permit record dictonary in kEasyUnlockPairing. | 43 // Key name of the local device permit record dictonary in kEasyUnlockPairing. |
41 const char kKeyPermitAccess[] = "permitAccess"; | 44 const char kKeyPermitAccess[] = "permitAccess"; |
42 | 45 |
43 // Key name of the remote device list in kEasyUnlockPairing. | 46 // Key name of the remote device list in kEasyUnlockPairing. |
44 const char kKeyDevices[] = "devices"; | 47 const char kKeyDevices[] = "devices"; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 } | 102 } |
100 | 103 |
101 // Owner of this class and should out-live this class. | 104 // Owner of this class and should out-live this class. |
102 EasyUnlockService* service_; | 105 EasyUnlockService* service_; |
103 scoped_refptr<device::BluetoothAdapter> adapter_; | 106 scoped_refptr<device::BluetoothAdapter> adapter_; |
104 base::WeakPtrFactory<BluetoothDetector> weak_ptr_factory_; | 107 base::WeakPtrFactory<BluetoothDetector> weak_ptr_factory_; |
105 | 108 |
106 DISALLOW_COPY_AND_ASSIGN(BluetoothDetector); | 109 DISALLOW_COPY_AND_ASSIGN(BluetoothDetector); |
107 }; | 110 }; |
108 | 111 |
112 #if defined(OS_CHROMEOS) | |
113 class EasyUnlockService::PowerMonitor : | |
114 public chromeos::PowerManagerClient::Observer { | |
115 public: | |
116 explicit PowerMonitor(EasyUnlockService* service) : service_(service) { | |
117 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | |
118 AddObserver(this); | |
119 } | |
120 | |
121 virtual ~PowerMonitor() { | |
122 chromeos::DBusThreadManager::Get()->GetPowerManagerClient()-> | |
123 RemoveObserver(this); | |
124 } | |
125 | |
126 private: | |
127 // chromeos::PowerManagerClient::Observer: | |
128 virtual void SuspendImminent() OVERRIDE { | |
129 service_->DisableApp(); | |
130 service_->screenlock_state_handler_.reset(); | |
131 } | |
132 | |
133 virtual void SuspendDone(const base::TimeDelta& sleep_duration) OVERRIDE { | |
134 service_->LoadApp(); | |
135 } | |
136 | |
137 EasyUnlockService* service_; | |
138 | |
139 DISALLOW_COPY_AND_ASSIGN(PowerMonitor); | |
140 }; | |
141 #endif | |
142 | |
109 EasyUnlockService::EasyUnlockService(Profile* profile) | 143 EasyUnlockService::EasyUnlockService(Profile* profile) |
110 : profile_(profile), | 144 : profile_(profile), |
111 bluetooth_detector_(new BluetoothDetector(this)), | 145 bluetooth_detector_(new BluetoothDetector(this)), |
112 turn_off_flow_status_(IDLE), | 146 turn_off_flow_status_(IDLE), |
113 weak_ptr_factory_(this) { | 147 weak_ptr_factory_(this) { |
114 extensions::ExtensionSystem::Get(profile_)->ready().Post( | 148 extensions::ExtensionSystem::Get(profile_)->ready().Post( |
115 FROM_HERE, | 149 FROM_HERE, |
116 base::Bind(&EasyUnlockService::Initialize, | 150 base::Bind(&EasyUnlockService::Initialize, |
117 weak_ptr_factory_.GetWeakPtr())); | 151 weak_ptr_factory_.GetWeakPtr())); |
118 } | 152 } |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 // Only allow app path override switch for debug build. | 346 // Only allow app path override switch for debug build. |
313 const CommandLine* command_line = CommandLine::ForCurrentProcess(); | 347 const CommandLine* command_line = CommandLine::ForCurrentProcess(); |
314 if (command_line->HasSwitch(switches::kEasyUnlockAppPath)) { | 348 if (command_line->HasSwitch(switches::kEasyUnlockAppPath)) { |
315 easy_unlock_path = | 349 easy_unlock_path = |
316 command_line->GetSwitchValuePath(switches::kEasyUnlockAppPath); | 350 command_line->GetSwitchValuePath(switches::kEasyUnlockAppPath); |
317 } | 351 } |
318 #endif // !defined(NDEBUG) | 352 #endif // !defined(NDEBUG) |
319 | 353 |
320 if (!easy_unlock_path.empty()) { | 354 if (!easy_unlock_path.empty()) { |
321 extensions::ComponentLoader* loader = GetComponentLoader(profile_); | 355 extensions::ComponentLoader* loader = GetComponentLoader(profile_); |
322 if (!loader->Exists(extension_misc::kEasyUnlockAppId)) | 356 if (!loader->Exists(extension_misc::kEasyUnlockAppId)) { |
323 loader->Add(IDR_EASY_UNLOCK_MANIFEST, easy_unlock_path); | 357 loader->Add(IDR_EASY_UNLOCK_MANIFEST, easy_unlock_path); |
358 } else { | |
tbarzic
2014/09/10 19:56:46
We probably want to ensure that the extension is e
Tim Song
2014/09/11 03:00:05
Can this scenario even happen? It doesn't seem lik
tbarzic
2014/09/11 03:16:42
Afaik, this may happen e.g. if chrome crashes when
| |
359 extensions::ExtensionRegistry* registry = | |
360 extensions::ExtensionRegistry::Get(profile_); | |
361 | |
362 // If the app is installed but disabled, then enable it. | |
363 if (registry->GetExtensionById(extension_misc::kEasyUnlockAppId, | |
tbarzic
2014/09/10 19:56:46
you can probably skip this if; EnableExtension han
Tim Song
2014/09/11 03:00:05
Good point. I'll fix it in https://codereview.chro
| |
364 extensions::ExtensionRegistry::DISABLED)) { | |
365 ExtensionService* extension_service = | |
366 extensions::ExtensionSystem::Get(profile_)->extension_service(); | |
367 extension_service->EnableExtension(extension_misc::kEasyUnlockAppId); | |
368 } | |
369 } | |
324 } | 370 } |
325 #endif // defined(GOOGLE_CHROME_BUILD) | 371 #endif // defined(GOOGLE_CHROME_BUILD) |
326 } | 372 } |
327 | 373 |
328 void EasyUnlockService::UnloadApp() { | 374 void EasyUnlockService::DisableApp() { |
329 extensions::ComponentLoader* loader = GetComponentLoader(profile_); | 375 extensions::ComponentLoader* loader = GetComponentLoader(profile_); |
330 if (loader->Exists(extension_misc::kEasyUnlockAppId)) | 376 extensions::ExtensionRegistry* registry = |
331 loader->Remove(extension_misc::kEasyUnlockAppId); | 377 extensions::ExtensionRegistry::Get(profile_); |
378 | |
379 if (loader->Exists(extension_misc::kEasyUnlockAppId) && | |
380 registry->GetExtensionById(extension_misc::kEasyUnlockAppId, | |
381 extensions::ExtensionRegistry::ENABLED)) { | |
382 ExtensionService* extension_service = | |
383 extensions::ExtensionSystem::Get(profile_)->extension_service(); | |
384 extension_service->DisableExtension(extension_misc::kEasyUnlockAppId, | |
385 extensions::Extension::DISABLE_RELOAD); | |
386 } | |
332 } | 387 } |
333 | 388 |
334 void EasyUnlockService::UpdateAppState() { | 389 void EasyUnlockService::UpdateAppState() { |
335 if (IsAllowed()) { | 390 if (IsAllowed()) { |
336 LoadApp(); | 391 LoadApp(); |
392 | |
393 #if defined(OS_CHROMEOS) | |
394 if (!power_monitor_) | |
395 power_monitor_.reset(new PowerMonitor(this)); | |
396 #endif | |
337 } else { | 397 } else { |
338 UnloadApp(); | 398 DisableApp(); |
339 // Reset the screenlock state handler to make sure Screenlock state set | 399 // Reset the screenlock state handler to make sure Screenlock state set |
340 // by Easy Unlock app is reset. | 400 // by Easy Unlock app is reset. |
341 screenlock_state_handler_.reset(); | 401 screenlock_state_handler_.reset(); |
402 | |
403 #if defined(OS_CHROMEOS) | |
404 power_monitor_.reset(); | |
405 #endif | |
342 } | 406 } |
343 } | 407 } |
344 | 408 |
345 void EasyUnlockService::OnPrefsChanged() { | 409 void EasyUnlockService::OnPrefsChanged() { |
346 UpdateAppState(); | 410 UpdateAppState(); |
347 } | 411 } |
348 | 412 |
349 void EasyUnlockService::OnBluetoothAdapterPresentChanged() { | 413 void EasyUnlockService::OnBluetoothAdapterPresentChanged() { |
350 UpdateAppState(); | 414 UpdateAppState(); |
351 } | 415 } |
(...skipping 18 matching lines...) Expand all Loading... | |
370 // Make sure lock screen state set by the extension gets reset. | 434 // Make sure lock screen state set by the extension gets reset. |
371 screenlock_state_handler_.reset(); | 435 screenlock_state_handler_.reset(); |
372 | 436 |
373 if (GetComponentLoader(profile_)->Exists(extension_misc::kEasyUnlockAppId)) { | 437 if (GetComponentLoader(profile_)->Exists(extension_misc::kEasyUnlockAppId)) { |
374 extensions::ExtensionSystem* extension_system = | 438 extensions::ExtensionSystem* extension_system = |
375 extensions::ExtensionSystem::Get(profile_); | 439 extensions::ExtensionSystem::Get(profile_); |
376 extension_system->extension_service()->ReloadExtension( | 440 extension_system->extension_service()->ReloadExtension( |
377 extension_misc::kEasyUnlockAppId); | 441 extension_misc::kEasyUnlockAppId); |
378 } | 442 } |
379 } | 443 } |
OLD | NEW |