Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Side by Side Diff: mojo/system/raw_channel.h

Issue 297683012: Mojo: Add a RawChannel::EnqueueMessage() that can be overridden by subclasses. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | mojo/system/raw_channel.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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_
OLDNEW
« no previous file with comments | « no previous file | mojo/system/raw_channel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698