OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/logging.h" |
| 8 #include "base/process_util.h" |
7 #include "ipc/ipc_platform_file.h" | 9 #include "ipc/ipc_platform_file.h" |
8 #include "ipc/ipc_test_sink.h" | 10 #include "ipc/ipc_test_sink.h" |
9 | 11 |
10 #if defined(OS_NACL) | 12 #if defined(OS_NACL) |
11 #include <unistd.h> | 13 #include <unistd.h> |
12 #endif | 14 #endif |
13 | 15 |
14 namespace ppapi { | 16 namespace ppapi { |
15 namespace proxy { | 17 namespace proxy { |
16 | 18 |
17 ProxyChannel::ProxyChannel() | 19 ProxyChannel::ProxyChannel() |
18 : delegate_(NULL), | 20 : delegate_(NULL), |
| 21 peer_pid_(base::kNullProcessId), |
19 test_sink_(NULL) { | 22 test_sink_(NULL) { |
20 } | 23 } |
21 | 24 |
22 ProxyChannel::~ProxyChannel() { | 25 ProxyChannel::~ProxyChannel() { |
23 DVLOG(1) << "ProxyChannel::~ProxyChannel()"; | 26 DVLOG(1) << "ProxyChannel::~ProxyChannel()"; |
24 } | 27 } |
25 | 28 |
26 bool ProxyChannel::InitWithChannel(Delegate* delegate, | 29 bool ProxyChannel::InitWithChannel(Delegate* delegate, |
| 30 base::ProcessId peer_pid, |
27 const IPC::ChannelHandle& channel_handle, | 31 const IPC::ChannelHandle& channel_handle, |
28 bool is_client) { | 32 bool is_client) { |
29 delegate_ = delegate; | 33 delegate_ = delegate; |
| 34 peer_pid_ = peer_pid; |
30 IPC::Channel::Mode mode = is_client ? IPC::Channel::MODE_CLIENT | 35 IPC::Channel::Mode mode = is_client ? IPC::Channel::MODE_CLIENT |
31 : IPC::Channel::MODE_SERVER; | 36 : IPC::Channel::MODE_SERVER; |
32 channel_.reset(new IPC::SyncChannel(channel_handle, mode, this, | 37 channel_.reset(new IPC::SyncChannel(channel_handle, mode, this, |
33 delegate->GetIPCMessageLoop(), true, | 38 delegate->GetIPCMessageLoop(), true, |
34 delegate->GetShutdownEvent())); | 39 delegate->GetShutdownEvent())); |
35 return true; | 40 return true; |
36 } | 41 } |
37 | 42 |
38 void ProxyChannel::InitWithTestSink(IPC::TestSink* test_sink) { | 43 void ProxyChannel::InitWithTestSink(IPC::TestSink* test_sink) { |
39 DCHECK(!test_sink_); | 44 DCHECK(!test_sink_); |
40 test_sink_ = test_sink; | 45 test_sink_ = test_sink; |
| 46 #if !defined(OS_NACL) |
| 47 peer_pid_ = base::GetCurrentProcId(); |
| 48 #endif |
41 } | 49 } |
42 | 50 |
43 void ProxyChannel::OnChannelError() { | 51 void ProxyChannel::OnChannelError() { |
44 channel_.reset(); | 52 channel_.reset(); |
45 } | 53 } |
46 | 54 |
47 #if defined(OS_POSIX) && !defined(OS_NACL) | 55 #if defined(OS_POSIX) && !defined(OS_NACL) |
48 int ProxyChannel::TakeRendererFD() { | 56 int ProxyChannel::TakeRendererFD() { |
49 DCHECK(channel()); | 57 DCHECK(channel()); |
50 return channel()->TakeClientFileDescriptor(); | 58 return channel()->TakeClientFileDescriptor(); |
51 } | 59 } |
52 #endif | 60 #endif |
53 | 61 |
54 IPC::PlatformFileForTransit ProxyChannel::ShareHandleWithRemote( | 62 IPC::PlatformFileForTransit ProxyChannel::ShareHandleWithRemote( |
55 base::PlatformFile handle, | 63 base::PlatformFile handle, |
56 bool should_close_source) { | 64 bool should_close_source) { |
57 // Channel could be closed if the plugin crashes. | 65 // Channel could be closed if the plugin crashes. |
58 if (!channel_.get()) { | 66 if (!channel_.get()) { |
59 if (should_close_source) { | 67 if (should_close_source) { |
60 #if !defined(OS_NACL) | 68 #if !defined(OS_NACL) |
61 base::ClosePlatformFile(handle); | 69 base::ClosePlatformFile(handle); |
62 #else | 70 #else |
63 close(handle); | 71 close(handle); |
64 #endif | 72 #endif |
65 } | 73 } |
66 return IPC::InvalidPlatformFileForTransit(); | 74 return IPC::InvalidPlatformFileForTransit(); |
67 } | 75 } |
68 return delegate_->ShareHandleWithRemote(handle, *channel_, | 76 DCHECK(peer_pid_ != base::kNullProcessId); |
| 77 return delegate_->ShareHandleWithRemote(handle, peer_pid_, |
69 should_close_source); | 78 should_close_source); |
70 } | 79 } |
71 | 80 |
72 bool ProxyChannel::Send(IPC::Message* msg) { | 81 bool ProxyChannel::Send(IPC::Message* msg) { |
73 if (test_sink_) | 82 if (test_sink_) |
74 return test_sink_->Send(msg); | 83 return test_sink_->Send(msg); |
75 if (channel_.get()) | 84 if (channel_.get()) |
76 return channel_->Send(msg); | 85 return channel_->Send(msg); |
77 | 86 |
78 // Remote side crashed, drop this message. | 87 // Remote side crashed, drop this message. |
79 delete msg; | 88 delete msg; |
80 return false; | 89 return false; |
81 } | 90 } |
82 | 91 |
83 } // namespace proxy | 92 } // namespace proxy |
84 } // namespace ppapi | 93 } // namespace ppapi |
OLD | NEW |