| 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/command_line.h" | 11 #include "base/command_line.h" |
| 12 #include "base/lazy_instance.h" | 12 #include "base/lazy_instance.h" |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/threading/thread_checker.h" | 16 #include "base/threading/thread_checker.h" |
| 17 #include "chrome/browser/browser_process.h" | 17 #include "chrome/browser/browser_process.h" |
| 18 #include "chrome/browser/browser_process_platform_part.h" | 18 #include "chrome/browser/browser_process_platform_part.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/policy/browser_policy_connector_chromeos.h" | 22 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" |
| 22 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 23 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 23 #include "chrome/browser/extensions/extension_util.h" | 24 #include "chrome/browser/extensions/extension_util.h" |
| 24 #include "chrome/browser/policy/profile_policy_connector.h" | 25 #include "chrome/browser/policy/profile_policy_connector.h" |
| 25 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 26 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 26 #include "chrome/browser/prefs/pref_service_syncable_util.h" | 27 #include "chrome/browser/prefs/pref_service_syncable_util.h" |
| 27 #include "chrome/browser/profiles/profile.h" | 28 #include "chrome/browser/profiles/profile.h" |
| 28 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" | 29 #include "chrome/browser/signin/profile_oauth2_token_service_factory.h" |
| 29 #include "chrome/browser/signin/signin_manager_factory.h" | 30 #include "chrome/browser/signin/signin_manager_factory.h" |
| 30 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" | 31 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" |
| 32 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
| 31 #include "chrome/browser/ui/extensions/app_launch_params.h" | 33 #include "chrome/browser/ui/extensions/app_launch_params.h" |
| 32 #include "chrome/browser/ui/extensions/application_launch.h" | 34 #include "chrome/browser/ui/extensions/application_launch.h" |
| 33 #include "chrome/common/pref_names.h" | 35 #include "chrome/common/pref_names.h" |
| 34 #include "chrome/grit/generated_resources.h" | 36 #include "chrome/grit/generated_resources.h" |
| 35 #include "chromeos/chromeos_switches.h" | 37 #include "chromeos/chromeos_switches.h" |
| 36 #include "components/arc/arc_bridge_service.h" | 38 #include "components/arc/arc_bridge_service.h" |
| 37 #include "components/policy/core/browser/browser_policy_connector.h" | 39 #include "components/policy/core/browser/browser_policy_connector.h" |
| 38 #include "components/policy/core/common/cloud/device_management_service.h" | 40 #include "components/policy/core/common/cloud/device_management_service.h" |
| 39 #include "components/pref_registry/pref_registry_syncable.h" | 41 #include "components/pref_registry/pref_registry_syncable.h" |
| 40 #include "components/prefs/pref_service.h" | 42 #include "components/prefs/pref_service.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 53 namespace arc { | 55 namespace arc { |
| 54 | 56 |
| 55 namespace { | 57 namespace { |
| 56 | 58 |
| 57 // Weak pointer. This class is owned by ArcServiceManager. | 59 // Weak pointer. This class is owned by ArcServiceManager. |
| 58 ArcAuthService* arc_auth_service = nullptr; | 60 ArcAuthService* arc_auth_service = nullptr; |
| 59 | 61 |
| 60 base::LazyInstance<base::ThreadChecker> thread_checker = | 62 base::LazyInstance<base::ThreadChecker> thread_checker = |
| 61 LAZY_INSTANCE_INITIALIZER; | 63 LAZY_INSTANCE_INITIALIZER; |
| 62 | 64 |
| 63 const char kPlayStoreAppId[] = "gpkmicpkkebkmabiaedjognfppcchdfa"; | |
| 64 const char kArcSupportExtensionId[] = "cnbgggchhmkkdmeppjobngjoejnihlei"; | |
| 65 const char kArcSupportStorageId[] = "arc_support"; | |
| 66 | |
| 67 // Skip creating UI in unit tests | 65 // Skip creating UI in unit tests |
| 68 bool disable_ui_for_testing = false; | 66 bool disable_ui_for_testing = false; |
| 69 | 67 |
| 70 // The Android management check is disabled by default, it's used only for | 68 // The Android management check is disabled by default, it's used only for |
| 71 // testing. | 69 // testing. |
| 72 bool enable_check_android_management_for_testing = false; | 70 bool enable_check_android_management_for_testing = false; |
| 73 | 71 |
| 74 const char kStateStopped[] = "STOPPED"; | 72 const char kStateStopped[] = "STOPPED"; |
| 75 const char kStateFetchingCode[] = "FETCHING_CODE"; | 73 const char kStateFetchingCode[] = "FETCHING_CODE"; |
| 76 const char kStateActive[] = "ACTIVE"; | 74 const char kStateActive[] = "ACTIVE"; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 bool ArcAuthService::IsOptInVerificationDisabled() { | 119 bool ArcAuthService::IsOptInVerificationDisabled() { |
| 122 return base::CommandLine::ForCurrentProcess()->HasSwitch( | 120 return base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 123 chromeos::switches::kDisableArcOptInVerification); | 121 chromeos::switches::kDisableArcOptInVerification); |
| 124 } | 122 } |
| 125 | 123 |
| 126 // static | 124 // static |
| 127 void ArcAuthService::EnableCheckAndroidManagementForTesting() { | 125 void ArcAuthService::EnableCheckAndroidManagementForTesting() { |
| 128 enable_check_android_management_for_testing = true; | 126 enable_check_android_management_for_testing = true; |
| 129 } | 127 } |
| 130 | 128 |
| 129 bool ArcAuthService::IsAllowedForProfile(const Profile* profile) { |
| 130 if (!arc::ArcBridgeService::GetEnabled( |
| 131 base::CommandLine::ForCurrentProcess())) { |
| 132 VLOG(1) << "Arc is not enabled."; |
| 133 return false; |
| 134 } |
| 135 |
| 136 user_manager::User const* const user = |
| 137 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); |
| 138 if (profile->IsLegacySupervised()) { |
| 139 VLOG(1) << "Supervised users are not supported in ARC."; |
| 140 return false; |
| 141 } |
| 142 if (!user->HasGaiaAccount()) { |
| 143 VLOG(1) << "Users without GAIA accounts are not supported in ARC."; |
| 144 return false; |
| 145 } |
| 146 |
| 147 if (user_manager::UserManager::Get() |
| 148 ->IsCurrentUserCryptohomeDataEphemeral()) { |
| 149 VLOG(2) << "Users with ephemeral data are not supported in Arc."; |
| 150 return false; |
| 151 } |
| 152 |
| 153 return true; |
| 154 } |
| 155 |
| 131 void ArcAuthService::OnAuthInstanceReady() { | 156 void ArcAuthService::OnAuthInstanceReady() { |
| 132 arc_bridge_service()->auth_instance()->Init( | 157 arc_bridge_service()->auth_instance()->Init( |
| 133 binding_.CreateInterfacePtrAndBind()); | 158 binding_.CreateInterfacePtrAndBind()); |
| 134 } | 159 } |
| 135 | 160 |
| 136 std::string ArcAuthService::GetAndResetAuthCode() { | 161 std::string ArcAuthService::GetAndResetAuthCode() { |
| 137 DCHECK(thread_checker.Get().CalledOnValidThread()); | 162 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 138 std::string auth_code; | 163 std::string auth_code; |
| 139 auth_code_.swap(auth_code); | 164 auth_code_.swap(auth_code); |
| 140 return auth_code; | 165 return auth_code; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 } | 252 } |
| 228 | 253 |
| 229 void ArcAuthService::SetState(State state) { | 254 void ArcAuthService::SetState(State state) { |
| 230 if (state_ == state) | 255 if (state_ == state) |
| 231 return; | 256 return; |
| 232 | 257 |
| 233 state_ = state; | 258 state_ = state; |
| 234 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInChanged(state_)); | 259 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInChanged(state_)); |
| 235 } | 260 } |
| 236 | 261 |
| 262 bool ArcAuthService::IsAllowed() const { |
| 263 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 264 return profile_ != nullptr; |
| 265 } |
| 266 |
| 237 void ArcAuthService::OnPrimaryUserProfilePrepared(Profile* profile) { | 267 void ArcAuthService::OnPrimaryUserProfilePrepared(Profile* profile) { |
| 238 DCHECK(profile && profile != profile_); | 268 DCHECK(profile && profile != profile_); |
| 239 DCHECK(thread_checker.Get().CalledOnValidThread()); | 269 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 240 | 270 |
| 241 Shutdown(); | 271 Shutdown(); |
| 242 | 272 |
| 243 user_manager::User const* const user = | 273 if (!IsAllowedForProfile(profile)) |
| 244 chromeos::ProfileHelper::Get()->GetUserByProfile(profile); | |
| 245 if (profile->IsLegacySupervised()) { | |
| 246 VLOG(1) << "Supervised users are not supported in ARC."; | |
| 247 return; | 274 return; |
| 248 } | |
| 249 if (!user->HasGaiaAccount()) { | |
| 250 VLOG(1) << "Users without GAIA accounts are not supported in ARC."; | |
| 251 return; | |
| 252 } | |
| 253 | |
| 254 if (user_manager::UserManager::Get() | |
| 255 ->IsCurrentUserCryptohomeDataEphemeral()) { | |
| 256 VLOG(2) << "Users with ephemeral data are not supported in Arc."; | |
| 257 return; | |
| 258 } | |
| 259 | 275 |
| 260 profile_ = profile; | 276 profile_ = profile; |
| 261 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( | 277 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( |
| 262 prefs::kArcEnabled, this); | 278 prefs::kArcEnabled, this); |
| 263 | 279 |
| 264 // Reuse storage used in ARC OptIn platform app. | 280 // Reuse storage used in ARC OptIn platform app. |
| 265 const std::string site_url = | 281 const std::string site_url = base::StringPrintf( |
| 266 base::StringPrintf("%s://%s/persist?%s", content::kGuestScheme, | 282 "%s://%s/persist?%s", content::kGuestScheme, ArcSupportHost::kHostAppId, |
| 267 kArcSupportExtensionId, kArcSupportStorageId); | 283 ArcSupportHost::kStorageId); |
| 268 storage_partition_ = content::BrowserContext::GetStoragePartitionForSite( | 284 storage_partition_ = content::BrowserContext::GetStoragePartitionForSite( |
| 269 profile_, GURL(site_url)); | 285 profile_, GURL(site_url)); |
| 270 CHECK(storage_partition_); | 286 CHECK(storage_partition_); |
| 271 | 287 |
| 272 // Get token service and account ID to fetch auth tokens. | 288 // Get token service and account ID to fetch auth tokens. |
| 273 token_service_ = ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | 289 token_service_ = ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); |
| 274 const SigninManagerBase* const signin_manager = | 290 const SigninManagerBase* const signin_manager = |
| 275 SigninManagerFactory::GetForProfile(profile_); | 291 SigninManagerFactory::GetForProfile(profile_); |
| 276 CHECK(token_service_ && signin_manager); | 292 CHECK(token_service_ && signin_manager); |
| 277 account_id_ = signin_manager->GetAuthenticatedAccountId(); | 293 account_id_ = signin_manager->GetAuthenticatedAccountId(); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 } | 344 } |
| 329 | 345 |
| 330 void ArcAuthService::ShowUI(UIPage page, const base::string16& status) { | 346 void ArcAuthService::ShowUI(UIPage page, const base::string16& status) { |
| 331 if (disable_ui_for_testing || IsOptInVerificationDisabled()) | 347 if (disable_ui_for_testing || IsOptInVerificationDisabled()) |
| 332 return; | 348 return; |
| 333 | 349 |
| 334 SetUIPage(page, status); | 350 SetUIPage(page, status); |
| 335 const extensions::AppWindowRegistry* const app_window_registry = | 351 const extensions::AppWindowRegistry* const app_window_registry = |
| 336 extensions::AppWindowRegistry::Get(profile_); | 352 extensions::AppWindowRegistry::Get(profile_); |
| 337 DCHECK(app_window_registry); | 353 DCHECK(app_window_registry); |
| 338 if (app_window_registry->GetCurrentAppWindowForApp(kArcSupportExtensionId)) | 354 if (app_window_registry->GetCurrentAppWindowForApp( |
| 355 ArcSupportHost::kHostAppId)) { |
| 339 return; | 356 return; |
| 357 } |
| 340 | 358 |
| 341 const extensions::Extension* extension = | 359 const extensions::Extension* extension = |
| 342 extensions::ExtensionRegistry::Get(profile_)->GetInstalledExtension( | 360 extensions::ExtensionRegistry::Get(profile_)->GetInstalledExtension( |
| 343 kArcSupportExtensionId); | 361 ArcSupportHost::kHostAppId); |
| 344 CHECK(extension && | 362 CHECK(extension && extensions::util::IsAppLaunchable( |
| 345 extensions::util::IsAppLaunchable(kArcSupportExtensionId, profile_)); | 363 ArcSupportHost::kHostAppId, profile_)); |
| 346 | 364 |
| 347 OpenApplication(CreateAppLaunchParamsUserContainer( | 365 OpenApplication(CreateAppLaunchParamsUserContainer( |
| 348 profile_, extension, NEW_WINDOW, extensions::SOURCE_CHROME_INTERNAL)); | 366 profile_, extension, NEW_WINDOW, extensions::SOURCE_CHROME_INTERNAL)); |
| 349 } | 367 } |
| 350 | 368 |
| 351 void ArcAuthService::OnMergeSessionSuccess(const std::string& data) { | 369 void ArcAuthService::OnMergeSessionSuccess(const std::string& data) { |
| 352 DCHECK(thread_checker.Get().CalledOnValidThread()); | 370 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 353 | 371 |
| 354 DCHECK(!initial_opt_in_); | 372 DCHECK(!initial_opt_in_); |
| 355 context_prepared_ = true; | 373 context_prepared_ = true; |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 516 if (state_ != State::FETCHING_CODE && ui_page_ != UIPage::ERROR) | 534 if (state_ != State::FETCHING_CODE && ui_page_ != UIPage::ERROR) |
| 517 return; | 535 return; |
| 518 | 536 |
| 519 // Update UMA with user cancel only if error is not currently shown. | 537 // Update UMA with user cancel only if error is not currently shown. |
| 520 if (ui_page_ != UIPage::ERROR && ui_page_ != UIPage::NO_PAGE) | 538 if (ui_page_ != UIPage::ERROR && ui_page_ != UIPage::NO_PAGE) |
| 521 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); | 539 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); |
| 522 | 540 |
| 523 DisableArc(); | 541 DisableArc(); |
| 524 } | 542 } |
| 525 | 543 |
| 544 bool ArcAuthService::IsArcEnabled() { |
| 545 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 546 DCHECK(profile_); |
| 547 return profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled); |
| 548 } |
| 549 |
| 526 void ArcAuthService::EnableArc() { | 550 void ArcAuthService::EnableArc() { |
| 527 DCHECK(thread_checker.Get().CalledOnValidThread()); | 551 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 552 DCHECK(profile_); |
| 528 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 553 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| 529 } | 554 } |
| 530 | 555 |
| 531 void ArcAuthService::DisableArc() { | 556 void ArcAuthService::DisableArc() { |
| 532 DCHECK(thread_checker.Get().CalledOnValidThread()); | 557 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 558 DCHECK(profile_); |
| 533 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); | 559 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); |
| 534 } | 560 } |
| 535 | 561 |
| 536 void ArcAuthService::PrepareContext() { | 562 void ArcAuthService::PrepareContext() { |
| 537 DCHECK(thread_checker.Get().CalledOnValidThread()); | 563 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 538 | 564 |
| 539 ubertoken_fethcher_.reset( | 565 ubertoken_fethcher_.reset( |
| 540 new UbertokenFetcher(token_service_, this, GaiaConstants::kChromeOSSource, | 566 new UbertokenFetcher(token_service_, this, GaiaConstants::kChromeOSSource, |
| 541 storage_partition_->GetURLRequestContext())); | 567 storage_partition_->GetURLRequestContext())); |
| 542 ubertoken_fethcher_->StartFetchingToken(account_id_); | 568 ubertoken_fethcher_->StartFetchingToken(account_id_); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 637 return os << kStateFetchingCode; | 663 return os << kStateFetchingCode; |
| 638 case ArcAuthService::State::ACTIVE: | 664 case ArcAuthService::State::ACTIVE: |
| 639 return os << kStateActive; | 665 return os << kStateActive; |
| 640 default: | 666 default: |
| 641 NOTREACHED(); | 667 NOTREACHED(); |
| 642 return os; | 668 return os; |
| 643 } | 669 } |
| 644 } | 670 } |
| 645 | 671 |
| 646 } // namespace arc | 672 } // namespace arc |
| OLD | NEW |