1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/browser_process_platform_part_chromeos.h"
7 #include "base/command_line.h"
8 #include "base/logging.h"
9 #include "base/time/default_tick_clock.h"
10 #include "base/time/tick_clock.h"
11 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/chromeos/login/session/chrome_session_manager.h"
13 #include "chrome/browser/chromeos/login/users/chrome_user_manager_impl.h"
14 #include "chrome/browser/chromeos/net/delay_network_call.h"
15 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
16 #include "chrome/browser/chromeos/profiles/profile_helper.h"
17 #include "chrome/browser/chromeos/settings/cros_settings.h"
18 #include "chrome/browser/chromeos/system/automatic_reboot_manager.h"
19 #include "chrome/browser/chromeos/system/device_disabling_manager.h"
20 #include "chrome/browser/chromeos/system/device_disabling_manager_default_delegate.h"
21 #include "chrome/browser/chromeos/system/system_clock.h"
22 #include "chrome/browser/chromeos/system/timezone_util.h"
23 #include "chrome/browser/profiles/profile.h"
24 #include "chrome/common/chrome_switches.h"
25 #include "chromeos/geolocation/simple_geolocation_provider.h"
26 #include "chromeos/timezone/timezone_resolver.h"
27 #include "components/session_manager/core/session_manager.h"
28 #include "components/user_manager/user_manager.h"
30 BrowserProcessPlatformPart::BrowserProcessPlatformPart()
31 : created_profile_helper_(false) {
34 BrowserProcessPlatformPart::~BrowserProcessPlatformPart() {
37 void BrowserProcessPlatformPart::InitializeAutomaticRebootManager() {
38 DCHECK(!automatic_reboot_manager_
);
40 automatic_reboot_manager_
.reset(new chromeos::system::AutomaticRebootManager(
41 scoped_ptr
<base::TickClock
>(new base::DefaultTickClock
)));
44 void BrowserProcessPlatformPart::ShutdownAutomaticRebootManager() {
45 automatic_reboot_manager_
.reset();
48 void BrowserProcessPlatformPart::InitializeChromeUserManager() {
49 DisableDinoEasterEggIfEnrolled();
50 DCHECK(!chrome_user_manager_
);
51 chrome_user_manager_
=
52 chromeos::ChromeUserManagerImpl::CreateChromeUserManager();
53 chrome_user_manager_
->Initialize();
56 void BrowserProcessPlatformPart::DestroyChromeUserManager() {
57 chrome_user_manager_
->Destroy();
58 chrome_user_manager_
.reset();
61 void BrowserProcessPlatformPart::InitializeDeviceDisablingManager() {
62 DCHECK(!device_disabling_manager_
);
64 device_disabling_manager_delegate_
.reset(
65 new chromeos::system::DeviceDisablingManagerDefaultDelegate
);
66 device_disabling_manager_
.reset(new chromeos::system::DeviceDisablingManager(
67 device_disabling_manager_delegate_
.get(),
68 chromeos::CrosSettings::Get(),
69 user_manager::UserManager::Get()));
72 void BrowserProcessPlatformPart::ShutdownDeviceDisablingManager() {
73 device_disabling_manager_
.reset();
74 device_disabling_manager_delegate_
.reset();
77 void BrowserProcessPlatformPart::InitializeSessionManager(
78 const base::CommandLine
& parsed_command_line
,
80 bool is_running_test
) {
81 DCHECK(!session_manager_
);
82 session_manager_
= chromeos::ChromeSessionManager::CreateSessionManager(
83 parsed_command_line
, profile
, is_running_test
);
86 void BrowserProcessPlatformPart::ShutdownSessionManager() {
87 session_manager_
.reset();
90 session_manager::SessionManager
* BrowserProcessPlatformPart::SessionManager() {
91 DCHECK(CalledOnValidThread());
92 return session_manager_
.get();
95 chromeos::ProfileHelper
* BrowserProcessPlatformPart::profile_helper() {
96 DCHECK(CalledOnValidThread());
97 if (!created_profile_helper_
)
98 CreateProfileHelper();
99 return profile_helper_
.get();
102 policy::BrowserPolicyConnectorChromeOS
*
103 BrowserProcessPlatformPart::browser_policy_connector_chromeos() {
104 return static_cast<policy::BrowserPolicyConnectorChromeOS
*>(
105 g_browser_process
->browser_policy_connector());
108 void BrowserProcessPlatformPart::DisableDinoEasterEggIfEnrolled() {
109 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
110 const bool is_enterprise_managed
= g_browser_process
->platform_part()->
111 browser_policy_connector_chromeos()->IsEnterpriseManaged();
112 if (is_enterprise_managed
)
113 command_line
->AppendSwitch(switches::kDisableDinosaurEasterEgg
);
116 chromeos::TimeZoneResolver
* BrowserProcessPlatformPart::GetTimezoneResolver() {
117 if (!timezone_resolver_
.get()) {
118 timezone_resolver_
.reset(new chromeos::TimeZoneResolver(
119 g_browser_process
->system_request_context(),
120 chromeos::SimpleGeolocationProvider::DefaultGeolocationProviderURL(),
121 base::Bind(&chromeos::system::ApplyTimeZone
),
122 base::Bind(&chromeos::DelayNetworkCall
,
123 base::TimeDelta::FromMilliseconds(
124 chromeos::kDefaultNetworkRetryDelayMS
)),
125 g_browser_process
->local_state()));
127 return timezone_resolver_
.get();
130 chromeos::system::SystemClock
* BrowserProcessPlatformPart::GetSystemClock() {
131 if (!system_clock_
.get())
132 system_clock_
.reset(new chromeos::system::SystemClock());
134 return system_clock_
.get();
136 void BrowserProcessPlatformPart::StartTearDown() {
137 // interactive_ui_tests check for memory leaks before this object is
138 // destroyed. So we need to destroy |timezone_resolver_| here.
139 timezone_resolver_
.reset();
140 profile_helper_
.reset();
143 scoped_ptr
<policy::BrowserPolicyConnector
>
144 BrowserProcessPlatformPart::CreateBrowserPolicyConnector() {
145 return scoped_ptr
<policy::BrowserPolicyConnector
>(
146 new policy::BrowserPolicyConnectorChromeOS());
149 void BrowserProcessPlatformPart::CreateProfileHelper() {
150 DCHECK(!created_profile_helper_
&& profile_helper_
.get() == NULL
);
151 created_profile_helper_
= true;
152 profile_helper_
.reset(new chromeos::ProfileHelper());