| 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 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" | 5 #include "mojo/public/cpp/bindings/lib/multiplex_router.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 Type type; | 278 Type type; |
| 279 | 279 |
| 280 private: | 280 private: |
| 281 explicit Task(Type in_type) : type(in_type) {} | 281 explicit Task(Type in_type) : type(in_type) {} |
| 282 }; | 282 }; |
| 283 | 283 |
| 284 MultiplexRouter::MultiplexRouter( | 284 MultiplexRouter::MultiplexRouter( |
| 285 ScopedMessagePipeHandle message_pipe, | 285 ScopedMessagePipeHandle message_pipe, |
| 286 Config config, | 286 Config config, |
| 287 bool set_interface_id_namesapce_bit, | 287 bool set_interface_id_namesapce_bit, |
| 288 scoped_refptr<base::SingleThreadTaskRunner> runner) | 288 scoped_refptr<base::SingleThreadTaskRunner> runner, |
| 289 ClientCallBehavior sync_client_call_behavior) |
| 289 : set_interface_id_namespace_bit_(set_interface_id_namesapce_bit), | 290 : set_interface_id_namespace_bit_(set_interface_id_namesapce_bit), |
| 290 task_runner_(runner), | 291 task_runner_(runner), |
| 291 header_validator_(nullptr), | 292 header_validator_(nullptr), |
| 292 filters_(this), | 293 filters_(this), |
| 293 connector_(std::move(message_pipe), | 294 connector_(std::move(message_pipe), |
| 294 config == MULTI_INTERFACE ? Connector::MULTI_THREADED_SEND | 295 config == MULTI_INTERFACE ? Connector::MULTI_THREADED_SEND |
| 295 : Connector::SINGLE_THREADED_SEND, | 296 : Connector::SINGLE_THREADED_SEND, |
| 296 std::move(runner)), | 297 std::move(runner)), |
| 297 lock_(config == MULTI_INTERFACE ? new base::Lock : nullptr), | 298 lock_(config == MULTI_INTERFACE ? new base::Lock : nullptr), |
| 298 control_message_handler_(this), | 299 control_message_handler_(this), |
| 299 control_message_proxy_(&connector_), | 300 control_message_proxy_(&connector_), |
| 300 next_interface_id_value_(1), | 301 next_interface_id_value_(1), |
| 301 posted_to_process_tasks_(false), | 302 posted_to_process_tasks_(false), |
| 302 encountered_error_(false), | 303 encountered_error_(false), |
| 303 paused_(false), | 304 paused_(false), |
| 304 testing_mode_(false) { | 305 testing_mode_(false), |
| 306 sync_client_call_behavior_(sync_client_call_behavior) { |
| 305 DCHECK(task_runner_->BelongsToCurrentThread()); | 307 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 306 | 308 |
| 307 if (config == SINGLE_INTERFACE_WITH_SYNC_METHODS || | 309 if (config == SINGLE_INTERFACE_WITH_SYNC_METHODS || |
| 308 config == MULTI_INTERFACE) { | 310 config == MULTI_INTERFACE) { |
| 309 // Always participate in sync handle watching in multi-interface mode, | 311 // Always participate in sync handle watching in multi-interface mode, |
| 310 // because even if it doesn't expect sync requests during sync handle | 312 // because even if it doesn't expect sync requests during sync handle |
| 311 // watching, it may still need to dispatch messages to associated endpoints | 313 // watching, it may still need to dispatch messages to associated endpoints |
| 312 // on a different thread. | 314 // on a different thread. |
| 313 connector_.AllowWokenUpBySyncWatchOnSameThread(); | 315 connector_.AllowWokenUpBySyncWatchOnSameThread(); |
| 314 } | 316 } |
| (...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 bool MultiplexRouter::Accept(Message* message) { | 535 bool MultiplexRouter::Accept(Message* message) { |
| 534 DCHECK(thread_checker_.CalledOnValidThread()); | 536 DCHECK(thread_checker_.CalledOnValidThread()); |
| 535 | 537 |
| 536 scoped_refptr<MultiplexRouter> protector(this); | 538 scoped_refptr<MultiplexRouter> protector(this); |
| 537 MayAutoLock locker(lock_.get()); | 539 MayAutoLock locker(lock_.get()); |
| 538 | 540 |
| 539 DCHECK(!paused_); | 541 DCHECK(!paused_); |
| 540 | 542 |
| 541 ClientCallBehavior client_call_behavior = | 543 ClientCallBehavior client_call_behavior = |
| 542 connector_.during_sync_handle_watcher_callback() | 544 connector_.during_sync_handle_watcher_callback() |
| 543 ? ALLOW_DIRECT_CLIENT_CALLS_FOR_SYNC_MESSAGES | 545 ? sync_client_call_behavior_ |
| 544 : ALLOW_DIRECT_CLIENT_CALLS; | 546 : ALLOW_DIRECT_CLIENT_CALLS; |
| 545 | 547 |
| 546 bool processed = | 548 bool processed = |
| 547 tasks_.empty() && ProcessIncomingMessage(message, client_call_behavior, | 549 tasks_.empty() && ProcessIncomingMessage(message, client_call_behavior, |
| 548 connector_.task_runner()); | 550 connector_.task_runner()); |
| 549 | 551 |
| 550 if (!processed) { | 552 if (!processed) { |
| 551 // Either the task queue is not empty or we cannot process the message | 553 // Either the task queue is not empty or we cannot process the message |
| 552 // directly. In both cases, there is no need to call ProcessTasks(). | 554 // directly. In both cases, there is no need to call ProcessTasks(). |
| 553 tasks_.push_back(Task::CreateMessageTask(message)); | 555 tasks_.push_back(Task::CreateMessageTask(message)); |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 912 | 914 |
| 913 void MultiplexRouter::AssertLockAcquired() { | 915 void MultiplexRouter::AssertLockAcquired() { |
| 914 #if DCHECK_IS_ON() | 916 #if DCHECK_IS_ON() |
| 915 if (lock_) | 917 if (lock_) |
| 916 lock_->AssertAcquired(); | 918 lock_->AssertAcquired(); |
| 917 #endif | 919 #endif |
| 918 } | 920 } |
| 919 | 921 |
| 920 } // namespace internal | 922 } // namespace internal |
| 921 } // namespace mojo | 923 } // namespace mojo |
| OLD | NEW |