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

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

Issue 2412133004: arc: Restore broken auth code requst on demand. (Closed)
Patch Set: refactor Created 4 years, 2 months 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 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
344 DCHECK(IsAuthCodeRequest());
345 DCHECK_EQ(state_, State::ACTIVE);
335 initial_opt_in_ = false; 346 initial_opt_in_ = false;
336 auth_account_callback_ = callback; 347 context_->PrepareContext();
337 StartUI();
338 } 348 }
339 349
340 void ArcAuthService::OnSignInComplete() { 350 void ArcAuthService::OnSignInComplete() {
341 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 351 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
342 DCHECK_EQ(state_, State::ACTIVE); 352 DCHECK_EQ(state_, State::ACTIVE);
343 DCHECK(!sign_in_time_.is_null()); 353 DCHECK(!sign_in_time_.is_null());
344 354
345 arc_sign_in_timer_.Stop(); 355 arc_sign_in_timer_.Stop();
346 356
347 if (!IsOptInVerificationDisabled() && 357 if (!IsOptInVerificationDisabled() &&
(...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 751
742 // 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.
743 if (ui_page_ == UIPage::ERROR) { 753 if (ui_page_ == UIPage::ERROR) {
744 UpdateOptInActionUMA(OptInActionType::RETRY); 754 UpdateOptInActionUMA(OptInActionType::RETRY);
745 } else if (ui_page_ == UIPage::ERROR_WITH_FEEDBACK) { 755 } else if (ui_page_ == UIPage::ERROR_WITH_FEEDBACK) {
746 UpdateOptInActionUMA(OptInActionType::RETRY); 756 UpdateOptInActionUMA(OptInActionType::RETRY);
747 ShutdownBridge(); 757 ShutdownBridge();
748 } 758 }
749 759
750 initial_opt_in_ = false; 760 initial_opt_in_ = false;
751 StartUI(); 761 StartUI();
hidehiko 2016/10/18 09:38:42 This should be PrepareContextForAuthCodeRequest(),
khmel 2016/10/20 15:31:40 Auth state in this case FETCHING_CODE, PrepareCont
752 } 762 }
753 763
754 void ArcAuthService::CancelAuthCode() { 764 void ArcAuthService::CancelAuthCode() {
755 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 765 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
756 766
757 if (state_ == State::NOT_INITIALIZED) { 767 if (state_ == State::NOT_INITIALIZED) {
758 NOTREACHED(); 768 NOTREACHED();
759 return; 769 return;
760 } 770 }
761 771
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 DCHECK_EQ(state_, State::FETCHING_CODE); 865 DCHECK_EQ(state_, State::FETCHING_CODE);
856 ShutdownBridgeAndShowUI( 866 ShutdownBridgeAndShowUI(
857 UIPage::ERROR, 867 UIPage::ERROR,
858 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); 868 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR));
859 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); 869 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR);
860 } 870 }
861 871
862 void ArcAuthService::CheckAndroidManagement(bool background_mode) { 872 void ArcAuthService::CheckAndroidManagement(bool background_mode) {
863 // Do not send requests for Chrome OS managed users. 873 // Do not send requests for Chrome OS managed users.
864 if (IsAccountManaged(profile_)) { 874 if (IsAccountManaged(profile_)) {
865 StartArcIfSignedIn(); 875 OnAndroidManagementPassed();
866 return; 876 return;
867 } 877 }
868 878
869 // Do not send requests for well-known consumer domains. 879 // Do not send requests for well-known consumer domains.
870 if (policy::BrowserPolicyConnector::IsNonEnterpriseUser( 880 if (policy::BrowserPolicyConnector::IsNonEnterpriseUser(
871 profile_->GetProfileUserName())) { 881 profile_->GetProfileUserName())) {
872 StartArcIfSignedIn(); 882 OnAndroidManagementPassed();
873 return; 883 return;
874 } 884 }
875 885
876 android_management_checker_.reset( 886 android_management_checker_.reset(
877 new ArcAndroidManagementChecker(this, context_->token_service(), 887 new ArcAndroidManagementChecker(this, context_->token_service(),
878 context_->account_id(), background_mode)); 888 context_->account_id(), background_mode));
879 if (background_mode) 889 if (background_mode)
880 StartArcIfSignedIn(); 890 OnAndroidManagementPassed();
881 } 891 }
882 892
883 void ArcAuthService::OnAndroidManagementChecked( 893 void ArcAuthService::OnAndroidManagementChecked(
884 policy::AndroidManagementClient::Result result) { 894 policy::AndroidManagementClient::Result result) {
885 switch (result) { 895 switch (result) {
886 case policy::AndroidManagementClient::Result::RESULT_UNMANAGED: 896 case policy::AndroidManagementClient::Result::RESULT_UNMANAGED:
887 StartArcIfSignedIn(); 897 OnAndroidManagementPassed();
888 break; 898 break;
889 case policy::AndroidManagementClient::Result::RESULT_MANAGED: 899 case policy::AndroidManagementClient::Result::RESULT_MANAGED:
890 if (android_management_checker_->background_mode()) { 900 if (android_management_checker_->background_mode()) {
891 DisableArc(); 901 DisableArc();
892 return; 902 return;
893 } 903 }
894 ShutdownBridgeAndShowUI( 904 ShutdownBridgeAndShowUI(
895 UIPage::ERROR, 905 UIPage::ERROR,
896 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR)); 906 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR));
897 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); 907 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED);
898 break; 908 break;
899 case policy::AndroidManagementClient::Result::RESULT_ERROR: 909 case policy::AndroidManagementClient::Result::RESULT_ERROR:
900 ShutdownBridgeAndShowUI( 910 ShutdownBridgeAndShowUI(
901 UIPage::ERROR, 911 UIPage::ERROR,
902 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); 912 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR));
903 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); 913 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR);
904 break; 914 break;
905 default: 915 default:
906 NOTREACHED(); 916 NOTREACHED();
907 } 917 }
908 } 918 }
909 919
910 void ArcAuthService::StartArcIfSignedIn() { 920 void ArcAuthService::FetchAuthCode() {
911 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 921 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
912 if (state_ == State::ACTIVE) 922 DCHECK_EQ(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();
913 return; 946 return;
947 }
914 948
915 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn) || 949 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn) ||
916 IsOptInVerificationDisabled()) { 950 IsOptInVerificationDisabled()) {
917 StartArc(); 951 StartArc();
918 } else { 952 } else {
919 const base::CommandLine* command_line = 953 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 } 954 }
934 } 955 }
935 956
936 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { 957 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) {
937 switch (state) { 958 switch (state) {
938 case ArcAuthService::State::NOT_INITIALIZED: 959 case ArcAuthService::State::NOT_INITIALIZED:
939 return os << kStateNotInitialized; 960 return os << kStateNotInitialized;
940 case ArcAuthService::State::STOPPED: 961 case ArcAuthService::State::STOPPED:
941 return os << kStateStopped; 962 return os << kStateStopped;
942 case ArcAuthService::State::FETCHING_CODE: 963 case ArcAuthService::State::FETCHING_CODE:
943 return os << kStateFetchingCode; 964 return os << kStateFetchingCode;
944 case ArcAuthService::State::ACTIVE: 965 case ArcAuthService::State::ACTIVE:
945 return os << kStateActive; 966 return os << kStateActive;
946 default: 967 default:
947 NOTREACHED(); 968 NOTREACHED();
948 return os; 969 return os;
949 } 970 }
950 } 971 }
951 972
952 } // 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