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

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

Issue 1488853002: Add multiplexing of message pipes in the new EDK. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: tsepez review comments 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/raw_channel_unittest.cc ('k') | mojo/edk/system/routed_raw_channel.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef MOJO_EDK_SYSTEM_ROUTED_RAW_CHANNEL_H_
6 #define MOJO_EDK_SYSTEM_ROUTED_RAW_CHANNEL_H_
7
8 #include "base/callback.h"
9 #include "base/containers/hash_tables.h"
10 #include "base/macros.h"
11 #include "base/synchronization/lock.h"
12 #include "mojo/edk/embedder/platform_handle_vector.h"
13 #include "mojo/edk/embedder/scoped_platform_handle.h"
14 #include "mojo/edk/system/broker.h"
15 #include "mojo/edk/system/raw_channel.h"
16 #include "mojo/edk/system/system_impl_export.h"
17
18 namespace mojo {
19 namespace edk {
20 class RawChannel;
21
22 // This class wraps a RawChannel and adds routing on top of it.
23 // Non-transferable MessagePipeDispatchers call here, indirectly through the
24 // Broker interface, to associate with their pipe_id.
25 class RoutedRawChannel : public RawChannel::Delegate {
26 public:
27 RoutedRawChannel(
28 ScopedPlatformHandle handle,
29 const base::Callback<void(RoutedRawChannel*)>& destruct_callback);
30
31 // Connect the given |pipe| with the pipe_id route. Only non-transferable
32 // message pipes can call this, and they can only call it once.
33 void AddRoute(uint64_t pipe_id, MessagePipeDispatcher* pipe);
34
35 // Called when the MessagePipeDispatcher is going away.
36 void RemoveRoute(uint64_t pipe_id, MessagePipeDispatcher* pipe);
37
38 RawChannel* channel() { return channel_; }
39
40 private:
41 friend class base::DeleteHelper<RoutedRawChannel>;
42 ~RoutedRawChannel() override;
43
44 // RawChannel::Delegate implementation:
45 void OnReadMessage(
46 const MessageInTransit::View& message_view,
47 ScopedPlatformHandleVectorPtr platform_handles) override;
48 void OnError(Error error) override;
49
50 RawChannel* channel_;
51
52 base::Lock lock_; // Guards access to below.
53 base::hash_map<uint64_t, MessagePipeDispatcher*> routes_;
54
55 // If we got messages before the route was added (due to race conditions
56 // between different channels), this is used to buffer them.
57 struct PendingMessage {
58 PendingMessage();
59 ~PendingMessage();
60 std::vector<char> message;
61 ScopedPlatformHandleVectorPtr handles;
62 };
63 std::vector<scoped_ptr<PendingMessage>> pending_messages_;
64
65 // If we got a ROUTE_CLOSED message for a route before it registered with us,
66 // we need to hold on to this information so that we can tell it that the
67 // connetion is closed when it does connect.
68 base::hash_set<uint64_t> close_routes_;
69
70 base::Callback<void(RoutedRawChannel*)> destruct_callback_;
71
72 DISALLOW_COPY_AND_ASSIGN(RoutedRawChannel);
73 };
74
75 } // namespace edk
76 } // namespace mojo
77
78 #endif // MOJO_EDK_SYSTEM_ROUTED_RAW_CHANNEL_H_
OLDNEW
« no previous file with comments | « mojo/edk/system/raw_channel_unittest.cc ('k') | mojo/edk/system/routed_raw_channel.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698