Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(241)

Side by Side Diff: chrome/browser/chromeos/arc/arc_auth_service.cc

Issue 2490093002: Migrate opt-in auth flow to re-auth flow. (Closed)
Patch Set: rebase Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 298
299 if (clear_required_) { 299 if (clear_required_) {
300 // This should be always true, but just in case as this is looked at 300 // This should be always true, but just in case as this is looked at
301 // inside RemoveArcData() at first. 301 // inside RemoveArcData() at first.
302 DCHECK(arc_bridge_service()->stopped()); 302 DCHECK(arc_bridge_service()->stopped());
303 RemoveArcData(); 303 RemoveArcData();
304 } else { 304 } else {
305 // To support special "Stop and enable ARC" procedure for enterprise, 305 // To support special "Stop and enable ARC" procedure for enterprise,
306 // here call OnArcDataRemoved(true) as if the data removal is successfully 306 // here call OnArcDataRemoved(true) as if the data removal is successfully
307 // done. 307 // done.
308 // TODO(hidehiko): Restructure the code. 308 // TODO(hidehiko): Restructure the code. crbug.com/665316
309 OnArcDataRemoved(true); 309 base::ThreadTaskRunnerHandle::Get()->PostTask(
310 FROM_HERE, base::Bind(&ArcAuthService::OnArcDataRemoved,
311 weak_ptr_factory_.GetWeakPtr(), true));
310 } 312 }
311 } 313 }
312 314
313 void ArcAuthService::RemoveArcData() { 315 void ArcAuthService::RemoveArcData() {
314 if (!arc_bridge_service()->stopped()) { 316 if (!arc_bridge_service()->stopped()) {
315 // 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,
316 // then session manager should remove the data. 318 // then session manager should remove the data.
317 clear_required_ = true; 319 clear_required_ = true;
318 return; 320 return;
319 } 321 }
(...skipping 16 matching lines...) Expand all
336 if (!reenable_arc_) 338 if (!reenable_arc_)
337 return; 339 return;
338 340
339 // Restart ARC anyway. Let the enterprise reporting instance decide whether 341 // Restart ARC anyway. Let the enterprise reporting instance decide whether
340 // the ARC user data wipe is still required or not. 342 // the ARC user data wipe is still required or not.
341 reenable_arc_ = false; 343 reenable_arc_ = false;
342 VLOG(1) << "Reenable ARC"; 344 VLOG(1) << "Reenable ARC";
343 EnableArc(); 345 EnableArc();
344 } 346 }
345 347
346 std::string ArcAuthService::GetAndResetAuthCode() {
347 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
348 std::string auth_code;
349 auth_code_.swap(auth_code);
350 return auth_code;
351 }
352
353 void ArcAuthService::GetAuthCodeDeprecated0( 348 void ArcAuthService::GetAuthCodeDeprecated0(
354 const GetAuthCodeDeprecated0Callback& callback) { 349 const GetAuthCodeDeprecated0Callback& callback) {
355 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 350 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
356 NOTREACHED() << "GetAuthCodeDeprecated0() should no longer be callable"; 351 NOTREACHED() << "GetAuthCodeDeprecated0() should no longer be callable";
357 } 352 }
358 353
359 void ArcAuthService::GetAuthCodeDeprecated( 354 void ArcAuthService::GetAuthCodeDeprecated(
360 const GetAuthCodeDeprecatedCallback& callback) { 355 const GetAuthCodeDeprecatedCallback& callback) {
361 // For robot account we must use RequestAccountInfo because it allows 356 // For robot account we must use RequestAccountInfo because it allows
362 // to specify account type. 357 // to specify account type.
(...skipping 23 matching lines...) Expand all
386 instance->OnAccountInfoReady(std::move(account_info)); 381 instance->OnAccountInfoReady(std::move(account_info));
387 } 382 }
388 383
389 void ArcAuthService::RequestAccountInfoInternal( 384 void ArcAuthService::RequestAccountInfoInternal(
390 std::unique_ptr<ArcAuthService::AccountInfoNotifier> 385 std::unique_ptr<ArcAuthService::AccountInfoNotifier>
391 account_info_notifier) { 386 account_info_notifier) {
392 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 387 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
393 // No other auth code-related operation may be in progress. 388 // No other auth code-related operation may be in progress.
394 DCHECK(!account_info_notifier_); 389 DCHECK(!account_info_notifier_);
395 390
396 const std::string auth_code = GetAndResetAuthCode(); 391 if (IsOptInVerificationDisabled()) {
397 const bool is_enforced = !IsOptInVerificationDisabled(); 392 account_info_notifier->Notify(false /* = is_enforced */, std::string(),
398 if (!auth_code.empty() || !is_enforced) { 393 GetAccountType(),
399 account_info_notifier->Notify(is_enforced, auth_code, GetAccountType(),
400 policy_util::IsAccountManaged(profile_)); 394 policy_util::IsAccountManaged(profile_));
401 return; 395 return;
402 } 396 }
403 397
404 account_info_notifier_ = std::move(account_info_notifier); 398 account_info_notifier_ = std::move(account_info_notifier);
405 399
406 if (IsArcKioskMode()) { 400 if (IsArcKioskMode()) {
407 arc_robot_auth_.reset(new ArcRobotAuth()); 401 arc_robot_auth_.reset(new ArcRobotAuth());
408 arc_robot_auth_->FetchRobotAuthCode( 402 arc_robot_auth_->FetchRobotAuthCode(
409 base::Bind(&ArcAuthService::OnRobotAuthCodeFetched, 403 base::Bind(&ArcAuthService::OnRobotAuthCodeFetched,
(...skipping 29 matching lines...) Expand all
439 return account_info_notifier_ != nullptr; 433 return account_info_notifier_ != nullptr;
440 } 434 }
441 435
442 void ArcAuthService::PrepareContextForAuthCodeRequest() { 436 void ArcAuthService::PrepareContextForAuthCodeRequest() {
443 // Requesting auth code on demand happens in following cases: 437 // Requesting auth code on demand happens in following cases:
444 // 1. To handle account password revoke. 438 // 1. To handle account password revoke.
445 // 2. In case Arc is activated in OOBE flow. 439 // 2. In case Arc is activated in OOBE flow.
446 // 3. For any other state on Android side that leads device appears in 440 // 3. For any other state on Android side that leads device appears in
447 // non-signed state. 441 // non-signed state.
448 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 442 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
449 DCHECK(state_ == State::FETCHING_CODE || state_ == State::ACTIVE); 443 DCHECK(state_ == State::ACTIVE);
450 if (state_ == State::ACTIVE) 444 DCHECK(IsAuthCodeRequest());
451 DCHECK(IsAuthCodeRequest());
452 DCHECK(!IsArcKioskMode()); 445 DCHECK(!IsArcKioskMode());
453 context_->PrepareContext(); 446 context_->PrepareContext();
454 } 447 }
455 448
456 void ArcAuthService::OnSignInComplete() { 449 void ArcAuthService::OnSignInComplete() {
457 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 450 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
458 DCHECK_EQ(state_, State::ACTIVE); 451 DCHECK_EQ(state_, State::ACTIVE);
459 452
460 if (!sign_in_time_.is_null()) { 453 if (!sign_in_time_.is_null()) {
461 arc_sign_in_timer_.Stop(); 454 arc_sign_in_timer_.Stop();
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 observer.OnOptInEnabled(arc_enabled); 719 observer.OnOptInEnabled(arc_enabled);
727 720
728 if (!arc_enabled) { 721 if (!arc_enabled) {
729 StopArc(); 722 StopArc();
730 RemoveArcData(); 723 RemoveArcData();
731 return; 724 return;
732 } 725 }
733 726
734 if (state_ == State::ACTIVE) 727 if (state_ == State::ACTIVE)
735 return; 728 return;
736 CloseUI();
737 auth_code_.clear();
738 729
739 // In case UI is disabled we assume that ARC is opted-in. For ARC Kiosk we 730 // In case UI is disabled we assume that ARC is opted-in. For ARC Kiosk we
740 // skip ToS because it is very likely that near the device there will be 731 // skip ToS because it is very likely that near the device there will be
741 // no one who is eligible to accept them. We skip if Android management check 732 // no one who is eligible to accept them. We skip if Android management check
742 // because there are no managed human users for Kiosk exist. 733 // because there are no managed human users for Kiosk exist.
743 if (IsOptInVerificationDisabled() || IsArcKioskMode()) { 734 if (IsOptInVerificationDisabled() || IsArcKioskMode()) {
744 // Automatically accept terms in kiosk mode. This is not required for 735 // Automatically accept terms in kiosk mode. This is not required for
745 // IsOptInVerificationDisabled mode because in last case it may cause 736 // IsOptInVerificationDisabled mode because in last case it may cause
746 // a privacy issue on next run without this flag set. 737 // a privacy issue on next run without this flag set.
747 if (IsArcKioskMode()) 738 if (IsArcKioskMode())
748 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); 739 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true);
749 StartArc(); 740 StartArc();
750 return; 741 return;
751 } 742 }
752 743
753 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { 744 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) {
754 if (profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { 745 if (profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) {
755 // Need pre-fetch auth code and start Arc. 746 StartArc();
756 SetState(State::FETCHING_CODE);
757 PrepareContextForAuthCodeRequest();
758 } else { 747 } else {
759 // Need pre-fetch auth code and show OptIn UI if needed. 748 // Need pre-fetch auth code and show OptIn UI if needed.
760 StartUI(); 749 StartUI();
761 } 750 }
762 } else { 751 } else {
763 // Ready to start Arc, but check Android management in parallel. 752 // Ready to start Arc, but check Android management in parallel.
764 StartArc(); 753 StartArc();
765 // Note: Because the callback may be called in synchronous way (i.e. called 754 // Note: Because the callback may be called in synchronous way (i.e. called
766 // on the same stack), StartCheck() needs to be called *after* StartArc(). 755 // on the same stack), StartCheck() needs to be called *after* StartArc().
767 // Otherwise, DisableArc() which may be called in 756 // Otherwise, DisableArc() which may be called in
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 reenable_arc_ = true; 825 reenable_arc_ = true;
837 StopArc(); 826 StopArc();
838 } 827 }
839 828
840 void ArcAuthService::StartArc() { 829 void ArcAuthService::StartArc() {
841 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 830 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
842 arc_bridge_service()->RequestStart(); 831 arc_bridge_service()->RequestStart();
843 SetState(State::ACTIVE); 832 SetState(State::ACTIVE);
844 } 833 }
845 834
846 void ArcAuthService::SetAuthCodeAndStartArc(const std::string& auth_code) { 835 void ArcAuthService::OnAuthCodeObtained(const std::string& auth_code) {
847 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 836 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
848 DCHECK(!auth_code.empty()); 837 DCHECK(!auth_code.empty());
849 838
850 if (IsAuthCodeRequest()) { 839 account_info_notifier_->Notify(!IsOptInVerificationDisabled(), auth_code,
851 account_info_notifier_->Notify(!IsOptInVerificationDisabled(), auth_code, 840 GetAccountType(),
852 GetAccountType(), 841 policy_util::IsAccountManaged(profile_));
853 policy_util::IsAccountManaged(profile_)); 842 account_info_notifier_.reset();
854 account_info_notifier_.reset();
855 return;
856 }
857
858 if (state_ != State::SHOWING_TERMS_OF_SERVICE &&
859 state_ != State::CHECKING_ANDROID_MANAGEMENT &&
860 state_ != State::FETCHING_CODE) {
861 ShutdownBridgeAndCloseUI();
862 return;
863 }
864
865 sign_in_time_ = base::Time::Now();
866 VLOG(1) << "Starting ARC for first sign in.";
867
868 SetUIPage(ArcSupportHost::UIPage::START_PROGRESS, base::string16());
869 ShutdownBridge();
870 auth_code_ = auth_code;
871 arc_sign_in_timer_.Start(FROM_HERE, kArcSignInTimeout,
872 base::Bind(&ArcAuthService::OnArcSignInTimeout,
873 weak_ptr_factory_.GetWeakPtr()));
874 StartArc();
875 } 843 }
876 844
877 void ArcAuthService::OnArcSignInTimeout() { 845 void ArcAuthService::OnArcSignInTimeout() {
878 LOG(ERROR) << "Timed out waiting for first sign in."; 846 LOG(ERROR) << "Timed out waiting for first sign in.";
879 OnSignInFailedInternal(ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT); 847 OnSignInFailedInternal(ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT);
880 } 848 }
881 849
882 void ArcAuthService::CancelAuthCode() { 850 void ArcAuthService::CancelAuthCode() {
883 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 851 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
884 852
885 if (state_ == State::NOT_INITIALIZED) { 853 if (state_ == State::NOT_INITIALIZED) {
886 NOTREACHED(); 854 NOTREACHED();
887 return; 855 return;
888 } 856 }
889 857
890 // In case |state_| is ACTIVE, |ui_page_| can be START_PROGRESS (which means 858 // In case |state_| is ACTIVE, |ui_page_| can be START_PROGRESS (which means
891 // normal Arc booting) or ERROR or ERROR_WITH_FEEDBACK (in case Arc can not 859 // normal Arc booting) or ERROR or ERROR_WITH_FEEDBACK (in case Arc can not
892 // be started). If Arc is booting normally dont't stop it on progress close. 860 // be started). If Arc is booting normally dont't stop it on progress close.
893 if ((state_ != State::FETCHING_CODE && 861 if ((state_ != State::SHOWING_TERMS_OF_SERVICE &&
894 state_ != State::SHOWING_TERMS_OF_SERVICE &&
895 state_ != State::CHECKING_ANDROID_MANAGEMENT) && 862 state_ != State::CHECKING_ANDROID_MANAGEMENT) &&
896 ui_page_ != ArcSupportHost::UIPage::ERROR && 863 ui_page_ != ArcSupportHost::UIPage::ERROR &&
897 ui_page_ != ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) { 864 ui_page_ != ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) {
898 return; 865 return;
899 } 866 }
900 867
901 // Update UMA with user cancel only if error is not currently shown. 868 // Update UMA with user cancel only if error is not currently shown.
902 if (ui_page_ != ArcSupportHost::UIPage::NO_PAGE && 869 if (ui_page_ != ArcSupportHost::UIPage::NO_PAGE &&
903 ui_page_ != ArcSupportHost::UIPage::ERROR && 870 ui_page_ != ArcSupportHost::UIPage::ERROR &&
904 ui_page_ != ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) { 871 ui_page_ != ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) {
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 ArcSupportHost::UIPage::ERROR, 931 ArcSupportHost::UIPage::ERROR,
965 l10n_util::GetStringUTF16(IDS_ARC_SIGN_IN_SERVICE_UNAVAILABLE_ERROR)); 932 l10n_util::GetStringUTF16(IDS_ARC_SIGN_IN_SERVICE_UNAVAILABLE_ERROR));
966 return; 933 return;
967 } 934 }
968 935
969 SetState(State::SHOWING_TERMS_OF_SERVICE); 936 SetState(State::SHOWING_TERMS_OF_SERVICE);
970 ShowUI(ArcSupportHost::UIPage::TERMS, base::string16()); 937 ShowUI(ArcSupportHost::UIPage::TERMS, base::string16());
971 } 938 }
972 939
973 void ArcAuthService::OnPrepareContextFailed() { 940 void ArcAuthService::OnPrepareContextFailed() {
974 DCHECK_EQ(state_, State::FETCHING_CODE);
975
976 ShutdownBridgeAndShowUI( 941 ShutdownBridgeAndShowUI(
977 ArcSupportHost::UIPage::ERROR, 942 ArcSupportHost::UIPage::ERROR,
978 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); 943 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR));
979 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); 944 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR);
980 } 945 }
981 946
982 void ArcAuthService::OnAuthCodeSuccess(const std::string& auth_code) { 947 void ArcAuthService::OnAuthCodeSuccess(const std::string& auth_code) {
983 SetAuthCodeAndStartArc(auth_code); 948 OnAuthCodeObtained(auth_code);
984 } 949 }
985 950
986 void ArcAuthService::OnAuthCodeFailed() { 951 void ArcAuthService::OnAuthCodeFailed() {
987 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 952 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
988 DCHECK_EQ(state_, State::FETCHING_CODE);
989 ShutdownBridgeAndShowUI( 953 ShutdownBridgeAndShowUI(
990 ArcSupportHost::UIPage::ERROR, 954 ArcSupportHost::UIPage::ERROR,
991 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); 955 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR));
992 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); 956 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR);
993 } 957 }
994 958
995 void ArcAuthService::StartArcAndroidManagementCheck() { 959 void ArcAuthService::StartArcAndroidManagementCheck() {
996 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 960 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
997 DCHECK(arc_bridge_service()->stopped()); 961 DCHECK(arc_bridge_service()->stopped());
998 DCHECK(state_ == State::SHOWING_TERMS_OF_SERVICE || 962 DCHECK(state_ == State::SHOWING_TERMS_OF_SERVICE ||
999 state_ == State::CHECKING_ANDROID_MANAGEMENT); 963 state_ == State::CHECKING_ANDROID_MANAGEMENT);
1000 SetState(State::CHECKING_ANDROID_MANAGEMENT); 964 SetState(State::CHECKING_ANDROID_MANAGEMENT);
1001 965
1002 android_management_checker_.reset(new ArcAndroidManagementChecker( 966 android_management_checker_.reset(new ArcAndroidManagementChecker(
1003 profile_, context_->token_service(), context_->account_id(), 967 profile_, context_->token_service(), context_->account_id(),
1004 false /* retry_on_error */)); 968 false /* retry_on_error */));
1005 android_management_checker_->StartCheck( 969 android_management_checker_->StartCheck(
1006 base::Bind(&ArcAuthService::OnAndroidManagementChecked, 970 base::Bind(&ArcAuthService::OnAndroidManagementChecked,
1007 weak_ptr_factory_.GetWeakPtr())); 971 weak_ptr_factory_.GetWeakPtr()));
1008 } 972 }
1009 973
1010 void ArcAuthService::OnAndroidManagementChecked( 974 void ArcAuthService::OnAndroidManagementChecked(
1011 policy::AndroidManagementClient::Result result) { 975 policy::AndroidManagementClient::Result result) {
1012 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 976 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
1013 DCHECK_EQ(state_, State::CHECKING_ANDROID_MANAGEMENT); 977 DCHECK_EQ(state_, State::CHECKING_ANDROID_MANAGEMENT);
1014 978
1015 switch (result) { 979 switch (result) {
1016 case policy::AndroidManagementClient::Result::UNMANAGED: 980 case policy::AndroidManagementClient::Result::UNMANAGED:
1017 if (IsOptInVerificationDisabled()) { 981 VLOG(1) << "Starting ARC for first sign in.";
1018 StartArc(); 982 sign_in_time_ = base::Time::Now();
1019 } else { 983 arc_sign_in_timer_.Start(FROM_HERE, kArcSignInTimeout,
1020 // TODO(hidehiko): Merge this prefetching into re-auth case. 984 base::Bind(&ArcAuthService::OnArcSignInTimeout,
1021 SetState(State::FETCHING_CODE); 985 weak_ptr_factory_.GetWeakPtr()));
1022 PrepareContextForAuthCodeRequest(); 986 StartArc();
1023 }
1024 break; 987 break;
1025 case policy::AndroidManagementClient::Result::MANAGED: 988 case policy::AndroidManagementClient::Result::MANAGED:
1026 ShutdownBridgeAndShowUI( 989 ShutdownBridgeAndShowUI(
1027 ArcSupportHost::UIPage::ERROR, 990 ArcSupportHost::UIPage::ERROR,
1028 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR)); 991 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR));
1029 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); 992 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED);
1030 break; 993 break;
1031 case policy::AndroidManagementClient::Result::ERROR: 994 case policy::AndroidManagementClient::Result::ERROR:
1032 ShutdownBridgeAndShowUI( 995 ShutdownBridgeAndShowUI(
1033 ArcSupportHost::UIPage::ERROR, 996 ArcSupportHost::UIPage::ERROR,
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 // This is ARC support's UI event callback, so this is called only when 1049 // This is ARC support's UI event callback, so this is called only when
1087 // the UI is visible. The condition to open the UI is 1050 // the UI is visible. The condition to open the UI is
1088 // !g_disable_ui_for_testing && !IsOptInVerificationDisabled() (see ShowUI()) 1051 // !g_disable_ui_for_testing && !IsOptInVerificationDisabled() (see ShowUI())
1089 // and in the case, preference_handler_ should be always created (see 1052 // and in the case, preference_handler_ should be always created (see
1090 // OnPrimaryUserProfilePrepared()), 1053 // OnPrimaryUserProfilePrepared()),
1091 // TODO(hidehiko): Simplify the logic with the code restructuring. 1054 // TODO(hidehiko): Simplify the logic with the code restructuring.
1092 DCHECK(preference_handler_); 1055 DCHECK(preference_handler_);
1093 preference_handler_->EnableMetrics(is_metrics_enabled); 1056 preference_handler_->EnableMetrics(is_metrics_enabled);
1094 preference_handler_->EnableBackupRestore(is_backup_and_restore_enabled); 1057 preference_handler_->EnableBackupRestore(is_backup_and_restore_enabled);
1095 preference_handler_->EnableLocationService(is_location_service_enabled); 1058 preference_handler_->EnableLocationService(is_location_service_enabled);
1059 SetUIPage(ArcSupportHost::UIPage::START_PROGRESS, base::string16());
1096 StartArcAndroidManagementCheck(); 1060 StartArcAndroidManagementCheck();
1097 } 1061 }
1098 1062
1099 void ArcAuthService::OnAuthSucceeded(const std::string& auth_code) { 1063 void ArcAuthService::OnAuthSucceeded(const std::string& auth_code) {
1100 SetAuthCodeAndStartArc(auth_code); 1064 OnAuthCodeObtained(auth_code);
1101 } 1065 }
1102 1066
1103 void ArcAuthService::OnRetryClicked() { 1067 void ArcAuthService::OnRetryClicked() {
1104 UpdateOptInActionUMA(OptInActionType::RETRY); 1068 UpdateOptInActionUMA(OptInActionType::RETRY);
1105 // ERROR_WITH_FEEDBACK is set in OnSignInFailed(). In the case, we postpone 1069
1106 // to stop the ARC to obtain the internal state. 1070 // TODO(hidehiko): Simplify the retry logic.
1107 // Here, on retry, stop it. 1071 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) {
1108 if (ui_page_ == ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) 1072 // If the user has not yet agreed on Terms of Service, then show it.
1073 ShowUI(ArcSupportHost::UIPage::TERMS, base::string16());
1074 } else if (ui_page_ == ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) {
1075 // ERROR_WITH_FEEDBACK is set in OnSignInFailed(). In the case, stopping
1076 // ARC was postponed to contain its internal state into the report.
1077 // Here, on retry, stop it, then restart.
1078 DCHECK_EQ(State::ACTIVE, state_);
1079 SetUIPage(ArcSupportHost::UIPage::START_PROGRESS, base::string16());
1109 ShutdownBridge(); 1080 ShutdownBridge();
1110 1081 reenable_arc_ = true;
1111 switch (state_) { 1082 } else if (state_ == State::ACTIVE) {
1112 case State::NOT_INITIALIZED: 1083 // This happens when ARC support Chrome app reports an error on "Sign in"
1113 NOTREACHED(); 1084 // page.
1114 break; 1085 // TODO(hidehiko): Currently, due to the existing code structure, we need
1115 case State::STOPPED: 1086 // to call PrepareContextForAuthCodeRequest() always. However, to fetch
1116 case State::SHOWING_TERMS_OF_SERVICE: 1087 // an authtoken via LSO page, it is not necessary to call PrepareContext().
1117 ShowUI(ArcSupportHost::UIPage::TERMS, base::string16()); 1088 // Instead, it is possible to show LSO page, immediately.
1118 break; 1089 SetUIPage(ArcSupportHost::UIPage::START_PROGRESS, base::string16());
1119 case State::CHECKING_ANDROID_MANAGEMENT: 1090 PrepareContextForAuthCodeRequest();
1120 StartArcAndroidManagementCheck(); 1091 } else {
1121 break; 1092 // Otherwise, we restart ARC. Note: this is the first boot case.
1122 case State::FETCHING_CODE: 1093 // For second or later boot, either ERROR_WITH_FEEDBACK case or ACTIVE
1123 case State::ACTIVE: 1094 // case must hit.
1124 PrepareContextForAuthCodeRequest(); 1095 SetUIPage(ArcSupportHost::UIPage::START_PROGRESS, base::string16());
1125 break; 1096 StartArcAndroidManagementCheck();
1126 } 1097 }
1127 } 1098 }
1128 1099
1129 void ArcAuthService::OnSendFeedbackClicked() { 1100 void ArcAuthService::OnSendFeedbackClicked() {
1130 chrome::OpenFeedbackDialog(nullptr); 1101 chrome::OpenFeedbackDialog(nullptr);
1131 } 1102 }
1132 1103
1133 void ArcAuthService::OnMetricsModeChanged(bool enabled, bool managed) { 1104 void ArcAuthService::OnMetricsModeChanged(bool enabled, bool managed) {
1134 if (!support_host_) 1105 if (!support_host_)
1135 return; 1106 return;
(...skipping 15 matching lines...) Expand all
1151 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { 1122 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) {
1152 switch (state) { 1123 switch (state) {
1153 case ArcAuthService::State::NOT_INITIALIZED: 1124 case ArcAuthService::State::NOT_INITIALIZED:
1154 return os << "NOT_INITIALIZED"; 1125 return os << "NOT_INITIALIZED";
1155 case ArcAuthService::State::STOPPED: 1126 case ArcAuthService::State::STOPPED:
1156 return os << "STOPPED"; 1127 return os << "STOPPED";
1157 case ArcAuthService::State::SHOWING_TERMS_OF_SERVICE: 1128 case ArcAuthService::State::SHOWING_TERMS_OF_SERVICE:
1158 return os << "SHOWING_TERMS_OF_SERVICE"; 1129 return os << "SHOWING_TERMS_OF_SERVICE";
1159 case ArcAuthService::State::CHECKING_ANDROID_MANAGEMENT: 1130 case ArcAuthService::State::CHECKING_ANDROID_MANAGEMENT:
1160 return os << "CHECKING_ANDROID_MANAGEMENT"; 1131 return os << "CHECKING_ANDROID_MANAGEMENT";
1161 case ArcAuthService::State::FETCHING_CODE:
1162 return os << "FETCHING_CODE";
1163 case ArcAuthService::State::ACTIVE: 1132 case ArcAuthService::State::ACTIVE:
1164 return os << "ACTIVE"; 1133 return os << "ACTIVE";
1165 } 1134 }
1166 1135
1167 // Some compiler reports an error even if all values of an enum-class are 1136 // Some compiler reports an error even if all values of an enum-class are
1168 // covered indivisually in a switch statement. 1137 // covered indivisually in a switch statement.
1169 NOTREACHED(); 1138 NOTREACHED();
1170 return os; 1139 return os;
1171 } 1140 }
1172 1141
1173 } // namespace arc 1142 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_auth_service.h ('k') | chrome/browser/chromeos/arc/arc_auth_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698