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

Side by Side Diff: mojo/system/dispatcher.h

Issue 265753006: Mojo: Factor MessageInTransit secondary buffer stuff out into a separate class. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: oops Created 6 years, 7 months 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 | Annotate | Revision Log
« no previous file with comments | « mojo/system/channel.cc ('k') | mojo/system/dispatcher.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 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_SYSTEM_DISPATCHER_H_ 5 #ifndef MOJO_SYSTEM_DISPATCHER_H_
6 #define MOJO_SYSTEM_DISPATCHER_H_ 6 #define MOJO_SYSTEM_DISPATCHER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/synchronization/lock.h" 16 #include "base/synchronization/lock.h"
17 #include "mojo/embedder/platform_handle.h" 17 #include "mojo/embedder/platform_handle.h"
18 #include "mojo/public/c/system/core.h" 18 #include "mojo/public/c/system/core.h"
19 #include "mojo/system/system_impl_export.h" 19 #include "mojo/system/system_impl_export.h"
20 20
21 namespace mojo { 21 namespace mojo {
22 namespace system { 22 namespace system {
23 23
24 class Channel; 24 class Channel;
25 class Core; 25 class Core;
26 class Dispatcher; 26 class Dispatcher;
27 class DispatcherTransport; 27 class DispatcherTransport;
28 class HandleTable; 28 class HandleTable;
29 class LocalMessagePipeEndpoint; 29 class LocalMessagePipeEndpoint;
30 class MessageInTransit;
31 class ProxyMessagePipeEndpoint; 30 class ProxyMessagePipeEndpoint;
32 class RawSharedBufferMapping; 31 class RawSharedBufferMapping;
32 class TransportData;
33 class Waiter; 33 class Waiter;
34 34
35 namespace test { 35 namespace test {
36 36
37 // Test helper. We need to declare it here so we can friend it. 37 // Test helper. We need to declare it here so we can friend it.
38 MOJO_SYSTEM_IMPL_EXPORT DispatcherTransport DispatcherTryStartTransport( 38 MOJO_SYSTEM_IMPL_EXPORT DispatcherTransport DispatcherTryStartTransport(
39 Dispatcher* dispatcher); 39 Dispatcher* dispatcher);
40 40
41 } // namespace test 41 } // namespace test
42 42
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 friend class HandleTable; 139 friend class HandleTable;
140 // Tests also need this, to avoid needing |Core|. 140 // Tests also need this, to avoid needing |Core|.
141 friend DispatcherTransport test::DispatcherTryStartTransport(Dispatcher*); 141 friend DispatcherTransport test::DispatcherTryStartTransport(Dispatcher*);
142 142
143 // This must be called under the handle table lock and only if the handle 143 // This must be called under the handle table lock and only if the handle
144 // table entry is not marked busy. The caller must maintain a reference to 144 // table entry is not marked busy. The caller must maintain a reference to
145 // |dispatcher| until |DispatcherTransport::End()| is called. 145 // |dispatcher| until |DispatcherTransport::End()| is called.
146 static DispatcherTransport TryStartTransport(Dispatcher* dispatcher); 146 static DispatcherTransport TryStartTransport(Dispatcher* dispatcher);
147 }; 147 };
148 148
149 // A |MessageInTransit| may serialize dispatchers that are attached to it to a 149 // A |TransportData| may serialize dispatchers that are given to it (and which
150 // given |Channel| and then (probably in a different process) deserialize. 150 // were previously attached to the |MessageInTransit| that is creating it) to
151 // a given |Channel| and then (probably in a different process) deserialize.
151 // Note that the |MessageInTransit| "owns" (i.e., has the only ref to) these 152 // Note that the |MessageInTransit| "owns" (i.e., has the only ref to) these
152 // dispatchers, so there are no locking issues. (There's no lock ordering 153 // dispatchers, so there are no locking issues. (There's no lock ordering
153 // issue, and in fact no need to take dispatcher locks at all.) 154 // issue, and in fact no need to take dispatcher locks at all.)
154 // TODO(vtl): Consider making another wrapper similar to |DispatcherTransport| 155 // TODO(vtl): Consider making another wrapper similar to |DispatcherTransport|
155 // (but with an owning, unique reference), and having 156 // (but with an owning, unique reference), and having
156 // |CreateEquivalentDispatcherAndCloseImplNoLock()| return that wrapper (and 157 // |CreateEquivalentDispatcherAndCloseImplNoLock()| return that wrapper (and
157 // |MessageInTransit| only holding on to such wrappers). 158 // |MessageInTransit|, etc. only holding on to such wrappers).
158 class MessageInTransitAccess { 159 class TransportDataAccess {
159 private: 160 private:
160 friend class MessageInTransit; 161 friend class TransportData;
161 162
162 // Serialization API. These functions may only be called on such 163 // Serialization API. These functions may only be called on such
163 // dispatchers. (|channel| is the |Channel| to which the dispatcher is to be 164 // dispatchers. (|channel| is the |Channel| to which the dispatcher is to be
164 // serialized.) See the |Dispatcher| methods of the same names for more 165 // serialized.) See the |Dispatcher| methods of the same names for more
165 // details. 166 // details.
166 static void StartSerialize(Dispatcher* dispatcher, 167 static void StartSerialize(Dispatcher* dispatcher,
167 Channel* channel, 168 Channel* channel,
168 size_t* max_size, 169 size_t* max_size,
169 size_t* max_platform_handles); 170 size_t* max_platform_handles);
170 static bool EndSerializeAndClose( 171 static bool EndSerializeAndClose(
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
279 void CloseNoLock(); 280 void CloseNoLock();
280 281
281 // Creates an equivalent dispatcher -- representing the same resource as this 282 // Creates an equivalent dispatcher -- representing the same resource as this
282 // dispatcher -- and close (i.e., disable) this dispatcher. I.e., this 283 // dispatcher -- and close (i.e., disable) this dispatcher. I.e., this
283 // dispatcher will look as though it was closed, but the resource it 284 // dispatcher will look as though it was closed, but the resource it
284 // represents will be assigned to the new dispatcher. This must be called 285 // represents will be assigned to the new dispatcher. This must be called
285 // under the dispatcher's lock. 286 // under the dispatcher's lock.
286 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseNoLock(); 287 scoped_refptr<Dispatcher> CreateEquivalentDispatcherAndCloseNoLock();
287 288
288 // API to serialize dispatchers to a |Channel|, exposed to only 289 // API to serialize dispatchers to a |Channel|, exposed to only
289 // |MessageInTransit| (via |MessageInTransitAccess|). They may only be called 290 // |TransportData| (via |TransportData|). They may only be called on a
290 // on a dispatcher attached to a |MessageInTransit| (and in particular not in 291 // dispatcher attached to a |MessageInTransit| (and in particular not in
291 // |CoreImpl|'s handle table). 292 // |CoreImpl|'s handle table).
292 // 293 //
293 // Starts the serialization. Returns (via the two "out" parameters) the 294 // Starts the serialization. Returns (via the two "out" parameters) the
294 // maximum amount of space that may be needed to serialize this dispatcher to 295 // maximum amount of space that may be needed to serialize this dispatcher to
295 // the given |Channel| (no more than 296 // the given |Channel| (no more than
296 // |MessageInTransit::kMaxSerializedDispatcherSize|) and the maximum number of 297 // |TransportData::kMaxSerializedDispatcherSize|) and the maximum number of
297 // |PlatformHandle|s that may need to be attached (no more than 298 // |PlatformHandle|s that may need to be attached (no more than
298 // |MessageInTransit::kMaxSerializedDispatcherPlatformHandles|). If this 299 // |TransportData::kMaxSerializedDispatcherPlatformHandles|). If this
299 // dispatcher cannot be serialized to the given |Channel|, |*max_size| and 300 // dispatcher cannot be serialized to the given |Channel|, |*max_size| and
300 // |*max_platform_handles| should be set to zero. A call to this method will 301 // |*max_platform_handles| should be set to zero. A call to this method will
301 // ALWAYS be followed by a call to |EndSerializeAndClose()| (even if this 302 // ALWAYS be followed by a call to |EndSerializeAndClose()| (even if this
302 // dispatcher cannot be serialized to the given |Channel|). 303 // dispatcher cannot be serialized to the given |Channel|).
303 void StartSerialize(Channel* channel, 304 void StartSerialize(Channel* channel,
304 size_t* max_size, 305 size_t* max_size,
305 size_t* max_platform_handles); 306 size_t* max_platform_handles);
306 // Completes the serialization of this dispatcher to the given |Channel| and 307 // Completes the serialization of this dispatcher to the given |Channel| and
307 // closes it. (This call will always follow an earlier call to 308 // closes it. (This call will always follow an earlier call to
308 // |StartSerialize()|, with the same |Channel|.) This does so by writing to 309 // |StartSerialize()|, with the same |Channel|.) This does so by writing to
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 361
361 Dispatcher* dispatcher_; 362 Dispatcher* dispatcher_;
362 363
363 // Copy and assign allowed. 364 // Copy and assign allowed.
364 }; 365 };
365 366
366 } // namespace system 367 } // namespace system
367 } // namespace mojo 368 } // namespace mojo
368 369
369 #endif // MOJO_SYSTEM_DISPATCHER_H_ 370 #endif // MOJO_SYSTEM_DISPATCHER_H_
OLDNEW
« no previous file with comments | « mojo/system/channel.cc ('k') | mojo/system/dispatcher.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698