| 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::OnSessionStopped(ArcStopReason reason, | 137 void ArcSessionManager::OnSessionStopped(ArcStopReason reason, |
| 146 bool restarting) { | 138 bool restarting) { |
| 147 if (restarting) { | 139 if (restarting) { |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 428 } | 420 } |
| 429 | 421 |
| 430 // Chrome may be shut down before completing ARC data removal. | 422 // Chrome may be shut down before completing ARC data removal. |
| 431 // In such a case, start removing the data now. | 423 // In such a case, start removing the data now. |
| 432 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { | 424 if (profile_->GetPrefs()->GetBoolean(prefs::kArcDataRemoveRequested)) { |
| 433 VLOG(1) << "ARC data removal requested in previous session."; | 425 VLOG(1) << "ARC data removal requested in previous session."; |
| 434 RemoveArcData(); | 426 RemoveArcData(); |
| 435 } | 427 } |
| 436 } | 428 } |
| 437 | 429 |
| 438 void ArcSessionManager::OnIsSyncingChanged() { | |
| 439 sync_preferences::PrefServiceSyncable* const pref_service_syncable = | |
| 440 PrefServiceSyncableFromProfile(profile_); | |
| 441 if (!pref_service_syncable->IsSyncing()) | |
| 442 return; | |
| 443 | |
| 444 pref_service_syncable->RemoveObserver(this); | |
| 445 if (!base::CommandLine::ForCurrentProcess()->HasSwitch( | |
| 446 chromeos::switches::kEnableArcOOBEOptIn) && | |
| 447 profile_->IsNewProfile() && | |
| 448 !profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) { | |
| 449 ArcAuthNotification::Show(profile_); | |
| 450 } | |
| 451 } | |
| 452 | |
| 453 void ArcSessionManager::Shutdown() { | 430 void ArcSessionManager::Shutdown() { |
| 454 ArcAuthNotification::Hide(); | |
| 455 | |
| 456 enable_requested_ = false; | 431 enable_requested_ = false; |
| 457 ShutdownSession(); | 432 ShutdownSession(); |
| 458 if (support_host_) { | 433 if (support_host_) { |
| 459 support_host_->Close(); | 434 support_host_->Close(); |
| 460 support_host_->RemoveObserver(this); | 435 support_host_->RemoveObserver(this); |
| 461 support_host_.reset(); | 436 support_host_.reset(); |
| 462 } | 437 } |
| 463 if (profile_) { | |
| 464 sync_preferences::PrefServiceSyncable* pref_service_syncable = | |
| 465 PrefServiceSyncableFromProfile(profile_); | |
| 466 pref_service_syncable->RemoveObserver(this); | |
| 467 } | |
| 468 pref_change_registrar_.RemoveAll(); | |
| 469 context_.reset(); | 438 context_.reset(); |
| 470 profile_ = nullptr; | 439 profile_ = nullptr; |
| 471 SetState(State::NOT_INITIALIZED); | 440 SetState(State::NOT_INITIALIZED); |
| 472 } | 441 } |
| 473 | 442 |
| 474 void ArcSessionManager::StartPreferenceHandler() { | |
| 475 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 476 DCHECK(profile_); | |
| 477 | |
| 478 // Start observing Google Play Store enabled preference. | |
| 479 pref_change_registrar_.Init(profile_->GetPrefs()); | |
| 480 pref_change_registrar_.Add( | |
| 481 prefs::kArcEnabled, | |
| 482 base::Bind(&ArcSessionManager::OnOptInPreferenceChanged, | |
| 483 weak_ptr_factory_.GetWeakPtr())); | |
| 484 | |
| 485 // Set initial managed state to ArcSupportHost to update the message. | |
| 486 if (support_host_) { | |
| 487 support_host_->SetArcManaged( | |
| 488 IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_)); | |
| 489 } | |
| 490 | |
| 491 // Update the state based on the initial Google Play Store enabled value. | |
| 492 if (IsArcPlayStoreEnabledForProfile(profile_)) { | |
| 493 VLOG(1) << "ARC is already enabled."; | |
| 494 DCHECK(!enable_requested_); | |
| 495 RequestEnable(); | |
| 496 } else { | |
| 497 if (IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_)) { | |
| 498 // All users that can disable ARC by themselves will have the | |
| 499 // |kARcDataRemoveRequested| pref set, so we don't need to eagerly remove | |
| 500 // the data for that case. | |
| 501 // For managed users, the preference can change when the Profile object is | |
| 502 // not alive, so we still need to check it here in case it was disabled to | |
| 503 // ensure that the data is deleted in case it was disabled between | |
| 504 // launches. | |
| 505 VLOG(1) << "ARC is initially disabled for managed profile. " | |
| 506 << "Removing data."; | |
| 507 RemoveArcData(); | |
| 508 } | |
| 509 PrefServiceSyncableFromProfile(profile_)->AddObserver(this); | |
| 510 OnIsSyncingChanged(); | |
| 511 } | |
| 512 } | |
| 513 | |
| 514 void ArcSessionManager::OnOptInPreferenceChanged() { | |
| 515 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | |
| 516 DCHECK(profile_); | |
| 517 | |
| 518 const bool is_play_store_enabled = IsArcPlayStoreEnabledForProfile(profile_); | |
| 519 const bool is_play_store_managed = | |
| 520 IsArcPlayStoreEnabledPreferenceManagedForProfile(profile_); | |
| 521 if (!is_play_store_managed) { | |
| 522 // Update UMA only for non-Managed cases. | |
| 523 UpdateOptInActionUMA(is_play_store_enabled ? OptInActionType::OPTED_IN | |
| 524 : OptInActionType::OPTED_OUT); | |
| 525 | |
| 526 if (!is_play_store_enabled) { | |
| 527 // Remove the pinned Play Store icon launcher in Shelf. | |
| 528 // This is only for non-Managed cases. In managed cases, it is expected | |
| 529 // to be "disabled" rather than "removed", so keep it here. | |
| 530 auto* shelf_delegate = ash::WmShell::HasInstance() | |
| 531 ? ash::WmShell::Get()->shelf_delegate() | |
| 532 : nullptr; | |
| 533 if (shelf_delegate) | |
| 534 shelf_delegate->UnpinAppWithID(ArcSupportHost::kHostAppId); | |
| 535 } | |
| 536 } | |
| 537 | |
| 538 if (support_host_) | |
| 539 support_host_->SetArcManaged(is_play_store_managed); | |
| 540 | |
| 541 // Hide auth notification if it was opened before and arc.enabled pref was | |
| 542 // explicitly set to true or false. | |
| 543 if (profile_->GetPrefs()->HasPrefPath(prefs::kArcEnabled)) | |
| 544 ArcAuthNotification::Hide(); | |
| 545 | |
| 546 if (is_play_store_enabled) | |
| 547 RequestEnable(); | |
| 548 else | |
| 549 RequestDisable(); | |
| 550 | |
| 551 for (auto& observer : observer_list_) | |
| 552 observer.OnArcPlayStoreEnabledChanged(is_play_store_enabled); | |
| 553 } | |
| 554 | 443 |
| 555 void ArcSessionManager::ShutdownSession() { | 444 void ArcSessionManager::ShutdownSession() { |
| 556 arc_sign_in_timer_.Stop(); | 445 arc_sign_in_timer_.Stop(); |
| 557 playstore_launcher_.reset(); | 446 playstore_launcher_.reset(); |
| 558 terms_of_service_negotiator_.reset(); | 447 terms_of_service_negotiator_.reset(); |
| 559 android_management_checker_.reset(); | 448 android_management_checker_.reset(); |
| 560 arc_session_runner_->RequestStop(); | 449 arc_session_runner_->RequestStop(); |
| 561 // TODO(hidehiko): The ARC instance's stopping is asynchronous, so it might | 450 // TODO(hidehiko): The ARC instance's stopping is asynchronous, so it might |
| 562 // still be running when we return from this function. Do not set the | 451 // still be running when we return from this function. Do not set the |
| 563 // STOPPED state immediately here. | 452 // STOPPED state immediately here. |
| 564 if (state_ != State::NOT_INITIALIZED && state_ != State::REMOVING_DATA_DIR) | 453 if (state_ != State::NOT_INITIALIZED && state_ != State::REMOVING_DATA_DIR) |
| 565 SetState(State::STOPPED); | 454 SetState(State::STOPPED); |
| 566 } | 455 } |
| 567 | 456 |
| 568 void ArcSessionManager::AddObserver(Observer* observer) { | 457 void ArcSessionManager::AddObserver(Observer* observer) { |
| 569 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 458 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 570 observer_list_.AddObserver(observer); | 459 observer_list_.AddObserver(observer); |
| 571 } | 460 } |
| 572 | 461 |
| 573 void ArcSessionManager::RemoveObserver(Observer* observer) { | 462 void ArcSessionManager::RemoveObserver(Observer* observer) { |
| 574 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 463 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 575 observer_list_.RemoveObserver(observer); | 464 observer_list_.RemoveObserver(observer); |
| 576 } | 465 } |
| 577 | 466 |
| 467 void ArcSessionManager::NotifyArcPlayStoreEnabledChanged(bool enabled) { |
| 468 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 469 for (auto& observer : observer_list_) |
| 470 observer.OnArcPlayStoreEnabledChanged(enabled); |
| 471 } |
| 472 |
| 578 bool ArcSessionManager::IsSessionRunning() const { | 473 bool ArcSessionManager::IsSessionRunning() const { |
| 579 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 474 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 580 return arc_session_runner_->IsRunning(); | 475 return arc_session_runner_->IsRunning(); |
| 581 } | 476 } |
| 582 | 477 |
| 583 bool ArcSessionManager::IsSessionStopped() const { | 478 bool ArcSessionManager::IsSessionStopped() const { |
| 584 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); | 479 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
| 585 return arc_session_runner_->IsStopped(); | 480 return arc_session_runner_->IsStopped(); |
| 586 } | 481 } |
| 587 | 482 |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 993 | 888 |
| 994 #undef MAP_STATE | 889 #undef MAP_STATE |
| 995 | 890 |
| 996 // Some compilers report an error even if all values of an enum-class are | 891 // Some compilers report an error even if all values of an enum-class are |
| 997 // covered exhaustively in a switch statement. | 892 // covered exhaustively in a switch statement. |
| 998 NOTREACHED() << "Invalid value " << static_cast<int>(state); | 893 NOTREACHED() << "Invalid value " << static_cast<int>(state); |
| 999 return os; | 894 return os; |
| 1000 } | 895 } |
| 1001 | 896 |
| 1002 } // namespace arc | 897 } // namespace arc |
| OLD | NEW |