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

Side by Side Diff: mojo/edk/system/broker_state.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/broker_messages.h ('k') | mojo/edk/system/broker_state.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 2015 The Chromium Authors. All rights reserved. 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 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_BROKER_STATE_H_ 5 #ifndef MOJO_EDK_SYSTEM_BROKER_STATE_H_
6 #define MOJO_EDK_SYSTEM_BROKER_STATE_H_ 6 #define MOJO_EDK_SYSTEM_BROKER_STATE_H_
7 7
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/containers/hash_tables.h" 9 #include "base/containers/hash_tables.h"
10 #include "base/macros.h"
10 #include "base/memory/singleton.h" 11 #include "base/memory/singleton.h"
12 #include "base/process/process_handle.h"
11 #include "base/synchronization/lock.h" 13 #include "base/synchronization/lock.h"
12 #include "base/threading/thread.h"
13 #include "mojo/edk/embedder/scoped_platform_handle.h" 14 #include "mojo/edk/embedder/scoped_platform_handle.h"
14 #include "mojo/edk/system/broker.h" 15 #include "mojo/edk/system/broker.h"
15 #include "mojo/edk/system/system_impl_export.h" 16 #include "mojo/edk/system/system_impl_export.h"
16 17
17 namespace mojo { 18 namespace mojo {
18 namespace edk { 19 namespace edk {
20 class ChildBrokerHost;
21 class RoutedRawChannel;
19 22
20 // Common broker state that has to live in a parent process. There is one 23 // Common broker state that has to live in a parent process. There is one
21 // instance of this class in the parent process. This class implements the 24 // instance of this class in the parent process. This class implements the
22 // Broker interface for use by code in the parent process as well. 25 // Broker interface for use by code in the parent process as well.
23 class MOJO_SYSTEM_IMPL_EXPORT BrokerState : NON_EXPORTED_BASE(public Broker) { 26 class MOJO_SYSTEM_IMPL_EXPORT BrokerState : NON_EXPORTED_BASE(public Broker) {
24 public: 27 public:
25 static BrokerState* GetInstance(); 28 static BrokerState* GetInstance();
26 29
27 // Broker implementation. 30 // Broker implementation:
28 #if defined(OS_WIN) 31 #if defined(OS_WIN)
29 void CreatePlatformChannelPair(ScopedPlatformHandle* server, 32 void CreatePlatformChannelPair(ScopedPlatformHandle* server,
30 ScopedPlatformHandle* client) override; 33 ScopedPlatformHandle* client) override;
31 void HandleToToken(const PlatformHandle* platform_handles, 34 void HandleToToken(const PlatformHandle* platform_handles,
32 size_t count, 35 size_t count,
33 uint64_t* tokens) override; 36 uint64_t* tokens) override;
34 void TokenToHandle(const uint64_t* tokens, 37 void TokenToHandle(const uint64_t* tokens,
35 size_t count, 38 size_t count,
36 PlatformHandle* handles) override; 39 PlatformHandle* handles) override;
37 #endif 40 #endif
41 void ConnectMessagePipe(uint64_t pipe_id,
42 MessagePipeDispatcher* message_pipe) override;
43 void CloseMessagePipe(uint64_t pipe_id,
44 MessagePipeDispatcher* message_pipe) override;
38 45
39 scoped_refptr<base::TaskRunner> broker_thread() { 46 // Called by ChildBrokerHost on construction and destruction.
40 return broker_thread_.task_runner(); 47 void ChildBrokerHostCreated(ChildBrokerHost* child_broker_host);
41 } 48 void ChildBrokerHostDestructed(ChildBrokerHost* child_broker_host);
49
50 // These are called by ChildBrokerHost as they dispatch IPCs from ChildBroker.
51 // They are called on the IO thread.
52 void HandleConnectMessagePipe(ChildBrokerHost* pipe_process,
53 uint64_t pipe_id);
54 void HandleCancelConnectMessagePipe(uint64_t pipe_id);
42 55
43 private: 56 private:
44 friend struct base::DefaultSingletonTraits<BrokerState>; 57 friend struct base::DefaultSingletonTraits<BrokerState>;
45 58
46 BrokerState(); 59 BrokerState();
47 ~BrokerState() override; 60 ~BrokerState() override;
48 61
49 // A separate thread to handle sync IPCs from child processes for exchanging 62 // Checks if there's a direct channel between the two processes, and if not
50 // platform handles with tokens. We use a separate thread because latency is 63 // creates one and tells them about it.
51 // very sensitive (since any time a pipe is created or sent, a child process 64 // If one of the processes is the current one, it should be pid1.
52 // makes a sync call to this class). 65 // Called on the IO thread.
53 base::Thread broker_thread_; 66 void EnsureProcessesConnected(base::ProcessId pid1, base::ProcessId pid2);
67
68 // Callback when a RoutedRawChannel is destroyed for cleanup.
69 // Called on the IO thread.
70 void ChannelDestructed(RoutedRawChannel* channel);
54 71
55 #if defined(OS_WIN) 72 #if defined(OS_WIN)
56 // Used in the parent (unsandboxed) process to hold a mapping between HANDLES 73 // Used in the parent (unsandboxed) process to hold a mapping between HANDLES
57 // and tokens. When a child process wants to send a HANDLE to another process, 74 // and tokens. When a child process wants to send a HANDLE to another process,
58 // it exchanges it to a token and then the other process exchanges that token 75 // it exchanges it to a token and then the other process exchanges that token
59 // back to a HANDLE. 76 // back to a HANDLE.
60 base::Lock lock_; // Guards access to below. 77 base::Lock token_map_lock_;
61 base::hash_map<uint64_t, HANDLE> token_map_; 78 base::hash_map<uint64_t, HANDLE> token_map_;
62 #endif 79 #endif
80
81 // For pending connects originiating in this process.
82 // Only accessed on the IO thread.
83 base::hash_map<uint64_t, MessagePipeDispatcher*> pending_connects_;
84
85 // For connected message pipes in this process. This is needed so that when a
86 // MessagePipeDispatcher is closed we can remove the route for the
87 // corresponding RoutedRawChannel.
88 // Only accessed on the IO thread.
89 base::hash_map<MessagePipeDispatcher*, RoutedRawChannel*> connected_pipes_;
90
91 base::Lock lock_; // Guards access to below.
92
93 // Holds a map of all the RoutedRawChannel that connect this parent process to
94 // a child process. The key is the child process'd pid.
95 base::hash_map<base::ProcessId, RoutedRawChannel*> child_channels_;
96
97 base::hash_map<uint64_t, ChildBrokerHost*> pending_child_connects_;
98
99 // Each entry is an std::pair of ints of processe IDs that have
100 // RoutedRawChannel objects between them. The pair always has the smaller
101 // process id value first.
102 // For now, we don't reap connections if there are no more routes between two
103 // processes.
104 base::hash_set<std::pair<base::ProcessId, base::ProcessId>>
105 connected_processes_;
106
107 base::hash_map<base::ProcessId, ChildBrokerHost*> child_processes_;
108
109 // Used for message pipes in the same process.
110 RoutedRawChannel* in_process_pipes_channel1_;
111 RoutedRawChannel* in_process_pipes_channel2_;
112
113 DISALLOW_COPY_AND_ASSIGN(BrokerState);
63 }; 114 };
64 115
65 } // namespace edk 116 } // namespace edk
66 } // namespace mojo 117 } // namespace mojo
67 118
68 #endif // MOJO_EDK_SYSTEM_BROKER_STATE_H_ 119 #endif // MOJO_EDK_SYSTEM_BROKER_STATE_H_
OLDNEW
« no previous file with comments | « mojo/edk/system/broker_messages.h ('k') | mojo/edk/system/broker_state.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698