| 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_SLAVE_CONNECTION_MANAGER_H_ | 5 #ifndef MOJO_EDK_SYSTEM_SLAVE_CONNECTION_MANAGER_H_ |
| 6 #define MOJO_EDK_SYSTEM_SLAVE_CONNECTION_MANAGER_H_ | 6 #define MOJO_EDK_SYSTEM_SLAVE_CONNECTION_MANAGER_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 11 #include "mojo/edk/embedder/scoped_platform_handle.h" | |
| 12 #include "mojo/edk/embedder/slave_process_delegate.h" | 11 #include "mojo/edk/embedder/slave_process_delegate.h" |
| 12 #include "mojo/edk/platform/scoped_platform_handle.h" |
| 13 #include "mojo/edk/platform/task_runner.h" | 13 #include "mojo/edk/platform/task_runner.h" |
| 14 #include "mojo/edk/system/connection_manager.h" | 14 #include "mojo/edk/system/connection_manager.h" |
| 15 #include "mojo/edk/system/raw_channel.h" | 15 #include "mojo/edk/system/raw_channel.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/waitable_event.h" | 18 #include "mojo/edk/util/waitable_event.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; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 45 // has completed. | 45 // has completed. |
| 46 explicit SlaveConnectionManager(embedder::PlatformSupport* platform_support); | 46 explicit SlaveConnectionManager(embedder::PlatformSupport* platform_support); |
| 47 ~SlaveConnectionManager() override; | 47 ~SlaveConnectionManager() override; |
| 48 | 48 |
| 49 // No other methods may be called until after this has been called. | 49 // No other methods may be called until after this has been called. |
| 50 // |delegate_thread_task_runner| should be the task runner for the "delegate | 50 // |delegate_thread_task_runner| should be the task runner for the "delegate |
| 51 // thread", on which |slave_process_delegate|'s methods will be called. Both | 51 // thread", on which |slave_process_delegate|'s methods will be called. Both |
| 52 // must stay alive at least until after |Shutdown()| has been called. | 52 // must stay alive at least until after |Shutdown()| has been called. |
| 53 void Init(util::RefPtr<platform::TaskRunner>&& delegate_thread_task_runner, | 53 void Init(util::RefPtr<platform::TaskRunner>&& delegate_thread_task_runner, |
| 54 embedder::SlaveProcessDelegate* slave_process_delegate, | 54 embedder::SlaveProcessDelegate* slave_process_delegate, |
| 55 embedder::ScopedPlatformHandle platform_handle); | 55 platform::ScopedPlatformHandle platform_handle); |
| 56 | 56 |
| 57 // |ConnectionManager| methods: | 57 // |ConnectionManager| methods: |
| 58 void Shutdown() override; | 58 void Shutdown() override; |
| 59 bool AllowConnect(const ConnectionIdentifier& connection_id) override; | 59 bool AllowConnect(const ConnectionIdentifier& connection_id) override; |
| 60 bool CancelConnect(const ConnectionIdentifier& connection_id) override; | 60 bool CancelConnect(const ConnectionIdentifier& connection_id) override; |
| 61 Result Connect(const ConnectionIdentifier& connection_id, | 61 Result Connect(const ConnectionIdentifier& connection_id, |
| 62 ProcessIdentifier* peer_process_identifier, | 62 ProcessIdentifier* peer_process_identifier, |
| 63 bool* is_first, | 63 bool* is_first, |
| 64 embedder::ScopedPlatformHandle* platform_handle) override; | 64 platform::ScopedPlatformHandle* platform_handle) override; |
| 65 | 65 |
| 66 private: | 66 private: |
| 67 // These should only be called on |private_thread_|: | 67 // These should only be called on |private_thread_|: |
| 68 void InitOnPrivateThread(embedder::ScopedPlatformHandle platform_handle); | 68 void InitOnPrivateThread(platform::ScopedPlatformHandle platform_handle); |
| 69 void ShutdownOnPrivateThread(); | 69 void ShutdownOnPrivateThread(); |
| 70 void AllowConnectOnPrivateThread(const ConnectionIdentifier& connection_id, | 70 void AllowConnectOnPrivateThread(const ConnectionIdentifier& connection_id, |
| 71 Result* result); | 71 Result* result); |
| 72 void CancelConnectOnPrivateThread(const ConnectionIdentifier& connection_id, | 72 void CancelConnectOnPrivateThread(const ConnectionIdentifier& connection_id, |
| 73 Result* result); | 73 Result* result); |
| 74 void ConnectOnPrivateThread(const ConnectionIdentifier& connection_id, | 74 void ConnectOnPrivateThread(const ConnectionIdentifier& connection_id, |
| 75 Result* result, | 75 Result* result, |
| 76 ProcessIdentifier* peer_process_identifier, | 76 ProcessIdentifier* peer_process_identifier, |
| 77 bool* is_first, | 77 bool* is_first, |
| 78 embedder::ScopedPlatformHandle* platform_handle); | 78 platform::ScopedPlatformHandle* platform_handle); |
| 79 | 79 |
| 80 // |RawChannel::Delegate| methods (only called on |private_thread_|): | 80 // |RawChannel::Delegate| methods (only called on |private_thread_|): |
| 81 void OnReadMessage( | 81 void OnReadMessage( |
| 82 const MessageInTransit::View& message_view, | 82 const MessageInTransit::View& message_view, |
| 83 std::unique_ptr<std::vector<embedder::ScopedPlatformHandle>> | 83 std::unique_ptr<std::vector<platform::ScopedPlatformHandle>> |
| 84 platform_handles) override; | 84 platform_handles) override; |
| 85 void OnError(Error error) override; | 85 void OnError(Error error) override; |
| 86 | 86 |
| 87 // Asserts that the current thread is *not* |private_thread_| (no-op if | 87 // Asserts that the current thread is *not* |private_thread_| (no-op if |
| 88 // DCHECKs are not enabled). This should only be called while | 88 // DCHECKs are not enabled). This should only be called while |
| 89 // |private_thread_| is alive (i.e., after |Init()| but before |Shutdown()|). | 89 // |private_thread_| is alive (i.e., after |Init()| but before |Shutdown()|). |
| 90 void AssertNotOnPrivateThread() const; | 90 void AssertNotOnPrivateThread() const; |
| 91 | 91 |
| 92 // Asserts that the current thread is |private_thread_| (no-op if DCHECKs are | 92 // Asserts that the current thread is |private_thread_| (no-op if DCHECKs are |
| 93 // not enabled). This should only be called while |private_thread_| is alive | 93 // not enabled). This should only be called while |private_thread_| is alive |
| (...skipping 18 matching lines...) Expand all Loading... |
| 112 NOT_AWAITING_ACK, | 112 NOT_AWAITING_ACK, |
| 113 AWAITING_ACCEPT_CONNECT_ACK, | 113 AWAITING_ACCEPT_CONNECT_ACK, |
| 114 AWAITING_CANCEL_CONNECT_ACK, | 114 AWAITING_CANCEL_CONNECT_ACK, |
| 115 AWAITING_CONNECT_ACK | 115 AWAITING_CONNECT_ACK |
| 116 }; | 116 }; |
| 117 AwaitingAckType awaiting_ack_type_; | 117 AwaitingAckType awaiting_ack_type_; |
| 118 Result* ack_result_; | 118 Result* ack_result_; |
| 119 // Used only when waiting for the ack to "connect": | 119 // Used only when waiting for the ack to "connect": |
| 120 ProcessIdentifier* ack_peer_process_identifier_; | 120 ProcessIdentifier* ack_peer_process_identifier_; |
| 121 bool* ack_is_first_; | 121 bool* ack_is_first_; |
| 122 embedder::ScopedPlatformHandle* ack_platform_handle_; | 122 platform::ScopedPlatformHandle* ack_platform_handle_; |
| 123 | 123 |
| 124 // The (synchronous) |ConnectionManager| methods are implemented in the | 124 // The (synchronous) |ConnectionManager| methods are implemented in the |
| 125 // following way (T is any thread other than |private_thread_|): | 125 // following way (T is any thread other than |private_thread_|): |
| 126 // | 126 // |
| 127 // On thread T: | 127 // On thread T: |
| 128 // 1. |F()| is called, where F is one of the |ConnectionManager| methods. | 128 // 1. |F()| is called, where F is one of the |ConnectionManager| methods. |
| 129 // 2. |lock_| is acquired. | 129 // 2. |lock_| is acquired. |
| 130 // 3. |FImpl()| is posted to |private_thread_|. | 130 // 3. |FImpl()| is posted to |private_thread_|. |
| 131 // 4. |event_| is waited on (while holding |lock_|!). | 131 // 4. |event_| is waited on (while holding |lock_|!). |
| 132 // | 132 // |
| (...skipping 17 matching lines...) Expand all Loading... |
| 150 util::Mutex mutex_; | 150 util::Mutex mutex_; |
| 151 util::AutoResetWaitableEvent event_; | 151 util::AutoResetWaitableEvent event_; |
| 152 | 152 |
| 153 MOJO_DISALLOW_COPY_AND_ASSIGN(SlaveConnectionManager); | 153 MOJO_DISALLOW_COPY_AND_ASSIGN(SlaveConnectionManager); |
| 154 }; | 154 }; |
| 155 | 155 |
| 156 } // namespace system | 156 } // namespace system |
| 157 } // namespace mojo | 157 } // namespace mojo |
| 158 | 158 |
| 159 #endif // MOJO_EDK_SYSTEM_SLAVE_CONNECTION_MANAGER_H_ | 159 #endif // MOJO_EDK_SYSTEM_SLAVE_CONNECTION_MANAGER_H_ |
| OLD | NEW |