| 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 "components/mus/mus_app.h" | 5 #include "components/mus/mus_app.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #if defined(USE_X11) | 35 #if defined(USE_X11) |
| 36 #include <X11/Xlib.h> | 36 #include <X11/Xlib.h> |
| 37 #include "base/command_line.h" | 37 #include "base/command_line.h" |
| 38 #include "ui/platform_window/x11/x11_window.h" | 38 #include "ui/platform_window/x11/x11_window.h" |
| 39 #elif defined(USE_OZONE) | 39 #elif defined(USE_OZONE) |
| 40 #include "ui/events/ozone/layout/keyboard_layout_engine.h" | 40 #include "ui/events/ozone/layout/keyboard_layout_engine.h" |
| 41 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" | 41 #include "ui/events/ozone/layout/keyboard_layout_engine_manager.h" |
| 42 #include "ui/ozone/public/ozone_platform.h" | 42 #include "ui/ozone/public/ozone_platform.h" |
| 43 #endif | 43 #endif |
| 44 | 44 |
| 45 using mojo::Connection; | 45 using shell::Connection; |
| 46 using mojo::InterfaceRequest; | 46 using mojo::InterfaceRequest; |
| 47 using mus::mojom::WindowTreeHostFactory; | 47 using mus::mojom::WindowTreeHostFactory; |
| 48 using mus::mojom::Gpu; | 48 using mus::mojom::Gpu; |
| 49 | 49 |
| 50 namespace mus { | 50 namespace mus { |
| 51 | 51 |
| 52 namespace { | 52 namespace { |
| 53 | 53 |
| 54 const char kResourceFileStrings[] = "mus_app_resources_strings.pak"; | 54 const char kResourceFileStrings[] = "mus_app_resources_strings.pak"; |
| 55 const char kResourceFile100[] = "mus_app_resources_100.pak"; | 55 const char kResourceFile100[] = "mus_app_resources_100.pak"; |
| 56 const char kResourceFile200[] = "mus_app_resources_200.pak"; | 56 const char kResourceFile200[] = "mus_app_resources_200.pak"; |
| 57 | 57 |
| 58 } // namespace | 58 } // namespace |
| 59 | 59 |
| 60 // TODO(sky): this is a pretty typical pattern, make it easier to do. | 60 // TODO(sky): this is a pretty typical pattern, make it easier to do. |
| 61 struct MandolineUIServicesApp::PendingRequest { | 61 struct MandolineUIServicesApp::PendingRequest { |
| 62 mojo::Connection* connection; | 62 shell::Connection* connection; |
| 63 scoped_ptr<mojo::InterfaceRequest<mojom::WindowTreeFactory>> wtf_request; | 63 scoped_ptr<mojo::InterfaceRequest<mojom::WindowTreeFactory>> wtf_request; |
| 64 }; | 64 }; |
| 65 | 65 |
| 66 struct MandolineUIServicesApp::UserState { | 66 struct MandolineUIServicesApp::UserState { |
| 67 scoped_ptr<ws::WindowTreeFactory> window_tree_factory; | 67 scoped_ptr<ws::WindowTreeFactory> window_tree_factory; |
| 68 scoped_ptr<ws::WindowTreeHostFactory> window_tree_host_factory; | 68 scoped_ptr<ws::WindowTreeHostFactory> window_tree_host_factory; |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 MandolineUIServicesApp::MandolineUIServicesApp() {} | 71 MandolineUIServicesApp::MandolineUIServicesApp() {} |
| 72 | 72 |
| 73 MandolineUIServicesApp::~MandolineUIServicesApp() { | 73 MandolineUIServicesApp::~MandolineUIServicesApp() { |
| 74 // Destroy |window_server_| first, since it depends on |event_source_|. | 74 // Destroy |window_server_| first, since it depends on |event_source_|. |
| 75 // WindowServer (or more correctly its Displays) may have state that needs to | 75 // WindowServer (or more correctly its Displays) may have state that needs to |
| 76 // be destroyed before GpuState as well. | 76 // be destroyed before GpuState as well. |
| 77 window_server_.reset(); | 77 window_server_.reset(); |
| 78 | 78 |
| 79 if (platform_display_init_params_.gpu_state) | 79 if (platform_display_init_params_.gpu_state) |
| 80 platform_display_init_params_.gpu_state->StopThreads(); | 80 platform_display_init_params_.gpu_state->StopThreads(); |
| 81 } | 81 } |
| 82 | 82 |
| 83 void MandolineUIServicesApp::InitializeResources(mojo::Connector* connector) { | 83 void MandolineUIServicesApp::InitializeResources(shell::Connector* connector) { |
| 84 if (ui::ResourceBundle::HasSharedInstance()) | 84 if (ui::ResourceBundle::HasSharedInstance()) |
| 85 return; | 85 return; |
| 86 | 86 |
| 87 std::set<std::string> resource_paths; | 87 std::set<std::string> resource_paths; |
| 88 resource_paths.insert(kResourceFileStrings); | 88 resource_paths.insert(kResourceFileStrings); |
| 89 resource_paths.insert(kResourceFile100); | 89 resource_paths.insert(kResourceFile100); |
| 90 resource_paths.insert(kResourceFile200); | 90 resource_paths.insert(kResourceFile200); |
| 91 | 91 |
| 92 resource_provider::ResourceLoader loader(connector, resource_paths); | 92 resource_provider::ResourceLoader loader(connector, resource_paths); |
| 93 if (!loader.BlockUntilLoaded()) | 93 if (!loader.BlockUntilLoaded()) |
| 94 return; | 94 return; |
| 95 ui::RegisterPathProvider(); | 95 ui::RegisterPathProvider(); |
| 96 | 96 |
| 97 // Initialize resource bundle with 1x and 2x cursor bitmaps. | 97 // Initialize resource bundle with 1x and 2x cursor bitmaps. |
| 98 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( | 98 ui::ResourceBundle::InitSharedInstanceWithPakFileRegion( |
| 99 loader.ReleaseFile(kResourceFileStrings), | 99 loader.ReleaseFile(kResourceFileStrings), |
| 100 base::MemoryMappedFile::Region::kWholeFile); | 100 base::MemoryMappedFile::Region::kWholeFile); |
| 101 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 101 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 102 rb.AddDataPackFromFile(loader.ReleaseFile(kResourceFile100), | 102 rb.AddDataPackFromFile(loader.ReleaseFile(kResourceFile100), |
| 103 ui::SCALE_FACTOR_100P); | 103 ui::SCALE_FACTOR_100P); |
| 104 rb.AddDataPackFromFile(loader.ReleaseFile(kResourceFile200), | 104 rb.AddDataPackFromFile(loader.ReleaseFile(kResourceFile200), |
| 105 ui::SCALE_FACTOR_200P); | 105 ui::SCALE_FACTOR_200P); |
| 106 } | 106 } |
| 107 | 107 |
| 108 MandolineUIServicesApp::UserState* MandolineUIServicesApp::GetUserState( | 108 MandolineUIServicesApp::UserState* MandolineUIServicesApp::GetUserState( |
| 109 mojo::Connection* connection) { | 109 shell::Connection* connection) { |
| 110 const ws::UserId& user_id = connection->GetRemoteIdentity().user_id(); | 110 const ws::UserId& user_id = connection->GetRemoteIdentity().user_id(); |
| 111 auto it = user_id_to_user_state_.find(user_id); | 111 auto it = user_id_to_user_state_.find(user_id); |
| 112 if (it != user_id_to_user_state_.end()) | 112 if (it != user_id_to_user_state_.end()) |
| 113 return it->second.get(); | 113 return it->second.get(); |
| 114 user_id_to_user_state_[user_id] = make_scoped_ptr(new UserState); | 114 user_id_to_user_state_[user_id] = make_scoped_ptr(new UserState); |
| 115 return user_id_to_user_state_[user_id].get(); | 115 return user_id_to_user_state_[user_id].get(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 void MandolineUIServicesApp::AddUserIfNecessary(mojo::Connection* connection) { | 118 void MandolineUIServicesApp::AddUserIfNecessary(shell::Connection* connection) { |
| 119 window_server_->user_id_tracker()->AddUserId( | 119 window_server_->user_id_tracker()->AddUserId( |
| 120 connection->GetRemoteIdentity().user_id()); | 120 connection->GetRemoteIdentity().user_id()); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void MandolineUIServicesApp::Initialize(mojo::Connector* connector, | 123 void MandolineUIServicesApp::Initialize(shell::Connector* connector, |
| 124 const mojo::Identity& identity, | 124 const shell::Identity& identity, |
| 125 uint32_t id) { | 125 uint32_t id) { |
| 126 platform_display_init_params_.connector = connector; | 126 platform_display_init_params_.connector = connector; |
| 127 platform_display_init_params_.surfaces_state = new SurfacesState; | 127 platform_display_init_params_.surfaces_state = new SurfacesState; |
| 128 | 128 |
| 129 base::PlatformThread::SetName("mus"); | 129 base::PlatformThread::SetName("mus"); |
| 130 | 130 |
| 131 #if defined(USE_X11) | 131 #if defined(USE_X11) |
| 132 XInitThreads(); | 132 XInitThreads(); |
| 133 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | 133 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); |
| 134 if (command_line->HasSwitch(kUseX11TestConfig)) { | 134 if (command_line->HasSwitch(kUseX11TestConfig)) { |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 base::MessageLoop::current()->QuitWhenIdle(); | 190 base::MessageLoop::current()->QuitWhenIdle(); |
| 191 } | 191 } |
| 192 | 192 |
| 193 void MandolineUIServicesApp::CreateDefaultDisplays() { | 193 void MandolineUIServicesApp::CreateDefaultDisplays() { |
| 194 // Display manages its own lifetime. | 194 // Display manages its own lifetime. |
| 195 ws::Display* host_impl = | 195 ws::Display* host_impl = |
| 196 new ws::Display(window_server_.get(), platform_display_init_params_); | 196 new ws::Display(window_server_.get(), platform_display_init_params_); |
| 197 host_impl->Init(nullptr); | 197 host_impl->Init(nullptr); |
| 198 } | 198 } |
| 199 | 199 |
| 200 void MandolineUIServicesApp::Create(mojo::Connection* connection, | 200 void MandolineUIServicesApp::Create(shell::Connection* connection, |
| 201 mojom::DisplayManagerRequest request) { | 201 mojom::DisplayManagerRequest request) { |
| 202 window_server_->display_manager() | 202 window_server_->display_manager() |
| 203 ->GetUserDisplayManager(connection->GetRemoteIdentity().user_id()) | 203 ->GetUserDisplayManager(connection->GetRemoteIdentity().user_id()) |
| 204 ->AddDisplayManagerBinding(std::move(request)); | 204 ->AddDisplayManagerBinding(std::move(request)); |
| 205 } | 205 } |
| 206 | 206 |
| 207 void MandolineUIServicesApp::Create(mojo::Connection* connection, | 207 void MandolineUIServicesApp::Create(shell::Connection* connection, |
| 208 mojom::UserAccessManagerRequest request) { | 208 mojom::UserAccessManagerRequest request) { |
| 209 window_server_->user_id_tracker()->Bind(std::move(request)); | 209 window_server_->user_id_tracker()->Bind(std::move(request)); |
| 210 } | 210 } |
| 211 | 211 |
| 212 void MandolineUIServicesApp::Create( | 212 void MandolineUIServicesApp::Create( |
| 213 mojo::Connection* connection, | 213 shell::Connection* connection, |
| 214 mojom::WindowManagerFactoryServiceRequest request) { | 214 mojom::WindowManagerFactoryServiceRequest request) { |
| 215 AddUserIfNecessary(connection); | 215 AddUserIfNecessary(connection); |
| 216 window_server_->window_manager_factory_registry()->Register( | 216 window_server_->window_manager_factory_registry()->Register( |
| 217 connection->GetRemoteIdentity().user_id(), std::move(request)); | 217 connection->GetRemoteIdentity().user_id(), std::move(request)); |
| 218 } | 218 } |
| 219 | 219 |
| 220 void MandolineUIServicesApp::Create(Connection* connection, | 220 void MandolineUIServicesApp::Create(Connection* connection, |
| 221 mojom::WindowTreeFactoryRequest request) { | 221 mojom::WindowTreeFactoryRequest request) { |
| 222 AddUserIfNecessary(connection); | 222 AddUserIfNecessary(connection); |
| 223 if (!window_server_->display_manager()->has_displays()) { | 223 if (!window_server_->display_manager()->has_displays()) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 243 mojom::WindowTreeHostFactoryRequest request) { | 243 mojom::WindowTreeHostFactoryRequest request) { |
| 244 UserState* user_state = GetUserState(connection); | 244 UserState* user_state = GetUserState(connection); |
| 245 if (!user_state->window_tree_host_factory) { | 245 if (!user_state->window_tree_host_factory) { |
| 246 user_state->window_tree_host_factory.reset(new ws::WindowTreeHostFactory( | 246 user_state->window_tree_host_factory.reset(new ws::WindowTreeHostFactory( |
| 247 window_server_.get(), connection->GetRemoteIdentity().user_id(), | 247 window_server_.get(), connection->GetRemoteIdentity().user_id(), |
| 248 platform_display_init_params_)); | 248 platform_display_init_params_)); |
| 249 } | 249 } |
| 250 user_state->window_tree_host_factory->AddBinding(std::move(request)); | 250 user_state->window_tree_host_factory->AddBinding(std::move(request)); |
| 251 } | 251 } |
| 252 | 252 |
| 253 void MandolineUIServicesApp::Create(mojo::Connection* connection, | 253 void MandolineUIServicesApp::Create(shell::Connection* connection, |
| 254 mojom::GpuRequest request) { | 254 mojom::GpuRequest request) { |
| 255 DCHECK(platform_display_init_params_.gpu_state); | 255 DCHECK(platform_display_init_params_.gpu_state); |
| 256 new GpuImpl(std::move(request), platform_display_init_params_.gpu_state); | 256 new GpuImpl(std::move(request), platform_display_init_params_.gpu_state); |
| 257 } | 257 } |
| 258 | 258 |
| 259 } // namespace mus | 259 } // namespace mus |
| OLD | NEW |