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

Side by Side Diff: content/browser/mojo/service_manager_context_impl.cc

Issue 2163883005: WIP: Obtain Bootstrap from utility process Service (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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/mojo/service_manager_context_impl.h"
6 6
7 #include <unordered_map> 7 #include <unordered_map>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/lazy_instance.h" 12 #include "base/lazy_instance.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 process_control->LoadApplication(app_name, std::move(request), 121 process_control->LoadApplication(app_name, std::move(request),
122 base::Bind(&OnApplicationLoaded, app_name)); 122 base::Bind(&OnApplicationLoaded, app_name));
123 } 123 }
124 124
125 #endif // ENABLE_MOJO_MEDIA_IN_GPU_PROCESS 125 #endif // ENABLE_MOJO_MEDIA_IN_GPU_PROCESS
126 126
127 } // namespace 127 } // namespace
128 128
129 // A ManifestProvider which resolves application names to builtin manifest 129 // A ManifestProvider which resolves application names to builtin manifest
130 // resources for the catalog service to consume. 130 // resources for the catalog service to consume.
131 class MojoShellContext::BuiltinManifestProvider 131 class ServiceManagerContextImpl::BuiltinManifestProvider
132 : public catalog::ManifestProvider { 132 : public catalog::ManifestProvider {
133 public: 133 public:
134 BuiltinManifestProvider() {} 134 BuiltinManifestProvider() {}
135 ~BuiltinManifestProvider() override {} 135 ~BuiltinManifestProvider() override {}
136 136
137 void AddManifestResource(const std::string& name, int resource_id) { 137 void AddManifestResource(const std::string& name, int resource_id) {
138 auto result = manifest_resources_.insert( 138 auto result = manifest_resources_.insert(
139 std::make_pair(name, resource_id)); 139 std::make_pair(name, resource_id));
140 DCHECK(result.second); 140 DCHECK(result.second);
141 } 141 }
(...skipping 25 matching lines...) Expand all
167 return false; 167 return false;
168 } 168 }
169 169
170 std::unordered_map<std::string, int> manifest_resources_; 170 std::unordered_map<std::string, int> manifest_resources_;
171 std::unique_ptr<ContentBrowserClient::MojoApplicationManifestMap> manifests_; 171 std::unique_ptr<ContentBrowserClient::MojoApplicationManifestMap> manifests_;
172 172
173 DISALLOW_COPY_AND_ASSIGN(BuiltinManifestProvider); 173 DISALLOW_COPY_AND_ASSIGN(BuiltinManifestProvider);
174 }; 174 };
175 175
176 // Thread-safe proxy providing access to the shell context from any thread. 176 // Thread-safe proxy providing access to the shell context from any thread.
177 class MojoShellContext::Proxy { 177 class ServiceManagerContextImpl::Proxy {
178 public: 178 public:
179 Proxy(MojoShellContext* shell_context) 179 Proxy(ServiceManagerContextImpl* context)
180 : shell_context_(shell_context), 180 : context_(context),
181 task_runner_(base::ThreadTaskRunnerHandle::Get()) {} 181 task_runner_(base::ThreadTaskRunnerHandle::Get()) {}
182 182
183 ~Proxy() {} 183 ~Proxy() {}
184 184
185 void ConnectToApplication( 185 void ConnectToApplication(
186 const std::string& user_id, 186 const std::string& user_id,
187 const std::string& name, 187 const std::string& name,
188 const std::string& requestor_name, 188 const std::string& requestor_name,
189 shell::mojom::InterfaceProviderRequest request, 189 shell::mojom::InterfaceProviderRequest request,
190 shell::mojom::InterfaceProviderPtr exposed_services, 190 shell::mojom::InterfaceProviderPtr exposed_services,
191 const shell::mojom::Connector::ConnectCallback& callback) { 191 const shell::mojom::Connector::ConnectCallback& callback) {
192 if (task_runner_ == base::ThreadTaskRunnerHandle::Get()) { 192 if (task_runner_ == base::ThreadTaskRunnerHandle::Get()) {
193 if (shell_context_) { 193 if (context_) {
194 shell_context_->ConnectToApplicationOnOwnThread( 194 context_->ConnectToApplicationOnOwnThread(
195 user_id, name, requestor_name, std::move(request), 195 user_id, name, requestor_name, std::move(request),
196 std::move(exposed_services), callback); 196 std::move(exposed_services), callback);
197 } 197 }
198 } else { 198 } else {
199 // |shell_context_| outlives the main MessageLoop, so it's safe for it to 199 // |context_| outlives the main MessageLoop, so it's safe for it to
200 // be unretained here. 200 // be unretained here.
201 task_runner_->PostTask( 201 task_runner_->PostTask(
202 FROM_HERE, 202 FROM_HERE,
203 base::Bind(&MojoShellContext::ConnectToApplicationOnOwnThread, 203 base::Bind(&ServiceManagerContextImpl::ConnectToApplicationOnOwnThread ,
204 base::Unretained(shell_context_), user_id, name, 204 base::Unretained(context_), user_id, name,
205 requestor_name, base::Passed(&request), 205 requestor_name, base::Passed(&request),
206 base::Passed(&exposed_services), callback)); 206 base::Passed(&exposed_services), callback));
207 } 207 }
208 } 208 }
209 209
210 private: 210 private:
211 MojoShellContext* shell_context_; 211 ServiceManagerContextImpl* context_;
212 scoped_refptr<base::SingleThreadTaskRunner> task_runner_; 212 scoped_refptr<base::SingleThreadTaskRunner> task_runner_;
213 213
214 DISALLOW_COPY_AND_ASSIGN(Proxy); 214 DISALLOW_COPY_AND_ASSIGN(Proxy);
215 }; 215 };
216 216
217 // static 217 // static
218 base::LazyInstance<std::unique_ptr<MojoShellContext::Proxy>> 218 base::LazyInstance<std::unique_ptr<ServiceManagerContextImpl::Proxy>>
219 MojoShellContext::proxy_ = LAZY_INSTANCE_INITIALIZER; 219 ServiceManagerContextImpl::proxy_ = LAZY_INSTANCE_INITIALIZER;
220 220
221 MojoShellContext::MojoShellContext() { 221 ServiceManagerContextImpl::ServiceManagerContextImpl() {
222 proxy_.Get().reset(new Proxy(this)); 222 proxy_.Get().reset(new Proxy(this));
223 223
224 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner = 224 scoped_refptr<base::SingleThreadTaskRunner> file_task_runner =
225 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE); 225 BrowserThread::GetTaskRunnerForThread(BrowserThread::FILE);
226 std::unique_ptr<shell::NativeRunnerFactory> native_runner_factory( 226 std::unique_ptr<shell::NativeRunnerFactory> native_runner_factory(
227 new shell::InProcessNativeRunnerFactory( 227 new shell::InProcessNativeRunnerFactory(
228 BrowserThread::GetBlockingPool())); 228 BrowserThread::GetBlockingPool()));
229 229
230 // Allow the embedder to register additional Mojo application manifests 230 // Allow the embedder to register additional Mojo application manifests
231 // beyond the default ones below. 231 // beyond the default ones below.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 std::move(request), 266 std::move(request),
267 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO))); 267 BrowserThread::GetTaskRunnerForThread(BrowserThread::IO)));
268 268
269 ContentBrowserClient::StaticMojoApplicationMap apps; 269 ContentBrowserClient::StaticMojoApplicationMap apps;
270 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps); 270 GetContentClient()->browser()->RegisterInProcessMojoApplications(&apps);
271 for (const auto& entry : apps) { 271 for (const auto& entry : apps) {
272 MojoShellConnection::GetForProcess()->AddEmbeddedService(entry.first, 272 MojoShellConnection::GetForProcess()->AddEmbeddedService(entry.first,
273 entry.second); 273 entry.second);
274 } 274 }
275 275
276 // This is safe to assign directly from any thread, because MojoShellContext 276 // This is safe to assign directly from any thread, because
277 // must be constructed before anyone can call GetConnectorForIOThread(). 277 // ServiceManagerContextImpl must be constructed before anyone can call
278 // GetConnectorForIOThread().
278 g_io_thread_connector.Get() = 279 g_io_thread_connector.Get() =
279 MojoShellConnection::GetForProcess()->GetConnector()->Clone(); 280 MojoShellConnection::GetForProcess()->GetConnector()->Clone();
280 281
281 MojoShellConnection::GetForProcess()->Start(); 282 MojoShellConnection::GetForProcess()->Start();
282 283
283 ContentBrowserClient::OutOfProcessMojoApplicationMap sandboxed_apps; 284 ContentBrowserClient::OutOfProcessMojoApplicationMap sandboxed_apps;
284 GetContentClient() 285 GetContentClient()
285 ->browser() 286 ->browser()
286 ->RegisterOutOfProcessMojoApplications(&sandboxed_apps); 287 ->RegisterOutOfProcessMojoApplications(&sandboxed_apps);
287 for (const auto& app : sandboxed_apps) { 288 for (const auto& app : sandboxed_apps) {
(...skipping 13 matching lines...) Expand all
301 base::Bind(&LaunchAppInUtilityProcess, app.first, app.second, 302 base::Bind(&LaunchAppInUtilityProcess, app.first, app.second,
302 false /* use_sandbox */)); 303 false /* use_sandbox */));
303 } 304 }
304 305
305 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) 306 #if (ENABLE_MOJO_MEDIA_IN_GPU_PROCESS)
306 MojoShellConnection::GetForProcess()->AddServiceRequestHandler( 307 MojoShellConnection::GetForProcess()->AddServiceRequestHandler(
307 "mojo:media", base::Bind(&LaunchAppInGpuProcess, "mojo:media")); 308 "mojo:media", base::Bind(&LaunchAppInGpuProcess, "mojo:media"));
308 #endif 309 #endif
309 } 310 }
310 311
311 MojoShellContext::~MojoShellContext() { 312 ServiceManagerContextImpl::~ServiceManagerContextImpl() {
312 if (MojoShellConnection::GetForProcess()) 313 if (MojoShellConnection::GetForProcess())
313 MojoShellConnection::DestroyForProcess(); 314 MojoShellConnection::DestroyForProcess();
314 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 315 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
315 base::Bind(&DestroyConnectorOnIOThread)); 316 base::Bind(&DestroyConnectorOnIOThread));
316 catalog_.reset(); 317 catalog_.reset();
317 } 318 }
318 319
319 // static 320 // static
320 void MojoShellContext::ConnectToApplication( 321 void ServiceManagerContextImpl::ConnectToApplication(
321 const std::string& user_id, 322 const std::string& user_id,
322 const std::string& name, 323 const std::string& name,
323 const std::string& requestor_name, 324 const std::string& requestor_name,
324 shell::mojom::InterfaceProviderRequest request, 325 shell::mojom::InterfaceProviderRequest request,
325 shell::mojom::InterfaceProviderPtr exposed_services, 326 shell::mojom::InterfaceProviderPtr exposed_services,
326 const shell::mojom::Connector::ConnectCallback& callback) { 327 const shell::mojom::Connector::ConnectCallback& callback) {
327 proxy_.Get()->ConnectToApplication(user_id, name, requestor_name, 328 proxy_.Get()->ConnectToApplication(user_id, name, requestor_name,
328 std::move(request), 329 std::move(request),
329 std::move(exposed_services), callback); 330 std::move(exposed_services), callback);
330 } 331 }
331 332
332 // static 333 // static
333 shell::Connector* MojoShellContext::GetConnectorForIOThread() { 334 shell::Connector* ServiceManagerContextImpl::GetConnectorForIOThread() {
334 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 335 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
335 return g_io_thread_connector.Get().get(); 336 return g_io_thread_connector.Get().get();
336 } 337 }
337 338
338 void MojoShellContext::ConnectToApplicationOnOwnThread( 339 void ServiceManagerContextImpl::ConnectToApplicationOnOwnThread(
339 const std::string& user_id, 340 const std::string& user_id,
340 const std::string& name, 341 const std::string& name,
341 const std::string& requestor_name, 342 const std::string& requestor_name,
342 shell::mojom::InterfaceProviderRequest request, 343 shell::mojom::InterfaceProviderRequest request,
343 shell::mojom::InterfaceProviderPtr exposed_services, 344 shell::mojom::InterfaceProviderPtr exposed_services,
344 const shell::mojom::Connector::ConnectCallback& callback) { 345 const shell::mojom::Connector::ConnectCallback& callback) {
345 std::unique_ptr<shell::ConnectParams> params(new shell::ConnectParams); 346 std::unique_ptr<shell::ConnectParams> params(new shell::ConnectParams);
346 shell::Identity source_id(requestor_name, user_id); 347 shell::Identity source_id(requestor_name, user_id);
347 params->set_source(source_id); 348 params->set_source(source_id);
348 params->set_target(shell::Identity(name, user_id)); 349 params->set_target(shell::Identity(name, user_id));
349 params->set_remote_interfaces(std::move(request)); 350 params->set_remote_interfaces(std::move(request));
350 params->set_local_interfaces(std::move(exposed_services)); 351 params->set_local_interfaces(std::move(exposed_services));
351 params->set_connect_callback(callback); 352 params->set_connect_callback(callback);
352 service_manager_->Connect(std::move(params)); 353 service_manager_->Connect(std::move(params));
353 } 354 }
354 355
356 // static
357 std::unique_ptr<ServiceManagerContext> ServiceManagerContext::Create() {
358 return base::WrapUnique(new ServiceManagerContextImpl);
359 }
360
355 } // namespace content 361 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/mojo/service_manager_context_impl.h ('k') | content/browser/utility_process_host_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698