| 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 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 <queue> | 8 #include <queue> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 | 119 |
| 120 // Data that we've queued from the plugin to send, but doesn't consist of a | 120 // Data that we've queued from the plugin to send, but doesn't consist of a |
| 121 // full message yet. The calling code can break apart the message into | 121 // full message yet. The calling code can break apart the message into |
| 122 // smaller pieces, and we need to send the message to the other process in | 122 // smaller pieces, and we need to send the message to the other process in |
| 123 // one chunk. | 123 // one chunk. |
| 124 // | 124 // |
| 125 // The IPC channel always starts a new send() at the beginning of each | 125 // The IPC channel always starts a new send() at the beginning of each |
| 126 // message, so we don't need to worry about arbitrary message boundaries. | 126 // message, so we don't need to worry about arbitrary message boundaries. |
| 127 std::string to_be_sent_; | 127 std::string to_be_sent_; |
| 128 | 128 |
| 129 // Wrapped descriptors and handles for transfer to untrusted code. | |
| 130 ScopedVector<nacl::DescWrapper> nacl_descs_; | |
| 131 | |
| 132 bool channel_closed_; | 129 bool channel_closed_; |
| 133 }; | 130 }; |
| 134 | 131 |
| 135 // This is the data that must only be accessed on the I/O thread (as defined | 132 // This is the data that must only be accessed on the I/O thread (as defined |
| 136 // by TaskRunner). This struct just separates it so it's easier to see. | 133 // by TaskRunner). This struct just separates it so it's easier to see. |
| 137 struct IOThreadData { | 134 struct IOThreadData { |
| 138 IOThreadData(); | 135 IOThreadData(); |
| 139 ~IOThreadData(); | 136 ~IOThreadData(); |
| 140 | 137 |
| 141 scoped_ptr<IPC::Channel> channel_; | 138 scoped_ptr<IPC::Channel> channel_; |
| 142 }; | 139 }; |
| 143 | 140 |
| 144 virtual ~NaClIPCAdapter(); | 141 virtual ~NaClIPCAdapter(); |
| 145 | 142 |
| 146 // Reads up to the given amount of data. Returns 0 if nothing is waiting. | 143 // Returns 0 if nothing is waiting. |
| 147 int LockedReceive(char* output_buffer, size_t output_buffer_size); | 144 int LockedReceive(NaClImcTypedMsgHdr* msg); |
| 148 | 145 |
| 149 // Sends a message that we know has been completed to the Chrome process. | 146 // Sends a message that we know has been completed to the Chrome process. |
| 150 bool SendCompleteMessage(const char* buffer, size_t buffer_len); | 147 bool SendCompleteMessage(const char* buffer, size_t buffer_len); |
| 151 | 148 |
| 152 // Clears the LockedData.to_be_sent_ structure in a way to make sure that | 149 // Clears the LockedData.to_be_sent_ structure in a way to make sure that |
| 153 // the memory is deleted. std::string can sometimes hold onto the buffer | 150 // the memory is deleted. std::string can sometimes hold onto the buffer |
| 154 // for future use which we don't want. | 151 // for future use which we don't want. |
| 155 void ClearToBeSent(); | 152 void ClearToBeSent(); |
| 156 | 153 |
| 157 void ConnectChannelOnIOThread(); | 154 void ConnectChannelOnIOThread(); |
| 158 void CloseChannelOnIOThread(); | 155 void CloseChannelOnIOThread(); |
| 159 void SendMessageOnIOThread(scoped_ptr<IPC::Message> message); | 156 void SendMessageOnIOThread(scoped_ptr<IPC::Message> message); |
| 160 | 157 |
| 161 // Saves the message to forward to NaCl. This method assumes that the caller | 158 // Saves the message to forward to NaCl. This method assumes that the caller |
| 162 // holds the lock for locked_data_. | 159 // holds the lock for locked_data_. |
| 163 void SaveMessage(const IPC::Message& message); | 160 void SaveMessage(const IPC::Message& message, |
| 161 RewrittenMessage* rewritten_message); |
| 164 | 162 |
| 165 base::Lock lock_; | 163 base::Lock lock_; |
| 166 base::ConditionVariable cond_var_; | 164 base::ConditionVariable cond_var_; |
| 167 | 165 |
| 168 scoped_refptr<base::TaskRunner> task_runner_; | 166 scoped_refptr<base::TaskRunner> task_runner_; |
| 169 | 167 |
| 170 // To be accessed inside of lock_ only. | 168 // To be accessed inside of lock_ only. |
| 171 LockedData locked_data_; | 169 LockedData locked_data_; |
| 172 | 170 |
| 173 // To be accessed on the I/O thread (via task runner) only. | 171 // To be accessed on the I/O thread (via task runner) only. |
| 174 IOThreadData io_thread_data_; | 172 IOThreadData io_thread_data_; |
| 175 | 173 |
| 176 DISALLOW_COPY_AND_ASSIGN(NaClIPCAdapter); | 174 DISALLOW_COPY_AND_ASSIGN(NaClIPCAdapter); |
| 177 }; | 175 }; |
| 178 | 176 |
| 179 #endif // CHROME_NACL_NACL_IPC_ADAPTER_H_ | 177 #endif // CHROME_NACL_NACL_IPC_ADAPTER_H_ |
| OLD | NEW |