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