| 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/service_manager/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" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; | 116 scoped_refptr<base::SequencedTaskRunner> io_task_runner_; |
| 117 std::unique_ptr<service_manager::Connection> connection_; | 117 std::unique_ptr<service_manager::Connection> connection_; |
| 118 service_manager::mojom::PIDReceiverPtr pid_receiver_; | 118 service_manager::mojom::PIDReceiverPtr pid_receiver_; |
| 119 | 119 |
| 120 DISALLOW_COPY_AND_ASSIGN(IOThreadContext); | 120 DISALLOW_COPY_AND_ASSIGN(IOThreadContext); |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 ChildConnection::ChildConnection( | 123 ChildConnection::ChildConnection( |
| 124 const std::string& service_name, | 124 const std::string& service_name, |
| 125 const std::string& instance_id, | 125 const std::string& instance_id, |
| 126 const std::string& child_token, | 126 const mojo::edk::PendingProcessConnection& process_connection, |
| 127 service_manager::Connector* connector, | 127 service_manager::Connector* connector, |
| 128 scoped_refptr<base::SequencedTaskRunner> io_task_runner) | 128 scoped_refptr<base::SequencedTaskRunner> io_task_runner) |
| 129 : child_token_(child_token), | 129 : context_(new IOThreadContext), |
| 130 context_(new IOThreadContext), | |
| 131 child_identity_(service_name, | 130 child_identity_(service_name, |
| 132 service_manager::mojom::kInheritUserID, | 131 service_manager::mojom::kInheritUserID, |
| 133 instance_id), | 132 instance_id), |
| 134 service_token_(mojo::edk::GenerateRandomToken()), | |
| 135 weak_factory_(this) { | 133 weak_factory_(this) { |
| 136 mojo::ScopedMessagePipeHandle service_pipe = | 134 context_->Initialize(child_identity_, connector, |
| 137 mojo::edk::CreateParentMessagePipe(service_token_, child_token_); | 135 process_connection.CreateMessagePipe(&service_token_), |
| 138 | |
| 139 context_->Initialize(child_identity_, connector, std::move(service_pipe), | |
| 140 io_task_runner); | 136 io_task_runner); |
| 141 remote_interfaces_.Forward( | 137 remote_interfaces_.Forward( |
| 142 base::Bind(&CallBinderOnTaskRunner, | 138 base::Bind(&CallBinderOnTaskRunner, |
| 143 base::Bind(&IOThreadContext::GetRemoteInterfaceOnIOThread, | 139 base::Bind(&IOThreadContext::GetRemoteInterfaceOnIOThread, |
| 144 context_), io_task_runner)); | 140 context_), io_task_runner)); |
| 145 } | 141 } |
| 146 | 142 |
| 147 ChildConnection::~ChildConnection() { | 143 ChildConnection::~ChildConnection() { |
| 148 context_->ShutDown(); | 144 context_->ShutDown(); |
| 149 | |
| 150 if (process_handle_ == base::kNullProcessHandle) { | |
| 151 // The process handle was never set, so we have to assume the process was | |
| 152 // not successfully launched. Note that ChildProcessLauncher may also call | |
| 153 // call ChildProcessLaunchFailed for the same token, so this is (harmlessly) | |
| 154 // redundant in some cases. | |
| 155 mojo::edk::ChildProcessLaunchFailed(child_token_); | |
| 156 } | |
| 157 } | 145 } |
| 158 | 146 |
| 159 void ChildConnection::SetProcessHandle(base::ProcessHandle handle) { | 147 void ChildConnection::SetProcessHandle(base::ProcessHandle handle) { |
| 160 process_handle_ = handle; | 148 process_handle_ = handle; |
| 161 context_->SetProcessHandle(handle); | 149 context_->SetProcessHandle(handle); |
| 162 } | 150 } |
| 163 | 151 |
| 164 } // namespace content | 152 } // namespace content |
| OLD | NEW |