Chromium Code Reviews| 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 41bf9da80aa1d4e06f7776497138f953a7f75231..5e56304b49c5da4d756a49f3df6f9a31103db7de 100644 |
| --- a/chrome/browser/chromeos/arc/arc_auth_service.cc |
| +++ b/chrome/browser/chromeos/arc/arc_auth_service.cc |
| @@ -12,8 +12,11 @@ |
| #include "base/lazy_instance.h" |
| #include "base/strings/stringprintf.h" |
| #include "base/threading/thread_checker.h" |
| +#include "chrome/browser/browser_process.h" |
| #include "chrome/browser/chromeos/arc/arc_auth_notification.h" |
| #include "chrome/browser/chromeos/arc/arc_optin_uma.h" |
| +#include "chrome/browser/chromeos/policy/android_management_client.h" |
| +#include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| #include "chrome/browser/extensions/extension_util.h" |
| #include "chrome/browser/policy/profile_policy_connector.h" |
| @@ -28,6 +31,8 @@ |
| #include "chrome/grit/generated_resources.h" |
| #include "chromeos/chromeos_switches.h" |
| #include "components/arc/arc_bridge_service.h" |
| +#include "components/policy/core/browser/browser_policy_connector.h" |
| +#include "components/policy/core/common/cloud/device_management_service.h" |
| #include "components/pref_registry/pref_registry_syncable.h" |
| #include "components/prefs/pref_service.h" |
| #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| @@ -231,6 +236,8 @@ void ArcAuthService::OnPrimaryUserProfilePrepared(Profile* profile) { |
| profile_, GURL(site_url)); |
| CHECK(storage_partition_); |
| + StartAndroidManagementClient(); |
| + |
| // In case UI is disabled we assume that ARC is opted-in. |
| if (!IsOptInVerificationDisabled()) { |
| pref_change_registrar_.Init(profile_->GetPrefs()); |
| @@ -305,8 +312,8 @@ void ArcAuthService::OnMergeSessionSuccess(const std::string& data) { |
| DCHECK(thread_checker.Get().CalledOnValidThread()); |
| DCHECK(!initial_opt_in_); |
| - context_prepared_ = true; |
| ShowUI(UIPage::LSO_PROGRESS, base::string16()); |
| + CheckAndroidManagement(); |
| } |
| void ArcAuthService::OnMergeSessionFailure( |
| @@ -321,6 +328,7 @@ void ArcAuthService::OnUbertokenSuccess(const std::string& token) { |
| merger_fetcher_.reset( |
| new GaiaAuthFetcher(this, GaiaConstants::kChromeOSSource, |
| storage_partition_->GetURLRequestContext())); |
| + auth_token_ = token; |
| merger_fetcher_->StartMergeSession(token, std::string()); |
| } |
| @@ -356,8 +364,8 @@ void ArcAuthService::OnOptInPreferenceChanged() { |
| initial_opt_in_ = true; |
| StartUI(); |
| } else { |
| - // Ready to start Arc. |
| - StartArc(); |
| + // Ready to start Arc, but check android management first. |
| + CheckAndroidManagement(); |
| } |
| UpdateEnabledStateUMA(true); |
| @@ -455,9 +463,6 @@ void ArcAuthService::StartLso() { |
| void ArcAuthService::CancelAuthCode() { |
| DCHECK(thread_checker.Get().CalledOnValidThread()); |
| - if (state_ != State::FETCHING_CODE) |
| - return; |
| - |
| // Update UMA with user cancel only if error is not currently shown. |
| if (ui_page_ != UIPage::ERROR && ui_page_ != UIPage::NO_PAGE) |
| UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); |
| @@ -515,6 +520,51 @@ void ArcAuthService::OnPrepareContextFailed() { |
| UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| } |
| +void ArcAuthService::StartAndroidManagementClient() { |
| + policy::BrowserPolicyConnectorChromeOS* connector = |
|
bartfab (slow)
2016/04/18 15:06:14
Nit: const pointer.
Polina Bondarenko
2016/04/20 13:37:45
Done.
|
| + g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
|
bartfab (slow)
2016/04/18 15:06:15
Nit: #include "chrome/browser/browser_process_plat
Polina Bondarenko
2016/04/20 13:37:45
Done.
|
| + policy::DeviceManagementService* service = |
|
bartfab (slow)
2016/04/18 15:06:14
Nit: const pointer.
Polina Bondarenko
2016/04/20 13:37:45
Done.
|
| + connector->device_management_service(); |
| + service->ScheduleInitialization(0); |
| + android_management_client_.reset(new policy::AndroidManagementClient( |
| + service, g_browser_process->system_request_context())); |
| +} |
| + |
| +void ArcAuthService::CheckAndroidManagement() { |
| + // No need to check Android management for Chrome OS managed users. |
|
bartfab (slow)
2016/04/18 15:06:15
Nit: Not just no need - you are only supposed to p
Polina Bondarenko
2016/04/20 13:37:45
Done.
|
| + if (policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile_) |
|
bartfab (slow)
2016/04/18 15:06:15
Nit: #include "chrome/browser/policy/profile_polic
Polina Bondarenko
2016/04/20 13:37:45
Done.
|
| + ->IsManaged()) { |
|
bartfab (slow)
2016/04/18 15:06:15
Nit: Indent.
Polina Bondarenko
2016/04/20 13:37:45
Done.
|
| + OnAndroidManagementChecked(true); |
| + return; |
| + } |
| + |
| + // No need to check Android management for well-known consumer domains. |
| + if (policy::BrowserPolicyConnector::IsNonEnterpriseUser( |
| + profile_->GetProfileUserName())) { |
|
bartfab (slow)
2016/04/18 15:06:14
Nit: Indent.
Polina Bondarenko
2016/04/20 13:37:44
Done.
|
| + OnAndroidManagementChecked(true); |
| + return; |
| + } |
| + |
| + android_management_client_->CheckAndroidManagement( |
| + auth_token_, base::Bind(&ArcAuthService::OnAndroidManagementChecked, |
| + base::Unretained(this))); |
| +} |
| + |
| +void ArcAuthService::OnAndroidManagementChecked(bool success) { |
| + if (success) { |
| + context_prepared_ = true; |
| + if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) |
| + ShowUI(UIPage::LSO, base::string16()); |
|
bartfab (slow)
2016/04/18 15:06:15
Nit: #include "base/strings/string16.h"
Polina Bondarenko
2016/04/20 13:37:45
Done.
|
| + else |
| + StartArc(); |
| + } else { |
| + ShutdownBridgeAndShowUI( |
| + UIPage::ERROR, |
| + l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_ENABLED_ERROR)); |
| + UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_ENABLED); |
| + } |
| +} |
| + |
| std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { |
| switch (state) { |
| case ArcAuthService::State::STOPPED: |