Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 Start() is called. |
| 88 void AddConnectionFilter(std::unique_ptr<ConnectionFilter> filter) { | 88 void AddConnectionFilter(std::unique_ptr<ConnectionFilter> filter) { |
| 89 DCHECK(!started_); | 89 //DCHECK(!started_); |
|
Ken Rockot(use gerrit already)
2016/07/29 17:09:46
Remove
| |
| 90 connection_filters_.emplace_back(std::move(filter)); | 90 connection_filters_.emplace_back(std::move(filter)); |
| 91 } | 91 } |
| 92 | 92 |
| 93 std::unique_ptr<ConnectionFilter> RemoveConnectionFilter( | |
| 94 ConnectionFilter* filter) { | |
| 95 for (auto it = connection_filters_.begin(); it != connection_filters_.end(); | |
| 96 ++it) { | |
| 97 if (it->get() == filter) { | |
| 98 std::unique_ptr<ConnectionFilter> taken = std::move(*it); | |
| 99 connection_filters_.erase(it); | |
| 100 return taken; | |
| 101 } | |
| 102 } | |
| 103 return nullptr; | |
| 104 } | |
| 105 | |
| 93 // Safe to call any time before Start() is called. | 106 // Safe to call any time before Start() is called. |
| 94 void SetDefaultBinderForBrowserConnection( | 107 void SetDefaultBinderForBrowserConnection( |
| 95 const shell::InterfaceRegistry::Binder& binder) { | 108 const shell::InterfaceRegistry::Binder& binder) { |
| 96 DCHECK(!started_); | 109 DCHECK(!started_); |
| 97 default_browser_binder_ = base::Bind( | 110 default_browser_binder_ = base::Bind( |
| 98 &IOThreadContext::CallBinderOnTaskRunner, | 111 &IOThreadContext::CallBinderOnTaskRunner, |
| 99 base::ThreadTaskRunnerHandle::Get(), binder); | 112 base::ThreadTaskRunnerHandle::Get(), binder); |
| 100 } | 113 } |
| 101 | 114 |
| 102 // Safe to call any time after Start() is called. | 115 // Safe to call any time after Start() is called. |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 381 | 394 |
| 382 void MojoShellConnectionImpl::SetupInterfaceRequestProxies( | 395 void MojoShellConnectionImpl::SetupInterfaceRequestProxies( |
| 383 shell::InterfaceRegistry* registry, | 396 shell::InterfaceRegistry* registry, |
| 384 shell::InterfaceProvider* provider) { | 397 shell::InterfaceProvider* provider) { |
| 385 // It's safe to bind |registry| as a raw pointer because the caller must | 398 // 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. | 399 // guarantee that it outlives |this|, and |this| is bound as a weak ptr here. |
| 387 context_->SetDefaultBinderForBrowserConnection( | 400 context_->SetDefaultBinderForBrowserConnection( |
| 388 base::Bind(&MojoShellConnectionImpl::GetInterface, | 401 base::Bind(&MojoShellConnectionImpl::GetInterface, |
| 389 weak_factory_.GetWeakPtr(), registry)); | 402 weak_factory_.GetWeakPtr(), registry)); |
| 390 | 403 |
| 404 if (!provider) | |
|
Ken Rockot(use gerrit already)
2016/07/29 17:09:46
Why would this be null? Tests?
Ben Goodger (Google)
2016/07/29 19:35:02
In the case I've just added. We use the IP from th
| |
| 405 return; | |
| 406 | |
| 391 // Forward all remote interface requests on |provider| to our IO-thread | 407 // Forward all remote interface requests on |provider| to our IO-thread |
| 392 // context. This will ensure they're forwarded to the provider on the | 408 // context. This will ensure they're forwarded to the provider on the |
| 393 // incoming browser connection. | 409 // incoming browser connection. |
| 394 provider->Forward(base::Bind(&IOThreadContext::GetRemoteInterface, context_)); | 410 provider->Forward(base::Bind(&IOThreadContext::GetRemoteInterface, |
| 411 context_)); | |
| 395 } | 412 } |
| 396 | 413 |
| 397 void MojoShellConnectionImpl::AddConnectionFilter( | 414 void MojoShellConnectionImpl::AddConnectionFilter( |
| 398 std::unique_ptr<ConnectionFilter> filter) { | 415 std::unique_ptr<ConnectionFilter> filter) { |
| 399 context_->AddConnectionFilter(std::move(filter)); | 416 context_->AddConnectionFilter(std::move(filter)); |
| 400 } | 417 } |
| 401 | 418 |
| 419 std::unique_ptr<ConnectionFilter> | |
| 420 MojoShellConnectionImpl::RemoveConnectionFilter(ConnectionFilter* filter) { | |
| 421 return context_->RemoveConnectionFilter(filter); | |
| 422 } | |
| 423 | |
| 402 void MojoShellConnectionImpl::AddEmbeddedService( | 424 void MojoShellConnectionImpl::AddEmbeddedService( |
| 403 const std::string& name, | 425 const std::string& name, |
| 404 const MojoApplicationInfo& info) { | 426 const MojoApplicationInfo& info) { |
| 405 std::unique_ptr<EmbeddedApplicationRunner> app( | 427 std::unique_ptr<EmbeddedApplicationRunner> app( |
| 406 new EmbeddedApplicationRunner(name, info)); | 428 new EmbeddedApplicationRunner(name, info)); |
| 407 AddServiceRequestHandler( | 429 AddServiceRequestHandler( |
| 408 name, base::Bind(&EmbeddedApplicationRunner::BindServiceRequest, | 430 name, base::Bind(&EmbeddedApplicationRunner::BindServiceRequest, |
| 409 base::Unretained(app.get()))); | 431 base::Unretained(app.get()))); |
| 410 auto result = embedded_apps_.insert(std::make_pair(name, std::move(app))); | 432 auto result = embedded_apps_.insert(std::make_pair(name, std::move(app))); |
| 411 DCHECK(result.second); | 433 DCHECK(result.second); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 439 } | 461 } |
| 440 | 462 |
| 441 void MojoShellConnectionImpl::GetInterface( | 463 void MojoShellConnectionImpl::GetInterface( |
| 442 shell::mojom::InterfaceProvider* provider, | 464 shell::mojom::InterfaceProvider* provider, |
| 443 const mojo::String& interface_name, | 465 const mojo::String& interface_name, |
| 444 mojo::ScopedMessagePipeHandle request_handle) { | 466 mojo::ScopedMessagePipeHandle request_handle) { |
| 445 provider->GetInterface(interface_name, std::move(request_handle)); | 467 provider->GetInterface(interface_name, std::move(request_handle)); |
| 446 } | 468 } |
| 447 | 469 |
| 448 } // namespace content | 470 } // namespace content |
| OLD | NEW |