| 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 "mojo/edk/system/node_channel.h" | 5 #include "mojo/edk/system/node_channel.h" |
| 6 | 6 |
| 7 #include <cstring> | 7 #include <cstring> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 | 10 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 } | 216 } |
| 217 | 217 |
| 218 void NodeChannel::NotifyBadMessage(const std::string& error) { | 218 void NodeChannel::NotifyBadMessage(const std::string& error) { |
| 219 if (!process_error_callback_.is_null()) | 219 if (!process_error_callback_.is_null()) |
| 220 process_error_callback_.Run("Received bad user message: " + error); | 220 process_error_callback_.Run("Received bad user message: " + error); |
| 221 } | 221 } |
| 222 | 222 |
| 223 void NodeChannel::SetRemoteProcessHandle(base::ProcessHandle process_handle) { | 223 void NodeChannel::SetRemoteProcessHandle(base::ProcessHandle process_handle) { |
| 224 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 224 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| 225 base::AutoLock lock(remote_process_handle_lock_); | 225 base::AutoLock lock(remote_process_handle_lock_); |
| 226 DCHECK_EQ(base::kNullProcessHandle, remote_process_handle_); |
| 226 CHECK_NE(remote_process_handle_, base::GetCurrentProcessHandle()); | 227 CHECK_NE(remote_process_handle_, base::GetCurrentProcessHandle()); |
| 227 remote_process_handle_ = process_handle; | 228 remote_process_handle_ = process_handle; |
| 229 #if defined(OS_WIN) |
| 230 DCHECK(!scoped_remote_process_handle_.is_valid()); |
| 231 scoped_remote_process_handle_.reset(PlatformHandle(process_handle)); |
| 232 #endif |
| 228 } | 233 } |
| 229 | 234 |
| 230 bool NodeChannel::HasRemoteProcessHandle() { | 235 bool NodeChannel::HasRemoteProcessHandle() { |
| 231 base::AutoLock lock(remote_process_handle_lock_); | 236 base::AutoLock lock(remote_process_handle_lock_); |
| 232 return remote_process_handle_ != base::kNullProcessHandle; | 237 return remote_process_handle_ != base::kNullProcessHandle; |
| 233 } | 238 } |
| 234 | 239 |
| 235 base::ProcessHandle NodeChannel::CopyRemoteProcessHandle() { | 240 base::ProcessHandle NodeChannel::CopyRemoteProcessHandle() { |
| 236 base::AutoLock lock(remote_process_handle_lock_); | 241 base::AutoLock lock(remote_process_handle_lock_); |
| 237 #if defined(OS_WIN) | 242 #if defined(OS_WIN) |
| 238 if (remote_process_handle_ != base::kNullProcessHandle) { | 243 if (remote_process_handle_ != base::kNullProcessHandle) { |
| 239 // Privileged nodes use this to pass their childrens' process handles to the | 244 // Privileged nodes use this to pass their childrens' process handles to the |
| 240 // broker on launch. | 245 // broker on launch. |
| 241 HANDLE handle = remote_process_handle_; | 246 HANDLE handle = remote_process_handle_; |
| 242 BOOL result = DuplicateHandle( | 247 BOOL result = DuplicateHandle( |
| 243 base::GetCurrentProcessHandle(), remote_process_handle_, | 248 base::GetCurrentProcessHandle(), remote_process_handle_, |
| 244 base::GetCurrentProcessHandle(), &handle, 0, FALSE, | 249 base::GetCurrentProcessHandle(), &handle, 0, FALSE, |
| 245 DUPLICATE_SAME_ACCESS); | 250 DUPLICATE_SAME_ACCESS); |
| 246 DCHECK(result); | 251 DPCHECK(result); |
| 247 return handle; | 252 return handle; |
| 248 } | 253 } |
| 249 return base::kNullProcessHandle; | 254 return base::kNullProcessHandle; |
| 250 #else | 255 #else |
| 251 return remote_process_handle_; | 256 return remote_process_handle_; |
| 252 #endif | 257 #endif |
| 253 } | 258 } |
| 254 | 259 |
| 255 void NodeChannel::SetRemoteNodeName(const ports::NodeName& name) { | 260 void NodeChannel::SetRemoteNodeName(const ports::NodeName& name) { |
| 256 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); | 261 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); |
| (...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 | 866 |
| 862 base::AutoLock lock(channel_lock_); | 867 base::AutoLock lock(channel_lock_); |
| 863 if (!channel_) | 868 if (!channel_) |
| 864 DLOG(ERROR) << "Dropping message on closed channel."; | 869 DLOG(ERROR) << "Dropping message on closed channel."; |
| 865 else | 870 else |
| 866 channel_->Write(std::move(message)); | 871 channel_->Write(std::move(message)); |
| 867 } | 872 } |
| 868 | 873 |
| 869 } // namespace edk | 874 } // namespace edk |
| 870 } // namespace mojo | 875 } // namespace mojo |
| OLD | NEW |