Revert of Add button to add new FSP services to Files app. (patchset #8 id:140001...
[chromium-blink-merge.git] / chrome / browser / browser_process_platform_part_chromeos.cc
blob12d6ce6a97ccb52be49e23d9f53251945b1fb68a
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/memory/oom_priority_manager.h"
15 #include "chrome/browser/chromeos/net/delay_network_call.h"
16 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
17 #include "chrome/browser/chromeos/profiles/profile_helper.h"
18 #include "chrome/browser/chromeos/settings/cros_settings.h"
19 #include "chrome/browser/chromeos/system/automatic_reboot_manager.h"
20 #include "chrome/browser/chromeos/system/device_disabling_manager.h"
21 #include "chrome/browser/chromeos/system/device_disabling_manager_default_delegate.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,
79 Profile* profile,
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::OomPriorityManager*
96 BrowserProcessPlatformPart::oom_priority_manager() {
97 DCHECK(CalledOnValidThread());
98 if (!oom_priority_manager_.get())
99 oom_priority_manager_.reset(new chromeos::OomPriorityManager());
100 return oom_priority_manager_.get();
103 chromeos::ProfileHelper* BrowserProcessPlatformPart::profile_helper() {
104 DCHECK(CalledOnValidThread());
105 if (!created_profile_helper_)
106 CreateProfileHelper();
107 return profile_helper_.get();
110 policy::BrowserPolicyConnectorChromeOS*
111 BrowserProcessPlatformPart::browser_policy_connector_chromeos() {
112 return static_cast<policy::BrowserPolicyConnectorChromeOS*>(
113 g_browser_process->browser_policy_connector());
116 void BrowserProcessPlatformPart::DisableDinoEasterEggIfEnrolled() {
117 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
118 const bool is_enterprise_managed = g_browser_process->platform_part()->
119 browser_policy_connector_chromeos()->IsEnterpriseManaged();
120 if (is_enterprise_managed)
121 command_line->AppendSwitch(switches::kDisableDinosaurEasterEgg);
124 chromeos::TimeZoneResolver* BrowserProcessPlatformPart::GetTimezoneResolver() {
125 if (!timezone_resolver_.get()) {
126 timezone_resolver_.reset(new chromeos::TimeZoneResolver(
127 g_browser_process->system_request_context(),
128 chromeos::SimpleGeolocationProvider::DefaultGeolocationProviderURL(),
129 base::Bind(&chromeos::system::ApplyTimeZone),
130 base::Bind(&chromeos::DelayNetworkCall,
131 base::TimeDelta::FromMilliseconds(
132 chromeos::kDefaultNetworkRetryDelayMS)),
133 g_browser_process->local_state()));
135 return timezone_resolver_.get();
138 void BrowserProcessPlatformPart::StartTearDown() {
139 // interactive_ui_tests check for memory leaks before this object is
140 // destroyed. So we need to destroy |timezone_resolver_| here.
141 timezone_resolver_.reset();
142 profile_helper_.reset();
145 scoped_ptr<policy::BrowserPolicyConnector>
146 BrowserProcessPlatformPart::CreateBrowserPolicyConnector() {
147 return scoped_ptr<policy::BrowserPolicyConnector>(
148 new policy::BrowserPolicyConnectorChromeOS());
151 void BrowserProcessPlatformPart::CreateProfileHelper() {
152 DCHECK(!created_profile_helper_ && profile_helper_.get() == NULL);
153 created_profile_helper_ = true;
154 profile_helper_.reset(new chromeos::ProfileHelper());