| 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 <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | |
| 12 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 13 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/logging.h" |
| 14 #include "base/strings/string16.h" |
| 14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 15 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
| 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/browser_process_platform_part.h" |
| 16 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" | 19 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" |
| 17 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" | 20 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" |
| 21 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 22 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 19 #include "chrome/browser/extensions/extension_util.h" | 23 #include "chrome/browser/extensions/extension_util.h" |
| 20 #include "chrome/browser/policy/profile_policy_connector.h" | 24 #include "chrome/browser/policy/profile_policy_connector.h" |
| 21 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 25 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 22 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 26 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 23 #include "chrome/browser/profiles/profile.h" | 27 #include "chrome/browser/profiles/profile.h" |
| 24 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 28 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 25 #include "chrome/browser/signin/signin_manager_factory.h" | 29 #include "chrome/browser/signin/signin_manager_factory.h" |
| 26 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" | 30 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" |
| 27 #include "chrome/browser/ui/extensions/app_launch_params.h" | 31 #include "chrome/browser/ui/extensions/app_launch_params.h" |
| 28 #include "chrome/browser/ui/extensions/application_launch.h" | 32 #include "chrome/browser/ui/extensions/application_launch.h" |
| 29 #include "chrome/common/pref_names.h" | 33 #include "chrome/common/pref_names.h" |
| 30 #include "chrome/grit/generated_resources.h" | 34 #include "chrome/grit/generated_resources.h" |
| 31 #include "chromeos/chromeos_switches.h" | 35 #include "chromeos/chromeos_switches.h" |
| 32 #include "components/arc/arc_bridge_service.h" | 36 #include "components/arc/arc_bridge_service.h" |
| 37 #include "components/policy/core/browser/browser_policy_connector.h" |
| 38 #include "components/policy/core/common/cloud/device_management_service.h" |
| 33 #include "components/pref_registry/pref_registry_syncable.h" | 39 #include "components/pref_registry/pref_registry_syncable.h" |
| 34 #include "components/prefs/pref_service.h" | 40 #include "components/prefs/pref_service.h" |
| 35 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 41 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 36 #include "components/signin/core/browser/signin_manager_base.h" | 42 #include "components/signin/core/browser/signin_manager_base.h" |
| 37 #include "components/syncable_prefs/pref_service_syncable.h" | 43 #include "components/syncable_prefs/pref_service_syncable.h" |
| 38 #include "components/user_manager/user.h" | 44 #include "components/user_manager/user.h" |
| 39 #include "content/public/browser/storage_partition.h" | 45 #include "content/public/browser/storage_partition.h" |
| 40 #include "content/public/common/url_constants.h" | 46 #include "content/public/common/url_constants.h" |
| 41 #include "extensions/browser/app_window/app_window_registry.h" | 47 #include "extensions/browser/app_window/app_window_registry.h" |
| 42 #include "extensions/browser/extension_prefs.h" | 48 #include "extensions/browser/extension_prefs.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 54 base::LazyInstance<base::ThreadChecker> thread_checker = | 60 base::LazyInstance<base::ThreadChecker> thread_checker = |
| 55 LAZY_INSTANCE_INITIALIZER; | 61 LAZY_INSTANCE_INITIALIZER; |
| 56 | 62 |
| 57 const char kPlayStoreAppId[] = "gpkmicpkkebkmabiaedjognfppcchdfa"; | 63 const char kPlayStoreAppId[] = "gpkmicpkkebkmabiaedjognfppcchdfa"; |
| 58 const char kArcSupportExtensionId[] = "cnbgggchhmkkdmeppjobngjoejnihlei"; | 64 const char kArcSupportExtensionId[] = "cnbgggchhmkkdmeppjobngjoejnihlei"; |
| 59 const char kArcSupportStorageId[] = "arc_support"; | 65 const char kArcSupportStorageId[] = "arc_support"; |
| 60 | 66 |
| 61 // Skip creating UI in unit tests | 67 // Skip creating UI in unit tests |
| 62 bool disable_ui_for_testing = false; | 68 bool disable_ui_for_testing = false; |
| 63 | 69 |
| 70 // The Android management check is disabled by default, it's used only for |
| 71 // testing. |
| 72 bool enable_check_android_management_for_testing = false; |
| 73 |
| 64 const char kStateStopped[] = "STOPPED"; | 74 const char kStateStopped[] = "STOPPED"; |
| 65 const char kStateFetchingCode[] = "FETCHING_CODE"; | 75 const char kStateFetchingCode[] = "FETCHING_CODE"; |
| 66 const char kStateActive[] = "ACTIVE"; | 76 const char kStateActive[] = "ACTIVE"; |
| 77 |
| 67 } // namespace | 78 } // namespace |
| 68 | 79 |
| 69 ArcAuthService::ArcAuthService(ArcBridgeService* bridge_service) | 80 ArcAuthService::ArcAuthService(ArcBridgeService* bridge_service) |
| 70 : ArcService(bridge_service), binding_(this) { | 81 : ArcService(bridge_service), binding_(this), weak_ptr_factory_(this) { |
| 71 DCHECK(!arc_auth_service); | 82 DCHECK(!arc_auth_service); |
| 72 DCHECK(thread_checker.Get().CalledOnValidThread()); | 83 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 73 | 84 |
| 74 arc_auth_service = this; | 85 arc_auth_service = this; |
| 75 | 86 |
| 76 arc_bridge_service()->AddObserver(this); | 87 arc_bridge_service()->AddObserver(this); |
| 77 } | 88 } |
| 78 | 89 |
| 79 ArcAuthService::~ArcAuthService() { | 90 ArcAuthService::~ArcAuthService() { |
| 80 DCHECK(thread_checker.Get().CalledOnValidThread()); | 91 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 105 void ArcAuthService::DisableUIForTesting() { | 116 void ArcAuthService::DisableUIForTesting() { |
| 106 disable_ui_for_testing = true; | 117 disable_ui_for_testing = true; |
| 107 } | 118 } |
| 108 | 119 |
| 109 // static | 120 // static |
| 110 bool ArcAuthService::IsOptInVerificationDisabled() { | 121 bool ArcAuthService::IsOptInVerificationDisabled() { |
| 111 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 122 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 112 chromeos::switches::kDisableArcOptInVerification); | 123 chromeos::switches::kDisableArcOptInVerification); |
| 113 } | 124 } |
| 114 | 125 |
| 126 // static |
| 127 void ArcAuthService::EnableCheckAndroidManagementForTesting() { |
| 128 enable_check_android_management_for_testing = true; |
| 129 } |
| 130 |
| 115 void ArcAuthService::OnAuthInstanceReady() { | 131 void ArcAuthService::OnAuthInstanceReady() { |
| 116 arc_bridge_service()->auth_instance()->Init( | 132 arc_bridge_service()->auth_instance()->Init( |
| 117 binding_.CreateInterfacePtrAndBind()); | 133 binding_.CreateInterfacePtrAndBind()); |
| 118 } | 134 } |
| 119 | 135 |
| 120 std::string ArcAuthService::GetAndResetAuthCode() { | 136 std::string ArcAuthService::GetAndResetAuthCode() { |
| 121 DCHECK(thread_checker.Get().CalledOnValidThread()); | 137 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 122 std::string auth_code; | 138 std::string auth_code; |
| 123 auth_code_.swap(auth_code); | 139 auth_code_.swap(auth_code); |
| 124 return auth_code; | 140 return auth_code; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 prefs::kArcEnabled, this); | 261 prefs::kArcEnabled, this); |
| 246 | 262 |
| 247 // Reuse storage used in ARC OptIn platform app. | 263 // Reuse storage used in ARC OptIn platform app. |
| 248 const std::string site_url = | 264 const std::string site_url = |
| 249 base::StringPrintf("%s://%s/persist?%s", content::kGuestScheme, | 265 base::StringPrintf("%s://%s/persist?%s", content::kGuestScheme, |
| 250 kArcSupportExtensionId, kArcSupportStorageId); | 266 kArcSupportExtensionId, kArcSupportStorageId); |
| 251 storage_partition_ = content::BrowserContext::GetStoragePartitionForSite( | 267 storage_partition_ = content::BrowserContext::GetStoragePartitionForSite( |
| 252 profile_, GURL(site_url)); | 268 profile_, GURL(site_url)); |
| 253 CHECK(storage_partition_); | 269 CHECK(storage_partition_); |
| 254 | 270 |
| 271 // Get token service and account ID to fetch auth tokens. |
| 272 token_service_ = ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| 273 const SigninManagerBase* const signin_manager = |
| 274 SigninManagerFactory::GetForProfile(profile_); |
| 275 CHECK(token_service_ && signin_manager); |
| 276 account_id_ = signin_manager->GetAuthenticatedAccountId(); |
| 277 |
| 255 // In case UI is disabled we assume that ARC is opted-in. | 278 // In case UI is disabled we assume that ARC is opted-in. |
| 256 if (!IsOptInVerificationDisabled()) { | 279 if (!IsOptInVerificationDisabled()) { |
| 280 if (!disable_ui_for_testing || enable_check_android_management_for_testing) |
| 281 StartAndroidManagementClient(); |
| 282 |
| 257 pref_change_registrar_.Init(profile_->GetPrefs()); | 283 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 258 pref_change_registrar_.Add( | 284 pref_change_registrar_.Add( |
| 259 prefs::kArcEnabled, | 285 prefs::kArcEnabled, |
| 260 base::Bind(&ArcAuthService::OnOptInPreferenceChanged, | 286 base::Bind(&ArcAuthService::OnOptInPreferenceChanged, |
| 261 base::Unretained(this))); | 287 weak_ptr_factory_.GetWeakPtr())); |
| 262 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { | 288 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { |
| 263 OnOptInPreferenceChanged(); | 289 OnOptInPreferenceChanged(); |
| 264 } else { | 290 } else { |
| 265 UpdateEnabledStateUMA(false); | 291 UpdateEnabledStateUMA(false); |
| 266 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); | 292 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); |
| 267 OnIsSyncingChanged(); | 293 OnIsSyncingChanged(); |
| 268 } | 294 } |
| 269 } else { | 295 } else { |
| 270 auth_code_.clear(); | 296 auth_code_.clear(); |
| 271 StartArc(); | 297 CheckAndroidManagement(); |
| 272 } | 298 } |
| 273 } | 299 } |
| 274 | 300 |
| 275 void ArcAuthService::OnIsSyncingChanged() { | 301 void ArcAuthService::OnIsSyncingChanged() { |
| 276 syncable_prefs::PrefServiceSyncable* const pref_service_syncable = | 302 syncable_prefs::PrefServiceSyncable* const pref_service_syncable = |
| 277 PrefServiceSyncableFromProfile(profile_); | 303 PrefServiceSyncableFromProfile(profile_); |
| 278 if (!pref_service_syncable->IsSyncing()) | 304 if (!pref_service_syncable->IsSyncing()) |
| 279 return; | 305 return; |
| 280 | 306 |
| 281 pref_service_syncable->RemoveObserver(this); | 307 pref_service_syncable->RemoveObserver(this); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 320 | 346 |
| 321 OpenApplication(CreateAppLaunchParamsUserContainer( | 347 OpenApplication(CreateAppLaunchParamsUserContainer( |
| 322 profile_, extension, NEW_WINDOW, extensions::SOURCE_CHROME_INTERNAL)); | 348 profile_, extension, NEW_WINDOW, extensions::SOURCE_CHROME_INTERNAL)); |
| 323 } | 349 } |
| 324 | 350 |
| 325 void ArcAuthService::OnMergeSessionSuccess(const std::string& data) { | 351 void ArcAuthService::OnMergeSessionSuccess(const std::string& data) { |
| 326 DCHECK(thread_checker.Get().CalledOnValidThread()); | 352 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 327 | 353 |
| 328 DCHECK(!initial_opt_in_); | 354 DCHECK(!initial_opt_in_); |
| 329 context_prepared_ = true; | 355 context_prepared_ = true; |
| 330 ShowUI(UIPage::LSO_PROGRESS, base::string16()); | 356 CheckAndroidManagement(); |
| 331 } | 357 } |
| 332 | 358 |
| 333 void ArcAuthService::OnMergeSessionFailure( | 359 void ArcAuthService::OnMergeSessionFailure( |
| 334 const GoogleServiceAuthError& error) { | 360 const GoogleServiceAuthError& error) { |
| 335 DCHECK(thread_checker.Get().CalledOnValidThread()); | 361 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 336 VLOG(2) << "Failed to merge gaia session " << error.ToString() << "."; | 362 VLOG(2) << "Failed to merge gaia session " << error.ToString() << "."; |
| 337 OnPrepareContextFailed(); | 363 OnPrepareContextFailed(); |
| 338 } | 364 } |
| 339 | 365 |
| 340 void ArcAuthService::OnUbertokenSuccess(const std::string& token) { | 366 void ArcAuthService::OnUbertokenSuccess(const std::string& token) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 if (state_ == State::ACTIVE) | 403 if (state_ == State::ACTIVE) |
| 378 return; | 404 return; |
| 379 CloseUI(); | 405 CloseUI(); |
| 380 auth_code_.clear(); | 406 auth_code_.clear(); |
| 381 | 407 |
| 382 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { | 408 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { |
| 383 // Need pre-fetch auth code and show OptIn UI if needed. | 409 // Need pre-fetch auth code and show OptIn UI if needed. |
| 384 initial_opt_in_ = true; | 410 initial_opt_in_ = true; |
| 385 StartUI(); | 411 StartUI(); |
| 386 } else { | 412 } else { |
| 387 // Ready to start Arc. | 413 // Ready to start Arc, but check Android management first. |
| 388 StartArc(); | 414 if (!disable_ui_for_testing || |
| 415 enable_check_android_management_for_testing) { |
| 416 CheckAndroidManagement(); |
| 417 } else { |
| 418 StartArc(); |
| 419 } |
| 389 } | 420 } |
| 390 | 421 |
| 391 UpdateEnabledStateUMA(true); | 422 UpdateEnabledStateUMA(true); |
| 392 } | 423 } |
| 393 | 424 |
| 394 void ArcAuthService::ShutdownBridge() { | 425 void ArcAuthService::ShutdownBridge() { |
| 395 playstore_launcher_.reset(); | 426 playstore_launcher_.reset(); |
| 396 auth_callback_.reset(); | 427 auth_callback_.reset(); |
| 397 ubertoken_fethcher_.reset(); | 428 ubertoken_fethcher_.reset(); |
| 398 merger_fetcher_.reset(); | 429 merger_fetcher_.reset(); |
| 430 token_service_ = nullptr; |
| 431 account_id_ = ""; |
| 399 arc_bridge_service()->Shutdown(); | 432 arc_bridge_service()->Shutdown(); |
| 400 SetState(State::STOPPED); | 433 SetState(State::STOPPED); |
| 434 FOR_EACH_OBSERVER(Observer, observer_list_, OnShutdownBridge()); |
| 401 } | 435 } |
| 402 | 436 |
| 403 void ArcAuthService::ShutdownBridgeAndCloseUI() { | 437 void ArcAuthService::ShutdownBridgeAndCloseUI() { |
| 404 ShutdownBridge(); | 438 ShutdownBridge(); |
| 405 CloseUI(); | 439 CloseUI(); |
| 406 } | 440 } |
| 407 | 441 |
| 408 void ArcAuthService::ShutdownBridgeAndShowUI(UIPage page, | 442 void ArcAuthService::ShutdownBridgeAndShowUI(UIPage page, |
| 409 const base::string16& status) { | 443 const base::string16& status) { |
| 410 ShutdownBridge(); | 444 ShutdownBridge(); |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 if (ui_page_ == UIPage::ERROR) | 506 if (ui_page_ == UIPage::ERROR) |
| 473 UpdateOptInActionUMA(OptInActionType::RETRY); | 507 UpdateOptInActionUMA(OptInActionType::RETRY); |
| 474 | 508 |
| 475 initial_opt_in_ = false; | 509 initial_opt_in_ = false; |
| 476 StartUI(); | 510 StartUI(); |
| 477 } | 511 } |
| 478 | 512 |
| 479 void ArcAuthService::CancelAuthCode() { | 513 void ArcAuthService::CancelAuthCode() { |
| 480 DCHECK(thread_checker.Get().CalledOnValidThread()); | 514 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 481 | 515 |
| 482 if (state_ != State::FETCHING_CODE) | 516 if (state_ != State::FETCHING_CODE && ui_page_ != UIPage::ERROR) |
| 483 return; | 517 return; |
| 484 | 518 |
| 485 // Update UMA with user cancel only if error is not currently shown. | 519 // Update UMA with user cancel only if error is not currently shown. |
| 486 if (ui_page_ != UIPage::ERROR && ui_page_ != UIPage::NO_PAGE) | 520 if (ui_page_ != UIPage::ERROR && ui_page_ != UIPage::NO_PAGE) |
| 487 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); | 521 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); |
| 488 | 522 |
| 489 DisableArc(); | 523 DisableArc(); |
| 490 } | 524 } |
| 491 | 525 |
| 492 void ArcAuthService::EnableArc() { | 526 void ArcAuthService::EnableArc() { |
| 493 DCHECK(thread_checker.Get().CalledOnValidThread()); | 527 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 494 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 528 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| 495 } | 529 } |
| 496 | 530 |
| 497 void ArcAuthService::DisableArc() { | 531 void ArcAuthService::DisableArc() { |
| 498 DCHECK(thread_checker.Get().CalledOnValidThread()); | 532 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 499 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); | 533 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); |
| 500 } | 534 } |
| 501 | 535 |
| 502 void ArcAuthService::PrepareContext() { | 536 void ArcAuthService::PrepareContext() { |
| 503 DCHECK(thread_checker.Get().CalledOnValidThread()); | 537 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 504 | 538 |
| 505 // Get auth token to continue. | |
| 506 ProfileOAuth2TokenService* token_service = | |
| 507 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | |
| 508 SigninManagerBase* signin_manager = | |
| 509 SigninManagerFactory::GetForProfile(profile_); | |
| 510 CHECK(token_service && signin_manager); | |
| 511 const std::string& account_id = signin_manager->GetAuthenticatedAccountId(); | |
| 512 ubertoken_fethcher_.reset( | 539 ubertoken_fethcher_.reset( |
| 513 new UbertokenFetcher(token_service, this, GaiaConstants::kChromeOSSource, | 540 new UbertokenFetcher(token_service_, this, GaiaConstants::kChromeOSSource, |
| 514 storage_partition_->GetURLRequestContext())); | 541 storage_partition_->GetURLRequestContext())); |
| 515 ubertoken_fethcher_->StartFetchingToken(account_id); | 542 ubertoken_fethcher_->StartFetchingToken(account_id_); |
| 516 } | 543 } |
| 517 | 544 |
| 518 void ArcAuthService::StartUI() { | 545 void ArcAuthService::StartUI() { |
| 519 DCHECK(thread_checker.Get().CalledOnValidThread()); | 546 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 520 | 547 |
| 521 SetState(State::FETCHING_CODE); | 548 SetState(State::FETCHING_CODE); |
| 522 | 549 |
| 523 if (initial_opt_in_) { | 550 if (initial_opt_in_) { |
| 524 initial_opt_in_ = false; | 551 initial_opt_in_ = false; |
| 525 ShowUI(UIPage::START, base::string16()); | 552 ShowUI(UIPage::START, base::string16()); |
| 526 } else if (context_prepared_) { | 553 } else if (context_prepared_) { |
| 527 ShowUI(UIPage::LSO_PROGRESS, base::string16()); | 554 CheckAndroidManagement(); |
| 528 } else { | 555 } else { |
| 529 PrepareContext(); | 556 PrepareContext(); |
| 530 } | 557 } |
| 531 } | 558 } |
| 532 | 559 |
| 533 void ArcAuthService::OnPrepareContextFailed() { | 560 void ArcAuthService::OnPrepareContextFailed() { |
| 534 DCHECK_EQ(state_, State::FETCHING_CODE); | 561 DCHECK_EQ(state_, State::FETCHING_CODE); |
| 535 | 562 |
| 536 ShutdownBridgeAndShowUI( | 563 ShutdownBridgeAndShowUI( |
| 537 UIPage::ERROR, | 564 UIPage::ERROR, |
| 538 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); | 565 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); |
| 539 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 566 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 540 } | 567 } |
| 541 | 568 |
| 569 void ArcAuthService::StartAndroidManagementClient() { |
| 570 policy::BrowserPolicyConnectorChromeOS* const connector = |
| 571 g_browser_process->platform_part()->browser_policy_connector_chromeos(); |
| 572 policy::DeviceManagementService* const service = |
| 573 connector->device_management_service(); |
| 574 service->ScheduleInitialization(0); |
| 575 android_management_client_.reset(new policy::AndroidManagementClient( |
| 576 service, g_browser_process->system_request_context(), account_id_, |
| 577 token_service_)); |
| 578 } |
| 579 |
| 580 void ArcAuthService::CheckAndroidManagement() { |
| 581 // Do not send requests for Chrome OS managed users. |
| 582 if (policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile_) |
| 583 ->IsManaged()) { |
| 584 StartArcIfSignedIn(); |
| 585 return; |
| 586 } |
| 587 |
| 588 // Do not send requests for well-known consumer domains. |
| 589 if (policy::BrowserPolicyConnector::IsNonEnterpriseUser( |
| 590 profile_->GetProfileUserName())) { |
| 591 StartArcIfSignedIn(); |
| 592 return; |
| 593 } |
| 594 |
| 595 android_management_client_->StartCheckAndroidManagement( |
| 596 base::Bind(&ArcAuthService::OnAndroidManagementChecked, |
| 597 weak_ptr_factory_.GetWeakPtr())); |
| 598 } |
| 599 |
| 600 void ArcAuthService::OnAndroidManagementChecked( |
| 601 policy::AndroidManagementClient::Result result) { |
| 602 switch (result) { |
| 603 case policy::AndroidManagementClient::Result::RESULT_UNMANAGED: |
| 604 StartArcIfSignedIn(); |
| 605 break; |
| 606 case policy::AndroidManagementClient::Result::RESULT_MANAGED: |
| 607 ShutdownBridgeAndShowUI( |
| 608 UIPage::ERROR, |
| 609 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR)); |
| 610 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); |
| 611 break; |
| 612 case policy::AndroidManagementClient::Result::RESULT_ERROR: |
| 613 ShutdownBridgeAndShowUI( |
| 614 UIPage::ERROR, |
| 615 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); |
| 616 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 617 break; |
| 618 default: |
| 619 NOTREACHED(); |
| 620 } |
| 621 } |
| 622 |
| 623 void ArcAuthService::StartArcIfSignedIn() { |
| 624 if (profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn) || |
| 625 IsOptInVerificationDisabled()) { |
| 626 StartArc(); |
| 627 } else { |
| 628 ShowUI(UIPage::LSO_PROGRESS, base::string16()); |
| 629 } |
| 630 } |
| 631 |
| 542 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { | 632 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { |
| 543 switch (state) { | 633 switch (state) { |
| 544 case ArcAuthService::State::STOPPED: | 634 case ArcAuthService::State::STOPPED: |
| 545 return os << kStateStopped; | 635 return os << kStateStopped; |
| 546 case ArcAuthService::State::FETCHING_CODE: | 636 case ArcAuthService::State::FETCHING_CODE: |
| 547 return os << kStateFetchingCode; | 637 return os << kStateFetchingCode; |
| 548 case ArcAuthService::State::ACTIVE: | 638 case ArcAuthService::State::ACTIVE: |
| 549 return os << kStateActive; | 639 return os << kStateActive; |
| 550 default: | 640 default: |
| 551 NOTREACHED(); | 641 NOTREACHED(); |
| 552 return os; | 642 return os; |
| 553 } | 643 } |
| 554 } | 644 } |
| 555 | 645 |
| 556 } // namespace arc | 646 } // namespace arc |
| OLD | NEW |