| 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_auth_attempt.h" | 16 #include "chrome/browser/signin/easy_unlock_auth_attempt.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/api/easy_unlock_private.h" |
| 22 #include "chrome/common/extensions/extension_constants.h" | 22 #include "chrome/common/extensions/extension_constants.h" |
| 23 #include "chrome/common/pref_names.h" | 23 #include "chrome/common/pref_names.h" |
| 24 #include "components/pref_registry/pref_registry_syncable.h" | 24 #include "components/pref_registry/pref_registry_syncable.h" |
| 25 #include "components/user_manager/user.h" |
| 25 #include "device/bluetooth/bluetooth_adapter.h" | 26 #include "device/bluetooth/bluetooth_adapter.h" |
| 26 #include "device/bluetooth/bluetooth_adapter_factory.h" | 27 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 27 #include "extensions/browser/event_router.h" | 28 #include "extensions/browser/event_router.h" |
| 28 #include "extensions/browser/extension_registry.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) |
| 35 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 34 #include "chromeos/dbus/dbus_thread_manager.h" | 36 #include "chromeos/dbus/dbus_thread_manager.h" |
| 35 #include "chromeos/dbus/power_manager_client.h" | 37 #include "chromeos/dbus/power_manager_client.h" |
| 36 #endif | 38 #endif |
| 37 | 39 |
| 38 namespace { | 40 namespace { |
| 39 | 41 |
| 40 extensions::ComponentLoader* GetComponentLoader( | 42 extensions::ComponentLoader* GetComponentLoader( |
| 41 content::BrowserContext* context) { | 43 content::BrowserContext* context) { |
| 42 extensions::ExtensionSystem* extension_system = | 44 extensions::ExtensionSystem* extension_system = |
| 43 extensions::ExtensionSystem::Get(context); | 45 extensions::ExtensionSystem::Get(context); |
| 44 ExtensionService* extension_service = extension_system->extension_service(); | 46 ExtensionService* extension_service = extension_system->extension_service(); |
| 45 return extension_service->component_loader(); | 47 return extension_service->component_loader(); |
| 46 } | 48 } |
| 47 | 49 |
| 48 } // namespace | 50 } // namespace |
| 49 | 51 |
| 50 // static | 52 // static |
| 51 EasyUnlockService* EasyUnlockService::Get(Profile* profile) { | 53 EasyUnlockService* EasyUnlockService::Get(Profile* profile) { |
| 52 return EasyUnlockServiceFactory::GetForProfile(profile); | 54 return EasyUnlockServiceFactory::GetForProfile(profile); |
| 53 } | 55 } |
| 54 | 56 |
| 57 // static |
| 58 EasyUnlockService* EasyUnlockService::GetForUser( |
| 59 const user_manager::User& user) { |
| 60 #if defined(OS_CHROMEOS) |
| 61 Profile* profile = chromeos::ProfileHelper::Get()->GetProfileByUser(&user); |
| 62 if (!profile) |
| 63 return NULL; |
| 64 return EasyUnlockService::Get(profile); |
| 65 #else |
| 66 return NULL; |
| 67 #endif |
| 68 } |
| 69 |
| 55 class EasyUnlockService::BluetoothDetector | 70 class EasyUnlockService::BluetoothDetector |
| 56 : public device::BluetoothAdapter::Observer { | 71 : public device::BluetoothAdapter::Observer { |
| 57 public: | 72 public: |
| 58 explicit BluetoothDetector(EasyUnlockService* service) | 73 explicit BluetoothDetector(EasyUnlockService* service) |
| 59 : service_(service), | 74 : service_(service), |
| 60 weak_ptr_factory_(this) { | 75 weak_ptr_factory_(this) { |
| 61 } | 76 } |
| 62 | 77 |
| 63 virtual ~BluetoothDetector() { | 78 virtual ~BluetoothDetector() { |
| 64 if (adapter_.get()) | 79 if (adapter_.get()) |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 #endif | 205 #endif |
| 191 } | 206 } |
| 192 | 207 |
| 193 EasyUnlockScreenlockStateHandler* | 208 EasyUnlockScreenlockStateHandler* |
| 194 EasyUnlockService::GetScreenlockStateHandler() { | 209 EasyUnlockService::GetScreenlockStateHandler() { |
| 195 if (!IsAllowed()) | 210 if (!IsAllowed()) |
| 196 return NULL; | 211 return NULL; |
| 197 if (!screenlock_state_handler_) { | 212 if (!screenlock_state_handler_) { |
| 198 screenlock_state_handler_.reset(new EasyUnlockScreenlockStateHandler( | 213 screenlock_state_handler_.reset(new EasyUnlockScreenlockStateHandler( |
| 199 GetUserEmail(), | 214 GetUserEmail(), |
| 215 IsHardlocked(), |
| 200 GetType() == TYPE_REGULAR ? profile_->GetPrefs() : NULL, | 216 GetType() == TYPE_REGULAR ? profile_->GetPrefs() : NULL, |
| 201 ScreenlockBridge::Get())); | 217 ScreenlockBridge::Get())); |
| 202 } | 218 } |
| 203 return screenlock_state_handler_.get(); | 219 return screenlock_state_handler_.get(); |
| 204 } | 220 } |
| 205 | 221 |
| 206 bool EasyUnlockService::UpdateScreenlockState( | 222 bool EasyUnlockService::UpdateScreenlockState( |
| 207 EasyUnlockScreenlockStateHandler::State state) { | 223 EasyUnlockScreenlockStateHandler::State state) { |
| 208 EasyUnlockScreenlockStateHandler* handler = GetScreenlockStateHandler(); | 224 EasyUnlockScreenlockStateHandler* handler = GetScreenlockStateHandler(); |
| 209 if (!handler) | 225 if (!handler) |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 void EasyUnlockService::NotifyTurnOffOperationStatusChanged() { | 385 void EasyUnlockService::NotifyTurnOffOperationStatusChanged() { |
| 370 FOR_EACH_OBSERVER( | 386 FOR_EACH_OBSERVER( |
| 371 EasyUnlockServiceObserver, observers_, OnTurnOffOperationStatusChanged()); | 387 EasyUnlockServiceObserver, observers_, OnTurnOffOperationStatusChanged()); |
| 372 } | 388 } |
| 373 | 389 |
| 374 void EasyUnlockService::ResetScreenlockState() { | 390 void EasyUnlockService::ResetScreenlockState() { |
| 375 screenlock_state_handler_.reset(); | 391 screenlock_state_handler_.reset(); |
| 376 auth_attempt_.reset(); | 392 auth_attempt_.reset(); |
| 377 } | 393 } |
| 378 | 394 |
| 395 void EasyUnlockService::SetScreenlockHardlockedState(bool value) { |
| 396 if (screenlock_state_handler_) |
| 397 screenlock_state_handler_->SetHardlocked(value); |
| 398 if (value) |
| 399 auth_attempt_.reset(); |
| 400 } |
| 401 |
| 379 void EasyUnlockService::Initialize() { | 402 void EasyUnlockService::Initialize() { |
| 380 InitializeInternal(); | 403 InitializeInternal(); |
| 381 | 404 |
| 382 #if defined(OS_CHROMEOS) | 405 #if defined(OS_CHROMEOS) |
| 383 // Only start Bluetooth detection for ChromeOS since the feature is | 406 // Only start Bluetooth detection for ChromeOS since the feature is |
| 384 // only offered on ChromeOS. Enabling this on non-ChromeOS platforms | 407 // only offered on ChromeOS. Enabling this on non-ChromeOS platforms |
| 385 // previously introduced a performance regression: http://crbug.com/404482 | 408 // previously introduced a performance regression: http://crbug.com/404482 |
| 386 // Make sure not to reintroduce a performance regression if re-enabling on | 409 // Make sure not to reintroduce a performance regression if re-enabling on |
| 387 // additional platforms. | 410 // additional platforms. |
| 388 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. | 411 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. |
| 389 bluetooth_detector_->Initialize(); | 412 bluetooth_detector_->Initialize(); |
| 390 #endif // defined(OS_CHROMEOS) | 413 #endif // defined(OS_CHROMEOS) |
| 391 } | 414 } |
| 392 | 415 |
| 393 void EasyUnlockService::OnBluetoothAdapterPresentChanged() { | 416 void EasyUnlockService::OnBluetoothAdapterPresentChanged() { |
| 394 UpdateAppState(); | 417 UpdateAppState(); |
| 395 } | 418 } |
| 396 | 419 |
| OLD | NEW |