| 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 <deque> | 8 #include <deque> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 // Static factory method. |handle| should be a handle to a | 82 // Static factory method. |handle| should be a handle to a |
| 83 // (platform-appropriate) bidirectional communication channel (e.g., a socket | 83 // (platform-appropriate) bidirectional communication channel (e.g., a socket |
| 84 // on POSIX, a named pipe on Windows). | 84 // on POSIX, a named pipe on Windows). |
| 85 static scoped_ptr<RawChannel> Create(embedder::ScopedPlatformHandle handle); | 85 static scoped_ptr<RawChannel> Create(embedder::ScopedPlatformHandle handle); |
| 86 | 86 |
| 87 // This must be called (on an I/O thread) before this object is used. Does | 87 // This must be called (on an I/O thread) before this object is used. Does |
| 88 // *not* take ownership of |delegate|. Both the I/O thread and |delegate| must | 88 // *not* take ownership of |delegate|. Both the I/O thread and |delegate| must |
| 89 // remain alive until |Shutdown()| is called (unless this fails); |delegate| | 89 // remain alive until |Shutdown()| is called (unless this fails); |delegate| |
| 90 // will no longer be used after |Shutdown()|. Returns true on success. On | 90 // will no longer be used after |Shutdown()|. |
| 91 // failure, |Shutdown()| should *not* be called. | 91 void Init(Delegate* delegate); |
| 92 bool Init(Delegate* delegate); | |
| 93 | 92 |
| 94 // This must be called (on the I/O thread) before this object is destroyed. | 93 // This must be called (on the I/O thread) before this object is destroyed. |
| 95 void Shutdown(); | 94 void Shutdown(); |
| 96 | 95 |
| 97 // Writes the given message (or schedules it to be written). |message| must | 96 // Writes the given message (or schedules it to be written). |message| must |
| 98 // have no |Dispatcher|s still attached (i.e., | 97 // have no |Dispatcher|s still attached (i.e., |
| 99 // |SerializeAndCloseDispatchers()| should have been called). This method is | 98 // |SerializeAndCloseDispatchers()| should have been called). This method is |
| 100 // thread-safe and may be called from any thread. Returns true on success. | 99 // thread-safe and may be called from any thread. Returns true on success. |
| 101 bool WriteMessage(scoped_ptr<MessageInTransit> message); | 100 bool WriteMessage(scoped_ptr<MessageInTransit> message); |
| 102 | 101 |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 // - if the method returns |IO_PENDING|, |OnWriteCompleted()| will be called | 271 // - if the method returns |IO_PENDING|, |OnWriteCompleted()| will be called |
| 273 // on the I/O thread to report the result, unless |Shutdown()| is called. | 272 // on the I/O thread to report the result, unless |Shutdown()| is called. |
| 274 virtual IOResult WriteNoLock(size_t* platform_handles_written, | 273 virtual IOResult WriteNoLock(size_t* platform_handles_written, |
| 275 size_t* bytes_written) = 0; | 274 size_t* bytes_written) = 0; |
| 276 // Similar to |WriteNoLock()|, except that the implementing subclass must also | 275 // Similar to |WriteNoLock()|, except that the implementing subclass must also |
| 277 // guarantee that the method doesn't succeed synchronously, i.e., it only | 276 // guarantee that the method doesn't succeed synchronously, i.e., it only |
| 278 // returns |IO_FAILED_...| or |IO_PENDING|. | 277 // returns |IO_FAILED_...| or |IO_PENDING|. |
| 279 virtual IOResult ScheduleWriteNoLock() = 0; | 278 virtual IOResult ScheduleWriteNoLock() = 0; |
| 280 | 279 |
| 281 // Must be called on the I/O thread WITHOUT |write_lock_| held. | 280 // Must be called on the I/O thread WITHOUT |write_lock_| held. |
| 282 virtual bool OnInit() = 0; | 281 virtual void OnInit() = 0; |
| 283 // On shutdown, passes the ownership of the buffers to subclasses, which may | 282 // On shutdown, passes the ownership of the buffers to subclasses, which may |
| 284 // want to preserve them if there are pending read/write. Must be called on | 283 // want to preserve them if there are pending read/write. Must be called on |
| 285 // the I/O thread under |write_lock_|. | 284 // the I/O thread under |write_lock_|. |
| 286 virtual void OnShutdownNoLock(scoped_ptr<ReadBuffer> read_buffer, | 285 virtual void OnShutdownNoLock(scoped_ptr<ReadBuffer> read_buffer, |
| 287 scoped_ptr<WriteBuffer> write_buffer) = 0; | 286 scoped_ptr<WriteBuffer> write_buffer) = 0; |
| 288 | 287 |
| 289 private: | 288 private: |
| 290 // Converts an |IO_FAILED_...| for a read to a |Delegate::Error|. | 289 // Converts an |IO_FAILED_...| for a read to a |Delegate::Error|. |
| 291 static Delegate::Error ReadIOResultToError(IOResult io_result); | 290 static Delegate::Error ReadIOResultToError(IOResult io_result); |
| 292 | 291 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 321 // are only used/invalidated on the I/O thread. | 320 // are only used/invalidated on the I/O thread. |
| 322 base::WeakPtrFactory<RawChannel> weak_ptr_factory_; | 321 base::WeakPtrFactory<RawChannel> weak_ptr_factory_; |
| 323 | 322 |
| 324 DISALLOW_COPY_AND_ASSIGN(RawChannel); | 323 DISALLOW_COPY_AND_ASSIGN(RawChannel); |
| 325 }; | 324 }; |
| 326 | 325 |
| 327 } // namespace system | 326 } // namespace system |
| 328 } // namespace mojo | 327 } // namespace mojo |
| 329 | 328 |
| 330 #endif // MOJO_EDK_SYSTEM_RAW_CHANNEL_H_ | 329 #endif // MOJO_EDK_SYSTEM_RAW_CHANNEL_H_ |
| OLD | NEW |