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_message_filter.h" | 5 #include "ipc/ipc_sync_message_filter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
12 #include "base/threading/thread_task_runner_handle.h" | 12 #include "base/threading/thread_task_runner_handle.h" |
13 #include "ipc/ipc_channel.h" | 13 #include "ipc/ipc_channel.h" |
14 #include "ipc/ipc_sync_message.h" | 14 #include "ipc/ipc_sync_message.h" |
15 | 15 |
16 namespace IPC { | 16 namespace IPC { |
17 | 17 |
18 bool SyncMessageFilter::Send(Message* message) { | 18 bool SyncMessageFilter::Send(Message* message) { |
19 if (!message->is_sync()) { | 19 if (!message->is_sync()) { |
20 { | 20 { |
21 base::AutoLock auto_lock(lock_); | 21 base::AutoLock auto_lock(lock_); |
22 if (sender_ && is_channel_send_thread_safe_) { | 22 if (!io_task_runner_.get()) { |
23 sender_->Send(message); | |
24 return true; | |
25 } else if (!io_task_runner_.get()) { | |
26 pending_messages_.push_back(message); | 23 pending_messages_.push_back(message); |
27 return true; | 24 return true; |
28 } | 25 } |
29 } | 26 } |
30 io_task_runner_->PostTask( | 27 io_task_runner_->PostTask( |
31 FROM_HERE, | 28 FROM_HERE, |
32 base::Bind(&SyncMessageFilter::SendOnIOThread, this, message)); | 29 base::Bind(&SyncMessageFilter::SendOnIOThread, this, message)); |
33 return true; | 30 return true; |
34 } | 31 } |
35 | 32 |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 "SyncMessageFilter::OnMessageReceived", | 107 "SyncMessageFilter::OnMessageReceived", |
111 (*iter)->done_event); | 108 (*iter)->done_event); |
112 (*iter)->done_event->Signal(); | 109 (*iter)->done_event->Signal(); |
113 return true; | 110 return true; |
114 } | 111 } |
115 } | 112 } |
116 | 113 |
117 return false; | 114 return false; |
118 } | 115 } |
119 | 116 |
| 117 bool SyncMessageFilter::SendNow(std::unique_ptr<Message> message) { |
| 118 if (!message->is_sync()) { |
| 119 base::AutoLock auto_lock(lock_); |
| 120 if (sender_ && is_channel_send_thread_safe_) { |
| 121 sender_->Send(message.release()); |
| 122 return true; |
| 123 } |
| 124 } |
| 125 |
| 126 // Fall back on default Send behavior. |
| 127 return Send(message.release()); |
| 128 } |
| 129 |
120 SyncMessageFilter::SyncMessageFilter(base::WaitableEvent* shutdown_event, | 130 SyncMessageFilter::SyncMessageFilter(base::WaitableEvent* shutdown_event, |
121 bool is_channel_send_thread_safe) | 131 bool is_channel_send_thread_safe) |
122 : sender_(NULL), | 132 : sender_(NULL), |
123 is_channel_send_thread_safe_(is_channel_send_thread_safe), | 133 is_channel_send_thread_safe_(is_channel_send_thread_safe), |
124 listener_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 134 listener_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
125 shutdown_event_(shutdown_event) { | 135 shutdown_event_(shutdown_event) { |
126 } | 136 } |
127 | 137 |
128 SyncMessageFilter::~SyncMessageFilter() { | 138 SyncMessageFilter::~SyncMessageFilter() { |
129 } | 139 } |
(...skipping 19 matching lines...) Expand all Loading... |
149 for (PendingSyncMessages::iterator iter = pending_sync_messages_.begin(); | 159 for (PendingSyncMessages::iterator iter = pending_sync_messages_.begin(); |
150 iter != pending_sync_messages_.end(); ++iter) { | 160 iter != pending_sync_messages_.end(); ++iter) { |
151 TRACE_EVENT_FLOW_BEGIN0(TRACE_DISABLED_BY_DEFAULT("ipc.flow"), | 161 TRACE_EVENT_FLOW_BEGIN0(TRACE_DISABLED_BY_DEFAULT("ipc.flow"), |
152 "SyncMessageFilter::SignalAllEvents", | 162 "SyncMessageFilter::SignalAllEvents", |
153 (*iter)->done_event); | 163 (*iter)->done_event); |
154 (*iter)->done_event->Signal(); | 164 (*iter)->done_event->Signal(); |
155 } | 165 } |
156 } | 166 } |
157 | 167 |
158 } // namespace IPC | 168 } // namespace IPC |
OLD | NEW |