| 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 507 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 518 WaitableEvent* shutdown_event) { | 518 WaitableEvent* shutdown_event) { |
| 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 // 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 |
| 530 // sending synchronous messages will deadlock. | 531 // sending synchronous messages will deadlock. |
| 531 DCHECK_NE(ipc_task_runner.get(), base::ThreadTaskRunnerHandle::Get().get()); | 532 DCHECK_NE(ipc_task_runner.get(), base::ThreadTaskRunnerHandle::Get().get()); |
| 532 StartWatching(); | 533 StartWatching(); |
| 533 } | 534 } |
| 534 | 535 |
| 535 SyncChannel::~SyncChannel() { | 536 SyncChannel::~SyncChannel() { |
| 536 } | 537 } |
| 537 | 538 |
| 538 void SyncChannel::SetRestrictDispatchChannelGroup(int group) { | 539 void SyncChannel::SetRestrictDispatchChannelGroup(int group) { |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 634 } | 635 } |
| 635 | 636 |
| 636 if (should_pump_messages) | 637 if (should_pump_messages) |
| 637 WaitForReplyWithNestedMessageLoop(context); // Run a nested message loop. | 638 WaitForReplyWithNestedMessageLoop(context); // Run a nested message loop. |
| 638 | 639 |
| 639 break; | 640 break; |
| 640 } | 641 } |
| 641 } | 642 } |
| 642 | 643 |
| 643 void SyncChannel::WaitForReplyWithNestedMessageLoop(SyncContext* context) { | 644 void SyncChannel::WaitForReplyWithNestedMessageLoop(SyncContext* context) { |
| 644 mojo::Watcher send_done_watcher; | 645 mojo::Watcher send_done_watcher(FROM_HERE); |
| 645 | 646 |
| 646 ReceivedSyncMsgQueue* sync_msg_queue = context->received_sync_msgs(); | 647 ReceivedSyncMsgQueue* sync_msg_queue = context->received_sync_msgs(); |
| 647 DCHECK_NE(sync_msg_queue, nullptr); | 648 DCHECK_NE(sync_msg_queue, nullptr); |
| 648 | 649 |
| 649 mojo::Watcher* old_watcher = sync_msg_queue->top_send_done_watcher(); | 650 mojo::Watcher* old_watcher = sync_msg_queue->top_send_done_watcher(); |
| 650 mojo::Handle old_handle(mojo::kInvalidHandleValue); | 651 mojo::Handle old_handle(mojo::kInvalidHandleValue); |
| 651 mojo::Watcher::ReadyCallback old_callback; | 652 mojo::Watcher::ReadyCallback old_callback; |
| 652 | 653 |
| 653 // Maintain a thread-local stack of watchers to ensure nested calls complete | 654 // Maintain a thread-local stack of watchers to ensure nested calls complete |
| 654 // in the correct sequence, i.e. the outermost call completes first, etc. | 655 // 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... |
| 692 MOJO_HANDLE_SIGNAL_READABLE, | 693 MOJO_HANDLE_SIGNAL_READABLE, |
| 693 base::Bind(&SyncChannel::OnDispatchHandleReady, | 694 base::Bind(&SyncChannel::OnDispatchHandleReady, |
| 694 base::Unretained(this))); | 695 base::Unretained(this))); |
| 695 } | 696 } |
| 696 | 697 |
| 697 void SyncChannel::OnChannelInit() { | 698 void SyncChannel::OnChannelInit() { |
| 698 pre_init_sync_message_filters_.clear(); | 699 pre_init_sync_message_filters_.clear(); |
| 699 } | 700 } |
| 700 | 701 |
| 701 } // namespace IPC | 702 } // namespace IPC |
| OLD | NEW |