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 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 369 base::MakeUnique<ArcAuthService::AccountInfoNotifier>(callback)); | 369 base::MakeUnique<ArcAuthService::AccountInfoNotifier>(callback)); |
| 370 } | 370 } |
| 371 | 371 |
| 372 void ArcAuthService::GetAuthCodeAndAccountTypeDeprecated( | 372 void ArcAuthService::GetAuthCodeAndAccountTypeDeprecated( |
| 373 const GetAuthCodeAndAccountTypeDeprecatedCallback& callback) { | 373 const GetAuthCodeAndAccountTypeDeprecatedCallback& callback) { |
| 374 RequestAccountInfoInternal( | 374 RequestAccountInfoInternal( |
| 375 base::MakeUnique<ArcAuthService::AccountInfoNotifier>(callback)); | 375 base::MakeUnique<ArcAuthService::AccountInfoNotifier>(callback)); |
| 376 } | 376 } |
| 377 | 377 |
| 378 void ArcAuthService::RequestAccountInfo() { | 378 void ArcAuthService::RequestAccountInfo() { |
| 379 RequestAccountInfoInternal( | 379 RequestAccountInfoInternal( |
|
Luis Héctor Chávez
2016/11/14 17:06:50
What states can this call be made in? ACTIVE and C
hidehiko
2016/11/14 19:07:57
Practically, ACTIVE.
However, some browser tests c
Luis Héctor Chávez
2016/11/14 19:19:25
sgtm
| |
| 380 base::MakeUnique<ArcAuthService::AccountInfoNotifier>( | 380 base::MakeUnique<ArcAuthService::AccountInfoNotifier>( |
| 381 base::Bind(&ArcAuthService::OnAccountInfoReady, | 381 base::Bind(&ArcAuthService::OnAccountInfoReady, |
| 382 weak_ptr_factory_.GetWeakPtr()))); | 382 weak_ptr_factory_.GetWeakPtr()))); |
| 383 } | 383 } |
| 384 | 384 |
| 385 void ArcAuthService::OnAccountInfoReady(mojom::AccountInfoPtr account_info) { | 385 void ArcAuthService::OnAccountInfoReady(mojom::AccountInfoPtr account_info) { |
| 386 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 386 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 387 auto* instance = arc_bridge_service()->auth()->GetInstanceForMethod( | 387 auto* instance = arc_bridge_service()->auth()->GetInstanceForMethod( |
| 388 "OnAccountInfoReady", kMinVersionForOnAccountInfoReady); | 388 "OnAccountInfoReady", kMinVersionForOnAccountInfoReady); |
| 389 DCHECK(instance); | 389 DCHECK(instance); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 443 return account_info_notifier_ != nullptr; | 443 return account_info_notifier_ != nullptr; |
| 444 } | 444 } |
| 445 | 445 |
| 446 void ArcAuthService::PrepareContextForAuthCodeRequest() { | 446 void ArcAuthService::PrepareContextForAuthCodeRequest() { |
| 447 // Requesting auth code on demand happens in following cases: | 447 // Requesting auth code on demand happens in following cases: |
| 448 // 1. To handle account password revoke. | 448 // 1. To handle account password revoke. |
| 449 // 2. In case Arc is activated in OOBE flow. | 449 // 2. In case Arc is activated in OOBE flow. |
| 450 // 3. For any other state on Android side that leads device appears in | 450 // 3. For any other state on Android side that leads device appears in |
| 451 // non-signed state. | 451 // non-signed state. |
| 452 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 452 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 453 DCHECK(state_ != State::ACTIVE || IsAuthCodeRequest()); | 453 DCHECK(state_ != State::ACTIVE || IsAuthCodeRequest()); |
|
Luis Héctor Chávez
2016/11/14 17:06:50
IIUC this can be DCHECK_(state_ == State::FETCHING
hidehiko
2016/11/14 19:07:57
Added slightly more straight forward checking. How
Luis Héctor Chávez
2016/11/14 19:19:25
sgtm
| |
| 454 DCHECK(!IsArcKioskMode()); | 454 DCHECK(!IsArcKioskMode()); |
| 455 context_->PrepareContext(); | 455 context_->PrepareContext(); |
| 456 } | 456 } |
| 457 | 457 |
| 458 void ArcAuthService::OnSignInComplete() { | 458 void ArcAuthService::OnSignInComplete() { |
| 459 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 459 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 460 DCHECK_EQ(state_, State::ACTIVE); | 460 DCHECK_EQ(state_, State::ACTIVE); |
| 461 | 461 |
| 462 if (!sign_in_time_.is_null()) { | 462 if (!sign_in_time_.is_null()) { |
| 463 arc_sign_in_timer_.Stop(); | 463 arc_sign_in_timer_.Stop(); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 594 // TODO(hidehiko): Revisit to think about lazy initialization. | 594 // TODO(hidehiko): Revisit to think about lazy initialization. |
| 595 support_host_.reset(new ArcSupportHost()); | 595 support_host_.reset(new ArcSupportHost()); |
| 596 support_host_->AddObserver(this); | 596 support_host_->AddObserver(this); |
| 597 if (!g_disable_ui_for_testing && !IsOptInVerificationDisabled()) { | 597 if (!g_disable_ui_for_testing && !IsOptInVerificationDisabled()) { |
| 598 preference_handler_ = base::MakeUnique<arc::ArcOptInPreferenceHandler>( | 598 preference_handler_ = base::MakeUnique<arc::ArcOptInPreferenceHandler>( |
| 599 this, profile_->GetPrefs()); | 599 this, profile_->GetPrefs()); |
| 600 // This automatically updates all preferences. | 600 // This automatically updates all preferences. |
| 601 preference_handler_->Start(); | 601 preference_handler_->Start(); |
| 602 } | 602 } |
| 603 | 603 |
| 604 SetState(State::STOPPED); | 604 SetState(State::STOPPED); |
|
Luis Héctor Chávez
2016/11/14 17:06:50
DCHECK_EQ(State::NOT_INITIALIZED, state_);
hidehiko
2016/11/14 19:07:57
Done.
| |
| 605 | 605 |
| 606 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( | 606 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( |
| 607 prefs::kArcEnabled, this); | 607 prefs::kArcEnabled, this); |
| 608 | 608 |
| 609 context_.reset(new ArcAuthContext(this, profile_)); | 609 context_.reset(new ArcAuthContext(this, profile_)); |
| 610 | 610 |
| 611 // In case UI is disabled we assume that ARC is opted-in. For ARC Kiosk we | 611 // 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 | 612 // 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 | 613 // 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. | 614 // because there are no managed human users for Kiosk exist. |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 688 ArcSupportHost::kHostAppId); | 688 ArcSupportHost::kHostAppId); |
| 689 CHECK(extension && extensions::util::IsAppLaunchable( | 689 CHECK(extension && extensions::util::IsAppLaunchable( |
| 690 ArcSupportHost::kHostAppId, profile_)); | 690 ArcSupportHost::kHostAppId, profile_)); |
| 691 OpenApplication(CreateAppLaunchParamsUserContainer( | 691 OpenApplication(CreateAppLaunchParamsUserContainer( |
| 692 profile_, extension, WindowOpenDisposition::NEW_WINDOW, | 692 profile_, extension, WindowOpenDisposition::NEW_WINDOW, |
| 693 extensions::SOURCE_CHROME_INTERNAL)); | 693 extensions::SOURCE_CHROME_INTERNAL)); |
| 694 } | 694 } |
| 695 | 695 |
| 696 void ArcAuthService::OnContextReady() { | 696 void ArcAuthService::OnContextReady() { |
| 697 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 697 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 698 | 698 FetchAuthCode(); |
| 699 // TODO(hidehiko): The check is not necessary if this is a part of re-auth | |
| 700 // flow and OOBE OptIn where Android Management check must be a part of | |
| 701 // checking if Arc OptIn should be skip. Remove this. | |
| 702 android_management_checker_.reset(new ArcAndroidManagementChecker( | |
| 703 profile_, context_->token_service(), context_->account_id(), | |
| 704 false /* retry_on_error */)); | |
| 705 android_management_checker_->StartCheck( | |
| 706 base::Bind(&ArcAuthService::OnAndroidManagementChecked, | |
| 707 weak_ptr_factory_.GetWeakPtr())); | |
| 708 } | 699 } |
| 709 | 700 |
| 710 void ArcAuthService::OnSyncedPrefChanged(const std::string& path, | 701 void ArcAuthService::OnSyncedPrefChanged(const std::string& path, |
| 711 bool from_sync) { | 702 bool from_sync) { |
| 712 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 703 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 713 | 704 |
| 714 // Update UMA only for local changes | 705 // Update UMA only for local changes |
| 715 if (!from_sync) { | 706 if (!from_sync) { |
| 716 const bool arc_enabled = | 707 const bool arc_enabled = |
| 717 profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled); | 708 profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 752 } | 743 } |
| 753 | 744 |
| 754 if (state_ == State::ACTIVE) | 745 if (state_ == State::ACTIVE) |
| 755 return; | 746 return; |
| 756 CloseUI(); | 747 CloseUI(); |
| 757 auth_code_.clear(); | 748 auth_code_.clear(); |
| 758 | 749 |
| 759 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { | 750 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { |
| 760 if (profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { | 751 if (profile_->GetPrefs()->GetBoolean(prefs::kArcTermsAccepted)) { |
| 761 // Need pre-fetch auth code and start Arc. | 752 // Need pre-fetch auth code and start Arc. |
| 762 SetState(State::FETCHING_CODE); | 753 SetState(State::FETCHING_CODE); |
|
Luis Héctor Chávez
2016/11/14 17:06:50
DCHECK_EQ(State::CHECKING_ANDROID_MANAGEMENT, stat
hidehiko
2016/11/14 19:07:57
Practically, we expect STOPPED here.
However, stat
| |
| 763 PrepareContextForAuthCodeRequest(); | 754 PrepareContextForAuthCodeRequest(); |
| 764 } else { | 755 } else { |
| 765 // Need pre-fetch auth code and show OptIn UI if needed. | 756 // Need pre-fetch auth code and show OptIn UI if needed. |
| 766 StartUI(); | 757 StartUI(); |
| 767 } | 758 } |
| 768 } else { | 759 } else { |
| 769 // Ready to start Arc, but check Android management in parallel. | 760 // Ready to start Arc, but check Android management in parallel. |
| 770 StartArc(); | 761 StartArc(); |
| 771 // Note: Because the callback may be called in synchronous way (i.e. called | 762 // Note: Because the callback may be called in synchronous way (i.e. called |
| 772 // on the same stack), StartCheck() needs to be called *after* StartArc(). | 763 // on the same stack), StartCheck() needs to be called *after* StartArc(). |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 839 void ArcAuthService::StopAndEnableArc() { | 830 void ArcAuthService::StopAndEnableArc() { |
| 840 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 831 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 841 DCHECK(!arc_bridge_service()->stopped()); | 832 DCHECK(!arc_bridge_service()->stopped()); |
| 842 reenable_arc_ = true; | 833 reenable_arc_ = true; |
| 843 StopArc(); | 834 StopArc(); |
| 844 } | 835 } |
| 845 | 836 |
| 846 void ArcAuthService::StartArc() { | 837 void ArcAuthService::StartArc() { |
| 847 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 838 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 848 arc_bridge_service()->RequestStart(); | 839 arc_bridge_service()->RequestStart(); |
| 849 SetState(State::ACTIVE); | 840 SetState(State::ACTIVE); |
|
Luis Héctor Chávez
2016/11/14 17:06:50
Can we check that state is either FETCHING_CODE or
hidehiko
2016/11/14 19:07:57
Unfortunately, StartArc() can be called in other s
Luis Héctor Chávez
2016/11/14 19:19:25
sure
| |
| 850 } | 841 } |
| 851 | 842 |
| 852 void ArcAuthService::SetAuthCodeAndStartArc(const std::string& auth_code) { | 843 void ArcAuthService::SetAuthCodeAndStartArc(const std::string& auth_code) { |
| 853 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 844 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 854 DCHECK(!auth_code.empty()); | 845 DCHECK(!auth_code.empty()); |
| 855 | 846 |
| 856 if (IsAuthCodeRequest()) { | 847 if (IsAuthCodeRequest()) { |
| 857 DCHECK_EQ(state_, State::FETCHING_CODE); | |
| 858 SetState(State::ACTIVE); | |
| 859 account_info_notifier_->Notify(!IsOptInVerificationDisabled(), auth_code, | 848 account_info_notifier_->Notify(!IsOptInVerificationDisabled(), auth_code, |
| 860 GetAccountType(), | 849 GetAccountType(), |
| 861 policy_util::IsAccountManaged(profile_)); | 850 policy_util::IsAccountManaged(profile_)); |
| 862 account_info_notifier_.reset(); | 851 account_info_notifier_.reset(); |
| 863 return; | 852 return; |
| 864 } | 853 } |
| 865 | 854 |
| 866 if (state_ != State::FETCHING_CODE) { | 855 if (state_ != State::SHOWING_TERMS_OF_SERVICE && |
| 856 state_ != State::CHECKING_ANDROID_MANAGEMENT && | |
| 857 state_ != State::FETCHING_CODE) { | |
| 867 ShutdownBridgeAndCloseUI(); | 858 ShutdownBridgeAndCloseUI(); |
| 868 return; | 859 return; |
| 869 } | 860 } |
| 870 | 861 |
| 871 sign_in_time_ = base::Time::Now(); | 862 sign_in_time_ = base::Time::Now(); |
| 872 VLOG(1) << "Starting ARC for first sign in."; | 863 VLOG(1) << "Starting ARC for first sign in."; |
| 873 | 864 |
| 874 SetUIPage(ArcSupportHost::UIPage::START_PROGRESS, base::string16()); | 865 SetUIPage(ArcSupportHost::UIPage::START_PROGRESS, base::string16()); |
| 875 ShutdownBridge(); | 866 ShutdownBridge(); |
| 876 auth_code_ = auth_code; | 867 auth_code_ = auth_code; |
| 877 arc_sign_in_timer_.Start(FROM_HERE, kArcSignInTimeout, | 868 arc_sign_in_timer_.Start(FROM_HERE, kArcSignInTimeout, |
| 878 base::Bind(&ArcAuthService::OnArcSignInTimeout, | 869 base::Bind(&ArcAuthService::OnArcSignInTimeout, |
| 879 weak_ptr_factory_.GetWeakPtr())); | 870 weak_ptr_factory_.GetWeakPtr())); |
| 880 StartArc(); | 871 StartArc(); |
| 881 } | 872 } |
| 882 | 873 |
| 883 void ArcAuthService::OnArcSignInTimeout() { | 874 void ArcAuthService::OnArcSignInTimeout() { |
| 884 LOG(ERROR) << "Timed out waiting for first sign in."; | 875 LOG(ERROR) << "Timed out waiting for first sign in."; |
| 885 OnSignInFailedInternal(ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT); | 876 OnSignInFailedInternal(ProvisioningResult::OVERALL_SIGN_IN_TIMEOUT); |
| 886 } | 877 } |
| 887 | 878 |
| 888 void ArcAuthService::StartLso() { | |
| 889 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 890 | |
| 891 // Terms were accepted | |
| 892 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); | |
| 893 | |
| 894 // Update UMA only if error (with or without feedback) is currently shown. | |
| 895 if (ui_page_ == ArcSupportHost::UIPage::ERROR) { | |
| 896 UpdateOptInActionUMA(OptInActionType::RETRY); | |
| 897 } else if (ui_page_ == ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) { | |
| 898 UpdateOptInActionUMA(OptInActionType::RETRY); | |
| 899 ShutdownBridge(); | |
| 900 } | |
| 901 | |
| 902 DCHECK(arc_bridge_service()->stopped()); | |
| 903 SetState(State::FETCHING_CODE); | |
| 904 PrepareContextForAuthCodeRequest(); | |
| 905 } | |
| 906 | |
| 907 void ArcAuthService::CancelAuthCode() { | 879 void ArcAuthService::CancelAuthCode() { |
| 908 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 880 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 909 | 881 |
| 910 if (state_ == State::NOT_INITIALIZED) { | 882 if (state_ == State::NOT_INITIALIZED) { |
| 911 NOTREACHED(); | 883 NOTREACHED(); |
| 912 return; | 884 return; |
| 913 } | 885 } |
| 914 | 886 |
| 915 // In case |state_| is ACTIVE, |ui_page_| can be START_PROGRESS (which means | 887 // In case |state_| is ACTIVE, |ui_page_| can be START_PROGRESS (which means |
| 916 // normal Arc booting) or ERROR or ERROR_WITH_FEEDBACK (in case Arc can not | 888 // normal Arc booting) or ERROR or ERROR_WITH_FEEDBACK (in case Arc can not |
| 917 // be started). If Arc is booting normally dont't stop it on progress close. | 889 // be started). If Arc is booting normally dont't stop it on progress close. |
| 918 if (state_ != State::FETCHING_CODE && | 890 if ((state_ != State::FETCHING_CODE && |
| 891 state_ != State::SHOWING_TERMS_OF_SERVICE && | |
| 892 state_ != State::CHECKING_ANDROID_MANAGEMENT) && | |
| 919 ui_page_ != ArcSupportHost::UIPage::ERROR && | 893 ui_page_ != ArcSupportHost::UIPage::ERROR && |
| 920 ui_page_ != ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) { | 894 ui_page_ != ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) { |
| 921 return; | 895 return; |
| 922 } | 896 } |
| 923 | 897 |
| 924 // Update UMA with user cancel only if error is not currently shown. | 898 // Update UMA with user cancel only if error is not currently shown. |
| 925 if (ui_page_ != ArcSupportHost::UIPage::NO_PAGE && | 899 if (ui_page_ != ArcSupportHost::UIPage::NO_PAGE && |
| 926 ui_page_ != ArcSupportHost::UIPage::ERROR && | 900 ui_page_ != ArcSupportHost::UIPage::ERROR && |
| 927 ui_page_ != ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) { | 901 ui_page_ != ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) { |
| 928 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); | 902 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 982 | 956 |
| 983 if (!arc_bridge_service()->stopped()) { | 957 if (!arc_bridge_service()->stopped()) { |
| 984 // If the user attempts to re-enable ARC while the bridge is still running | 958 // If the user attempts to re-enable ARC while the bridge is still running |
| 985 // the user should not be able to continue until the bridge has stopped. | 959 // the user should not be able to continue until the bridge has stopped. |
| 986 ShowUI( | 960 ShowUI( |
| 987 ArcSupportHost::UIPage::ERROR, | 961 ArcSupportHost::UIPage::ERROR, |
| 988 l10n_util::GetStringUTF16(IDS_ARC_SIGN_IN_SERVICE_UNAVAILABLE_ERROR)); | 962 l10n_util::GetStringUTF16(IDS_ARC_SIGN_IN_SERVICE_UNAVAILABLE_ERROR)); |
| 989 return; | 963 return; |
| 990 } | 964 } |
| 991 | 965 |
| 992 SetState(State::FETCHING_CODE); | 966 SetState(State::SHOWING_TERMS_OF_SERVICE); |
|
Luis Héctor Chávez
2016/11/14 17:06:50
DCHECK_EQ(State::STOPPED, state_);
hidehiko
2016/11/14 19:07:57
Practically, we expect STOPPED, but technically th
Luis Héctor Chávez
2016/11/14 19:19:25
sure
| |
| 993 ShowUI(ArcSupportHost::UIPage::TERMS, base::string16()); | 967 ShowUI(ArcSupportHost::UIPage::TERMS, base::string16()); |
| 994 } | 968 } |
| 995 | 969 |
| 996 void ArcAuthService::OnPrepareContextFailed() { | 970 void ArcAuthService::OnPrepareContextFailed() { |
| 997 DCHECK_EQ(state_, State::FETCHING_CODE); | 971 DCHECK_EQ(state_, State::FETCHING_CODE); |
| 998 | 972 |
| 999 ShutdownBridgeAndShowUI( | 973 ShutdownBridgeAndShowUI( |
| 1000 ArcSupportHost::UIPage::ERROR, | 974 ArcSupportHost::UIPage::ERROR, |
| 1001 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); | 975 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); |
| 1002 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 976 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 1003 } | 977 } |
| 1004 | 978 |
| 1005 void ArcAuthService::OnAuthCodeSuccess(const std::string& auth_code) { | 979 void ArcAuthService::OnAuthCodeSuccess(const std::string& auth_code) { |
| 1006 SetAuthCodeAndStartArc(auth_code); | 980 SetAuthCodeAndStartArc(auth_code); |
| 1007 } | 981 } |
| 1008 | 982 |
| 1009 void ArcAuthService::OnAuthCodeFailed() { | 983 void ArcAuthService::OnAuthCodeFailed() { |
| 1010 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 984 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 1011 DCHECK_EQ(state_, State::FETCHING_CODE); | 985 DCHECK_EQ(state_, State::FETCHING_CODE); |
| 1012 ShutdownBridgeAndShowUI( | 986 ShutdownBridgeAndShowUI( |
| 1013 ArcSupportHost::UIPage::ERROR, | 987 ArcSupportHost::UIPage::ERROR, |
| 1014 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); | 988 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); |
| 1015 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 989 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 1016 } | 990 } |
| 1017 | 991 |
| 992 void ArcAuthService::StartArcAndroidManagementCheck() { | |
| 993 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 994 DCHECK(arc_bridge_service()->stopped()); | |
| 995 SetState(State::CHECKING_ANDROID_MANAGEMENT); | |
|
Luis Héctor Chávez
2016/11/14 17:06:50
DCHECK_EQ(State::SHOWING_TERMS_OF_SERVICE, state_)
hidehiko
2016/11/14 19:07:57
Added DCHECK.
I know the state machine handling i
| |
| 996 | |
| 997 android_management_checker_.reset(new ArcAndroidManagementChecker( | |
| 998 profile_, context_->token_service(), context_->account_id(), | |
| 999 false /* retry_on_error */)); | |
| 1000 android_management_checker_->StartCheck( | |
| 1001 base::Bind(&ArcAuthService::OnAndroidManagementChecked, | |
| 1002 weak_ptr_factory_.GetWeakPtr())); | |
| 1003 } | |
| 1004 | |
| 1018 void ArcAuthService::OnAndroidManagementChecked( | 1005 void ArcAuthService::OnAndroidManagementChecked( |
| 1019 policy::AndroidManagementClient::Result result) { | 1006 policy::AndroidManagementClient::Result result) { |
| 1020 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 1007 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 1008 DCHECK_EQ(state_, State::CHECKING_ANDROID_MANAGEMENT); | |
| 1009 | |
| 1021 switch (result) { | 1010 switch (result) { |
| 1022 case policy::AndroidManagementClient::Result::UNMANAGED: | 1011 case policy::AndroidManagementClient::Result::UNMANAGED: |
| 1023 OnAndroidManagementPassed(); | 1012 if (IsOptInVerificationDisabled()) { |
| 1013 StartArc(); | |
| 1014 } else { | |
| 1015 // TODO(hidehiko): Merge this prefetching into re-auth case. | |
| 1016 SetState(State::FETCHING_CODE); | |
| 1017 PrepareContextForAuthCodeRequest(); | |
| 1018 } | |
| 1024 break; | 1019 break; |
| 1025 case policy::AndroidManagementClient::Result::MANAGED: | 1020 case policy::AndroidManagementClient::Result::MANAGED: |
| 1026 ShutdownBridgeAndShowUI( | 1021 ShutdownBridgeAndShowUI( |
| 1027 ArcSupportHost::UIPage::ERROR, | 1022 ArcSupportHost::UIPage::ERROR, |
| 1028 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR)); | 1023 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR)); |
| 1029 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); | 1024 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); |
| 1030 break; | 1025 break; |
| 1031 case policy::AndroidManagementClient::Result::ERROR: | 1026 case policy::AndroidManagementClient::Result::ERROR: |
| 1032 ShutdownBridgeAndShowUI( | 1027 ShutdownBridgeAndShowUI( |
| 1033 ArcSupportHost::UIPage::ERROR, | 1028 ArcSupportHost::UIPage::ERROR, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1066 } | 1061 } |
| 1067 | 1062 |
| 1068 if (!auth_endpoint.empty()) { | 1063 if (!auth_endpoint.empty()) { |
| 1069 auth_code_fetcher_.reset(new ArcAuthCodeFetcher( | 1064 auth_code_fetcher_.reset(new ArcAuthCodeFetcher( |
| 1070 this, context_->GetURLRequestContext(), profile_, auth_endpoint)); | 1065 this, context_->GetURLRequestContext(), profile_, auth_endpoint)); |
| 1071 } else { | 1066 } else { |
| 1072 ShowUI(ArcSupportHost::UIPage::LSO_PROGRESS, base::string16()); | 1067 ShowUI(ArcSupportHost::UIPage::LSO_PROGRESS, base::string16()); |
| 1073 } | 1068 } |
| 1074 } | 1069 } |
| 1075 | 1070 |
| 1076 void ArcAuthService::OnAndroidManagementPassed() { | |
| 1077 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 1078 | |
| 1079 if (state_ == State::ACTIVE) { | |
| 1080 if (IsAuthCodeRequest()) | |
| 1081 FetchAuthCode(); | |
| 1082 return; | |
| 1083 } | |
| 1084 | |
| 1085 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn) || | |
| 1086 IsOptInVerificationDisabled()) { | |
| 1087 StartArc(); | |
| 1088 } else { | |
| 1089 FetchAuthCode(); | |
| 1090 } | |
| 1091 } | |
| 1092 | |
| 1093 void ArcAuthService::OnWindowClosed() { | 1071 void ArcAuthService::OnWindowClosed() { |
| 1094 CancelAuthCode(); | 1072 CancelAuthCode(); |
| 1095 } | 1073 } |
| 1096 | 1074 |
| 1097 void ArcAuthService::OnTermsAgreed(bool is_metrics_enabled, | 1075 void ArcAuthService::OnTermsAgreed(bool is_metrics_enabled, |
| 1098 bool is_backup_and_restore_enabled, | 1076 bool is_backup_and_restore_enabled, |
| 1099 bool is_location_service_enabled) { | 1077 bool is_location_service_enabled) { |
| 1078 // Terms were accepted | |
| 1079 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, true); | |
| 1080 | |
| 1100 // This is ARC support's UI event callback, so this is called only when | 1081 // This is ARC support's UI event callback, so this is called only when |
| 1101 // the UI is visible. The condition to open the UI is | 1082 // the UI is visible. The condition to open the UI is |
| 1102 // !g_disable_ui_for_testing && !IsOptInVerificationDisabled() (see ShowUI()) | 1083 // !g_disable_ui_for_testing && !IsOptInVerificationDisabled() (see ShowUI()) |
| 1103 // and in the case, preference_handler_ should be always created (see | 1084 // and in the case, preference_handler_ should be always created (see |
| 1104 // OnPrimaryUserProfilePrepared()), | 1085 // OnPrimaryUserProfilePrepared()), |
| 1105 // TODO(hidehiko): Simplify the logic with the code restructuring. | 1086 // TODO(hidehiko): Simplify the logic with the code restructuring. |
| 1106 DCHECK(preference_handler_); | 1087 DCHECK(preference_handler_); |
| 1107 preference_handler_->EnableMetrics(is_metrics_enabled); | 1088 preference_handler_->EnableMetrics(is_metrics_enabled); |
| 1108 preference_handler_->EnableBackupRestore(is_backup_and_restore_enabled); | 1089 preference_handler_->EnableBackupRestore(is_backup_and_restore_enabled); |
| 1109 preference_handler_->EnableLocationService(is_location_service_enabled); | 1090 preference_handler_->EnableLocationService(is_location_service_enabled); |
| 1110 StartLso(); | 1091 StartArcAndroidManagementCheck(); |
| 1111 } | 1092 } |
| 1112 | 1093 |
| 1113 void ArcAuthService::OnAuthSucceeded(const std::string& auth_code) { | 1094 void ArcAuthService::OnAuthSucceeded(const std::string& auth_code) { |
| 1114 SetAuthCodeAndStartArc(auth_code); | 1095 SetAuthCodeAndStartArc(auth_code); |
| 1115 } | 1096 } |
| 1116 | 1097 |
| 1098 void ArcAuthService::OnRetryClicked() { | |
| 1099 UpdateOptInActionUMA(OptInActionType::RETRY); | |
| 1100 // ERROR_WITH_FEEDBACK is set in OnSignInFailed(). In the case, we postpone | |
| 1101 // to stop the ARC to obtain the internal state. | |
| 1102 // Here, on retry, stop it. | |
| 1103 if (ui_page_ == ArcSupportHost::UIPage::ERROR_WITH_FEEDBACK) | |
| 1104 ShutdownBridge(); | |
| 1105 | |
| 1106 switch (state_) { | |
| 1107 case State::NOT_INITIALIZED: | |
| 1108 NOTREACHED(); | |
| 1109 break; | |
| 1110 case State::STOPPED: | |
| 1111 case State::SHOWING_TERMS_OF_SERVICE: | |
| 1112 ShowUI(ArcSupportHost::UIPage::TERMS, base::string16()); | |
| 1113 break; | |
| 1114 case State::CHECKING_ANDROID_MANAGEMENT: | |
| 1115 StartArcAndroidManagementCheck(); | |
| 1116 break; | |
| 1117 case State::FETCHING_CODE: | |
| 1118 case State::ACTIVE: | |
|
Luis Héctor Chávez
2016/11/14 17:06:50
If State::ACTIVE, you also need to check if there
hidehiko
2016/11/14 19:07:57
Done in PrepareContextForAuthCodeRequest().
| |
| 1119 PrepareContextForAuthCodeRequest(); | |
| 1120 break; | |
| 1121 } | |
| 1122 } | |
| 1123 | |
| 1117 void ArcAuthService::OnSendFeedbackClicked() { | 1124 void ArcAuthService::OnSendFeedbackClicked() { |
| 1118 chrome::OpenFeedbackDialog(nullptr); | 1125 chrome::OpenFeedbackDialog(nullptr); |
| 1119 } | 1126 } |
| 1120 | 1127 |
| 1121 void ArcAuthService::OnMetricsModeChanged(bool enabled, bool managed) { | 1128 void ArcAuthService::OnMetricsModeChanged(bool enabled, bool managed) { |
| 1122 if (!support_host_) | 1129 if (!support_host_) |
| 1123 return; | 1130 return; |
| 1124 support_host_->SetMetricsPreferenceCheckbox(enabled, managed); | 1131 support_host_->SetMetricsPreferenceCheckbox(enabled, managed); |
| 1125 } | 1132 } |
| 1126 | 1133 |
| 1127 void ArcAuthService::OnBackupAndRestoreModeChanged(bool enabled, bool managed) { | 1134 void ArcAuthService::OnBackupAndRestoreModeChanged(bool enabled, bool managed) { |
| 1128 if (!support_host_) | 1135 if (!support_host_) |
| 1129 return; | 1136 return; |
| 1130 support_host_->SetBackupAndRestorePreferenceCheckbox(enabled, managed); | 1137 support_host_->SetBackupAndRestorePreferenceCheckbox(enabled, managed); |
| 1131 } | 1138 } |
| 1132 | 1139 |
| 1133 void ArcAuthService::OnLocationServicesModeChanged(bool enabled, bool managed) { | 1140 void ArcAuthService::OnLocationServicesModeChanged(bool enabled, bool managed) { |
| 1134 if (!support_host_) | 1141 if (!support_host_) |
| 1135 return; | 1142 return; |
| 1136 support_host_->SetLocationServicesPreferenceCheckbox(enabled, managed); | 1143 support_host_->SetLocationServicesPreferenceCheckbox(enabled, managed); |
| 1137 } | 1144 } |
| 1138 | 1145 |
| 1139 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { | 1146 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { |
| 1140 switch (state) { | 1147 switch (state) { |
| 1141 case ArcAuthService::State::NOT_INITIALIZED: | 1148 case ArcAuthService::State::NOT_INITIALIZED: |
| 1142 return os << "NOT_INITIALIZED"; | 1149 return os << "NOT_INITIALIZED"; |
| 1143 case ArcAuthService::State::STOPPED: | 1150 case ArcAuthService::State::STOPPED: |
| 1144 return os << "STOPPED"; | 1151 return os << "STOPPED"; |
| 1152 case ArcAuthService::State::SHOWING_TERMS_OF_SERVICE: | |
| 1153 return os << "SHOWING_TERMS_OF_SERVICE"; | |
| 1154 case ArcAuthService::State::CHECKING_ANDROID_MANAGEMENT: | |
| 1155 return os << "CHECKING_ANDROID_MANAGEMENT"; | |
| 1145 case ArcAuthService::State::FETCHING_CODE: | 1156 case ArcAuthService::State::FETCHING_CODE: |
| 1146 return os << "FETCHING_CODE"; | 1157 return os << "FETCHING_CODE"; |
| 1147 case ArcAuthService::State::ACTIVE: | 1158 case ArcAuthService::State::ACTIVE: |
| 1148 return os << "ACTIVE"; | 1159 return os << "ACTIVE"; |
| 1149 default: | 1160 default: |
| 1150 NOTREACHED(); | 1161 NOTREACHED(); |
| 1151 return os; | 1162 return os; |
| 1152 } | 1163 } |
| 1153 } | 1164 } |
| 1154 | 1165 |
| 1155 } // namespace arc | 1166 } // namespace arc |
| OLD | NEW |