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

Side by Side Diff: mojo/edk/system/channel_manager.h

Issue 1483823004: EDK: Move {platform_handle,scoped_platform_handle}.* to //mojo/edk/platform. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « mojo/edk/system/channel.cc ('k') | mojo/edk/system/channel_manager.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 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 <unordered_map> 10 #include <unordered_map>
11 11
12 #include "base/callback_forward.h" 12 #include "base/callback_forward.h"
13 #include "mojo/edk/embedder/scoped_platform_handle.h" 13 #include "mojo/edk/platform/scoped_platform_handle.h"
14 #include "mojo/edk/platform/task_runner.h" 14 #include "mojo/edk/platform/task_runner.h"
15 #include "mojo/edk/system/channel_id.h" 15 #include "mojo/edk/system/channel_id.h"
16 #include "mojo/edk/util/mutex.h" 16 #include "mojo/edk/util/mutex.h"
17 #include "mojo/edk/util/ref_ptr.h" 17 #include "mojo/edk/util/ref_ptr.h"
18 #include "mojo/edk/util/thread_annotations.h" 18 #include "mojo/edk/util/thread_annotations.h"
19 #include "mojo/public/cpp/system/macros.h" 19 #include "mojo/public/cpp/system/macros.h"
20 20
21 namespace base { 21 namespace base {
22 class TaskRunner; 22 class TaskRunner;
23 } 23 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 const base::Closure& callback, 67 const base::Closure& callback,
68 util::RefPtr<platform::TaskRunner>&& callback_thread_task_runner); 68 util::RefPtr<platform::TaskRunner>&& callback_thread_task_runner);
69 69
70 // Creates a |Channel| and adds it to the set of channels managed by this 70 // Creates a |Channel| and adds it to the set of channels managed by this
71 // |ChannelManager|. This must be called from the I/O thread (given to the 71 // |ChannelManager|. This must be called from the I/O thread (given to the
72 // constructor). |channel_id| should be a valid |ChannelId| (i.e., nonzero) 72 // constructor). |channel_id| should be a valid |ChannelId| (i.e., nonzero)
73 // not "assigned" to any other |Channel| being managed by this 73 // not "assigned" to any other |Channel| being managed by this
74 // |ChannelManager|. 74 // |ChannelManager|.
75 util::RefPtr<MessagePipeDispatcher> CreateChannelOnIOThread( 75 util::RefPtr<MessagePipeDispatcher> CreateChannelOnIOThread(
76 ChannelId channel_id, 76 ChannelId channel_id,
77 embedder::ScopedPlatformHandle platform_handle); 77 platform::ScopedPlatformHandle platform_handle);
78 78
79 // Like |CreateChannelOnIOThread()|, but doesn't create a bootstrap message 79 // Like |CreateChannelOnIOThread()|, but doesn't create a bootstrap message
80 // pipe. Returns the newly-created |Channel|. 80 // pipe. Returns the newly-created |Channel|.
81 // TODO(vtl): Maybe get rid of the others (and bootstrap message pipes in 81 // TODO(vtl): Maybe get rid of the others (and bootstrap message pipes in
82 // general). 82 // general).
83 util::RefPtr<Channel> CreateChannelWithoutBootstrapOnIOThread( 83 util::RefPtr<Channel> CreateChannelWithoutBootstrapOnIOThread(
84 ChannelId channel_id, 84 ChannelId channel_id,
85 embedder::ScopedPlatformHandle platform_handle); 85 platform::ScopedPlatformHandle platform_handle);
86 86
87 // Like |CreateChannelOnIOThread()|, but may be called from any thread. On 87 // Like |CreateChannelOnIOThread()|, but may be called from any thread. On
88 // completion, will call |callback| (using |callback_thread_task_runner| if it 88 // completion, will call |callback| (using |callback_thread_task_runner| if it
89 // is non-null, else on the I/O thread). Note: This will always post a task to 89 // is non-null, else on the I/O thread). Note: This will always post a task to
90 // the I/O thread, even if called from that thread. 90 // the I/O thread, even if called from that thread.
91 util::RefPtr<MessagePipeDispatcher> CreateChannel( 91 util::RefPtr<MessagePipeDispatcher> CreateChannel(
92 ChannelId channel_id, 92 ChannelId channel_id,
93 embedder::ScopedPlatformHandle platform_handle, 93 platform::ScopedPlatformHandle platform_handle,
94 const base::Closure& callback, 94 const base::Closure& callback,
95 util::RefPtr<platform::TaskRunner>&& callback_thread_task_runner); 95 util::RefPtr<platform::TaskRunner>&& callback_thread_task_runner);
96 96
97 // Gets the |Channel| with the given ID (which must exist). 97 // Gets the |Channel| with the given ID (which must exist).
98 util::RefPtr<Channel> GetChannel(ChannelId channel_id) const; 98 util::RefPtr<Channel> GetChannel(ChannelId channel_id) const;
99 99
100 // Informs the channel manager (and thus channel) that it will be shutdown 100 // Informs the channel manager (and thus channel) that it will be shutdown
101 // soon (by calling |ShutdownChannel()|). Calling this is optional (and may in 101 // soon (by calling |ShutdownChannel()|). Calling this is optional (and may in
102 // fact be called multiple times) but it will suppress certain warnings (e.g., 102 // fact be called multiple times) but it will suppress certain warnings (e.g.,
103 // for the channel being broken) and enable others (if messages are written to 103 // for the channel being broken) and enable others (if messages are written to
(...skipping 23 matching lines...) Expand all
127 // that doesn't work with |base::Bind()|. 127 // that doesn't work with |base::Bind()|.
128 void ShutdownHelper( 128 void ShutdownHelper(
129 const base::Closure& callback, 129 const base::Closure& callback,
130 util::RefPtr<platform::TaskRunner> callback_thread_task_runner); 130 util::RefPtr<platform::TaskRunner> callback_thread_task_runner);
131 131
132 // Used by |CreateChannelOnIOThread()| and |CreateChannelHelper()|. Called on 132 // Used by |CreateChannelOnIOThread()| and |CreateChannelHelper()|. Called on
133 // the I/O thread. |bootstrap_channel_endpoint| is optional and may be null. 133 // the I/O thread. |bootstrap_channel_endpoint| is optional and may be null.
134 // Returns the newly-created |Channel|. 134 // Returns the newly-created |Channel|.
135 util::RefPtr<Channel> CreateChannelOnIOThreadHelper( 135 util::RefPtr<Channel> CreateChannelOnIOThreadHelper(
136 ChannelId channel_id, 136 ChannelId channel_id,
137 embedder::ScopedPlatformHandle platform_handle, 137 platform::ScopedPlatformHandle platform_handle,
138 util::RefPtr<ChannelEndpoint>&& bootstrap_channel_endpoint); 138 util::RefPtr<ChannelEndpoint>&& bootstrap_channel_endpoint);
139 139
140 // Used by |CreateChannel()|. Called on the I/O thread. 140 // Used by |CreateChannel()|. Called on the I/O thread.
141 // TODO(vtl): |bootstrap_channel_endpoint| and |callback_thread_task_runner| 141 // TODO(vtl): |bootstrap_channel_endpoint| and |callback_thread_task_runner|
142 // should be rvalue references, but that doesn't currently work correctly with 142 // should be rvalue references, but that doesn't currently work correctly with
143 // base::Bind. 143 // base::Bind.
144 void CreateChannelHelper( 144 void CreateChannelHelper(
145 ChannelId channel_id, 145 ChannelId channel_id,
146 embedder::ScopedPlatformHandle platform_handle, 146 platform::ScopedPlatformHandle platform_handle,
147 util::RefPtr<ChannelEndpoint> bootstrap_channel_endpoint, 147 util::RefPtr<ChannelEndpoint> bootstrap_channel_endpoint,
148 const base::Closure& callback, 148 const base::Closure& callback,
149 util::RefPtr<platform::TaskRunner> callback_thread_task_runner); 149 util::RefPtr<platform::TaskRunner> callback_thread_task_runner);
150 150
151 // Note: These must not be used after shutdown. 151 // Note: These must not be used after shutdown.
152 embedder::PlatformSupport* const platform_support_; 152 embedder::PlatformSupport* const platform_support_;
153 const util::RefPtr<platform::TaskRunner> io_thread_task_runner_; 153 const util::RefPtr<platform::TaskRunner> io_thread_task_runner_;
154 ConnectionManager* const connection_manager_; 154 ConnectionManager* const connection_manager_;
155 155
156 // Note: |Channel| methods should not be called under |mutex_|. 156 // Note: |Channel| methods should not be called under |mutex_|.
157 // TODO(vtl): Annotate the above rule using |MOJO_ACQUIRED_{BEFORE,AFTER}()|, 157 // TODO(vtl): Annotate the above rule using |MOJO_ACQUIRED_{BEFORE,AFTER}()|,
158 // once clang actually checks such annotations. 158 // once clang actually checks such annotations.
159 // https://github.com/domokit/mojo/issues/313 159 // https://github.com/domokit/mojo/issues/313
160 mutable util::Mutex mutex_; 160 mutable util::Mutex mutex_;
161 161
162 using ChannelIdToChannelMap = 162 using ChannelIdToChannelMap =
163 std::unordered_map<ChannelId, util::RefPtr<Channel>>; 163 std::unordered_map<ChannelId, util::RefPtr<Channel>>;
164 ChannelIdToChannelMap channels_ MOJO_GUARDED_BY(mutex_); 164 ChannelIdToChannelMap channels_ MOJO_GUARDED_BY(mutex_);
165 165
166 MOJO_DISALLOW_COPY_AND_ASSIGN(ChannelManager); 166 MOJO_DISALLOW_COPY_AND_ASSIGN(ChannelManager);
167 }; 167 };
168 168
169 } // namespace system 169 } // namespace system
170 } // namespace mojo 170 } // namespace mojo
171 171
172 #endif // MOJO_EDK_SYSTEM_CHANNEL_MANAGER_H_ 172 #endif // MOJO_EDK_SYSTEM_CHANNEL_MANAGER_H_
OLDNEW
« no previous file with comments | « mojo/edk/system/channel.cc ('k') | mojo/edk/system/channel_manager.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698