OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ipc/ipc_sync_channel.h" | 5 #include "ipc/ipc_sync_channel.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <utility> | 10 #include <utility> |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 return base::WrapUnique( | 519 return base::WrapUnique( |
520 new SyncChannel(listener, ipc_task_runner, shutdown_event)); | 520 new SyncChannel(listener, ipc_task_runner, shutdown_event)); |
521 } | 521 } |
522 | 522 |
523 SyncChannel::SyncChannel( | 523 SyncChannel::SyncChannel( |
524 Listener* listener, | 524 Listener* listener, |
525 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner, | 525 const scoped_refptr<base::SingleThreadTaskRunner>& ipc_task_runner, |
526 WaitableEvent* shutdown_event) | 526 WaitableEvent* shutdown_event) |
527 : ChannelProxy(new SyncContext(listener, ipc_task_runner, shutdown_event)), | 527 : ChannelProxy(new SyncContext(listener, ipc_task_runner, shutdown_event)), |
528 sync_handle_registry_(mojo::SyncHandleRegistry::current()), | 528 sync_handle_registry_(mojo::SyncHandleRegistry::current()), |
529 dispatch_watcher_(FROM_HERE) { | 529 dispatch_watcher_(FROM_HERE, mojo::Watcher::ArmingPolicy::AUTOMATIC) { |
530 // The current (listener) thread must be distinct from the IPC thread, or else | 530 // The current (listener) thread must be distinct from the IPC thread, or else |
531 // sending synchronous messages will deadlock. | 531 // sending synchronous messages will deadlock. |
532 DCHECK_NE(ipc_task_runner.get(), base::ThreadTaskRunnerHandle::Get().get()); | 532 DCHECK_NE(ipc_task_runner.get(), base::ThreadTaskRunnerHandle::Get().get()); |
533 StartWatching(); | 533 StartWatching(); |
534 } | 534 } |
535 | 535 |
536 SyncChannel::~SyncChannel() { | 536 SyncChannel::~SyncChannel() { |
537 } | 537 } |
538 | 538 |
539 void SyncChannel::SetRestrictDispatchChannelGroup(int group) { | 539 void SyncChannel::SetRestrictDispatchChannelGroup(int group) { |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
635 } | 635 } |
636 | 636 |
637 if (should_pump_messages) | 637 if (should_pump_messages) |
638 WaitForReplyWithNestedMessageLoop(context); // Run a nested message loop. | 638 WaitForReplyWithNestedMessageLoop(context); // Run a nested message loop. |
639 | 639 |
640 break; | 640 break; |
641 } | 641 } |
642 } | 642 } |
643 | 643 |
644 void SyncChannel::WaitForReplyWithNestedMessageLoop(SyncContext* context) { | 644 void SyncChannel::WaitForReplyWithNestedMessageLoop(SyncContext* context) { |
645 mojo::Watcher send_done_watcher(FROM_HERE); | 645 mojo::Watcher send_done_watcher(FROM_HERE, |
| 646 mojo::Watcher::ArmingPolicy::AUTOMATIC); |
646 | 647 |
647 ReceivedSyncMsgQueue* sync_msg_queue = context->received_sync_msgs(); | 648 ReceivedSyncMsgQueue* sync_msg_queue = context->received_sync_msgs(); |
648 DCHECK_NE(sync_msg_queue, nullptr); | 649 DCHECK_NE(sync_msg_queue, nullptr); |
649 | 650 |
650 mojo::Watcher* old_watcher = sync_msg_queue->top_send_done_watcher(); | 651 mojo::Watcher* old_watcher = sync_msg_queue->top_send_done_watcher(); |
651 mojo::Handle old_handle(mojo::kInvalidHandleValue); | 652 mojo::Handle old_handle(mojo::kInvalidHandleValue); |
652 mojo::Watcher::ReadyCallback old_callback; | 653 mojo::Watcher::ReadyCallback old_callback; |
653 | 654 |
654 // Maintain a thread-local stack of watchers to ensure nested calls complete | 655 // Maintain a thread-local stack of watchers to ensure nested calls complete |
655 // in the correct sequence, i.e. the outermost call completes first, etc. | 656 // in the correct sequence, i.e. the outermost call completes first, etc. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
693 MOJO_HANDLE_SIGNAL_READABLE, | 694 MOJO_HANDLE_SIGNAL_READABLE, |
694 base::Bind(&SyncChannel::OnDispatchHandleReady, | 695 base::Bind(&SyncChannel::OnDispatchHandleReady, |
695 base::Unretained(this))); | 696 base::Unretained(this))); |
696 } | 697 } |
697 | 698 |
698 void SyncChannel::OnChannelInit() { | 699 void SyncChannel::OnChannelInit() { |
699 pre_init_sync_message_filters_.clear(); | 700 pre_init_sync_message_filters_.clear(); |
700 } | 701 } |
701 | 702 |
702 } // namespace IPC | 703 } // namespace IPC |
OLD | NEW |