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

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

Issue 2454533002: [Merge-M55] arc: Restore broken auth code request on demand. (Closed)
Patch Set: 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
« no previous file with comments | « chrome/browser/chromeos/arc/arc_auth_service.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 286 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
687 void ArcAuthService::StartArc() { 702 void ArcAuthService::StartArc() {
688 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 703 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
689 arc_bridge_service()->HandleStartup(); 704 arc_bridge_service()->HandleStartup();
690 SetState(State::ACTIVE); 705 SetState(State::ACTIVE);
691 } 706 }
692 707
693 void ArcAuthService::SetAuthCodeAndStartArc(const std::string& auth_code) { 708 void ArcAuthService::SetAuthCodeAndStartArc(const std::string& auth_code) {
694 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 709 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
695 DCHECK(!auth_code.empty()); 710 DCHECK(!auth_code.empty());
696 711
697 if (!auth_callback_.is_null() || !auth_account_callback_.is_null()) { 712 if (IsAuthCodeRequest()) {
698 DCHECK_EQ(state_, State::FETCHING_CODE); 713 DCHECK_EQ(state_, State::FETCHING_CODE);
699 SetState(State::ACTIVE); 714 SetState(State::ACTIVE);
700 if (!auth_callback_.is_null()) { 715 if (!auth_callback_.is_null()) {
701 auth_callback_.Run(auth_code, !IsOptInVerificationDisabled()); 716 auth_callback_.Run(auth_code, !IsOptInVerificationDisabled());
702 auth_callback_.Reset(); 717 auth_callback_.Reset();
703 return; 718 return;
704 } else { 719 } else {
705 auth_account_callback_.Run(auth_code, !IsOptInVerificationDisabled(), 720 auth_account_callback_.Run(auth_code, !IsOptInVerificationDisabled(),
706 mojom::ChromeAccountType::USER_ACCOUNT); 721 mojom::ChromeAccountType::USER_ACCOUNT);
707 auth_account_callback_.Reset(); 722 auth_account_callback_.Reset();
(...skipping 27 matching lines...) Expand all
735 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 750 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
736 751
737 // Update UMA only if error (with or without feedback) is currently shown. 752 // Update UMA only if error (with or without feedback) is currently shown.
738 if (ui_page_ == UIPage::ERROR) { 753 if (ui_page_ == UIPage::ERROR) {
739 UpdateOptInActionUMA(OptInActionType::RETRY); 754 UpdateOptInActionUMA(OptInActionType::RETRY);
740 } else if (ui_page_ == UIPage::ERROR_WITH_FEEDBACK) { 755 } else if (ui_page_ == UIPage::ERROR_WITH_FEEDBACK) {
741 UpdateOptInActionUMA(OptInActionType::RETRY); 756 UpdateOptInActionUMA(OptInActionType::RETRY);
742 ShutdownBridge(); 757 ShutdownBridge();
743 } 758 }
744 759
760 // TODO(khmel): Use PrepareContextForAuthCodeRequest for this case.
745 initial_opt_in_ = false; 761 initial_opt_in_ = false;
746 StartUI(); 762 StartUI();
747 } 763 }
748 764
749 void ArcAuthService::CancelAuthCode() { 765 void ArcAuthService::CancelAuthCode() {
750 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 766 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
751 767
752 if (state_ == State::NOT_INITIALIZED) { 768 if (state_ == State::NOT_INITIALIZED) {
753 NOTREACHED(); 769 NOTREACHED();
754 return; 770 return;
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 DCHECK_EQ(state_, State::FETCHING_CODE); 866 DCHECK_EQ(state_, State::FETCHING_CODE);
851 ShutdownBridgeAndShowUI( 867 ShutdownBridgeAndShowUI(
852 UIPage::ERROR, 868 UIPage::ERROR,
853 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); 869 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR));
854 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); 870 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR);
855 } 871 }
856 872
857 void ArcAuthService::CheckAndroidManagement(bool background_mode) { 873 void ArcAuthService::CheckAndroidManagement(bool background_mode) {
858 // Do not send requests for Chrome OS managed users. 874 // Do not send requests for Chrome OS managed users.
859 if (IsAccountManaged(profile_)) { 875 if (IsAccountManaged(profile_)) {
860 StartArcIfSignedIn(); 876 OnAndroidManagementPassed();
861 return; 877 return;
862 } 878 }
863 879
864 // Do not send requests for well-known consumer domains. 880 // Do not send requests for well-known consumer domains.
865 if (policy::BrowserPolicyConnector::IsNonEnterpriseUser( 881 if (policy::BrowserPolicyConnector::IsNonEnterpriseUser(
866 profile_->GetProfileUserName())) { 882 profile_->GetProfileUserName())) {
867 StartArcIfSignedIn(); 883 OnAndroidManagementPassed();
868 return; 884 return;
869 } 885 }
870 886
871 android_management_checker_.reset( 887 android_management_checker_.reset(
872 new ArcAndroidManagementChecker(this, context_->token_service(), 888 new ArcAndroidManagementChecker(this, context_->token_service(),
873 context_->account_id(), background_mode)); 889 context_->account_id(), background_mode));
874 if (background_mode) 890 if (background_mode)
875 StartArcIfSignedIn(); 891 OnAndroidManagementPassed();
876 } 892 }
877 893
878 void ArcAuthService::OnAndroidManagementChecked( 894 void ArcAuthService::OnAndroidManagementChecked(
879 policy::AndroidManagementClient::Result result) { 895 policy::AndroidManagementClient::Result result) {
880 switch (result) { 896 switch (result) {
881 case policy::AndroidManagementClient::Result::RESULT_UNMANAGED: 897 case policy::AndroidManagementClient::Result::RESULT_UNMANAGED:
882 StartArcIfSignedIn(); 898 OnAndroidManagementPassed();
883 break; 899 break;
884 case policy::AndroidManagementClient::Result::RESULT_MANAGED: 900 case policy::AndroidManagementClient::Result::RESULT_MANAGED:
885 if (android_management_checker_->background_mode()) { 901 if (android_management_checker_->background_mode()) {
886 DisableArc(); 902 DisableArc();
887 return; 903 return;
888 } 904 }
889 ShutdownBridgeAndShowUI( 905 ShutdownBridgeAndShowUI(
890 UIPage::ERROR, 906 UIPage::ERROR,
891 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR)); 907 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR));
892 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); 908 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED);
893 break; 909 break;
894 case policy::AndroidManagementClient::Result::RESULT_ERROR: 910 case policy::AndroidManagementClient::Result::RESULT_ERROR:
895 ShutdownBridgeAndShowUI( 911 ShutdownBridgeAndShowUI(
896 UIPage::ERROR, 912 UIPage::ERROR,
897 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); 913 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR));
898 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); 914 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR);
899 break; 915 break;
900 default: 916 default:
901 NOTREACHED(); 917 NOTREACHED();
902 } 918 }
903 } 919 }
904 920
905 void ArcAuthService::StartArcIfSignedIn() { 921 void ArcAuthService::FetchAuthCode() {
906 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 922 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
907 if (state_ == State::ACTIVE) 923
924 const base::CommandLine* command_line =
925 base::CommandLine::ForCurrentProcess();
926 std::string auth_endpoint;
927 if (command_line->HasSwitch(chromeos::switches::kArcUseAuthEndpoint)) {
928 auth_endpoint = command_line->GetSwitchValueASCII(
929 chromeos::switches::kArcUseAuthEndpoint);
930 }
931
932 if (!auth_endpoint.empty()) {
933 auth_code_fetcher_.reset(new ArcAuthCodeFetcher(
934 this, context_->GetURLRequestContext(), profile_, auth_endpoint));
935 } else {
936 ShowUI(UIPage::LSO_PROGRESS, base::string16());
937 }
938 }
939
940 void ArcAuthService::OnAndroidManagementPassed() {
941 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
942
943 if (state_ == State::ACTIVE) {
944 if (IsAuthCodeRequest())
945 FetchAuthCode();
908 return; 946 return;
947 }
909 948
910 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn) || 949 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn) ||
911 IsOptInVerificationDisabled()) { 950 IsOptInVerificationDisabled()) {
912 StartArc(); 951 StartArc();
913 } else { 952 } else {
914 const base::CommandLine* command_line = 953 FetchAuthCode();
915 base::CommandLine::ForCurrentProcess();
916 std::string auth_endpoint;
917 if (command_line->HasSwitch(chromeos::switches::kArcUseAuthEndpoint)) {
918 auth_endpoint = command_line->GetSwitchValueASCII(
919 chromeos::switches::kArcUseAuthEndpoint);
920 }
921
922 if (!auth_endpoint.empty()) {
923 auth_code_fetcher_.reset(new ArcAuthCodeFetcher(
924 this, context_->GetURLRequestContext(), profile_, auth_endpoint));
925 } else {
926 ShowUI(UIPage::LSO_PROGRESS, base::string16());
927 }
928 } 954 }
929 } 955 }
930 956
931 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { 957 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) {
932 switch (state) { 958 switch (state) {
933 case ArcAuthService::State::NOT_INITIALIZED: 959 case ArcAuthService::State::NOT_INITIALIZED:
934 return os << kStateNotInitialized; 960 return os << kStateNotInitialized;
935 case ArcAuthService::State::STOPPED: 961 case ArcAuthService::State::STOPPED:
936 return os << kStateStopped; 962 return os << kStateStopped;
937 case ArcAuthService::State::FETCHING_CODE: 963 case ArcAuthService::State::FETCHING_CODE:
938 return os << kStateFetchingCode; 964 return os << kStateFetchingCode;
939 case ArcAuthService::State::ACTIVE: 965 case ArcAuthService::State::ACTIVE:
940 return os << kStateActive; 966 return os << kStateActive;
941 default: 967 default:
942 NOTREACHED(); 968 NOTREACHED();
943 return os; 969 return os;
944 } 970 }
945 } 971 }
946 972
947 } // namespace arc 973 } // namespace arc
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/arc/arc_auth_service.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698