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/timezone_util.h"
22 #include "chrome/browser/profiles/profile.h"
23 #include "chrome/common/chrome_switches.h"
24 #include "chromeos/geolocation/simple_geolocation_provider.h"
25 #include "chromeos/timezone/timezone_resolver.h"
26 #include "components/session_manager/core/session_manager.h"
27 #include "components/user_manager/user_manager.h"
29 BrowserProcessPlatformPart::BrowserProcessPlatformPart()
30 : created_profile_helper_(false) {
33 BrowserProcessPlatformPart::~BrowserProcessPlatformPart() {
36 void BrowserProcessPlatformPart::InitializeAutomaticRebootManager() {
37 DCHECK(!automatic_reboot_manager_
);
39 automatic_reboot_manager_
.reset(new chromeos::system::AutomaticRebootManager(
40 scoped_ptr
<base::TickClock
>(new base::DefaultTickClock
)));
43 void BrowserProcessPlatformPart::ShutdownAutomaticRebootManager() {
44 automatic_reboot_manager_
.reset();
47 void BrowserProcessPlatformPart::InitializeChromeUserManager() {
48 DisableDinoEasterEggIfEnrolled();
49 DCHECK(!chrome_user_manager_
);
50 chrome_user_manager_
=
51 chromeos::ChromeUserManagerImpl::CreateChromeUserManager();
52 chrome_user_manager_
->Initialize();
55 void BrowserProcessPlatformPart::DestroyChromeUserManager() {
56 chrome_user_manager_
->Destroy();
57 chrome_user_manager_
.reset();
60 void BrowserProcessPlatformPart::InitializeDeviceDisablingManager() {
61 DCHECK(!device_disabling_manager_
);
63 device_disabling_manager_delegate_
.reset(
64 new chromeos::system::DeviceDisablingManagerDefaultDelegate
);
65 device_disabling_manager_
.reset(new chromeos::system::DeviceDisablingManager(
66 device_disabling_manager_delegate_
.get(),
67 chromeos::CrosSettings::Get(),
68 user_manager::UserManager::Get()));
71 void BrowserProcessPlatformPart::ShutdownDeviceDisablingManager() {
72 device_disabling_manager_
.reset();
73 device_disabling_manager_delegate_
.reset();
76 void BrowserProcessPlatformPart::InitializeSessionManager(
77 const base::CommandLine
& parsed_command_line
,
79 bool is_running_test
) {
80 DCHECK(!session_manager_
);
81 session_manager_
= chromeos::ChromeSessionManager::CreateSessionManager(
82 parsed_command_line
, profile
, is_running_test
);
85 void BrowserProcessPlatformPart::ShutdownSessionManager() {
86 session_manager_
.reset();
89 session_manager::SessionManager
* BrowserProcessPlatformPart::SessionManager() {
90 DCHECK(CalledOnValidThread());
91 return session_manager_
.get();
94 chromeos::ProfileHelper
* BrowserProcessPlatformPart::profile_helper() {
95 DCHECK(CalledOnValidThread());
96 if (!created_profile_helper_
)
97 CreateProfileHelper();
98 return profile_helper_
.get();
101 policy::BrowserPolicyConnectorChromeOS
*
102 BrowserProcessPlatformPart::browser_policy_connector_chromeos() {
103 return static_cast<policy::BrowserPolicyConnectorChromeOS
*>(
104 g_browser_process
->browser_policy_connector());
107 void BrowserProcessPlatformPart::DisableDinoEasterEggIfEnrolled() {
108 base::CommandLine
* command_line
= base::CommandLine::ForCurrentProcess();
109 const bool is_enterprise_managed
= g_browser_process
->platform_part()->
110 browser_policy_connector_chromeos()->IsEnterpriseManaged();
111 if (is_enterprise_managed
)
112 command_line
->AppendSwitch(switches::kDisableDinosaurEasterEgg
);
115 chromeos::TimeZoneResolver
* BrowserProcessPlatformPart::GetTimezoneResolver() {
116 if (!timezone_resolver_
.get()) {
117 timezone_resolver_
.reset(new chromeos::TimeZoneResolver(
118 g_browser_process
->system_request_context(),
119 chromeos::SimpleGeolocationProvider::DefaultGeolocationProviderURL(),
120 base::Bind(&chromeos::system::ApplyTimeZone
),
121 base::Bind(&chromeos::DelayNetworkCall
,
122 base::TimeDelta::FromMilliseconds(
123 chromeos::kDefaultNetworkRetryDelayMS
)),
124 g_browser_process
->local_state()));
126 return timezone_resolver_
.get();
129 void BrowserProcessPlatformPart::StartTearDown() {
130 // interactive_ui_tests check for memory leaks before this object is
131 // destroyed. So we need to destroy |timezone_resolver_| here.
132 timezone_resolver_
.reset();
133 profile_helper_
.reset();
136 scoped_ptr
<policy::BrowserPolicyConnector
>
137 BrowserProcessPlatformPart::CreateBrowserPolicyConnector() {
138 return scoped_ptr
<policy::BrowserPolicyConnector
>(
139 new policy::BrowserPolicyConnectorChromeOS());
142 void BrowserProcessPlatformPart::CreateProfileHelper() {
143 DCHECK(!created_profile_helper_
&& profile_helper_
.get() == NULL
);
144 created_profile_helper_
= true;
145 profile_helper_
.reset(new chromeos::ProfileHelper());