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 325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 336 if (!reenable_arc_) | 336 if (!reenable_arc_) |
| 337 return; | 337 return; |
| 338 | 338 |
| 339 // Restart ARC anyway. Let the enterprise reporting instance decide whether | 339 // Restart ARC anyway. Let the enterprise reporting instance decide whether |
| 340 // the ARC user data wipe is still required or not. | 340 // the ARC user data wipe is still required or not. |
| 341 reenable_arc_ = false; | 341 reenable_arc_ = false; |
| 342 VLOG(1) << "Reenable ARC"; | 342 VLOG(1) << "Reenable ARC"; |
| 343 EnableArc(); | 343 EnableArc(); |
| 344 } | 344 } |
| 345 | 345 |
| 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( | 346 void ArcAuthService::GetAuthCodeDeprecated0( |
| 354 const GetAuthCodeDeprecated0Callback& callback) { | 347 const GetAuthCodeDeprecated0Callback& callback) { |
| 355 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 348 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 356 DCHECK(!IsOptInVerificationDisabled()); | 349 NOTREACHED() << "GetAuthCodeDeprecated0() should no longer be callable"; |
| 357 // For robot account we must use RequestAccountInfo because it allows to | 350 callback.Run(std::string()); |
| 358 // specify account type. | |
| 359 DCHECK(!IsArcKioskMode()); | |
| 360 callback.Run(GetAndResetAuthCode()); | |
| 361 } | 351 } |
| 362 | 352 |
| 363 void ArcAuthService::GetAuthCodeDeprecated( | 353 void ArcAuthService::GetAuthCodeDeprecated( |
| 364 const GetAuthCodeDeprecatedCallback& callback) { | 354 const GetAuthCodeDeprecatedCallback& callback) { |
| 365 // For robot account we must use RequestAccountInfo because it allows | 355 // For robot account we must use RequestAccountInfo because it allows |
| 366 // to specify account type. | 356 // to specify account type. |
| 367 DCHECK(!IsArcKioskMode()); | 357 DCHECK(!IsArcKioskMode()); |
| 368 RequestAccountInfoInternal( | 358 RequestAccountInfoInternal( |
| 369 base::MakeUnique<ArcAuthService::AccountInfoNotifier>(callback)); | 359 base::MakeUnique<ArcAuthService::AccountInfoNotifier>(callback)); |
| 370 } | 360 } |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 390 instance->OnAccountInfoReady(std::move(account_info)); | 380 instance->OnAccountInfoReady(std::move(account_info)); |
| 391 } | 381 } |
| 392 | 382 |
| 393 void ArcAuthService::RequestAccountInfoInternal( | 383 void ArcAuthService::RequestAccountInfoInternal( |
| 394 std::unique_ptr<ArcAuthService::AccountInfoNotifier> | 384 std::unique_ptr<ArcAuthService::AccountInfoNotifier> |
| 395 account_info_notifier) { | 385 account_info_notifier) { |
| 396 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 386 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 397 // No other auth code-related operation may be in progress. | 387 // No other auth code-related operation may be in progress. |
| 398 DCHECK(!account_info_notifier_); | 388 DCHECK(!account_info_notifier_); |
| 399 | 389 |
| 400 const std::string auth_code = GetAndResetAuthCode(); | 390 if (IsOptInVerificationDisabled()) { |
| 401 const bool is_enforced = !IsOptInVerificationDisabled(); | 391 account_info_notifier->Notify(false /* = is_enforced */, std::string(), |
| 402 if (!auth_code.empty() || !is_enforced) { | 392 GetAccountType(), |
| 403 account_info_notifier->Notify(is_enforced, auth_code, GetAccountType(), | |
| 404 policy_util::IsAccountManaged(profile_)); | 393 policy_util::IsAccountManaged(profile_)); |
| 405 return; | 394 return; |
| 406 } | 395 } |
| 407 | 396 |
| 408 account_info_notifier_ = std::move(account_info_notifier); | 397 account_info_notifier_ = std::move(account_info_notifier); |
| 409 | 398 |
| 410 if (IsArcKioskMode()) { | 399 if (IsArcKioskMode()) { |
| 411 arc_robot_auth_.reset(new ArcRobotAuth()); | 400 arc_robot_auth_.reset(new ArcRobotAuth()); |
| 412 arc_robot_auth_->FetchRobotAuthCode( | 401 arc_robot_auth_->FetchRobotAuthCode( |
| 413 base::Bind(&ArcAuthService::OnRobotAuthCodeFetched, | 402 base::Bind(&ArcAuthService::OnRobotAuthCodeFetched, |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 606 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( | 595 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( |
| 607 prefs::kArcEnabled, this); | 596 prefs::kArcEnabled, this); |
| 608 | 597 |
| 609 context_.reset(new ArcAuthContext(this, profile_)); | 598 context_.reset(new ArcAuthContext(this, profile_)); |
| 610 | 599 |
| 611 // In case UI is disabled we assume that ARC is opted-in. For ARC Kiosk we | 600 // In case UI is disabled we assume that ARC is opted-in. For ARC Kiosk we |
| 612 // skip ToS because it is very likely that near the device there will be | 601 // skip ToS because it is very likely that near the device there will be |
| 613 // no one who is eligible to accept them. We skip if Android management check | 602 // no one who is eligible to accept them. We skip if Android management check |
| 614 // because there are no managed human users for Kiosk exist. | 603 // because there are no managed human users for Kiosk exist. |
| 615 if (IsOptInVerificationDisabled() || IsArcKioskMode()) { | 604 if (IsOptInVerificationDisabled() || IsArcKioskMode()) { |
| 616 auth_code_.clear(); | |
| 617 StartArc(); | 605 StartArc(); |
| 618 return; | 606 return; |
| 619 } | 607 } |
| 620 | 608 |
| 621 if (!g_disable_ui_for_testing || | 609 if (!g_disable_ui_for_testing || |
| 622 g_enable_check_android_management_for_testing) { | 610 g_enable_check_android_management_for_testing) { |
| 623 ArcAndroidManagementChecker::StartClient(); | 611 ArcAndroidManagementChecker::StartClient(); |
| 624 } | 612 } |
| 625 pref_change_registrar_.Init(profile_->GetPrefs()); | 613 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 626 pref_change_registrar_.Add( | 614 pref_change_registrar_.Add( |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 738 | 726 |
| 739 if (!arc_enabled) { | 727 if (!arc_enabled) { |
| 740 StopArc(); | 728 StopArc(); |
| 741 RemoveArcData(); | 729 RemoveArcData(); |
| 742 return; | 730 return; |
| 743 } | 731 } |
| 744 | 732 |
| 745 if (state_ == State::ACTIVE) | 733 if (state_ == State::ACTIVE) |
| 746 return; | 734 return; |
| 747 CloseUI(); | 735 CloseUI(); |
| 748 auth_code_.clear(); | |
| 749 | 736 |
| 750 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { | 737 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { |
| 751 if (profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { | 738 if (profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { |
| 752 // Need pre-fetch auth code and start Arc. | 739 StartArc(); |
| 753 SetState(State::FETCHING_CODE); | |
| 754 PrepareContextForAuthCodeRequest(); | |
| 755 } else { | 740 } else { |
| 756 // Need pre-fetch auth code and show OptIn UI if needed. | 741 // Need pre-fetch auth code and show OptIn UI if needed. |
| 757 StartUI(); | 742 StartUI(); |
| 758 } | 743 } |
| 759 } else { | 744 } else { |
| 760 // Ready to start Arc, but check Android management in parallel. | 745 // Ready to start Arc, but check Android management in parallel. |
| 761 StartArc(); | 746 StartArc(); |
| 762 // Note: Because the callback may be called in synchronous way (i.e. called | 747 // Note: Because the callback may be called in synchronous way (i.e. called |
| 763 // on the same stack), StartCheck() needs to be called *after* StartArc(). | 748 // on the same stack), StartCheck() needs to be called *after* StartArc(). |
| 764 // Otherwise, DisableArc() which may be called in | 749 // Otherwise, DisableArc() which may be called in |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 833 reenable_arc_ = true; | 818 reenable_arc_ = true; |
| 834 StopArc(); | 819 StopArc(); |
| 835 } | 820 } |
| 836 | 821 |
| 837 void ArcAuthService::StartArc() { | 822 void ArcAuthService::StartArc() { |
| 838 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 823 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 839 arc_bridge_service()->RequestStart(); | 824 arc_bridge_service()->RequestStart(); |
| 840 SetState(State::ACTIVE); | 825 SetState(State::ACTIVE); |
| 841 } | 826 } |
| 842 | 827 |
| 843 void ArcAuthService::SetAuthCodeAndStartArc(const std::string& auth_code) { | 828 void ArcAuthService::OnAuthCodeObtained(const std::string& auth_code) { |
| 844 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 829 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 845 DCHECK(!auth_code.empty()); | 830 DCHECK(!auth_code.empty()); |
| 846 | 831 |
| 847 if (IsAuthCodeRequest()) { | 832 account_info_notifier_->Notify(!IsOptInVerificationDisabled(), auth_code, |
| 848 account_info_notifier_->Notify(!IsOptInVerificationDisabled(), auth_code, | 833 GetAccountType(), |
| 849 GetAccountType(), | 834 policy_util::IsAccountManaged(profile_)); |
| 850 policy_util::IsAccountManaged(profile_)); | 835 account_info_notifier_.reset(); |
| 851 account_info_notifier_.reset(); | |
| 852 return; | |
| 853 } | |
| 854 | |
| 855 if (state_ != State::SHOWING_TERMS_OF_SERVICE && | |
| 856 state_ != State::CHECKING_ANDROID_MANAGEMENT && | |
| 857 state_ != State::FETCHING_CODE) { | |
| 858 ShutdownBridgeAndCloseUI(); | |
| 859 return; | |
| 860 } | |
| 861 | |
| 862 sign_in_time_ = base::Time::Now(); | |
| 863 VLOG(1) << "Starting ARC for first sign in."; | |
| 864 | |
| 865 SetUIPage(ArcSupportHost::UIPage::START_PROGRESS, base::string16()); | |
| 866 ShutdownBridge(); | |
| 867 auth_code_ = auth_code; | |
| 868 arc_sign_in_timer_.Start(FROM_HERE, kArcSignInTimeout, | |
| 869 base::Bind(&ArcAuthService::OnArcSignInTimeout, | |
| 870 weak_ptr_factory_.GetWeakPtr())); | |
| 871 StartArc(); | |
| 872 } | 836 } |
| 873 | 837 |
| 874 void ArcAuthService::OnArcSignInTimeout() { | 838 void ArcAuthService::OnArcSignInTimeout() { |
| 875 LOG(ERROR) << "Timed out waiting for first sign in."; | 839 LOG(ERROR) << "Timed out waiting for first sign in."; |
| 876 OnSignInFailedInternal(ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT); | 840 OnSignInFailedInternal(ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT); |
| 877 } | 841 } |
| 878 | 842 |
| 879 void ArcAuthService::CancelAuthCode() { | 843 void ArcAuthService::CancelAuthCode() { |
| 880 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 844 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 881 | 845 |
| 882 if (state_ == State::NOT_INITIALIZED) { | 846 if (state_ == State::NOT_INITIALIZED) { |
| 883 NOTREACHED(); | 847 NOTREACHED(); |
| 884 return; | 848 return; |
| 885 } | 849 } |
| 886 | 850 |
| 887 // In case |state_| is ACTIVE, |ui_page_| can be START_PROGRESS (which means | 851 // In case |state_| is ACTIVE, |ui_page_| can be START_PROGRESS (which means |
| 888 // normal Arc booting) or ERROR or ERROR_WITH_FEEDBACK (in case Arc can not | 852 // normal Arc booting) or ERROR or ERROR_WITH_FEEDBACK (in case Arc can not |
| 889 // be started). If Arc is booting normally dont't stop it on progress close. | 853 // be started). If Arc is booting normally dont't stop it on progress close. |
| 890 if ((state_ != State::FETCHING_CODE && | 854 if ((state_ != State::SHOWING_TERMS_OF_SERVICE && |
| 891 state_ != State::SHOWING_TERMS_OF_SERVICE && | |
| 892 state_ != State::CHECKING_ANDROID_MANAGEMENT) && | 855 state_ != State::CHECKING_ANDROID_MANAGEMENT) && |
| 893 ui_page_ != ArcSupportHost::UIPage::ERROR && | 856 ui_page_ != ArcSupportHost::UIPage::ERROR && |
| 894 ui_page_ != ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) { | 857 ui_page_ != ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) { |
| 895 return; | 858 return; |
| 896 } | 859 } |
| 897 | 860 |
| 898 // Update UMA with user cancel only if error is not currently shown. | 861 // Update UMA with user cancel only if error is not currently shown. |
| 899 if (ui_page_ != ArcSupportHost::UIPage::NO_PAGE && | 862 if (ui_page_ != ArcSupportHost::UIPage::NO_PAGE && |
| 900 ui_page_ != ArcSupportHost::UIPage::ERROR && | 863 ui_page_ != ArcSupportHost::UIPage::ERROR && |
| 901 ui_page_ != ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) { | 864 ui_page_ != ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 961 ArcSupportHost::UIPage::ERROR, | 924 ArcSupportHost::UIPage::ERROR, |
| 962 l10n_util::GetStringUTF16(IDS_ARC_SIGN_IN_SERVICE_UNAVAILABLE_ERROR)); | 925 l10n_util::GetStringUTF16(IDS_ARC_SIGN_IN_SERVICE_UNAVAILABLE_ERROR)); |
| 963 return; | 926 return; |
| 964 } | 927 } |
| 965 | 928 |
| 966 SetState(State::SHOWING_TERMS_OF_SERVICE); | 929 SetState(State::SHOWING_TERMS_OF_SERVICE); |
| 967 ShowUI(ArcSupportHost::UIPage::TERMS, base::string16()); | 930 ShowUI(ArcSupportHost::UIPage::TERMS, base::string16()); |
| 968 } | 931 } |
| 969 | 932 |
| 970 void ArcAuthService::OnPrepareContextFailed() { | 933 void ArcAuthService::OnPrepareContextFailed() { |
| 971 DCHECK_EQ(state_, State::FETCHING_CODE); | |
| 972 | |
| 973 ShutdownBridgeAndShowUI( | 934 ShutdownBridgeAndShowUI( |
| 974 ArcSupportHost::UIPage::ERROR, | 935 ArcSupportHost::UIPage::ERROR, |
| 975 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); | 936 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); |
| 976 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 937 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 977 } | 938 } |
| 978 | 939 |
| 979 void ArcAuthService::OnAuthCodeSuccess(const std::string& auth_code) { | 940 void ArcAuthService::OnAuthCodeSuccess(const std::string& auth_code) { |
| 980 SetAuthCodeAndStartArc(auth_code); | 941 OnAuthCodeObtained(auth_code); |
| 981 } | 942 } |
| 982 | 943 |
| 983 void ArcAuthService::OnAuthCodeFailed() { | 944 void ArcAuthService::OnAuthCodeFailed() { |
| 984 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 945 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 985 DCHECK_EQ(state_, State::FETCHING_CODE); | |
| 986 ShutdownBridgeAndShowUI( | 946 ShutdownBridgeAndShowUI( |
| 987 ArcSupportHost::UIPage::ERROR, | 947 ArcSupportHost::UIPage::ERROR, |
| 988 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); | 948 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); |
| 989 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 949 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 990 } | 950 } |
| 991 | 951 |
| 992 void ArcAuthService::StartArcAndroidManagementCheck() { | 952 void ArcAuthService::StartArcAndroidManagementCheck() { |
| 993 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 953 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 994 DCHECK(arc_bridge_service()->stopped()); | 954 DCHECK(arc_bridge_service()->stopped()); |
| 995 SetState(State::CHECKING_ANDROID_MANAGEMENT); | 955 SetState(State::CHECKING_ANDROID_MANAGEMENT); |
| 996 | 956 |
| 997 android_management_checker_.reset(new ArcAndroidManagementChecker( | 957 android_management_checker_.reset(new ArcAndroidManagementChecker( |
| 998 profile_, context_->token_service(), context_->account_id(), | 958 profile_, context_->token_service(), context_->account_id(), |
| 999 false /* retry_on_error */)); | 959 false /* retry_on_error */)); |
| 1000 android_management_checker_->StartCheck( | 960 android_management_checker_->StartCheck( |
| 1001 base::Bind(&ArcAuthService::OnAndroidManagementChecked, | 961 base::Bind(&ArcAuthService::OnAndroidManagementChecked, |
| 1002 weak_ptr_factory_.GetWeakPtr())); | 962 weak_ptr_factory_.GetWeakPtr())); |
| 1003 } | 963 } |
| 1004 | 964 |
| 1005 void ArcAuthService::OnAndroidManagementChecked( | 965 void ArcAuthService::OnAndroidManagementChecked( |
| 1006 policy::AndroidManagementClient::Result result) { | 966 policy::AndroidManagementClient::Result result) { |
| 1007 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 967 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 1008 DCHECK_EQ(state_, State::CHECKING_ANDROID_MANAGEMENT); | 968 DCHECK_EQ(state_, State::CHECKING_ANDROID_MANAGEMENT); |
| 1009 | 969 |
| 1010 switch (result) { | 970 switch (result) { |
| 1011 case policy::AndroidManagementClient::Result::UNMANAGED: | 971 case policy::AndroidManagementClient::Result::UNMANAGED: |
| 1012 if (IsOptInVerificationDisabled()) { | 972 VLOG(1) << "Starting ARC for first sign in."; |
| 1013 StartArc(); | 973 sign_in_time_ = base::Time::Now(); |
| 1014 } else { | 974 arc_sign_in_timer_.Start(FROM_HERE, kArcSignInTimeout, |
| 1015 // TODO(hidehiko): Merge this prefetching into re-auth case. | 975 base::Bind(&ArcAuthService::OnArcSignInTimeout, |
| 1016 SetState(State::FETCHING_CODE); | 976 weak_ptr_factory_.GetWeakPtr())); |
| 1017 PrepareContextForAuthCodeRequest(); | 977 StartArc(); |
| 1018 } | |
| 1019 break; | 978 break; |
| 1020 case policy::AndroidManagementClient::Result::MANAGED: | 979 case policy::AndroidManagementClient::Result::MANAGED: |
| 1021 ShutdownBridgeAndShowUI( | 980 ShutdownBridgeAndShowUI( |
| 1022 ArcSupportHost::UIPage::ERROR, | 981 ArcSupportHost::UIPage::ERROR, |
| 1023 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR)); | 982 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR)); |
| 1024 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); | 983 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); |
| 1025 break; | 984 break; |
| 1026 case policy::AndroidManagementClient::Result::ERROR: | 985 case policy::AndroidManagementClient::Result::ERROR: |
| 1027 ShutdownBridgeAndShowUI( | 986 ShutdownBridgeAndShowUI( |
| 1028 ArcSupportHost::UIPage::ERROR, | 987 ArcSupportHost::UIPage::ERROR, |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1081 // This is ARC support's UI event callback, so this is called only when | 1040 // This is ARC support's UI event callback, so this is called only when |
| 1082 // the UI is visible. The condition to open the UI is | 1041 // the UI is visible. The condition to open the UI is |
| 1083 // !g_disable_ui_for_testing && !IsOptInVerificationDisabled() (see ShowUI()) | 1042 // !g_disable_ui_for_testing && !IsOptInVerificationDisabled() (see ShowUI()) |
| 1084 // and in the case, preference_handler_ should be always created (see | 1043 // and in the case, preference_handler_ should be always created (see |
| 1085 // OnPrimaryUserProfilePrepared()), | 1044 // OnPrimaryUserProfilePrepared()), |
| 1086 // TODO(hidehiko): Simplify the logic with the code restructuring. | 1045 // TODO(hidehiko): Simplify the logic with the code restructuring. |
| 1087 DCHECK(preference_handler_); | 1046 DCHECK(preference_handler_); |
| 1088 preference_handler_->EnableMetrics(is_metrics_enabled); | 1047 preference_handler_->EnableMetrics(is_metrics_enabled); |
| 1089 preference_handler_->EnableBackupRestore(is_backup_and_restore_enabled); | 1048 preference_handler_->EnableBackupRestore(is_backup_and_restore_enabled); |
| 1090 preference_handler_->EnableLocationService(is_location_service_enabled); | 1049 preference_handler_->EnableLocationService(is_location_service_enabled); |
| 1050 SetUIPage(ArcSupportHost::UIPage::START_PROGRESS, base::string16()); | |
| 1091 StartArcAndroidManagementCheck(); | 1051 StartArcAndroidManagementCheck(); |
| 1092 } | 1052 } |
| 1093 | 1053 |
| 1094 void ArcAuthService::OnAuthSucceeded(const std::string& auth_code) { | 1054 void ArcAuthService::OnAuthSucceeded(const std::string& auth_code) { |
| 1095 SetAuthCodeAndStartArc(auth_code); | 1055 OnAuthCodeObtained(auth_code); |
| 1096 } | 1056 } |
| 1097 | 1057 |
| 1098 void ArcAuthService::OnRetryClicked() { | 1058 void ArcAuthService::OnRetryClicked() { |
| 1099 UpdateOptInActionUMA(OptInActionType::RETRY); | 1059 UpdateOptInActionUMA(OptInActionType::RETRY); |
| 1100 // ERROR_WITH_FEEDBACK is set in OnSignInFailed(). In the case, we postpone | 1060 |
| 1101 // to stop the ARC to obtain the internal state. | 1061 // TODO(hidehiko): Simplify the retry logic. |
| 1102 // Here, on retry, stop it. | 1062 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { |
| 1103 if (ui_page_ == ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) | 1063 // If the user has not yet agreed on Terms of Service, then show it. |
| 1064 ShowUI(ArcSupportHost::UIPage::TERMS, base::string16()); | |
| 1065 } else if (ui_page_ == ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) { | |
| 1066 // ERROR_WITH_FEEDBACK is set in OnSignInFailed(). In the case, stopping | |
| 1067 // ARC was postponed to contain its internal state into the report. | |
| 1068 // Here, on retry, stop it, then restart. | |
| 1069 SetUIPage(ArcSupportHost::UIPage::START_PROGRESS, base::string16()); | |
|
Luis Héctor Chávez
2016/11/14 17:21:36
DCHECK_EQ(State::ACTIVE, state_); ?
hidehiko
2016/11/15 11:26:47
Done.
| |
| 1104 ShutdownBridge(); | 1070 ShutdownBridge(); |
|
hidehiko
2016/11/14 16:57:00
FYI: this implementation seems to hit some hidden
| |
| 1105 | 1071 reenable_arc_ = true; |
| 1106 switch (state_) { | 1072 } else if (state_ == State::ACTIVE) { |
| 1107 case State::NOT_INITIALIZED: | 1073 // This happens when ARC support Chrome app reports an error on "Sign in" |
| 1108 NOTREACHED(); | 1074 // page. |
| 1109 break; | 1075 // TODO(hidehiko): Currently, due to the existing code structure, we need |
| 1110 case State::STOPPED: | 1076 // to call PrepareContextForAuthCodeRequest() always. However, to fetch |
| 1111 case State::SHOWING_TERMS_OF_SERVICE: | 1077 // an authtoken via LSO page, it is not necessary to call PrepareContext(). |
| 1112 ShowUI(ArcSupportHost::UIPage::TERMS, base::string16()); | 1078 // Instead, it is possible to show LSO page, immediately. |
| 1113 break; | 1079 SetUIPage(ArcSupportHost::UIPage::START_PROGRESS, base::string16()); |
| 1114 case State::CHECKING_ANDROID_MANAGEMENT: | 1080 PrepareContextForAuthCodeRequest(); |
| 1115 StartArcAndroidManagementCheck(); | 1081 } else { |
| 1116 break; | 1082 // Otherwise, we restart the ARC. Note: this is the first boot case. |
|
Luis Héctor Chávez
2016/11/14 17:21:36
nit: s/the ARC/ARC/g
hidehiko
2016/11/15 11:26:47
Done.
| |
| 1117 case State::FETCHING_CODE: | 1083 // For second or later boot, either ERROR_WITH_FEEDBACK case or ACTIVE |
| 1118 case State::ACTIVE: | 1084 // case must hit. |
| 1119 PrepareContextForAuthCodeRequest(); | 1085 SetUIPage(ArcSupportHost::UIPage::START_PROGRESS, base::string16()); |
| 1120 break; | 1086 StartArcAndroidManagementCheck(); |
| 1121 } | 1087 } |
| 1122 } | 1088 } |
| 1123 | 1089 |
| 1124 void ArcAuthService::OnSendFeedbackClicked() { | 1090 void ArcAuthService::OnSendFeedbackClicked() { |
| 1125 chrome::OpenFeedbackDialog(nullptr); | 1091 chrome::OpenFeedbackDialog(nullptr); |
| 1126 } | 1092 } |
| 1127 | 1093 |
| 1128 void ArcAuthService::OnMetricsModeChanged(bool enabled, bool managed) { | 1094 void ArcAuthService::OnMetricsModeChanged(bool enabled, bool managed) { |
| 1129 if (!support_host_) | 1095 if (!support_host_) |
| 1130 return; | 1096 return; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 1146 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { | 1112 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { |
| 1147 switch (state) { | 1113 switch (state) { |
| 1148 case ArcAuthService::State::NOT_INITIALIZED: | 1114 case ArcAuthService::State::NOT_INITIALIZED: |
| 1149 return os << "NOT_INITIALIZED"; | 1115 return os << "NOT_INITIALIZED"; |
| 1150 case ArcAuthService::State::STOPPED: | 1116 case ArcAuthService::State::STOPPED: |
| 1151 return os << "STOPPED"; | 1117 return os << "STOPPED"; |
| 1152 case ArcAuthService::State::SHOWING_TERMS_OF_SERVICE: | 1118 case ArcAuthService::State::SHOWING_TERMS_OF_SERVICE: |
| 1153 return os << "SHOWING_TERMS_OF_SERVICE"; | 1119 return os << "SHOWING_TERMS_OF_SERVICE"; |
| 1154 case ArcAuthService::State::CHECKING_ANDROID_MANAGEMENT: | 1120 case ArcAuthService::State::CHECKING_ANDROID_MANAGEMENT: |
| 1155 return os << "CHECKING_ANDROID_MANAGEMENT"; | 1121 return os << "CHECKING_ANDROID_MANAGEMENT"; |
| 1156 case ArcAuthService::State::FETCHING_CODE: | |
| 1157 return os << "FETCHING_CODE"; | |
| 1158 case ArcAuthService::State::ACTIVE: | 1122 case ArcAuthService::State::ACTIVE: |
| 1159 return os << "ACTIVE"; | 1123 return os << "ACTIVE"; |
| 1160 default: | 1124 default: |
| 1161 NOTREACHED(); | 1125 NOTREACHED(); |
| 1162 return os; | 1126 return os; |
| 1163 } | 1127 } |
| 1164 } | 1128 } |
| 1165 | 1129 |
| 1166 } // namespace arc | 1130 } // namespace arc |
| OLD | NEW |