Chromium Code Reviews| 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 <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| 11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
| 14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 15 #include "chrome/browser/browser_process.h" | |
| 15 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" | 16 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" |
| 16 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" | 17 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" |
| 18 #include "chrome/browser/chromeos/policy/android_management_client.h" | |
| 19 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" | |
| 17 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 20 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 18 #include "chrome/browser/extensions/extension_util.h" | 21 #include "chrome/browser/extensions/extension_util.h" |
| 19 #include "chrome/browser/policy/profile_policy_connector.h" | 22 #include "chrome/browser/policy/profile_policy_connector.h" |
| 20 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 23 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 21 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 24 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 22 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 23 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 26 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 24 #include "chrome/browser/signin/signin_manager_factory.h" | 27 #include "chrome/browser/signin/signin_manager_factory.h" |
| 25 #include "chrome/browser/ui/extensions/app_launch_params.h" | 28 #include "chrome/browser/ui/extensions/app_launch_params.h" |
| 26 #include "chrome/browser/ui/extensions/application_launch.h" | 29 #include "chrome/browser/ui/extensions/application_launch.h" |
| 27 #include "chrome/common/pref_names.h" | 30 #include "chrome/common/pref_names.h" |
| 28 #include "chrome/grit/generated_resources.h" | 31 #include "chrome/grit/generated_resources.h" |
| 29 #include "chromeos/chromeos_switches.h" | 32 #include "chromeos/chromeos_switches.h" |
| 30 #include "components/arc/arc_bridge_service.h" | 33 #include "components/arc/arc_bridge_service.h" |
| 34 #include "components/policy/core/browser/browser_policy_connector.h" | |
| 35 #include "components/policy/core/common/cloud/device_management_service.h" | |
| 31 #include "components/pref_registry/pref_registry_syncable.h" | 36 #include "components/pref_registry/pref_registry_syncable.h" |
| 32 #include "components/prefs/pref_service.h" | 37 #include "components/prefs/pref_service.h" |
| 33 #include "components/signin/core/browser/profile_oauth2_token_service.h" | 38 #include "components/signin/core/browser/profile_oauth2_token_service.h" |
| 34 #include "components/signin/core/browser/signin_manager_base.h" | 39 #include "components/signin/core/browser/signin_manager_base.h" |
| 35 #include "components/syncable_prefs/pref_service_syncable.h" | 40 #include "components/syncable_prefs/pref_service_syncable.h" |
| 36 #include "components/user_manager/user.h" | 41 #include "components/user_manager/user.h" |
| 37 #include "content/public/browser/storage_partition.h" | 42 #include "content/public/browser/storage_partition.h" |
| 38 #include "content/public/common/url_constants.h" | 43 #include "content/public/common/url_constants.h" |
| 39 #include "extensions/browser/app_window/app_window_registry.h" | 44 #include "extensions/browser/app_window/app_window_registry.h" |
| 40 #include "extensions/browser/extension_prefs.h" | 45 #include "extensions/browser/extension_prefs.h" |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 224 prefs::kArcEnabled, this); | 229 prefs::kArcEnabled, this); |
| 225 | 230 |
| 226 // Reuse storage used in ARC OptIn platform app. | 231 // Reuse storage used in ARC OptIn platform app. |
| 227 const std::string site_url = | 232 const std::string site_url = |
| 228 base::StringPrintf("%s://%s/persist?%s", content::kGuestScheme, | 233 base::StringPrintf("%s://%s/persist?%s", content::kGuestScheme, |
| 229 kArcSupportExtensionId, kArcSupportStorageId); | 234 kArcSupportExtensionId, kArcSupportStorageId); |
| 230 storage_partition_ = content::BrowserContext::GetStoragePartitionForSite( | 235 storage_partition_ = content::BrowserContext::GetStoragePartitionForSite( |
| 231 profile_, GURL(site_url)); | 236 profile_, GURL(site_url)); |
| 232 CHECK(storage_partition_); | 237 CHECK(storage_partition_); |
| 233 | 238 |
| 239 StartAndroidManagementClient(); | |
| 240 | |
| 234 // In case UI is disabled we assume that ARC is opted-in. | 241 // In case UI is disabled we assume that ARC is opted-in. |
| 235 if (!IsOptInVerificationDisabled()) { | 242 if (!IsOptInVerificationDisabled()) { |
| 236 pref_change_registrar_.Init(profile_->GetPrefs()); | 243 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 237 pref_change_registrar_.Add( | 244 pref_change_registrar_.Add( |
| 238 prefs::kArcEnabled, | 245 prefs::kArcEnabled, |
| 239 base::Bind(&ArcAuthService::OnOptInPreferenceChanged, | 246 base::Bind(&ArcAuthService::OnOptInPreferenceChanged, |
| 240 base::Unretained(this))); | 247 base::Unretained(this))); |
| 241 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { | 248 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { |
| 242 OnOptInPreferenceChanged(); | 249 OnOptInPreferenceChanged(); |
| 243 } else { | 250 } else { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 extensions::util::IsAppLaunchable(kArcSupportExtensionId, profile_)); | 305 extensions::util::IsAppLaunchable(kArcSupportExtensionId, profile_)); |
| 299 | 306 |
| 300 OpenApplication(CreateAppLaunchParamsUserContainer( | 307 OpenApplication(CreateAppLaunchParamsUserContainer( |
| 301 profile_, extension, NEW_WINDOW, extensions::SOURCE_CHROME_INTERNAL)); | 308 profile_, extension, NEW_WINDOW, extensions::SOURCE_CHROME_INTERNAL)); |
| 302 } | 309 } |
| 303 | 310 |
| 304 void ArcAuthService::OnMergeSessionSuccess(const std::string& data) { | 311 void ArcAuthService::OnMergeSessionSuccess(const std::string& data) { |
| 305 DCHECK(thread_checker.Get().CalledOnValidThread()); | 312 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 306 | 313 |
| 307 DCHECK(!initial_opt_in_); | 314 DCHECK(!initial_opt_in_); |
| 308 context_prepared_ = true; | |
| 309 ShowUI(UIPage::LSO_PROGRESS, base::string16()); | 315 ShowUI(UIPage::LSO_PROGRESS, base::string16()); |
| 316 CheckAndroidManagement(); | |
| 310 } | 317 } |
| 311 | 318 |
| 312 void ArcAuthService::OnMergeSessionFailure( | 319 void ArcAuthService::OnMergeSessionFailure( |
| 313 const GoogleServiceAuthError& error) { | 320 const GoogleServiceAuthError& error) { |
| 314 DCHECK(thread_checker.Get().CalledOnValidThread()); | 321 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 315 VLOG(2) << "Failed to merge gaia session " << error.ToString() << "."; | 322 VLOG(2) << "Failed to merge gaia session " << error.ToString() << "."; |
| 316 OnPrepareContextFailed(); | 323 OnPrepareContextFailed(); |
| 317 } | 324 } |
| 318 | 325 |
| 319 void ArcAuthService::OnUbertokenSuccess(const std::string& token) { | 326 void ArcAuthService::OnUbertokenSuccess(const std::string& token) { |
| 320 DCHECK(thread_checker.Get().CalledOnValidThread()); | 327 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 321 merger_fetcher_.reset( | 328 merger_fetcher_.reset( |
| 322 new GaiaAuthFetcher(this, GaiaConstants::kChromeOSSource, | 329 new GaiaAuthFetcher(this, GaiaConstants::kChromeOSSource, |
| 323 storage_partition_->GetURLRequestContext())); | 330 storage_partition_->GetURLRequestContext())); |
| 331 auth_token_ = token; | |
| 324 merger_fetcher_->StartMergeSession(token, std::string()); | 332 merger_fetcher_->StartMergeSession(token, std::string()); |
| 325 } | 333 } |
| 326 | 334 |
| 327 void ArcAuthService::OnUbertokenFailure(const GoogleServiceAuthError& error) { | 335 void ArcAuthService::OnUbertokenFailure(const GoogleServiceAuthError& error) { |
| 328 DCHECK(thread_checker.Get().CalledOnValidThread()); | 336 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 329 VLOG(2) << "Failed to get ubertoken " << error.ToString() << "."; | 337 VLOG(2) << "Failed to get ubertoken " << error.ToString() << "."; |
| 330 OnPrepareContextFailed(); | 338 OnPrepareContextFailed(); |
| 331 } | 339 } |
| 332 | 340 |
| 333 void ArcAuthService::OnSyncedPrefChanged(const std::string& path, | 341 void ArcAuthService::OnSyncedPrefChanged(const std::string& path, |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 349 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { | 357 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { |
| 350 if (state_ != State::ACTIVE) { | 358 if (state_ != State::ACTIVE) { |
| 351 CloseUI(); | 359 CloseUI(); |
| 352 auth_code_.clear(); | 360 auth_code_.clear(); |
| 353 | 361 |
| 354 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { | 362 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { |
| 355 // Need pre-fetch auth code and show OptIn UI if needed. | 363 // Need pre-fetch auth code and show OptIn UI if needed. |
| 356 initial_opt_in_ = true; | 364 initial_opt_in_ = true; |
| 357 StartUI(); | 365 StartUI(); |
| 358 } else { | 366 } else { |
| 359 // Ready to start Arc. | 367 // Ready to start Arc, but check android management first. |
| 360 StartArc(); | 368 CheckAndroidManagement(); |
| 361 } | 369 } |
| 362 | 370 |
| 363 UpdateEnabledStateUMA(true); | 371 UpdateEnabledStateUMA(true); |
| 364 } | 372 } |
| 365 } else { | 373 } else { |
| 366 if (state_ != State::STOPPED) | 374 if (state_ != State::STOPPED) |
| 367 UpdateEnabledStateUMA(false); | 375 UpdateEnabledStateUMA(false); |
| 368 ShutdownBridgeAndCloseUI(); | 376 ShutdownBridgeAndCloseUI(); |
| 369 } | 377 } |
| 370 } | 378 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 448 if (ui_page_ == UIPage::ERROR) | 456 if (ui_page_ == UIPage::ERROR) |
| 449 UpdateOptInActionUMA(OptInActionType::RETRY); | 457 UpdateOptInActionUMA(OptInActionType::RETRY); |
| 450 | 458 |
| 451 initial_opt_in_ = false; | 459 initial_opt_in_ = false; |
| 452 StartUI(); | 460 StartUI(); |
| 453 } | 461 } |
| 454 | 462 |
| 455 void ArcAuthService::CancelAuthCode() { | 463 void ArcAuthService::CancelAuthCode() { |
| 456 DCHECK(thread_checker.Get().CalledOnValidThread()); | 464 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 457 | 465 |
| 458 if (state_ != State::FETCHING_CODE) | |
| 459 return; | |
| 460 | |
| 461 // Update UMA with user cancel only if error is not currently shown. | 466 // Update UMA with user cancel only if error is not currently shown. |
| 462 if (ui_page_ != UIPage::ERROR && ui_page_ != UIPage::NO_PAGE) | 467 if (ui_page_ != UIPage::ERROR && ui_page_ != UIPage::NO_PAGE) |
| 463 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); | 468 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); |
| 464 | 469 |
| 465 DisableArc(); | 470 DisableArc(); |
| 466 } | 471 } |
| 467 | 472 |
| 468 void ArcAuthService::EnableArc() { | 473 void ArcAuthService::EnableArc() { |
| 469 DCHECK(thread_checker.Get().CalledOnValidThread()); | 474 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 470 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 475 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 508 | 513 |
| 509 void ArcAuthService::OnPrepareContextFailed() { | 514 void ArcAuthService::OnPrepareContextFailed() { |
| 510 DCHECK_EQ(state_, State::FETCHING_CODE); | 515 DCHECK_EQ(state_, State::FETCHING_CODE); |
| 511 | 516 |
| 512 ShutdownBridgeAndShowUI( | 517 ShutdownBridgeAndShowUI( |
| 513 UIPage::ERROR, | 518 UIPage::ERROR, |
| 514 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); | 519 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); |
| 515 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 520 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 516 } | 521 } |
| 517 | 522 |
| 523 void ArcAuthService::StartAndroidManagementClient() { | |
| 524 policy::BrowserPolicyConnectorChromeOS* connector = | |
|
bartfab (slow)
2016/04/18 15:06:14
Nit: const pointer.
Polina Bondarenko
2016/04/20 13:37:45
Done.
| |
| 525 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.
| |
| 526 policy::DeviceManagementService* service = | |
|
bartfab (slow)
2016/04/18 15:06:14
Nit: const pointer.
Polina Bondarenko
2016/04/20 13:37:45
Done.
| |
| 527 connector->device_management_service(); | |
| 528 service->ScheduleInitialization(0); | |
| 529 android_management_client_.reset(new policy::AndroidManagementClient( | |
| 530 service, g_browser_process->system_request_context())); | |
| 531 } | |
| 532 | |
| 533 void ArcAuthService::CheckAndroidManagement() { | |
| 534 // 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.
| |
| 535 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.
| |
| 536 ->IsManaged()) { | |
|
bartfab (slow)
2016/04/18 15:06:15
Nit: Indent.
Polina Bondarenko
2016/04/20 13:37:45
Done.
| |
| 537 OnAndroidManagementChecked(true); | |
| 538 return; | |
| 539 } | |
| 540 | |
| 541 // No need to check Android management for well-known consumer domains. | |
| 542 if (policy::BrowserPolicyConnector::IsNonEnterpriseUser( | |
| 543 profile_->GetProfileUserName())) { | |
|
bartfab (slow)
2016/04/18 15:06:14
Nit: Indent.
Polina Bondarenko
2016/04/20 13:37:44
Done.
| |
| 544 OnAndroidManagementChecked(true); | |
| 545 return; | |
| 546 } | |
| 547 | |
| 548 android_management_client_->CheckAndroidManagement( | |
| 549 auth_token_, base::Bind(&ArcAuthService::OnAndroidManagementChecked, | |
| 550 base::Unretained(this))); | |
| 551 } | |
| 552 | |
| 553 void ArcAuthService::OnAndroidManagementChecked(bool success) { | |
| 554 if (success) { | |
| 555 context_prepared_ = true; | |
| 556 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) | |
| 557 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.
| |
| 558 else | |
| 559 StartArc(); | |
| 560 } else { | |
| 561 ShutdownBridgeAndShowUI( | |
| 562 UIPage::ERROR, | |
| 563 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_ENABLED_ERROR)); | |
| 564 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_ENABLED); | |
| 565 } | |
| 566 } | |
| 567 | |
| 518 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { | 568 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { |
| 519 switch (state) { | 569 switch (state) { |
| 520 case ArcAuthService::State::STOPPED: | 570 case ArcAuthService::State::STOPPED: |
| 521 return os << kStateStopped; | 571 return os << kStateStopped; |
| 522 case ArcAuthService::State::FETCHING_CODE: | 572 case ArcAuthService::State::FETCHING_CODE: |
| 523 return os << kStateFetchingCode; | 573 return os << kStateFetchingCode; |
| 524 case ArcAuthService::State::ACTIVE: | 574 case ArcAuthService::State::ACTIVE: |
| 525 return os << kStateActive; | 575 return os << kStateActive; |
| 526 default: | 576 default: |
| 527 NOTREACHED(); | 577 NOTREACHED(); |
| 528 return os; | 578 return os; |
| 529 } | 579 } |
| 530 } | 580 } |
| 531 | 581 |
| 532 } // namespace arc | 582 } // namespace arc |
| OLD | NEW |