| Index: chrome/browser/chromeos/arc/arc_auth_service.cc
|
| diff --git a/chrome/browser/chromeos/arc/arc_auth_service.cc b/chrome/browser/chromeos/arc/arc_auth_service.cc
|
| index a5e680699ccbe8b9f55c2b1aa7be7e9d142f4d2a..838ab27b01de49c38fe8a8b09e82c7e6c02027d9 100644
|
| --- a/chrome/browser/chromeos/arc/arc_auth_service.cc
|
| +++ b/chrome/browser/chromeos/arc/arc_auth_service.cc
|
| @@ -304,7 +304,7 @@ void ArcAuthService::GetAuthCodeDeprecated(
|
| void ArcAuthService::GetAuthCode(const GetAuthCodeCallback& callback) {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| // GetAuthCodeAndAccountType operation must not be in progress.
|
| - DCHECK(!auth_account_callback_.is_null());
|
| + DCHECK(auth_account_callback_.is_null());
|
|
|
| const std::string auth_code = GetAndResetAuthCode();
|
| const bool verification_disabled = IsOptInVerificationDisabled();
|
| @@ -313,16 +313,15 @@ void ArcAuthService::GetAuthCode(const GetAuthCodeCallback& callback) {
|
| return;
|
| }
|
|
|
| - initial_opt_in_ = false;
|
| auth_callback_ = callback;
|
| - StartUI();
|
| + PrepareContextForAuthCodeRequest();
|
| }
|
|
|
| void ArcAuthService::GetAuthCodeAndAccountType(
|
| const GetAuthCodeAndAccountTypeCallback& callback) {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| // GetAuthCode operation must not be in progress.
|
| - DCHECK(!auth_callback_.is_null());
|
| + DCHECK(auth_callback_.is_null());
|
|
|
| const std::string auth_code = GetAndResetAuthCode();
|
| const bool verification_disabled = IsOptInVerificationDisabled();
|
| @@ -332,9 +331,20 @@ void ArcAuthService::GetAuthCodeAndAccountType(
|
| return;
|
| }
|
|
|
| - initial_opt_in_ = false;
|
| auth_account_callback_ = callback;
|
| - StartUI();
|
| + PrepareContextForAuthCodeRequest();
|
| +}
|
| +
|
| +bool ArcAuthService::IsAuthCodeRequest() const {
|
| + return !auth_callback_.is_null() || !auth_account_callback_.is_null();
|
| +}
|
| +
|
| +void ArcAuthService::PrepareContextForAuthCodeRequest() {
|
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| + DCHECK(IsAuthCodeRequest());
|
| + DCHECK_EQ(state_, State::ACTIVE);
|
| + initial_opt_in_ = false;
|
| + context_->PrepareContext();
|
| }
|
|
|
| void ArcAuthService::OnSignInComplete() {
|
| @@ -862,14 +872,14 @@ void ArcAuthService::OnAuthCodeFailed() {
|
| void ArcAuthService::CheckAndroidManagement(bool background_mode) {
|
| // Do not send requests for Chrome OS managed users.
|
| if (IsAccountManaged(profile_)) {
|
| - StartArcIfSignedIn();
|
| + OnAndroidManagementPassed();
|
| return;
|
| }
|
|
|
| // Do not send requests for well-known consumer domains.
|
| if (policy::BrowserPolicyConnector::IsNonEnterpriseUser(
|
| profile_->GetProfileUserName())) {
|
| - StartArcIfSignedIn();
|
| + OnAndroidManagementPassed();
|
| return;
|
| }
|
|
|
| @@ -877,14 +887,14 @@ void ArcAuthService::CheckAndroidManagement(bool background_mode) {
|
| new ArcAndroidManagementChecker(this, context_->token_service(),
|
| context_->account_id(), background_mode));
|
| if (background_mode)
|
| - StartArcIfSignedIn();
|
| + OnAndroidManagementPassed();
|
| }
|
|
|
| void ArcAuthService::OnAndroidManagementChecked(
|
| policy::AndroidManagementClient::Result result) {
|
| switch (result) {
|
| case policy::AndroidManagementClient::Result::RESULT_UNMANAGED:
|
| - StartArcIfSignedIn();
|
| + OnAndroidManagementPassed();
|
| break;
|
| case policy::AndroidManagementClient::Result::RESULT_MANAGED:
|
| if (android_management_checker_->background_mode()) {
|
| @@ -907,29 +917,40 @@ void ArcAuthService::OnAndroidManagementChecked(
|
| }
|
| }
|
|
|
| -void ArcAuthService::StartArcIfSignedIn() {
|
| +void ArcAuthService::FetchAuthCode() {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| - if (state_ == State::ACTIVE)
|
| + DCHECK_EQ(state_, State::ACTIVE);
|
| +
|
| + const base::CommandLine* command_line =
|
| + base::CommandLine::ForCurrentProcess();
|
| + std::string auth_endpoint;
|
| + if (command_line->HasSwitch(chromeos::switches::kArcUseAuthEndpoint)) {
|
| + auth_endpoint = command_line->GetSwitchValueASCII(
|
| + chromeos::switches::kArcUseAuthEndpoint);
|
| + }
|
| +
|
| + if (!auth_endpoint.empty()) {
|
| + auth_code_fetcher_.reset(new ArcAuthCodeFetcher(
|
| + this, context_->GetURLRequestContext(), profile_, auth_endpoint));
|
| + } else {
|
| + ShowUI(UIPage::LSO_PROGRESS, base::string16());
|
| + }
|
| +}
|
| +
|
| +void ArcAuthService::OnAndroidManagementPassed() {
|
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| +
|
| + if (state_ == State::ACTIVE) {
|
| + if (IsAuthCodeRequest())
|
| + FetchAuthCode();
|
| return;
|
| + }
|
|
|
| if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn) ||
|
| IsOptInVerificationDisabled()) {
|
| StartArc();
|
| } else {
|
| - const base::CommandLine* command_line =
|
| - base::CommandLine::ForCurrentProcess();
|
| - std::string auth_endpoint;
|
| - if (command_line->HasSwitch(chromeos::switches::kArcUseAuthEndpoint)) {
|
| - auth_endpoint = command_line->GetSwitchValueASCII(
|
| - chromeos::switches::kArcUseAuthEndpoint);
|
| - }
|
| -
|
| - if (!auth_endpoint.empty()) {
|
| - auth_code_fetcher_.reset(new ArcAuthCodeFetcher(
|
| - this, context_->GetURLRequestContext(), profile_, auth_endpoint));
|
| - } else {
|
| - ShowUI(UIPage::LSO_PROGRESS, base::string16());
|
| - }
|
| + FetchAuthCode();
|
| }
|
| }
|
|
|
|
|