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

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 for (auto it = connection_filters_.begin(); it != connection_filters_.end();
Ken Rockot(use gerrit already) 2016/07/29 23:20:47 This needs to hold lock_ too
97 ++it) {
98 if (it->get() == filter) {
99 std::unique_ptr<ConnectionFilter> taken = std::move(*it);
100 connection_filters_.erase(it);
101 return taken;
102 }
103 }
104 return nullptr;
105 }
106
93 // Safe to call any time before Start() is called. 107 // Safe to call any time before Start() is called.
94 void SetDefaultBinderForBrowserConnection( 108 void SetDefaultBinderForBrowserConnection(
95 const shell::InterfaceRegistry::Binder& binder) { 109 const shell::InterfaceRegistry::Binder& binder) {
96 DCHECK(!started_); 110 DCHECK(!started_);
97 default_browser_binder_ = base::Bind( 111 default_browser_binder_ = base::Bind(
98 &IOThreadContext::CallBinderOnTaskRunner, 112 &IOThreadContext::CallBinderOnTaskRunner,
99 base::ThreadTaskRunnerHandle::Get(), binder); 113 base::ThreadTaskRunnerHandle::Get(), binder);
100 } 114 }
101 115
102 // Safe to call any time after Start() is called. 116 // Safe to call any time after Start() is called.
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 // InterfaceRegistry. 292 // InterfaceRegistry.
279 // 293 //
280 // TODO(rockot): Remove this once all interfaces exposed to the browser are 294 // TODO(rockot): Remove this once all interfaces exposed to the browser are
281 // exposed via a ConnectionFilter. 295 // exposed via a ConnectionFilter.
282 shell::InterfaceRegistry::Binder default_browser_binder_; 296 shell::InterfaceRegistry::Binder default_browser_binder_;
283 297
284 std::unique_ptr<shell::ServiceContext> service_context_; 298 std::unique_ptr<shell::ServiceContext> service_context_;
285 mojo::BindingSet<shell::mojom::ServiceFactory> factory_bindings_; 299 mojo::BindingSet<shell::mojom::ServiceFactory> factory_bindings_;
286 std::vector<std::unique_ptr<ConnectionFilter>> connection_filters_; 300 std::vector<std::unique_ptr<ConnectionFilter>> connection_filters_;
287 301
302 base::Lock lock_;
303
288 DISALLOW_COPY_AND_ASSIGN(IOThreadContext); 304 DISALLOW_COPY_AND_ASSIGN(IOThreadContext);
289 }; 305 };
290 306
291 //////////////////////////////////////////////////////////////////////////////// 307 ////////////////////////////////////////////////////////////////////////////////
292 // MojoShellConnection, public: 308 // MojoShellConnection, public:
293 309
294 // static 310 // static
295 void MojoShellConnection::SetForProcess( 311 void MojoShellConnection::SetForProcess(
296 std::unique_ptr<MojoShellConnection> connection) { 312 std::unique_ptr<MojoShellConnection> connection) {
297 DCHECK(!g_connection_for_process.Get()); 313 DCHECK(!g_connection_for_process.Get());
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 397
382 void MojoShellConnectionImpl::SetupInterfaceRequestProxies( 398 void MojoShellConnectionImpl::SetupInterfaceRequestProxies(
383 shell::InterfaceRegistry* registry, 399 shell::InterfaceRegistry* registry,
384 shell::InterfaceProvider* provider) { 400 shell::InterfaceProvider* provider) {
385 // It's safe to bind |registry| as a raw pointer because the caller must 401 // 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. 402 // guarantee that it outlives |this|, and |this| is bound as a weak ptr here.
387 context_->SetDefaultBinderForBrowserConnection( 403 context_->SetDefaultBinderForBrowserConnection(
388 base::Bind(&MojoShellConnectionImpl::GetInterface, 404 base::Bind(&MojoShellConnectionImpl::GetInterface,
389 weak_factory_.GetWeakPtr(), registry)); 405 weak_factory_.GetWeakPtr(), registry));
390 406
407 if (!provider)
408 return;
409
391 // Forward all remote interface requests on |provider| to our IO-thread 410 // Forward all remote interface requests on |provider| to our IO-thread
392 // context. This will ensure they're forwarded to the provider on the 411 // context. This will ensure they're forwarded to the provider on the
393 // incoming browser connection. 412 // incoming browser connection.
394 provider->Forward(base::Bind(&IOThreadContext::GetRemoteInterface, context_)); 413 provider->Forward(base::Bind(&IOThreadContext::GetRemoteInterface,
414 context_));
395 } 415 }
396 416
397 void MojoShellConnectionImpl::AddConnectionFilter( 417 void MojoShellConnectionImpl::AddConnectionFilter(
398 std::unique_ptr<ConnectionFilter> filter) { 418 std::unique_ptr<ConnectionFilter> filter) {
399 context_->AddConnectionFilter(std::move(filter)); 419 context_->AddConnectionFilter(std::move(filter));
400 } 420 }
401 421
422 std::unique_ptr<ConnectionFilter>
423 MojoShellConnectionImpl::RemoveConnectionFilter(ConnectionFilter* filter) {
424 return context_->RemoveConnectionFilter(filter);
425 }
426
402 void MojoShellConnectionImpl::AddEmbeddedService( 427 void MojoShellConnectionImpl::AddEmbeddedService(
403 const std::string& name, 428 const std::string& name,
404 const MojoApplicationInfo& info) { 429 const MojoApplicationInfo& info) {
405 std::unique_ptr<EmbeddedApplicationRunner> app( 430 std::unique_ptr<EmbeddedApplicationRunner> app(
406 new EmbeddedApplicationRunner(name, info)); 431 new EmbeddedApplicationRunner(name, info));
407 AddServiceRequestHandler( 432 AddServiceRequestHandler(
408 name, base::Bind(&EmbeddedApplicationRunner::BindServiceRequest, 433 name, base::Bind(&EmbeddedApplicationRunner::BindServiceRequest,
409 base::Unretained(app.get()))); 434 base::Unretained(app.get())));
410 auto result = embedded_apps_.insert(std::make_pair(name, std::move(app))); 435 auto result = embedded_apps_.insert(std::make_pair(name, std::move(app)));
411 DCHECK(result.second); 436 DCHECK(result.second);
(...skipping 27 matching lines...) Expand all
439 } 464 }
440 465
441 void MojoShellConnectionImpl::GetInterface( 466 void MojoShellConnectionImpl::GetInterface(
442 shell::mojom::InterfaceProvider* provider, 467 shell::mojom::InterfaceProvider* provider,
443 const mojo::String& interface_name, 468 const mojo::String& interface_name,
444 mojo::ScopedMessagePipeHandle request_handle) { 469 mojo::ScopedMessagePipeHandle request_handle) {
445 provider->GetInterface(interface_name, std::move(request_handle)); 470 provider->GetInterface(interface_name, std::move(request_handle));
446 } 471 }
447 472
448 } // namespace content 473 } // 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