| 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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 84 std::unique_ptr<mojom::WindowTreeFactoryRequest> wtf_request; | 84 std::unique_ptr<mojom::WindowTreeFactoryRequest> wtf_request; |
| 85 std::unique_ptr<mojom::DisplayManagerRequest> dm_request; | 85 std::unique_ptr<mojom::DisplayManagerRequest> dm_request; |
| 86 }; | 86 }; |
| 87 | 87 |
| 88 struct Service::UserState { | 88 struct Service::UserState { |
| 89 std::unique_ptr<clipboard::ClipboardImpl> clipboard; | 89 std::unique_ptr<clipboard::ClipboardImpl> clipboard; |
| 90 std::unique_ptr<ws::AccessibilityManager> accessibility; | 90 std::unique_ptr<ws::AccessibilityManager> accessibility; |
| 91 std::unique_ptr<ws::WindowTreeHostFactory> window_tree_host_factory; | 91 std::unique_ptr<ws::WindowTreeHostFactory> window_tree_host_factory; |
| 92 }; | 92 }; |
| 93 | 93 |
| 94 Service::Service() | 94 Service::Service(scoped_refptr<base::SingleThreadTaskRunner> resource_runner) |
| 95 : test_config_(false), | 95 : resource_runner_(resource_runner), |
| 96 /*in_process_(resource_runner != nullptr),*/ |
| 97 test_config_(false), |
| 96 ime_registrar_(&ime_server_) {} | 98 ime_registrar_(&ime_server_) {} |
| 97 | 99 |
| 98 Service::~Service() { | 100 Service::~Service() { |
| 99 // Destroy |window_server_| first, since it depends on |event_source_|. | 101 // Destroy |window_server_| first, since it depends on |event_source_|. |
| 100 // WindowServer (or more correctly its Displays) may have state that needs to | 102 // WindowServer (or more correctly its Displays) may have state that needs to |
| 101 // be destroyed before GpuState as well. | 103 // be destroyed before GpuState as well. |
| 102 window_server_.reset(); | 104 window_server_.reset(); |
| 103 | 105 |
| 104 #if defined(USE_OZONE) | 106 #if defined(USE_OZONE) |
| 105 #if defined(OS_CHROMEOS) | 107 #if defined(OS_CHROMEOS) |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 user_id_to_user_state_[user_id] = base::WrapUnique(new UserState); | 153 user_id_to_user_state_[user_id] = base::WrapUnique(new UserState); |
| 152 return user_id_to_user_state_[user_id].get(); | 154 return user_id_to_user_state_[user_id].get(); |
| 153 } | 155 } |
| 154 | 156 |
| 155 void Service::AddUserIfNecessary( | 157 void Service::AddUserIfNecessary( |
| 156 const service_manager::Identity& remote_identity) { | 158 const service_manager::Identity& remote_identity) { |
| 157 window_server_->user_id_tracker()->AddUserId(remote_identity.user_id()); | 159 window_server_->user_id_tracker()->AddUserId(remote_identity.user_id()); |
| 158 } | 160 } |
| 159 | 161 |
| 160 void Service::OnStart() { | 162 void Service::OnStart() { |
| 161 base::PlatformThread::SetName("mus"); | 163 if (!in_process()) |
| 164 base::PlatformThread::SetName("mus"); |
| 165 |
| 162 TRACE_EVENT0("mus", "Service::Initialize started"); | 166 TRACE_EVENT0("mus", "Service::Initialize started"); |
| 163 | 167 |
| 164 test_config_ = base::CommandLine::ForCurrentProcess()->HasSwitch( | 168 test_config_ = base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 165 switches::kUseTestConfig); | 169 switches::kUseTestConfig); |
| 170 |
| 166 #if defined(USE_X11) | 171 #if defined(USE_X11) |
| 167 XInitThreads(); | 172 XInitThreads(); |
| 168 ui::SetDefaultX11ErrorHandlers(); | 173 ui::SetDefaultX11ErrorHandlers(); |
| 169 #endif | 174 #endif |
| 170 | 175 |
| 171 if (test_config_) | 176 if (test_config_) |
| 172 ui::test::EnableTestConfigForPlatformWindows(); | 177 ui::test::EnableTestConfigForPlatformWindows(); |
| 173 | 178 |
| 174 // If resources are unavailable do not complete start-up. | 179 // If resources are unavailable do not complete start-up. |
| 175 if (!InitializeResources(context()->connector())) { | 180 if (!InitializeResources(context()->connector())) { |
| 176 context()->QuitNow(); | 181 context()->QuitNow(); |
| 177 return; | 182 return; |
| 178 } | 183 } |
| 179 | 184 |
| 180 #if defined(USE_OZONE) | 185 #if defined(USE_OZONE) |
| 181 // The ozone platform can provide its own event source. So initialize the | 186 // The ozone platform can provide its own event source. So initialize the |
| 182 // platform before creating the default event source. | 187 // platform before creating the default event source. |
| 183 // Because GL libraries need to be initialized before entering the sandbox, | 188 // Because GL libraries need to be initialized before entering the sandbox, |
| 184 // in MUS, |InitializeForUI| will load the GL libraries. | 189 // in MUS, |InitializeForUI| will load the GL libraries. |
| 185 ui::OzonePlatform::InitParams params; | 190 ui::OzonePlatform::InitParams params; |
| 186 params.connector = context()->connector(); | 191 params.connector = context()->connector(); |
| 187 params.single_process = false; | 192 params.single_process = false; |
| 188 ui::OzonePlatform::InitializeForUI(params); | 193 ui::OzonePlatform::InitializeForUI(params); |
| 189 | 194 |
| 190 // Assume a client will change the layout to an appropriate configuration. | 195 // Assume a client will change the layout to an appropriate configuration. |
| 191 ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine() | 196 ui::KeyboardLayoutEngineManager::GetKeyboardLayoutEngine() |
| 192 ->SetCurrentLayoutByName("us"); | 197 ->SetCurrentLayoutByName("us"); |
| 193 client_native_pixmap_factory_ = ui::CreateClientNativePixmapFactoryOzone(); | 198 |
| 194 gfx::ClientNativePixmapFactory::SetInstance( | 199 // TODO: Ok? |
| 195 client_native_pixmap_factory_.get()); | 200 if (!in_process()) { |
| 201 client_native_pixmap_factory_ = ui::CreateClientNativePixmapFactoryOzone(); |
| 202 gfx::ClientNativePixmapFactory::SetInstance( |
| 203 client_native_pixmap_factory_.get()); |
| 204 } |
| 196 | 205 |
| 197 DCHECK(gfx::ClientNativePixmapFactory::GetInstance()); | 206 DCHECK(gfx::ClientNativePixmapFactory::GetInstance()); |
| 198 | 207 |
| 199 #if defined(OS_CHROMEOS) | 208 #if defined(OS_CHROMEOS) |
| 200 input_device_controller_ = base::MakeUnique<InputDeviceController>(); | 209 input_device_controller_ = base::MakeUnique<InputDeviceController>(); |
| 201 input_device_controller_->AddInterface(®istry_); | 210 input_device_controller_->AddInterface(®istry_); |
| 202 #endif | 211 #endif |
| 203 #endif | 212 #endif |
| 204 | 213 |
| 205 // TODO(rjkroege): Enter sandbox here before we start threads in GpuState | 214 // TODO(rjkroege): Enter sandbox here before we start threads in GpuState |
| 206 // http://crbug.com/584532 | 215 // http://crbug.com/584532 |
| 207 | 216 |
| 208 #if !defined(OS_ANDROID) | 217 #if !defined(OS_ANDROID) |
| 209 event_source_ = ui::PlatformEventSource::CreateDefault(); | 218 event_source_ = ui::PlatformEventSource::CreateDefault(); |
| 210 #endif | 219 #endif |
| 211 | 220 |
| 212 // This needs to happen after DeviceDataManager has been constructed. That | 221 // This needs to happen after DeviceDataManager has been constructed. That |
| 213 // happens either during OzonePlatform or PlatformEventSource initialization, | 222 // happens either during OzonePlatform or PlatformEventSource initialization, |
| 214 // so keep this line below both of those. | 223 // so keep this line below both of those. |
| 215 input_device_server_.RegisterAsObserver(); | 224 input_device_server_.RegisterAsObserver(); |
| 216 | 225 |
| 217 window_server_.reset(new ws::WindowServer(this)); | 226 window_server_.reset(new ws::WindowServer(this, resource_runner_)); |
| 218 std::unique_ptr<ws::GpuHost> gpu_host = | 227 std::unique_ptr<ws::GpuHost> gpu_host = |
| 219 base::MakeUnique<ws::DefaultGpuHost>(window_server_.get()); | 228 base::MakeUnique<ws::DefaultGpuHost>(window_server_.get()); |
| 220 std::unique_ptr<ws::FrameSinkManagerClientBinding> frame_sink_manager = | 229 std::unique_ptr<ws::FrameSinkManagerClientBinding> frame_sink_manager = |
| 221 base::MakeUnique<ws::FrameSinkManagerClientBinding>(window_server_.get(), | 230 base::MakeUnique<ws::FrameSinkManagerClientBinding>(window_server_.get(), |
| 222 gpu_host.get()); | 231 gpu_host.get()); |
| 223 window_server_->SetGpuHost(std::move(gpu_host)); | 232 window_server_->SetGpuHost(std::move(gpu_host)); |
| 224 window_server_->SetFrameSinkManager(std::move(frame_sink_manager)); | 233 window_server_->SetFrameSinkManager(std::move(frame_sink_manager)); |
| 225 | 234 |
| 226 ime_server_.Init(context()->connector(), test_config_); | 235 ime_server_.Init(context()->connector(), test_config_); |
| 227 | 236 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 | 327 |
| 319 DVLOG(3) << "OnWillCreateTreeForWindowManager " | 328 DVLOG(3) << "OnWillCreateTreeForWindowManager " |
| 320 << automatically_create_display_roots; | 329 << automatically_create_display_roots; |
| 321 ws::DisplayCreationConfig config = automatically_create_display_roots | 330 ws::DisplayCreationConfig config = automatically_create_display_roots |
| 322 ? ws::DisplayCreationConfig::AUTOMATIC | 331 ? ws::DisplayCreationConfig::AUTOMATIC |
| 323 : ws::DisplayCreationConfig::MANUAL; | 332 : ws::DisplayCreationConfig::MANUAL; |
| 324 window_server_->SetDisplayCreationConfig(config); | 333 window_server_->SetDisplayCreationConfig(config); |
| 325 if (window_server_->display_creation_config() == | 334 if (window_server_->display_creation_config() == |
| 326 ws::DisplayCreationConfig::MANUAL) { | 335 ws::DisplayCreationConfig::MANUAL) { |
| 327 #if defined(USE_OZONE) && defined(OS_CHROMEOS) | 336 #if defined(USE_OZONE) && defined(OS_CHROMEOS) |
| 328 screen_manager_ = base::MakeUnique<display::ScreenManagerForwarding>(); | 337 screen_manager_ = |
| 338 base::MakeUnique<display::ScreenManagerForwarding>(in_process()); |
| 329 #else | 339 #else |
| 330 CHECK(false); | 340 CHECK(false); |
| 331 #endif | 341 #endif |
| 332 } else { | 342 } else { |
| 333 screen_manager_ = display::ScreenManager::Create(); | 343 screen_manager_ = display::ScreenManager::Create(); |
| 334 } | 344 } |
| 335 screen_manager_->AddInterfaces(®istry_); | 345 screen_manager_->AddInterfaces(®istry_); |
| 336 if (is_gpu_ready_) | 346 if (is_gpu_ready_) |
| 337 screen_manager_->Init(window_server_->display_manager()); | 347 screen_manager_->Init(window_server_->display_manager()); |
| 338 } | 348 } |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 458 mojom::WindowServerTestRequest request) { | 468 mojom::WindowServerTestRequest request) { |
| 459 if (!test_config_) | 469 if (!test_config_) |
| 460 return; | 470 return; |
| 461 mojo::MakeStrongBinding( | 471 mojo::MakeStrongBinding( |
| 462 base::MakeUnique<ws::WindowServerTestImpl>(window_server_.get()), | 472 base::MakeUnique<ws::WindowServerTestImpl>(window_server_.get()), |
| 463 std::move(request)); | 473 std::move(request)); |
| 464 } | 474 } |
| 465 | 475 |
| 466 | 476 |
| 467 } // namespace ui | 477 } // namespace ui |
| OLD | NEW |