Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(803)

Side by Side Diff: content/browser/service_manager/service_manager_context.cc

Issue 2387263002: Rename MojoShellContext -> ServiceManagerContext. (Closed)
Patch Set: . Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/mojo/mojo_shell_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/mojo/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/mojo/mojo_shell_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/mojo_shell_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"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 125 }
126 126
127 std::map<std::string, std::unique_ptr<base::Value>> manifests_; 127 std::map<std::string, std::unique_ptr<base::Value>> manifests_;
128 128
129 DISALLOW_COPY_AND_ASSIGN(BuiltinManifestProvider); 129 DISALLOW_COPY_AND_ASSIGN(BuiltinManifestProvider);
130 }; 130 };
131 131
132 } // namespace 132 } // namespace
133 133
134 // State which lives on the IO thread and drives the ServiceManager. 134 // State which lives on the IO thread and drives the ServiceManager.
135 class MojoShellContext::InProcessServiceManagerContext 135 class ServiceManagerContext::InProcessServiceManagerContext
136 : public base::RefCountedThreadSafe<InProcessServiceManagerContext> { 136 : public base::RefCountedThreadSafe<InProcessServiceManagerContext> {
137 public: 137 public:
138 InProcessServiceManagerContext() {} 138 InProcessServiceManagerContext() {}
139 139
140 shell::mojom::ServiceRequest Start( 140 shell::mojom::ServiceRequest Start(
141 std::unique_ptr<BuiltinManifestProvider> manifest_provider) { 141 std::unique_ptr<BuiltinManifestProvider> manifest_provider) {
142 shell::mojom::ServicePtr embedder_service_proxy; 142 shell::mojom::ServicePtr embedder_service_proxy;
143 shell::mojom::ServiceRequest embedder_service_request = 143 shell::mojom::ServiceRequest embedder_service_request =
144 mojo::GetProxy(&embedder_service_proxy); 144 mojo::GetProxy(&embedder_service_proxy);
145 shell::mojom::ServicePtrInfo embedder_service_proxy_info = 145 shell::mojom::ServicePtrInfo embedder_service_proxy_info =
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 manifest_provider_.reset(); 188 manifest_provider_.reset();
189 } 189 }
190 190
191 std::unique_ptr<BuiltinManifestProvider> manifest_provider_; 191 std::unique_ptr<BuiltinManifestProvider> manifest_provider_;
192 std::unique_ptr<catalog::Catalog> catalog_; 192 std::unique_ptr<catalog::Catalog> catalog_;
193 std::unique_ptr<shell::ServiceManager> service_manager_; 193 std::unique_ptr<shell::ServiceManager> service_manager_;
194 194
195 DISALLOW_COPY_AND_ASSIGN(InProcessServiceManagerContext); 195 DISALLOW_COPY_AND_ASSIGN(InProcessServiceManagerContext);
196 }; 196 };
197 197
198 MojoShellContext::MojoShellContext() { 198 ServiceManagerContext::ServiceManagerContext() {
199 shell::mojom::ServiceRequest request; 199 shell::mojom::ServiceRequest request;
200 if (shell::ShellIsRemote()) { 200 if (shell::ShellIsRemote()) {
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;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::StaticMojoApplicationMap apps;
248 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); 248 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps);
249 for (const auto& entry : apps) { 249 for (const auto& entry : apps) {
250 MojoShellConnection::GetForProcess()->AddEmbeddedService(entry.first, 250 MojoShellConnection::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 MojoShellContext 254 // This is safe to assign directly from any thread, because
255 // must be constructed before anyone can call GetConnectorForIOThread(). 255 // ServiceManagerContext must be constructed before anyone can call
256 // GetConnectorForIOThread().
256 g_io_thread_connector.Get() = 257 g_io_thread_connector.Get() =
257 MojoShellConnection::GetForProcess()->GetConnector()->Clone(); 258 MojoShellConnection::GetForProcess()->GetConnector()->Clone();
258 259
259 MojoShellConnection::GetForProcess()->Start(); 260 MojoShellConnection::GetForProcess()->Start();
260 261
261 ContentBrowserClient::OutOfProcessMojoApplicationMap sandboxed_apps; 262 ContentBrowserClient::OutOfProcessMojoApplicationMap sandboxed_apps;
262 GetContentClient() 263 GetContentClient()
263 ->browser() 264 ->browser()
264 ->RegisterOutOfProcessMojoApplications(&sandboxed_apps); 265 ->RegisterOutOfProcessMojoApplications(&sandboxed_apps);
265 for (const auto& app : sandboxed_apps) { 266 for (const auto& app : sandboxed_apps) {
(...skipping 13 matching lines...) Expand all
279 base::Bind(&StartServiceInUtilityProcess, app.first, app.second, 280 base::Bind(&StartServiceInUtilityProcess, app.first, app.second,
280 false /* use_sandbox */)); 281 false /* use_sandbox */));
281 } 282 }
282 283
283 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) 284 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS)
284 MojoShellConnection::GetForProcess()->AddServiceRequestHandler( 285 MojoShellConnection::GetForProcess()->AddServiceRequestHandler(
285 "service:media", base::Bind(&StartServiceInGpuProcess, "service:media")); 286 "service:media", base::Bind(&StartServiceInGpuProcess, "service:media"));
286 #endif 287 #endif
287 } 288 }
288 289
289 MojoShellContext::~MojoShellContext() { 290 ServiceManagerContext::~ServiceManagerContext() {
290 // NOTE: The in-process ServiceManager MUST be destroyed before the browser 291 // NOTE: The in-process ServiceManager MUST be destroyed before the browser
291 // process-wide MojoShellConnection. Otherwise it's possible for the 292 // process-wide MojoShellConnection. Otherwise it's possible for the
292 // ServiceManager to receive connection requests for service:content_browser 293 // ServiceManager to receive connection requests for service:content_browser
293 // 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.
294 if (in_process_context_) 295 if (in_process_context_)
295 in_process_context_->ShutDown(); 296 in_process_context_->ShutDown();
296 if (MojoShellConnection::GetForProcess()) 297 if (MojoShellConnection::GetForProcess())
297 MojoShellConnection::DestroyForProcess(); 298 MojoShellConnection::DestroyForProcess();
298 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 299 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
299 base::Bind(&DestroyConnectorOnIOThread)); 300 base::Bind(&DestroyConnectorOnIOThread));
300 } 301 }
301 302
302 // static 303 // static
303 shell::Connector* MojoShellContext::GetConnectorForIOThread() { 304 shell::Connector* ServiceManagerContext::GetConnectorForIOThread() {
304 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 305 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
305 return g_io_thread_connector.Get().get(); 306 return g_io_thread_connector.Get().get();
306 } 307 }
307 308
308 } // namespace content 309 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698