| 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 371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 382 // No other auth code-related operation may be in progress. | 382 // No other auth code-related operation may be in progress. |
| 383 DCHECK(!account_info_notifier_); | 383 DCHECK(!account_info_notifier_); |
| 384 | 384 |
| 385 if (IsOptInVerificationDisabled()) { | 385 if (IsOptInVerificationDisabled()) { |
| 386 account_info_notifier->Notify(false /* = is_enforced */, std::string(), | 386 account_info_notifier->Notify(false /* = is_enforced */, std::string(), |
| 387 GetAccountType(), | 387 GetAccountType(), |
| 388 policy_util::IsAccountManaged(profile_)); | 388 policy_util::IsAccountManaged(profile_)); |
| 389 return; | 389 return; |
| 390 } | 390 } |
| 391 | 391 |
| 392 // Hereafter asynchronous operation. Remember the notifier. |
| 392 account_info_notifier_ = std::move(account_info_notifier); | 393 account_info_notifier_ = std::move(account_info_notifier); |
| 393 | 394 |
| 395 // In Kiosk mode, use Robot auth code fetching. |
| 394 if (IsArcKioskMode()) { | 396 if (IsArcKioskMode()) { |
| 395 arc_robot_auth_.reset(new ArcRobotAuth()); | 397 arc_robot_auth_.reset(new ArcRobotAuth()); |
| 396 arc_robot_auth_->FetchRobotAuthCode( | 398 arc_robot_auth_->FetchRobotAuthCode( |
| 397 base::Bind(&ArcAuthService::OnRobotAuthCodeFetched, | 399 base::Bind(&ArcAuthService::OnRobotAuthCodeFetched, |
| 398 weak_ptr_factory_.GetWeakPtr())); | 400 weak_ptr_factory_.GetWeakPtr())); |
| 399 } else { | 401 return; |
| 400 PrepareContextForAuthCodeRequest(); | |
| 401 } | 402 } |
| 403 |
| 404 // If endpoint is passed via command line flag, use automatic auth code |
| 405 // fetching. |
| 406 const base::CommandLine* command_line = |
| 407 base::CommandLine::ForCurrentProcess(); |
| 408 if (command_line->HasSwitch(chromeos::switches::kArcUseAuthEndpoint)) { |
| 409 std::string auth_endpoint = command_line->GetSwitchValueASCII( |
| 410 chromeos::switches::kArcUseAuthEndpoint); |
| 411 if (!auth_endpoint.empty()) { |
| 412 DCHECK(!auth_code_fetcher_); |
| 413 auth_code_fetcher_ = base::MakeUnique<ArcAuthCodeFetcher>( |
| 414 profile_, context_.get(), auth_endpoint); |
| 415 auth_code_fetcher_->Fetch(base::Bind(&ArcAuthService::OnAuthCodeFetched, |
| 416 weak_ptr_factory_.GetWeakPtr())); |
| 417 return; |
| 418 } |
| 419 } |
| 420 |
| 421 // Otherwise, show LSO page to user, and let them click "Sign in" button. |
| 422 if (support_host_) |
| 423 support_host_->ShowLso(); |
| 402 } | 424 } |
| 403 | 425 |
| 404 void ArcAuthService::OnRobotAuthCodeFetched( | 426 void ArcAuthService::OnRobotAuthCodeFetched( |
| 405 const std::string& robot_auth_code) { | 427 const std::string& robot_auth_code) { |
| 406 // We fetching robot auth code for ARC kiosk only. | 428 // We fetching robot auth code for ARC kiosk only. |
| 407 DCHECK(IsArcKioskMode()); | 429 DCHECK(IsArcKioskMode()); |
| 408 | 430 |
| 409 // Current instance of ArcRobotAuth became useless. | 431 // Current instance of ArcRobotAuth became useless. |
| 410 arc_robot_auth_.reset(); | 432 arc_robot_auth_.reset(); |
| 411 | 433 |
| 412 if (robot_auth_code.empty()) { | 434 if (robot_auth_code.empty()) { |
| 413 VLOG(1) << "Robot account auth code fetching error"; | 435 VLOG(1) << "Robot account auth code fetching error"; |
| 414 // Log out the user. All the cleanup will be done in Shutdown() method. | 436 // Log out the user. All the cleanup will be done in Shutdown() method. |
| 415 // The callback is not called because auth code is empty. | 437 // The callback is not called because auth code is empty. |
| 416 chrome::AttemptUserExit(); | 438 chrome::AttemptUserExit(); |
| 417 return; | 439 return; |
| 418 } | 440 } |
| 419 | 441 |
| 420 account_info_notifier_->Notify( | 442 OnAuthCodeObtained(robot_auth_code); |
| 421 !IsOptInVerificationDisabled(), robot_auth_code, | |
| 422 mojom::ChromeAccountType::ROBOT_ACCOUNT, false); | |
| 423 account_info_notifier_.reset(); | |
| 424 } | 443 } |
| 425 | 444 |
| 426 bool ArcAuthService::IsAuthCodeRequest() const { | 445 void ArcAuthService::OnAuthCodeFetched(const std::string& auth_code) { |
| 427 return account_info_notifier_ != nullptr; | 446 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 428 } | 447 auth_code_fetcher_.reset(); |
| 429 | 448 |
| 430 void ArcAuthService::PrepareContextForAuthCodeRequest() { | 449 if (auth_code.empty()) { |
| 431 // Requesting auth code on demand happens in following cases: | 450 OnProvisioningFinished( |
| 432 // 1. To handle account password revoke. | 451 ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); |
| 433 // 2. In case Arc is activated in OOBE flow. | 452 return; |
| 434 // 3. For any other state on Android side that leads device appears in | 453 } |
| 435 // non-signed state. | 454 |
| 436 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 455 OnAuthCodeObtained(auth_code); |
| 437 DCHECK(state_ == State::ACTIVE); | |
| 438 DCHECK(IsAuthCodeRequest()); | |
| 439 DCHECK(!IsArcKioskMode()); | |
| 440 context_->PrepareContext(); | |
| 441 } | 456 } |
| 442 | 457 |
| 443 void ArcAuthService::OnSignInComplete() { | 458 void ArcAuthService::OnSignInComplete() { |
| 444 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 459 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 445 DCHECK_EQ(state_, State::ACTIVE); | 460 DCHECK_EQ(state_, State::ACTIVE); |
| 446 OnProvisioningFinished(ProvisioningResult::SUCCESS); | 461 OnProvisioningFinished(ProvisioningResult::SUCCESS); |
| 447 } | 462 } |
| 448 | 463 |
| 449 void ArcAuthService::OnSignInFailed(mojom::ArcSignInFailureReason reason) { | 464 void ArcAuthService::OnSignInFailed(mojom::ArcSignInFailureReason reason) { |
| 450 OnProvisioningFinished( | 465 OnProvisioningFinished( |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 601 // This automatically updates all preferences. | 616 // This automatically updates all preferences. |
| 602 preference_handler_->Start(); | 617 preference_handler_->Start(); |
| 603 } | 618 } |
| 604 | 619 |
| 605 DCHECK_EQ(State::NOT_INITIALIZED, state_); | 620 DCHECK_EQ(State::NOT_INITIALIZED, state_); |
| 606 SetState(State::STOPPED); | 621 SetState(State::STOPPED); |
| 607 | 622 |
| 608 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( | 623 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( |
| 609 prefs::kArcEnabled, this); | 624 prefs::kArcEnabled, this); |
| 610 | 625 |
| 611 context_.reset(new ArcAuthContext(this, profile_)); | 626 context_.reset(new ArcAuthContext(profile_)); |
| 612 | 627 |
| 613 if (!g_disable_ui_for_testing || | 628 if (!g_disable_ui_for_testing || |
| 614 g_enable_check_android_management_for_testing) { | 629 g_enable_check_android_management_for_testing) { |
| 615 ArcAndroidManagementChecker::StartClient(); | 630 ArcAndroidManagementChecker::StartClient(); |
| 616 } | 631 } |
| 617 pref_change_registrar_.Init(profile_->GetPrefs()); | 632 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 618 pref_change_registrar_.Add( | 633 pref_change_registrar_.Add( |
| 619 prefs::kArcEnabled, base::Bind(&ArcAuthService::OnOptInPreferenceChanged, | 634 prefs::kArcEnabled, base::Bind(&ArcAuthService::OnOptInPreferenceChanged, |
| 620 weak_ptr_factory_.GetWeakPtr())); | 635 weak_ptr_factory_.GetWeakPtr())); |
| 621 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { | 636 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { |
| (...skipping 27 matching lines...) Expand all Loading... |
| 649 pref_service_syncable->RemoveObserver(this); | 664 pref_service_syncable->RemoveObserver(this); |
| 650 pref_service_syncable->RemoveSyncedPrefObserver(prefs::kArcEnabled, this); | 665 pref_service_syncable->RemoveSyncedPrefObserver(prefs::kArcEnabled, this); |
| 651 } | 666 } |
| 652 pref_change_registrar_.RemoveAll(); | 667 pref_change_registrar_.RemoveAll(); |
| 653 context_.reset(); | 668 context_.reset(); |
| 654 profile_ = nullptr; | 669 profile_ = nullptr; |
| 655 arc_robot_auth_.reset(); | 670 arc_robot_auth_.reset(); |
| 656 SetState(State::NOT_INITIALIZED); | 671 SetState(State::NOT_INITIALIZED); |
| 657 } | 672 } |
| 658 | 673 |
| 659 void ArcAuthService::OnContextReady() { | |
| 660 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 661 FetchAuthCode(); | |
| 662 } | |
| 663 | |
| 664 void ArcAuthService::OnSyncedPrefChanged(const std::string& path, | 674 void ArcAuthService::OnSyncedPrefChanged(const std::string& path, |
| 665 bool from_sync) { | 675 bool from_sync) { |
| 666 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 676 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 667 | 677 |
| 668 // Update UMA only for local changes | 678 // Update UMA only for local changes |
| 669 if (!from_sync) { | 679 if (!from_sync) { |
| 670 const bool arc_enabled = | 680 const bool arc_enabled = |
| 671 profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled); | 681 profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled); |
| 672 UpdateOptInActionUMA(arc_enabled ? OptInActionType::OPTED_IN | 682 UpdateOptInActionUMA(arc_enabled ? OptInActionType::OPTED_IN |
| 673 : OptInActionType::OPTED_OUT); | 683 : OptInActionType::OPTED_OUT); |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 891 ArcSupportHost::Error::SIGN_IN_SERVICE_UNAVAILABLE_ERROR, false); | 901 ArcSupportHost::Error::SIGN_IN_SERVICE_UNAVAILABLE_ERROR, false); |
| 892 } | 902 } |
| 893 return; | 903 return; |
| 894 } | 904 } |
| 895 | 905 |
| 896 SetState(State::SHOWING_TERMS_OF_SERVICE); | 906 SetState(State::SHOWING_TERMS_OF_SERVICE); |
| 897 if (support_host_) | 907 if (support_host_) |
| 898 support_host_->ShowTermsOfService(); | 908 support_host_->ShowTermsOfService(); |
| 899 } | 909 } |
| 900 | 910 |
| 901 void ArcAuthService::OnPrepareContextFailed() { | |
| 902 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 903 OnProvisioningFinished(ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); | |
| 904 } | |
| 905 | |
| 906 void ArcAuthService::OnAuthCodeSuccess(const std::string& auth_code) { | |
| 907 OnAuthCodeObtained(auth_code); | |
| 908 } | |
| 909 | |
| 910 void ArcAuthService::OnAuthCodeFailed() { | |
| 911 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 912 OnProvisioningFinished(ProvisioningResult::CHROME_SERVER_COMMUNICATION_ERROR); | |
| 913 } | |
| 914 | |
| 915 void ArcAuthService::StartArcAndroidManagementCheck() { | 911 void ArcAuthService::StartArcAndroidManagementCheck() { |
| 916 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 912 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 917 DCHECK(arc_bridge_service()->stopped()); | 913 DCHECK(arc_bridge_service()->stopped()); |
| 918 DCHECK(state_ == State::SHOWING_TERMS_OF_SERVICE || | 914 DCHECK(state_ == State::SHOWING_TERMS_OF_SERVICE || |
| 919 state_ == State::CHECKING_ANDROID_MANAGEMENT); | 915 state_ == State::CHECKING_ANDROID_MANAGEMENT); |
| 920 SetState(State::CHECKING_ANDROID_MANAGEMENT); | 916 SetState(State::CHECKING_ANDROID_MANAGEMENT); |
| 921 | 917 |
| 922 android_management_checker_.reset(new ArcAndroidManagementChecker( | 918 android_management_checker_.reset(new ArcAndroidManagementChecker( |
| 923 profile_, context_->token_service(), context_->account_id(), | 919 profile_, context_->token_service(), context_->account_id(), |
| 924 false /* retry_on_error */)); | 920 false /* retry_on_error */)); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 970 case policy::AndroidManagementClient::Result::MANAGED: | 966 case policy::AndroidManagementClient::Result::MANAGED: |
| 971 DisableArc(); | 967 DisableArc(); |
| 972 break; | 968 break; |
| 973 case policy::AndroidManagementClient::Result::ERROR: | 969 case policy::AndroidManagementClient::Result::ERROR: |
| 974 // This code should not be reached. For background check, | 970 // This code should not be reached. For background check, |
| 975 // retry_on_error should be set. | 971 // retry_on_error should be set. |
| 976 NOTREACHED(); | 972 NOTREACHED(); |
| 977 } | 973 } |
| 978 } | 974 } |
| 979 | 975 |
| 980 void ArcAuthService::FetchAuthCode() { | |
| 981 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 982 | |
| 983 const base::CommandLine* command_line = | |
| 984 base::CommandLine::ForCurrentProcess(); | |
| 985 std::string auth_endpoint; | |
| 986 if (command_line->HasSwitch(chromeos::switches::kArcUseAuthEndpoint)) { | |
| 987 auth_endpoint = command_line->GetSwitchValueASCII( | |
| 988 chromeos::switches::kArcUseAuthEndpoint); | |
| 989 } | |
| 990 | |
| 991 if (!auth_endpoint.empty()) { | |
| 992 auth_code_fetcher_.reset(new ArcAuthCodeFetcher( | |
| 993 this, context_->GetURLRequestContext(), profile_, auth_endpoint)); | |
| 994 } else { | |
| 995 if (support_host_) | |
| 996 support_host_->ShowLso(); | |
| 997 } | |
| 998 } | |
| 999 | |
| 1000 void ArcAuthService::OnWindowClosed() { | 976 void ArcAuthService::OnWindowClosed() { |
| 1001 DCHECK(support_host_); | 977 DCHECK(support_host_); |
| 1002 CancelAuthCode(); | 978 CancelAuthCode(); |
| 1003 } | 979 } |
| 1004 | 980 |
| 1005 void ArcAuthService::OnTermsAgreed(bool is_metrics_enabled, | 981 void ArcAuthService::OnTermsAgreed(bool is_metrics_enabled, |
| 1006 bool is_backup_and_restore_enabled, | 982 bool is_backup_and_restore_enabled, |
| 1007 bool is_location_service_enabled) { | 983 bool is_location_service_enabled) { |
| 1008 DCHECK(support_host_); | 984 DCHECK(support_host_); |
| 1009 | 985 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1040 // ERROR_WITH_FEEDBACK is set in OnSignInFailed(). In the case, stopping | 1016 // ERROR_WITH_FEEDBACK is set in OnSignInFailed(). In the case, stopping |
| 1041 // ARC was postponed to contain its internal state into the report. | 1017 // ARC was postponed to contain its internal state into the report. |
| 1042 // Here, on retry, stop it, then restart. | 1018 // Here, on retry, stop it, then restart. |
| 1043 DCHECK_EQ(State::ACTIVE, state_); | 1019 DCHECK_EQ(State::ACTIVE, state_); |
| 1044 support_host_->ShowArcLoading(); | 1020 support_host_->ShowArcLoading(); |
| 1045 ShutdownBridge(); | 1021 ShutdownBridge(); |
| 1046 reenable_arc_ = true; | 1022 reenable_arc_ = true; |
| 1047 } else if (state_ == State::ACTIVE) { | 1023 } else if (state_ == State::ACTIVE) { |
| 1048 // This happens when ARC support Chrome app reports an error on "Sign in" | 1024 // This happens when ARC support Chrome app reports an error on "Sign in" |
| 1049 // page. | 1025 // page. |
| 1050 // TODO(hidehiko): Currently, due to the existing code structure, we need | 1026 support_host_->ShowLso(); |
| 1051 // to call PrepareContextForAuthCodeRequest() always. However, to fetch | |
| 1052 // an authtoken via LSO page, it is not necessary to call PrepareContext(). | |
| 1053 // Instead, it is possible to show LSO page, immediately. | |
| 1054 support_host_->ShowArcLoading(); | |
| 1055 PrepareContextForAuthCodeRequest(); | |
| 1056 } else { | 1027 } else { |
| 1057 // Otherwise, we restart ARC. Note: this is the first boot case. | 1028 // Otherwise, we restart ARC. Note: this is the first boot case. |
| 1058 // For second or later boot, either ERROR_WITH_FEEDBACK case or ACTIVE | 1029 // For second or later boot, either ERROR_WITH_FEEDBACK case or ACTIVE |
| 1059 // case must hit. | 1030 // case must hit. |
| 1060 support_host_->ShowArcLoading(); | 1031 support_host_->ShowArcLoading(); |
| 1061 StartArcAndroidManagementCheck(); | 1032 StartArcAndroidManagementCheck(); |
| 1062 } | 1033 } |
| 1063 } | 1034 } |
| 1064 | 1035 |
| 1065 void ArcAuthService::OnSendFeedbackClicked() { | 1036 void ArcAuthService::OnSendFeedbackClicked() { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1099 return os << "ACTIVE"; | 1070 return os << "ACTIVE"; |
| 1100 } | 1071 } |
| 1101 | 1072 |
| 1102 // Some compiler reports an error even if all values of an enum-class are | 1073 // Some compiler reports an error even if all values of an enum-class are |
| 1103 // covered indivisually in a switch statement. | 1074 // covered indivisually in a switch statement. |
| 1104 NOTREACHED(); | 1075 NOTREACHED(); |
| 1105 return os; | 1076 return os; |
| 1106 } | 1077 } |
| 1107 | 1078 |
| 1108 } // namespace arc | 1079 } // namespace arc |
| OLD | NEW |