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_EDK_SYSTEM_RAW_CHANNEL_H_ | 5 #ifndef MOJO_EDK_SYSTEM_RAW_CHANNEL_H_ |
6 #define MOJO_EDK_SYSTEM_RAW_CHANNEL_H_ | 6 #define MOJO_EDK_SYSTEM_RAW_CHANNEL_H_ |
7 | 7 |
| 8 #include <memory> |
8 #include <vector> | 9 #include <vector> |
9 | 10 |
10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
11 #include "base/memory/weak_ptr.h" | 12 #include "base/memory/weak_ptr.h" |
12 #include "mojo/edk/embedder/platform_handle_vector.h" | 13 #include "mojo/edk/embedder/platform_handle_vector.h" |
13 #include "mojo/edk/embedder/scoped_platform_handle.h" | 14 #include "mojo/edk/embedder/scoped_platform_handle.h" |
14 #include "mojo/edk/system/message_in_transit.h" | 15 #include "mojo/edk/system/message_in_transit.h" |
15 #include "mojo/edk/system/message_in_transit_queue.h" | 16 #include "mojo/edk/system/message_in_transit_queue.h" |
16 #include "mojo/edk/system/mutex.h" | 17 #include "mojo/edk/system/mutex.h" |
17 #include "mojo/edk/system/system_impl_export.h" | 18 #include "mojo/edk/system/system_impl_export.h" |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 // guarantee that the method doesn't succeed synchronously, i.e., it only | 283 // guarantee that the method doesn't succeed synchronously, i.e., it only |
283 // returns |IO_FAILED_...| or |IO_PENDING|. | 284 // returns |IO_FAILED_...| or |IO_PENDING|. |
284 virtual IOResult ScheduleWriteNoLock() = 0; | 285 virtual IOResult ScheduleWriteNoLock() = 0; |
285 | 286 |
286 // Must be called on the I/O thread. | 287 // Must be called on the I/O thread. |
287 virtual void OnInit() MOJO_LOCKS_EXCLUDED(write_mutex_) = 0; | 288 virtual void OnInit() MOJO_LOCKS_EXCLUDED(write_mutex_) = 0; |
288 // On shutdown, passes the ownership of the buffers to subclasses, which may | 289 // On shutdown, passes the ownership of the buffers to subclasses, which may |
289 // want to preserve them if there are pending read/writes. After this is | 290 // want to preserve them if there are pending read/writes. After this is |
290 // called, |OnReadCompleted()| must no longer be called. Must be called on the | 291 // called, |OnReadCompleted()| must no longer be called. Must be called on the |
291 // I/O thread. | 292 // I/O thread. |
292 virtual void OnShutdownNoLock(scoped_ptr<ReadBuffer> read_buffer, | 293 virtual void OnShutdownNoLock(std::unique_ptr<ReadBuffer> read_buffer, |
293 scoped_ptr<WriteBuffer> write_buffer) | 294 std::unique_ptr<WriteBuffer> write_buffer) |
294 MOJO_EXCLUSIVE_LOCKS_REQUIRED(write_mutex_) = 0; | 295 MOJO_EXCLUSIVE_LOCKS_REQUIRED(write_mutex_) = 0; |
295 | 296 |
296 private: | 297 private: |
297 // Converts an |IO_FAILED_...| for a read to a |Delegate::Error|. | 298 // Converts an |IO_FAILED_...| for a read to a |Delegate::Error|. |
298 static Delegate::Error ReadIOResultToError(IOResult io_result); | 299 static Delegate::Error ReadIOResultToError(IOResult io_result); |
299 | 300 |
300 // Calls |delegate_->OnError(error)|. Must be called on the I/O thread. This | 301 // Calls |delegate_->OnError(error)|. Must be called on the I/O thread. This |
301 // object may be destroyed by this call. | 302 // object may be destroyed by this call. |
302 void CallOnError(Delegate::Error error) MOJO_LOCKS_EXCLUDED(write_mutex_); | 303 void CallOnError(Delegate::Error error) MOJO_LOCKS_EXCLUDED(write_mutex_); |
303 | 304 |
304 // If |io_result| is |IO_SUCCESS|, updates the write buffer and schedules a | 305 // If |io_result| is |IO_SUCCESS|, updates the write buffer and schedules a |
305 // write operation to run later if there is more to write. If |io_result| is | 306 // write operation to run later if there is more to write. If |io_result| is |
306 // failure or any other error occurs, cancels pending writes and returns | 307 // failure or any other error occurs, cancels pending writes and returns |
307 // false. May only be called if |write_stopped_| is false. | 308 // false. May only be called if |write_stopped_| is false. |
308 bool OnWriteCompletedNoLock(IOResult io_result, | 309 bool OnWriteCompletedNoLock(IOResult io_result, |
309 size_t platform_handles_written, | 310 size_t platform_handles_written, |
310 size_t bytes_written) | 311 size_t bytes_written) |
311 MOJO_EXCLUSIVE_LOCKS_REQUIRED(write_mutex_); | 312 MOJO_EXCLUSIVE_LOCKS_REQUIRED(write_mutex_); |
312 | 313 |
313 // Set in |Init()| and never changed (hence usable on any thread without | 314 // Set in |Init()| and never changed (hence usable on any thread without |
314 // locking): | 315 // locking): |
315 base::MessageLoopForIO* message_loop_for_io_; | 316 base::MessageLoopForIO* message_loop_for_io_; |
316 | 317 |
317 // Only used on the I/O thread: | 318 // Only used on the I/O thread: |
318 Delegate* delegate_; | 319 Delegate* delegate_; |
319 bool* set_on_shutdown_; | 320 bool* set_on_shutdown_; |
320 scoped_ptr<ReadBuffer> read_buffer_; | 321 std::unique_ptr<ReadBuffer> read_buffer_; |
321 | 322 |
322 Mutex write_mutex_; // Protects the following members. | 323 Mutex write_mutex_; // Protects the following members. |
323 bool write_stopped_ MOJO_GUARDED_BY(write_mutex_); | 324 bool write_stopped_ MOJO_GUARDED_BY(write_mutex_); |
324 scoped_ptr<WriteBuffer> write_buffer_ MOJO_GUARDED_BY(write_mutex_); | 325 std::unique_ptr<WriteBuffer> write_buffer_ MOJO_GUARDED_BY(write_mutex_); |
325 | 326 |
326 // This is used for posting tasks from write threads to the I/O thread. The | 327 // This is used for posting tasks from write threads to the I/O thread. The |
327 // weak pointers it produces are only used/invalidated on the I/O thread. | 328 // weak pointers it produces are only used/invalidated on the I/O thread. |
328 base::WeakPtrFactory<RawChannel> weak_ptr_factory_ | 329 base::WeakPtrFactory<RawChannel> weak_ptr_factory_ |
329 MOJO_GUARDED_BY(write_mutex_); | 330 MOJO_GUARDED_BY(write_mutex_); |
330 | 331 |
331 MOJO_DISALLOW_COPY_AND_ASSIGN(RawChannel); | 332 MOJO_DISALLOW_COPY_AND_ASSIGN(RawChannel); |
332 }; | 333 }; |
333 | 334 |
334 } // namespace system | 335 } // namespace system |
335 } // namespace mojo | 336 } // namespace mojo |
336 | 337 |
337 #endif // MOJO_EDK_SYSTEM_RAW_CHANNEL_H_ | 338 #endif // MOJO_EDK_SYSTEM_RAW_CHANNEL_H_ |
OLD | NEW |