| 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/metrics/field_trial.h" | 10 #include "base/metrics/field_trial.h" |
| 11 #include "base/prefs/pref_service.h" | 11 #include "base/prefs/pref_service.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/extensions/component_loader.h" | 13 #include "chrome/browser/extensions/component_loader.h" |
| 14 #include "chrome/browser/extensions/extension_service.h" | 14 #include "chrome/browser/extensions/extension_service.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" | 16 #include "chrome/browser/signin/easy_unlock_screenlock_state_handler.h" |
| 17 #include "chrome/browser/signin/easy_unlock_service_factory.h" | 17 #include "chrome/browser/signin/easy_unlock_service_factory.h" |
| 18 #include "chrome/browser/signin/easy_unlock_service_observer.h" | 18 #include "chrome/browser/signin/easy_unlock_service_observer.h" |
| 19 #include "chrome/browser/signin/screenlock_bridge.h" | 19 #include "chrome/browser/signin/screenlock_bridge.h" |
| 20 #include "chrome/common/chrome_switches.h" | 20 #include "chrome/common/chrome_switches.h" |
| 21 #include "chrome/common/extensions/api/easy_unlock_private.h" |
| 21 #include "chrome/common/extensions/extension_constants.h" | 22 #include "chrome/common/extensions/extension_constants.h" |
| 22 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 23 #include "components/pref_registry/pref_registry_syncable.h" | 24 #include "components/pref_registry/pref_registry_syncable.h" |
| 24 #include "device/bluetooth/bluetooth_adapter.h" | 25 #include "device/bluetooth/bluetooth_adapter.h" |
| 25 #include "device/bluetooth/bluetooth_adapter_factory.h" | 26 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 27 #include "extensions/browser/event_router.h" |
| 26 #include "extensions/browser/extension_registry.h" | 28 #include "extensions/browser/extension_registry.h" |
| 27 #include "extensions/browser/extension_system.h" | 29 #include "extensions/browser/extension_system.h" |
| 28 #include "extensions/common/one_shot_event.h" | 30 #include "extensions/common/one_shot_event.h" |
| 29 #include "grit/browser_resources.h" | 31 #include "grit/browser_resources.h" |
| 30 | 32 |
| 31 #if defined(OS_CHROMEOS) | 33 #if defined(OS_CHROMEOS) |
| 32 #include "chromeos/dbus/dbus_thread_manager.h" | 34 #include "chromeos/dbus/dbus_thread_manager.h" |
| 33 #include "chromeos/dbus/power_manager_client.h" | 35 #include "chromeos/dbus/power_manager_client.h" |
| 34 #endif | 36 #endif |
| 35 | 37 |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 #endif // !defined(NDEBUG) | 226 #endif // !defined(NDEBUG) |
| 225 | 227 |
| 226 if (!easy_unlock_path.empty()) { | 228 if (!easy_unlock_path.empty()) { |
| 227 extensions::ComponentLoader* loader = GetComponentLoader(profile_); | 229 extensions::ComponentLoader* loader = GetComponentLoader(profile_); |
| 228 if (!loader->Exists(extension_misc::kEasyUnlockAppId)) | 230 if (!loader->Exists(extension_misc::kEasyUnlockAppId)) |
| 229 loader->Add(IDR_EASY_UNLOCK_MANIFEST, easy_unlock_path); | 231 loader->Add(IDR_EASY_UNLOCK_MANIFEST, easy_unlock_path); |
| 230 | 232 |
| 231 ExtensionService* extension_service = | 233 ExtensionService* extension_service = |
| 232 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 234 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 233 extension_service->EnableExtension(extension_misc::kEasyUnlockAppId); | 235 extension_service->EnableExtension(extension_misc::kEasyUnlockAppId); |
| 236 |
| 237 NotifyUserUpdated(); |
| 234 } | 238 } |
| 235 #endif // defined(GOOGLE_CHROME_BUILD) | 239 #endif // defined(GOOGLE_CHROME_BUILD) |
| 236 } | 240 } |
| 237 | 241 |
| 238 void EasyUnlockService::DisableAppIfLoaded() { | 242 void EasyUnlockService::DisableAppIfLoaded() { |
| 239 // Make sure lock screen state set by the extension gets reset. | 243 // Make sure lock screen state set by the extension gets reset. |
| 240 screenlock_state_handler_.reset(); | 244 ResetScreenlockStateHandler(); |
| 241 | 245 |
| 242 extensions::ComponentLoader* loader = GetComponentLoader(profile_); | 246 extensions::ComponentLoader* loader = GetComponentLoader(profile_); |
| 243 if (!loader->Exists(extension_misc::kEasyUnlockAppId)) | 247 if (!loader->Exists(extension_misc::kEasyUnlockAppId)) |
| 244 return; | 248 return; |
| 245 | 249 |
| 246 ExtensionService* extension_service = | 250 ExtensionService* extension_service = |
| 247 extensions::ExtensionSystem::Get(profile_)->extension_service(); | 251 extensions::ExtensionSystem::Get(profile_)->extension_service(); |
| 248 extension_service->DisableExtension(extension_misc::kEasyUnlockAppId, | 252 extension_service->DisableExtension(extension_misc::kEasyUnlockAppId, |
| 249 extensions::Extension::DISABLE_RELOAD); | 253 extensions::Extension::DISABLE_RELOAD); |
| 250 } | 254 } |
| 251 | 255 |
| 256 void EasyUnlockService::UnloadApp() { |
| 257 GetComponentLoader(profile_)->Remove(extension_misc::kEasyUnlockAppId); |
| 258 } |
| 259 |
| 252 void EasyUnlockService::ReloadApp() { | 260 void EasyUnlockService::ReloadApp() { |
| 253 // Make sure lock screen state set by the extension gets reset. | 261 // Make sure lock screen state set by the extension gets reset. |
| 254 screenlock_state_handler_.reset(); | 262 ResetScreenlockStateHandler(); |
| 255 | 263 |
| 256 if (GetComponentLoader(profile_)->Exists(extension_misc::kEasyUnlockAppId)) { | 264 if (!GetComponentLoader(profile_)->Exists(extension_misc::kEasyUnlockAppId)) |
| 257 extensions::ExtensionSystem* extension_system = | 265 return; |
| 258 extensions::ExtensionSystem::Get(profile_); | 266 extensions::ExtensionSystem* extension_system = |
| 259 extension_system->extension_service()->ReloadExtension( | 267 extensions::ExtensionSystem::Get(profile_); |
| 260 extension_misc::kEasyUnlockAppId); | 268 extension_system->extension_service()->ReloadExtension( |
| 261 } | 269 extension_misc::kEasyUnlockAppId); |
| 270 NotifyUserUpdated(); |
| 262 } | 271 } |
| 263 | 272 |
| 264 void EasyUnlockService::UpdateAppState() { | 273 void EasyUnlockService::UpdateAppState() { |
| 265 if (IsAllowed()) { | 274 if (IsAllowed()) { |
| 266 LoadApp(); | 275 LoadApp(); |
| 267 | 276 |
| 268 #if defined(OS_CHROMEOS) | 277 #if defined(OS_CHROMEOS) |
| 269 if (!power_monitor_) | 278 if (!power_monitor_) |
| 270 power_monitor_.reset(new PowerMonitor(this)); | 279 power_monitor_.reset(new PowerMonitor(this)); |
| 271 #endif | 280 #endif |
| 272 } else { | 281 } else { |
| 273 DisableAppIfLoaded(); | 282 DisableAppIfLoaded(); |
| 274 #if defined(OS_CHROMEOS) | 283 #if defined(OS_CHROMEOS) |
| 275 power_monitor_.reset(); | 284 power_monitor_.reset(); |
| 276 #endif | 285 #endif |
| 277 } | 286 } |
| 278 } | 287 } |
| 279 | 288 |
| 289 void EasyUnlockService::NotifyUserUpdated() { |
| 290 std::string user_id = GetUserEmail(); |
| 291 if (user_id.empty()) |
| 292 return; |
| 293 |
| 294 // Notify the easy unlock app that the user info changed. |
| 295 extensions::api::easy_unlock_private::UserInfo info; |
| 296 info.user_id = user_id; |
| 297 info.logged_in = GetType() == TYPE_REGULAR; |
| 298 info.data_ready = GetRemoteDevices(); |
| 299 |
| 300 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 301 args->Append(info.ToValue().release()); |
| 302 |
| 303 scoped_ptr<extensions::Event> event(new extensions::Event( |
| 304 extensions::api::easy_unlock_private::OnUserInfoUpdated::kEventName, |
| 305 args.Pass())); |
| 306 |
| 307 extensions::EventRouter::Get(profile_)->DispatchEventToExtension( |
| 308 extension_misc::kEasyUnlockAppId, event.Pass()); |
| 309 } |
| 310 |
| 280 void EasyUnlockService::NotifyTurnOffOperationStatusChanged() { | 311 void EasyUnlockService::NotifyTurnOffOperationStatusChanged() { |
| 281 FOR_EACH_OBSERVER( | 312 FOR_EACH_OBSERVER( |
| 282 EasyUnlockServiceObserver, observers_, OnTurnOffOperationStatusChanged()); | 313 EasyUnlockServiceObserver, observers_, OnTurnOffOperationStatusChanged()); |
| 283 } | 314 } |
| 284 | 315 |
| 316 void EasyUnlockService::ResetScreenlockStateHandler() { |
| 317 screenlock_state_handler_.reset(); |
| 318 } |
| 319 |
| 285 void EasyUnlockService::Initialize() { | 320 void EasyUnlockService::Initialize() { |
| 286 InitializeInternal(); | 321 InitializeInternal(); |
| 287 | 322 |
| 288 #if defined(OS_CHROMEOS) | 323 #if defined(OS_CHROMEOS) |
| 289 // Only start Bluetooth detection for ChromeOS since the feature is | 324 // Only start Bluetooth detection for ChromeOS since the feature is |
| 290 // only offered on ChromeOS. Enabling this on non-ChromeOS platforms | 325 // only offered on ChromeOS. Enabling this on non-ChromeOS platforms |
| 291 // previously introduced a performance regression: http://crbug.com/404482 | 326 // previously introduced a performance regression: http://crbug.com/404482 |
| 292 // Make sure not to reintroduce a performance regression if re-enabling on | 327 // Make sure not to reintroduce a performance regression if re-enabling on |
| 293 // additional platforms. | 328 // additional platforms. |
| 294 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. | 329 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. |
| 295 bluetooth_detector_->Initialize(); | 330 bluetooth_detector_->Initialize(); |
| 296 #endif // defined(OS_CHROMEOS) | 331 #endif // defined(OS_CHROMEOS) |
| 297 } | 332 } |
| 298 | 333 |
| 299 void EasyUnlockService::OnBluetoothAdapterPresentChanged() { | 334 void EasyUnlockService::OnBluetoothAdapterPresentChanged() { |
| 300 UpdateAppState(); | 335 UpdateAppState(); |
| 301 } | 336 } |
| 302 | 337 |
| OLD | NEW |