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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 // is swapped back into |ReceivedSyncMsgQueue::top_send_done_event_watcher_|, | 81 // is swapped back into |ReceivedSyncMsgQueue::top_send_done_event_watcher_|, |
82 // and its watch is resumed immediately. | 82 // and its watch is resumed immediately. |
83 class NestedSendDoneWatcher { | 83 class NestedSendDoneWatcher { |
84 public: | 84 public: |
85 NestedSendDoneWatcher(SyncChannel::SyncContext* context, | 85 NestedSendDoneWatcher(SyncChannel::SyncContext* context, |
86 base::RunLoop* run_loop) | 86 base::RunLoop* run_loop) |
87 : sync_msg_queue_(context->received_sync_msgs()), | 87 : sync_msg_queue_(context->received_sync_msgs()), |
88 outer_state_(sync_msg_queue_->top_send_done_event_watcher_), | 88 outer_state_(sync_msg_queue_->top_send_done_event_watcher_), |
89 event_(context->GetSendDoneEvent()), | 89 event_(context->GetSendDoneEvent()), |
90 callback_( | 90 callback_( |
91 base::Bind(&SyncChannel::SyncContext::OnSendDoneEventSignaled, | 91 base::BindOnce(&SyncChannel::SyncContext::OnSendDoneEventSignaled, |
92 context, | 92 context, |
93 run_loop)) { | 93 run_loop)) { |
94 sync_msg_queue_->top_send_done_event_watcher_ = this; | 94 sync_msg_queue_->top_send_done_event_watcher_ = this; |
95 if (outer_state_) | 95 if (outer_state_) |
96 outer_state_->StopWatching(); | 96 outer_state_->StopWatching(); |
97 StartWatching(); | 97 StartWatching(); |
98 } | 98 } |
99 | 99 |
100 ~NestedSendDoneWatcher() { | 100 ~NestedSendDoneWatcher() { |
101 sync_msg_queue_->top_send_done_event_watcher_ = outer_state_; | 101 sync_msg_queue_->top_send_done_event_watcher_ = outer_state_; |
102 if (outer_state_) | 102 if (outer_state_) |
103 outer_state_->StartWatching(); | 103 outer_state_->StartWatching(); |
104 } | 104 } |
105 | 105 |
106 private: | 106 private: |
107 void StartWatching() { watcher_.StartWatching(event_, callback_); } | 107 void Run(WaitableEvent* event) { |
108 DCHECK(callback_); | |
109 std::move(callback_).Run(event); | |
110 } | |
111 | |
112 void StartWatching() { | |
113 watcher_.StartWatching(event_, base::BindOnce(&NestedSendDoneWatcher::Run, | |
114 base::Unretained(this))); | |
dcheng
2017/04/14 21:56:59
Out of curiosity, why do we need this intermediate
tzik
2017/04/17 08:28:34
StartWatching/StopWatching may be called more than
| |
115 } | |
116 | |
108 void StopWatching() { watcher_.StopWatching(); } | 117 void StopWatching() { watcher_.StopWatching(); } |
109 | 118 |
110 ReceivedSyncMsgQueue* const sync_msg_queue_; | 119 ReceivedSyncMsgQueue* const sync_msg_queue_; |
111 NestedSendDoneWatcher* const outer_state_; | 120 NestedSendDoneWatcher* const outer_state_; |
112 | 121 |
113 base::WaitableEvent* const event_; | 122 base::WaitableEvent* const event_; |
114 const base::WaitableEventWatcher::EventCallback callback_; | 123 base::WaitableEventWatcher::EventCallback callback_; |
115 base::WaitableEventWatcher watcher_; | 124 base::WaitableEventWatcher watcher_; |
116 | 125 |
117 DISALLOW_COPY_AND_ASSIGN(NestedSendDoneWatcher); | 126 DISALLOW_COPY_AND_ASSIGN(NestedSendDoneWatcher); |
118 }; | 127 }; |
119 | 128 |
120 // Returns the ReceivedSyncMsgQueue instance for this thread, creating one | 129 // Returns the ReceivedSyncMsgQueue instance for this thread, creating one |
121 // if necessary. Call RemoveContext on the same thread when done. | 130 // if necessary. Call RemoveContext on the same thread when done. |
122 static ReceivedSyncMsgQueue* AddContext() { | 131 static ReceivedSyncMsgQueue* AddContext() { |
123 // We want one ReceivedSyncMsgQueue per listener thread (i.e. since multiple | 132 // We want one ReceivedSyncMsgQueue per listener thread (i.e. since multiple |
124 // SyncChannel objects can block the same thread). | 133 // SyncChannel objects can block the same thread). |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
698 sync_context()->GetDispatchEvent(), | 707 sync_context()->GetDispatchEvent(), |
699 base::Bind(&SyncChannel::OnDispatchEventSignaled, | 708 base::Bind(&SyncChannel::OnDispatchEventSignaled, |
700 base::Unretained(this))); | 709 base::Unretained(this))); |
701 } | 710 } |
702 | 711 |
703 void SyncChannel::OnChannelInit() { | 712 void SyncChannel::OnChannelInit() { |
704 pre_init_sync_message_filters_.clear(); | 713 pre_init_sync_message_filters_.clear(); |
705 } | 714 } |
706 | 715 |
707 } // namespace IPC | 716 } // namespace IPC |
OLD | NEW |