OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "content/browser/service_manager/service_manager_context.h" | 5 #include "content/browser/service_manager/service_manager_context.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
17 #include "content/browser/gpu/gpu_process_host.h" | 17 #include "content/browser/gpu/gpu_process_host.h" |
18 #include "content/browser/service_manager/merge_dictionary.h" | 18 #include "content/browser/service_manager/merge_dictionary.h" |
19 #include "content/common/mojo/mojo_shell_connection_impl.h" | 19 #include "content/common/service_manager/service_manager_connection_impl.h" |
20 #include "content/grit/content_resources.h" | 20 #include "content/grit/content_resources.h" |
21 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
22 #include "content/public/browser/content_browser_client.h" | 22 #include "content/public/browser/content_browser_client.h" |
23 #include "content/public/browser/utility_process_host.h" | 23 #include "content/public/browser/utility_process_host.h" |
24 #include "content/public/browser/utility_process_host_client.h" | 24 #include "content/public/browser/utility_process_host_client.h" |
25 #include "content/public/common/content_client.h" | 25 #include "content/public/common/content_client.h" |
26 #include "content/public/common/mojo_shell_connection.h" | 26 #include "content/public/common/service_manager_connection.h" |
27 #include "content/public/common/service_names.h" | 27 #include "content/public/common/service_names.h" |
28 #include "mojo/edk/embedder/embedder.h" | 28 #include "mojo/edk/embedder/embedder.h" |
29 #include "services/catalog/catalog.h" | 29 #include "services/catalog/catalog.h" |
30 #include "services/catalog/manifest_provider.h" | 30 #include "services/catalog/manifest_provider.h" |
31 #include "services/catalog/store.h" | 31 #include "services/catalog/store.h" |
32 #include "services/file/public/cpp/constants.h" | 32 #include "services/file/public/cpp/constants.h" |
33 #include "services/shell/connect_params.h" | 33 #include "services/shell/connect_params.h" |
34 #include "services/shell/native_runner.h" | 34 #include "services/shell/native_runner.h" |
35 #include "services/shell/public/cpp/connector.h" | 35 #include "services/shell/public/cpp/connector.h" |
36 #include "services/shell/public/cpp/service.h" | 36 #include "services/shell/public/cpp/service.h" |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 | 170 |
171 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool(); | 171 base::SequencedWorkerPool* blocking_pool = BrowserThread::GetBlockingPool(); |
172 std::unique_ptr<shell::NativeRunnerFactory> native_runner_factory( | 172 std::unique_ptr<shell::NativeRunnerFactory> native_runner_factory( |
173 new shell::InProcessNativeRunnerFactory(blocking_pool)); | 173 new shell::InProcessNativeRunnerFactory(blocking_pool)); |
174 catalog_.reset( | 174 catalog_.reset( |
175 new catalog::Catalog(blocking_pool, nullptr, manifest_provider_.get())); | 175 new catalog::Catalog(blocking_pool, nullptr, manifest_provider_.get())); |
176 service_manager_.reset(new shell::ServiceManager( | 176 service_manager_.reset(new shell::ServiceManager( |
177 std::move(native_runner_factory), catalog_->TakeService())); | 177 std::move(native_runner_factory), catalog_->TakeService())); |
178 | 178 |
179 shell::mojom::ServiceRequest request = | 179 shell::mojom::ServiceRequest request = |
180 service_manager_->StartEmbedderService(kBrowserMojoApplicationName); | 180 service_manager_->StartEmbedderService(kBrowserServiceName); |
181 mojo::FuseInterface( | 181 mojo::FuseInterface( |
182 std::move(request), std::move(embedder_service_proxy_info)); | 182 std::move(request), std::move(embedder_service_proxy_info)); |
183 } | 183 } |
184 | 184 |
185 void ShutDownOnIOThread() { | 185 void ShutDownOnIOThread() { |
186 service_manager_.reset(); | 186 service_manager_.reset(); |
187 catalog_.reset(); | 187 catalog_.reset(); |
188 manifest_provider_.reset(); | 188 manifest_provider_.reset(); |
189 } | 189 } |
190 | 190 |
(...skipping 10 matching lines...) Expand all Loading... |
201 mojo::edk::SetParentPipeHandleFromCommandLine(); | 201 mojo::edk::SetParentPipeHandleFromCommandLine(); |
202 request = shell::GetServiceRequestFromCommandLine(); | 202 request = shell::GetServiceRequestFromCommandLine(); |
203 } else { | 203 } else { |
204 std::unique_ptr<BuiltinManifestProvider> manifest_provider = | 204 std::unique_ptr<BuiltinManifestProvider> manifest_provider = |
205 base::MakeUnique<BuiltinManifestProvider>(); | 205 base::MakeUnique<BuiltinManifestProvider>(); |
206 | 206 |
207 static const struct ManifestInfo { | 207 static const struct ManifestInfo { |
208 const char* name; | 208 const char* name; |
209 int resource_id; | 209 int resource_id; |
210 } kManifests[] = { | 210 } kManifests[] = { |
211 { kBrowserMojoApplicationName, IDR_MOJO_CONTENT_BROWSER_MANIFEST }, | 211 { kBrowserServiceName, IDR_MOJO_CONTENT_BROWSER_MANIFEST }, |
212 { kGpuMojoApplicationName, IDR_MOJO_CONTENT_GPU_MANIFEST }, | 212 { kGpuServiceName, IDR_MOJO_CONTENT_GPU_MANIFEST }, |
213 { kPluginMojoApplicationName, IDR_MOJO_CONTENT_PLUGIN_MANIFEST }, | 213 { kPluginServiceName, IDR_MOJO_CONTENT_PLUGIN_MANIFEST }, |
214 { kRendererMojoApplicationName, IDR_MOJO_CONTENT_RENDERER_MANIFEST }, | 214 { kRendererServiceName, IDR_MOJO_CONTENT_RENDERER_MANIFEST }, |
215 { kUtilityMojoApplicationName, IDR_MOJO_CONTENT_UTILITY_MANIFEST }, | 215 { kUtilityServiceName, IDR_MOJO_CONTENT_UTILITY_MANIFEST }, |
216 { "service:catalog", IDR_MOJO_CATALOG_MANIFEST }, | 216 { "service:catalog", IDR_MOJO_CATALOG_MANIFEST }, |
217 { file::kFileServiceName, IDR_MOJO_FILE_MANIFEST } | 217 { file::kFileServiceName, IDR_MOJO_FILE_MANIFEST } |
218 }; | 218 }; |
219 | 219 |
220 for (size_t i = 0; i < arraysize(kManifests); ++i) { | 220 for (size_t i = 0; i < arraysize(kManifests); ++i) { |
221 std::string contents = GetContentClient()->GetDataResource( | 221 std::string contents = GetContentClient()->GetDataResource( |
222 kManifests[i].resource_id, | 222 kManifests[i].resource_id, |
223 ui::ScaleFactor::SCALE_FACTOR_NONE).as_string(); | 223 ui::ScaleFactor::SCALE_FACTOR_NONE).as_string(); |
224 DCHECK(!contents.empty()); | 224 DCHECK(!contents.empty()); |
225 std::unique_ptr<base::Value> manifest_value = | 225 std::unique_ptr<base::Value> manifest_value = |
226 base::JSONReader::Read(contents); | 226 base::JSONReader::Read(contents); |
227 std::unique_ptr<base::Value> overlay_value = | 227 std::unique_ptr<base::Value> overlay_value = |
228 GetContentClient()->browser()->GetServiceManifestOverlay( | 228 GetContentClient()->browser()->GetServiceManifestOverlay( |
229 kManifests[i].name); | 229 kManifests[i].name); |
230 if (overlay_value) { | 230 if (overlay_value) { |
231 base::DictionaryValue* manifest_dictionary = nullptr; | 231 base::DictionaryValue* manifest_dictionary = nullptr; |
232 CHECK(manifest_value->GetAsDictionary(&manifest_dictionary)); | 232 CHECK(manifest_value->GetAsDictionary(&manifest_dictionary)); |
233 base::DictionaryValue* overlay_dictionary = nullptr; | 233 base::DictionaryValue* overlay_dictionary = nullptr; |
234 CHECK(overlay_value->GetAsDictionary(&overlay_dictionary)); | 234 CHECK(overlay_value->GetAsDictionary(&overlay_dictionary)); |
235 MergeDictionary(manifest_dictionary, overlay_dictionary); | 235 MergeDictionary(manifest_dictionary, overlay_dictionary); |
236 } | 236 } |
237 manifest_provider->AddManifestValue(kManifests[i].name, | 237 manifest_provider->AddManifestValue(kManifests[i].name, |
238 std::move(manifest_value)); | 238 std::move(manifest_value)); |
239 } | 239 } |
240 in_process_context_ = new InProcessServiceManagerContext; | 240 in_process_context_ = new InProcessServiceManagerContext; |
241 request = in_process_context_->Start(std::move(manifest_provider)); | 241 request = in_process_context_->Start(std::move(manifest_provider)); |
242 } | 242 } |
243 MojoShellConnection::SetForProcess(MojoShellConnection::Create( | 243 ServiceManagerConnection::SetForProcess(ServiceManagerConnection::Create( |
244 std::move(request), | 244 std::move(request), |
245 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))); | 245 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))); |
246 | 246 |
247 ContentBrowserClient::StaticMojoApplicationMap apps; | 247 ContentBrowserClient::StaticServiceMap services; |
248 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); | 248 GetContentClient()->browser()->RegisterInProcessServices(&services); |
249 for (const auto& entry : apps) { | 249 for (const auto& entry : services) { |
250 MojoShellConnection::GetForProcess()->AddEmbeddedService(entry.first, | 250 ServiceManagerConnection::GetForProcess()->AddEmbeddedService(entry.first, |
251 entry.second); | 251 entry.second); |
252 } | 252 } |
253 | 253 |
254 // This is safe to assign directly from any thread, because | 254 // This is safe to assign directly from any thread, because |
255 // ServiceManagerContext must be constructed before anyone can call | 255 // ServiceManagerContext must be constructed before anyone can call |
256 // GetConnectorForIOThread(). | 256 // GetConnectorForIOThread(). |
257 g_io_thread_connector.Get() = | 257 g_io_thread_connector.Get() = |
258 MojoShellConnection::GetForProcess()->GetConnector()->Clone(); | 258 ServiceManagerConnection::GetForProcess()->GetConnector()->Clone(); |
259 | 259 |
260 MojoShellConnection::GetForProcess()->Start(); | 260 ServiceManagerConnection::GetForProcess()->Start(); |
261 | 261 |
262 ContentBrowserClient::OutOfProcessMojoApplicationMap sandboxed_apps; | 262 ContentBrowserClient::OutOfProcessServiceMap sandboxed_services; |
263 GetContentClient() | 263 GetContentClient() |
264 ->browser() | 264 ->browser() |
265 ->RegisterOutOfProcessMojoApplications(&sandboxed_apps); | 265 ->RegisterOutOfProcessServices(&sandboxed_services); |
266 for (const auto& app : sandboxed_apps) { | 266 for (const auto& service : sandboxed_services) { |
267 MojoShellConnection::GetForProcess()->AddServiceRequestHandler( | 267 ServiceManagerConnection::GetForProcess()->AddServiceRequestHandler( |
268 app.first, | 268 service.first, |
269 base::Bind(&StartServiceInUtilityProcess, app.first, app.second, | 269 base::Bind(&StartServiceInUtilityProcess, service.first, service.second, |
270 true /* use_sandbox */)); | 270 true /* use_sandbox */)); |
271 } | 271 } |
272 | 272 |
273 ContentBrowserClient::OutOfProcessMojoApplicationMap unsandboxed_apps; | 273 ContentBrowserClient::OutOfProcessServiceMap unsandboxed_services; |
274 GetContentClient() | 274 GetContentClient() |
275 ->browser() | 275 ->browser() |
276 ->RegisterUnsandboxedOutOfProcessMojoApplications(&unsandboxed_apps); | 276 ->RegisterUnsandboxedOutOfProcessServices(&unsandboxed_services); |
277 for (const auto& app : unsandboxed_apps) { | 277 for (const auto& service : unsandboxed_services) { |
278 MojoShellConnection::GetForProcess()->AddServiceRequestHandler( | 278 ServiceManagerConnection::GetForProcess()->AddServiceRequestHandler( |
279 app.first, | 279 service.first, |
280 base::Bind(&StartServiceInUtilityProcess, app.first, app.second, | 280 base::Bind(&StartServiceInUtilityProcess, service.first, service.second, |
281 false /* use_sandbox */)); | 281 false /* use_sandbox */)); |
282 } | 282 } |
283 | 283 |
284 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) | 284 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) |
285 MojoShellConnection::GetForProcess()->AddServiceRequestHandler( | 285 ServiceManagerConnection::GetForProcess()->AddServiceRequestHandler( |
286 "service:media", base::Bind(&StartServiceInGpuProcess, "service:media")); | 286 "service:media", base::Bind(&StartServiceInGpuProcess, "service:media")); |
287 #endif | 287 #endif |
288 } | 288 } |
289 | 289 |
290 ServiceManagerContext::~ServiceManagerContext() { | 290 ServiceManagerContext::~ServiceManagerContext() { |
291 // NOTE: The in-process ServiceManager MUST be destroyed before the browser | 291 // NOTE: The in-process ServiceManager MUST be destroyed before the browser |
292 // process-wide MojoShellConnection. Otherwise it's possible for the | 292 // process-wide ServiceManagerConnection. Otherwise it's possible for the |
293 // ServiceManager to receive connection requests for service:content_browser | 293 // ServiceManager to receive connection requests for service:content_browser |
294 // which it may attempt to service by launching a new instance of the browser. | 294 // which it may attempt to service by launching a new instance of the browser. |
295 if (in_process_context_) | 295 if (in_process_context_) |
296 in_process_context_->ShutDown(); | 296 in_process_context_->ShutDown(); |
297 if (MojoShellConnection::GetForProcess()) | 297 if (ServiceManagerConnection::GetForProcess()) |
298 MojoShellConnection::DestroyForProcess(); | 298 ServiceManagerConnection::DestroyForProcess(); |
299 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, | 299 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, |
300 base::Bind(&DestroyConnectorOnIOThread)); | 300 base::Bind(&DestroyConnectorOnIOThread)); |
301 } | 301 } |
302 | 302 |
303 // static | 303 // static |
304 shell::Connector* ServiceManagerContext::GetConnectorForIOThread() { | 304 shell::Connector* ServiceManagerContext::GetConnectorForIOThread() { |
305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
306 return g_io_thread_connector.Get().get(); | 306 return g_io_thread_connector.Get().get(); |
307 } | 307 } |
308 | 308 |
309 } // namespace content | 309 } // namespace content |
OLD | NEW |