OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/chromeos/chrome_interface_factory.h" | 5 #include "chrome/browser/chromeos/chrome_interface_factory.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "ash/common/mojo_interface_factory.h" | 9 #include "ash/common/mojo_interface_factory.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/memory/ptr_util.h" |
11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
12 #include "base/threading/thread_checker.h" | 13 #include "base/threading/thread_checker.h" |
13 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
14 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" | 15 #include "chrome/browser/chromeos/login/users/wallpaper/wallpaper_manager.h" |
15 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
17 #include "chrome/browser/ui/ash/app_list/app_list_presenter_service.h" | 18 #include "chrome/browser/ui/ash/app_list/app_list_presenter_service.h" |
18 #include "chrome/browser/ui/ash/ash_util.h" | 19 #include "chrome/browser/ui/ash/ash_util.h" |
19 #include "chrome/browser/ui/ash/keyboard_ui_service.h" | 20 #include "chrome/browser/ui/ash/keyboard_ui_service.h" |
20 #include "chrome/browser/ui/ash/system_tray_client.h" | 21 #include "chrome/browser/ui/ash/system_tray_client.h" |
| 22 #include "chrome/browser/ui/ash/volume_controller_chromeos.h" |
21 #include "chrome/browser/ui/browser_commands.h" | 23 #include "chrome/browser/ui/browser_commands.h" |
22 #include "chrome/browser/ui/browser_finder.h" | 24 #include "chrome/browser/ui/browser_finder.h" |
23 #include "content/public/common/service_manager_connection.h" | 25 #include "content/public/common/service_manager_connection.h" |
24 #include "mash/public/interfaces/launchable.mojom.h" | 26 #include "mash/public/interfaces/launchable.mojom.h" |
25 #include "mojo/public/cpp/bindings/binding_set.h" | 27 #include "mojo/public/cpp/bindings/binding_set.h" |
26 #include "services/service_manager/public/cpp/connection.h" | 28 #include "services/service_manager/public/cpp/connection.h" |
27 #include "services/service_manager/public/cpp/interface_registry.h" | 29 #include "services/service_manager/public/cpp/interface_registry.h" |
28 #include "ui/app_list/presenter/app_list_presenter.mojom.h" | 30 #include "ui/app_list/presenter/app_list_presenter.mojom.h" |
29 #include "ui/keyboard/keyboard.mojom.h" | 31 #include "ui/keyboard/keyboard.mojom.h" |
30 | 32 |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 service_manager::InterfaceRegistry* registry, | 88 service_manager::InterfaceRegistry* registry, |
87 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | 89 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
88 registry->AddInterface<Interface>( | 90 registry->AddInterface<Interface>( |
89 base::Bind(&FactoryImpl::CallMainThreadFactory<Interface>), | 91 base::Bind(&FactoryImpl::CallMainThreadFactory<Interface>), |
90 task_runner); | 92 task_runner); |
91 } | 93 } |
92 | 94 |
93 private: | 95 private: |
94 static FactoryImpl* Get() { | 96 static FactoryImpl* Get() { |
95 if (!factory_.Get()) | 97 if (!factory_.Get()) |
96 factory_.Get().reset(new FactoryImpl); | 98 factory_.Get() = base::MakeUnique<FactoryImpl>(); |
97 return factory_.Get().get(); | 99 return factory_.Get().get(); |
98 } | 100 } |
99 | 101 |
100 template <typename Interface> | 102 template <typename Interface> |
101 static void CallMainThreadFactory(mojo::InterfaceRequest<Interface> request) { | 103 static void CallMainThreadFactory(mojo::InterfaceRequest<Interface> request) { |
102 Get()->BindRequest(std::move(request)); | 104 Get()->BindRequest(std::move(request)); |
103 } | 105 } |
104 | 106 |
105 void BindRequest(keyboard::mojom::KeyboardRequest request) { | 107 void BindRequest(keyboard::mojom::KeyboardRequest request) { |
106 if (!keyboard_ui_service_) | 108 if (!keyboard_ui_service_) |
107 keyboard_ui_service_.reset(new KeyboardUIService); | 109 keyboard_ui_service_ = base::MakeUnique<KeyboardUIService>(); |
108 keyboard_bindings_.AddBinding(keyboard_ui_service_.get(), | 110 keyboard_bindings_.AddBinding(keyboard_ui_service_.get(), |
109 std::move(request)); | 111 std::move(request)); |
110 } | 112 } |
111 | 113 |
112 void BindRequest(mash::mojom::LaunchableRequest request) { | 114 void BindRequest(mash::mojom::LaunchableRequest request) { |
113 if (!launchable_) | 115 if (!launchable_) |
114 launchable_.reset(new ChromeLaunchable); | 116 launchable_ = base::MakeUnique<ChromeLaunchable>(); |
115 launchable_->ProcessRequest(std::move(request)); | 117 launchable_->ProcessRequest(std::move(request)); |
116 } | 118 } |
117 | 119 |
118 void BindRequest(ash::mojom::SystemTrayClientRequest request) { | 120 void BindRequest(ash::mojom::SystemTrayClientRequest request) { |
119 system_tray_client_bindings_.AddBinding(SystemTrayClient::Get(), | 121 system_tray_client_bindings_.AddBinding(SystemTrayClient::Get(), |
120 std::move(request)); | 122 std::move(request)); |
121 } | 123 } |
122 | 124 |
123 void BindRequest(ash::mojom::WallpaperManagerRequest request) { | 125 void BindRequest(ash::mojom::WallpaperManagerRequest request) { |
124 WallpaperManager::Get()->BindRequest(std::move(request)); | 126 WallpaperManager::Get()->BindRequest(std::move(request)); |
125 } | 127 } |
126 | 128 |
| 129 void BindRequest(ash::mojom::VolumeControllerRequest request) { |
| 130 if (!volume_controller_) |
| 131 volume_controller_ = base::MakeUnique<VolumeController>(); |
| 132 volume_controller_->BindRequest(std::move(request)); |
| 133 } |
| 134 |
127 void BindRequest(app_list::mojom::AppListPresenterRequest request) { | 135 void BindRequest(app_list::mojom::AppListPresenterRequest request) { |
128 if (!app_list_presenter_service_) | 136 if (!app_list_presenter_service_) |
129 app_list_presenter_service_.reset(new AppListPresenterService); | 137 app_list_presenter_service_ = base::MakeUnique<AppListPresenterService>(); |
130 app_list_presenter_bindings_.AddBinding(app_list_presenter_service_.get(), | 138 app_list_presenter_bindings_.AddBinding(app_list_presenter_service_.get(), |
131 std::move(request)); | 139 std::move(request)); |
132 } | 140 } |
133 | 141 |
134 static base::LazyInstance<std::unique_ptr<FactoryImpl>>::Leaky factory_; | 142 static base::LazyInstance<std::unique_ptr<FactoryImpl>>::Leaky factory_; |
135 | 143 |
136 std::unique_ptr<KeyboardUIService> keyboard_ui_service_; | 144 std::unique_ptr<KeyboardUIService> keyboard_ui_service_; |
137 mojo::BindingSet<keyboard::mojom::Keyboard> keyboard_bindings_; | 145 mojo::BindingSet<keyboard::mojom::Keyboard> keyboard_bindings_; |
138 std::unique_ptr<ChromeLaunchable> launchable_; | 146 std::unique_ptr<ChromeLaunchable> launchable_; |
139 mojo::BindingSet<ash::mojom::SystemTrayClient> system_tray_client_bindings_; | 147 mojo::BindingSet<ash::mojom::SystemTrayClient> system_tray_client_bindings_; |
| 148 std::unique_ptr<VolumeController> volume_controller_; |
140 std::unique_ptr<AppListPresenterService> app_list_presenter_service_; | 149 std::unique_ptr<AppListPresenterService> app_list_presenter_service_; |
141 mojo::BindingSet<app_list::mojom::AppListPresenter> | 150 mojo::BindingSet<app_list::mojom::AppListPresenter> |
142 app_list_presenter_bindings_; | 151 app_list_presenter_bindings_; |
143 | 152 |
144 DISALLOW_COPY_AND_ASSIGN(FactoryImpl); | 153 DISALLOW_COPY_AND_ASSIGN(FactoryImpl); |
145 }; | 154 }; |
146 | 155 |
147 base::LazyInstance<std::unique_ptr<FactoryImpl>>::Leaky FactoryImpl::factory_ = | 156 base::LazyInstance<std::unique_ptr<FactoryImpl>>::Leaky FactoryImpl::factory_ = |
148 LAZY_INSTANCE_INITIALIZER; | 157 LAZY_INSTANCE_INITIALIZER; |
149 | 158 |
150 } // namespace | 159 } // namespace |
151 | 160 |
152 ChromeInterfaceFactory::ChromeInterfaceFactory() | 161 ChromeInterfaceFactory::ChromeInterfaceFactory() |
153 : main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()) {} | 162 : main_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()) {} |
154 | 163 |
155 ChromeInterfaceFactory::~ChromeInterfaceFactory() {} | 164 ChromeInterfaceFactory::~ChromeInterfaceFactory() {} |
156 | 165 |
157 bool ChromeInterfaceFactory::OnConnect( | 166 bool ChromeInterfaceFactory::OnConnect( |
158 const service_manager::Identity& remote_identity, | 167 const service_manager::Identity& remote_identity, |
159 service_manager::InterfaceRegistry* registry, | 168 service_manager::InterfaceRegistry* registry, |
160 service_manager::Connector* connector) { | 169 service_manager::Connector* connector) { |
161 FactoryImpl::AddFactory<keyboard::mojom::Keyboard>(registry, | 170 FactoryImpl::AddFactory<keyboard::mojom::Keyboard>(registry, |
162 main_thread_task_runner_); | 171 main_thread_task_runner_); |
163 FactoryImpl::AddFactory<mash::mojom::Launchable>(registry, | 172 FactoryImpl::AddFactory<mash::mojom::Launchable>(registry, |
164 main_thread_task_runner_); | 173 main_thread_task_runner_); |
165 FactoryImpl::AddFactory<ash::mojom::SystemTrayClient>( | 174 FactoryImpl::AddFactory<ash::mojom::SystemTrayClient>( |
166 registry, main_thread_task_runner_); | 175 registry, main_thread_task_runner_); |
| 176 FactoryImpl::AddFactory<ash::mojom::VolumeController>( |
| 177 registry, main_thread_task_runner_); |
167 FactoryImpl::AddFactory<ash::mojom::WallpaperManager>( | 178 FactoryImpl::AddFactory<ash::mojom::WallpaperManager>( |
168 registry, main_thread_task_runner_); | 179 registry, main_thread_task_runner_); |
169 FactoryImpl::AddFactory<app_list::mojom::AppListPresenter>( | 180 FactoryImpl::AddFactory<app_list::mojom::AppListPresenter>( |
170 registry, main_thread_task_runner_); | 181 registry, main_thread_task_runner_); |
171 | 182 |
172 // In classic ash, the browser process provides ash services to itself. | 183 // In classic ash, the browser process provides ash services to itself. |
173 if (!chrome::IsRunningInMash()) { | 184 if (!chrome::IsRunningInMash()) { |
174 ash::mojo_interface_factory::RegisterInterfaces(registry, | 185 ash::mojo_interface_factory::RegisterInterfaces(registry, |
175 main_thread_task_runner_); | 186 main_thread_task_runner_); |
176 } | 187 } |
177 | 188 |
178 return true; | 189 return true; |
179 } | 190 } |
180 | 191 |
181 } // namespace chromeos | 192 } // namespace chromeos |
OLD | NEW |