| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_CHANNEL_MANAGER_H_ | 5 #ifndef MOJO_EDK_SYSTEM_CHANNEL_MANAGER_H_ |
| 6 #define MOJO_EDK_SYSTEM_CHANNEL_MANAGER_H_ | 6 #define MOJO_EDK_SYSTEM_CHANNEL_MANAGER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <functional> | 10 #include <functional> |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 namespace base { | 21 namespace base { |
| 22 class TaskRunner; | 22 class TaskRunner; |
| 23 } | 23 } |
| 24 | 24 |
| 25 namespace mojo { | 25 namespace mojo { |
| 26 | 26 |
| 27 namespace embedder { | 27 namespace embedder { |
| 28 class PlatformSupport; | 28 class PlatformSupport; |
| 29 } | 29 } |
| 30 | 30 |
| 31 namespace platform { |
| 32 class PlatformHandleWatcher; |
| 33 } |
| 34 |
| 31 namespace system { | 35 namespace system { |
| 32 | 36 |
| 33 class Channel; | 37 class Channel; |
| 34 class ChannelEndpoint; | 38 class ChannelEndpoint; |
| 35 class ConnectionManager; | 39 class ConnectionManager; |
| 36 class MessagePipeDispatcher; | 40 class MessagePipeDispatcher; |
| 37 | 41 |
| 38 // This class manages and "owns" |Channel|s (which typically connect to other | 42 // This class manages and "owns" |Channel|s (which typically connect to other |
| 39 // processes) for a given process. This class is thread-safe, except as | 43 // processes) for a given process. This class is thread-safe, except as |
| 40 // specifically noted. | 44 // specifically noted. |
| 41 class ChannelManager { | 45 class ChannelManager { |
| 42 public: | 46 public: |
| 43 // |io_thread_task_runner| should be the |TaskRunner| for the I/O thread, on | 47 // |io_task_runner| and |io_watcher| should be the |TaskRunner| and |
| 44 // which this channel manager will create all channels. Connection manager is | 48 // |PlatformHandleWatcher|, respectively, for the I/O thread, on which this |
| 45 // optional and may be null. All arguments (if non-null) must remain alive at | 49 // channel manager will create all channels. |connection_manager| is optional |
| 46 // least until after shutdown completion. | 50 // and may be null. All arguments (if non-null) must remain alive at least |
| 51 // until after shutdown completion. |
| 47 ChannelManager(embedder::PlatformSupport* platform_support, | 52 ChannelManager(embedder::PlatformSupport* platform_support, |
| 48 util::RefPtr<platform::TaskRunner>&& io_thread_task_runner, | 53 util::RefPtr<platform::TaskRunner>&& io_task_runner, |
| 54 platform::PlatformHandleWatcher* io_watcher, |
| 49 ConnectionManager* connection_manager); | 55 ConnectionManager* connection_manager); |
| 50 ~ChannelManager(); | 56 ~ChannelManager(); |
| 51 | 57 |
| 52 // Shuts down the channel manager, including shutting down all channels (as if | 58 // Shuts down the channel manager, including shutting down all channels (as if |
| 53 // |ShutdownChannelOnIOThread()| were called for each channel). This must be | 59 // |ShutdownChannelOnIOThread()| were called for each channel). This must be |
| 54 // called from the I/O thread (given to the constructor) and completes | 60 // called from the I/O thread (given to the constructor) and completes |
| 55 // synchronously. This, or |Shutdown()|, must be called before destroying this | 61 // synchronously. This, or |Shutdown()|, must be called before destroying this |
| 56 // object. | 62 // object. |
| 57 void ShutdownOnIOThread(); | 63 void ShutdownOnIOThread(); |
| 58 | 64 |
| 59 // Like |ShutdownOnIOThread()|, but may be called from any thread. On | 65 // Like |ShutdownOnIOThread()|, but may be called from any thread. On |
| 60 // completion, will call |callback| ("on" |io_thread_task_runner| if | 66 // completion, will call |callback| ("on" |io_task_runner| if |
| 61 // |callback_thread_task_runner| is null else by posted using | 67 // |callback_thread_task_runner| is null else by posted using |
| 62 // |callback_thread_task_runner|). Note: This will always post a task to the | 68 // |callback_thread_task_runner|). Note: This will always post a task to the |
| 63 // I/O thread, even it is the current thread. | 69 // I/O thread, even it is the current thread. |
| 64 // TODO(vtl): Consider if this is really necessary, since it only has one use | 70 // TODO(vtl): Consider if this is really necessary, since it only has one use |
| 65 // (in tests). | 71 // (in tests). |
| 66 void Shutdown( | 72 void Shutdown( |
| 67 std::function<void()>&& callback, | 73 std::function<void()>&& callback, |
| 68 util::RefPtr<platform::TaskRunner>&& callback_thread_task_runner); | 74 util::RefPtr<platform::TaskRunner>&& callback_thread_task_runner); |
| 69 | 75 |
| 70 // Creates a |Channel| and adds it to the set of channels managed by this | 76 // Creates a |Channel| and adds it to the set of channels managed by this |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 // Used by |CreateChannelOnIOThread()| and |CreateChannel()|. Called on the | 131 // Used by |CreateChannelOnIOThread()| and |CreateChannel()|. Called on the |
| 126 // I/O thread. |bootstrap_channel_endpoint| is optional and may be null. | 132 // I/O thread. |bootstrap_channel_endpoint| is optional and may be null. |
| 127 // Returns the newly-created |Channel|. | 133 // Returns the newly-created |Channel|. |
| 128 util::RefPtr<Channel> CreateChannelOnIOThreadHelper( | 134 util::RefPtr<Channel> CreateChannelOnIOThreadHelper( |
| 129 ChannelId channel_id, | 135 ChannelId channel_id, |
| 130 platform::ScopedPlatformHandle platform_handle, | 136 platform::ScopedPlatformHandle platform_handle, |
| 131 util::RefPtr<ChannelEndpoint>&& bootstrap_channel_endpoint); | 137 util::RefPtr<ChannelEndpoint>&& bootstrap_channel_endpoint); |
| 132 | 138 |
| 133 // Note: These must not be used after shutdown. | 139 // Note: These must not be used after shutdown. |
| 134 embedder::PlatformSupport* const platform_support_; | 140 embedder::PlatformSupport* const platform_support_; |
| 135 const util::RefPtr<platform::TaskRunner> io_thread_task_runner_; | 141 const util::RefPtr<platform::TaskRunner> io_task_runner_; |
| 142 platform::PlatformHandleWatcher* const io_watcher_; |
| 136 ConnectionManager* const connection_manager_; | 143 ConnectionManager* const connection_manager_; |
| 137 | 144 |
| 138 // Note: |Channel| methods should not be called under |mutex_|. | 145 // Note: |Channel| methods should not be called under |mutex_|. |
| 139 // TODO(vtl): Annotate the above rule using |MOJO_ACQUIRED_{BEFORE,AFTER}()|, | 146 // TODO(vtl): Annotate the above rule using |MOJO_ACQUIRED_{BEFORE,AFTER}()|, |
| 140 // once clang actually checks such annotations. | 147 // once clang actually checks such annotations. |
| 141 // https://github.com/domokit/mojo/issues/313 | 148 // https://github.com/domokit/mojo/issues/313 |
| 142 mutable util::Mutex mutex_; | 149 mutable util::Mutex mutex_; |
| 143 | 150 |
| 144 using ChannelIdToChannelMap = | 151 using ChannelIdToChannelMap = |
| 145 std::unordered_map<ChannelId, util::RefPtr<Channel>>; | 152 std::unordered_map<ChannelId, util::RefPtr<Channel>>; |
| 146 ChannelIdToChannelMap channels_ MOJO_GUARDED_BY(mutex_); | 153 ChannelIdToChannelMap channels_ MOJO_GUARDED_BY(mutex_); |
| 147 | 154 |
| 148 MOJO_DISALLOW_COPY_AND_ASSIGN(ChannelManager); | 155 MOJO_DISALLOW_COPY_AND_ASSIGN(ChannelManager); |
| 149 }; | 156 }; |
| 150 | 157 |
| 151 } // namespace system | 158 } // namespace system |
| 152 } // namespace mojo | 159 } // namespace mojo |
| 153 | 160 |
| 154 #endif // MOJO_EDK_SYSTEM_CHANNEL_MANAGER_H_ | 161 #endif // MOJO_EDK_SYSTEM_CHANNEL_MANAGER_H_ |
| OLD | NEW |