Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: chrome/browser/browser_process_platform_part_chromeos.cc

Issue 2977043002: Refactor: Moving CrOS-specific service registration code (Closed)
Patch Set: Removing unneeded dependency. Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 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 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/browser_process_platform_part_chromeos.h" 5 #include "chrome/browser/browser_process_platform_part_chromeos.h"
6 6
7 #include "ash/public/interfaces/constants.mojom.h"
7 #include "base/logging.h" 8 #include "base/logging.h"
8 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
9 #include "base/time/default_tick_clock.h" 10 #include "base/time/default_tick_clock.h"
10 #include "base/time/tick_clock.h" 11 #include "base/time/tick_clock.h"
11 #include "chrome/browser/browser_process.h" 12 #include "chrome/browser/browser_process.h"
12 #include "chrome/browser/chromeos/ash_config.h" 13 #include "chrome/browser/chromeos/ash_config.h"
13 #include "chrome/browser/chromeos/chrome_service_name.h" 14 #include "chrome/browser/chromeos/chrome_service_name.h"
14 #include "chrome/browser/chromeos/login/session/chrome_session_manager.h" 15 #include "chrome/browser/chromeos/login/session/chrome_session_manager.h"
15 #include "chrome/browser/chromeos/login/users/chrome_user_manager_impl.h" 16 #include "chrome/browser/chromeos/login/users/chrome_user_manager_impl.h"
16 #include "chrome/browser/chromeos/net/delay_network_call.h" 17 #include "chrome/browser/chromeos/net/delay_network_call.h"
17 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h" 18 #include "chrome/browser/chromeos/policy/browser_policy_connector_chromeos.h"
18 #include "chrome/browser/chromeos/profiles/profile_helper.h" 19 #include "chrome/browser/chromeos/profiles/profile_helper.h"
19 #include "chrome/browser/chromeos/settings/cros_settings.h" 20 #include "chrome/browser/chromeos/settings/cros_settings.h"
20 #include "chrome/browser/chromeos/system/automatic_reboot_manager.h" 21 #include "chrome/browser/chromeos/system/automatic_reboot_manager.h"
21 #include "chrome/browser/chromeos/system/device_disabling_manager.h" 22 #include "chrome/browser/chromeos/system/device_disabling_manager.h"
22 #include "chrome/browser/chromeos/system/device_disabling_manager_default_delega te.h" 23 #include "chrome/browser/chromeos/system/device_disabling_manager_default_delega te.h"
23 #include "chrome/browser/chromeos/system/system_clock.h" 24 #include "chrome/browser/chromeos/system/system_clock.h"
24 #include "chrome/browser/chromeos/system/timezone_resolver_manager.h" 25 #include "chrome/browser/chromeos/system/timezone_resolver_manager.h"
25 #include "chrome/browser/chromeos/system/timezone_util.h" 26 #include "chrome/browser/chromeos/system/timezone_util.h"
26 #include "chrome/browser/lifetime/keep_alive_types.h" 27 #include "chrome/browser/lifetime/keep_alive_types.h"
27 #include "chrome/browser/lifetime/scoped_keep_alive.h" 28 #include "chrome/browser/lifetime/scoped_keep_alive.h"
29 #include "chrome/browser/prefs/active_profile_pref_service.h"
30 #include "chrome/browser/profiles/profile_manager.h"
31 #include "chrome/browser/ui/ash/ash_util.h"
32 #include "chrome/browser/ui/browser_commands.h"
33 #include "chrome/browser/ui/browser_finder.h"
34 #include "chrome/browser/ui/browser_window.h"
35 #include "chrome/common/chrome_features.h"
28 #include "chrome/common/chrome_switches.h" 36 #include "chrome/common/chrome_switches.h"
29 #include "chromeos/geolocation/simple_geolocation_provider.h" 37 #include "chromeos/geolocation/simple_geolocation_provider.h"
30 #include "chromeos/timezone/timezone_resolver.h" 38 #include "chromeos/timezone/timezone_resolver.h"
31 #include "components/session_manager/core/session_manager.h" 39 #include "components/session_manager/core/session_manager.h"
32 #include "components/user_manager/user_manager.h" 40 #include "components/user_manager/user_manager.h"
41 #include "mash/public/interfaces/launchable.mojom.h"
42 #include "services/preferences/public/interfaces/preferences.mojom.h"
43 #include "services/service_manager/public/cpp/binder_registry.h"
44 #include "services/service_manager/public/cpp/interface_provider.h"
45 #include "services/service_manager/public/cpp/service.h"
46 #include "services/ui/public/interfaces/constants.mojom.h"
33 47
34 #if defined(USE_OZONE) 48 #if defined(USE_OZONE)
35 #include "ash/public/interfaces/constants.mojom.h"
36 #include "content/public/common/service_manager_connection.h" 49 #include "content/public/common/service_manager_connection.h"
37 #include "services/service_manager/runner/common/client_util.h" 50 #include "services/service_manager/runner/common/client_util.h"
51 #include "services/ui/public/cpp/input_devices/input_device_controller.h"
38 #include "services/ui/public/cpp/input_devices/input_device_controller_client.h" 52 #include "services/ui/public/cpp/input_devices/input_device_controller_client.h"
39 #include "services/ui/public/interfaces/constants.mojom.h" 53 #include "services/ui/public/interfaces/constants.mojom.h"
40 #endif 54 #endif
41 55
56 namespace {
57 // Packaged service implementation used to expose miscellaneous application
58 // control features. This is a singleton service which runs on the main thread
59 // and never stops.
60 class ChromeServiceChromeOS : public service_manager::Service,
61 public mash::mojom::Launchable {
62 public:
63 ChromeServiceChromeOS() {
64 #if defined(USE_OZONE)
65 input_device_controller_.AddInterface(&interfaces_);
66 #endif
67 interfaces_.AddInterface<mash::mojom::Launchable>(
68 base::Bind(&ChromeServiceChromeOS::Create, base::Unretained(this)));
69 }
70 ~ChromeServiceChromeOS() override {}
71
72 static std::unique_ptr<service_manager::Service> CreateService() {
73 return base::MakeUnique<ChromeServiceChromeOS>();
74 }
75
76 private:
77 void CreateNewWindowImpl(bool is_incognito) {
78 Profile* profile = ProfileManager::GetActiveUserProfile();
79 chrome::NewEmptyWindow(is_incognito ? profile->GetOffTheRecordProfile()
80 : profile);
81 }
82
83 // service_manager::Service:
84 void OnBindInterface(const service_manager::BindSourceInfo& remote_info,
85 const std::string& name,
86 mojo::ScopedMessagePipeHandle handle) override {
87 interfaces_.BindInterface(remote_info, name, std::move(handle));
88 }
89
90 // mash::mojom::Launchable:
91 void Launch(uint32_t what, mash::mojom::LaunchMode how) override {
92 bool is_incognito;
93 switch (what) {
94 case mash::mojom::kWindow:
95 is_incognito = false;
96 break;
97 case mash::mojom::kIncognitoWindow:
98 is_incognito = true;
99 break;
100 default:
101 NOTREACHED();
102 }
103
104 bool reuse = how != mash::mojom::LaunchMode::MAKE_NEW;
105 if (reuse) {
106 Profile* profile = ProfileManager::GetActiveUserProfile();
107 Browser* browser = chrome::FindTabbedBrowser(
108 is_incognito ? profile->GetOffTheRecordProfile() : profile, false);
109 if (browser) {
110 browser->window()->Show();
111 return;
112 }
113 }
114
115 CreateNewWindowImpl(is_incognito);
116 }
117
118 void Create(const service_manager::BindSourceInfo& source_info,
119 mash::mojom::LaunchableRequest request) {
120 bindings_.AddBinding(this, std::move(request));
121 }
122
123 service_manager::BinderRegistry interfaces_;
124 mojo::BindingSet<mash::mojom::Launchable> bindings_;
125 #if defined(USE_OZONE)
126 ui::InputDeviceController input_device_controller_;
127 #endif
128
129 DISALLOW_COPY_AND_ASSIGN(ChromeServiceChromeOS);
130 };
131
132 } // namespace
133
42 BrowserProcessPlatformPart::BrowserProcessPlatformPart() 134 BrowserProcessPlatformPart::BrowserProcessPlatformPart()
43 : created_profile_helper_(false) {} 135 : created_profile_helper_(false) {}
44 136
45 BrowserProcessPlatformPart::~BrowserProcessPlatformPart() { 137 BrowserProcessPlatformPart::~BrowserProcessPlatformPart() {
46 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); 138 DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_);
47 } 139 }
48 140
49 void BrowserProcessPlatformPart::InitializeAutomaticRebootManager() { 141 void BrowserProcessPlatformPart::InitializeAutomaticRebootManager() {
50 DCHECK(!automatic_reboot_manager_); 142 DCHECK(!automatic_reboot_manager_);
51 143
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 timezone_resolver_.reset(); 241 timezone_resolver_.reset();
150 profile_helper_.reset(); 242 profile_helper_.reset();
151 } 243 }
152 244
153 std::unique_ptr<policy::BrowserPolicyConnector> 245 std::unique_ptr<policy::BrowserPolicyConnector>
154 BrowserProcessPlatformPart::CreateBrowserPolicyConnector() { 246 BrowserProcessPlatformPart::CreateBrowserPolicyConnector() {
155 return std::unique_ptr<policy::BrowserPolicyConnector>( 247 return std::unique_ptr<policy::BrowserPolicyConnector>(
156 new policy::BrowserPolicyConnectorChromeOS()); 248 new policy::BrowserPolicyConnectorChromeOS());
157 } 249 }
158 250
251 void BrowserProcessPlatformPart::RegisterInProcessServices(
252 content::ContentBrowserClient::StaticServiceMap* services) {
253 {
254 service_manager::EmbeddedServiceInfo info;
255 info.factory = base::Bind(&ChromeServiceChromeOS::CreateService);
256 info.task_runner = base::ThreadTaskRunnerHandle::Get();
257 services->insert(std::make_pair(chromeos::kChromeServiceName, info));
258 }
259
260 if (features::PrefServiceEnabled()) {
261 service_manager::EmbeddedServiceInfo info;
262 info.factory = base::Bind([] {
263 return std::unique_ptr<service_manager::Service>(
264 base::MakeUnique<ActiveProfilePrefService>());
265 });
266 info.task_runner = base::ThreadTaskRunnerHandle::Get();
267 services->insert(std::make_pair(prefs::mojom::kForwarderServiceName, info));
268 }
269
270 if (!ash_util::IsRunningInMash()) {
271 service_manager::EmbeddedServiceInfo info;
272 info.factory = base::Bind(&ash_util::CreateEmbeddedAshService,
273 base::ThreadTaskRunnerHandle::Get());
274 info.task_runner = base::ThreadTaskRunnerHandle::Get();
275 services->insert(std::make_pair(ash::mojom::kServiceName, info));
276 }
277 }
278
159 chromeos::system::SystemClock* BrowserProcessPlatformPart::GetSystemClock() { 279 chromeos::system::SystemClock* BrowserProcessPlatformPart::GetSystemClock() {
160 if (!system_clock_.get()) 280 if (!system_clock_.get())
161 system_clock_.reset(new chromeos::system::SystemClock()); 281 system_clock_.reset(new chromeos::system::SystemClock());
162 return system_clock_.get(); 282 return system_clock_.get();
163 } 283 }
164 284
165 void BrowserProcessPlatformPart::DestroySystemClock() { 285 void BrowserProcessPlatformPart::DestroySystemClock() {
166 system_clock_.reset(); 286 system_clock_.reset();
167 } 287 }
168 288
(...skipping 22 matching lines...) Expand all
191 } 311 }
192 return input_device_controller_client_.get(); 312 return input_device_controller_client_.get();
193 } 313 }
194 #endif 314 #endif
195 315
196 void BrowserProcessPlatformPart::CreateProfileHelper() { 316 void BrowserProcessPlatformPart::CreateProfileHelper() {
197 DCHECK(!created_profile_helper_ && !profile_helper_); 317 DCHECK(!created_profile_helper_ && !profile_helper_);
198 created_profile_helper_ = true; 318 created_profile_helper_ = true;
199 profile_helper_.reset(new chromeos::ProfileHelper()); 319 profile_helper_.reset(new chromeos::ProfileHelper());
200 } 320 }
OLDNEW
« no previous file with comments | « chrome/browser/browser_process_platform_part_chromeos.h ('k') | chrome/browser/chrome_content_browser_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698