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

Unified Diff: content/common/service_manager/child_connection.cc

Issue 2766263009: Convert content ConnectionFilter to OnBindInterface (Closed)
Patch Set: . Created 3 years, 8 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 side-by-side diff with in-line comments
Download patch
Index: content/common/service_manager/child_connection.cc
diff --git a/content/common/service_manager/child_connection.cc b/content/common/service_manager/child_connection.cc
index 42faac05185213e5473761b1163261909b696a9a..63bea119e437d3039573d096f63c81a6e59fb1d8 100644
--- a/content/common/service_manager/child_connection.cc
+++ b/content/common/service_manager/child_connection.cc
@@ -8,6 +8,7 @@
#include <utility>
#include "base/macros.h"
+#include "content/common/child.mojom.h"
#include "content/public/common/service_manager_connection.h"
#include "mojo/edk/embedder/embedder.h"
#include "mojo/public/cpp/system/message_pipe.h"
@@ -18,20 +19,6 @@
namespace content {
-namespace {
-
-void CallBinderOnTaskRunner(
- const service_manager::InterfaceRegistry::Binder& binder,
- scoped_refptr<base::SequencedTaskRunner> task_runner,
- const std::string& interface_name,
- mojo::ScopedMessagePipeHandle request_handle) {
- task_runner->PostTask(
- FROM_HERE,
- base::Bind(binder, interface_name, base::Passed(&request_handle)));
-}
-
-} // namespace
-
class ChildConnection::IOThreadContext
: public base::RefCountedThreadSafe<IOThreadContext> {
public:
@@ -45,15 +32,22 @@ class ChildConnection::IOThreadContext
io_task_runner_ = io_task_runner;
std::unique_ptr<service_manager::Connector> io_thread_connector;
if (connector)
- io_thread_connector = connector->Clone();
+ connector_ = connector->Clone();
+ child_identity_ = child_identity;
io_task_runner_->PostTask(
FROM_HERE,
base::Bind(&IOThreadContext::InitializeOnIOThread, this,
child_identity,
- base::Passed(&io_thread_connector),
base::Passed(&service_pipe)));
}
+ void BindInterface(const std::string& interface_name,
+ mojo::ScopedMessagePipeHandle interface_pipe) {
+ io_task_runner_->PostTask(
+ FROM_HERE, base::Bind(&IOThreadContext::BindInterfaceOnIOThread, this,
+ interface_name, base::Passed(&interface_pipe)));
+ }
+
void ShutDown() {
if (!io_task_runner_)
return;
@@ -63,12 +57,11 @@ class ChildConnection::IOThreadContext
DCHECK(posted);
}
- void GetRemoteInterfaceOnIOThread(
- const std::string& interface_name,
- mojo::ScopedMessagePipeHandle request_handle) {
- if (connection_) {
- connection_->GetRemoteInterfaces()->GetInterface(
- interface_name, std::move(request_handle));
+ void BindInterfaceOnIOThread(const std::string& interface_name,
+ mojo::ScopedMessagePipeHandle request_handle) {
+ if (connector_) {
+ connector_->BindInterface(child_identity_, interface_name,
+ std::move(request_handle));
}
}
@@ -86,7 +79,6 @@ class ChildConnection::IOThreadContext
void InitializeOnIOThread(
const service_manager::Identity& child_identity,
- std::unique_ptr<service_manager::Connector> connector,
mojo::ScopedMessagePipeHandle service_pipe) {
service_manager::mojom::ServicePtr service;
service.Bind(mojo::InterfacePtrInfo<service_manager::mojom::Service>(
@@ -94,16 +86,15 @@ class ChildConnection::IOThreadContext
service_manager::mojom::PIDReceiverRequest pid_receiver_request(
&pid_receiver_);
- if (connector) {
- connector->StartService(child_identity,
- std::move(service),
- std::move(pid_receiver_request));
- connection_ = connector->Connect(child_identity);
+ if (connector_) {
+ connector_->StartService(child_identity, std::move(service),
+ std::move(pid_receiver_request));
+ connector_->BindInterface(child_identity, &child_);
}
}
void ShutDownOnIOThread() {
- connection_.reset();
+ connector_.reset();
pid_receiver_.reset();
}
@@ -114,7 +105,11 @@ class ChildConnection::IOThreadContext
}
scoped_refptr<base::SequencedTaskRunner> io_task_runner_;
- std::unique_ptr<service_manager::Connection> connection_;
+ // Usable from the IO thread only.
+ std::unique_ptr<service_manager::Connector> connector_;
+ service_manager::Identity child_identity_;
+ // ServiceManagerConnection in the child monitors the lifetime of this pipe.
+ mojom::ChildPtr child_;
service_manager::mojom::PIDReceiverPtr pid_receiver_;
DISALLOW_COPY_AND_ASSIGN(IOThreadContext);
@@ -134,16 +129,18 @@ ChildConnection::ChildConnection(
context_->Initialize(child_identity_, connector,
process_connection->CreateMessagePipe(&service_token_),
io_task_runner);
- remote_interfaces_.Forward(
- base::Bind(&CallBinderOnTaskRunner,
- base::Bind(&IOThreadContext::GetRemoteInterfaceOnIOThread,
- context_), io_task_runner));
}
ChildConnection::~ChildConnection() {
context_->ShutDown();
}
+void ChildConnection::BindInterface(
+ const std::string& interface_name,
+ mojo::ScopedMessagePipeHandle interface_pipe) {
+ context_->BindInterface(interface_name, std::move(interface_pipe));
+}
+
void ChildConnection::SetProcessHandle(base::ProcessHandle handle) {
process_handle_ = handle;
context_->SetProcessHandle(handle);
« no previous file with comments | « content/common/service_manager/child_connection.h ('k') | content/common/service_manager/service_manager_connection_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698