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_regular.h" | 5 #include "chrome/browser/signin/easy_unlock_service_regular.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/prefs/scoped_user_pref_update.h" | 10 #include "base/prefs/scoped_user_pref_update.h" |
| 11 #include "base/sys_info.h" | 11 #include "base/sys_info.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "base/version.h" | 13 #include "base/version.h" |
| 14 #include "chrome/browser/browser_process.h" | 14 #include "chrome/browser/browser_process.h" |
| 15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 16 #include "chrome/browser/signin/easy_unlock_util.h" | |
| 16 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 17 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 17 #include "chrome/browser/signin/screenlock_bridge.h" | |
| 18 #include "chrome/browser/signin/signin_manager_factory.h" | 18 #include "chrome/browser/signin/signin_manager_factory.h" |
| 19 #include "chrome/common/chrome_version_info.h" | 19 #include "chrome/common/chrome_version_info.h" |
| 20 #include "chrome/common/extensions/api/easy_unlock_private.h" | 20 #include "chrome/common/extensions/api/easy_unlock_private.h" |
| 21 #include "chrome/common/extensions/extension_constants.h" | 21 #include "chrome/common/extensions/extension_constants.h" |
| 22 #include "chrome/common/pref_names.h" | 22 #include "chrome/common/pref_names.h" |
| 23 #include "chromeos/login/user_names.h" | 23 #include "chromeos/login/user_names.h" |
| 24 #include "components/pref_registry/pref_registry_syncable.h" | 24 #include "components/pref_registry/pref_registry_syncable.h" |
| 25 #include "components/proximity_auth/cryptauth/cryptauth_access_token_fetcher.h" | 25 #include "components/proximity_auth/cryptauth/cryptauth_access_token_fetcher.h" |
| 26 #include "components/proximity_auth/cryptauth/cryptauth_client_impl.h" | 26 #include "components/proximity_auth/cryptauth/cryptauth_client_impl.h" |
| 27 #include "components/proximity_auth/screenlock_bridge.h" | |
| 27 #include "components/proximity_auth/switches.h" | 28 #include "components/proximity_auth/switches.h" |
| 28 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 29 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 29 #include "components/signin/core/browser/signin_manager.h" | 30 #include "components/signin/core/browser/signin_manager.h" |
| 30 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
| 31 #include "extensions/browser/event_router.h" | 32 #include "extensions/browser/event_router.h" |
| 32 #include "extensions/common/constants.h" | 33 #include "extensions/common/constants.h" |
| 33 | 34 |
| 34 #if defined(OS_CHROMEOS) | 35 #if defined(OS_CHROMEOS) |
| 35 #include "apps/app_lifetime_monitor_factory.h" | 36 #include "apps/app_lifetime_monitor_factory.h" |
| 36 #include "base/thread_task_runner_handle.h" | 37 #include "base/thread_task_runner_handle.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 85 } | 86 } |
| 86 | 87 |
| 87 EasyUnlockServiceRegular::~EasyUnlockServiceRegular() { | 88 EasyUnlockServiceRegular::~EasyUnlockServiceRegular() { |
| 88 } | 89 } |
| 89 | 90 |
| 90 EasyUnlockService::Type EasyUnlockServiceRegular::GetType() const { | 91 EasyUnlockService::Type EasyUnlockServiceRegular::GetType() const { |
| 91 return EasyUnlockService::TYPE_REGULAR; | 92 return EasyUnlockService::TYPE_REGULAR; |
| 92 } | 93 } |
| 93 | 94 |
| 94 std::string EasyUnlockServiceRegular::GetUserEmail() const { | 95 std::string EasyUnlockServiceRegular::GetUserEmail() const { |
| 95 return ScreenlockBridge::GetAuthenticatedUserEmail(profile()); | 96 const SigninManagerBase* signin_manager = |
| 97 SigninManagerFactory::GetForProfileIfExists(profile()); | |
| 98 // |profile| has to be a signed-in profile with SigninManager already | |
| 99 // created. Otherwise, just crash to collect stack. | |
| 100 CHECK(signin_manager); | |
|
Ilya Sherman
2015/04/24 21:22:02
This should be at most a DCHECK. CHECK is used ve
msarda
2015/04/27 11:29:24
Done.
| |
| 101 return signin_manager->GetAuthenticatedUsername(); | |
| 96 } | 102 } |
| 97 | 103 |
| 98 void EasyUnlockServiceRegular::LaunchSetup() { | 104 void EasyUnlockServiceRegular::LaunchSetup() { |
| 99 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 105 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 100 #if defined(OS_CHROMEOS) | 106 #if defined(OS_CHROMEOS) |
| 101 // Force the user to reauthenticate by showing a modal overlay (similar to the | 107 // Force the user to reauthenticate by showing a modal overlay (similar to the |
| 102 // lock screen). The password obtained from the reauth is cached for a short | 108 // lock screen). The password obtained from the reauth is cached for a short |
| 103 // period of time and used to create the cryptohome keys for sign-in. | 109 // period of time and used to create the cryptohome keys for sign-in. |
| 104 if (short_lived_user_context_ && short_lived_user_context_->user_context()) { | 110 if (short_lived_user_context_ && short_lived_user_context_->user_context()) { |
| 105 OpenSetupApp(); | 111 OpenSetupApp(); |
| (...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 void EasyUnlockServiceRegular::SetAutoPairingResult( | 297 void EasyUnlockServiceRegular::SetAutoPairingResult( |
| 292 bool success, | 298 bool success, |
| 293 const std::string& error) { | 299 const std::string& error) { |
| 294 DCHECK(!auto_pairing_callback_.is_null()); | 300 DCHECK(!auto_pairing_callback_.is_null()); |
| 295 | 301 |
| 296 auto_pairing_callback_.Run(success, error); | 302 auto_pairing_callback_.Run(success, error); |
| 297 auto_pairing_callback_.Reset(); | 303 auto_pairing_callback_.Reset(); |
| 298 } | 304 } |
| 299 | 305 |
| 300 void EasyUnlockServiceRegular::InitializeInternal() { | 306 void EasyUnlockServiceRegular::InitializeInternal() { |
| 301 ScreenlockBridge::Get()->AddObserver(this); | 307 GetScreenlockBridgeInstance()->AddObserver(this); |
| 302 registrar_.Init(profile()->GetPrefs()); | 308 registrar_.Init(profile()->GetPrefs()); |
| 303 registrar_.Add( | 309 registrar_.Add( |
| 304 prefs::kEasyUnlockAllowed, | 310 prefs::kEasyUnlockAllowed, |
| 305 base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged, | 311 base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged, |
| 306 base::Unretained(this))); | 312 base::Unretained(this))); |
| 307 registrar_.Add(prefs::kEasyUnlockProximityRequired, | 313 registrar_.Add(prefs::kEasyUnlockProximityRequired, |
| 308 base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged, | 314 base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged, |
| 309 base::Unretained(this))); | 315 base::Unretained(this))); |
| 310 OnPrefsChanged(); | 316 OnPrefsChanged(); |
| 311 } | 317 } |
| 312 | 318 |
| 313 void EasyUnlockServiceRegular::ShutdownInternal() { | 319 void EasyUnlockServiceRegular::ShutdownInternal() { |
| 314 #if defined(OS_CHROMEOS) | 320 #if defined(OS_CHROMEOS) |
| 315 short_lived_user_context_.reset(); | 321 short_lived_user_context_.reset(); |
| 316 #endif | 322 #endif |
| 317 | 323 |
| 318 turn_off_flow_status_ = EasyUnlockService::IDLE; | 324 turn_off_flow_status_ = EasyUnlockService::IDLE; |
| 319 registrar_.RemoveAll(); | 325 registrar_.RemoveAll(); |
| 320 ScreenlockBridge::Get()->RemoveObserver(this); | 326 GetScreenlockBridgeInstance()->RemoveObserver(this); |
| 321 } | 327 } |
| 322 | 328 |
| 323 bool EasyUnlockServiceRegular::IsAllowedInternal() const { | 329 bool EasyUnlockServiceRegular::IsAllowedInternal() const { |
| 324 #if defined(OS_CHROMEOS) | 330 #if defined(OS_CHROMEOS) |
| 325 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); | 331 user_manager::UserManager* user_manager = user_manager::UserManager::Get(); |
| 326 if (!user_manager->IsLoggedInAsUserWithGaiaAccount()) | 332 if (!user_manager->IsLoggedInAsUserWithGaiaAccount()) |
| 327 return false; | 333 return false; |
| 328 | 334 |
| 329 // TODO(tengs): Ephemeral accounts generate a new enrollment every time they | 335 // TODO(tengs): Ephemeral accounts generate a new enrollment every time they |
| 330 // are added, so disable Smart Lock to reduce enrollments on server. However, | 336 // are added, so disable Smart Lock to reduce enrollments on server. However, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 347 | 353 |
| 348 void EasyUnlockServiceRegular::OnWillFinalizeUnlock(bool success) { | 354 void EasyUnlockServiceRegular::OnWillFinalizeUnlock(bool success) { |
| 349 will_unlock_using_easy_unlock_ = success; | 355 will_unlock_using_easy_unlock_ = success; |
| 350 } | 356 } |
| 351 | 357 |
| 352 void EasyUnlockServiceRegular::OnSuspendDone() { | 358 void EasyUnlockServiceRegular::OnSuspendDone() { |
| 353 lock_screen_last_shown_timestamp_ = base::TimeTicks::Now(); | 359 lock_screen_last_shown_timestamp_ = base::TimeTicks::Now(); |
| 354 } | 360 } |
| 355 | 361 |
| 356 void EasyUnlockServiceRegular::OnScreenDidLock( | 362 void EasyUnlockServiceRegular::OnScreenDidLock( |
| 357 ScreenlockBridge::LockHandler::ScreenType screen_type) { | 363 proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type) { |
| 358 will_unlock_using_easy_unlock_ = false; | 364 will_unlock_using_easy_unlock_ = false; |
| 359 lock_screen_last_shown_timestamp_ = base::TimeTicks::Now(); | 365 lock_screen_last_shown_timestamp_ = base::TimeTicks::Now(); |
| 360 } | 366 } |
| 361 | 367 |
| 362 void EasyUnlockServiceRegular::OnScreenDidUnlock( | 368 void EasyUnlockServiceRegular::OnScreenDidUnlock( |
| 363 ScreenlockBridge::LockHandler::ScreenType screen_type) { | 369 proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type) { |
| 364 // Notifications of signin screen unlock events can also reach this code path; | 370 // Notifications of signin screen unlock events can also reach this code path; |
| 365 // disregard them. | 371 // disregard them. |
| 366 if (screen_type != ScreenlockBridge::LockHandler::LOCK_SCREEN) | 372 if (screen_type != proximity_auth::ScreenlockBridge::LockHandler::LOCK_SCREEN) |
| 367 return; | 373 return; |
| 368 | 374 |
| 369 // Only record metrics for users who have enabled the feature. | 375 // Only record metrics for users who have enabled the feature. |
| 370 if (IsEnabled()) { | 376 if (IsEnabled()) { |
| 371 EasyUnlockAuthEvent event = | 377 EasyUnlockAuthEvent event = |
| 372 will_unlock_using_easy_unlock_ | 378 will_unlock_using_easy_unlock_ |
| 373 ? EASY_UNLOCK_SUCCESS | 379 ? EASY_UNLOCK_SUCCESS |
| 374 : GetPasswordAuthEvent(); | 380 : GetPasswordAuthEvent(); |
| 375 RecordEasyUnlockScreenUnlockEvent(event); | 381 RecordEasyUnlockScreenUnlockEvent(event); |
| 376 | 382 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 new base::DictionaryValue()); | 432 new base::DictionaryValue()); |
| 427 user_prefs_dict->SetBooleanWithoutPathExpansion( | 433 user_prefs_dict->SetBooleanWithoutPathExpansion( |
| 428 prefs::kEasyUnlockProximityRequired, | 434 prefs::kEasyUnlockProximityRequired, |
| 429 profile_prefs->GetBoolean(prefs::kEasyUnlockProximityRequired)); | 435 profile_prefs->GetBoolean(prefs::kEasyUnlockProximityRequired)); |
| 430 | 436 |
| 431 DictionaryPrefUpdate update(local_state, | 437 DictionaryPrefUpdate update(local_state, |
| 432 prefs::kEasyUnlockLocalStateUserPrefs); | 438 prefs::kEasyUnlockLocalStateUserPrefs); |
| 433 std::string user_email = GetUserEmail(); | 439 std::string user_email = GetUserEmail(); |
| 434 update->SetWithoutPathExpansion(user_email, user_prefs_dict.Pass()); | 440 update->SetWithoutPathExpansion(user_email, user_prefs_dict.Pass()); |
| 435 } | 441 } |
| OLD | NEW |