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" |
11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
12 #include "base/memory/weak_ptr.h" | |
13 #include "base/message_loop/message_loop.h" | 12 #include "base/message_loop/message_loop.h" |
14 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
15 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
16 #include "base/trace_event/trace_event.h" | 15 #include "base/trace_event/trace_event.h" |
17 #include "build/build_config.h" | 16 #include "build/build_config.h" |
18 #include "components/discardable_memory/service/discardable_shared_memory_manage
r.h" | 17 #include "components/discardable_memory/service/discardable_shared_memory_manage
r.h" |
19 #include "mojo/public/cpp/bindings/strong_binding.h" | 18 #include "mojo/public/cpp/bindings/strong_binding.h" |
20 #include "services/catalog/public/cpp/resource_loader.h" | 19 #include "services/catalog/public/cpp/resource_loader.h" |
21 #include "services/catalog/public/interfaces/constants.mojom.h" | 20 #include "services/catalog/public/interfaces/constants.mojom.h" |
22 #include "services/service_manager/public/c/main.h" | 21 #include "services/service_manager/public/c/main.h" |
23 #include "services/service_manager/public/cpp/connector.h" | 22 #include "services/service_manager/public/cpp/connector.h" |
24 #include "services/service_manager/public/cpp/service_context.h" | 23 #include "services/service_manager/public/cpp/service_context.h" |
25 #include "services/ui/clipboard/clipboard_impl.h" | 24 #include "services/ui/clipboard/clipboard_impl.h" |
| 25 #include "services/ui/common/image_cursors_set.h" |
26 #include "services/ui/common/switches.h" | 26 #include "services/ui/common/switches.h" |
27 #include "services/ui/display/screen_manager.h" | 27 #include "services/ui/display/screen_manager.h" |
28 #include "services/ui/ime/ime_driver_bridge.h" | 28 #include "services/ui/ime/ime_driver_bridge.h" |
29 #include "services/ui/ime/ime_registrar_impl.h" | 29 #include "services/ui/ime/ime_registrar_impl.h" |
30 #include "services/ui/ws/accessibility_manager.h" | 30 #include "services/ui/ws/accessibility_manager.h" |
31 #include "services/ui/ws/display_binding.h" | 31 #include "services/ui/ws/display_binding.h" |
32 #include "services/ui/ws/display_creation_config.h" | 32 #include "services/ui/ws/display_creation_config.h" |
33 #include "services/ui/ws/display_manager.h" | 33 #include "services/ui/ws/display_manager.h" |
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/threaded_image_cursors.h" |
| 37 #include "services/ui/ws/threaded_image_cursors_factory.h" |
36 #include "services/ui/ws/user_activity_monitor.h" | 38 #include "services/ui/ws/user_activity_monitor.h" |
37 #include "services/ui/ws/user_display_manager.h" | 39 #include "services/ui/ws/user_display_manager.h" |
38 #include "services/ui/ws/window_server.h" | 40 #include "services/ui/ws/window_server.h" |
39 #include "services/ui/ws/window_server_test_impl.h" | 41 #include "services/ui/ws/window_server_test_impl.h" |
40 #include "services/ui/ws/window_tree.h" | 42 #include "services/ui/ws/window_tree.h" |
41 #include "services/ui/ws/window_tree_binding.h" | 43 #include "services/ui/ws/window_tree_binding.h" |
42 #include "services/ui/ws/window_tree_factory.h" | 44 #include "services/ui/ws/window_tree_factory.h" |
43 #include "services/ui/ws/window_tree_host_factory.h" | 45 #include "services/ui/ws/window_tree_host_factory.h" |
| 46 #include "ui/base/cursor/image_cursors.h" |
44 #include "ui/base/platform_window_defaults.h" | 47 #include "ui/base/platform_window_defaults.h" |
45 #include "ui/base/resource/resource_bundle.h" | 48 #include "ui/base/resource/resource_bundle.h" |
46 #include "ui/base/ui_base_paths.h" | 49 #include "ui/base/ui_base_paths.h" |
47 #include "ui/events/event_switches.h" | 50 #include "ui/events/event_switches.h" |
48 #include "ui/events/platform/platform_event_source.h" | 51 #include "ui/events/platform/platform_event_source.h" |
49 #include "ui/gfx/geometry/rect.h" | 52 #include "ui/gfx/geometry/rect.h" |
50 #include "ui/gl/gl_surface.h" | 53 #include "ui/gl/gl_surface.h" |
51 | 54 |
52 #if defined(USE_X11) | 55 #if defined(USE_X11) |
53 #include <X11/Xlib.h> | 56 #include <X11/Xlib.h> |
(...skipping 15 matching lines...) Expand all Loading... |
69 using ui::mojom::WindowTreeHostFactory; | 72 using ui::mojom::WindowTreeHostFactory; |
70 | 73 |
71 namespace ui { | 74 namespace ui { |
72 | 75 |
73 namespace { | 76 namespace { |
74 | 77 |
75 const char kResourceFileStrings[] = "mus_app_resources_strings.pak"; | 78 const char kResourceFileStrings[] = "mus_app_resources_strings.pak"; |
76 const char kResourceFile100[] = "mus_app_resources_100.pak"; | 79 const char kResourceFile100[] = "mus_app_resources_100.pak"; |
77 const char kResourceFile200[] = "mus_app_resources_200.pak"; | 80 const char kResourceFile200[] = "mus_app_resources_200.pak"; |
78 | 81 |
| 82 class ThreadedImageCursorsFactoryImpl : public ws::ThreadedImageCursorsFactory { |
| 83 public: |
| 84 // Uses the same InProcessConfig as the UI Service. |config| will be null when |
| 85 // the UI Service runs in it's own separate process as opposed to the WM's |
| 86 // process. |
| 87 explicit ThreadedImageCursorsFactoryImpl(Service::InProcessConfig* config) { |
| 88 if (config) { |
| 89 resource_runner_ = config->resource_runner; |
| 90 image_cursors_set_weak_ptr_ = config->image_cursors_set_weak_ptr; |
| 91 DCHECK(resource_runner_); |
| 92 } |
| 93 } |
| 94 |
| 95 ~ThreadedImageCursorsFactoryImpl() override {} |
| 96 |
| 97 // ws::ThreadedImageCursorsFactory: |
| 98 std::unique_ptr<ws::ThreadedImageCursors> CreateCursors() override { |
| 99 // |resource_runner_| will not be initialized if and only if UI Service runs |
| 100 // in it's own separate process. In this case we can (lazily) initialize it |
| 101 // to the current thread (i.e. the UI Services's thread). We also initialize |
| 102 // the local |image_cursors_set_| and make |image_cursors_set_weak_ptr_| |
| 103 // point to it. |
| 104 if (!resource_runner_) { |
| 105 resource_runner_ = base::ThreadTaskRunnerHandle::Get(); |
| 106 image_cursors_set_ = base::MakeUnique<ui::ImageCursorsSet>(); |
| 107 image_cursors_set_weak_ptr_ = image_cursors_set_->GetWeakPtr(); |
| 108 } |
| 109 return base::MakeUnique<ws::ThreadedImageCursors>( |
| 110 resource_runner_, image_cursors_set_weak_ptr_); |
| 111 } |
| 112 |
| 113 private: |
| 114 scoped_refptr<base::SingleThreadTaskRunner> resource_runner_; |
| 115 base::WeakPtr<ui::ImageCursorsSet> image_cursors_set_weak_ptr_; |
| 116 |
| 117 // Used when UI Service doesn't run inside WM's process. |
| 118 std::unique_ptr<ui::ImageCursorsSet> image_cursors_set_; |
| 119 |
| 120 DISALLOW_COPY_AND_ASSIGN(ThreadedImageCursorsFactoryImpl); |
| 121 }; |
| 122 |
79 } // namespace | 123 } // namespace |
80 | 124 |
81 // TODO(sky): this is a pretty typical pattern, make it easier to do. | 125 // TODO(sky): this is a pretty typical pattern, make it easier to do. |
82 struct Service::PendingRequest { | 126 struct Service::PendingRequest { |
83 service_manager::BindSourceInfo source_info; | 127 service_manager::BindSourceInfo source_info; |
84 std::unique_ptr<mojom::WindowTreeFactoryRequest> wtf_request; | 128 std::unique_ptr<mojom::WindowTreeFactoryRequest> wtf_request; |
85 std::unique_ptr<mojom::DisplayManagerRequest> dm_request; | 129 std::unique_ptr<mojom::DisplayManagerRequest> dm_request; |
86 }; | 130 }; |
87 | 131 |
88 struct Service::UserState { | 132 struct Service::UserState { |
89 std::unique_ptr<clipboard::ClipboardImpl> clipboard; | 133 std::unique_ptr<clipboard::ClipboardImpl> clipboard; |
90 std::unique_ptr<ws::AccessibilityManager> accessibility; | 134 std::unique_ptr<ws::AccessibilityManager> accessibility; |
91 std::unique_ptr<ws::WindowTreeHostFactory> window_tree_host_factory; | 135 std::unique_ptr<ws::WindowTreeHostFactory> window_tree_host_factory; |
92 }; | 136 }; |
93 | 137 |
94 Service::Service() : test_config_(false), ime_registrar_(&ime_driver_) {} | 138 Service::InProcessConfig::InProcessConfig() = default; |
| 139 |
| 140 Service::InProcessConfig::InProcessConfig(const InProcessConfig& params) = |
| 141 default; |
| 142 |
| 143 Service::InProcessConfig::~InProcessConfig() = default; |
| 144 |
| 145 Service::Service(InProcessConfig* config) |
| 146 : is_in_process_(config != nullptr), |
| 147 threaded_image_cursors_factory_( |
| 148 base::MakeUnique<ThreadedImageCursorsFactoryImpl>(config)), |
| 149 test_config_(false), |
| 150 ime_registrar_(&ime_driver_) {} |
95 | 151 |
96 Service::~Service() { | 152 Service::~Service() { |
97 // Destroy |window_server_| first, since it depends on |event_source_|. | 153 // Destroy |window_server_| first, since it depends on |event_source_|. |
98 // WindowServer (or more correctly its Displays) may have state that needs to | 154 // WindowServer (or more correctly its Displays) may have state that needs to |
99 // be destroyed before GpuState as well. | 155 // be destroyed before GpuState as well. |
100 window_server_.reset(); | 156 window_server_.reset(); |
101 | 157 |
102 #if defined(USE_OZONE) | 158 #if defined(USE_OZONE) |
103 #if defined(OS_CHROMEOS) | 159 #if defined(OS_CHROMEOS) |
104 // InputDeviceController uses ozone. | 160 // InputDeviceController uses ozone. |
105 input_device_controller_.reset(); | 161 input_device_controller_.reset(); |
106 #endif | 162 #endif |
107 | 163 |
108 OzonePlatform::Shutdown(); | 164 OzonePlatform::Shutdown(); |
109 #endif | 165 #endif |
110 } | 166 } |
111 | 167 |
112 bool Service::InitializeResources(service_manager::Connector* connector) { | 168 bool Service::InitializeResources(service_manager::Connector* connector) { |
113 if (ui::ResourceBundle::HasSharedInstance()) | 169 if (is_in_process() || ui::ResourceBundle::HasSharedInstance()) |
114 return true; | 170 return true; |
115 | 171 |
116 std::set<std::string> resource_paths; | 172 std::set<std::string> resource_paths; |
117 resource_paths.insert(kResourceFileStrings); | 173 resource_paths.insert(kResourceFileStrings); |
118 resource_paths.insert(kResourceFile100); | 174 resource_paths.insert(kResourceFile100); |
119 resource_paths.insert(kResourceFile200); | 175 resource_paths.insert(kResourceFile200); |
120 | 176 |
121 catalog::ResourceLoader loader; | 177 catalog::ResourceLoader loader; |
122 filesystem::mojom::DirectoryPtr directory; | 178 filesystem::mojom::DirectoryPtr directory; |
123 connector->BindInterface(catalog::mojom::kServiceName, &directory); | 179 connector->BindInterface(catalog::mojom::kServiceName, &directory); |
124 if (!loader.OpenFiles(std::move(directory), resource_paths)) { | 180 if (!loader.OpenFiles(std::move(directory), resource_paths)) { |
125 LOG(ERROR) << "Service failed to open resource files."; | 181 LOG(ERROR) << "Service failed to open resource files."; |
126 return false; | 182 return false; |
127 } | 183 } |
128 | 184 |
129 ui::RegisterPathProvider(); | 185 ui::RegisterPathProvider(); |
130 | 186 |
131 // Initialize resource bundle with 1x and 2x cursor bitmaps. | 187 // Initialize resource bundle with 1x and 2x cursor bitmaps. |
132 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( | 188 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( |
133 loader.TakeFile(kResourceFileStrings), | 189 loader.TakeFile(kResourceFileStrings), |
134 base::MemoryMappedFile::Region::kWholeFile); | 190 base::MemoryMappedFile::Region::kWholeFile); |
135 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 191 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
136 rb.AddDataPackFromFile(loader.TakeFile(kResourceFile100), | 192 rb.AddDataPackFromFile(loader.TakeFile(kResourceFile100), |
137 ui::SCALE_FACTOR_100P); | 193 ui::SCALE_FACTOR_100P); |
138 rb.AddDataPackFromFile(loader.TakeFile(kResourceFile200), | 194 rb.AddDataPackFromFile(loader.TakeFile(kResourceFile200), |
139 ui::SCALE_FACTOR_200P); | 195 ui::SCALE_FACTOR_200P); |
| 196 |
140 return true; | 197 return true; |
141 } | 198 } |
142 | 199 |
143 Service::UserState* Service::GetUserState( | 200 Service::UserState* Service::GetUserState( |
144 const service_manager::Identity& remote_identity) { | 201 const service_manager::Identity& remote_identity) { |
145 const ws::UserId& user_id = remote_identity.user_id(); | 202 const ws::UserId& user_id = remote_identity.user_id(); |
146 auto it = user_id_to_user_state_.find(user_id); | 203 auto it = user_id_to_user_state_.find(user_id); |
147 if (it != user_id_to_user_state_.end()) | 204 if (it != user_id_to_user_state_.end()) |
148 return it->second.get(); | 205 return it->second.get(); |
149 user_id_to_user_state_[user_id] = base::WrapUnique(new UserState); | 206 user_id_to_user_state_[user_id] = base::WrapUnique(new UserState); |
150 return user_id_to_user_state_[user_id].get(); | 207 return user_id_to_user_state_[user_id].get(); |
151 } | 208 } |
152 | 209 |
153 void Service::AddUserIfNecessary( | 210 void Service::AddUserIfNecessary( |
154 const service_manager::Identity& remote_identity) { | 211 const service_manager::Identity& remote_identity) { |
155 window_server_->user_id_tracker()->AddUserId(remote_identity.user_id()); | 212 window_server_->user_id_tracker()->AddUserId(remote_identity.user_id()); |
156 } | 213 } |
157 | 214 |
158 void Service::OnStart() { | 215 void Service::OnStart() { |
159 base::PlatformThread::SetName("mus"); | 216 if (!is_in_process()) |
| 217 base::PlatformThread::SetName("mus"); |
| 218 |
160 TRACE_EVENT0("mus", "Service::Initialize started"); | 219 TRACE_EVENT0("mus", "Service::Initialize started"); |
161 | 220 |
162 test_config_ = base::CommandLine::ForCurrentProcess()->HasSwitch( | 221 test_config_ = base::CommandLine::ForCurrentProcess()->HasSwitch( |
163 switches::kUseTestConfig); | 222 switches::kUseTestConfig); |
| 223 |
164 #if defined(USE_X11) | 224 #if defined(USE_X11) |
165 XInitThreads(); | 225 XInitThreads(); |
166 ui::SetDefaultX11ErrorHandlers(); | 226 ui::SetDefaultX11ErrorHandlers(); |
167 #endif | 227 #endif |
168 | 228 |
169 if (test_config_) | 229 if (test_config_) |
170 ui::test::EnableTestConfigForPlatformWindows(); | 230 ui::test::EnableTestConfigForPlatformWindows(); |
171 | 231 |
172 // If resources are unavailable do not complete start-up. | 232 // If resources are unavailable do not complete start-up. |
173 if (!InitializeResources(context()->connector())) { | 233 if (!InitializeResources(context()->connector())) { |
174 context()->QuitNow(); | 234 context()->QuitNow(); |
175 return; | 235 return; |
176 } | 236 } |
177 | 237 |
178 #if defined(USE_OZONE) | 238 #if defined(USE_OZONE) |
179 // The ozone platform can provide its own event source. So initialize the | 239 // The ozone platform can provide its own event source. So initialize the |
180 // platform before creating the default event source. | 240 // platform before creating the default event source. |
181 // Because GL libraries need to be initialized before entering the sandbox, | 241 // Because GL libraries need to be initialized before entering the sandbox, |
182 // in MUS, |InitializeForUI| will load the GL libraries. | 242 // in MUS, |InitializeForUI| will load the GL libraries. |
183 ui::OzonePlatform::InitParams params; | 243 ui::OzonePlatform::InitParams params; |
184 params.connector = context()->connector(); | 244 params.connector = context()->connector(); |
185 params.single_process = false; | 245 params.single_process = false; |
186 ui::OzonePlatform::InitializeForUI(params); | 246 ui::OzonePlatform::InitializeForUI(params); |
187 | 247 |
188 // Assume a client will change the layout to an appropriate configuration. | 248 // Assume a client will change the layout to an appropriate configuration. |
189 ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine() | 249 ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine() |
190 ->SetCurrentLayoutByName("us"); | 250 ->SetCurrentLayoutByName("us"); |
191 client_native_pixmap_factory_ = ui::CreateClientNativePixmapFactoryOzone(); | 251 |
192 gfx::ClientNativePixmapFactory::SetInstance( | 252 if (!is_in_process()) { |
193 client_native_pixmap_factory_.get()); | 253 client_native_pixmap_factory_ = ui::CreateClientNativePixmapFactoryOzone(); |
| 254 gfx::ClientNativePixmapFactory::SetInstance( |
| 255 client_native_pixmap_factory_.get()); |
| 256 } |
194 | 257 |
195 DCHECK(gfx::ClientNativePixmapFactory::GetInstance()); | 258 DCHECK(gfx::ClientNativePixmapFactory::GetInstance()); |
196 | 259 |
197 #if defined(OS_CHROMEOS) | 260 #if defined(OS_CHROMEOS) |
198 input_device_controller_ = base::MakeUnique<InputDeviceController>(); | 261 input_device_controller_ = base::MakeUnique<InputDeviceController>(); |
199 input_device_controller_->AddInterface(®istry_); | 262 input_device_controller_->AddInterface(®istry_); |
200 #endif | 263 #endif |
201 #endif | 264 #endif |
202 | 265 |
203 // TODO(rjkroege): Enter sandbox here before we start threads in GpuState | 266 // 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 | 379 |
317 DVLOG(3) << "OnWillCreateTreeForWindowManager " | 380 DVLOG(3) << "OnWillCreateTreeForWindowManager " |
318 << automatically_create_display_roots; | 381 << automatically_create_display_roots; |
319 ws::DisplayCreationConfig config = automatically_create_display_roots | 382 ws::DisplayCreationConfig config = automatically_create_display_roots |
320 ? ws::DisplayCreationConfig::AUTOMATIC | 383 ? ws::DisplayCreationConfig::AUTOMATIC |
321 : ws::DisplayCreationConfig::MANUAL; | 384 : ws::DisplayCreationConfig::MANUAL; |
322 window_server_->SetDisplayCreationConfig(config); | 385 window_server_->SetDisplayCreationConfig(config); |
323 if (window_server_->display_creation_config() == | 386 if (window_server_->display_creation_config() == |
324 ws::DisplayCreationConfig::MANUAL) { | 387 ws::DisplayCreationConfig::MANUAL) { |
325 #if defined(USE_OZONE) && defined(OS_CHROMEOS) | 388 #if defined(USE_OZONE) && defined(OS_CHROMEOS) |
326 screen_manager_ = base::MakeUnique<display::ScreenManagerForwarding>(); | 389 display::ScreenManagerForwarding::Mode mode = |
| 390 is_in_process() ? display::ScreenManagerForwarding::Mode::IN_WM_PROCESS |
| 391 : display::ScreenManagerForwarding::Mode::OWN_PROCESS; |
| 392 screen_manager_ = base::MakeUnique<display::ScreenManagerForwarding>(mode); |
327 #else | 393 #else |
328 CHECK(false); | 394 CHECK(false); |
329 #endif | 395 #endif |
330 } else { | 396 } else { |
331 screen_manager_ = display::ScreenManager::Create(); | 397 screen_manager_ = display::ScreenManager::Create(); |
332 } | 398 } |
333 screen_manager_->AddInterfaces(®istry_); | 399 screen_manager_->AddInterfaces(®istry_); |
334 if (is_gpu_ready_) | 400 if (is_gpu_ready_) |
335 screen_manager_->Init(window_server_->display_manager()); | 401 screen_manager_->Init(window_server_->display_manager()); |
336 } | 402 } |
337 | 403 |
| 404 ws::ThreadedImageCursorsFactory* Service::GetThreadedImageCursorsFactory() { |
| 405 return threaded_image_cursors_factory_.get(); |
| 406 } |
| 407 |
338 void Service::BindAccessibilityManagerRequest( | 408 void Service::BindAccessibilityManagerRequest( |
339 const service_manager::BindSourceInfo& source_info, | 409 const service_manager::BindSourceInfo& source_info, |
340 mojom::AccessibilityManagerRequest request) { | 410 mojom::AccessibilityManagerRequest request) { |
341 UserState* user_state = GetUserState(source_info.identity); | 411 UserState* user_state = GetUserState(source_info.identity); |
342 if (!user_state->accessibility) { | 412 if (!user_state->accessibility) { |
343 const ws::UserId& user_id = source_info.identity.user_id(); | 413 const ws::UserId& user_id = source_info.identity.user_id(); |
344 user_state->accessibility.reset( | 414 user_state->accessibility.reset( |
345 new ws::AccessibilityManager(window_server_.get(), user_id)); | 415 new ws::AccessibilityManager(window_server_.get(), user_id)); |
346 } | 416 } |
347 user_state->accessibility->Bind(std::move(request)); | 417 user_state->accessibility->Bind(std::move(request)); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 mojom::WindowServerTestRequest request) { | 526 mojom::WindowServerTestRequest request) { |
457 if (!test_config_) | 527 if (!test_config_) |
458 return; | 528 return; |
459 mojo::MakeStrongBinding( | 529 mojo::MakeStrongBinding( |
460 base::MakeUnique<ws::WindowServerTestImpl>(window_server_.get()), | 530 base::MakeUnique<ws::WindowServerTestImpl>(window_server_.get()), |
461 std::move(request)); | 531 std::move(request)); |
462 } | 532 } |
463 | 533 |
464 | 534 |
465 } // namespace ui | 535 } // namespace ui |
OLD | NEW |