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" |
|
bartfab (slow)
2016/05/02 14:55:48
Nit: No longer used.
Polina Bondarenko
2016/05/03 13:41:54
Done.
| |
| 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" | |
|
bartfab (slow)
2016/05/02 14:55:48
Nit: Where is this used?
Polina Bondarenko
2016/05/03 13:41:54
It's used in ShowUI() and it's calls.
| |
| 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. | |
|
bartfab (slow)
2016/05/02 14:55:48
The comment says "do check" but the default value
Polina Bondarenko
2016/05/03 13:41:54
Done.
| |
| 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after 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 = | |
|
bartfab (slow)
2016/05/02 14:55:48
Nit: const pointer
Polina Bondarenko
2016/05/03 13:41:54
Done.
| |
| 263 SigninManagerFactory::GetForProfile(profile_); | |
| 264 CHECK(token_service_ && signin_manager); | |
|
bartfab (slow)
2016/05/02 14:55:48
Nit: #include "base/logging.h"
Polina Bondarenko
2016/05/03 13:41:54
Done.
| |
| 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 weak_ptr_factory_.GetWeakPtr())); |
| 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(); |
|
bartfab (slow)
2016/05/02 14:55:48
Will this not circumvent the management check?
Polina Bondarenko
2016/05/03 13:41:54
Yes, it will. This branch of 'if' is used only for
bartfab (slow)
2016/05/03 14:25:18
According to the documentation, that switch "disab
Polina Bondarenko
2016/05/03 14:55:44
Would you recommend to add check here too? This br
bartfab (slow)
2016/05/03 15:26:38
Yes, I think we should add the check to that code
Polina Bondarenko
2016/05/03 16:42:16
Ok, added check. It seems like nothing's failed fo
| |
| 262 } | 287 } |
| 263 } | 288 } |
| 264 | 289 |
| 265 void ArcAuthService::OnIsSyncingChanged() { | 290 void ArcAuthService::OnIsSyncingChanged() { |
| 266 syncable_prefs::PrefServiceSyncable* const pref_service_syncable = | 291 syncable_prefs::PrefServiceSyncable* const pref_service_syncable = |
| 267 PrefServiceSyncableFromProfile(profile_); | 292 PrefServiceSyncableFromProfile(profile_); |
| 268 if (!pref_service_syncable->IsSyncing()) | 293 if (!pref_service_syncable->IsSyncing()) |
| 269 return; | 294 return; |
| 270 | 295 |
| 271 pref_service_syncable->RemoveObserver(this); | 296 pref_service_syncable->RemoveObserver(this); |
| 272 | 297 |
| 273 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) | 298 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) |
| 274 OnOptInPreferenceChanged(); | 299 OnOptInPreferenceChanged(); |
| 275 | 300 |
| 276 if (!disable_ui_for_testing && profile_->IsNewProfile() && | 301 if (!disable_ui_for_testing && profile_->IsNewProfile() && |
| 277 !profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { | 302 !profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { |
| 278 arc::ArcAuthNotification::Show(); | 303 arc::ArcAuthNotification::Show(); |
| 279 } | 304 } |
| 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 // Destroy here, because |android_management_client_| is used for each ARC | |
|
bartfab (slow)
2016/05/02 14:55:48
I do not understand what this comment is trying to
Polina Bondarenko
2016/05/03 13:41:54
It doesn't have to, removed. I tried to show that
| |
| 316 // connect, even if ARC is signed-in. | |
| 317 android_management_client_.reset(); | |
| 290 pref_change_registrar_.RemoveAll(); | 318 pref_change_registrar_.RemoveAll(); |
| 291 profile_ = nullptr; | 319 profile_ = nullptr; |
| 292 } | 320 } |
| 293 | 321 |
| 294 void ArcAuthService::ShowUI(UIPage page, const base::string16& status) { | 322 void ArcAuthService::ShowUI(UIPage page, const base::string16& status) { |
| 295 if (disable_ui_for_testing || IsOptInVerificationDisabled()) | 323 if (disable_ui_for_testing || IsOptInVerificationDisabled()) |
| 296 return; | 324 return; |
| 297 | 325 |
| 298 SetUIPage(page, status); | 326 SetUIPage(page, status); |
| 299 const extensions::AppWindowRegistry* const app_window_registry = | 327 const extensions::AppWindowRegistry* const app_window_registry = |
| 300 extensions::AppWindowRegistry::Get(profile_); | 328 extensions::AppWindowRegistry::Get(profile_); |
| 301 DCHECK(app_window_registry); | 329 DCHECK(app_window_registry); |
| 302 if (app_window_registry->GetCurrentAppWindowForApp(kArcSupportExtensionId)) | 330 if (app_window_registry->GetCurrentAppWindowForApp(kArcSupportExtensionId)) |
| 303 return; | 331 return; |
| 304 | 332 |
| 305 const extensions::Extension* extension = | 333 const extensions::Extension* extension = |
| 306 extensions::ExtensionRegistry::Get(profile_)->GetInstalledExtension( | 334 extensions::ExtensionRegistry::Get(profile_)->GetInstalledExtension( |
| 307 kArcSupportExtensionId); | 335 kArcSupportExtensionId); |
| 308 CHECK(extension && | 336 CHECK(extension && |
| 309 extensions::util::IsAppLaunchable(kArcSupportExtensionId, profile_)); | 337 extensions::util::IsAppLaunchable(kArcSupportExtensionId, profile_)); |
| 310 | 338 |
| 311 OpenApplication(CreateAppLaunchParamsUserContainer( | 339 OpenApplication(CreateAppLaunchParamsUserContainer( |
| 312 profile_, extension, NEW_WINDOW, extensions::SOURCE_CHROME_INTERNAL)); | 340 profile_, extension, NEW_WINDOW, extensions::SOURCE_CHROME_INTERNAL)); |
| 313 } | 341 } |
| 314 | 342 |
| 315 void ArcAuthService::OnMergeSessionSuccess(const std::string& data) { | 343 void ArcAuthService::OnMergeSessionSuccess(const std::string& data) { |
| 316 DCHECK(thread_checker.Get().CalledOnValidThread()); | 344 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 317 | 345 |
| 318 DCHECK(!initial_opt_in_); | 346 DCHECK(!initial_opt_in_); |
| 319 context_prepared_ = true; | 347 CheckAndroidManagement(); |
| 320 ShowUI(UIPage::LSO_PROGRESS, base::string16()); | |
| 321 } | 348 } |
| 322 | 349 |
| 323 void ArcAuthService::OnMergeSessionFailure( | 350 void ArcAuthService::OnMergeSessionFailure( |
| 324 const GoogleServiceAuthError& error) { | 351 const GoogleServiceAuthError& error) { |
| 325 DCHECK(thread_checker.Get().CalledOnValidThread()); | 352 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 326 VLOG(2) << "Failed to merge gaia session " << error.ToString() << "."; | 353 VLOG(2) << "Failed to merge gaia session " << error.ToString() << "."; |
| 327 OnPrepareContextFailed(); | 354 OnPrepareContextFailed(); |
| 328 } | 355 } |
| 329 | 356 |
| 330 void ArcAuthService::OnUbertokenSuccess(const std::string& token) { | 357 void ArcAuthService::OnUbertokenSuccess(const std::string& token) { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 360 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { | 387 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { |
| 361 if (state_ != State::ACTIVE) { | 388 if (state_ != State::ACTIVE) { |
| 362 CloseUI(); | 389 CloseUI(); |
| 363 auth_code_.clear(); | 390 auth_code_.clear(); |
| 364 | 391 |
| 365 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { | 392 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) { |
| 366 // Need pre-fetch auth code and show OptIn UI if needed. | 393 // Need pre-fetch auth code and show OptIn UI if needed. |
| 367 initial_opt_in_ = true; | 394 initial_opt_in_ = true; |
| 368 StartUI(); | 395 StartUI(); |
| 369 } else { | 396 } else { |
| 370 // Ready to start Arc. | 397 // Ready to start Arc, but check android management first. |
| 371 StartArc(); | 398 if (!disable_ui_for_testing || |
| 399 enable_check_android_management_for_testing) { | |
| 400 CheckAndroidManagement(); | |
| 401 } else { | |
| 402 StartArc(); | |
| 403 } | |
| 372 } | 404 } |
| 373 | 405 |
| 374 UpdateEnabledStateUMA(true); | 406 UpdateEnabledStateUMA(true); |
| 375 } | 407 } |
| 376 } else { | 408 } else { |
| 377 if (state_ != State::STOPPED) | 409 if (state_ != State::STOPPED) |
| 378 UpdateEnabledStateUMA(false); | 410 UpdateEnabledStateUMA(false); |
| 379 ShutdownBridgeAndCloseUI(); | 411 ShutdownBridgeAndCloseUI(); |
| 380 } | 412 } |
| 381 } | 413 } |
| 382 | 414 |
| 383 void ArcAuthService::ShutdownBridge() { | 415 void ArcAuthService::ShutdownBridge() { |
| 416 FOR_EACH_OBSERVER(Observer, observer_list_, OnShutdownBridge()); | |
| 384 playstore_launcher_.reset(); | 417 playstore_launcher_.reset(); |
| 385 auth_callback_.reset(); | 418 auth_callback_.reset(); |
| 386 ubertoken_fethcher_.reset(); | 419 ubertoken_fethcher_.reset(); |
| 387 merger_fetcher_.reset(); | 420 merger_fetcher_.reset(); |
| 421 token_service_ = nullptr; | |
| 422 account_id_ = ""; | |
| 388 arc_bridge_service()->Shutdown(); | 423 arc_bridge_service()->Shutdown(); |
| 389 SetState(State::STOPPED); | 424 SetState(State::STOPPED); |
| 390 } | 425 } |
| 391 | 426 |
| 392 void ArcAuthService::ShutdownBridgeAndCloseUI() { | 427 void ArcAuthService::ShutdownBridgeAndCloseUI() { |
| 393 ShutdownBridge(); | 428 ShutdownBridge(); |
| 394 CloseUI(); | 429 CloseUI(); |
| 395 } | 430 } |
| 396 | 431 |
| 397 void ArcAuthService::ShutdownBridgeAndShowUI(UIPage page, | 432 void ArcAuthService::ShutdownBridgeAndShowUI(UIPage page, |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 461 if (ui_page_ == UIPage::ERROR) | 496 if (ui_page_ == UIPage::ERROR) |
| 462 UpdateOptInActionUMA(OptInActionType::RETRY); | 497 UpdateOptInActionUMA(OptInActionType::RETRY); |
| 463 | 498 |
| 464 initial_opt_in_ = false; | 499 initial_opt_in_ = false; |
| 465 StartUI(); | 500 StartUI(); |
| 466 } | 501 } |
| 467 | 502 |
| 468 void ArcAuthService::CancelAuthCode() { | 503 void ArcAuthService::CancelAuthCode() { |
| 469 DCHECK(thread_checker.Get().CalledOnValidThread()); | 504 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 470 | 505 |
| 471 if (state_ != State::FETCHING_CODE) | 506 if (state_ != State::FETCHING_CODE && ui_page_ != UIPage::ERROR) |
| 472 return; | 507 return; |
| 473 | 508 |
| 474 // Update UMA with user cancel only if error is not currently shown. | 509 // Update UMA with user cancel only if error is not currently shown. |
| 475 if (ui_page_ != UIPage::ERROR && ui_page_ != UIPage::NO_PAGE) | 510 if (ui_page_ != UIPage::ERROR && ui_page_ != UIPage::NO_PAGE) |
| 476 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); | 511 UpdateOptInCancelUMA(OptInCancelReason::USER_CANCEL); |
| 477 | 512 |
| 478 DisableArc(); | 513 DisableArc(); |
| 479 } | 514 } |
| 480 | 515 |
| 481 void ArcAuthService::EnableArc() { | 516 void ArcAuthService::EnableArc() { |
| 482 DCHECK(thread_checker.Get().CalledOnValidThread()); | 517 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 483 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); | 518 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, true); |
| 484 } | 519 } |
| 485 | 520 |
| 486 void ArcAuthService::DisableArc() { | 521 void ArcAuthService::DisableArc() { |
| 487 DCHECK(thread_checker.Get().CalledOnValidThread()); | 522 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 488 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); | 523 profile_->GetPrefs()->SetBoolean(prefs::kArcEnabled, false); |
| 489 } | 524 } |
| 490 | 525 |
| 491 void ArcAuthService::PrepareContext() { | 526 void ArcAuthService::PrepareContext() { |
| 492 DCHECK(thread_checker.Get().CalledOnValidThread()); | 527 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 493 | 528 |
| 494 // Get auth token to continue. | |
| 495 ProfileOAuth2TokenService* token_service = | |
| 496 ProfileOAuth2TokenServiceFactory::GetForProfile(profile_); | |
| 497 SigninManagerBase* signin_manager = | |
| 498 SigninManagerFactory::GetForProfile(profile_); | |
| 499 CHECK(token_service && signin_manager); | |
| 500 const std::string& account_id = signin_manager->GetAuthenticatedAccountId(); | |
| 501 ubertoken_fethcher_.reset( | 529 ubertoken_fethcher_.reset( |
| 502 new UbertokenFetcher(token_service, this, GaiaConstants::kChromeOSSource, | 530 new UbertokenFetcher(token_service_, this, GaiaConstants::kChromeOSSource, |
| 503 storage_partition_->GetURLRequestContext())); | 531 storage_partition_->GetURLRequestContext())); |
| 504 ubertoken_fethcher_->StartFetchingToken(account_id); | 532 ubertoken_fethcher_->StartFetchingToken(account_id_); |
| 505 } | 533 } |
| 506 | 534 |
| 507 void ArcAuthService::StartUI() { | 535 void ArcAuthService::StartUI() { |
| 508 DCHECK(thread_checker.Get().CalledOnValidThread()); | 536 DCHECK(thread_checker.Get().CalledOnValidThread()); |
| 509 | 537 |
| 510 SetState(State::FETCHING_CODE); | 538 SetState(State::FETCHING_CODE); |
| 511 | 539 |
| 512 if (initial_opt_in_) { | 540 if (initial_opt_in_) { |
| 513 initial_opt_in_ = false; | 541 initial_opt_in_ = false; |
| 514 ShowUI(UIPage::START, base::string16()); | 542 ShowUI(UIPage::START, base::string16()); |
| 515 } else if (context_prepared_) { | 543 } else if (context_prepared_) { |
| 516 ShowUI(UIPage::LSO_PROGRESS, base::string16()); | 544 ShowUI(UIPage::LSO_PROGRESS, base::string16()); |
| 517 } else { | 545 } else { |
| 518 PrepareContext(); | 546 PrepareContext(); |
| 519 } | 547 } |
| 520 } | 548 } |
| 521 | 549 |
| 522 void ArcAuthService::OnPrepareContextFailed() { | 550 void ArcAuthService::OnPrepareContextFailed() { |
| 523 DCHECK_EQ(state_, State::FETCHING_CODE); | 551 DCHECK_EQ(state_, State::FETCHING_CODE); |
| 524 | 552 |
| 525 ShutdownBridgeAndShowUI( | 553 ShutdownBridgeAndShowUI( |
| 526 UIPage::ERROR, | 554 UIPage::ERROR, |
| 527 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); | 555 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); |
| 528 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | 556 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); |
| 529 } | 557 } |
| 530 | 558 |
| 559 void ArcAuthService::StartAndroidManagementClient() { | |
| 560 policy::BrowserPolicyConnectorChromeOS* const connector = | |
| 561 g_browser_process->platform_part()->browser_policy_connector_chromeos(); | |
| 562 policy::DeviceManagementService* const service = | |
| 563 connector->device_management_service(); | |
| 564 service->ScheduleInitialization(0); | |
| 565 android_management_client_.reset(new policy::AndroidManagementClient( | |
| 566 service, g_browser_process->system_request_context(), account_id_, | |
| 567 token_service_)); | |
| 568 } | |
| 569 | |
| 570 void ArcAuthService::CheckAndroidManagement() { | |
| 571 // Do not send requests for Chrome OS managed users. | |
| 572 if (policy::ProfilePolicyConnectorFactory::GetForBrowserContext(profile_) | |
| 573 ->IsManaged()) { | |
| 574 OnAndroidManagementChecked( | |
| 575 policy::AndroidManagementClient::Result::RESULT_UNMANAGED); | |
|
bartfab (slow)
2016/05/02 14:55:48
It is a bit odd semantically that for a *managed*
Polina Bondarenko
2016/05/03 13:41:54
Yes, fixed to a plain code. Hopefully it doesn't l
bartfab (slow)
2016/05/03 14:25:18
You could always extract these four lines to a hel
Polina Bondarenko
2016/05/03 14:55:44
Done.
| |
| 576 return; | |
| 577 } | |
| 578 | |
| 579 // Do not send requests for well-known consumer domains. | |
| 580 if (policy::BrowserPolicyConnector::IsNonEnterpriseUser( | |
| 581 profile_->GetProfileUserName())) { | |
| 582 OnAndroidManagementChecked( | |
| 583 policy::AndroidManagementClient::Result::RESULT_UNMANAGED); | |
| 584 return; | |
| 585 } | |
| 586 | |
| 587 android_management_client_->StartCheckAndroidManagement( | |
| 588 base::Bind(&ArcAuthService::OnAndroidManagementChecked, | |
| 589 weak_ptr_factory_.GetWeakPtr())); | |
| 590 } | |
| 591 | |
| 592 void ArcAuthService::OnAndroidManagementChecked( | |
| 593 policy::AndroidManagementClient::Result result) { | |
| 594 switch (result) { | |
| 595 case policy::AndroidManagementClient::Result::RESULT_UNMANAGED: | |
| 596 context_prepared_ = true; | |
| 597 if (!profile_->GetPrefs()->GetBoolean(prefs::kArcSignedIn)) | |
| 598 ShowUI(UIPage::LSO_PROGRESS, base::string16()); | |
| 599 else | |
| 600 StartArc(); | |
| 601 break; | |
| 602 case policy::AndroidManagementClient::Result::RESULT_MANAGED: | |
| 603 ShutdownBridgeAndShowUI( | |
| 604 UIPage::ERROR, | |
| 605 l10n_util::GetStringUTF16(IDS_ARC_ANDROID_MANAGEMENT_REQUIRED_ERROR)); | |
| 606 UpdateOptInCancelUMA(OptInCancelReason::ANDROID_MANAGEMENT_REQUIRED); | |
| 607 break; | |
| 608 case policy::AndroidManagementClient::Result::RESULT_ERROR: | |
| 609 ShutdownBridgeAndShowUI( | |
| 610 UIPage::ERROR, | |
| 611 l10n_util::GetStringUTF16(IDS_ARC_SERVER_COMMUNICATION_ERROR)); | |
| 612 UpdateOptInCancelUMA(OptInCancelReason::NETWORK_ERROR); | |
| 613 break; | |
| 614 default: | |
| 615 NOTREACHED(); | |
| 616 } | |
| 617 } | |
| 618 | |
| 531 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { | 619 std::ostream& operator<<(std::ostream& os, const ArcAuthService::State& state) { |
| 532 switch (state) { | 620 switch (state) { |
| 533 case ArcAuthService::State::STOPPED: | 621 case ArcAuthService::State::STOPPED: |
| 534 return os << kStateStopped; | 622 return os << kStateStopped; |
| 535 case ArcAuthService::State::FETCHING_CODE: | 623 case ArcAuthService::State::FETCHING_CODE: |
| 536 return os << kStateFetchingCode; | 624 return os << kStateFetchingCode; |
| 537 case ArcAuthService::State::ACTIVE: | 625 case ArcAuthService::State::ACTIVE: |
| 538 return os << kStateActive; | 626 return os << kStateActive; |
| 539 default: | 627 default: |
| 540 NOTREACHED(); | 628 NOTREACHED(); |
| 541 return os; | 629 return os; |
| 542 } | 630 } |
| 543 } | 631 } |
| 544 | 632 |
| 545 } // namespace arc | 633 } // namespace arc |
| OLD | NEW |