Chromium Code Reviews| 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" |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 22 #include "chrome/browser/signin/easy_unlock_service_factory.h" | 22 #include "chrome/browser/signin/easy_unlock_service_factory.h" |
| 23 #include "chrome/browser/signin/easy_unlock_service_observer.h" | 23 #include "chrome/browser/signin/easy_unlock_service_observer.h" |
| 24 #include "chrome/browser/signin/screenlock_bridge.h" | 24 #include "chrome/browser/signin/screenlock_bridge.h" |
| 25 #include "chrome/common/chrome_switches.h" | 25 #include "chrome/common/chrome_switches.h" |
| 26 #include "chrome/common/extensions/api/easy_unlock_private.h" | 26 #include "chrome/common/extensions/api/easy_unlock_private.h" |
| 27 #include "chrome/common/extensions/extension_constants.h" | 27 #include "chrome/common/extensions/extension_constants.h" |
| 28 #include "chrome/common/pref_names.h" | 28 #include "chrome/common/pref_names.h" |
| 29 #include "components/pref_registry/pref_registry_syncable.h" | 29 #include "components/pref_registry/pref_registry_syncable.h" |
| 30 #include "components/proximity_auth/switches.h" | 30 #include "components/proximity_auth/switches.h" |
| 31 #include "components/user_manager/user.h" | 31 #include "components/user_manager/user.h" |
| 32 #include "components/user_manager/user_manager.h" | |
| 32 #include "device/bluetooth/bluetooth_adapter.h" | 33 #include "device/bluetooth/bluetooth_adapter.h" |
| 33 #include "device/bluetooth/bluetooth_adapter_factory.h" | 34 #include "device/bluetooth/bluetooth_adapter_factory.h" |
| 34 #include "extensions/browser/event_router.h" | 35 #include "extensions/browser/event_router.h" |
| 35 #include "extensions/browser/extension_registry.h" | 36 #include "extensions/browser/extension_registry.h" |
| 36 #include "extensions/browser/extension_system.h" | 37 #include "extensions/browser/extension_system.h" |
| 37 #include "extensions/common/one_shot_event.h" | 38 #include "extensions/common/one_shot_event.h" |
| 38 #include "grit/browser_resources.h" | 39 #include "grit/browser_resources.h" |
| 39 | 40 |
| 40 #if defined(OS_CHROMEOS) | 41 #if defined(OS_CHROMEOS) |
| 41 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" | 42 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_key_manager.h" |
| 43 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager. h" | |
| 44 #include "chrome/browser/chromeos/login/easy_unlock/easy_unlock_tpm_key_manager_ factory.h" | |
| 42 #include "chrome/browser/chromeos/login/session/user_session_manager.h" | 45 #include "chrome/browser/chromeos/login/session/user_session_manager.h" |
| 43 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 46 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 44 #include "chromeos/dbus/dbus_thread_manager.h" | 47 #include "chromeos/dbus/dbus_thread_manager.h" |
| 45 #include "chromeos/dbus/power_manager_client.h" | 48 #include "chromeos/dbus/power_manager_client.h" |
| 46 #endif | 49 #endif |
| 47 | 50 |
| 48 namespace { | 51 namespace { |
| 49 | 52 |
| 50 extensions::ComponentLoader* GetComponentLoader( | 53 extensions::ComponentLoader* GetComponentLoader( |
| 51 content::BrowserContext* context) { | 54 content::BrowserContext* context) { |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 189 base::WeakPtrFactory<PowerMonitor> weak_ptr_factory_; | 192 base::WeakPtrFactory<PowerMonitor> weak_ptr_factory_; |
| 190 | 193 |
| 191 DISALLOW_COPY_AND_ASSIGN(PowerMonitor); | 194 DISALLOW_COPY_AND_ASSIGN(PowerMonitor); |
| 192 }; | 195 }; |
| 193 #endif | 196 #endif |
| 194 | 197 |
| 195 EasyUnlockService::EasyUnlockService(Profile* profile) | 198 EasyUnlockService::EasyUnlockService(Profile* profile) |
| 196 : profile_(profile), | 199 : profile_(profile), |
| 197 bluetooth_detector_(new BluetoothDetector(this)), | 200 bluetooth_detector_(new BluetoothDetector(this)), |
| 198 shut_down_(false), | 201 shut_down_(false), |
| 202 tpm_key_checked_(false), | |
| 199 weak_ptr_factory_(this) { | 203 weak_ptr_factory_(this) { |
| 200 extensions::ExtensionSystem::Get(profile_)->ready().Post( | 204 extensions::ExtensionSystem::Get(profile_)->ready().Post( |
| 201 FROM_HERE, | 205 FROM_HERE, |
| 202 base::Bind(&EasyUnlockService::Initialize, | 206 base::Bind(&EasyUnlockService::Initialize, |
| 203 weak_ptr_factory_.GetWeakPtr())); | 207 weak_ptr_factory_.GetWeakPtr())); |
| 204 } | 208 } |
| 205 | 209 |
| 206 EasyUnlockService::~EasyUnlockService() { | 210 EasyUnlockService::~EasyUnlockService() { |
| 207 } | 211 } |
| 208 | 212 |
| 209 // static | 213 // static |
| 210 void EasyUnlockService::RegisterProfilePrefs( | 214 void EasyUnlockService::RegisterProfilePrefs( |
| 211 user_prefs::PrefRegistrySyncable* registry) { | 215 user_prefs::PrefRegistrySyncable* registry) { |
| 212 registry->RegisterBooleanPref( | 216 registry->RegisterBooleanPref( |
| 213 prefs::kEasyUnlockAllowed, | 217 prefs::kEasyUnlockAllowed, |
| 214 true, | 218 true, |
| 215 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 219 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 216 registry->RegisterBooleanPref( | 220 registry->RegisterBooleanPref( |
| 217 prefs::kEasyUnlockEnabled, | 221 prefs::kEasyUnlockEnabled, |
| 218 false, | 222 false, |
| 219 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 223 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 220 registry->RegisterDictionaryPref( | 224 registry->RegisterDictionaryPref( |
| 221 prefs::kEasyUnlockPairing, | 225 prefs::kEasyUnlockPairing, |
| 222 new base::DictionaryValue(), | 226 new base::DictionaryValue(), |
| 223 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); | 227 user_prefs::PrefRegistrySyncable::UNSYNCABLE_PREF); |
| 224 registry->RegisterBooleanPref( | 228 registry->RegisterBooleanPref( |
| 225 prefs::kEasyUnlockProximityRequired, | 229 prefs::kEasyUnlockProximityRequired, |
| 226 false, | 230 false, |
| 227 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); | 231 user_prefs::PrefRegistrySyncable::SYNCABLE_PREF); |
| 232 #if defined(OS_CHROMEOS) | |
| 233 EasyUnlockTpmKeyManager::RegisterProfilePrefs(registry); | |
| 234 #endif | |
| 228 } | 235 } |
| 229 | 236 |
| 230 // static | 237 // static |
| 231 void EasyUnlockService::RegisterPrefs(PrefRegistrySimple* registry) { | 238 void EasyUnlockService::RegisterPrefs(PrefRegistrySimple* registry) { |
| 232 registry->RegisterDictionaryPref(prefs::kEasyUnlockHardlockState); | 239 registry->RegisterDictionaryPref(prefs::kEasyUnlockHardlockState); |
| 240 #if defined(OS_CHROMEOS) | |
| 241 EasyUnlockTpmKeyManager::RegisterLocalStatePrefs(registry); | |
| 242 #endif | |
| 233 } | 243 } |
| 234 | 244 |
| 235 // static | 245 // static |
| 236 void EasyUnlockService::ResetLocalStateForUser(const std::string& user_id) { | 246 void EasyUnlockService::ResetLocalStateForUser(const std::string& user_id) { |
| 237 DCHECK(!user_id.empty()); | 247 DCHECK(!user_id.empty()); |
| 238 | 248 |
| 239 PrefService* local_state = GetLocalState(); | 249 PrefService* local_state = GetLocalState(); |
| 240 if (!local_state) | 250 if (!local_state) |
| 241 return; | 251 return; |
| 242 | 252 |
| 243 DictionaryPrefUpdate update(local_state, prefs::kEasyUnlockHardlockState); | 253 DictionaryPrefUpdate update(local_state, prefs::kEasyUnlockHardlockState); |
| 244 update->RemoveWithoutPathExpansion(user_id, NULL); | 254 update->RemoveWithoutPathExpansion(user_id, NULL); |
| 255 | |
| 256 #if defined(OS_CHROMEOS) | |
| 257 EasyUnlockTpmKeyManager::ResetLocalStateForUser(user_id); | |
|
xiyuan
2014/12/02 23:15:58
nit: fix indent
tbarzic
2014/12/03 19:10:28
Done.
| |
| 258 #endif | |
| 245 } | 259 } |
| 246 | 260 |
| 247 bool EasyUnlockService::IsAllowed() { | 261 bool EasyUnlockService::IsAllowed() { |
| 248 if (shut_down_) | 262 if (shut_down_) |
| 249 return false; | 263 return false; |
| 250 | 264 |
| 251 if (!IsAllowedInternal()) | 265 if (!IsAllowedInternal()) |
| 252 return false; | 266 return false; |
| 253 | 267 |
| 254 #if defined(OS_CHROMEOS) | 268 #if defined(OS_CHROMEOS) |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 525 return; | 539 return; |
| 526 extensions::ExtensionSystem* extension_system = | 540 extensions::ExtensionSystem* extension_system = |
| 527 extensions::ExtensionSystem::Get(profile_); | 541 extensions::ExtensionSystem::Get(profile_); |
| 528 extension_system->extension_service()->ReloadExtension( | 542 extension_system->extension_service()->ReloadExtension( |
| 529 extension_misc::kEasyUnlockAppId); | 543 extension_misc::kEasyUnlockAppId); |
| 530 NotifyUserUpdated(); | 544 NotifyUserUpdated(); |
| 531 } | 545 } |
| 532 | 546 |
| 533 void EasyUnlockService::UpdateAppState() { | 547 void EasyUnlockService::UpdateAppState() { |
| 534 if (IsAllowed()) { | 548 if (IsAllowed()) { |
| 549 EnsureTpmKeyPresentIfNeeded(); | |
| 535 LoadApp(); | 550 LoadApp(); |
| 536 | 551 |
| 537 #if defined(OS_CHROMEOS) | 552 #if defined(OS_CHROMEOS) |
| 538 if (!power_monitor_) | 553 if (!power_monitor_) |
| 539 power_monitor_.reset(new PowerMonitor(this)); | 554 power_monitor_.reset(new PowerMonitor(this)); |
| 540 #endif | 555 #endif |
| 541 } else { | 556 } else { |
| 542 bool bluetooth_waking_up = false; | 557 bool bluetooth_waking_up = false; |
| 543 #if defined(OS_CHROMEOS) | 558 #if defined(OS_CHROMEOS) |
| 544 // If the service is not allowed due to bluetooth not being detected just | 559 // If the service is not allowed due to bluetooth not being detected just |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 } | 677 } |
| 663 #endif | 678 #endif |
| 664 | 679 |
| 665 void EasyUnlockService::PrepareForSuspend() { | 680 void EasyUnlockService::PrepareForSuspend() { |
| 666 DisableAppIfLoaded(); | 681 DisableAppIfLoaded(); |
| 667 if (screenlock_state_handler_ && screenlock_state_handler_->IsActive()) { | 682 if (screenlock_state_handler_ && screenlock_state_handler_->IsActive()) { |
| 668 UpdateScreenlockState( | 683 UpdateScreenlockState( |
| 669 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); | 684 EasyUnlockScreenlockStateHandler::STATE_BLUETOOTH_CONNECTING); |
| 670 } | 685 } |
| 671 } | 686 } |
| 687 | |
| 688 void EasyUnlockService::EnsureTpmKeyPresentIfNeeded() { | |
| 689 if (tpm_key_checked_ || GetType() != TYPE_REGULAR) | |
| 690 return; | |
| 691 | |
| 692 // If this is called beforei the session is started, the chances are Chrome | |
|
xiyuan
2014/12/02 23:15:58
nit: beforei -> before
tbarzic
2014/12/03 19:10:28
Done.
| |
| 693 // is restarting in order to apply user flags. Don't check TPM keys in this | |
| 694 // case. | |
| 695 if (!user_manager::UserManager::Get() || | |
| 696 !user_manager::UserManager::Get()->IsSessionStarted()) | |
| 697 return; | |
| 698 | |
| 699 tpm_key_checked_ = true; | |
| 700 | |
| 701 #if defined(OS_CHROMEOS) | |
| 702 // TODO(tbarzic): Set check_private_key only if previous sign-in attempt | |
| 703 // failed. | |
| 704 EasyUnlockTpmKeyManagerFactory::GetInstance()->Get(profile_) | |
| 705 ->IsTpmKeyPresent(GetUserEmail(), | |
| 706 true /* check_private_key */, | |
| 707 base::Closure()); | |
| 708 #endif | |
| 709 } | |
| OLD | NEW |