| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_session_manager.h" | 5 #include "chrome/browser/chromeos/arc/arc_session_manager.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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "chrome/browser/chromeos/arc/arc_support_host.h" | 22 #include "chrome/browser/chromeos/arc/arc_support_host.h" |
| 23 #include "chrome/browser/chromeos/arc/arc_util.h" | 23 #include "chrome/browser/chromeos/arc/arc_util.h" |
| 24 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_default_negotia
tor.h" | 24 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_default_negotia
tor.h" |
| 25 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator
.h" | 25 #include "chrome/browser/chromeos/arc/optin/arc_terms_of_service_oobe_negotiator
.h" |
| 26 #include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h" | 26 #include "chrome/browser/chromeos/arc/policy/arc_android_management_checker.h" |
| 27 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h" | 27 #include "chrome/browser/chromeos/arc/policy/arc_policy_util.h" |
| 28 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | 28 #include "chrome/browser/chromeos/login/ui/login_display_host.h" |
| 29 #include "chrome/browser/lifetime/application_lifetime.h" | 29 #include "chrome/browser/lifetime/application_lifetime.h" |
| 30 #include "chrome/browser/policy/profile_policy_connector.h" | 30 #include "chrome/browser/policy/profile_policy_connector.h" |
| 31 #include "chrome/browser/policy/profile_policy_connector_factory.h" | 31 #include "chrome/browser/policy/profile_policy_connector_factory.h" |
| 32 #include "chrome/browser/prefs/pref_service_syncable_util.h" | |
| 33 #include "chrome/browser/profiles/profile.h" | 32 #include "chrome/browser/profiles/profile.h" |
| 34 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" | 33 #include "chrome/browser/ui/app_list/arc/arc_app_launcher.h" |
| 35 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" | 34 #include "chrome/browser/ui/app_list/arc/arc_app_utils.h" |
| 36 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" | 35 #include "chrome/browser/ui/ash/multi_user/multi_user_util.h" |
| 37 #include "chrome/browser/ui/browser_commands.h" | 36 #include "chrome/browser/ui/browser_commands.h" |
| 38 #include "chrome/common/pref_names.h" | 37 #include "chrome/common/pref_names.h" |
| 39 #include "chrome/grit/generated_resources.h" | |
| 40 #include "chromeos/chromeos_switches.h" | 38 #include "chromeos/chromeos_switches.h" |
| 41 #include "chromeos/cryptohome/cryptohome_parameters.h" | 39 #include "chromeos/cryptohome/cryptohome_parameters.h" |
| 42 #include "chromeos/dbus/dbus_thread_manager.h" | 40 #include "chromeos/dbus/dbus_thread_manager.h" |
| 43 #include "chromeos/dbus/session_manager_client.h" | 41 #include "chromeos/dbus/session_manager_client.h" |
| 44 #include "components/arc/arc_bridge_service.h" | |
| 45 #include "components/arc/arc_session_runner.h" | 42 #include "components/arc/arc_session_runner.h" |
| 46 #include "components/arc/arc_util.h" | 43 #include "components/arc/arc_util.h" |
| 47 #include "components/pref_registry/pref_registry_syncable.h" | 44 #include "components/pref_registry/pref_registry_syncable.h" |
| 48 #include "components/prefs/pref_service.h" | 45 #include "components/prefs/pref_service.h" |
| 49 #include "components/sync_preferences/pref_service_syncable.h" | |
| 50 #include "content/public/browser/browser_thread.h" | 46 #include "content/public/browser/browser_thread.h" |
| 51 #include "extensions/browser/extension_prefs.h" | |
| 52 | 47 |
| 53 namespace arc { | 48 namespace arc { |
| 54 | 49 |
| 55 namespace { | 50 namespace { |
| 56 | 51 |
| 57 // Weak pointer. This class is owned by ArcServiceManager. | 52 // Weak pointer. This class is owned by ArcServiceManager. |
| 58 ArcSessionManager* g_arc_session_manager = nullptr; | 53 ArcSessionManager* g_arc_session_manager = nullptr; |
| 59 | 54 |
| 60 // Skip creating UI in unit tests | 55 // Skip creating UI in unit tests |
| 61 bool g_disable_ui_for_testing = false; | 56 bool g_disable_ui_for_testing = false; |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 chromeos::switches::kEnableArcOOBEOptIn)) | 120 chromeos::switches::kEnableArcOOBEOptIn)) |
| 126 return false; | 121 return false; |
| 127 if (!chromeos::LoginDisplayHost::default_host()) | 122 if (!chromeos::LoginDisplayHost::default_host()) |
| 128 return false; | 123 return false; |
| 129 return true; | 124 return true; |
| 130 } | 125 } |
| 131 | 126 |
| 132 // static | 127 // static |
| 133 void ArcSessionManager::DisableUIForTesting() { | 128 void ArcSessionManager::DisableUIForTesting() { |
| 134 g_disable_ui_for_testing = true; | 129 g_disable_ui_for_testing = true; |
| 135 // TODO(hidehiko): When the dependency to ArcAuthNotification from this | |
| 136 // class is removed, we should remove this as well. | |
| 137 ArcAuthNotification::DisableForTesting(); | |
| 138 } | 130 } |
| 139 | 131 |
| 140 // static | 132 // static |
| 141 void ArcSessionManager::EnableCheckAndroidManagementForTesting() { | 133 void ArcSessionManager::EnableCheckAndroidManagementForTesting() { |
| 142 g_enable_check_android_management_for_testing = true; | 134 g_enable_check_android_management_for_testing = true; |
| 143 } | 135 } |
| 144 | 136 |
| 145 void ArcSessionManager::OnSessionReady() { | 137 void ArcSessionManager::OnSessionReady() { |
| 146 for (auto& observer : arc_session_observer_list_) | 138 for (auto& observer : arc_session_observer_list_) |
| 147 observer.OnSessionReady(); | 139 observer.OnSessionReady(); |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 } | 417 } |
| 426 | 418 |
| 427 // Chrome may be shut down before completing ARC data removal. | 419 // Chrome may be shut down before completing ARC data removal. |
| 428 // In such a case, start removing the data now. | 420 // In such a case, start removing the data now. |
| 429 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { | 421 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { |
| 430 VLOG(1) << "ARC data removal requested in previous session."; | 422 VLOG(1) << "ARC data removal requested in previous session."; |
| 431 RemoveArcData(); | 423 RemoveArcData(); |
| 432 } | 424 } |
| 433 } | 425 } |
| 434 | 426 |
| 435 void ArcSessionManager::OnIsSyncingChanged() { | |
| 436 sync_preferences::PrefServiceSyncable* const pref_service_syncable = | |
| 437 PrefServiceSyncableFromProfile(profile_); | |
| 438 if (!pref_service_syncable->IsSyncing()) | |
| 439 return; | |
| 440 | |
| 441 pref_service_syncable->RemoveObserver(this); | |
| 442 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 443 chromeos::switches::kEnableArcOOBEOptIn) && | |
| 444 profile_->IsNewProfile() && | |
| 445 !profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { | |
| 446 ArcAuthNotification::Show(profile_); | |
| 447 } | |
| 448 } | |
| 449 | |
| 450 void ArcSessionManager::Shutdown() { | 427 void ArcSessionManager::Shutdown() { |
| 451 ArcAuthNotification::Hide(); | |
| 452 | |
| 453 enable_requested_ = false; | 428 enable_requested_ = false; |
| 454 ShutdownSession(); | 429 ShutdownSession(); |
| 455 if (support_host_) { | 430 if (support_host_) { |
| 456 support_host_->Close(); | 431 support_host_->Close(); |
| 457 support_host_->RemoveObserver(this); | 432 support_host_->RemoveObserver(this); |
| 458 support_host_.reset(); | 433 support_host_.reset(); |
| 459 } | 434 } |
| 460 if (profile_) { | |
| 461 sync_preferences::PrefServiceSyncable* pref_service_syncable = | |
| 462 PrefServiceSyncableFromProfile(profile_); | |
| 463 pref_service_syncable->RemoveObserver(this); | |
| 464 } | |
| 465 pref_change_registrar_.RemoveAll(); | |
| 466 context_.reset(); | 435 context_.reset(); |
| 467 profile_ = nullptr; | 436 profile_ = nullptr; |
| 468 SetState(State::NOT_INITIALIZED); | 437 SetState(State::NOT_INITIALIZED); |
| 469 } | 438 } |
| 470 | 439 |
| 471 void ArcSessionManager::StopArc() { | 440 void ArcSessionManager::StopArc() { |
| 472 if (state_ != State::STOPPED) { | 441 if (state_ != State::STOPPED) { |
| 473 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); | 442 profile_->GetPrefs()->SetBoolean(prefs::kArcSignedIn, false); |
| 474 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, false); | 443 profile_->GetPrefs()->SetBoolean(prefs::kArcTermsAccepted, false); |
| 475 } | 444 } |
| 476 ShutdownSession(); | 445 ShutdownSession(); |
| 477 if (support_host_) | 446 if (support_host_) |
| 478 support_host_->Close(); | 447 support_host_->Close(); |
| 479 } | 448 } |
| 480 | 449 |
| 481 void ArcSessionManager::StartPreferenceHandler() { | |
| 482 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 483 DCHECK(profile_); | |
| 484 | |
| 485 // Start observing Google Play Store enabled preference. | |
| 486 pref_change_registrar_.Init(profile_->GetPrefs()); | |
| 487 pref_change_registrar_.Add( | |
| 488 prefs::kArcEnabled, | |
| 489 base::Bind(&ArcSessionManager::OnOptInPreferenceChanged, | |
| 490 weak_ptr_factory_.GetWeakPtr())); | |
| 491 | |
| 492 // Set initial managed state to ArcSupportHost to update the message. | |
| 493 if (support_host_) { | |
| 494 support_host_->SetArcManaged( | |
| 495 IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_)); | |
| 496 } | |
| 497 | |
| 498 // Update the state based on the initial Google Play Store enabled value. | |
| 499 if (IsArcPlayStoreEnabledForProfile(profile_)) { | |
| 500 VLOG(1) << "ARC is already enabled."; | |
| 501 DCHECK(!enable_requested_); | |
| 502 RequestEnable(); | |
| 503 } else { | |
| 504 if (IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_)) { | |
| 505 // All users that can disable ARC by themselves will have the | |
| 506 // |kARcDataRemoveRequested| pref set, so we don't need to eagerly remove | |
| 507 // the data for that case. | |
| 508 // For managed users, the preference can change when the Profile object is | |
| 509 // not alive, so we still need to check it here in case it was disabled to | |
| 510 // ensure that the data is deleted in case it was disabled between | |
| 511 // launches. | |
| 512 VLOG(1) << "ARC is initially disabled for managed profile. " | |
| 513 << "Removing data."; | |
| 514 RemoveArcData(); | |
| 515 } | |
| 516 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); | |
| 517 OnIsSyncingChanged(); | |
| 518 } | |
| 519 } | |
| 520 | |
| 521 void ArcSessionManager::OnOptInPreferenceChanged() { | |
| 522 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 523 DCHECK(profile_); | |
| 524 | |
| 525 const bool is_play_store_enabled = IsArcPlayStoreEnabledForProfile(profile_); | |
| 526 const bool is_play_store_managed = | |
| 527 IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_); | |
| 528 if (!is_play_store_managed) { | |
| 529 // Update UMA only for non-Managed cases. | |
| 530 UpdateOptInActionUMA(is_play_store_enabled ? OptInActionType::OPTED_IN | |
| 531 : OptInActionType::OPTED_OUT); | |
| 532 | |
| 533 if (!is_play_store_enabled) { | |
| 534 // Remove the pinned Play Store icon launcher in Shelf. | |
| 535 // This is only for non-Managed cases. In managed cases, it is expected | |
| 536 // to be "disabled" rather than "removed", so keep it here. | |
| 537 auto* shelf_delegate = ash::WmShell::HasInstance() | |
| 538 ? ash::WmShell::Get()->shelf_delegate() | |
| 539 : nullptr; | |
| 540 if (shelf_delegate) | |
| 541 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); | |
| 542 } | |
| 543 } | |
| 544 | |
| 545 if (support_host_) | |
| 546 support_host_->SetArcManaged(is_play_store_managed); | |
| 547 | |
| 548 // Hide auth notification if it was opened before and arc.enabled pref was | |
| 549 // explicitly set to true or false. | |
| 550 if (profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) | |
| 551 ArcAuthNotification::Hide(); | |
| 552 | |
| 553 if (is_play_store_enabled) | |
| 554 RequestEnable(); | |
| 555 else | |
| 556 RequestDisable(); | |
| 557 | |
| 558 for (auto& observer : observer_list_) | |
| 559 observer.OnArcPlayStoreEnabledChanged(is_play_store_enabled); | |
| 560 } | |
| 561 | |
| 562 void ArcSessionManager::ShutdownSession() { | 450 void ArcSessionManager::ShutdownSession() { |
| 563 arc_sign_in_timer_.Stop(); | 451 arc_sign_in_timer_.Stop(); |
| 564 playstore_launcher_.reset(); | 452 playstore_launcher_.reset(); |
| 565 terms_of_service_negotiator_.reset(); | 453 terms_of_service_negotiator_.reset(); |
| 566 android_management_checker_.reset(); | 454 android_management_checker_.reset(); |
| 567 arc_session_runner_->RequestStop(); | 455 arc_session_runner_->RequestStop(); |
| 568 // TODO(hidehiko): The ARC instance's stopping is asynchronous, so it might | 456 // TODO(hidehiko): The ARC instance's stopping is asynchronous, so it might |
| 569 // still be running when we return from this function. Do not set the | 457 // still be running when we return from this function. Do not set the |
| 570 // STOPPED state immediately here. | 458 // STOPPED state immediately here. |
| 571 if (state_ != State::NOT_INITIALIZED && state_ != State::REMOVING_DATA_DIR) | 459 if (state_ != State::NOT_INITIALIZED && state_ != State::REMOVING_DATA_DIR) |
| 572 SetState(State::STOPPED); | 460 SetState(State::STOPPED); |
| 573 } | 461 } |
| 574 | 462 |
| 575 void ArcSessionManager::AddObserver(Observer* observer) { | 463 void ArcSessionManager::AddObserver(Observer* observer) { |
| 576 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 464 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 577 observer_list_.AddObserver(observer); | 465 observer_list_.AddObserver(observer); |
| 578 } | 466 } |
| 579 | 467 |
| 580 void ArcSessionManager::RemoveObserver(Observer* observer) { | 468 void ArcSessionManager::RemoveObserver(Observer* observer) { |
| 581 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 469 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 582 observer_list_.RemoveObserver(observer); | 470 observer_list_.RemoveObserver(observer); |
| 583 } | 471 } |
| 584 | 472 |
| 473 void ArcSessionManager::NotifyArcPlayStoreEnabledChanged(bool enabled) { |
| 474 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 475 for (auto& observer : observer_list_) |
| 476 observer.OnArcPlayStoreEnabledChanged(enabled); |
| 477 } |
| 478 |
| 585 void ArcSessionManager::AddSessionObserver(ArcSessionObserver* observer) { | 479 void ArcSessionManager::AddSessionObserver(ArcSessionObserver* observer) { |
| 586 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 480 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 587 arc_session_observer_list_.AddObserver(observer); | 481 arc_session_observer_list_.AddObserver(observer); |
| 588 } | 482 } |
| 589 | 483 |
| 590 void ArcSessionManager::RemoveSessionObserver(ArcSessionObserver* observer) { | 484 void ArcSessionManager::RemoveSessionObserver(ArcSessionObserver* observer) { |
| 591 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 485 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 592 arc_session_observer_list_.RemoveObserver(observer); | 486 arc_session_observer_list_.RemoveObserver(observer); |
| 593 } | 487 } |
| 594 | 488 |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1000 | 894 |
| 1001 #undef MAP_STATE | 895 #undef MAP_STATE |
| 1002 | 896 |
| 1003 // Some compilers report an error even if all values of an enum-class are | 897 // Some compilers report an error even if all values of an enum-class are |
| 1004 // covered exhaustively in a switch statement. | 898 // covered exhaustively in a switch statement. |
| 1005 NOTREACHED() << "Invalid value " << static_cast<int>(state); | 899 NOTREACHED() << "Invalid value " << static_cast<int>(state); |
| 1006 return os; | 900 return os; |
| 1007 } | 901 } |
| 1008 | 902 |
| 1009 } // namespace arc | 903 } // namespace arc |
| OLD | NEW |