Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/chromeos/arc/arc_auth_service.h" | 5 #include "chrome/browser/chromeos/arc/arc_auth_service.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "ash/common/shelf/shelf_delegate.h" | 9 #include "ash/common/shelf/shelf_delegate.h" |
| 10 #include "ash/common/wm_shell.h" | 10 #include "ash/common/wm_shell.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 114 return ProvisioningResult::UNKNOWN_ERROR; | 114 return ProvisioningResult::UNKNOWN_ERROR; |
| 115 } | 115 } |
| 116 | 116 |
| 117 } // namespace | 117 } // namespace |
| 118 | 118 |
| 119 // TODO(lhchavez): Get rid of this class once we can safely remove all the | 119 // TODO(lhchavez): Get rid of this class once we can safely remove all the |
| 120 // deprecated interfaces and only need to care about one type of callback. | 120 // deprecated interfaces and only need to care about one type of callback. |
| 121 class ArcAuthService::AccountInfoNotifier { | 121 class ArcAuthService::AccountInfoNotifier { |
| 122 public: | 122 public: |
| 123 explicit AccountInfoNotifier( | 123 explicit AccountInfoNotifier( |
| 124 const GetAuthCodeDeprecated0Callback& auth0_callback) | |
|
Luis Héctor Chávez
2016/11/10 23:58:20
This hasn't been used since M52. Let's get rid of
hidehiko
2016/11/14 11:29:31
Extracted to crrev.com/2499933002.
For this topic,
| |
| 125 : callback_type_(CallbackType::AUTH_CODE0), | |
| 126 auth0_callback_(auth0_callback) {} | |
| 127 | |
| 128 explicit AccountInfoNotifier( | |
| 124 const GetAuthCodeDeprecatedCallback& auth_callback) | 129 const GetAuthCodeDeprecatedCallback& auth_callback) |
| 125 : callback_type_(CallbackType::AUTH_CODE), | 130 : callback_type_(CallbackType::AUTH_CODE), |
| 126 auth_callback_(auth_callback) {} | 131 auth_callback_(auth_callback) {} |
| 127 | 132 |
| 128 explicit AccountInfoNotifier( | 133 explicit AccountInfoNotifier( |
| 129 const GetAuthCodeAndAccountTypeDeprecatedCallback& auth_account_callback) | 134 const GetAuthCodeAndAccountTypeDeprecatedCallback& auth_account_callback) |
| 130 : callback_type_(CallbackType::AUTH_CODE_AND_ACCOUNT), | 135 : callback_type_(CallbackType::AUTH_CODE_AND_ACCOUNT), |
| 131 auth_account_callback_(auth_account_callback) {} | 136 auth_account_callback_(auth_account_callback) {} |
| 132 | 137 |
| 133 explicit AccountInfoNotifier(const AccountInfoCallback& account_info_callback) | 138 explicit AccountInfoNotifier(const AccountInfoCallback& account_info_callback) |
| 134 : callback_type_(CallbackType::ACCOUNT_INFO), | 139 : callback_type_(CallbackType::ACCOUNT_INFO), |
| 135 account_info_callback_(account_info_callback) {} | 140 account_info_callback_(account_info_callback) {} |
| 136 | 141 |
| 137 void Notify(bool is_enforced, | 142 void Notify(bool is_enforced, |
| 138 const std::string& auth_code, | 143 const std::string& auth_code, |
| 139 mojom::ChromeAccountType account_type, | 144 mojom::ChromeAccountType account_type, |
| 140 bool is_managed) { | 145 bool is_managed) { |
| 141 switch (callback_type_) { | 146 switch (callback_type_) { |
| 147 case CallbackType::AUTH_CODE0: | |
| 148 DCHECK(!auth0_callback_.is_null()); | |
| 149 auth0_callback_.Run(auth_code); | |
| 150 break; | |
| 142 case CallbackType::AUTH_CODE: | 151 case CallbackType::AUTH_CODE: |
| 143 DCHECK(!auth_callback_.is_null()); | 152 DCHECK(!auth_callback_.is_null()); |
| 144 auth_callback_.Run(auth_code, is_enforced); | 153 auth_callback_.Run(auth_code, is_enforced); |
| 145 break; | 154 break; |
| 146 case CallbackType::AUTH_CODE_AND_ACCOUNT: | 155 case CallbackType::AUTH_CODE_AND_ACCOUNT: |
| 147 DCHECK(!auth_account_callback_.is_null()); | 156 DCHECK(!auth_account_callback_.is_null()); |
| 148 auth_account_callback_.Run(auth_code, is_enforced, account_type); | 157 auth_account_callback_.Run(auth_code, is_enforced, account_type); |
| 149 break; | 158 break; |
| 150 case CallbackType::ACCOUNT_INFO: | 159 case CallbackType::ACCOUNT_INFO: |
| 151 DCHECK(!account_info_callback_.is_null()); | 160 DCHECK(!account_info_callback_.is_null()); |
| 152 mojom::AccountInfoPtr account_info = mojom::AccountInfo::New(); | 161 mojom::AccountInfoPtr account_info = mojom::AccountInfo::New(); |
| 153 if (!is_enforced) { | 162 if (!is_enforced) { |
| 154 account_info->auth_code = nullptr; | 163 account_info->auth_code = nullptr; |
| 155 } else { | 164 } else { |
| 156 account_info->auth_code = auth_code; | 165 account_info->auth_code = auth_code; |
| 157 } | 166 } |
| 158 account_info->account_type = account_type; | 167 account_info->account_type = account_type; |
| 159 account_info->is_managed = is_managed; | 168 account_info->is_managed = is_managed; |
| 160 account_info_callback_.Run(std::move(account_info)); | 169 account_info_callback_.Run(std::move(account_info)); |
| 161 break; | 170 break; |
| 162 } | 171 } |
| 163 } | 172 } |
| 164 | 173 |
| 165 private: | 174 private: |
| 166 enum class CallbackType { AUTH_CODE, AUTH_CODE_AND_ACCOUNT, ACCOUNT_INFO }; | 175 enum class CallbackType { |
| 176 AUTH_CODE0, | |
| 177 AUTH_CODE, | |
| 178 AUTH_CODE_AND_ACCOUNT, | |
| 179 ACCOUNT_INFO | |
| 180 }; | |
| 167 | 181 |
| 168 const CallbackType callback_type_; | 182 const CallbackType callback_type_; |
| 183 const GetAuthCodeDeprecated0Callback auth0_callback_; | |
| 169 const GetAuthCodeDeprecatedCallback auth_callback_; | 184 const GetAuthCodeDeprecatedCallback auth_callback_; |
| 170 const GetAuthCodeAndAccountTypeDeprecatedCallback auth_account_callback_; | 185 const GetAuthCodeAndAccountTypeDeprecatedCallback auth_account_callback_; |
| 171 const AccountInfoCallback account_info_callback_; | 186 const AccountInfoCallback account_info_callback_; |
| 172 }; | 187 }; |
| 173 | 188 |
| 174 ArcAuthService::ArcAuthService(ArcBridgeService* bridge_service) | 189 ArcAuthService::ArcAuthService(ArcBridgeService* bridge_service) |
| 175 : ArcService(bridge_service), binding_(this), weak_ptr_factory_(this) { | 190 : ArcService(bridge_service), binding_(this), weak_ptr_factory_(this) { |
| 176 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 191 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 177 DCHECK(!g_arc_auth_service); | 192 DCHECK(!g_arc_auth_service); |
| 178 | 193 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 } | 313 } |
| 299 | 314 |
| 300 void ArcAuthService::RemoveArcData() { | 315 void ArcAuthService::RemoveArcData() { |
| 301 if (!arc_bridge_service()->stopped()) { | 316 if (!arc_bridge_service()->stopped()) { |
| 302 // Just set a flag. On bridge stopped, this will be re-called, | 317 // Just set a flag. On bridge stopped, this will be re-called, |
| 303 // then session manager should remove the data. | 318 // then session manager should remove the data. |
| 304 clear_required_ = true; | 319 clear_required_ = true; |
| 305 return; | 320 return; |
| 306 } | 321 } |
| 307 clear_required_ = false; | 322 clear_required_ = false; |
| 323 DCHECK(!arc_data_is_being_removed_); | |
| 324 arc_data_is_being_removed_ = true; | |
| 308 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData( | 325 chromeos::DBusThreadManager::Get()->GetSessionManagerClient()->RemoveArcData( |
| 309 cryptohome::Identification( | 326 cryptohome::Identification( |
| 310 multi_user_util::GetAccountIdFromProfile(profile_)), | 327 multi_user_util::GetAccountIdFromProfile(profile_)), |
| 311 base::Bind(&ArcAuthService::OnArcDataRemoved, | 328 base::Bind(&ArcAuthService::OnArcDataRemoved, |
| 312 weak_ptr_factory_.GetWeakPtr())); | 329 weak_ptr_factory_.GetWeakPtr())); |
| 313 } | 330 } |
| 314 | 331 |
| 315 void ArcAuthService::OnArcDataRemoved(bool success) { | 332 void ArcAuthService::OnArcDataRemoved(bool success) { |
| 316 LOG_IF(ERROR, !success) << "Required ARC user data wipe failed."; | 333 LOG_IF(ERROR, !success) << "Required ARC user data wipe failed."; |
| 334 arc_data_is_being_removed_ = false; | |
| 317 | 335 |
| 318 // Here check if |reenable_arc_| is marked or not. | 336 // Here check if |reenable_arc_| is marked or not. |
| 319 // The only case this happens should be in the special case for enterprise | 337 // The only case this happens should be in the special case for enterprise |
| 320 // "on managed lost" case. In that case, OnBridgeStopped() should trigger | 338 // "on managed lost" case. In that case, OnBridgeStopped() should trigger |
| 321 // the RemoveArcData(), then this. | 339 // the RemoveArcData(), then this. |
| 322 // TODO(hidehiko): Restructure the code. | 340 // TODO(hidehiko): Restructure the code. |
| 323 if (!reenable_arc_) | 341 if (!reenable_arc_) |
| 324 return; | 342 return; |
| 325 | 343 |
| 326 // Restart ARC anyway. Let the enterprise reporting instance decide whether | 344 // Restart ARC anyway. Let the enterprise reporting instance decide whether |
| 327 // the ARC user data wipe is still required or not. | 345 // the ARC user data wipe is still required or not. |
| 328 reenable_arc_ = false; | 346 reenable_arc_ = false; |
| 329 VLOG(1) << "Reenable ARC"; | 347 VLOG(1) << "Reenable ARC"; |
| 330 EnableArc(); | 348 EnableArc(); |
| 331 } | 349 } |
| 332 | 350 |
| 333 std::string ArcAuthService::GetAndResetAuthCode() { | |
| 334 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 335 std::string auth_code; | |
| 336 auth_code_.swap(auth_code); | |
| 337 return auth_code; | |
| 338 } | |
| 339 | |
| 340 void ArcAuthService::GetAuthCodeDeprecated0( | 351 void ArcAuthService::GetAuthCodeDeprecated0( |
| 341 const GetAuthCodeDeprecated0Callback& callback) { | 352 const GetAuthCodeDeprecated0Callback& callback) { |
| 342 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 353 RequestAccountInfoInternal( |
| 343 DCHECK(!IsOptInVerificationDisabled()); | 354 base::MakeUnique<ArcAuthService::AccountInfoNotifier>(callback)); |
| 344 callback.Run(GetAndResetAuthCode()); | |
|
hidehiko
2016/11/10 06:49:28
Note: If you prefer, I can extract this part into
Luis Héctor Chávez
2016/11/10 23:58:20
Actually can you log that this method is deprecate
hidehiko
2016/11/14 11:29:31
Acknowledged.
| |
| 345 } | 355 } |
| 346 | 356 |
| 347 void ArcAuthService::GetAuthCodeDeprecated( | 357 void ArcAuthService::GetAuthCodeDeprecated( |
| 348 const GetAuthCodeDeprecatedCallback& callback) { | 358 const GetAuthCodeDeprecatedCallback& callback) { |
| 349 RequestAccountInfoInternal( | 359 RequestAccountInfoInternal( |
| 350 base::MakeUnique<ArcAuthService::AccountInfoNotifier>(callback)); | 360 base::MakeUnique<ArcAuthService::AccountInfoNotifier>(callback)); |
| 351 } | 361 } |
| 352 | 362 |
| 353 void ArcAuthService::GetAuthCodeAndAccountTypeDeprecated( | 363 void ArcAuthService::GetAuthCodeAndAccountTypeDeprecated( |
| 354 const GetAuthCodeAndAccountTypeDeprecatedCallback& callback) { | 364 const GetAuthCodeAndAccountTypeDeprecatedCallback& callback) { |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 371 instance->OnAccountInfoReady(std::move(account_info)); | 381 instance->OnAccountInfoReady(std::move(account_info)); |
| 372 } | 382 } |
| 373 | 383 |
| 374 void ArcAuthService::RequestAccountInfoInternal( | 384 void ArcAuthService::RequestAccountInfoInternal( |
| 375 std::unique_ptr<ArcAuthService::AccountInfoNotifier> | 385 std::unique_ptr<ArcAuthService::AccountInfoNotifier> |
| 376 account_info_notifier) { | 386 account_info_notifier) { |
| 377 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 387 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 378 // No other auth code-related operation may be in progress. | 388 // No other auth code-related operation may be in progress. |
| 379 DCHECK(!account_info_notifier_); | 389 DCHECK(!account_info_notifier_); |
| 380 | 390 |
| 381 const std::string auth_code = GetAndResetAuthCode(); | 391 if (IsOptInVerificationDisabled()) { |
| 382 const bool is_enforced = !IsOptInVerificationDisabled(); | 392 account_info_notifier->Notify(false /* = is_enforced */, "", |
|
Luis Héctor Chávez
2016/11/10 23:58:20
nit: s/""/std::string()/
hidehiko
2016/11/14 11:29:31
Done.
| |
| 383 if (!auth_code.empty() || !is_enforced) { | |
| 384 account_info_notifier->Notify(is_enforced, auth_code, | |
| 385 mojom::ChromeAccountType::USER_ACCOUNT, | 393 mojom::ChromeAccountType::USER_ACCOUNT, |
| 386 policy_util::IsAccountManaged(profile_)); | 394 policy_util::IsAccountManaged(profile_)); |
| 387 return; | 395 return; |
| 388 } | 396 } |
| 389 | 397 |
| 390 account_info_notifier_ = std::move(account_info_notifier); | 398 account_info_notifier_ = std::move(account_info_notifier); |
| 391 PrepareContextForAuthCodeRequest(); | 399 PrepareContextForAuthCodeRequest(); |
| 392 } | 400 } |
| 393 | 401 |
| 394 bool ArcAuthService::IsAuthCodeRequest() const { | 402 bool ArcAuthService::IsAuthCodeRequest() const { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 554 | 562 |
| 555 SetState(State::STOPPED); | 563 SetState(State::STOPPED); |
| 556 | 564 |
| 557 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( | 565 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( |
| 558 prefs::kArcEnabled, this); | 566 prefs::kArcEnabled, this); |
| 559 | 567 |
| 560 context_.reset(new ArcAuthContext(this, profile_)); | 568 context_.reset(new ArcAuthContext(this, profile_)); |
| 561 | 569 |
| 562 // In case UI is disabled we assume that ARC is opted-in. | 570 // In case UI is disabled we assume that ARC is opted-in. |
| 563 if (IsOptInVerificationDisabled()) { | 571 if (IsOptInVerificationDisabled()) { |
| 564 auth_code_.clear(); | |
| 565 StartArc(); | 572 StartArc(); |
| 566 return; | 573 return; |
| 567 } | 574 } |
| 568 | 575 |
| 569 if (!g_disable_ui_for_testing || | 576 if (!g_disable_ui_for_testing || |
| 570 g_enable_check_android_management_for_testing) { | 577 g_enable_check_android_management_for_testing) { |
| 571 ArcAndroidManagementChecker::StartClient(); | 578 ArcAndroidManagementChecker::StartClient(); |
| 572 } | 579 } |
| 573 pref_change_registrar_.Init(profile_->GetPrefs()); | 580 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 574 pref_change_registrar_.Add( | 581 pref_change_registrar_.Add( |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 678 | 685 |
| 679 if (!arc_enabled) { | 686 if (!arc_enabled) { |
| 680 StopArc(); | 687 StopArc(); |
| 681 RemoveArcData(); | 688 RemoveArcData(); |
| 682 return; | 689 return; |
| 683 } | 690 } |
| 684 | 691 |
| 685 if (state_ == State::ACTIVE) | 692 if (state_ == State::ACTIVE) |
| 686 return; | 693 return; |
| 687 CloseUI(); | 694 CloseUI(); |
| 688 auth_code_.clear(); | |
| 689 | 695 |
| 690 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { | 696 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { |
| 691 if (profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { | 697 if (profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { |
| 692 // Need pre-fetch auth code and start Arc. | 698 StartArc(); |
| 693 SetState(State::FETCHING_CODE); | |
| 694 PrepareContextForAuthCodeRequest(); | |
| 695 } else { | 699 } else { |
| 696 // Need pre-fetch auth code and show OptIn UI if needed. | 700 // Need pre-fetch auth code and show OptIn UI if needed. |
| 697 StartUI(); | 701 StartUI(); |
| 698 } | 702 } |
| 699 } else { | 703 } else { |
| 700 // Ready to start Arc, but check Android management in parallel. | 704 // Ready to start Arc, but check Android management in parallel. |
| 701 StartArc(); | 705 StartArc(); |
| 702 // Note: Because the callback may be called in synchronous way (i.e. called | 706 // Note: Because the callback may be called in synchronous way (i.e. called |
| 703 // on the same stack), StartCheck() needs to be called *after* StartArc(). | 707 // on the same stack), StartCheck() needs to be called *after* StartArc(). |
| 704 // Otherwise, DisableArc() which may be called in | 708 // Otherwise, DisableArc() which may be called in |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 773 reenable_arc_ = true; | 777 reenable_arc_ = true; |
| 774 StopArc(); | 778 StopArc(); |
| 775 } | 779 } |
| 776 | 780 |
| 777 void ArcAuthService::StartArc() { | 781 void ArcAuthService::StartArc() { |
| 778 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 782 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 779 arc_bridge_service()->RequestStart(); | 783 arc_bridge_service()->RequestStart(); |
| 780 SetState(State::ACTIVE); | 784 SetState(State::ACTIVE); |
| 781 } | 785 } |
| 782 | 786 |
| 783 void ArcAuthService::SetAuthCodeAndStartArc(const std::string& auth_code) { | 787 void ArcAuthService::OnAuthCodeObtained(const std::string& auth_code) { |
| 784 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 788 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 785 DCHECK(!auth_code.empty()); | 789 DCHECK(!auth_code.empty()); |
| 786 | 790 |
| 787 if (IsAuthCodeRequest()) { | 791 account_info_notifier_->Notify(!IsOptInVerificationDisabled(), auth_code, |
| 788 account_info_notifier_->Notify(!IsOptInVerificationDisabled(), auth_code, | 792 mojom::ChromeAccountType::USER_ACCOUNT, |
| 789 mojom::ChromeAccountType::USER_ACCOUNT, | 793 policy_util::IsAccountManaged(profile_)); |
| 790 policy_util::IsAccountManaged(profile_)); | 794 account_info_notifier_.reset(); |
| 791 account_info_notifier_.reset(); | |
| 792 return; | |
| 793 } | |
| 794 | |
| 795 if (state_ != State::TERMS && state_ != State::ANDROID_MANAGEMENT_CHECK && | |
| 796 state_ != State::FETCHING_CODE) { | |
| 797 ShutdownBridgeAndCloseUI(); | |
| 798 return; | |
| 799 } | |
| 800 | |
| 801 sign_in_time_ = base::Time::Now(); | |
| 802 VLOG(1) << "Starting ARC for first sign in."; | |
|
Luis Héctor Chávez
2016/11/10 23:58:20
Is there no way of knowing if this is the first si
hidehiko
2016/11/14 11:29:31
Moved to OnAndroidManagementChecked().
| |
| 803 | |
| 804 SetUIPage(ArcSupportHost::UIPage::START_PROGRESS, base::string16()); | |
| 805 ShutdownBridge(); | |
| 806 auth_code_ = auth_code; | |
| 807 arc_sign_in_timer_.Start(FROM_HERE, kArcSignInTimeout, | |
| 808 base::Bind(&ArcAuthService::OnArcSignInTimeout, | |
| 809 weak_ptr_factory_.GetWeakPtr())); | |
| 810 StartArc(); | |
| 811 } | 795 } |
| 812 | 796 |
| 813 void ArcAuthService::OnArcSignInTimeout() { | 797 void ArcAuthService::OnArcSignInTimeout() { |
| 814 LOG(ERROR) << "Timed out waiting for first sign in."; | 798 LOG(ERROR) << "Timed out waiting for first sign in."; |
| 815 OnSignInFailedInternal(ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT); | 799 OnSignInFailedInternal(ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT); |
| 816 } | 800 } |
| 817 | 801 |
| 818 void ArcAuthService::StartLso() { | 802 void ArcAuthService::StartLso() { |
| 819 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 803 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 820 | 804 |
| 821 DCHECK(arc_bridge_service()->stopped()); | 805 DCHECK(arc_bridge_service()->stopped()); |
| 822 SetState(State::ANDROID_MANAGEMENT_CHECK); | 806 SetState(State::ANDROID_MANAGEMENT_CHECK); |
| 823 PrepareContextForAuthCodeRequest(); | 807 PrepareContextForAuthCodeRequest(); |
| 824 } | 808 } |
| 825 | 809 |
| 826 void ArcAuthService::CancelAuthCode() { | 810 void ArcAuthService::CancelAuthCode() { |
| 827 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 811 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 828 | 812 |
| 829 if (state_ == State::NOT_INITIALIZED) { | 813 if (state_ == State::NOT_INITIALIZED) { |
| 830 NOTREACHED(); | 814 NOTREACHED(); |
| 831 return; | 815 return; |
| 832 } | 816 } |
| 833 | 817 |
| 834 // In case |state_| is ACTIVE, |ui_page_| can be START_PROGRESS (which means | 818 // In case |state_| is ACTIVE, |ui_page_| can be START_PROGRESS (which means |
| 835 // normal Arc booting) or ERROR or ERROR_WITH_FEEDBACK (in case Arc can not | 819 // normal Arc booting) or ERROR or ERROR_WITH_FEEDBACK (in case Arc can not |
| 836 // be started). If Arc is booting normally dont't stop it on progress close. | 820 // be started). If Arc is booting normally dont't stop it on progress close. |
| 837 if ((state_ != State::FETCHING_CODE && state_ != State::TERMS && | 821 if ((state_ != State::TERMS && state_ != State::ANDROID_MANAGEMENT_CHECK) && |
| 838 state_ != State::ANDROID_MANAGEMENT_CHECK) && | |
| 839 ui_page_ != ArcSupportHost::UIPage::ERROR && | 822 ui_page_ != ArcSupportHost::UIPage::ERROR && |
| 840 ui_page_ != ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) { | 823 ui_page_ != ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) { |
| 841 return; | 824 return; |
| 842 } | 825 } |
| 843 | 826 |
| 844 // Update UMA with user cancel only if error is not currently shown. | 827 // Update UMA with user cancel only if error is not currently shown. |
| 845 if (ui_page_ == ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) | 828 if (ui_page_ == ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) |
| 846 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); | 829 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); |
| 847 | 830 |
| 848 StopArc(); | 831 StopArc(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 904 ArcSupportHost::UIPage::ERROR, | 887 ArcSupportHost::UIPage::ERROR, |
| 905 l10n_util::GetStringUTF16(IDS_ARC_SIGN_IN_SERVICE_UNAVAILABLE_ERROR)); | 888 l10n_util::GetStringUTF16(IDS_ARC_SIGN_IN_SERVICE_UNAVAILABLE_ERROR)); |
| 906 return; | 889 return; |
| 907 } | 890 } |
| 908 | 891 |
| 909 SetState(State::TERMS); | 892 SetState(State::TERMS); |
| 910 ShowUI(ArcSupportHost::UIPage::TERMS, base::string16()); | 893 ShowUI(ArcSupportHost::UIPage::TERMS, base::string16()); |
| 911 } | 894 } |
| 912 | 895 |
| 913 void ArcAuthService::OnPrepareContextFailed() { | 896 void ArcAuthService::OnPrepareContextFailed() { |
| 914 DCHECK_EQ(state_, State::FETCHING_CODE); | |
|
hidehiko
2016/11/10 06:49:28
NOTE: This was actually wrong. This could be ACTIV
| |
| 915 | |
| 916 ShutdownBridgeAndShowUI( | 897 ShutdownBridgeAndShowUI( |
| 917 ArcSupportHost::UIPage::ERROR, | 898 ArcSupportHost::UIPage::ERROR, |
| 918 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); | 899 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); |
| 919 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 900 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 920 } | 901 } |
| 921 | 902 |
| 922 void ArcAuthService::OnAuthCodeSuccess(const std::string& auth_code) { | 903 void ArcAuthService::OnAuthCodeSuccess(const std::string& auth_code) { |
| 923 SetAuthCodeAndStartArc(auth_code); | 904 OnAuthCodeObtained(auth_code); |
| 924 } | 905 } |
| 925 | 906 |
| 926 void ArcAuthService::OnAuthCodeFailed() { | 907 void ArcAuthService::OnAuthCodeFailed() { |
| 927 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 908 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 928 DCHECK_EQ(state_, State::FETCHING_CODE); | |
|
hidehiko
2016/11/10 06:49:28
Ditto.
| |
| 929 ShutdownBridgeAndShowUI( | 909 ShutdownBridgeAndShowUI( |
| 930 ArcSupportHost::UIPage::ERROR, | 910 ArcSupportHost::UIPage::ERROR, |
| 931 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); | 911 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); |
| 932 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 912 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 933 } | 913 } |
| 934 | 914 |
| 935 void ArcAuthService::StartArcAndroidManagementCheck() { | 915 void ArcAuthService::StartArcAndroidManagementCheck() { |
| 936 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 916 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 937 DCHECK(arc_bridge_service()->stopped()); | 917 DCHECK(arc_bridge_service()->stopped()); |
| 938 SetState(State::ANDROID_MANAGEMENT_CHECK); | 918 SetState(State::ANDROID_MANAGEMENT_CHECK); |
| 939 | 919 |
| 940 android_management_checker_.reset(new ArcAndroidManagementChecker( | 920 android_management_checker_.reset(new ArcAndroidManagementChecker( |
| 941 profile_, context_->token_service(), context_->account_id(), | 921 profile_, context_->token_service(), context_->account_id(), |
| 942 false /* retry_on_error */)); | 922 false /* retry_on_error */)); |
| 943 android_management_checker_->StartCheck( | 923 android_management_checker_->StartCheck( |
| 944 base::Bind(&ArcAuthService::OnAndroidManagementChecked, | 924 base::Bind(&ArcAuthService::OnAndroidManagementChecked, |
| 945 weak_ptr_factory_.GetWeakPtr())); | 925 weak_ptr_factory_.GetWeakPtr())); |
| 946 } | 926 } |
| 947 | 927 |
| 948 void ArcAuthService::OnAndroidManagementChecked( | 928 void ArcAuthService::OnAndroidManagementChecked( |
| 949 policy::AndroidManagementClient::Result result) { | 929 policy::AndroidManagementClient::Result result) { |
| 950 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 930 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 951 DCHECK_EQ(state_, State::ANDROID_MANAGEMENT_CHECK); | 931 DCHECK_EQ(state_, State::ANDROID_MANAGEMENT_CHECK); |
| 952 | 932 |
| 953 switch (result) { | 933 switch (result) { |
| 954 case policy::AndroidManagementClient::Result::UNMANAGED: | 934 case policy::AndroidManagementClient::Result::UNMANAGED: |
| 955 if (IsOptInVerificationDisabled()) { | 935 arc_sign_in_timer_.Start(FROM_HERE, kArcSignInTimeout, |
|
Luis Héctor Chávez
2016/11/10 23:58:20
|sign_in_time_| should always be updated in tandem
hidehiko
2016/11/14 11:29:31
Good catch. Done.
| |
| 956 StartArc(); | 936 base::Bind(&ArcAuthService::OnArcSignInTimeout, |
| 957 } else { | 937 weak_ptr_factory_.GetWeakPtr())); |
| 958 // TODO(hidehiko): Merge this prefetching into re-auth case. | 938 StartArc(); |
| 959 SetState(State::FETCHING_CODE); | |
| 960 PrepareContextForAuthCodeRequest(); | |
| 961 } | |
| 962 break; | 939 break; |
| 963 case policy::AndroidManagementClient::Result::MANAGED: | 940 case policy::AndroidManagementClient::Result::MANAGED: |
| 964 ShutdownBridgeAndShowUI( | 941 ShutdownBridgeAndShowUI( |
| 965 ArcSupportHost::UIPage::ERROR, | 942 ArcSupportHost::UIPage::ERROR, |
| 966 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR)); | 943 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR)); |
| 967 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); | 944 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); |
| 968 break; | 945 break; |
| 969 case policy::AndroidManagementClient::Result::ERROR: | 946 case policy::AndroidManagementClient::Result::ERROR: |
| 970 ShutdownBridgeAndShowUI( | 947 ShutdownBridgeAndShowUI( |
| 971 ArcSupportHost::UIPage::ERROR, | 948 ArcSupportHost::UIPage::ERROR, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1024 // This is ARC support's UI event callback, so this is called only when | 1001 // This is ARC support's UI event callback, so this is called only when |
| 1025 // the UI is visible. The condition to open the UI is | 1002 // the UI is visible. The condition to open the UI is |
| 1026 // !g_disable_ui_for_testing && !IsOptInVerificationDisabled() (see ShowUI()) | 1003 // !g_disable_ui_for_testing && !IsOptInVerificationDisabled() (see ShowUI()) |
| 1027 // and in the case, preference_handler_ should be always created (see | 1004 // and in the case, preference_handler_ should be always created (see |
| 1028 // OnPrimaryUserProfilePrepared()), | 1005 // OnPrimaryUserProfilePrepared()), |
| 1029 // TODO(hidehiko): Simplify the logic with the code restructuring. | 1006 // TODO(hidehiko): Simplify the logic with the code restructuring. |
| 1030 DCHECK(preference_handler_); | 1007 DCHECK(preference_handler_); |
| 1031 preference_handler_->EnableMetrics(is_metrics_enabled); | 1008 preference_handler_->EnableMetrics(is_metrics_enabled); |
| 1032 preference_handler_->EnableBackupRestore(is_backup_and_restore_enabled); | 1009 preference_handler_->EnableBackupRestore(is_backup_and_restore_enabled); |
| 1033 preference_handler_->EnableLocationService(is_location_service_enabled); | 1010 preference_handler_->EnableLocationService(is_location_service_enabled); |
| 1011 SetUIPage(ArcSupportHost::UIPage::START_PROGRESS, base::string16()); | |
| 1034 StartArcAndroidManagementCheck(); | 1012 StartArcAndroidManagementCheck(); |
| 1035 } | 1013 } |
| 1036 | 1014 |
| 1037 void ArcAuthService::OnAuthSucceeded(const std::string& auth_code) { | 1015 void ArcAuthService::OnAuthSucceeded(const std::string& auth_code) { |
| 1038 SetAuthCodeAndStartArc(auth_code); | 1016 OnAuthCodeObtained(auth_code); |
| 1039 } | 1017 } |
| 1040 | 1018 |
| 1041 void ArcAuthService::OnRetryClicked() { | 1019 void ArcAuthService::OnRetryClicked() { |
| 1042 UpdateOptInActionUMA(OptInActionType::RETRY); | 1020 UpdateOptInActionUMA(OptInActionType::RETRY); |
| 1043 // ERROR_WITH_FEEDBACK is set in OnSignInFailed(). In the case, we postpone | 1021 // ERROR_WITH_FEEDBACK is set in OnSignInFailed(). In the case, we postpone |
| 1044 // to stop the ARC to obtain the internal state. | 1022 // to stop the ARC to obtain the internal state. |
| 1045 // Here, on retry, stop it. | 1023 // Here, on retry, stop it. |
| 1046 if (ui_page_ == ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) | 1024 if (ui_page_ == ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) |
| 1047 ShutdownBridge(); | 1025 ShutdownBridge(); |
| 1048 | 1026 |
| 1049 switch (state_) { | 1027 switch (state_) { |
| 1050 case State::NOT_INITIALIZED: | 1028 case State::NOT_INITIALIZED: |
| 1051 NOTREACHED(); | 1029 NOTREACHED(); |
| 1052 break; | 1030 break; |
| 1053 case State::STOPPED: | 1031 case State::STOPPED: |
| 1054 case State::TERMS: | 1032 case State::TERMS: |
| 1055 ShowUI(ArcSupportHost::UIPage::TERMS, base::string16()); | 1033 ShowUI(ArcSupportHost::UIPage::TERMS, base::string16()); |
| 1056 break; | 1034 break; |
| 1057 case State::ANDROID_MANAGEMENT_CHECK: | 1035 case State::ANDROID_MANAGEMENT_CHECK: |
| 1058 StartArcAndroidManagementCheck(); | 1036 StartArcAndroidManagementCheck(); |
| 1059 break; | 1037 break; |
| 1060 case State::FETCHING_CODE: | |
| 1061 case State::ACTIVE: | 1038 case State::ACTIVE: |
| 1062 PrepareContextForAuthCodeRequest(); | 1039 SetUIPage(ArcSupportHost::UIPage::START_PROGRESS, base::string16()); |
| 1040 if (state_ != State::STOPPED) { | |
|
Luis Héctor Chávez
2016/11/10 23:58:20
Shouldn't this be always true? (|state_| should be
hidehiko
2016/11/14 11:29:31
Unfortunately, there is a case this triggers. Comm
hidehiko
2016/11/14 16:57:00
Oops, no. I was misunderstanding, and my test cove
| |
| 1041 PrepareContextForAuthCodeRequest(); | |
| 1042 } else if (!arc_bridge_service()->stopped() || | |
| 1043 arc_data_is_being_removed_) { | |
| 1044 reenable_arc_ = true; | |
| 1045 } else { | |
| 1046 StartArc(); | |
| 1047 } | |
| 1063 break; | 1048 break; |
| 1064 } | 1049 } |
| 1065 } | 1050 } |
| 1066 | 1051 |
| 1067 void ArcAuthService::OnSendFeedbackClicked() { | 1052 void ArcAuthService::OnSendFeedbackClicked() { |
| 1068 chrome::OpenFeedbackDialog(nullptr); | 1053 chrome::OpenFeedbackDialog(nullptr); |
| 1069 } | 1054 } |
| 1070 | 1055 |
| 1071 void ArcAuthService::OnMetricsModeChanged(bool enabled, bool managed) { | 1056 void ArcAuthService::OnMetricsModeChanged(bool enabled, bool managed) { |
| 1072 if (!support_host_) | 1057 if (!support_host_) |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 1089 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { | 1074 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { |
| 1090 switch (state) { | 1075 switch (state) { |
| 1091 case ArcAuthService::State::NOT_INITIALIZED: | 1076 case ArcAuthService::State::NOT_INITIALIZED: |
| 1092 return os << "NOT_INITIALIZED"; | 1077 return os << "NOT_INITIALIZED"; |
| 1093 case ArcAuthService::State::STOPPED: | 1078 case ArcAuthService::State::STOPPED: |
| 1094 return os << "STOPPED"; | 1079 return os << "STOPPED"; |
| 1095 case ArcAuthService::State::TERMS: | 1080 case ArcAuthService::State::TERMS: |
| 1096 return os << "TERMS"; | 1081 return os << "TERMS"; |
| 1097 case ArcAuthService::State::ANDROID_MANAGEMENT_CHECK: | 1082 case ArcAuthService::State::ANDROID_MANAGEMENT_CHECK: |
| 1098 return os << "ANDROID_MANAGEMENT_CHECK"; | 1083 return os << "ANDROID_MANAGEMENT_CHECK"; |
| 1099 case ArcAuthService::State::FETCHING_CODE: | |
| 1100 return os << "FETCHING_CODE"; | |
| 1101 case ArcAuthService::State::ACTIVE: | 1084 case ArcAuthService::State::ACTIVE: |
| 1102 return os << "ACTIVE"; | 1085 return os << "ACTIVE"; |
| 1103 default: | 1086 default: |
| 1104 NOTREACHED(); | 1087 NOTREACHED(); |
| 1105 return os; | 1088 return os; |
| 1106 } | 1089 } |
| 1107 } | 1090 } |
| 1108 | 1091 |
| 1109 } // namespace arc | 1092 } // namespace arc |
| OLD | NEW |