| 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 "ash/common/shelf/shelf_delegate.h" | 9 #include "ash/common/shelf/shelf_delegate.h" |
| 10 #include "ash/common/wm_shell.h" | 10 #include "ash/common/wm_shell.h" |
| 11 #include "base/auto_reset.h" | 11 #include "base/auto_reset.h" |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "chrome/browser/chromeos/arc/arc_auth_code_fetcher.h" | 17 #include "chrome/browser/chromeos/arc/arc_auth_code_fetcher.h" |
| 18 #include "chrome/browser/chromeos/arc/arc_auth_context.h" | 18 #include "chrome/browser/chromeos/arc/arc_auth_context.h" |
| 19 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" | 19 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" |
| 20 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" | 20 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" |
| 21 #include "chrome/browser/chromeos/arc/arc_support_host.h" | 21 #include "chrome/browser/chromeos/arc/arc_support_host.h" |
| 22 #include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h" | 22 #include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h" |
| 23 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h" |
| 23 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 24 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 24 #include "chrome/browser/extensions/extension_util.h" | 25 #include "chrome/browser/extensions/extension_util.h" |
| 25 #include "chrome/browser/policy/profile_policy_connector.h" | 26 #include "chrome/browser/policy/profile_policy_connector.h" |
| 26 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 27 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 27 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 28 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 28 #include "chrome/browser/profiles/profile.h" | 29 #include "chrome/browser/profiles/profile.h" |
| 29 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" | 30 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" |
| 30 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 31 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
| 31 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 32 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 32 #include "chrome/browser/ui/extensions/app_launch_params.h" | 33 #include "chrome/browser/ui/extensions/app_launch_params.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 // Maximum amount of time we'll wait for ARC to finish booting up. Once this | 70 // Maximum amount of time we'll wait for ARC to finish booting up. Once this |
| 70 // timeout expires, keep ARC running in case the user wants to file feedback, | 71 // timeout expires, keep ARC running in case the user wants to file feedback, |
| 71 // but present the UI to try again. | 72 // but present the UI to try again. |
| 72 constexpr base::TimeDelta kArcSignInTimeout = base::TimeDelta::FromMinutes(5); | 73 constexpr base::TimeDelta kArcSignInTimeout = base::TimeDelta::FromMinutes(5); |
| 73 | 74 |
| 74 const char kStateNotInitialized[] = "NOT_INITIALIZED"; | 75 const char kStateNotInitialized[] = "NOT_INITIALIZED"; |
| 75 const char kStateStopped[] = "STOPPED"; | 76 const char kStateStopped[] = "STOPPED"; |
| 76 const char kStateFetchingCode[] = "FETCHING_CODE"; | 77 const char kStateFetchingCode[] = "FETCHING_CODE"; |
| 77 const char kStateActive[] = "ACTIVE"; | 78 const char kStateActive[] = "ACTIVE"; |
| 78 | 79 |
| 79 bool IsAccountManaged(Profile* profile) { | |
| 80 return policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile) | |
| 81 ->IsManaged(); | |
| 82 } | |
| 83 | |
| 84 bool IsArcDisabledForEnterprise() { | |
| 85 return base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 86 chromeos::switches::kEnterpriseDisableArc); | |
| 87 } | |
| 88 | |
| 89 ash::ShelfDelegate* GetShelfDelegate() { | 80 ash::ShelfDelegate* GetShelfDelegate() { |
| 90 if (g_shelf_delegate_for_testing) | 81 if (g_shelf_delegate_for_testing) |
| 91 return g_shelf_delegate_for_testing; | 82 return g_shelf_delegate_for_testing; |
| 92 if (ash::WmShell::HasInstance()) { | 83 if (ash::WmShell::HasInstance()) { |
| 93 DCHECK(ash::WmShell::Get()->shelf_delegate()); | 84 DCHECK(ash::WmShell::Get()->shelf_delegate()); |
| 94 return ash::WmShell::Get()->shelf_delegate(); | 85 return ash::WmShell::Get()->shelf_delegate(); |
| 95 } | 86 } |
| 96 return nullptr; | 87 return nullptr; |
| 97 } | 88 } |
| 98 | 89 |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 361 | 352 |
| 362 if (!IsOptInVerificationDisabled() && | 353 if (!IsOptInVerificationDisabled() && |
| 363 !profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { | 354 !profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { |
| 364 playstore_launcher_.reset( | 355 playstore_launcher_.reset( |
| 365 new ArcAppLauncher(profile_, kPlayStoreAppId, true)); | 356 new ArcAppLauncher(profile_, kPlayStoreAppId, true)); |
| 366 } | 357 } |
| 367 | 358 |
| 368 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, true); | 359 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, true); |
| 369 CloseUI(); | 360 CloseUI(); |
| 370 UpdateProvisioningTiming(base::Time::Now() - sign_in_time_, true, | 361 UpdateProvisioningTiming(base::Time::Now() - sign_in_time_, true, |
| 371 IsAccountManaged(profile_)); | 362 policy_util::IsAccountManaged(profile_)); |
| 372 UpdateProvisioningResultUMA(ProvisioningResult::SUCCESS, | 363 UpdateProvisioningResultUMA(ProvisioningResult::SUCCESS, |
| 373 IsAccountManaged(profile_)); | 364 policy_util::IsAccountManaged(profile_)); |
| 374 | 365 |
| 375 for (auto& observer : observer_list_) | 366 for (auto& observer : observer_list_) |
| 376 observer.OnInitialStart(); | 367 observer.OnInitialStart(); |
| 377 } | 368 } |
| 378 | 369 |
| 379 void ArcAuthService::OnSignInFailed(mojom::ArcSignInFailureReason reason) { | 370 void ArcAuthService::OnSignInFailed(mojom::ArcSignInFailureReason reason) { |
| 380 OnSignInFailedInternal( | 371 OnSignInFailedInternal( |
| 381 ConvertArcSignInFailureReasonToProvisioningResult(reason)); | 372 ConvertArcSignInFailureReasonToProvisioningResult(reason)); |
| 382 } | 373 } |
| 383 | 374 |
| 384 void ArcAuthService::OnSignInFailedInternal(ProvisioningResult result) { | 375 void ArcAuthService::OnSignInFailedInternal(ProvisioningResult result) { |
| 385 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 376 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 386 DCHECK_EQ(state_, State::ACTIVE); | 377 DCHECK_EQ(state_, State::ACTIVE); |
| 387 DCHECK(!sign_in_time_.is_null()); | 378 DCHECK(!sign_in_time_.is_null()); |
| 388 | 379 |
| 389 arc_sign_in_timer_.Stop(); | 380 arc_sign_in_timer_.Stop(); |
| 390 | 381 |
| 391 UpdateProvisioningTiming(base::Time::Now() - sign_in_time_, false, | 382 UpdateProvisioningTiming(base::Time::Now() - sign_in_time_, false, |
| 392 IsAccountManaged(profile_)); | 383 policy_util::IsAccountManaged(profile_)); |
| 393 UpdateOptInCancelUMA(OptInCancelReason::CLOUD_PROVISION_FLOW_FAIL); | 384 UpdateOptInCancelUMA(OptInCancelReason::CLOUD_PROVISION_FLOW_FAIL); |
| 394 UpdateProvisioningResultUMA(result, IsAccountManaged(profile_)); | 385 UpdateProvisioningResultUMA(result, policy_util::IsAccountManaged(profile_)); |
| 395 | 386 |
| 396 int error_message_id; | 387 int error_message_id; |
| 397 switch (result) { | 388 switch (result) { |
| 398 case ProvisioningResult::GMS_NETWORK_ERROR: | 389 case ProvisioningResult::GMS_NETWORK_ERROR: |
| 399 error_message_id = IDS_ARC_SIGN_IN_NETWORK_ERROR; | 390 error_message_id = IDS_ARC_SIGN_IN_NETWORK_ERROR; |
| 400 break; | 391 break; |
| 401 case ProvisioningResult::GMS_SERVICE_UNAVAILABLE: | 392 case ProvisioningResult::GMS_SERVICE_UNAVAILABLE: |
| 402 case ProvisioningResult::GMS_SIGN_IN_FAILED: | 393 case ProvisioningResult::GMS_SIGN_IN_FAILED: |
| 403 case ProvisioningResult::GMS_SIGN_IN_TIMEOUT: | 394 case ProvisioningResult::GMS_SIGN_IN_TIMEOUT: |
| 404 case ProvisioningResult::GMS_SIGN_IN_INTERNAL_ERROR: | 395 case ProvisioningResult::GMS_SIGN_IN_INTERNAL_ERROR: |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 // We'll delay shutting down the bridge in this case to allow people to send | 435 // We'll delay shutting down the bridge in this case to allow people to send |
| 445 // feedback. | 436 // feedback. |
| 446 ShowUI(UIPage::ERROR_WITH_FEEDBACK, | 437 ShowUI(UIPage::ERROR_WITH_FEEDBACK, |
| 447 l10n_util::GetStringUTF16(error_message_id)); | 438 l10n_util::GetStringUTF16(error_message_id)); |
| 448 } | 439 } |
| 449 | 440 |
| 450 void ArcAuthService::GetIsAccountManaged( | 441 void ArcAuthService::GetIsAccountManaged( |
| 451 const GetIsAccountManagedCallback& callback) { | 442 const GetIsAccountManagedCallback& callback) { |
| 452 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 443 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 453 | 444 |
| 454 callback.Run(IsAccountManaged(profile_)); | 445 callback.Run(policy_util::IsAccountManaged(profile_)); |
| 455 } | 446 } |
| 456 | 447 |
| 457 void ArcAuthService::SetState(State state) { | 448 void ArcAuthService::SetState(State state) { |
| 458 if (state_ == state) | 449 if (state_ == state) |
| 459 return; | 450 return; |
| 460 | 451 |
| 461 state_ = state; | 452 state_ = state; |
| 462 for (auto& observer : observer_list_) | 453 for (auto& observer : observer_list_) |
| 463 observer.OnOptInChanged(state_); | 454 observer.OnOptInChanged(state_); |
| 464 } | 455 } |
| 465 | 456 |
| 466 bool ArcAuthService::IsAllowed() const { | 457 bool ArcAuthService::IsAllowed() const { |
| 467 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 458 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 468 return profile_ != nullptr; | 459 return profile_ != nullptr; |
| 469 } | 460 } |
| 470 | 461 |
| 471 void ArcAuthService::OnPrimaryUserProfilePrepared(Profile* profile) { | 462 void ArcAuthService::OnPrimaryUserProfilePrepared(Profile* profile) { |
| 472 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 463 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 473 DCHECK(profile && profile != profile_); | 464 DCHECK(profile && profile != profile_); |
| 474 | 465 |
| 475 Shutdown(); | 466 Shutdown(); |
| 476 | 467 |
| 477 if (!IsAllowedForProfile(profile)) | 468 if (!IsAllowedForProfile(profile)) |
| 478 return; | 469 return; |
| 479 | 470 |
| 480 // TODO(khmel): Move this to IsAllowedForProfile. | 471 // TODO(khmel): Move this to IsAllowedForProfile. |
| 481 if (IsArcDisabledForEnterprise() && IsAccountManaged(profile)) { | 472 if (policy_util::IsArcDisabledForEnterprise() && |
| 473 policy_util::IsAccountManaged(profile)) { |
| 482 VLOG(2) << "Enterprise users are not supported in ARC."; | 474 VLOG(2) << "Enterprise users are not supported in ARC."; |
| 483 return; | 475 return; |
| 484 } | 476 } |
| 485 | 477 |
| 486 profile_ = profile; | 478 profile_ = profile; |
| 487 // Create the support host at initialization. Note that, practically, | 479 // Create the support host at initialization. Note that, practically, |
| 488 // ARC support Chrome app is rarely used (only opt-in and re-auth flow). | 480 // ARC support Chrome app is rarely used (only opt-in and re-auth flow). |
| 489 // So, it may be better to initialize it lazily. | 481 // So, it may be better to initialize it lazily. |
| 490 // TODO(hidehiko): Revisit to think about lazy initialization. | 482 // TODO(hidehiko): Revisit to think about lazy initialization. |
| 491 support_host_.reset(new ArcSupportHost()); | 483 support_host_.reset(new ArcSupportHost()); |
| (...skipping 382 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 874 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 866 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 875 DCHECK_EQ(state_, State::FETCHING_CODE); | 867 DCHECK_EQ(state_, State::FETCHING_CODE); |
| 876 ShutdownBridgeAndShowUI( | 868 ShutdownBridgeAndShowUI( |
| 877 UIPage::ERROR, | 869 UIPage::ERROR, |
| 878 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); | 870 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); |
| 879 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 871 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 880 } | 872 } |
| 881 | 873 |
| 882 void ArcAuthService::CheckAndroidManagement(bool background_mode) { | 874 void ArcAuthService::CheckAndroidManagement(bool background_mode) { |
| 883 // Do not send requests for Chrome OS managed users. | 875 // Do not send requests for Chrome OS managed users. |
| 884 if (IsAccountManaged(profile_)) { | 876 if (policy_util::IsAccountManaged(profile_)) { |
| 885 OnAndroidManagementPassed(); | 877 OnAndroidManagementPassed(); |
| 886 return; | 878 return; |
| 887 } | 879 } |
| 888 | 880 |
| 889 // Do not send requests for well-known consumer domains. | 881 // Do not send requests for well-known consumer domains. |
| 890 if (policy::BrowserPolicyConnector::IsNonEnterpriseUser( | 882 if (policy::BrowserPolicyConnector::IsNonEnterpriseUser( |
| 891 profile_->GetProfileUserName())) { | 883 profile_->GetProfileUserName())) { |
| 892 OnAndroidManagementPassed(); | 884 OnAndroidManagementPassed(); |
| 893 return; | 885 return; |
| 894 } | 886 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 973 return os << kStateFetchingCode; | 965 return os << kStateFetchingCode; |
| 974 case ArcAuthService::State::ACTIVE: | 966 case ArcAuthService::State::ACTIVE: |
| 975 return os << kStateActive; | 967 return os << kStateActive; |
| 976 default: | 968 default: |
| 977 NOTREACHED(); | 969 NOTREACHED(); |
| 978 return os; | 970 return os; |
| 979 } | 971 } |
| 980 } | 972 } |
| 981 | 973 |
| 982 } // namespace arc | 974 } // namespace arc |
| OLD | NEW |