| 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 827972626d7bad8e421952bdd23014bd81b89967..fd2357792f56565d0031c582b4143ff9769f6a94 100644
|
| --- a/chrome/browser/chromeos/arc/arc_auth_service.cc
|
| +++ b/chrome/browser/chromeos/arc/arc_auth_service.cc
|
| @@ -20,6 +20,7 @@
|
| #include "chrome/browser/chromeos/arc/arc_optin_uma.h"
|
| #include "chrome/browser/chromeos/arc/arc_support_host.h"
|
| #include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h"
|
| +#include "chrome/browser/chromeos/arc/policy/arc_policy_util.h"
|
| #include "chrome/browser/chromeos/profiles/profile_helper.h"
|
| #include "chrome/browser/extensions/extension_util.h"
|
| #include "chrome/browser/policy/profile_policy_connector.h"
|
| @@ -38,7 +39,6 @@
|
| #include "chromeos/dbus/dbus_thread_manager.h"
|
| #include "chromeos/dbus/session_manager_client.h"
|
| #include "components/arc/arc_bridge_service.h"
|
| -#include "components/policy/core/browser/browser_policy_connector.h"
|
| #include "components/pref_registry/pref_registry_syncable.h"
|
| #include "components/prefs/pref_service.h"
|
| #include "components/syncable_prefs/pref_service_syncable.h"
|
| @@ -76,11 +76,6 @@ const char kStateStopped[] = "STOPPED";
|
| const char kStateFetchingCode[] = "FETCHING_CODE";
|
| const char kStateActive[] = "ACTIVE";
|
|
|
| -bool IsAccountManaged(Profile* profile) {
|
| - return policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile)
|
| - ->IsManaged();
|
| -}
|
| -
|
| bool IsArcDisabledForEnterprise() {
|
| return base::CommandLine::ForCurrentProcess()->HasSwitch(
|
| chromeos::switches::kEnterpriseDisableArc);
|
| @@ -368,9 +363,9 @@ void ArcAuthService::OnSignInComplete() {
|
| profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, true);
|
| CloseUI();
|
| UpdateProvisioningTiming(base::Time::Now() - sign_in_time_, true,
|
| - IsAccountManaged(profile_));
|
| + policy_util::IsAccountManaged(profile_));
|
| UpdateProvisioningResultUMA(ProvisioningResult::SUCCESS,
|
| - IsAccountManaged(profile_));
|
| + policy_util::IsAccountManaged(profile_));
|
|
|
| for (auto& observer : observer_list_)
|
| observer.OnInitialStart();
|
| @@ -389,9 +384,9 @@ void ArcAuthService::OnSignInFailedInternal(ProvisioningResult result) {
|
| arc_sign_in_timer_.Stop();
|
|
|
| UpdateProvisioningTiming(base::Time::Now() - sign_in_time_, false,
|
| - IsAccountManaged(profile_));
|
| + policy_util::IsAccountManaged(profile_));
|
| UpdateOptInCancelUMA(OptInCancelReason::CLOUD_PROVISION_FLOW_FAIL);
|
| - UpdateProvisioningResultUMA(result, IsAccountManaged(profile_));
|
| + UpdateProvisioningResultUMA(result, policy_util::IsAccountManaged(profile_));
|
|
|
| int error_message_id;
|
| switch (result) {
|
| @@ -451,7 +446,7 @@ void ArcAuthService::GetIsAccountManaged(
|
| const GetIsAccountManagedCallback& callback) {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
|
|
| - callback.Run(IsAccountManaged(profile_));
|
| + callback.Run(policy_util::IsAccountManaged(profile_));
|
| }
|
|
|
| void ArcAuthService::SetState(State state) {
|
| @@ -478,7 +473,7 @@ void ArcAuthService::OnPrimaryUserProfilePrepared(Profile* profile) {
|
| return;
|
|
|
| // TODO(khmel): Move this to IsAllowedForProfile.
|
| - if (IsArcDisabledForEnterprise() && IsAccountManaged(profile)) {
|
| + if (IsArcDisabledForEnterprise() && policy_util::IsAccountManaged(profile)) {
|
| VLOG(2) << "Enterprise users are not supported in ARC.";
|
| return;
|
| }
|
| @@ -579,7 +574,15 @@ void ArcAuthService::OnContextReady() {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
|
|
| DCHECK(!initial_opt_in_);
|
| - CheckAndroidManagement(false);
|
| +
|
| + // TODO(hidehiko): The check is not necessary if this is a part of re-auth
|
| + // flow. Remove this.
|
| + android_management_checker_.reset(new ArcAndroidManagementChecker(
|
| + profile_, context_->token_service(), context_->account_id(),
|
| + false /* retry_on_error */));
|
| + android_management_checker_->StartCheck(
|
| + base::Bind(&ArcAuthService::OnAndroidManagementChecked,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| }
|
|
|
| void ArcAuthService::OnSyncedPrefChanged(const std::string& path,
|
| @@ -636,12 +639,20 @@ void ArcAuthService::OnOptInPreferenceChanged() {
|
| initial_opt_in_ = true;
|
| StartUI();
|
| } else {
|
| - // Ready to start Arc, but check Android management first.
|
| + // Ready to start Arc, but check Android management in parallel.
|
| + StartArc();
|
| + // Note: Because the callback may be called in synchronous way (i.e. called
|
| + // on the same stack), StartCheck() needs to be called *after* StartArc().
|
| + // Otherwise, DisableArc() which may be called in
|
| + // OnBackgroundAndroidManagementChecked() could be ignored.
|
| if (!g_disable_ui_for_testing ||
|
| g_enable_check_android_management_for_testing) {
|
| - CheckAndroidManagement(true);
|
| - } else {
|
| - StartArc();
|
| + android_management_checker_.reset(new ArcAndroidManagementChecker(
|
| + profile_, context_->token_service(), context_->account_id(),
|
| + true /* retry_on_error */));
|
| + android_management_checker_->StartCheck(
|
| + base::Bind(&ArcAuthService::OnBackgroundAndroidManagementChecked,
|
| + weak_ptr_factory_.GetWeakPtr()));
|
| }
|
| }
|
|
|
| @@ -879,38 +890,14 @@ void ArcAuthService::OnAuthCodeFailed() {
|
| UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR);
|
| }
|
|
|
| -void ArcAuthService::CheckAndroidManagement(bool background_mode) {
|
| - // Do not send requests for Chrome OS managed users.
|
| - if (IsAccountManaged(profile_)) {
|
| - OnAndroidManagementPassed();
|
| - return;
|
| - }
|
| -
|
| - // Do not send requests for well-known consumer domains.
|
| - if (policy::BrowserPolicyConnector::IsNonEnterpriseUser(
|
| - profile_->GetProfileUserName())) {
|
| - OnAndroidManagementPassed();
|
| - return;
|
| - }
|
| -
|
| - android_management_checker_.reset(
|
| - new ArcAndroidManagementChecker(this, context_->token_service(),
|
| - context_->account_id(), background_mode));
|
| - if (background_mode)
|
| - OnAndroidManagementPassed();
|
| -}
|
| -
|
| void ArcAuthService::OnAndroidManagementChecked(
|
| policy::AndroidManagementClient::Result result) {
|
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| switch (result) {
|
| case policy::AndroidManagementClient::Result::RESULT_UNMANAGED:
|
| OnAndroidManagementPassed();
|
| break;
|
| case policy::AndroidManagementClient::Result::RESULT_MANAGED:
|
| - if (android_management_checker_->background_mode()) {
|
| - DisableArc();
|
| - return;
|
| - }
|
| ShutdownBridgeAndShowUI(
|
| UIPage::ERROR,
|
| l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR));
|
| @@ -927,6 +914,23 @@ void ArcAuthService::OnAndroidManagementChecked(
|
| }
|
| }
|
|
|
| +void ArcAuthService::OnBackgroundAndroidManagementChecked(
|
| + policy::AndroidManagementClient::Result result) {
|
| + DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
| + switch (result) {
|
| + case policy::AndroidManagementClient::Result::RESULT_UNMANAGED:
|
| + // Do nothing. ARC should be started already.
|
| + break;
|
| + case policy::AndroidManagementClient::Result::RESULT_MANAGED:
|
| + DisableArc();
|
| + break;
|
| + case policy::AndroidManagementClient::Result::RESULT_ERROR:
|
| + // This code should not be reached. For background check,
|
| + // retry_on_error should be set.
|
| + NOTREACHED();
|
| + }
|
| +}
|
| +
|
| void ArcAuthService::FetchAuthCode() {
|
| DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
|
|
|
|
|