OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 CHROME_NACL_NACL_IPC_ADAPTER_H_ | 5 #ifndef CHROME_NACL_NACL_IPC_ADAPTER_H_ |
6 #define CHROME_NACL_NACL_IPC_ADAPTER_H_ | 6 #define CHROME_NACL_NACL_IPC_ADAPTER_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <queue> | 9 #include <queue> |
10 #include <string> | 10 #include <string> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
14 #include "base/callback.h" | |
14 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
16 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
17 #include "base/memory/shared_memory.h" | 18 #include "base/memory/shared_memory.h" |
18 #include "base/pickle.h" | 19 #include "base/pickle.h" |
19 #include "base/synchronization/condition_variable.h" | 20 #include "base/synchronization/condition_variable.h" |
20 #include "base/synchronization/lock.h" | 21 #include "base/synchronization/lock.h" |
21 #include "base/task_runner.h" | 22 #include "base/task_runner.h" |
22 #include "ipc/ipc_listener.h" | 23 #include "ipc/ipc_listener.h" |
24 #include "ipc/ipc_platform_file.h" | |
23 #include "ppapi/c/pp_stdint.h" | 25 #include "ppapi/c/pp_stdint.h" |
24 #include "ppapi/proxy/nacl_message_scanner.h" | 26 #include "ppapi/proxy/nacl_message_scanner.h" |
25 | 27 |
26 struct NaClDesc; | 28 struct NaClDesc; |
27 struct NaClImcTypedMsgHdr; | 29 struct NaClImcTypedMsgHdr; |
28 struct PP_Size; | 30 struct PP_Size; |
29 | 31 |
30 namespace IPC { | 32 namespace IPC { |
31 class Channel; | 33 class Channel; |
32 struct ChannelHandle; | 34 struct ChannelHandle; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 | 107 |
106 #if defined(OS_POSIX) | 108 #if defined(OS_POSIX) |
107 int TakeClientFileDescriptor(); | 109 int TakeClientFileDescriptor(); |
108 #endif | 110 #endif |
109 | 111 |
110 // Listener implementation. | 112 // Listener implementation. |
111 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; | 113 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; |
112 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; | 114 virtual void OnChannelConnected(int32 peer_pid) OVERRIDE; |
113 virtual void OnChannelError() OVERRIDE; | 115 virtual void OnChannelError() OVERRIDE; |
114 | 116 |
117 typedef base::Callback<void(uint64_t, // file_token_lo | |
118 uint64_t, // file_token_hi | |
119 base::Callback<void(IPC::PlatformFileForTransit, | |
120 base::FilePath)>)> | |
dmichael (off chromium)
2014/08/27 20:49:14
nit: Maybe a typedef for the internal one might ma
teravest
2014/09/04 22:13:30
Done.
| |
121 ResolveFileTokenCallback; | |
122 | |
123 void set_resolve_file_token_callback(ResolveFileTokenCallback cb) { | |
124 resolve_file_token_cb_ = cb; | |
125 } | |
dmichael (off chromium)
2014/08/27 20:49:14
Somewhere in here it might make sense to document
teravest
2014/09/04 22:13:30
Done.
| |
126 | |
115 private: | 127 private: |
116 friend class base::RefCountedThreadSafe<NaClIPCAdapter>; | 128 friend class base::RefCountedThreadSafe<NaClIPCAdapter>; |
117 | 129 |
118 class RewrittenMessage; | 130 class RewrittenMessage; |
119 | 131 |
120 // This is the data that must only be accessed inside the lock. This struct | 132 // This is the data that must only be accessed inside the lock. This struct |
121 // just separates it so it's easier to see. | 133 // just separates it so it's easier to see. |
122 struct LockedData { | 134 struct LockedData { |
123 LockedData(); | 135 LockedData(); |
124 ~LockedData(); | 136 ~LockedData(); |
(...skipping 26 matching lines...) Expand all Loading... | |
151 | 163 |
152 // When we send a synchronous message (from untrusted to trusted), we store | 164 // When we send a synchronous message (from untrusted to trusted), we store |
153 // its type here, so that later we can associate the reply with its type | 165 // its type here, so that later we can associate the reply with its type |
154 // for scanning. | 166 // for scanning. |
155 typedef std::map<int, uint32> PendingSyncMsgMap; | 167 typedef std::map<int, uint32> PendingSyncMsgMap; |
156 PendingSyncMsgMap pending_sync_msgs_; | 168 PendingSyncMsgMap pending_sync_msgs_; |
157 }; | 169 }; |
158 | 170 |
159 virtual ~NaClIPCAdapter(); | 171 virtual ~NaClIPCAdapter(); |
160 | 172 |
173 void OnFileTokenResolved(const IPC::Message& orig_msg, | |
174 IPC::PlatformFileForTransit ipc_fd, | |
175 base::FilePath file_path); | |
176 | |
177 bool RewriteMessage(const IPC::Message& msg, uint32_t type); | |
178 | |
161 // Returns 0 if nothing is waiting. | 179 // Returns 0 if nothing is waiting. |
162 int LockedReceive(NaClImcTypedMsgHdr* msg); | 180 int LockedReceive(NaClImcTypedMsgHdr* msg); |
163 | 181 |
164 // Sends a message that we know has been completed to the Chrome process. | 182 // Sends a message that we know has been completed to the Chrome process. |
165 bool SendCompleteMessage(const char* buffer, size_t buffer_len); | 183 bool SendCompleteMessage(const char* buffer, size_t buffer_len); |
166 | 184 |
167 // Clears the LockedData.to_be_sent_ structure in a way to make sure that | 185 // Clears the LockedData.to_be_sent_ structure in a way to make sure that |
168 // the memory is deleted. std::string can sometimes hold onto the buffer | 186 // the memory is deleted. std::string can sometimes hold onto the buffer |
169 // for future use which we don't want. | 187 // for future use which we don't want. |
170 void ClearToBeSent(); | 188 void ClearToBeSent(); |
171 | 189 |
172 void ConnectChannelOnIOThread(); | 190 void ConnectChannelOnIOThread(); |
173 void CloseChannelOnIOThread(); | 191 void CloseChannelOnIOThread(); |
174 void SendMessageOnIOThread(scoped_ptr<IPC::Message> message); | 192 void SendMessageOnIOThread(scoped_ptr<IPC::Message> message); |
175 | 193 |
176 // Saves the message to forward to NaCl. This method assumes that the caller | 194 // Saves the message to forward to NaCl. This method assumes that the caller |
177 // holds the lock for locked_data_. | 195 // holds the lock for locked_data_. |
178 void SaveMessage(const IPC::Message& message, | 196 void SaveMessage(const IPC::Message& message, |
179 RewrittenMessage* rewritten_message); | 197 RewrittenMessage* rewritten_message); |
180 | 198 |
181 base::Lock lock_; | 199 base::Lock lock_; |
182 base::ConditionVariable cond_var_; | 200 base::ConditionVariable cond_var_; |
183 | 201 |
184 scoped_refptr<base::TaskRunner> task_runner_; | 202 scoped_refptr<base::TaskRunner> task_runner_; |
203 scoped_refptr<base::TaskRunner> main_task_runner_; | |
204 | |
205 ResolveFileTokenCallback resolve_file_token_cb_; | |
185 | 206 |
186 // To be accessed inside of lock_ only. | 207 // To be accessed inside of lock_ only. |
187 LockedData locked_data_; | 208 LockedData locked_data_; |
188 | 209 |
189 // To be accessed on the I/O thread (via task runner) only. | 210 // To be accessed on the I/O thread (via task runner) only. |
190 IOThreadData io_thread_data_; | 211 IOThreadData io_thread_data_; |
191 | 212 |
192 DISALLOW_COPY_AND_ASSIGN(NaClIPCAdapter); | 213 DISALLOW_COPY_AND_ASSIGN(NaClIPCAdapter); |
193 }; | 214 }; |
194 | 215 |
195 // Export TranslatePepperFileReadWriteOpenFlags for testing. | 216 // Export TranslatePepperFileReadWriteOpenFlags for testing. |
196 int TranslatePepperFileReadWriteOpenFlagsForTesting(int32_t pp_open_flags); | 217 int TranslatePepperFileReadWriteOpenFlagsForTesting(int32_t pp_open_flags); |
197 | 218 |
198 #endif // CHROME_NACL_NACL_IPC_ADAPTER_H_ | 219 #endif // CHROME_NACL_NACL_IPC_ADAPTER_H_ |
OLD | NEW |