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 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "base/location.h" | 12 #include "base/location.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/memory/ptr_util.h" | 14 #include "base/memory/ptr_util.h" |
15 #include "base/single_thread_task_runner.h" | 15 #include "base/single_thread_task_runner.h" |
16 #include "base/stl_util.h" | 16 #include "base/stl_util.h" |
17 #include "base/threading/thread_task_runner_handle.h" | 17 #include "base/threading/thread_task_runner_handle.h" |
18 #include "mojo/public/cpp/bindings/associated_group.h" | 18 #include "mojo/public/cpp/bindings/associated_group.h" |
19 #include "mojo/public/cpp/bindings/interface_endpoint_client.h" | 19 #include "mojo/public/cpp/bindings/interface_endpoint_client.h" |
20 #include "mojo/public/cpp/bindings/interface_endpoint_controller.h" | 20 #include "mojo/public/cpp/bindings/interface_endpoint_controller.h" |
21 #include "mojo/public/cpp/bindings/lib/sync_handle_watcher.h" | 21 #include "mojo/public/cpp/bindings/sync_handle_watcher.h" |
22 | 22 |
23 namespace mojo { | 23 namespace mojo { |
24 namespace internal { | 24 namespace internal { |
25 | 25 |
26 // InterfaceEndpoint stores the information of an interface endpoint registered | 26 // InterfaceEndpoint stores the information of an interface endpoint registered |
27 // with the router. | 27 // with the router. |
28 // No one other than the router's |endpoints_| and |tasks_| should hold refs to | 28 // No one other than the router's |endpoints_| and |tasks_| should hold refs to |
29 // this object. | 29 // this object. |
30 class MultiplexRouter::InterfaceEndpoint | 30 class MultiplexRouter::InterfaceEndpoint |
31 : public base::RefCounted<InterfaceEndpoint>, | 31 : public base::RefCounted<InterfaceEndpoint>, |
(...skipping 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
490 bool processed = | 490 bool processed = |
491 tasks_.empty() && ProcessIncomingMessage(message, client_call_behavior, | 491 tasks_.empty() && ProcessIncomingMessage(message, client_call_behavior, |
492 connector_.task_runner()); | 492 connector_.task_runner()); |
493 | 493 |
494 if (!processed) { | 494 if (!processed) { |
495 // Either the task queue is not empty or we cannot process the message | 495 // Either the task queue is not empty or we cannot process the message |
496 // directly. In both cases, there is no need to call ProcessTasks(). | 496 // directly. In both cases, there is no need to call ProcessTasks(). |
497 tasks_.push_back(Task::CreateMessageTask(message)); | 497 tasks_.push_back(Task::CreateMessageTask(message)); |
498 Task* task = tasks_.back().get(); | 498 Task* task = tasks_.back().get(); |
499 | 499 |
500 if (task->message->has_flag(kMessageIsSync)) { | 500 if (task->message->has_flag(Message::kFlagIsSync)) { |
501 InterfaceId id = task->message->interface_id(); | 501 InterfaceId id = task->message->interface_id(); |
502 sync_message_tasks_[id].push_back(task); | 502 sync_message_tasks_[id].push_back(task); |
503 auto iter = endpoints_.find(id); | 503 auto iter = endpoints_.find(id); |
504 if (iter != endpoints_.end()) | 504 if (iter != endpoints_.end()) |
505 iter->second->SignalSyncMessageEvent(); | 505 iter->second->SignalSyncMessageEvent(); |
506 } | 506 } |
507 } else if (!tasks_.empty()) { | 507 } else if (!tasks_.empty()) { |
508 // Processing the message may result in new tasks (for error notification) | 508 // Processing the message may result in new tasks (for error notification) |
509 // being added to the queue. In this case, we have to attempt to process the | 509 // being added to the queue. In this case, we have to attempt to process the |
510 // tasks. | 510 // tasks. |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 | 589 |
590 if (posted_to_process_tasks_) | 590 if (posted_to_process_tasks_) |
591 return; | 591 return; |
592 | 592 |
593 while (!tasks_.empty()) { | 593 while (!tasks_.empty()) { |
594 std::unique_ptr<Task> task(std::move(tasks_.front())); | 594 std::unique_ptr<Task> task(std::move(tasks_.front())); |
595 tasks_.pop_front(); | 595 tasks_.pop_front(); |
596 | 596 |
597 InterfaceId id = kInvalidInterfaceId; | 597 InterfaceId id = kInvalidInterfaceId; |
598 bool sync_message = task->IsMessageTask() && task->message && | 598 bool sync_message = task->IsMessageTask() && task->message && |
599 task->message->has_flag(kMessageIsSync); | 599 task->message->has_flag(Message::kFlagIsSync); |
600 if (sync_message) { | 600 if (sync_message) { |
601 id = task->message->interface_id(); | 601 id = task->message->interface_id(); |
602 auto& sync_message_queue = sync_message_tasks_[id]; | 602 auto& sync_message_queue = sync_message_tasks_[id]; |
603 DCHECK_EQ(task.get(), sync_message_queue.front()); | 603 DCHECK_EQ(task.get(), sync_message_queue.front()); |
604 sync_message_queue.pop_front(); | 604 sync_message_queue.pop_front(); |
605 } | 605 } |
606 | 606 |
607 bool processed = | 607 bool processed = |
608 task->IsNotifyErrorTask() | 608 task->IsNotifyErrorTask() |
609 ? ProcessNotifyErrorTask(task.get(), client_call_behavior, | 609 ? ProcessNotifyErrorTask(task.get(), client_call_behavior, |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 if (endpoint->closed()) | 737 if (endpoint->closed()) |
738 return true; | 738 return true; |
739 | 739 |
740 if (!endpoint->client()) { | 740 if (!endpoint->client()) { |
741 // We need to wait until a client is attached in order to dispatch further | 741 // We need to wait until a client is attached in order to dispatch further |
742 // messages. | 742 // messages. |
743 return false; | 743 return false; |
744 } | 744 } |
745 | 745 |
746 bool can_direct_call; | 746 bool can_direct_call; |
747 if (message->has_flag(kMessageIsSync)) { | 747 if (message->has_flag(Message::kFlagIsSync)) { |
748 can_direct_call = client_call_behavior != NO_DIRECT_CLIENT_CALLS && | 748 can_direct_call = client_call_behavior != NO_DIRECT_CLIENT_CALLS && |
749 endpoint->task_runner()->BelongsToCurrentThread(); | 749 endpoint->task_runner()->BelongsToCurrentThread(); |
750 } else { | 750 } else { |
751 can_direct_call = client_call_behavior == ALLOW_DIRECT_CLIENT_CALLS && | 751 can_direct_call = client_call_behavior == ALLOW_DIRECT_CLIENT_CALLS && |
752 endpoint->task_runner() == current_task_runner; | 752 endpoint->task_runner() == current_task_runner; |
753 } | 753 } |
754 | 754 |
755 if (!can_direct_call) { | 755 if (!can_direct_call) { |
756 MaybePostToProcessTasks(endpoint->task_runner()); | 756 MaybePostToProcessTasks(endpoint->task_runner()); |
757 return false; | 757 return false; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
840 *inserted = true; | 840 *inserted = true; |
841 } else { | 841 } else { |
842 endpoint = iter->second.get(); | 842 endpoint = iter->second.get(); |
843 } | 843 } |
844 | 844 |
845 return endpoint; | 845 return endpoint; |
846 } | 846 } |
847 | 847 |
848 } // namespace internal | 848 } // namespace internal |
849 } // namespace mojo | 849 } // namespace mojo |
OLD | NEW |