OLD | NEW |
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/common/mojo/mojo_child_connection.h" | 5 #include "content/common/service_manager/child_connection.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/macros.h" | 10 #include "base/macros.h" |
11 #include "content/public/common/mojo_shell_connection.h" | 11 #include "content/public/common/service_manager_connection.h" |
12 #include "mojo/edk/embedder/embedder.h" | 12 #include "mojo/edk/embedder/embedder.h" |
13 #include "mojo/public/cpp/system/message_pipe.h" | 13 #include "mojo/public/cpp/system/message_pipe.h" |
14 #include "services/shell/public/cpp/connector.h" | 14 #include "services/shell/public/cpp/connector.h" |
15 #include "services/shell/public/cpp/identity.h" | 15 #include "services/shell/public/cpp/identity.h" |
16 #include "services/shell/public/cpp/interface_registry.h" | 16 #include "services/shell/public/cpp/interface_registry.h" |
17 #include "services/shell/public/interfaces/service.mojom.h" | 17 #include "services/shell/public/interfaces/service.mojom.h" |
18 | 18 |
19 namespace content { | 19 namespace content { |
20 | 20 |
21 namespace { | 21 namespace { |
22 | 22 |
23 void CallBinderOnTaskRunner( | 23 void CallBinderOnTaskRunner( |
24 const shell::InterfaceRegistry::Binder& binder, | 24 const shell::InterfaceRegistry::Binder& binder, |
25 scoped_refptr<base::SequencedTaskRunner> task_runner, | 25 scoped_refptr<base::SequencedTaskRunner> task_runner, |
26 const std::string& interface_name, | 26 const std::string& interface_name, |
27 mojo::ScopedMessagePipeHandle request_handle) { | 27 mojo::ScopedMessagePipeHandle request_handle) { |
28 task_runner->PostTask( | 28 task_runner->PostTask( |
29 FROM_HERE, | 29 FROM_HERE, |
30 base::Bind(binder, interface_name, base::Passed(&request_handle))); | 30 base::Bind(binder, interface_name, base::Passed(&request_handle))); |
31 } | 31 } |
32 | 32 |
33 } // namespace | 33 } // namespace |
34 | 34 |
35 class MojoChildConnection::IOThreadContext | 35 class ChildConnection::IOThreadContext |
36 : public base::RefCountedThreadSafe<IOThreadContext> { | 36 : public base::RefCountedThreadSafe<IOThreadContext> { |
37 public: | 37 public: |
38 IOThreadContext() {} | 38 IOThreadContext() {} |
39 | 39 |
40 void Initialize(const shell::Identity& child_identity, | 40 void Initialize(const shell::Identity& child_identity, |
41 shell::Connector* connector, | 41 shell::Connector* connector, |
42 mojo::ScopedMessagePipeHandle service_pipe, | 42 mojo::ScopedMessagePipeHandle service_pipe, |
43 scoped_refptr<base::SequencedTaskRunner> io_task_runner) { | 43 scoped_refptr<base::SequencedTaskRunner> io_task_runner) { |
44 DCHECK(!io_task_runner_); | 44 DCHECK(!io_task_runner_); |
45 io_task_runner_ = io_task_runner; | 45 io_task_runner_ = io_task_runner; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 pid_receiver_.reset(); | 114 pid_receiver_.reset(); |
115 } | 115 } |
116 | 116 |
117 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; | 117 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; |
118 std::unique_ptr<shell::Connection> connection_; | 118 std::unique_ptr<shell::Connection> connection_; |
119 shell::mojom::PIDReceiverPtr pid_receiver_; | 119 shell::mojom::PIDReceiverPtr pid_receiver_; |
120 | 120 |
121 DISALLOW_COPY_AND_ASSIGN(IOThreadContext); | 121 DISALLOW_COPY_AND_ASSIGN(IOThreadContext); |
122 }; | 122 }; |
123 | 123 |
124 MojoChildConnection::MojoChildConnection( | 124 ChildConnection::ChildConnection( |
125 const std::string& service_name, | 125 const std::string& service_name, |
126 const std::string& instance_id, | 126 const std::string& instance_id, |
127 const std::string& child_token, | 127 const std::string& child_token, |
128 shell::Connector* connector, | 128 shell::Connector* connector, |
129 scoped_refptr<base::SequencedTaskRunner> io_task_runner) | 129 scoped_refptr<base::SequencedTaskRunner> io_task_runner) |
130 : context_(new IOThreadContext), | 130 : context_(new IOThreadContext), |
131 child_identity_(service_name, shell::mojom::kInheritUserID, instance_id), | 131 child_identity_(service_name, shell::mojom::kInheritUserID, instance_id), |
132 service_token_(mojo::edk::GenerateRandomToken()), | 132 service_token_(mojo::edk::GenerateRandomToken()), |
133 weak_factory_(this) { | 133 weak_factory_(this) { |
134 mojo::ScopedMessagePipeHandle service_pipe = | 134 mojo::ScopedMessagePipeHandle service_pipe = |
135 mojo::edk::CreateParentMessagePipe(service_token_, child_token); | 135 mojo::edk::CreateParentMessagePipe(service_token_, child_token); |
136 | 136 |
137 context_->Initialize(child_identity_, connector, std::move(service_pipe), | 137 context_->Initialize(child_identity_, connector, std::move(service_pipe), |
138 io_task_runner); | 138 io_task_runner); |
139 remote_interfaces_.Forward( | 139 remote_interfaces_.Forward( |
140 base::Bind(&CallBinderOnTaskRunner, | 140 base::Bind(&CallBinderOnTaskRunner, |
141 base::Bind(&IOThreadContext::GetRemoteInterfaceOnIOThread, | 141 base::Bind(&IOThreadContext::GetRemoteInterfaceOnIOThread, |
142 context_), io_task_runner)); | 142 context_), io_task_runner)); |
143 } | 143 } |
144 | 144 |
145 MojoChildConnection::~MojoChildConnection() { | 145 ChildConnection::~ChildConnection() { |
146 context_->ShutDown(); | 146 context_->ShutDown(); |
147 } | 147 } |
148 | 148 |
149 void MojoChildConnection::SetProcessHandle(base::ProcessHandle handle) { | 149 void ChildConnection::SetProcessHandle(base::ProcessHandle handle) { |
150 context_->SetProcessHandle(handle); | 150 context_->SetProcessHandle(handle); |
151 } | 151 } |
152 | 152 |
153 } // namespace content | 153 } // namespace content |
OLD | NEW |