| 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_PUBLIC_CPP_BINDINGS_LIB_MULTIPLEX_ROUTER_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_LIB_MULTIPLEX_ROUTER_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MULTIPLEX_ROUTER_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MULTIPLEX_ROUTER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <deque> | 10 #include <deque> |
| 11 #include <map> | 11 #include <map> |
| 12 | 12 |
| 13 #include "base/logging.h" | 13 #include "base/logging.h" |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/ref_counted_delete_on_message_loop.h" | 16 #include "base/memory/ref_counted_delete_on_message_loop.h" |
| 17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/synchronization/lock.h" | 19 #include "base/synchronization/lock.h" |
| 20 #include "base/threading/thread_checker.h" | 20 #include "base/threading/thread_checker.h" |
| 21 #include "mojo/public/cpp/bindings/callback.h" | 21 #include "mojo/public/cpp/bindings/callback.h" |
| 22 #include "mojo/public/cpp/bindings/lib/connector.h" | 22 #include "mojo/public/cpp/bindings/lib/connector.h" |
| 23 #include "mojo/public/cpp/bindings/lib/interface_id.h" | 23 #include "mojo/public/cpp/bindings/lib/interface_id.h" |
| 24 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" | 24 #include "mojo/public/cpp/bindings/lib/message_header_validator.h" |
| 25 #include "mojo/public/cpp/bindings/lib/pipe_control_message_handler.h" | 25 #include "mojo/public/cpp/bindings/lib/pipe_control_message_handler.h" |
| 26 #include "mojo/public/cpp/bindings/lib/pipe_control_message_handler_delegate.h" | 26 #include "mojo/public/cpp/bindings/lib/pipe_control_message_handler_delegate.h" |
| 27 #include "mojo/public/cpp/bindings/lib/pipe_control_message_proxy.h" | 27 #include "mojo/public/cpp/bindings/lib/pipe_control_message_proxy.h" |
| 28 #include "mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h" | 28 #include "mojo/public/cpp/bindings/lib/scoped_interface_endpoint_handle.h" |
| 29 | 29 |
| 30 namespace base { |
| 31 class SingleThreadTaskRunner; |
| 32 } |
| 33 |
| 30 namespace mojo { | 34 namespace mojo { |
| 31 | 35 |
| 32 class AssociatedGroup; | 36 class AssociatedGroup; |
| 33 | 37 |
| 34 namespace internal { | 38 namespace internal { |
| 35 | 39 |
| 36 class InterfaceEndpointClient; | 40 class InterfaceEndpointClient; |
| 37 | 41 |
| 38 // MultiplexRouter supports routing messages for multiple interfaces over a | 42 // MultiplexRouter supports routing messages for multiple interfaces over a |
| 39 // single message pipe. | 43 // single message pipe. |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 | 169 |
| 166 // Processes enqueued tasks (incoming messages and error notifications). | 170 // Processes enqueued tasks (incoming messages and error notifications). |
| 167 // If |force_async| is true, it guarantees not to call any | 171 // If |force_async| is true, it guarantees not to call any |
| 168 // InterfaceEndpointClient methods directly. | 172 // InterfaceEndpointClient methods directly. |
| 169 // | 173 // |
| 170 // Note: Because calling into InterfaceEndpointClient may lead to destruction | 174 // Note: Because calling into InterfaceEndpointClient may lead to destruction |
| 171 // of this object, if |force_async| is set to false, the caller needs to hold | 175 // of this object, if |force_async| is set to false, the caller needs to hold |
| 172 // on to a ref outside of |lock_| before calling this method. | 176 // on to a ref outside of |lock_| before calling this method. |
| 173 void ProcessTasks(bool force_async); | 177 void ProcessTasks(bool force_async); |
| 174 | 178 |
| 175 // Returns true to indicate that |task| has been processed. Otherwise the task | 179 // Returns true to indicate that |task|/|message| has been processed. |
| 176 // will be added back to the front of the queue. | |
| 177 bool ProcessNotifyErrorTask(Task* task, bool force_async); | 180 bool ProcessNotifyErrorTask(Task* task, bool force_async); |
| 178 bool ProcessIncomingMessageTask(Task* task, bool force_async); | 181 bool ProcessIncomingMessage(Message* message, bool force_async); |
| 179 | 182 |
| 183 void MaybePostToProcessTasks(base::SingleThreadTaskRunner* task_runner); |
| 180 void LockAndCallProcessTasks(); | 184 void LockAndCallProcessTasks(); |
| 181 | 185 |
| 182 // Updates the state of |endpoint|. If both the endpoint and its peer have | 186 // Updates the state of |endpoint|. If both the endpoint and its peer have |
| 183 // been closed, removes it from |endpoints_|. | 187 // been closed, removes it from |endpoints_|. |
| 184 // NOTE: The method may invalidate |endpoint|. | 188 // NOTE: The method may invalidate |endpoint|. |
| 185 enum EndpointStateUpdateType { ENDPOINT_CLOSED, PEER_ENDPOINT_CLOSED }; | 189 enum EndpointStateUpdateType { ENDPOINT_CLOSED, PEER_ENDPOINT_CLOSED }; |
| 186 void UpdateEndpointStateMayRemove(InterfaceEndpoint* endpoint, | 190 void UpdateEndpointStateMayRemove(InterfaceEndpoint* endpoint, |
| 187 EndpointStateUpdateType type); | 191 EndpointStateUpdateType type); |
| 188 | 192 |
| 189 void RaiseErrorInNonTestingMode(); | 193 void RaiseErrorInNonTestingMode(); |
| 190 | 194 |
| 195 InterfaceEndpoint* FindOrInsertEndpoint(InterfaceId id, bool* inserted); |
| 196 |
| 191 // Whether to set the namespace bit when generating interface IDs. Please see | 197 // Whether to set the namespace bit when generating interface IDs. Please see |
| 192 // comments of kInterfaceIdNamespaceMask. | 198 // comments of kInterfaceIdNamespaceMask. |
| 193 const bool set_interface_id_namespace_bit_; | 199 const bool set_interface_id_namespace_bit_; |
| 194 | 200 |
| 195 MessageHeaderValidator header_validator_; | 201 MessageHeaderValidator header_validator_; |
| 196 Connector connector_; | 202 Connector connector_; |
| 197 bool encountered_error_; | 203 bool encountered_error_; |
| 198 | 204 |
| 199 base::ThreadChecker thread_checker_; | 205 base::ThreadChecker thread_checker_; |
| 200 | 206 |
| 201 // Protects the following members. | 207 // Protects the following members. |
| 202 mutable base::Lock lock_; | 208 mutable base::Lock lock_; |
| 203 PipeControlMessageHandler control_message_handler_; | 209 PipeControlMessageHandler control_message_handler_; |
| 204 PipeControlMessageProxy control_message_proxy_; | 210 PipeControlMessageProxy control_message_proxy_; |
| 205 | 211 |
| 206 std::map<InterfaceId, scoped_refptr<InterfaceEndpoint>> endpoints_; | 212 std::map<InterfaceId, scoped_refptr<InterfaceEndpoint>> endpoints_; |
| 207 uint32_t next_interface_id_value_; | 213 uint32_t next_interface_id_value_; |
| 208 | 214 |
| 209 std::deque<scoped_ptr<Task>> tasks_; | 215 std::deque<scoped_ptr<Task>> tasks_; |
| 210 | 216 |
| 217 bool posted_to_process_tasks_; |
| 218 |
| 211 bool testing_mode_; | 219 bool testing_mode_; |
| 212 | 220 |
| 213 DISALLOW_COPY_AND_ASSIGN(MultiplexRouter); | 221 DISALLOW_COPY_AND_ASSIGN(MultiplexRouter); |
| 214 }; | 222 }; |
| 215 | 223 |
| 216 } // namespace internal | 224 } // namespace internal |
| 217 } // namespace mojo | 225 } // namespace mojo |
| 218 | 226 |
| 219 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MULTIPLEX_ROUTER_H_ | 227 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MULTIPLEX_ROUTER_H_ |
| OLD | NEW |