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 #ifndef PPAPI_PROXY_PROXY_CHANNEL_H_ | 5 #ifndef PPAPI_PROXY_PROXY_CHANNEL_H_ |
6 #define PPAPI_PROXY_PROXY_CHANNEL_H_ | 6 #define PPAPI_PROXY_PROXY_CHANNEL_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/process.h" | 9 #include "base/process.h" |
10 #include "ipc/ipc_listener.h" | 10 #include "ipc/ipc_listener.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 // message loop exits. | 40 // message loop exits. |
41 virtual base::WaitableEvent* GetShutdownEvent() = 0; | 41 virtual base::WaitableEvent* GetShutdownEvent() = 0; |
42 | 42 |
43 // Duplicates a handle to the provided object, returning one that is valid | 43 // Duplicates a handle to the provided object, returning one that is valid |
44 // on the other side of the channel. This is part of the delegate interface | 44 // on the other side of the channel. This is part of the delegate interface |
45 // because both sides of the channel may not have sufficient permission to | 45 // because both sides of the channel may not have sufficient permission to |
46 // duplicate handles directly. The implementation must provide the same | 46 // duplicate handles directly. The implementation must provide the same |
47 // guarantees as ProxyChannel::ShareHandleWithRemote below. | 47 // guarantees as ProxyChannel::ShareHandleWithRemote below. |
48 virtual IPC::PlatformFileForTransit ShareHandleWithRemote( | 48 virtual IPC::PlatformFileForTransit ShareHandleWithRemote( |
49 base::PlatformFile handle, | 49 base::PlatformFile handle, |
50 const IPC::SyncChannel& channel, | 50 base::ProcessId remote_pid, |
51 bool should_close_source) = 0; | 51 bool should_close_source) = 0; |
52 }; | 52 }; |
53 | 53 |
54 virtual ~ProxyChannel(); | 54 virtual ~ProxyChannel(); |
55 | 55 |
56 // Alternative to InitWithChannel() for unit tests that want to send all | 56 // Alternative to InitWithChannel() for unit tests that want to send all |
57 // messages sent via this channel to the given test sink. The test sink | 57 // messages sent via this channel to the given test sink. The test sink |
58 // must outlive this class. | 58 // must outlive this class. In this case, the peer PID will be the current |
| 59 // process ID. |
59 void InitWithTestSink(IPC::TestSink* test_sink); | 60 void InitWithTestSink(IPC::TestSink* test_sink); |
60 | 61 |
61 // Shares a file handle (HANDLE / file descriptor) with the remote side. It | 62 // Shares a file handle (HANDLE / file descriptor) with the remote side. It |
62 // returns a handle that should be sent in exactly one IPC message. Upon | 63 // returns a handle that should be sent in exactly one IPC message. Upon |
63 // receipt, the remote side then owns that handle. Note: if sending the | 64 // receipt, the remote side then owns that handle. Note: if sending the |
64 // message fails, the returned handle is properly closed by the IPC system. If | 65 // message fails, the returned handle is properly closed by the IPC system. If |
65 // should_close_source is set to true, the original handle is closed by this | 66 // should_close_source is set to true, the original handle is closed by this |
66 // operation and should not be used again. | 67 // operation and should not be used again. |
67 IPC::PlatformFileForTransit ShareHandleWithRemote( | 68 IPC::PlatformFileForTransit ShareHandleWithRemote( |
68 base::PlatformFile handle, | 69 base::PlatformFile handle, |
(...skipping 14 matching lines...) Expand all Loading... |
83 int TakeRendererFD(); | 84 int TakeRendererFD(); |
84 #endif | 85 #endif |
85 | 86 |
86 protected: | 87 protected: |
87 explicit ProxyChannel(); | 88 explicit ProxyChannel(); |
88 | 89 |
89 // You must call this function before anything else. Returns true on success. | 90 // You must call this function before anything else. Returns true on success. |
90 // The delegate pointer must outlive this class, ownership is not | 91 // The delegate pointer must outlive this class, ownership is not |
91 // transferred. | 92 // transferred. |
92 virtual bool InitWithChannel(Delegate* delegate, | 93 virtual bool InitWithChannel(Delegate* delegate, |
| 94 base::ProcessId peer_pid, |
93 const IPC::ChannelHandle& channel_handle, | 95 const IPC::ChannelHandle& channel_handle, |
94 bool is_client); | 96 bool is_client); |
95 | 97 |
96 ProxyChannel::Delegate* delegate() const { | 98 ProxyChannel::Delegate* delegate() const { |
97 return delegate_; | 99 return delegate_; |
98 } | 100 } |
99 | 101 |
100 private: | 102 private: |
101 // Non-owning pointer. Guaranteed non-NULL after init is called. | 103 // Non-owning pointer. Guaranteed non-NULL after init is called. |
102 ProxyChannel::Delegate* delegate_; | 104 ProxyChannel::Delegate* delegate_; |
103 | 105 |
| 106 // PID of the remote process. Use this instead of the Channel::peer_pid since |
| 107 // this is set synchronously on construction rather than waiting on the |
| 108 // "hello" message from the peer (which introduces a race condition). |
| 109 base::ProcessId peer_pid_; |
| 110 |
104 // When we're unit testing, this will indicate the sink for the messages to | 111 // When we're unit testing, this will indicate the sink for the messages to |
105 // be deposited so they can be inspected by the test. When non-NULL, this | 112 // be deposited so they can be inspected by the test. When non-NULL, this |
106 // indicates that the channel should not be used. | 113 // indicates that the channel should not be used. |
107 IPC::TestSink* test_sink_; | 114 IPC::TestSink* test_sink_; |
108 | 115 |
109 // Will be null for some tests when there is a test_sink_, and if the | 116 // Will be null for some tests when there is a test_sink_, and if the |
110 // remote side has crashed. | 117 // remote side has crashed. |
111 scoped_ptr<IPC::SyncChannel> channel_; | 118 scoped_ptr<IPC::SyncChannel> channel_; |
112 | 119 |
113 DISALLOW_COPY_AND_ASSIGN(ProxyChannel); | 120 DISALLOW_COPY_AND_ASSIGN(ProxyChannel); |
114 }; | 121 }; |
115 | 122 |
116 } // namespace proxy | 123 } // namespace proxy |
117 } // namespace ppapi | 124 } // namespace ppapi |
118 | 125 |
119 #endif // PPAPI_PROXY_PROXY_CHANNEL_H_ | 126 #endif // PPAPI_PROXY_PROXY_CHANNEL_H_ |
OLD | NEW |