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(IPC::PlatformFileForTransit, base::FilePath)> | |
118 ResolveFileTokenReplyCallback; | |
119 | |
120 typedef base::Callback<void(uint64_t, // file_token_lo | |
121 uint64_t, // file_token_hi | |
122 ResolveFileTokenReplyCallback)> | |
123 ResolveFileTokenCallback; | |
124 | |
125 // Sets a callback to be invoked for resolving file tokens received from the | |
126 // renderer. When the file token is resolvded, the | |
Mark Seaborn
2014/09/05 15:43:46
"resolved"
teravest
2014/09/06 02:25:15
Done.
| |
127 // ResolveFileTokenReplyCallback passed inside the ResolveFileTokenCallback | |
128 // will be invoked. | |
129 void set_resolve_file_token_callback(ResolveFileTokenCallback cb) { | |
130 resolve_file_token_cb_ = cb; | |
131 } | |
132 | |
115 private: | 133 private: |
116 friend class base::RefCountedThreadSafe<NaClIPCAdapter>; | 134 friend class base::RefCountedThreadSafe<NaClIPCAdapter>; |
117 | 135 |
118 class RewrittenMessage; | 136 class RewrittenMessage; |
119 | 137 |
120 // This is the data that must only be accessed inside the lock. This struct | 138 // This is the data that must only be accessed inside the lock. This struct |
121 // just separates it so it's easier to see. | 139 // just separates it so it's easier to see. |
122 struct LockedData { | 140 struct LockedData { |
123 LockedData(); | 141 LockedData(); |
124 ~LockedData(); | 142 ~LockedData(); |
(...skipping 26 matching lines...) Expand all Loading... | |
151 | 169 |
152 // When we send a synchronous message (from untrusted to trusted), we store | 170 // 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 | 171 // its type here, so that later we can associate the reply with its type |
154 // for scanning. | 172 // for scanning. |
155 typedef std::map<int, uint32> PendingSyncMsgMap; | 173 typedef std::map<int, uint32> PendingSyncMsgMap; |
156 PendingSyncMsgMap pending_sync_msgs_; | 174 PendingSyncMsgMap pending_sync_msgs_; |
157 }; | 175 }; |
158 | 176 |
159 virtual ~NaClIPCAdapter(); | 177 virtual ~NaClIPCAdapter(); |
160 | 178 |
179 void OnFileTokenResolved(const IPC::Message& orig_msg, | |
180 IPC::PlatformFileForTransit ipc_fd, | |
181 base::FilePath file_path); | |
182 | |
183 bool RewriteMessage(const IPC::Message& msg, uint32_t type); | |
184 | |
161 // Returns 0 if nothing is waiting. | 185 // Returns 0 if nothing is waiting. |
162 int LockedReceive(NaClImcTypedMsgHdr* msg); | 186 int LockedReceive(NaClImcTypedMsgHdr* msg); |
163 | 187 |
164 // Sends a message that we know has been completed to the Chrome process. | 188 // Sends a message that we know has been completed to the Chrome process. |
165 bool SendCompleteMessage(const char* buffer, size_t buffer_len); | 189 bool SendCompleteMessage(const char* buffer, size_t buffer_len); |
166 | 190 |
167 // Clears the LockedData.to_be_sent_ structure in a way to make sure that | 191 // 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 | 192 // the memory is deleted. std::string can sometimes hold onto the buffer |
169 // for future use which we don't want. | 193 // for future use which we don't want. |
170 void ClearToBeSent(); | 194 void ClearToBeSent(); |
171 | 195 |
172 void ConnectChannelOnIOThread(); | 196 void ConnectChannelOnIOThread(); |
173 void CloseChannelOnIOThread(); | 197 void CloseChannelOnIOThread(); |
174 void SendMessageOnIOThread(scoped_ptr<IPC::Message> message); | 198 void SendMessageOnIOThread(scoped_ptr<IPC::Message> message); |
175 | 199 |
176 // Saves the message to forward to NaCl. This method assumes that the caller | 200 // Saves the message to forward to NaCl. This method assumes that the caller |
177 // holds the lock for locked_data_. | 201 // holds the lock for locked_data_. |
178 void SaveMessage(const IPC::Message& message, | 202 void SaveMessage(const IPC::Message& message, |
179 RewrittenMessage* rewritten_message); | 203 RewrittenMessage* rewritten_message); |
180 | 204 |
181 base::Lock lock_; | 205 base::Lock lock_; |
182 base::ConditionVariable cond_var_; | 206 base::ConditionVariable cond_var_; |
183 | 207 |
184 scoped_refptr<base::TaskRunner> task_runner_; | 208 scoped_refptr<base::TaskRunner> task_runner_; |
209 scoped_refptr<base::TaskRunner> main_task_runner_; | |
210 | |
211 ResolveFileTokenCallback resolve_file_token_cb_; | |
185 | 212 |
186 // To be accessed inside of lock_ only. | 213 // To be accessed inside of lock_ only. |
187 LockedData locked_data_; | 214 LockedData locked_data_; |
188 | 215 |
189 // To be accessed on the I/O thread (via task runner) only. | 216 // To be accessed on the I/O thread (via task runner) only. |
190 IOThreadData io_thread_data_; | 217 IOThreadData io_thread_data_; |
191 | 218 |
192 DISALLOW_COPY_AND_ASSIGN(NaClIPCAdapter); | 219 DISALLOW_COPY_AND_ASSIGN(NaClIPCAdapter); |
193 }; | 220 }; |
194 | 221 |
195 // Export TranslatePepperFileReadWriteOpenFlags for testing. | 222 // Export TranslatePepperFileReadWriteOpenFlags for testing. |
196 int TranslatePepperFileReadWriteOpenFlagsForTesting(int32_t pp_open_flags); | 223 int TranslatePepperFileReadWriteOpenFlagsForTesting(int32_t pp_open_flags); |
197 | 224 |
198 #endif // CHROME_NACL_NACL_IPC_ADAPTER_H_ | 225 #endif // CHROME_NACL_NACL_IPC_ADAPTER_H_ |
OLD | NEW |