OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "services/ui/service.h" | 5 #include "services/ui/service.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
34 #include "services/ui/ws/frame_sink_manager_client_binding.h" | 34 #include "services/ui/ws/frame_sink_manager_client_binding.h" |
35 #include "services/ui/ws/gpu_host.h" | 35 #include "services/ui/ws/gpu_host.h" |
36 #include "services/ui/ws/user_activity_monitor.h" | 36 #include "services/ui/ws/user_activity_monitor.h" |
37 #include "services/ui/ws/user_display_manager.h" | 37 #include "services/ui/ws/user_display_manager.h" |
38 #include "services/ui/ws/window_server.h" | 38 #include "services/ui/ws/window_server.h" |
39 #include "services/ui/ws/window_server_test_impl.h" | 39 #include "services/ui/ws/window_server_test_impl.h" |
40 #include "services/ui/ws/window_tree.h" | 40 #include "services/ui/ws/window_tree.h" |
41 #include "services/ui/ws/window_tree_binding.h" | 41 #include "services/ui/ws/window_tree_binding.h" |
42 #include "services/ui/ws/window_tree_factory.h" | 42 #include "services/ui/ws/window_tree_factory.h" |
43 #include "services/ui/ws/window_tree_host_factory.h" | 43 #include "services/ui/ws/window_tree_host_factory.h" |
44 #include "ui/base/cursor/image_cursors.h" | |
44 #include "ui/base/platform_window_defaults.h" | 45 #include "ui/base/platform_window_defaults.h" |
45 #include "ui/base/resource/resource_bundle.h" | 46 #include "ui/base/resource/resource_bundle.h" |
46 #include "ui/base/ui_base_paths.h" | 47 #include "ui/base/ui_base_paths.h" |
47 #include "ui/events/event_switches.h" | 48 #include "ui/events/event_switches.h" |
48 #include "ui/events/platform/platform_event_source.h" | 49 #include "ui/events/platform/platform_event_source.h" |
49 #include "ui/gfx/geometry/rect.h" | 50 #include "ui/gfx/geometry/rect.h" |
50 #include "ui/gl/gl_surface.h" | 51 #include "ui/gl/gl_surface.h" |
51 | 52 |
52 #if defined(USE_X11) | 53 #if defined(USE_X11) |
53 #include <X11/Xlib.h> | 54 #include <X11/Xlib.h> |
(...skipping 30 matching lines...) Expand all Loading... | |
84 std::unique_ptr<mojom::WindowTreeFactoryRequest> wtf_request; | 85 std::unique_ptr<mojom::WindowTreeFactoryRequest> wtf_request; |
85 std::unique_ptr<mojom::DisplayManagerRequest> dm_request; | 86 std::unique_ptr<mojom::DisplayManagerRequest> dm_request; |
86 }; | 87 }; |
87 | 88 |
88 struct Service::UserState { | 89 struct Service::UserState { |
89 std::unique_ptr<clipboard::ClipboardImpl> clipboard; | 90 std::unique_ptr<clipboard::ClipboardImpl> clipboard; |
90 std::unique_ptr<ws::AccessibilityManager> accessibility; | 91 std::unique_ptr<ws::AccessibilityManager> accessibility; |
91 std::unique_ptr<ws::WindowTreeHostFactory> window_tree_host_factory; | 92 std::unique_ptr<ws::WindowTreeHostFactory> window_tree_host_factory; |
92 }; | 93 }; |
93 | 94 |
94 Service::Service() : test_config_(false), ime_registrar_(&ime_driver_) {} | 95 Service::Service(scoped_refptr<base::SingleThreadTaskRunner> resource_runner, |
96 base::WeakPtr<ui::ImageCursors> image_cursors_weak_ptr) | |
97 : in_process_(resource_runner != nullptr), | |
98 resource_runner_(resource_runner), | |
99 image_cursors_weak_ptr_(image_cursors_weak_ptr), | |
100 test_config_(false), | |
101 ime_registrar_(&ime_driver_) {} | |
95 | 102 |
96 Service::~Service() { | 103 Service::~Service() { |
97 // Destroy |window_server_| first, since it depends on |event_source_|. | 104 // Destroy |window_server_| first, since it depends on |event_source_|. |
98 // WindowServer (or more correctly its Displays) may have state that needs to | 105 // WindowServer (or more correctly its Displays) may have state that needs to |
99 // be destroyed before GpuState as well. | 106 // be destroyed before GpuState as well. |
100 window_server_.reset(); | 107 window_server_.reset(); |
101 | 108 |
102 #if defined(USE_OZONE) | 109 #if defined(USE_OZONE) |
103 #if defined(OS_CHROMEOS) | 110 #if defined(OS_CHROMEOS) |
104 // InputDeviceController uses ozone. | 111 // InputDeviceController uses ozone. |
105 input_device_controller_.reset(); | 112 input_device_controller_.reset(); |
106 #endif | 113 #endif |
107 | 114 |
108 OzonePlatform::Shutdown(); | 115 OzonePlatform::Shutdown(); |
109 #endif | 116 #endif |
110 } | 117 } |
111 | 118 |
112 bool Service::InitializeResources(service_manager::Connector* connector) { | 119 bool Service::InitializeResources(service_manager::Connector* connector) { |
113 if (ui::ResourceBundle::HasSharedInstance()) | 120 if (in_process() || ui::ResourceBundle::HasSharedInstance()) |
114 return true; | 121 return true; |
115 | 122 |
116 std::set<std::string> resource_paths; | 123 std::set<std::string> resource_paths; |
117 resource_paths.insert(kResourceFileStrings); | 124 resource_paths.insert(kResourceFileStrings); |
118 resource_paths.insert(kResourceFile100); | 125 resource_paths.insert(kResourceFile100); |
119 resource_paths.insert(kResourceFile200); | 126 resource_paths.insert(kResourceFile200); |
120 | 127 |
121 catalog::ResourceLoader loader; | 128 catalog::ResourceLoader loader; |
122 filesystem::mojom::DirectoryPtr directory; | 129 filesystem::mojom::DirectoryPtr directory; |
123 connector->BindInterface(catalog::mojom::kServiceName, &directory); | 130 connector->BindInterface(catalog::mojom::kServiceName, &directory); |
124 if (!loader.OpenFiles(std::move(directory), resource_paths)) { | 131 if (!loader.OpenFiles(std::move(directory), resource_paths)) { |
125 LOG(ERROR) << "Service failed to open resource files."; | 132 LOG(ERROR) << "Service failed to open resource files."; |
126 return false; | 133 return false; |
127 } | 134 } |
128 | 135 |
129 ui::RegisterPathProvider(); | 136 ui::RegisterPathProvider(); |
130 | 137 |
131 // Initialize resource bundle with 1x and 2x cursor bitmaps. | 138 // Initialize resource bundle with 1x and 2x cursor bitmaps. |
132 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( | 139 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( |
133 loader.TakeFile(kResourceFileStrings), | 140 loader.TakeFile(kResourceFileStrings), |
134 base::MemoryMappedFile::Region::kWholeFile); | 141 base::MemoryMappedFile::Region::kWholeFile); |
135 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 142 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
136 rb.AddDataPackFromFile(loader.TakeFile(kResourceFile100), | 143 rb.AddDataPackFromFile(loader.TakeFile(kResourceFile100), |
137 ui::SCALE_FACTOR_100P); | 144 ui::SCALE_FACTOR_100P); |
138 rb.AddDataPackFromFile(loader.TakeFile(kResourceFile200), | 145 rb.AddDataPackFromFile(loader.TakeFile(kResourceFile200), |
139 ui::SCALE_FACTOR_200P); | 146 ui::SCALE_FACTOR_200P); |
147 | |
148 // Initialize the cursors. | |
sky
2017/06/27 19:58:56
This comment just documents the code and so isn't
mfomitchev
2017/07/11 21:46:59
Done.
| |
149 image_cursors_ = base::MakeUnique<ui::ImageCursors>(); | |
150 image_cursors_weak_ptr_ = image_cursors_->GetWeakPtr(); | |
151 | |
140 return true; | 152 return true; |
141 } | 153 } |
142 | 154 |
143 Service::UserState* Service::GetUserState( | 155 Service::UserState* Service::GetUserState( |
144 const service_manager::Identity& remote_identity) { | 156 const service_manager::Identity& remote_identity) { |
145 const ws::UserId& user_id = remote_identity.user_id(); | 157 const ws::UserId& user_id = remote_identity.user_id(); |
146 auto it = user_id_to_user_state_.find(user_id); | 158 auto it = user_id_to_user_state_.find(user_id); |
147 if (it != user_id_to_user_state_.end()) | 159 if (it != user_id_to_user_state_.end()) |
148 return it->second.get(); | 160 return it->second.get(); |
149 user_id_to_user_state_[user_id] = base::WrapUnique(new UserState); | 161 user_id_to_user_state_[user_id] = base::WrapUnique(new UserState); |
150 return user_id_to_user_state_[user_id].get(); | 162 return user_id_to_user_state_[user_id].get(); |
151 } | 163 } |
152 | 164 |
153 void Service::AddUserIfNecessary( | 165 void Service::AddUserIfNecessary( |
154 const service_manager::Identity& remote_identity) { | 166 const service_manager::Identity& remote_identity) { |
155 window_server_->user_id_tracker()->AddUserId(remote_identity.user_id()); | 167 window_server_->user_id_tracker()->AddUserId(remote_identity.user_id()); |
156 } | 168 } |
157 | 169 |
158 void Service::OnStart() { | 170 void Service::OnStart() { |
159 base::PlatformThread::SetName("mus"); | 171 if (!in_process()) |
172 base::PlatformThread::SetName("mus"); | |
173 | |
160 TRACE_EVENT0("mus", "Service::Initialize started"); | 174 TRACE_EVENT0("mus", "Service::Initialize started"); |
161 | 175 |
176 if (!resource_runner_) | |
177 resource_runner_ = base::ThreadTaskRunnerHandle::Get(); | |
178 | |
162 test_config_ = base::CommandLine::ForCurrentProcess()->HasSwitch( | 179 test_config_ = base::CommandLine::ForCurrentProcess()->HasSwitch( |
163 switches::kUseTestConfig); | 180 switches::kUseTestConfig); |
181 | |
164 #if defined(USE_X11) | 182 #if defined(USE_X11) |
165 XInitThreads(); | 183 XInitThreads(); |
166 ui::SetDefaultX11ErrorHandlers(); | 184 ui::SetDefaultX11ErrorHandlers(); |
167 #endif | 185 #endif |
168 | 186 |
169 if (test_config_) | 187 if (test_config_) |
170 ui::test::EnableTestConfigForPlatformWindows(); | 188 ui::test::EnableTestConfigForPlatformWindows(); |
171 | 189 |
172 // If resources are unavailable do not complete start-up. | 190 // If resources are unavailable do not complete start-up. |
173 if (!InitializeResources(context()->connector())) { | 191 if (!InitializeResources(context()->connector())) { |
174 context()->QuitNow(); | 192 context()->QuitNow(); |
175 return; | 193 return; |
176 } | 194 } |
177 | 195 |
178 #if defined(USE_OZONE) | 196 #if defined(USE_OZONE) |
179 // The ozone platform can provide its own event source. So initialize the | 197 // The ozone platform can provide its own event source. So initialize the |
180 // platform before creating the default event source. | 198 // platform before creating the default event source. |
181 // Because GL libraries need to be initialized before entering the sandbox, | 199 // Because GL libraries need to be initialized before entering the sandbox, |
182 // in MUS, |InitializeForUI| will load the GL libraries. | 200 // in MUS, |InitializeForUI| will load the GL libraries. |
183 ui::OzonePlatform::InitParams params; | 201 ui::OzonePlatform::InitParams params; |
184 params.connector = context()->connector(); | 202 params.connector = context()->connector(); |
185 params.single_process = false; | 203 params.single_process = false; |
186 ui::OzonePlatform::InitializeForUI(params); | 204 ui::OzonePlatform::InitializeForUI(params); |
187 | 205 |
188 // Assume a client will change the layout to an appropriate configuration. | 206 // Assume a client will change the layout to an appropriate configuration. |
189 ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine() | 207 ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine() |
190 ->SetCurrentLayoutByName("us"); | 208 ->SetCurrentLayoutByName("us"); |
191 client_native_pixmap_factory_ = ui::CreateClientNativePixmapFactoryOzone(); | 209 |
192 gfx::ClientNativePixmapFactory::SetInstance( | 210 if (!in_process()) { |
193 client_native_pixmap_factory_.get()); | 211 client_native_pixmap_factory_ = ui::CreateClientNativePixmapFactoryOzone(); |
212 gfx::ClientNativePixmapFactory::SetInstance( | |
213 client_native_pixmap_factory_.get()); | |
214 } | |
194 | 215 |
195 DCHECK(gfx::ClientNativePixmapFactory::GetInstance()); | 216 DCHECK(gfx::ClientNativePixmapFactory::GetInstance()); |
196 | 217 |
197 #if defined(OS_CHROMEOS) | 218 #if defined(OS_CHROMEOS) |
198 input_device_controller_ = base::MakeUnique<InputDeviceController>(); | 219 input_device_controller_ = base::MakeUnique<InputDeviceController>(); |
199 input_device_controller_->AddInterface(®istry_); | 220 input_device_controller_->AddInterface(®istry_); |
200 #endif | 221 #endif |
201 #endif | 222 #endif |
202 | 223 |
203 // TODO(rjkroege): Enter sandbox here before we start threads in GpuState | 224 // TODO(rjkroege): Enter sandbox here before we start threads in GpuState |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 | 337 |
317 DVLOG(3) << "OnWillCreateTreeForWindowManager " | 338 DVLOG(3) << "OnWillCreateTreeForWindowManager " |
318 << automatically_create_display_roots; | 339 << automatically_create_display_roots; |
319 ws::DisplayCreationConfig config = automatically_create_display_roots | 340 ws::DisplayCreationConfig config = automatically_create_display_roots |
320 ? ws::DisplayCreationConfig::AUTOMATIC | 341 ? ws::DisplayCreationConfig::AUTOMATIC |
321 : ws::DisplayCreationConfig::MANUAL; | 342 : ws::DisplayCreationConfig::MANUAL; |
322 window_server_->SetDisplayCreationConfig(config); | 343 window_server_->SetDisplayCreationConfig(config); |
323 if (window_server_->display_creation_config() == | 344 if (window_server_->display_creation_config() == |
324 ws::DisplayCreationConfig::MANUAL) { | 345 ws::DisplayCreationConfig::MANUAL) { |
325 #if defined(USE_OZONE) && defined(OS_CHROMEOS) | 346 #if defined(USE_OZONE) && defined(OS_CHROMEOS) |
326 screen_manager_ = base::MakeUnique<display::ScreenManagerForwarding>(); | 347 screen_manager_ = |
348 base::MakeUnique<display::ScreenManagerForwarding>(in_process()); | |
327 #else | 349 #else |
328 CHECK(false); | 350 CHECK(false); |
329 #endif | 351 #endif |
330 } else { | 352 } else { |
331 screen_manager_ = display::ScreenManager::Create(); | 353 screen_manager_ = display::ScreenManager::Create(); |
332 } | 354 } |
333 screen_manager_->AddInterfaces(®istry_); | 355 screen_manager_->AddInterfaces(®istry_); |
334 if (is_gpu_ready_) | 356 if (is_gpu_ready_) |
335 screen_manager_->Init(window_server_->display_manager()); | 357 screen_manager_->Init(window_server_->display_manager()); |
336 } | 358 } |
337 | 359 |
360 scoped_refptr<base::SingleThreadTaskRunner>& Service::GetResourceRunner() { | |
361 DCHECK(resource_runner_); | |
362 return resource_runner_; | |
363 } | |
364 | |
365 base::WeakPtr<ui::ImageCursors> Service::GetImageCursorsWeakPtr() { | |
366 return image_cursors_weak_ptr_; | |
367 } | |
368 | |
338 void Service::BindAccessibilityManagerRequest( | 369 void Service::BindAccessibilityManagerRequest( |
339 const service_manager::BindSourceInfo& source_info, | 370 const service_manager::BindSourceInfo& source_info, |
340 mojom::AccessibilityManagerRequest request) { | 371 mojom::AccessibilityManagerRequest request) { |
341 UserState* user_state = GetUserState(source_info.identity); | 372 UserState* user_state = GetUserState(source_info.identity); |
342 if (!user_state->accessibility) { | 373 if (!user_state->accessibility) { |
343 const ws::UserId& user_id = source_info.identity.user_id(); | 374 const ws::UserId& user_id = source_info.identity.user_id(); |
344 user_state->accessibility.reset( | 375 user_state->accessibility.reset( |
345 new ws::AccessibilityManager(window_server_.get(), user_id)); | 376 new ws::AccessibilityManager(window_server_.get(), user_id)); |
346 } | 377 } |
347 user_state->accessibility->Bind(std::move(request)); | 378 user_state->accessibility->Bind(std::move(request)); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
456 mojom::WindowServerTestRequest request) { | 487 mojom::WindowServerTestRequest request) { |
457 if (!test_config_) | 488 if (!test_config_) |
458 return; | 489 return; |
459 mojo::MakeStrongBinding( | 490 mojo::MakeStrongBinding( |
460 base::MakeUnique<ws::WindowServerTestImpl>(window_server_.get()), | 491 base::MakeUnique<ws::WindowServerTestImpl>(window_server_.get()), |
461 std::move(request)); | 492 std::move(request)); |
462 } | 493 } |
463 | 494 |
464 | 495 |
465 } // namespace ui | 496 } // namespace ui |
OLD | NEW |