OLD | NEW |
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_MASTER_CONNECTION_MANAGER_H_ | 5 #ifndef MOJO_EDK_SYSTEM_MASTER_CONNECTION_MANAGER_H_ |
6 #define MOJO_EDK_SYSTEM_MASTER_CONNECTION_MANAGER_H_ | 6 #define MOJO_EDK_SYSTEM_MASTER_CONNECTION_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/threading/thread.h" | 12 #include "base/threading/thread.h" |
13 #include "mojo/edk/embedder/platform_task_runner.h" | |
14 #include "mojo/edk/embedder/scoped_platform_handle.h" | 13 #include "mojo/edk/embedder/scoped_platform_handle.h" |
| 14 #include "mojo/edk/platform/task_runner.h" |
15 #include "mojo/edk/system/connection_manager.h" | 15 #include "mojo/edk/system/connection_manager.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 } |
24 | 24 |
(...skipping 22 matching lines...) Expand all Loading... |
47 | 47 |
48 // |platform_support| must be valid and remain alive until after |Shutdown()| | 48 // |platform_support| must be valid and remain alive until after |Shutdown()| |
49 // has completed. | 49 // has completed. |
50 explicit MasterConnectionManager(embedder::PlatformSupport* platform_support); | 50 explicit MasterConnectionManager(embedder::PlatformSupport* platform_support); |
51 ~MasterConnectionManager() override; | 51 ~MasterConnectionManager() override; |
52 | 52 |
53 // No other methods may be called until after this has been called. | 53 // No other methods may be called until after this has been called. |
54 // |delegate_thread_task_runner| should be the task runner for the "delegate | 54 // |delegate_thread_task_runner| should be the task runner for the "delegate |
55 // thread", on which |master_process_delegate|'s methods will be called. Both | 55 // thread", on which |master_process_delegate|'s methods will be called. Both |
56 // must stay alive at least until after |Shutdown()| has been called. | 56 // must stay alive at least until after |Shutdown()| has been called. |
57 void Init( | 57 void Init(util::RefPtr<platform::TaskRunner>&& delegate_thread_task_runner, |
58 util::RefPtr<embedder::PlatformTaskRunner>&& delegate_thread_task_runner, | 58 embedder::MasterProcessDelegate* master_process_delegate) |
59 embedder::MasterProcessDelegate* master_process_delegate) | |
60 MOJO_NOT_THREAD_SAFE; | 59 MOJO_NOT_THREAD_SAFE; |
61 | 60 |
62 // Adds a slave process and sets up/tracks a connection to that slave (using | 61 // Adds a slave process and sets up/tracks a connection to that slave (using |
63 // |platform_handle|). |slave_info| is used by the caller/implementation of | 62 // |platform_handle|). |slave_info| is used by the caller/implementation of |
64 // |embedder::MasterProcessDelegate| to track this process. It must remain | 63 // |embedder::MasterProcessDelegate| to track this process. It must remain |
65 // alive until the delegate's |OnSlaveDisconnect()| is called with it as the | 64 // alive until the delegate's |OnSlaveDisconnect()| is called with it as the |
66 // argument. |OnSlaveDisconnect()| will always be called for each slave, | 65 // argument. |OnSlaveDisconnect()| will always be called for each slave, |
67 // assuming proper shutdown. Returns the process identifier for the | 66 // assuming proper shutdown. Returns the process identifier for the |
68 // newly-added slave. | 67 // newly-added slave. |
69 ProcessIdentifier AddSlave(embedder::SlaveInfo slave_info, | 68 ProcessIdentifier AddSlave(embedder::SlaveInfo slave_info, |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 | 132 |
134 // Asserts that the current thread is |private_thread_| (no-op if DCHECKs are | 133 // Asserts that the current thread is |private_thread_| (no-op if DCHECKs are |
135 // not enabled). This should only be called while |private_thread_| is alive | 134 // not enabled). This should only be called while |private_thread_| is alive |
136 // (i.e., after |Init()| but before |Shutdown()|). | 135 // (i.e., after |Init()| but before |Shutdown()|). |
137 void AssertOnPrivateThread() const; | 136 void AssertOnPrivateThread() const; |
138 | 137 |
139 // These are set in |Init()| before |private_thread_| exists and only cleared | 138 // These are set in |Init()| before |private_thread_| exists and only cleared |
140 // in |Shutdown()| after |private_thread_| is dead. Thus it's safe to "use" on | 139 // in |Shutdown()| after |private_thread_| is dead. Thus it's safe to "use" on |
141 // |private_thread_|. (Note that |master_process_delegate_| may only be called | 140 // |private_thread_|. (Note that |master_process_delegate_| may only be called |
142 // from the delegate thread.) | 141 // from the delegate thread.) |
143 util::RefPtr<embedder::PlatformTaskRunner> delegate_thread_task_runner_; | 142 util::RefPtr<platform::TaskRunner> delegate_thread_task_runner_; |
144 embedder::MasterProcessDelegate* master_process_delegate_; | 143 embedder::MasterProcessDelegate* master_process_delegate_; |
145 | 144 |
146 // This is a private I/O thread on which this class does the bulk of its work. | 145 // This is a private I/O thread on which this class does the bulk of its work. |
147 // It is started in |Init()| and terminated in |Shutdown()|. | 146 // It is started in |Init()| and terminated in |Shutdown()|. |
148 base::Thread private_thread_; | 147 base::Thread private_thread_; |
149 | 148 |
150 // The following members are only accessed on |private_thread_|: | 149 // The following members are only accessed on |private_thread_|: |
151 std::unordered_map<ProcessIdentifier, Helper*> helpers_; // Owns its values. | 150 std::unordered_map<ProcessIdentifier, Helper*> helpers_; // Owns its values. |
152 | 151 |
153 // Note: |mutex_| is not needed in the constructor, |Init()|, | 152 // Note: |mutex_| is not needed in the constructor, |Init()|, |
(...skipping 20 matching lines...) Expand all Loading... |
174 std::unordered_map<ProcessIdentifier, ProcessConnections*> connections_ | 173 std::unordered_map<ProcessIdentifier, ProcessConnections*> connections_ |
175 MOJO_GUARDED_BY(mutex_); // Owns its values. | 174 MOJO_GUARDED_BY(mutex_); // Owns its values. |
176 | 175 |
177 MOJO_DISALLOW_COPY_AND_ASSIGN(MasterConnectionManager); | 176 MOJO_DISALLOW_COPY_AND_ASSIGN(MasterConnectionManager); |
178 }; | 177 }; |
179 | 178 |
180 } // namespace system | 179 } // namespace system |
181 } // namespace mojo | 180 } // namespace mojo |
182 | 181 |
183 #endif // MOJO_EDK_SYSTEM_MASTER_CONNECTION_MANAGER_H_ | 182 #endif // MOJO_EDK_SYSTEM_MASTER_CONNECTION_MANAGER_H_ |
OLD | NEW |