| 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/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 11 #include "base/prefs/scoped_user_pref_update.h" | 11 #include "base/prefs/scoped_user_pref_update.h" |
| 12 #include "base/sys_info.h" | 12 #include "base/sys_info.h" |
| 13 #include "base/time/default_clock.h" | 13 #include "base/time/default_clock.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "chrome/browser/browser_process.h" | 15 #include "chrome/browser/browser_process.h" |
| 16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
| 17 #include "chrome/browser/services/gcm/gcm_profile_service.h" | 17 #include "chrome/browser/services/gcm/gcm_profile_service.h" |
| 18 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" | 18 #include "chrome/browser/services/gcm/gcm_profile_service_factory.h" |
| 19 #include "chrome/browser/signin/chrome_proximity_auth_client.h" | 19 #include "chrome/browser/signin/chrome_proximity_auth_client.h" |
| 20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 20 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 21 #include "chrome/browser/signin/signin_manager_factory.h" | 21 #include "chrome/browser/signin/signin_manager_factory.h" |
| 22 #include "chrome/common/extensions/api/easy_unlock_private.h" | 22 #include "chrome/common/extensions/api/easy_unlock_private.h" |
| 23 #include "chrome/common/extensions/extension_constants.h" | 23 #include "chrome/common/extensions/extension_constants.h" |
| 24 #include "chrome/common/pref_names.h" | 24 #include "chrome/common/pref_names.h" |
| 25 #include "chromeos/login/user_names.h" | 25 #include "chromeos/login/user_names.h" |
| 26 #include "components/pref_registry/pref_registry_syncable.h" | 26 #include "components/pref_registry/pref_registry_syncable.h" |
| 27 #include "components/proximity_auth/cryptauth/base64url.h" | |
| 28 #include "components/proximity_auth/cryptauth/cryptauth_access_token_fetcher.h" | 27 #include "components/proximity_auth/cryptauth/cryptauth_access_token_fetcher.h" |
| 29 #include "components/proximity_auth/cryptauth/cryptauth_client_impl.h" | 28 #include "components/proximity_auth/cryptauth/cryptauth_client_impl.h" |
| 29 #include "components/proximity_auth/cryptauth/cryptauth_device_manager.h" |
| 30 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_manager.h" | 30 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_manager.h" |
| 31 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_utils.h" | 31 #include "components/proximity_auth/cryptauth/cryptauth_enrollment_utils.h" |
| 32 #include "components/proximity_auth/cryptauth/cryptauth_gcm_manager_impl.h" | 32 #include "components/proximity_auth/cryptauth/cryptauth_gcm_manager_impl.h" |
| 33 #include "components/proximity_auth/cryptauth/secure_message_delegate.h" | 33 #include "components/proximity_auth/cryptauth/secure_message_delegate.h" |
| 34 #include "components/proximity_auth/cryptauth_enroller_factory_impl.h" | 34 #include "components/proximity_auth/cryptauth_enroller_factory_impl.h" |
| 35 #include "components/proximity_auth/logging/logging.h" | 35 #include "components/proximity_auth/logging/logging.h" |
| 36 #include "components/proximity_auth/proximity_auth_pref_manager.h" | 36 #include "components/proximity_auth/proximity_auth_pref_manager.h" |
| 37 #include "components/proximity_auth/proximity_auth_system.h" | |
| 38 #include "components/proximity_auth/remote_device_loader.h" | |
| 39 #include "components/proximity_auth/screenlock_bridge.h" | 37 #include "components/proximity_auth/screenlock_bridge.h" |
| 40 #include "components/proximity_auth/switches.h" | 38 #include "components/proximity_auth/switches.h" |
| 41 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 39 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 42 #include "components/signin/core/browser/signin_manager.h" | 40 #include "components/signin/core/browser/signin_manager.h" |
| 43 #include "components/translate/core/browser/translate_download_manager.h" | 41 #include "components/translate/core/browser/translate_download_manager.h" |
| 44 #include "components/version_info/version_info.h" | 42 #include "components/version_info/version_info.h" |
| 45 #include "content/public/browser/browser_thread.h" | 43 #include "content/public/browser/browser_thread.h" |
| 46 #include "extensions/browser/event_router.h" | 44 #include "extensions/browser/event_router.h" |
| 47 #include "extensions/common/constants.h" | 45 #include "extensions/common/constants.h" |
| 48 #include "google_apis/gaia/gaia_auth_util.h" | 46 #include "google_apis/gaia/gaia_auth_util.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 69 // Key name of the remote device list in kEasyUnlockPairing. | 67 // Key name of the remote device list in kEasyUnlockPairing. |
| 70 const char kKeyDevices[] = "devices"; | 68 const char kKeyDevices[] = "devices"; |
| 71 | 69 |
| 72 } // namespace | 70 } // namespace |
| 73 | 71 |
| 74 EasyUnlockServiceRegular::EasyUnlockServiceRegular(Profile* profile) | 72 EasyUnlockServiceRegular::EasyUnlockServiceRegular(Profile* profile) |
| 75 : EasyUnlockService(profile), | 73 : EasyUnlockService(profile), |
| 76 turn_off_flow_status_(EasyUnlockService::IDLE), | 74 turn_off_flow_status_(EasyUnlockService::IDLE), |
| 77 will_unlock_using_easy_unlock_(false), | 75 will_unlock_using_easy_unlock_(false), |
| 78 lock_screen_last_shown_timestamp_(base::TimeTicks::Now()), | 76 lock_screen_last_shown_timestamp_(base::TimeTicks::Now()), |
| 79 deferring_device_load_(false), | 77 weak_ptr_factory_(this) { |
| 80 weak_ptr_factory_(this) {} | 78 } |
| 81 | 79 |
| 82 EasyUnlockServiceRegular::~EasyUnlockServiceRegular() { | 80 EasyUnlockServiceRegular::~EasyUnlockServiceRegular() { |
| 83 } | 81 } |
| 84 | 82 |
| 85 proximity_auth::CryptAuthEnrollmentManager* | 83 proximity_auth::CryptAuthEnrollmentManager* |
| 86 EasyUnlockServiceRegular::GetCryptAuthEnrollmentManager() { | 84 EasyUnlockServiceRegular::GetCryptAuthEnrollmentManager() { |
| 87 return enrollment_manager_.get(); | 85 return enrollment_manager_.get(); |
| 88 } | 86 } |
| 89 | 87 |
| 90 proximity_auth::CryptAuthDeviceManager* | 88 proximity_auth::CryptAuthDeviceManager* |
| 91 EasyUnlockServiceRegular::GetCryptAuthDeviceManager() { | 89 EasyUnlockServiceRegular::GetCryptAuthDeviceManager() { |
| 92 return device_manager_.get(); | 90 return device_manager_.get(); |
| 93 } | 91 } |
| 94 | 92 |
| 95 proximity_auth::ProximityAuthPrefManager* | 93 proximity_auth::ProximityAuthPrefManager* |
| 96 EasyUnlockServiceRegular::GetProximityAuthPrefManager() { | 94 EasyUnlockServiceRegular::GetProximityAuthPrefManager() { |
| 97 return pref_manager_.get(); | 95 return pref_manager_.get(); |
| 98 } | 96 } |
| 99 | 97 |
| 100 void EasyUnlockServiceRegular::LoadRemoteDevices() { | |
| 101 if (device_manager_->unlock_keys().empty()) { | |
| 102 OnRemoteDeviceChanged(nullptr); | |
| 103 return; | |
| 104 } | |
| 105 | |
| 106 remote_device_loader_.reset(new proximity_auth::RemoteDeviceLoader( | |
| 107 device_manager_->unlock_keys(), proximity_auth_client()->GetAccountId(), | |
| 108 enrollment_manager_->GetUserPrivateKey(), | |
| 109 proximity_auth_client()->CreateSecureMessageDelegate(), | |
| 110 pref_manager_.get())); | |
| 111 remote_device_loader_->Load( | |
| 112 base::Bind(&EasyUnlockServiceRegular::OnRemoteDevicesLoaded, | |
| 113 weak_ptr_factory_.GetWeakPtr())); | |
| 114 } | |
| 115 | |
| 116 void EasyUnlockServiceRegular::OnRemoteDevicesLoaded( | |
| 117 const std::vector<proximity_auth::RemoteDevice>& remote_devices) { | |
| 118 // TODO(tengs): We only support unlocking with one remote device at the | |
| 119 // moment. We need to revisit once multiple devices are supported. | |
| 120 OnRemoteDeviceChanged(&remote_devices[0]); | |
| 121 | |
| 122 #if defined(OS_CHROMEOS) | |
| 123 // We need to store a copy of |remote devices_| in the TPM, so it can be | |
| 124 // retrieved on the sign-in screen when a user session has not been started | |
| 125 // yet. | |
| 126 scoped_ptr<base::ListValue> device_list(new base::ListValue()); | |
| 127 for (const auto& device : remote_devices) { | |
| 128 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | |
| 129 std::string b64_public_key, b64_psk; | |
| 130 proximity_auth::Base64UrlEncode(device.public_key, &b64_public_key); | |
| 131 proximity_auth::Base64UrlEncode(device.persistent_symmetric_key, &b64_psk); | |
| 132 | |
| 133 dict->SetString("name", device.name); | |
| 134 dict->SetString("psk", b64_psk); | |
| 135 dict->SetString("bluetoothAddress", device.bluetooth_address); | |
| 136 dict->SetString("permitId", "permit://google.com/easyunlock/v1/" + | |
| 137 proximity_auth_client()->GetAccountId()); | |
| 138 dict->SetString("permitRecord.id", b64_public_key); | |
| 139 dict->SetString("permitRecord.type", "license"); | |
| 140 dict->SetString("permitRecord.data", b64_public_key); | |
| 141 device_list->Append(dict.Pass()); | |
| 142 } | |
| 143 | |
| 144 // TODO(tengs): Rename this function after the easy_unlock app is replaced. | |
| 145 SetRemoteDevices(*device_list); | |
| 146 #endif | |
| 147 } | |
| 148 | |
| 149 EasyUnlockService::Type EasyUnlockServiceRegular::GetType() const { | 98 EasyUnlockService::Type EasyUnlockServiceRegular::GetType() const { |
| 150 return EasyUnlockService::TYPE_REGULAR; | 99 return EasyUnlockService::TYPE_REGULAR; |
| 151 } | 100 } |
| 152 | 101 |
| 153 std::string EasyUnlockServiceRegular::GetUserEmail() const { | 102 std::string EasyUnlockServiceRegular::GetUserEmail() const { |
| 154 const SigninManagerBase* signin_manager = | 103 const SigninManagerBase* signin_manager = |
| 155 SigninManagerFactory::GetForProfileIfExists(profile()); | 104 SigninManagerFactory::GetForProfileIfExists(profile()); |
| 156 // |profile| has to be a signed-in profile with SigninManager already | 105 // |profile| has to be a signed-in profile with SigninManager already |
| 157 // created. Otherwise, just crash to collect stack. | 106 // created. Otherwise, just crash to collect stack. |
| 158 DCHECK(signin_manager); | 107 DCHECK(signin_manager); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 proximity_auth::ScreenlockBridge::Get()->AddObserver(this); | 330 proximity_auth::ScreenlockBridge::Get()->AddObserver(this); |
| 382 registrar_.Init(profile()->GetPrefs()); | 331 registrar_.Init(profile()->GetPrefs()); |
| 383 registrar_.Add( | 332 registrar_.Add( |
| 384 prefs::kEasyUnlockAllowed, | 333 prefs::kEasyUnlockAllowed, |
| 385 base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged, | 334 base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged, |
| 386 base::Unretained(this))); | 335 base::Unretained(this))); |
| 387 registrar_.Add(prefs::kEasyUnlockProximityRequired, | 336 registrar_.Add(prefs::kEasyUnlockProximityRequired, |
| 388 base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged, | 337 base::Bind(&EasyUnlockServiceRegular::OnPrefsChanged, |
| 389 base::Unretained(this))); | 338 base::Unretained(this))); |
| 390 | 339 |
| 391 OnPrefsChanged(); | |
| 392 | |
| 393 #if defined(OS_CHROMEOS) | 340 #if defined(OS_CHROMEOS) |
| 394 if (base::CommandLine::ForCurrentProcess()->HasSwitch( | 341 if (base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 395 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery)) { | 342 proximity_auth::switches::kEnableBluetoothLowEnergyDiscovery)) { |
| 343 InitializeCryptAuth(); |
| 396 pref_manager_.reset( | 344 pref_manager_.reset( |
| 397 new proximity_auth::ProximityAuthPrefManager(profile()->GetPrefs())); | 345 new proximity_auth::ProximityAuthPrefManager(profile()->GetPrefs())); |
| 398 InitializeCryptAuth(); | |
| 399 LoadRemoteDevices(); | |
| 400 } | 346 } |
| 401 #endif | 347 #endif |
| 348 |
| 349 OnPrefsChanged(); |
| 402 } | 350 } |
| 403 | 351 |
| 404 void EasyUnlockServiceRegular::ShutdownInternal() { | 352 void EasyUnlockServiceRegular::ShutdownInternal() { |
| 405 #if defined(OS_CHROMEOS) | 353 #if defined(OS_CHROMEOS) |
| 406 short_lived_user_context_.reset(); | 354 short_lived_user_context_.reset(); |
| 407 #endif | 355 #endif |
| 408 | 356 |
| 409 turn_off_flow_status_ = EasyUnlockService::IDLE; | 357 turn_off_flow_status_ = EasyUnlockService::IDLE; |
| 410 registrar_.RemoveAll(); | 358 registrar_.RemoveAll(); |
| 411 proximity_auth::ScreenlockBridge::Get()->RemoveObserver(this); | 359 proximity_auth::ScreenlockBridge::Get()->RemoveObserver(this); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 433 #else | 381 #else |
| 434 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. | 382 // TODO(xiyuan): Revisit when non-chromeos platforms are supported. |
| 435 return false; | 383 return false; |
| 436 #endif | 384 #endif |
| 437 } | 385 } |
| 438 | 386 |
| 439 void EasyUnlockServiceRegular::OnWillFinalizeUnlock(bool success) { | 387 void EasyUnlockServiceRegular::OnWillFinalizeUnlock(bool success) { |
| 440 will_unlock_using_easy_unlock_ = success; | 388 will_unlock_using_easy_unlock_ = success; |
| 441 } | 389 } |
| 442 | 390 |
| 443 void EasyUnlockServiceRegular::OnSuspendDoneInternal() { | 391 void EasyUnlockServiceRegular::OnSuspendDone() { |
| 444 lock_screen_last_shown_timestamp_ = base::TimeTicks::Now(); | 392 lock_screen_last_shown_timestamp_ = base::TimeTicks::Now(); |
| 445 } | 393 } |
| 446 | 394 |
| 447 void EasyUnlockServiceRegular::OnRefreshTokenAvailable( | 395 void EasyUnlockServiceRegular::OnRefreshTokenAvailable( |
| 448 const std::string& account_id) { | 396 const std::string& account_id) { |
| 449 if (account_id == proximity_auth_client()->GetAccountId()) { | 397 if (account_id == proximity_auth_client()->GetAccountId()) { |
| 450 OAuth2TokenService* token_service = | 398 OAuth2TokenService* token_service = |
| 451 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()); | 399 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()); |
| 452 token_service->RemoveObserver(this); | 400 token_service->RemoveObserver(this); |
| 453 #if defined(OS_CHROMEOS) | 401 #if defined(OS_CHROMEOS) |
| 454 enrollment_manager_->Start(); | 402 InitializeCryptAuth(); |
| 455 device_manager_->Start(); | |
| 456 #endif | 403 #endif |
| 457 } | 404 } |
| 458 } | 405 } |
| 459 | 406 |
| 460 void EasyUnlockServiceRegular::OnSyncFinished( | |
| 461 proximity_auth::CryptAuthDeviceManager::SyncResult sync_result, | |
| 462 proximity_auth::CryptAuthDeviceManager::DeviceChangeResult | |
| 463 device_change_result) { | |
| 464 if (device_change_result != | |
| 465 proximity_auth::CryptAuthDeviceManager::DeviceChangeResult::CHANGED) | |
| 466 return; | |
| 467 | |
| 468 if (proximity_auth::ScreenlockBridge::Get()->IsLocked()) { | |
| 469 PA_LOG(INFO) << "Deferring device load until screen is unlocked."; | |
| 470 deferring_device_load_ = true; | |
| 471 } else { | |
| 472 LoadRemoteDevices(); | |
| 473 } | |
| 474 } | |
| 475 | |
| 476 void EasyUnlockServiceRegular::OnScreenDidLock( | 407 void EasyUnlockServiceRegular::OnScreenDidLock( |
| 477 proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type) { | 408 proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type) { |
| 478 will_unlock_using_easy_unlock_ = false; | 409 will_unlock_using_easy_unlock_ = false; |
| 479 lock_screen_last_shown_timestamp_ = base::TimeTicks::Now(); | 410 lock_screen_last_shown_timestamp_ = base::TimeTicks::Now(); |
| 480 } | 411 } |
| 481 | 412 |
| 482 void EasyUnlockServiceRegular::OnScreenDidUnlock( | 413 void EasyUnlockServiceRegular::OnScreenDidUnlock( |
| 483 proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type) { | 414 proximity_auth::ScreenlockBridge::LockHandler::ScreenType screen_type) { |
| 484 // Notifications of signin screen unlock events can also reach this code path; | 415 // Notifications of signin screen unlock events can also reach this code path; |
| 485 // disregard them. | 416 // disregard them. |
| 486 if (screen_type != proximity_auth::ScreenlockBridge::LockHandler::LOCK_SCREEN) | 417 if (screen_type != proximity_auth::ScreenlockBridge::LockHandler::LOCK_SCREEN) |
| 487 return; | 418 return; |
| 488 | 419 |
| 489 // Only record metrics for users who have enabled the feature. | 420 // Only record metrics for users who have enabled the feature. |
| 490 if (IsEnabled()) { | 421 if (IsEnabled()) { |
| 491 EasyUnlockAuthEvent event = | 422 EasyUnlockAuthEvent event = |
| 492 will_unlock_using_easy_unlock_ | 423 will_unlock_using_easy_unlock_ |
| 493 ? EASY_UNLOCK_SUCCESS | 424 ? EASY_UNLOCK_SUCCESS |
| 494 : GetPasswordAuthEvent(); | 425 : GetPasswordAuthEvent(); |
| 495 RecordEasyUnlockScreenUnlockEvent(event); | 426 RecordEasyUnlockScreenUnlockEvent(event); |
| 496 | 427 |
| 497 if (will_unlock_using_easy_unlock_) { | 428 if (will_unlock_using_easy_unlock_) { |
| 498 RecordEasyUnlockScreenUnlockDuration( | 429 RecordEasyUnlockScreenUnlockDuration( |
| 499 base::TimeTicks::Now() - lock_screen_last_shown_timestamp_); | 430 base::TimeTicks::Now() - lock_screen_last_shown_timestamp_); |
| 500 } | 431 } |
| 501 } | 432 } |
| 502 | 433 |
| 503 will_unlock_using_easy_unlock_ = false; | 434 will_unlock_using_easy_unlock_ = false; |
| 504 | |
| 505 // If we synced remote devices while the screen was locked, we can now load | |
| 506 // the new remote devices. | |
| 507 if (deferring_device_load_) { | |
| 508 PA_LOG(INFO) << "Loading deferred devices after screen unlock."; | |
| 509 deferring_device_load_ = false; | |
| 510 LoadRemoteDevices(); | |
| 511 } | |
| 512 } | 435 } |
| 513 | 436 |
| 514 void EasyUnlockServiceRegular::OnFocusedUserChanged( | 437 void EasyUnlockServiceRegular::OnFocusedUserChanged( |
| 515 const std::string& user_id) { | 438 const std::string& user_id) { |
| 516 // Nothing to do. | 439 // Nothing to do. |
| 517 } | 440 } |
| 518 | 441 |
| 519 void EasyUnlockServiceRegular::OnPrefsChanged() { | 442 void EasyUnlockServiceRegular::OnPrefsChanged() { |
| 520 SyncProfilePrefsToLocalState(); | 443 SyncProfilePrefsToLocalState(); |
| 521 UpdateAppState(); | 444 UpdateAppState(); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 // Note: The unit of this measument is in milli-inches. | 525 // Note: The unit of this measument is in milli-inches. |
| 603 device_info.set_device_display_diagonal_mils(diagonal_in_inches * 1000.0); | 526 device_info.set_device_display_diagonal_mils(diagonal_in_inches * 1000.0); |
| 604 #else | 527 #else |
| 605 // TODO(tengs): Fill in device information for other platforms. | 528 // TODO(tengs): Fill in device information for other platforms. |
| 606 #endif | 529 #endif |
| 607 return device_info; | 530 return device_info; |
| 608 } | 531 } |
| 609 | 532 |
| 610 #if defined(OS_CHROMEOS) | 533 #if defined(OS_CHROMEOS) |
| 611 void EasyUnlockServiceRegular::InitializeCryptAuth() { | 534 void EasyUnlockServiceRegular::InitializeCryptAuth() { |
| 535 OAuth2TokenService* token_service = |
| 536 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()); |
| 537 if (!token_service->RefreshTokenIsAvailable( |
| 538 proximity_auth_client()->GetAccountId())) { |
| 539 PA_LOG(INFO) << "Refresh token not yet available."; |
| 540 token_service->AddObserver(this); |
| 541 return; |
| 542 } |
| 543 |
| 612 PA_LOG(INFO) << "Initializing CryptAuth managers."; | 544 PA_LOG(INFO) << "Initializing CryptAuth managers."; |
| 613 // Initialize GCM manager. | 545 // Initialize GCM manager. |
| 614 gcm_manager_.reset(new proximity_auth::CryptAuthGCMManagerImpl( | 546 gcm_manager_.reset(new proximity_auth::CryptAuthGCMManagerImpl( |
| 615 gcm::GCMProfileServiceFactory::GetForProfile(profile())->driver(), | 547 gcm::GCMProfileServiceFactory::GetForProfile(profile())->driver(), |
| 616 proximity_auth_client()->GetPrefService())); | 548 proximity_auth_client()->GetPrefService())); |
| 617 gcm_manager_->StartListening(); | 549 gcm_manager_->StartListening(); |
| 618 | 550 |
| 619 // Initialize enrollment manager. | 551 // Initialize enrollment manager. |
| 620 cryptauth::GcmDeviceInfo device_info; | 552 cryptauth::GcmDeviceInfo device_info; |
| 621 enrollment_manager_.reset(new proximity_auth::CryptAuthEnrollmentManager( | 553 enrollment_manager_.reset(new proximity_auth::CryptAuthEnrollmentManager( |
| 622 make_scoped_ptr(new base::DefaultClock()), | 554 make_scoped_ptr(new base::DefaultClock()), |
| 623 make_scoped_ptr(new proximity_auth::CryptAuthEnrollerFactoryImpl( | 555 make_scoped_ptr(new proximity_auth::CryptAuthEnrollerFactoryImpl( |
| 624 proximity_auth_client())), | 556 proximity_auth_client())), |
| 625 proximity_auth_client()->CreateSecureMessageDelegate(), | 557 proximity_auth_client()->CreateSecureMessageDelegate(), |
| 626 GetGcmDeviceInfo(), gcm_manager_.get(), | 558 GetGcmDeviceInfo(), gcm_manager_.get(), |
| 627 proximity_auth_client()->GetPrefService())); | 559 proximity_auth_client()->GetPrefService())); |
| 560 enrollment_manager_->Start(); |
| 628 | 561 |
| 629 // Initialize device manager. | 562 // Initialize device manager. |
| 630 device_manager_.reset(new proximity_auth::CryptAuthDeviceManager( | 563 device_manager_.reset(new proximity_auth::CryptAuthDeviceManager( |
| 631 make_scoped_ptr(new base::DefaultClock()), | 564 make_scoped_ptr(new base::DefaultClock()), |
| 632 proximity_auth_client()->CreateCryptAuthClientFactory(), | 565 proximity_auth_client()->CreateCryptAuthClientFactory(), |
| 633 gcm_manager_.get(), proximity_auth_client()->GetPrefService())); | 566 gcm_manager_.get(), proximity_auth_client()->GetPrefService())); |
| 634 | |
| 635 OAuth2TokenService* token_service = | |
| 636 ProfileOAuth2TokenServiceFactory::GetForProfile(profile()); | |
| 637 if (!token_service->RefreshTokenIsAvailable( | |
| 638 proximity_auth_client()->GetAccountId())) { | |
| 639 PA_LOG(INFO) << "Refresh token not yet available, " | |
| 640 << "waiting before starting CryptAuth managers"; | |
| 641 token_service->AddObserver(this); | |
| 642 } | |
| 643 | |
| 644 device_manager_->AddObserver(this); | |
| 645 enrollment_manager_->Start(); | |
| 646 device_manager_->Start(); | 567 device_manager_->Start(); |
| 647 } | 568 } |
| 648 #endif | 569 #endif |
| OLD | NEW |