1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325
|
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/browser_process_platform_part_ash.h"
#include <memory>
#include <utility>
#include "base/check_op.h"
#include "base/functional/bind.h"
#include "base/memory/singleton.h"
#include "base/time/default_clock.h"
#include "base/time/default_tick_clock.h"
#include "base/time/tick_clock.h"
#include "chrome/browser/ash/crosapi/browser_manager.h"
#include "chrome/browser/ash/login/saml/in_session_password_change_manager.h"
#include "chrome/browser/ash/login/session/chrome_session_manager.h"
#include "chrome/browser/ash/login/users/chrome_user_manager_impl.h"
#include "chrome/browser/ash/net/ash_proxy_monitor.h"
#include "chrome/browser/ash/net/delay_network_call.h"
#include "chrome/browser/ash/net/system_proxy_manager.h"
#include "chrome/browser/ash/policy/core/browser_policy_connector_ash.h"
#include "chrome/browser/ash/profiles/profile_helper.h"
#include "chrome/browser/ash/scheduler_configuration_manager.h"
#include "chrome/browser/ash/settings/cros_settings.h"
#include "chrome/browser/ash/system/automatic_reboot_manager.h"
#include "chrome/browser/ash/system/device_disabling_manager.h"
#include "chrome/browser/ash/system/device_disabling_manager_default_delegate.h"
#include "chrome/browser/ash/system/system_clock.h"
#include "chrome/browser/ash/system/timezone_resolver_manager.h"
#include "chrome/browser/ash/system/timezone_util.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/component_updater/metadata_table_chromeos.h"
#include "chrome/common/chrome_switches.h"
#include "chromeos/ash/components/account_manager/account_manager_factory.h"
#include "chromeos/ash/components/browser_context_helper/browser_context_flusher.h"
#include "chromeos/ash/components/dbus/debug_daemon/debug_daemon_client.h"
#include "chromeos/ash/components/geolocation/simple_geolocation_provider.h"
#include "chromeos/ash/components/timezone/timezone_resolver.h"
#include "components/keep_alive_registry/keep_alive_types.h"
#include "components/keep_alive_registry/scoped_keep_alive.h"
#include "components/keyed_service/content/browser_context_keyed_service_shutdown_notifier_factory.h"
#include "components/session_manager/core/session_manager.h"
#include "components/user_manager/user_manager.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/preferences/public/mojom/preferences.mojom.h"
#include "services/service_manager/public/cpp/binder_registry.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "services/service_manager/public/cpp/service.h"
namespace {
class PrimaryProfileServicesShutdownNotifierFactory
: public BrowserContextKeyedServiceShutdownNotifierFactory {
public:
static PrimaryProfileServicesShutdownNotifierFactory* GetInstance() {
return base::Singleton<
PrimaryProfileServicesShutdownNotifierFactory>::get();
}
PrimaryProfileServicesShutdownNotifierFactory(
const PrimaryProfileServicesShutdownNotifierFactory&) = delete;
PrimaryProfileServicesShutdownNotifierFactory& operator=(
const PrimaryProfileServicesShutdownNotifierFactory&) = delete;
private:
friend struct base::DefaultSingletonTraits<
PrimaryProfileServicesShutdownNotifierFactory>;
PrimaryProfileServicesShutdownNotifierFactory()
: BrowserContextKeyedServiceShutdownNotifierFactory(
"PrimaryProfileServices") {}
~PrimaryProfileServicesShutdownNotifierFactory() override {}
};
} // namespace
BrowserProcessPlatformPart::BrowserProcessPlatformPart()
: created_profile_helper_(false),
browser_context_flusher_(std::make_unique<ash::BrowserContextFlusher>()),
account_manager_factory_(std::make_unique<ash::AccountManagerFactory>()) {
}
BrowserProcessPlatformPart::~BrowserProcessPlatformPart() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
}
void BrowserProcessPlatformPart::InitializeAutomaticRebootManager() {
DCHECK(!automatic_reboot_manager_);
automatic_reboot_manager_ =
std::make_unique<ash::system::AutomaticRebootManager>(
base::DefaultClock::GetInstance(),
base::DefaultTickClock::GetInstance());
}
void BrowserProcessPlatformPart::ShutdownAutomaticRebootManager() {
automatic_reboot_manager_.reset();
}
void BrowserProcessPlatformPart::InitializeChromeUserManager() {
DCHECK(!chrome_user_manager_);
chrome_user_manager_ = ash::ChromeUserManagerImpl::CreateChromeUserManager();
// LoginState and DeviceCloudPolicyManager outlives UserManager, so on
// their initialization, there's no way to start observing UserManager.
// This is the earliest timing to do so.
if (auto* login_state = ash::LoginState::Get()) {
login_state->OnUserManagerCreated(chrome_user_manager_.get());
}
if (auto* policy_manager =
browser_policy_connector_ash()->GetDeviceCloudPolicyManager()) {
policy_manager->OnUserManagerCreated(chrome_user_manager_.get());
}
chrome_user_manager_->Initialize();
}
void BrowserProcessPlatformPart::DestroyChromeUserManager() {
chrome_user_manager_->Destroy();
if (auto* policy_manager =
browser_policy_connector_ash()->GetDeviceCloudPolicyManager()) {
policy_manager->OnUserManagerWillBeDestroyed(chrome_user_manager_.get());
}
if (auto* login_state = ash::LoginState::Get()) {
login_state->OnUserManagerWillBeDestroyed(chrome_user_manager_.get());
}
chrome_user_manager_.reset();
}
void BrowserProcessPlatformPart::InitializeDeviceDisablingManager() {
DCHECK(!device_disabling_manager_);
device_disabling_manager_delegate_ =
std::make_unique<ash::system::DeviceDisablingManagerDefaultDelegate>();
device_disabling_manager_ =
std::make_unique<ash::system::DeviceDisablingManager>(
device_disabling_manager_delegate_.get(), ash::CrosSettings::Get(),
user_manager::UserManager::Get());
device_disabling_manager_->Init();
}
void BrowserProcessPlatformPart::ShutdownDeviceDisablingManager() {
device_disabling_manager_.reset();
device_disabling_manager_delegate_.reset();
}
void BrowserProcessPlatformPart::InitializeSessionManager() {
DCHECK(!session_manager_);
session_manager_ = std::make_unique<ash::ChromeSessionManager>();
}
void BrowserProcessPlatformPart::ShutdownSessionManager() {
session_manager_.reset();
}
void BrowserProcessPlatformPart::InitializeCrosComponentManager() {
if (using_testing_cros_component_manager_)
return;
DCHECK(!cros_component_manager_);
cros_component_manager_ =
base::MakeRefCounted<component_updater::CrOSComponentInstaller>(
std::make_unique<component_updater::MetadataTable>(
g_browser_process->local_state()),
g_browser_process->component_updater());
// Register all installed components for regular update.
cros_component_manager_->RegisterInstalled();
}
void BrowserProcessPlatformPart::ShutdownCrosComponentManager() {
if (using_testing_cros_component_manager_)
return;
cros_component_manager_.reset();
}
void BrowserProcessPlatformPart::InitializeSchedulerConfigurationManager() {
DCHECK(!scheduler_configuration_manager_);
scheduler_configuration_manager_ =
std::make_unique<ash::SchedulerConfigurationManager>(
ash::DebugDaemonClient::Get(), g_browser_process->local_state());
}
void BrowserProcessPlatformPart::ShutdownSchedulerConfigurationManager() {
scheduler_configuration_manager_.reset();
}
void BrowserProcessPlatformPart::InitializeAshProxyMonitor() {
DCHECK(!ash_proxy_monitor_);
ash_proxy_monitor_ = std::make_unique<ash::AshProxyMonitor>(
g_browser_process->local_state(), g_browser_process->profile_manager());
}
void BrowserProcessPlatformPart::ShutdownAshProxyMonitor() {
ash_proxy_monitor_.reset();
}
void BrowserProcessPlatformPart::InitializePrimaryProfileServices(
Profile* primary_profile) {
DCHECK(primary_profile);
DCHECK(!in_session_password_change_manager_);
in_session_password_change_manager_ =
ash::InSessionPasswordChangeManager::CreateIfEnabled(primary_profile);
primary_profile_shutdown_subscription_ =
PrimaryProfileServicesShutdownNotifierFactory::GetInstance()
->Get(primary_profile)
->Subscribe(base::BindRepeating(
&BrowserProcessPlatformPart::ShutdownPrimaryProfileServices,
base::Unretained(this)));
if (ash::SystemProxyManager::Get()) {
ash::SystemProxyManager::Get()->StartObservingPrimaryProfilePrefs(
primary_profile);
}
}
void BrowserProcessPlatformPart::ShutdownPrimaryProfileServices() {
if (ash::SystemProxyManager::Get())
ash::SystemProxyManager::Get()->StopObservingPrimaryProfilePrefs();
in_session_password_change_manager_.reset();
}
void BrowserProcessPlatformPart::RegisterKeepAlive() {
DCHECK(!keep_alive_);
keep_alive_ = std::make_unique<ScopedKeepAlive>(
KeepAliveOrigin::BROWSER_PROCESS_CHROMEOS,
KeepAliveRestartOption::DISABLED);
}
void BrowserProcessPlatformPart::UnregisterKeepAlive() {
keep_alive_.reset();
}
ash::ProfileHelper* BrowserProcessPlatformPart::profile_helper() {
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
if (!created_profile_helper_)
CreateProfileHelper();
return profile_helper_.get();
}
policy::BrowserPolicyConnectorAsh*
BrowserProcessPlatformPart::browser_policy_connector_ash() {
return static_cast<policy::BrowserPolicyConnectorAsh*>(
g_browser_process->browser_policy_connector());
}
ash::system::TimeZoneResolverManager*
BrowserProcessPlatformPart::GetTimezoneResolverManager() {
if (!timezone_resolver_manager_.get()) {
timezone_resolver_manager_ =
std::make_unique<ash::system::TimeZoneResolverManager>();
}
return timezone_resolver_manager_.get();
}
ash::TimeZoneResolver* BrowserProcessPlatformPart::GetTimezoneResolver() {
if (!timezone_resolver_.get()) {
timezone_resolver_ = std::make_unique<ash::TimeZoneResolver>(
GetTimezoneResolverManager(),
g_browser_process->shared_url_loader_factory(),
ash::SimpleGeolocationProvider::DefaultGeolocationProviderURL(),
base::BindRepeating(&ash::system::ApplyTimeZone),
base::BindRepeating(&ash::DelayNetworkCall),
g_browser_process->local_state());
}
return timezone_resolver_.get();
}
void BrowserProcessPlatformPart::StartTearDown() {
// Some tests check for memory leaks before this object is
// destroyed. So we need to destroy |timezone_resolver_| and
// |timezone_resolver_manager_| here.
timezone_resolver_.reset();
timezone_resolver_manager_.reset();
profile_helper_.reset();
browser_context_flusher_.reset();
}
void BrowserProcessPlatformPart::AttemptExit(bool try_to_quit_application) {
// Request Lacros terminate early during shutdown to give it the opportunity
// to shutdown gracefully. Check to make sure `browser_manager` is available
// as it may be null in tests.
if (auto* browser_manager = crosapi::BrowserManager::Get())
browser_manager->Shutdown();
BrowserProcessPlatformPartChromeOS::AttemptExit(try_to_quit_application);
}
ash::system::SystemClock* BrowserProcessPlatformPart::GetSystemClock() {
if (!system_clock_.get())
system_clock_ = std::make_unique<ash::system::SystemClock>();
return system_clock_.get();
}
void BrowserProcessPlatformPart::DestroySystemClock() {
system_clock_.reset();
}
void BrowserProcessPlatformPart::CreateProfileHelper() {
DCHECK(!created_profile_helper_ && !profile_helper_);
created_profile_helper_ = true;
profile_helper_ = ash::ProfileHelper::CreateInstance();
}
ash::AccountManagerFactory*
BrowserProcessPlatformPart::GetAccountManagerFactory() {
return account_manager_factory_.get();
}
bool BrowserProcessPlatformPart::CanRestoreUrlsForProfile(
const Profile* profile) const {
return profile->IsRegularProfile() && !profile->IsSystemProfile() &&
ash::ProfileHelper::IsUserProfile(profile) &&
!ash::ProfileHelper::IsEphemeralUserProfile(profile);
}
// static
void BrowserProcessPlatformPart::EnsureFactoryBuilt() {
PrimaryProfileServicesShutdownNotifierFactory::GetInstance();
}
|