| 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 <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 12 #include "mojo/edk/platform/platform_handle.h" | 12 #include "mojo/edk/platform/platform_handle.h" |
| 13 #include "mojo/edk/platform/platform_handle_watcher.h" |
| 13 #include "mojo/edk/platform/scoped_platform_handle.h" | 14 #include "mojo/edk/platform/scoped_platform_handle.h" |
| 15 #include "mojo/edk/platform/task_runner.h" |
| 14 #include "mojo/edk/system/message_in_transit.h" | 16 #include "mojo/edk/system/message_in_transit.h" |
| 15 #include "mojo/edk/system/message_in_transit_queue.h" | 17 #include "mojo/edk/system/message_in_transit_queue.h" |
| 16 #include "mojo/edk/util/mutex.h" | 18 #include "mojo/edk/util/mutex.h" |
| 19 #include "mojo/edk/util/ref_ptr.h" |
| 17 #include "mojo/edk/util/thread_annotations.h" | 20 #include "mojo/edk/util/thread_annotations.h" |
| 18 #include "mojo/public/cpp/system/macros.h" | 21 #include "mojo/public/cpp/system/macros.h" |
| 19 | 22 |
| 20 namespace base { | 23 namespace base { |
| 21 class MessageLoopForIO; | 24 class MessageLoopForIO; |
| 22 } | 25 } |
| 23 | 26 |
| 24 namespace mojo { | 27 namespace mojo { |
| 25 namespace system { | 28 namespace system { |
| 26 | 29 |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 // Static factory method. |handle| should be a handle to a | 88 // Static factory method. |handle| should be a handle to a |
| 86 // (platform-appropriate) bidirectional communication channel (e.g., a socket | 89 // (platform-appropriate) bidirectional communication channel (e.g., a socket |
| 87 // on POSIX, a named pipe on Windows). | 90 // on POSIX, a named pipe on Windows). |
| 88 static std::unique_ptr<RawChannel> Create( | 91 static std::unique_ptr<RawChannel> Create( |
| 89 platform::ScopedPlatformHandle handle); | 92 platform::ScopedPlatformHandle handle); |
| 90 | 93 |
| 91 // This must be called (on an I/O thread) before this object is used. Does | 94 // This must be called (on an I/O thread) before this object is used. Does |
| 92 // *not* take ownership of |delegate|. Both the I/O thread and |delegate| must | 95 // *not* take ownership of |delegate|. Both the I/O thread and |delegate| must |
| 93 // remain alive until |Shutdown()| is called (unless this fails); |delegate| | 96 // remain alive until |Shutdown()| is called (unless this fails); |delegate| |
| 94 // will no longer be used after |Shutdown()|. | 97 // will no longer be used after |Shutdown()|. |
| 95 void Init(Delegate* delegate) MOJO_NOT_THREAD_SAFE; | 98 void Init(util::RefPtr<platform::TaskRunner>&& io_task_runner, |
| 99 platform::PlatformHandleWatcher* io_watcher, |
| 100 Delegate* delegate) MOJO_NOT_THREAD_SAFE; |
| 96 | 101 |
| 97 // This must be called (on the I/O thread) before this object is destroyed. | 102 // This must be called (on the I/O thread) before this object is destroyed. |
| 98 void Shutdown() MOJO_NOT_THREAD_SAFE; | 103 void Shutdown() MOJO_NOT_THREAD_SAFE; |
| 99 | 104 |
| 100 // Writes the given message (or schedules it to be written). |message| must | 105 // Writes the given message (or schedules it to be written). |message| must |
| 101 // have no |Dispatcher|s still attached (i.e., | 106 // have no |Dispatcher|s still attached (i.e., |
| 102 // |SerializeAndCloseDispatchers()| should have been called). This method is | 107 // |SerializeAndCloseDispatchers()| should have been called). This method is |
| 103 // thread-safe and may be called from any thread. Returns true on success. | 108 // thread-safe and may be called from any thread. Returns true on success. |
| 104 bool WriteMessage(std::unique_ptr<MessageInTransit> message); | 109 bool WriteMessage(std::unique_ptr<MessageInTransit> message); |
| 105 | 110 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 // write operation to run later if there is more to write. If |io_result| is | 314 // write operation to run later if there is more to write. If |io_result| is |
| 310 // failure or any other error occurs, cancels pending writes and returns | 315 // failure or any other error occurs, cancels pending writes and returns |
| 311 // false. May only be called if |write_stopped_| is false. | 316 // false. May only be called if |write_stopped_| is false. |
| 312 bool OnWriteCompletedNoLock(IOResult io_result, | 317 bool OnWriteCompletedNoLock(IOResult io_result, |
| 313 size_t platform_handles_written, | 318 size_t platform_handles_written, |
| 314 size_t bytes_written) | 319 size_t bytes_written) |
| 315 MOJO_EXCLUSIVE_LOCKS_REQUIRED(write_mutex_); | 320 MOJO_EXCLUSIVE_LOCKS_REQUIRED(write_mutex_); |
| 316 | 321 |
| 317 // Set in |Init()| and never changed (hence usable on any thread without | 322 // Set in |Init()| and never changed (hence usable on any thread without |
| 318 // locking): | 323 // locking): |
| 324 util::RefPtr<platform::TaskRunner> io_task_runner_; |
| 325 // TODO(vtl): Remove this, once RawChannelPosix has been converted. |
| 319 base::MessageLoopForIO* message_loop_for_io_; | 326 base::MessageLoopForIO* message_loop_for_io_; |
| 320 | 327 |
| 321 // Only used on the I/O thread: | 328 // Only used on the I/O thread: |
| 329 platform::PlatformHandleWatcher* io_watcher_; |
| 322 Delegate* delegate_; | 330 Delegate* delegate_; |
| 323 bool* set_on_shutdown_; | 331 bool* set_on_shutdown_; |
| 324 std::unique_ptr<ReadBuffer> read_buffer_; | 332 std::unique_ptr<ReadBuffer> read_buffer_; |
| 325 | 333 |
| 326 util::Mutex write_mutex_; // Protects the following members. | 334 util::Mutex write_mutex_; // Protects the following members. |
| 327 bool write_stopped_ MOJO_GUARDED_BY(write_mutex_); | 335 bool write_stopped_ MOJO_GUARDED_BY(write_mutex_); |
| 328 std::unique_ptr<WriteBuffer> write_buffer_ MOJO_GUARDED_BY(write_mutex_); | 336 std::unique_ptr<WriteBuffer> write_buffer_ MOJO_GUARDED_BY(write_mutex_); |
| 329 | 337 |
| 330 // This is used for posting tasks from write threads to the I/O thread. The | 338 // This is used for posting tasks from write threads to the I/O thread. The |
| 331 // weak pointers it produces are only used/invalidated on the I/O thread. | 339 // weak pointers it produces are only used/invalidated on the I/O thread. |
| 332 base::WeakPtrFactory<RawChannel> weak_ptr_factory_ | 340 base::WeakPtrFactory<RawChannel> weak_ptr_factory_ |
| 333 MOJO_GUARDED_BY(write_mutex_); | 341 MOJO_GUARDED_BY(write_mutex_); |
| 334 | 342 |
| 335 MOJO_DISALLOW_COPY_AND_ASSIGN(RawChannel); | 343 MOJO_DISALLOW_COPY_AND_ASSIGN(RawChannel); |
| 336 }; | 344 }; |
| 337 | 345 |
| 338 } // namespace system | 346 } // namespace system |
| 339 } // namespace mojo | 347 } // namespace mojo |
| 340 | 348 |
| 341 #endif // MOJO_EDK_SYSTEM_RAW_CHANNEL_H_ | 349 #endif // MOJO_EDK_SYSTEM_RAW_CHANNEL_H_ |
| OLD | NEW |