| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "ppapi/proxy/proxy_channel.h" | 5 #include "ppapi/proxy/proxy_channel.h" |
| 6 | 6 |
| 7 #include "ipc/ipc_platform_file.h" |
| 7 #include "ipc/ipc_test_sink.h" | 8 #include "ipc/ipc_test_sink.h" |
| 8 | 9 |
| 9 namespace pp { | 10 namespace pp { |
| 10 namespace proxy { | 11 namespace proxy { |
| 11 | 12 |
| 12 ProxyChannel::ProxyChannel(base::ProcessHandle remote_process_handle) | 13 ProxyChannel::ProxyChannel(base::ProcessHandle remote_process_handle) |
| 13 : delegate_(NULL), | 14 : delegate_(NULL), |
| 14 remote_process_handle_(remote_process_handle), | 15 remote_process_handle_(remote_process_handle), |
| 15 test_sink_(NULL) { | 16 test_sink_(NULL) { |
| 16 } | 17 } |
| (...skipping 25 matching lines...) Expand all Loading... |
| 42 #if defined(OS_POSIX) | 43 #if defined(OS_POSIX) |
| 43 int ProxyChannel::GetRendererFD() { | 44 int ProxyChannel::GetRendererFD() { |
| 44 DCHECK(channel()); | 45 DCHECK(channel()); |
| 45 return channel()->GetClientFileDescriptor(); | 46 return channel()->GetClientFileDescriptor(); |
| 46 } | 47 } |
| 47 #endif | 48 #endif |
| 48 | 49 |
| 49 IPC::PlatformFileForTransit ProxyChannel::ShareHandleWithRemote( | 50 IPC::PlatformFileForTransit ProxyChannel::ShareHandleWithRemote( |
| 50 base::PlatformFile handle, | 51 base::PlatformFile handle, |
| 51 bool should_close_source) { | 52 bool should_close_source) { |
| 52 IPC::PlatformFileForTransit out_handle; | 53 return IPC::GetFileHandleForProcess(handle, remote_process_handle_, |
| 53 #if defined(OS_WIN) | 54 should_close_source); |
| 54 DWORD options = DUPLICATE_SAME_ACCESS; | |
| 55 if (should_close_source) | |
| 56 options |= DUPLICATE_CLOSE_SOURCE; | |
| 57 if (!::DuplicateHandle(::GetCurrentProcess(), | |
| 58 handle, | |
| 59 remote_process_handle_, | |
| 60 &out_handle, | |
| 61 0, | |
| 62 FALSE, | |
| 63 options)) | |
| 64 out_handle = IPC::InvalidPlatformFileForTransit(); | |
| 65 #elif defined(OS_POSIX) | |
| 66 // If asked to close the source, we can simply re-use the source fd instead of | |
| 67 // dup()ing and close()ing. | |
| 68 int fd = should_close_source ? handle : ::dup(handle); | |
| 69 out_handle = base::FileDescriptor(fd, true); | |
| 70 #else | |
| 71 #error Not implemented. | |
| 72 #endif | |
| 73 return out_handle; | |
| 74 } | 55 } |
| 75 | 56 |
| 76 bool ProxyChannel::Send(IPC::Message* msg) { | 57 bool ProxyChannel::Send(IPC::Message* msg) { |
| 77 if (test_sink_) | 58 if (test_sink_) |
| 78 return test_sink_->Send(msg); | 59 return test_sink_->Send(msg); |
| 79 if (channel_.get()) | 60 if (channel_.get()) |
| 80 return channel_->Send(msg); | 61 return channel_->Send(msg); |
| 81 | 62 |
| 82 // Remote side crashed, drop this message. | 63 // Remote side crashed, drop this message. |
| 83 delete msg; | 64 delete msg; |
| 84 return false; | 65 return false; |
| 85 } | 66 } |
| 86 | 67 |
| 87 } // namespace proxy | 68 } // namespace proxy |
| 88 } // namespace pp | 69 } // namespace pp |
| OLD | NEW |