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

Side by Side Diff: content/common/mojo/mojo_shell_connection_impl.cc

Issue 2183703005: Renderers should obtain browser InterfaceProvider by connecting to browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 4 years, 4 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
« no previous file with comments | « content/common/mojo/mojo_shell_connection_impl.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "content/common/mojo/mojo_shell_connection_impl.h" 5 #include "content/common/mojo/mojo_shell_connection_impl.h"
6 6
7 #include <queue> 7 #include <queue>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // Start()). Must be called before IO thread shutdown. 77 // Start()). Must be called before IO thread shutdown.
78 void ShutDown() { 78 void ShutDown() {
79 if (!started_) 79 if (!started_)
80 return; 80 return;
81 81
82 bool posted = io_task_runner_->PostTask( 82 bool posted = io_task_runner_->PostTask(
83 FROM_HERE, base::Bind(&IOThreadContext::ShutDownOnIOThread, this)); 83 FROM_HERE, base::Bind(&IOThreadContext::ShutDownOnIOThread, this));
84 DCHECK(posted); 84 DCHECK(posted);
85 } 85 }
86 86
87 // Safe to call any time before Start() is called. 87 // Safe to call any time before a message is received from a process.
88 // i.e. can be called when starting the process but not afterwards.
88 void AddConnectionFilter(std::unique_ptr<ConnectionFilter> filter) { 89 void AddConnectionFilter(std::unique_ptr<ConnectionFilter> filter) {
89 DCHECK(!started_); 90 base::AutoLock lock(lock_);
90 connection_filters_.emplace_back(std::move(filter)); 91 connection_filters_.emplace_back(std::move(filter));
91 } 92 }
92 93
94 std::unique_ptr<ConnectionFilter> RemoveConnectionFilter(
95 ConnectionFilter* filter) {
96 base::AutoLock lock(lock_);
97 for (auto it = connection_filters_.begin(); it != connection_filters_.end();
98 ++it) {
99 if (it->get() == filter) {
100 std::unique_ptr<ConnectionFilter> taken = std::move(*it);
101 connection_filters_.erase(it);
102 return taken;
103 }
104 }
105 return nullptr;
106 }
107
93 // Safe to call any time before Start() is called. 108 // Safe to call any time before Start() is called.
94 void SetDefaultBinderForBrowserConnection( 109 void SetDefaultBinderForBrowserConnection(
95 const shell::InterfaceRegistry::Binder& binder) { 110 const shell::InterfaceRegistry::Binder& binder) {
96 DCHECK(!started_); 111 DCHECK(!started_);
97 default_browser_binder_ = base::Bind( 112 default_browser_binder_ = base::Bind(
98 &IOThreadContext::CallBinderOnTaskRunner, 113 &IOThreadContext::CallBinderOnTaskRunner,
99 base::ThreadTaskRunnerHandle::Get(), binder); 114 base::ThreadTaskRunnerHandle::Get(), binder);
100 } 115 }
101 116
102 // Safe to call any time after Start() is called. 117 // Safe to call any time after Start() is called.
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 // InterfaceRegistry. 293 // InterfaceRegistry.
279 // 294 //
280 // TODO(rockot): Remove this once all interfaces exposed to the browser are 295 // TODO(rockot): Remove this once all interfaces exposed to the browser are
281 // exposed via a ConnectionFilter. 296 // exposed via a ConnectionFilter.
282 shell::InterfaceRegistry::Binder default_browser_binder_; 297 shell::InterfaceRegistry::Binder default_browser_binder_;
283 298
284 std::unique_ptr<shell::ServiceContext> service_context_; 299 std::unique_ptr<shell::ServiceContext> service_context_;
285 mojo::BindingSet<shell::mojom::ServiceFactory> factory_bindings_; 300 mojo::BindingSet<shell::mojom::ServiceFactory> factory_bindings_;
286 std::vector<std::unique_ptr<ConnectionFilter>> connection_filters_; 301 std::vector<std::unique_ptr<ConnectionFilter>> connection_filters_;
287 302
303 base::Lock lock_;
304
288 DISALLOW_COPY_AND_ASSIGN(IOThreadContext); 305 DISALLOW_COPY_AND_ASSIGN(IOThreadContext);
289 }; 306 };
290 307
291 //////////////////////////////////////////////////////////////////////////////// 308 ////////////////////////////////////////////////////////////////////////////////
292 // MojoShellConnection, public: 309 // MojoShellConnection, public:
293 310
294 // static 311 // static
295 void MojoShellConnection::SetForProcess( 312 void MojoShellConnection::SetForProcess(
296 std::unique_ptr<MojoShellConnection> connection) { 313 std::unique_ptr<MojoShellConnection> connection) {
297 DCHECK(!g_connection_for_process.Get()); 314 DCHECK(!g_connection_for_process.Get());
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 398
382 void MojoShellConnectionImpl::SetupInterfaceRequestProxies( 399 void MojoShellConnectionImpl::SetupInterfaceRequestProxies(
383 shell::InterfaceRegistry* registry, 400 shell::InterfaceRegistry* registry,
384 shell::InterfaceProvider* provider) { 401 shell::InterfaceProvider* provider) {
385 // It's safe to bind |registry| as a raw pointer because the caller must 402 // It's safe to bind |registry| as a raw pointer because the caller must
386 // guarantee that it outlives |this|, and |this| is bound as a weak ptr here. 403 // guarantee that it outlives |this|, and |this| is bound as a weak ptr here.
387 context_->SetDefaultBinderForBrowserConnection( 404 context_->SetDefaultBinderForBrowserConnection(
388 base::Bind(&MojoShellConnectionImpl::GetInterface, 405 base::Bind(&MojoShellConnectionImpl::GetInterface,
389 weak_factory_.GetWeakPtr(), registry)); 406 weak_factory_.GetWeakPtr(), registry));
390 407
408 if (!provider)
409 return;
410
391 // Forward all remote interface requests on |provider| to our IO-thread 411 // Forward all remote interface requests on |provider| to our IO-thread
392 // context. This will ensure they're forwarded to the provider on the 412 // context. This will ensure they're forwarded to the provider on the
393 // incoming browser connection. 413 // incoming browser connection.
394 provider->Forward(base::Bind(&IOThreadContext::GetRemoteInterface, context_)); 414 provider->Forward(base::Bind(&IOThreadContext::GetRemoteInterface,
415 context_));
395 } 416 }
396 417
397 void MojoShellConnectionImpl::AddConnectionFilter( 418 void MojoShellConnectionImpl::AddConnectionFilter(
398 std::unique_ptr<ConnectionFilter> filter) { 419 std::unique_ptr<ConnectionFilter> filter) {
399 context_->AddConnectionFilter(std::move(filter)); 420 context_->AddConnectionFilter(std::move(filter));
400 } 421 }
401 422
423 std::unique_ptr<ConnectionFilter>
424 MojoShellConnectionImpl::RemoveConnectionFilter(ConnectionFilter* filter) {
425 return context_->RemoveConnectionFilter(filter);
426 }
427
402 void MojoShellConnectionImpl::AddEmbeddedService( 428 void MojoShellConnectionImpl::AddEmbeddedService(
403 const std::string& name, 429 const std::string& name,
404 const MojoApplicationInfo& info) { 430 const MojoApplicationInfo& info) {
405 std::unique_ptr<EmbeddedApplicationRunner> app( 431 std::unique_ptr<EmbeddedApplicationRunner> app(
406 new EmbeddedApplicationRunner(name, info)); 432 new EmbeddedApplicationRunner(name, info));
407 AddServiceRequestHandler( 433 AddServiceRequestHandler(
408 name, base::Bind(&EmbeddedApplicationRunner::BindServiceRequest, 434 name, base::Bind(&EmbeddedApplicationRunner::BindServiceRequest,
409 base::Unretained(app.get()))); 435 base::Unretained(app.get())));
410 auto result = embedded_apps_.insert(std::make_pair(name, std::move(app))); 436 auto result = embedded_apps_.insert(std::make_pair(name, std::move(app)));
411 DCHECK(result.second); 437 DCHECK(result.second);
(...skipping 27 matching lines...) Expand all
439 } 465 }
440 466
441 void MojoShellConnectionImpl::GetInterface( 467 void MojoShellConnectionImpl::GetInterface(
442 shell::mojom::InterfaceProvider* provider, 468 shell::mojom::InterfaceProvider* provider,
443 const mojo::String& interface_name, 469 const mojo::String& interface_name,
444 mojo::ScopedMessagePipeHandle request_handle) { 470 mojo::ScopedMessagePipeHandle request_handle) {
445 provider->GetInterface(interface_name, std::move(request_handle)); 471 provider->GetInterface(interface_name, std::move(request_handle));
446 } 472 }
447 473
448 } // namespace content 474 } // namespace content
OLDNEW
« no previous file with comments | « content/common/mojo/mojo_shell_connection_impl.h ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698