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