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 MOJO_SYSTEM_RAW_CHANNEL_H_ | 5 #ifndef MOJO_SYSTEM_RAW_CHANNEL_H_ |
6 #define MOJO_SYSTEM_RAW_CHANNEL_H_ | 6 #define MOJO_SYSTEM_RAW_CHANNEL_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 // The first message's data may have been partially sent. |data_offset_| | 178 // The first message's data may have been partially sent. |data_offset_| |
179 // indicates the position in the first message's data to start the next | 179 // indicates the position in the first message's data to start the next |
180 // write. | 180 // write. |
181 size_t data_offset_; | 181 size_t data_offset_; |
182 | 182 |
183 DISALLOW_COPY_AND_ASSIGN(WriteBuffer); | 183 DISALLOW_COPY_AND_ASSIGN(WriteBuffer); |
184 }; | 184 }; |
185 | 185 |
186 RawChannel(); | 186 RawChannel(); |
187 | 187 |
| 188 // Must be called on the I/O thread WITHOUT |write_lock_| held. |
| 189 void OnReadCompleted(bool result, size_t bytes_read); |
| 190 // Must be called on the I/O thread WITHOUT |write_lock_| held. |
| 191 void OnWriteCompleted(bool result, |
| 192 size_t platform_handles_written, |
| 193 size_t bytes_written); |
| 194 |
188 base::MessageLoopForIO* message_loop_for_io() { return message_loop_for_io_; } | 195 base::MessageLoopForIO* message_loop_for_io() { return message_loop_for_io_; } |
189 base::Lock& write_lock() { return write_lock_; } | 196 base::Lock& write_lock() { return write_lock_; } |
190 | 197 |
191 // Only accessed on the I/O thread. | 198 // Should only be called on the I/O thread. |
192 ReadBuffer* read_buffer(); | 199 ReadBuffer* read_buffer() { return read_buffer_.get(); } |
193 | 200 |
194 // Only accessed under |write_lock_|. | 201 // Only called under |write_lock_|. |
195 WriteBuffer* write_buffer_no_lock(); | 202 WriteBuffer* write_buffer_no_lock() { |
| 203 write_lock_.AssertAcquired(); |
| 204 return write_buffer_.get(); |
| 205 } |
| 206 |
| 207 // Adds |message| to the write message queue. Implementation subclasses may |
| 208 // override this to add any additional "control" messages needed. This is |
| 209 // called (on any thread) with |write_lock_| held. |
| 210 virtual void EnqueueMessageNoLock(scoped_ptr<MessageInTransit> message); |
196 | 211 |
197 // Reads into |read_buffer()|. | 212 // Reads into |read_buffer()|. |
198 // This class guarantees that: | 213 // This class guarantees that: |
199 // - the area indicated by |GetBuffer()| will stay valid until read completion | 214 // - the area indicated by |GetBuffer()| will stay valid until read completion |
200 // (but please also see the comments for |OnShutdownNoLock()|); | 215 // (but please also see the comments for |OnShutdownNoLock()|); |
201 // - a second read is not started if there is a pending read; | 216 // - a second read is not started if there is a pending read; |
202 // - the method is called on the I/O thread WITHOUT |write_lock_| held. | 217 // - the method is called on the I/O thread WITHOUT |write_lock_| held. |
203 // | 218 // |
204 // The implementing subclass must guarantee that: | 219 // The implementing subclass must guarantee that: |
205 // - |bytes_read| is untouched unless |Read()| returns |IO_SUCCEEDED|; | 220 // - |bytes_read| is untouched unless |Read()| returns |IO_SUCCEEDED|; |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 | 257 |
243 // Must be called on the I/O thread WITHOUT |write_lock_| held. | 258 // Must be called on the I/O thread WITHOUT |write_lock_| held. |
244 virtual bool OnInit() = 0; | 259 virtual bool OnInit() = 0; |
245 // On shutdown, passes the ownership of the buffers to subclasses, which may | 260 // On shutdown, passes the ownership of the buffers to subclasses, which may |
246 // want to preserve them if there are pending read/write. Must be called on | 261 // want to preserve them if there are pending read/write. Must be called on |
247 // the I/O thread under |write_lock_|. | 262 // the I/O thread under |write_lock_|. |
248 virtual void OnShutdownNoLock( | 263 virtual void OnShutdownNoLock( |
249 scoped_ptr<ReadBuffer> read_buffer, | 264 scoped_ptr<ReadBuffer> read_buffer, |
250 scoped_ptr<WriteBuffer> write_buffer) = 0; | 265 scoped_ptr<WriteBuffer> write_buffer) = 0; |
251 | 266 |
252 // Must be called on the I/O thread WITHOUT |write_lock_| held. | |
253 void OnReadCompleted(bool result, size_t bytes_read); | |
254 // Must be called on the I/O thread WITHOUT |write_lock_| held. | |
255 void OnWriteCompleted(bool result, | |
256 size_t platform_handles_written, | |
257 size_t bytes_written); | |
258 | |
259 private: | 267 private: |
260 // Calls |delegate_->OnFatalError(fatal_error)|. Must be called on the I/O | 268 // Calls |delegate_->OnFatalError(fatal_error)|. Must be called on the I/O |
261 // thread WITHOUT |write_lock_| held. | 269 // thread WITHOUT |write_lock_| held. |
262 void CallOnFatalError(Delegate::FatalError fatal_error); | 270 void CallOnFatalError(Delegate::FatalError fatal_error); |
263 | 271 |
264 // If |result| is true, updates the write buffer and schedules a write | 272 // If |result| is true, updates the write buffer and schedules a write |
265 // operation to run later if there are more contents to write. If |result| is | 273 // operation to run later if there are more contents to write. If |result| is |
266 // false or any error occurs during the method execution, cancels pending | 274 // false or any error occurs during the method execution, cancels pending |
267 // writes and returns false. | 275 // writes and returns false. |
268 // Must be called only if |write_stopped_| is false and under |write_lock_|. | 276 // Must be called only if |write_stopped_| is false and under |write_lock_|. |
(...skipping 19 matching lines...) Expand all Loading... |
288 // are only used/invalidated on the I/O thread. | 296 // are only used/invalidated on the I/O thread. |
289 base::WeakPtrFactory<RawChannel> weak_ptr_factory_; | 297 base::WeakPtrFactory<RawChannel> weak_ptr_factory_; |
290 | 298 |
291 DISALLOW_COPY_AND_ASSIGN(RawChannel); | 299 DISALLOW_COPY_AND_ASSIGN(RawChannel); |
292 }; | 300 }; |
293 | 301 |
294 } // namespace system | 302 } // namespace system |
295 } // namespace mojo | 303 } // namespace mojo |
296 | 304 |
297 #endif // MOJO_SYSTEM_RAW_CHANNEL_H_ | 305 #endif // MOJO_SYSTEM_RAW_CHANNEL_H_ |
OLD | NEW |