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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 void ArcAuthService::GetAuthCodeDeprecated( | 297 void ArcAuthService::GetAuthCodeDeprecated( |
298 const GetAuthCodeDeprecatedCallback& callback) { | 298 const GetAuthCodeDeprecatedCallback& callback) { |
299 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 299 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
300 DCHECK(!IsOptInVerificationDisabled()); | 300 DCHECK(!IsOptInVerificationDisabled()); |
301 callback.Run(GetAndResetAuthCode()); | 301 callback.Run(GetAndResetAuthCode()); |
302 } | 302 } |
303 | 303 |
304 void ArcAuthService::GetAuthCode(const GetAuthCodeCallback& callback) { | 304 void ArcAuthService::GetAuthCode(const GetAuthCodeCallback& callback) { |
305 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 305 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
306 // GetAuthCodeAndAccountType operation must not be in progress. | 306 // GetAuthCodeAndAccountType operation must not be in progress. |
307 DCHECK(!auth_account_callback_.is_null()); | 307 DCHECK(auth_account_callback_.is_null()); |
308 | 308 |
309 const std::string auth_code = GetAndResetAuthCode(); | 309 const std::string auth_code = GetAndResetAuthCode(); |
310 const bool verification_disabled = IsOptInVerificationDisabled(); | 310 const bool verification_disabled = IsOptInVerificationDisabled(); |
311 if (!auth_code.empty() || verification_disabled) { | 311 if (!auth_code.empty() || verification_disabled) { |
312 callback.Run(auth_code, !verification_disabled); | 312 callback.Run(auth_code, !verification_disabled); |
313 return; | 313 return; |
314 } | 314 } |
315 | 315 |
316 initial_opt_in_ = false; | |
317 auth_callback_ = callback; | 316 auth_callback_ = callback; |
318 StartUI(); | 317 PrepareContextForAuthCodeRequest(); |
319 } | 318 } |
320 | 319 |
321 void ArcAuthService::GetAuthCodeAndAccountType( | 320 void ArcAuthService::GetAuthCodeAndAccountType( |
322 const GetAuthCodeAndAccountTypeCallback& callback) { | 321 const GetAuthCodeAndAccountTypeCallback& callback) { |
323 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 322 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
324 // GetAuthCode operation must not be in progress. | 323 // GetAuthCode operation must not be in progress. |
325 DCHECK(!auth_callback_.is_null()); | 324 DCHECK(auth_callback_.is_null()); |
326 | 325 |
327 const std::string auth_code = GetAndResetAuthCode(); | 326 const std::string auth_code = GetAndResetAuthCode(); |
328 const bool verification_disabled = IsOptInVerificationDisabled(); | 327 const bool verification_disabled = IsOptInVerificationDisabled(); |
329 if (!auth_code.empty() || verification_disabled) { | 328 if (!auth_code.empty() || verification_disabled) { |
330 callback.Run(auth_code, !verification_disabled, | 329 callback.Run(auth_code, !verification_disabled, |
331 mojom::ChromeAccountType::USER_ACCOUNT); | 330 mojom::ChromeAccountType::USER_ACCOUNT); |
332 return; | 331 return; |
333 } | 332 } |
334 | 333 |
| 334 auth_account_callback_ = callback; |
| 335 PrepareContextForAuthCodeRequest(); |
| 336 } |
| 337 |
| 338 bool ArcAuthService::IsAuthCodeRequest() const { |
| 339 return !auth_callback_.is_null() || !auth_account_callback_.is_null(); |
| 340 } |
| 341 |
| 342 void ArcAuthService::PrepareContextForAuthCodeRequest() { |
| 343 // Requesting auth code on demand happens in following cases: |
| 344 // 1. To handle account password revoke. |
| 345 // 2. In case Arc is activated in OOBE flow. |
| 346 // 3. For any other state on Android side that leads device appears in |
| 347 // non-signed state. |
| 348 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 349 DCHECK(IsAuthCodeRequest()); |
| 350 DCHECK_EQ(state_, State::ACTIVE); |
335 initial_opt_in_ = false; | 351 initial_opt_in_ = false; |
336 auth_account_callback_ = callback; | 352 context_->PrepareContext(); |
337 StartUI(); | |
338 } | 353 } |
339 | 354 |
340 void ArcAuthService::OnSignInComplete() { | 355 void ArcAuthService::OnSignInComplete() { |
341 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 356 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
342 DCHECK_EQ(state_, State::ACTIVE); | 357 DCHECK_EQ(state_, State::ACTIVE); |
343 DCHECK(!sign_in_time_.is_null()); | 358 DCHECK(!sign_in_time_.is_null()); |
344 | 359 |
345 arc_sign_in_timer_.Stop(); | 360 arc_sign_in_timer_.Stop(); |
346 | 361 |
347 if (!IsOptInVerificationDisabled() && | 362 if (!IsOptInVerificationDisabled() && |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
692 void ArcAuthService::StartArc() { | 707 void ArcAuthService::StartArc() { |
693 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 708 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
694 arc_bridge_service()->HandleStartup(); | 709 arc_bridge_service()->HandleStartup(); |
695 SetState(State::ACTIVE); | 710 SetState(State::ACTIVE); |
696 } | 711 } |
697 | 712 |
698 void ArcAuthService::SetAuthCodeAndStartArc(const std::string& auth_code) { | 713 void ArcAuthService::SetAuthCodeAndStartArc(const std::string& auth_code) { |
699 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 714 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
700 DCHECK(!auth_code.empty()); | 715 DCHECK(!auth_code.empty()); |
701 | 716 |
702 if (!auth_callback_.is_null() || !auth_account_callback_.is_null()) { | 717 if (IsAuthCodeRequest()) { |
703 DCHECK_EQ(state_, State::FETCHING_CODE); | 718 DCHECK_EQ(state_, State::FETCHING_CODE); |
704 SetState(State::ACTIVE); | 719 SetState(State::ACTIVE); |
705 if (!auth_callback_.is_null()) { | 720 if (!auth_callback_.is_null()) { |
706 auth_callback_.Run(auth_code, !IsOptInVerificationDisabled()); | 721 auth_callback_.Run(auth_code, !IsOptInVerificationDisabled()); |
707 auth_callback_.Reset(); | 722 auth_callback_.Reset(); |
708 return; | 723 return; |
709 } else { | 724 } else { |
710 auth_account_callback_.Run(auth_code, !IsOptInVerificationDisabled(), | 725 auth_account_callback_.Run(auth_code, !IsOptInVerificationDisabled(), |
711 mojom::ChromeAccountType::USER_ACCOUNT); | 726 mojom::ChromeAccountType::USER_ACCOUNT); |
712 auth_account_callback_.Reset(); | 727 auth_account_callback_.Reset(); |
(...skipping 27 matching lines...) Expand all Loading... |
740 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 755 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
741 | 756 |
742 // Update UMA only if error (with or without feedback) is currently shown. | 757 // Update UMA only if error (with or without feedback) is currently shown. |
743 if (ui_page_ == UIPage::ERROR) { | 758 if (ui_page_ == UIPage::ERROR) { |
744 UpdateOptInActionUMA(OptInActionType::RETRY); | 759 UpdateOptInActionUMA(OptInActionType::RETRY); |
745 } else if (ui_page_ == UIPage::ERROR_WITH_FEEDBACK) { | 760 } else if (ui_page_ == UIPage::ERROR_WITH_FEEDBACK) { |
746 UpdateOptInActionUMA(OptInActionType::RETRY); | 761 UpdateOptInActionUMA(OptInActionType::RETRY); |
747 ShutdownBridge(); | 762 ShutdownBridge(); |
748 } | 763 } |
749 | 764 |
| 765 // TODO(khmel): Use PrepareContextForAuthCodeRequest for this case. |
750 initial_opt_in_ = false; | 766 initial_opt_in_ = false; |
751 StartUI(); | 767 StartUI(); |
752 } | 768 } |
753 | 769 |
754 void ArcAuthService::CancelAuthCode() { | 770 void ArcAuthService::CancelAuthCode() { |
755 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 771 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
756 | 772 |
757 if (state_ == State::NOT_INITIALIZED) { | 773 if (state_ == State::NOT_INITIALIZED) { |
758 NOTREACHED(); | 774 NOTREACHED(); |
759 return; | 775 return; |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
855 DCHECK_EQ(state_, State::FETCHING_CODE); | 871 DCHECK_EQ(state_, State::FETCHING_CODE); |
856 ShutdownBridgeAndShowUI( | 872 ShutdownBridgeAndShowUI( |
857 UIPage::ERROR, | 873 UIPage::ERROR, |
858 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); | 874 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); |
859 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 875 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
860 } | 876 } |
861 | 877 |
862 void ArcAuthService::CheckAndroidManagement(bool background_mode) { | 878 void ArcAuthService::CheckAndroidManagement(bool background_mode) { |
863 // Do not send requests for Chrome OS managed users. | 879 // Do not send requests for Chrome OS managed users. |
864 if (IsAccountManaged(profile_)) { | 880 if (IsAccountManaged(profile_)) { |
865 StartArcIfSignedIn(); | 881 OnAndroidManagementPassed(); |
866 return; | 882 return; |
867 } | 883 } |
868 | 884 |
869 // Do not send requests for well-known consumer domains. | 885 // Do not send requests for well-known consumer domains. |
870 if (policy::BrowserPolicyConnector::IsNonEnterpriseUser( | 886 if (policy::BrowserPolicyConnector::IsNonEnterpriseUser( |
871 profile_->GetProfileUserName())) { | 887 profile_->GetProfileUserName())) { |
872 StartArcIfSignedIn(); | 888 OnAndroidManagementPassed(); |
873 return; | 889 return; |
874 } | 890 } |
875 | 891 |
876 android_management_checker_.reset( | 892 android_management_checker_.reset( |
877 new ArcAndroidManagementChecker(this, context_->token_service(), | 893 new ArcAndroidManagementChecker(this, context_->token_service(), |
878 context_->account_id(), background_mode)); | 894 context_->account_id(), background_mode)); |
879 if (background_mode) | 895 if (background_mode) |
880 StartArcIfSignedIn(); | 896 OnAndroidManagementPassed(); |
881 } | 897 } |
882 | 898 |
883 void ArcAuthService::OnAndroidManagementChecked( | 899 void ArcAuthService::OnAndroidManagementChecked( |
884 policy::AndroidManagementClient::Result result) { | 900 policy::AndroidManagementClient::Result result) { |
885 switch (result) { | 901 switch (result) { |
886 case policy::AndroidManagementClient::Result::RESULT_UNMANAGED: | 902 case policy::AndroidManagementClient::Result::RESULT_UNMANAGED: |
887 StartArcIfSignedIn(); | 903 OnAndroidManagementPassed(); |
888 break; | 904 break; |
889 case policy::AndroidManagementClient::Result::RESULT_MANAGED: | 905 case policy::AndroidManagementClient::Result::RESULT_MANAGED: |
890 if (android_management_checker_->background_mode()) { | 906 if (android_management_checker_->background_mode()) { |
891 DisableArc(); | 907 DisableArc(); |
892 return; | 908 return; |
893 } | 909 } |
894 ShutdownBridgeAndShowUI( | 910 ShutdownBridgeAndShowUI( |
895 UIPage::ERROR, | 911 UIPage::ERROR, |
896 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR)); | 912 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR)); |
897 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); | 913 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); |
898 break; | 914 break; |
899 case policy::AndroidManagementClient::Result::RESULT_ERROR: | 915 case policy::AndroidManagementClient::Result::RESULT_ERROR: |
900 ShutdownBridgeAndShowUI( | 916 ShutdownBridgeAndShowUI( |
901 UIPage::ERROR, | 917 UIPage::ERROR, |
902 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); | 918 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); |
903 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 919 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
904 break; | 920 break; |
905 default: | 921 default: |
906 NOTREACHED(); | 922 NOTREACHED(); |
907 } | 923 } |
908 } | 924 } |
909 | 925 |
910 void ArcAuthService::StartArcIfSignedIn() { | 926 void ArcAuthService::FetchAuthCode() { |
911 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 927 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
912 if (state_ == State::ACTIVE) | 928 |
| 929 const base::CommandLine* command_line = |
| 930 base::CommandLine::ForCurrentProcess(); |
| 931 std::string auth_endpoint; |
| 932 if (command_line->HasSwitch(chromeos::switches::kArcUseAuthEndpoint)) { |
| 933 auth_endpoint = command_line->GetSwitchValueASCII( |
| 934 chromeos::switches::kArcUseAuthEndpoint); |
| 935 } |
| 936 |
| 937 if (!auth_endpoint.empty()) { |
| 938 auth_code_fetcher_.reset(new ArcAuthCodeFetcher( |
| 939 this, context_->GetURLRequestContext(), profile_, auth_endpoint)); |
| 940 } else { |
| 941 ShowUI(UIPage::LSO_PROGRESS, base::string16()); |
| 942 } |
| 943 } |
| 944 |
| 945 void ArcAuthService::OnAndroidManagementPassed() { |
| 946 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 947 |
| 948 if (state_ == State::ACTIVE) { |
| 949 if (IsAuthCodeRequest()) |
| 950 FetchAuthCode(); |
913 return; | 951 return; |
| 952 } |
914 | 953 |
915 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn) || | 954 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn) || |
916 IsOptInVerificationDisabled()) { | 955 IsOptInVerificationDisabled()) { |
917 StartArc(); | 956 StartArc(); |
918 } else { | 957 } else { |
919 const base::CommandLine* command_line = | 958 FetchAuthCode(); |
920 base::CommandLine::ForCurrentProcess(); | |
921 std::string auth_endpoint; | |
922 if (command_line->HasSwitch(chromeos::switches::kArcUseAuthEndpoint)) { | |
923 auth_endpoint = command_line->GetSwitchValueASCII( | |
924 chromeos::switches::kArcUseAuthEndpoint); | |
925 } | |
926 | |
927 if (!auth_endpoint.empty()) { | |
928 auth_code_fetcher_.reset(new ArcAuthCodeFetcher( | |
929 this, context_->GetURLRequestContext(), profile_, auth_endpoint)); | |
930 } else { | |
931 ShowUI(UIPage::LSO_PROGRESS, base::string16()); | |
932 } | |
933 } | 959 } |
934 } | 960 } |
935 | 961 |
936 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { | 962 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { |
937 switch (state) { | 963 switch (state) { |
938 case ArcAuthService::State::NOT_INITIALIZED: | 964 case ArcAuthService::State::NOT_INITIALIZED: |
939 return os << kStateNotInitialized; | 965 return os << kStateNotInitialized; |
940 case ArcAuthService::State::STOPPED: | 966 case ArcAuthService::State::STOPPED: |
941 return os << kStateStopped; | 967 return os << kStateStopped; |
942 case ArcAuthService::State::FETCHING_CODE: | 968 case ArcAuthService::State::FETCHING_CODE: |
943 return os << kStateFetchingCode; | 969 return os << kStateFetchingCode; |
944 case ArcAuthService::State::ACTIVE: | 970 case ArcAuthService::State::ACTIVE: |
945 return os << kStateActive; | 971 return os << kStateActive; |
946 default: | 972 default: |
947 NOTREACHED(); | 973 NOTREACHED(); |
948 return os; | 974 return os; |
949 } | 975 } |
950 } | 976 } |
951 | 977 |
952 } // namespace arc | 978 } // namespace arc |
OLD | NEW |