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 "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 "chrome/browser/chromeos/arc/arc_android_management_checker.h" | 16 #include "chrome/browser/chromeos/arc/arc_android_management_checker.h" |
| 17 #include "chrome/browser/chromeos/arc/arc_auth_context.h" | 17 #include "chrome/browser/chromeos/arc/arc_auth_context.h" |
| 18 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" | 18 #include "chrome/browser/chromeos/arc/arc_auth_notification.h" |
| 19 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" | 19 #include "chrome/browser/chromeos/arc/arc_optin_uma.h" |
| 20 #include "chrome/browser/chromeos/arc/arc_support_host.h" | 20 #include "chrome/browser/chromeos/arc/arc_support_host.h" |
| 21 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 21 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
| 22 #include "chrome/browser/extensions/extension_util.h" | 22 #include "chrome/browser/extensions/extension_util.h" |
| 23 #include "chrome/browser/policy/profile_policy_connector.h" | 23 #include "chrome/browser/policy/profile_policy_connector.h" |
| 24 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 24 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 25 #include "chrome/browser/prefs/pref_service_syncable_util.h" | |
| 26 #include "chrome/browser/profiles/profile.h" | 25 #include "chrome/browser/profiles/profile.h" |
| 27 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" | 26 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" |
| 28 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 27 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
| 29 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 28 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 30 #include "chrome/browser/ui/extensions/app_launch_params.h" | 29 #include "chrome/browser/ui/extensions/app_launch_params.h" |
| 31 #include "chrome/browser/ui/extensions/application_launch.h" | 30 #include "chrome/browser/ui/extensions/application_launch.h" |
| 32 #include "chrome/common/pref_names.h" | 31 #include "chrome/common/pref_names.h" |
| 33 #include "chrome/grit/generated_resources.h" | 32 #include "chrome/grit/generated_resources.h" |
| 34 #include "chromeos/chromeos_switches.h" | 33 #include "chromeos/chromeos_switches.h" |
| 35 #include "chromeos/cryptohome/cryptohome_parameters.h" | 34 #include "chromeos/cryptohome/cryptohome_parameters.h" |
| 36 #include "chromeos/dbus/dbus_thread_manager.h" | 35 #include "chromeos/dbus/dbus_thread_manager.h" |
| 37 #include "chromeos/dbus/session_manager_client.h" | 36 #include "chromeos/dbus/session_manager_client.h" |
| 38 #include "components/arc/arc_bridge_service.h" | 37 #include "components/arc/arc_bridge_service.h" |
| 39 #include "components/policy/core/browser/browser_policy_connector.h" | 38 #include "components/policy/core/browser/browser_policy_connector.h" |
| 40 #include "components/pref_registry/pref_registry_syncable.h" | 39 #include "components/pref_registry/pref_registry_syncable.h" |
| 41 #include "components/prefs/pref_service.h" | 40 #include "components/prefs/pref_service.h" |
| 42 #include "components/syncable_prefs/pref_service_syncable.h" | |
| 43 #include "components/user_manager/user.h" | 41 #include "components/user_manager/user.h" |
| 44 #include "content/public/browser/browser_thread.h" | 42 #include "content/public/browser/browser_thread.h" |
| 45 #include "extensions/browser/app_window/app_window_registry.h" | 43 #include "extensions/browser/app_window/app_window_registry.h" |
| 46 #include "extensions/browser/extension_prefs.h" | 44 #include "extensions/browser/extension_prefs.h" |
| 47 #include "extensions/browser/extension_registry.h" | 45 #include "extensions/browser/extension_registry.h" |
| 48 #include "ui/base/l10n/l10n_util.h" | 46 #include "ui/base/l10n/l10n_util.h" |
| 49 | 47 |
| 50 namespace arc { | 48 namespace arc { |
| 51 | 49 |
| 52 namespace { | 50 namespace { |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 391 | 389 |
| 392 // TODO(khmel): Move this to IsAllowedForProfile. | 390 // TODO(khmel): Move this to IsAllowedForProfile. |
| 393 if (IsArcDisabledForEnterprise() && IsAccountManaged(profile)) { | 391 if (IsArcDisabledForEnterprise() && IsAccountManaged(profile)) { |
| 394 VLOG(2) << "Enterprise users are not supported in ARC."; | 392 VLOG(2) << "Enterprise users are not supported in ARC."; |
| 395 return; | 393 return; |
| 396 } | 394 } |
| 397 | 395 |
| 398 profile_ = profile; | 396 profile_ = profile; |
| 399 SetState(State::STOPPED); | 397 SetState(State::STOPPED); |
| 400 | 398 |
| 401 PrefServiceSyncableFromProfile(profile_)->AddSyncedPrefObserver( | |
| 402 prefs::kArcEnabled, this); | |
| 403 | |
| 404 context_.reset(new ArcAuthContext(this, profile_)); | 399 context_.reset(new ArcAuthContext(this, profile_)); |
| 405 | 400 |
| 406 // In case UI is disabled we assume that ARC is opted-in. | 401 // In case UI is disabled we assume that ARC is opted-in. |
| 407 if (IsOptInVerificationDisabled()) { | 402 if (IsOptInVerificationDisabled()) { |
| 408 auth_code_.clear(); | 403 auth_code_.clear(); |
| 409 StartArc(); | 404 StartArc(); |
| 410 return; | 405 return; |
| 411 } | 406 } |
| 412 | 407 |
| 413 if (!g_disable_ui_for_testing || | 408 if (!g_disable_ui_for_testing || |
| 414 g_enable_check_android_management_for_testing) { | 409 g_enable_check_android_management_for_testing) { |
| 415 ArcAndroidManagementChecker::StartClient(); | 410 ArcAndroidManagementChecker::StartClient(); |
| 416 } | 411 } |
| 417 pref_change_registrar_.Init(profile_->GetPrefs()); | 412 pref_change_registrar_.Init(profile_->GetPrefs()); |
| 418 pref_change_registrar_.Add( | 413 pref_change_registrar_.Add( |
| 419 prefs::kArcEnabled, base::Bind(&ArcAuthService::OnOptInPreferenceChanged, | 414 prefs::kArcEnabled, base::Bind(&ArcAuthService::OnOptInPreferenceChanged, |
| 420 weak_ptr_factory_.GetWeakPtr())); | 415 weak_ptr_factory_.GetWeakPtr())); |
| 421 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { | 416 if (profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled)) { |
| 422 OnOptInPreferenceChanged(); | 417 OnOptInPreferenceChanged(); |
| 423 } else { | 418 } else { |
| 424 UpdateEnabledStateUMA(false); | 419 UpdateEnabledStateUMA(false); |
| 425 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); | |
| 426 OnIsSyncingChanged(); | |
| 427 } | |
| 428 } | |
| 429 | |
| 430 void ArcAuthService::OnIsSyncingChanged() { | |
| 431 syncable_prefs::PrefServiceSyncable* const pref_service_syncable = | |
| 432 PrefServiceSyncableFromProfile(profile_); | |
| 433 if (!pref_service_syncable->IsSyncing()) | |
| 434 return; | |
| 435 | |
| 436 pref_service_syncable->RemoveObserver(this); | |
| 437 | |
| 438 if (IsArcEnabled()) | |
| 439 OnOptInPreferenceChanged(); | |
| 440 | |
| 441 if (!g_disable_ui_for_testing && profile_->IsNewProfile() && | |
| 442 !profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { | |
| 443 ArcAuthNotification::Show(profile_); | |
| 444 } | 420 } |
| 445 } | 421 } |
| 446 | 422 |
| 447 void ArcAuthService::Shutdown() { | 423 void ArcAuthService::Shutdown() { |
| 448 ShutdownBridgeAndCloseUI(); | 424 ShutdownBridgeAndCloseUI(); |
| 449 if (profile_) { | |
| 450 syncable_prefs::PrefServiceSyncable* pref_service_syncable = | |
| 451 PrefServiceSyncableFromProfile(profile_); | |
| 452 pref_service_syncable->RemoveObserver(this); | |
| 453 pref_service_syncable->RemoveSyncedPrefObserver(prefs::kArcEnabled, this); | |
| 454 } | |
| 455 pref_change_registrar_.RemoveAll(); | 425 pref_change_registrar_.RemoveAll(); |
| 456 context_.reset(); | 426 context_.reset(); |
| 457 profile_ = nullptr; | 427 profile_ = nullptr; |
| 458 SetState(State::NOT_INITIALIZED); | 428 SetState(State::NOT_INITIALIZED); |
| 459 } | 429 } |
| 460 | 430 |
| 461 void ArcAuthService::ShowUI(UIPage page, const base::string16& status) { | 431 void ArcAuthService::ShowUI(UIPage page, const base::string16& status) { |
| 462 if (g_disable_ui_for_testing || IsOptInVerificationDisabled()) | 432 if (g_disable_ui_for_testing || IsOptInVerificationDisabled()) |
| 463 return; | 433 return; |
| 464 | 434 |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 481 profile_, extension, NEW_WINDOW, extensions::SOURCE_CHROME_INTERNAL)); | 451 profile_, extension, NEW_WINDOW, extensions::SOURCE_CHROME_INTERNAL)); |
| 482 } | 452 } |
| 483 | 453 |
| 484 void ArcAuthService::OnContextReady() { | 454 void ArcAuthService::OnContextReady() { |
| 485 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 455 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 486 | 456 |
| 487 DCHECK(!initial_opt_in_); | 457 DCHECK(!initial_opt_in_); |
| 488 CheckAndroidManagement(false); | 458 CheckAndroidManagement(false); |
| 489 } | 459 } |
| 490 | 460 |
| 491 void ArcAuthService::OnSyncedPrefChanged(const std::string& path, | |
| 492 bool from_sync) { | |
| 493 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 494 | |
| 495 // Update UMA only for local changes | |
| 496 if (!from_sync) { | |
| 497 const bool arc_enabled = | |
| 498 profile_->GetPrefs()->GetBoolean(prefs::kArcEnabled); | |
| 499 UpdateOptInActionUMA(arc_enabled ? OptInActionType::OPTED_IN | |
| 500 : OptInActionType::OPTED_OUT); | |
| 501 | |
| 502 if (!disable_arc_from_ui_ && !arc_enabled && !IsArcManaged()) { | |
| 503 ash::ShelfDelegate* shelf_delegate = GetShelfDelegate(); | |
| 504 if (shelf_delegate) | |
| 505 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); | |
| 506 } | |
| 507 } | |
| 508 } | |
| 509 | |
| 510 void ArcAuthService::StopArc() { | 461 void ArcAuthService::StopArc() { |
| 511 if (state_ != State::STOPPED) { | 462 if (state_ != State::STOPPED) { |
| 512 UpdateEnabledStateUMA(false); | 463 UpdateEnabledStateUMA(false); |
| 513 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); | 464 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); |
| 514 } | 465 } |
| 515 ShutdownBridgeAndCloseUI(); | 466 ShutdownBridgeAndCloseUI(); |
| 516 } | 467 } |
| 517 | 468 |
| 518 void ArcAuthService::OnOptInPreferenceChanged() { | 469 void ArcAuthService::OnOptInPreferenceChanged() { |
| 519 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 470 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 520 DCHECK(profile_); | 471 DCHECK(profile_); |
| 521 | 472 |
| 522 const bool arc_enabled = IsArcEnabled(); | 473 const bool arc_enabled = IsArcEnabled(); |
| 523 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInEnabled(arc_enabled)); | 474 FOR_EACH_OBSERVER(Observer, observer_list_, OnOptInEnabled(arc_enabled)); |
| 524 | 475 |
| 476 UpdateOptInActionUMA(arc_enabled ? OptInActionType::OPTED_IN | |
|
khmel
2016/08/03 14:28:32
Now this statistics is incorrect for managed pref.
| |
| 477 : OptInActionType::OPTED_OUT); | |
| 478 | |
| 479 if (!disable_arc_from_ui_ && !arc_enabled && !IsArcManaged()) { | |
| 480 ash::ShelfDelegate* shelf_delegate = GetShelfDelegate(); | |
| 481 if (shelf_delegate) | |
| 482 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); | |
| 483 } | |
| 484 | |
| 525 if (!arc_enabled) { | 485 if (!arc_enabled) { |
| 526 StopArc(); | 486 StopArc(); |
| 527 return; | 487 return; |
| 528 } | 488 } |
| 529 | 489 |
| 530 if (state_ == State::ACTIVE) | 490 if (state_ == State::ACTIVE) |
| 531 return; | 491 return; |
| 532 CloseUI(); | 492 CloseUI(); |
| 533 auth_code_.clear(); | 493 auth_code_.clear(); |
| 534 | 494 |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 806 return os << kStateFetchingCode; | 766 return os << kStateFetchingCode; |
| 807 case ArcAuthService::State::ACTIVE: | 767 case ArcAuthService::State::ACTIVE: |
| 808 return os << kStateActive; | 768 return os << kStateActive; |
| 809 default: | 769 default: |
| 810 NOTREACHED(); | 770 NOTREACHED(); |
| 811 return os; | 771 return os; |
| 812 } | 772 } |
| 813 } | 773 } |
| 814 | 774 |
| 815 } // namespace arc | 775 } // namespace arc |
| OLD | NEW |