| 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/macros.h" | 10 #include "base/macros.h" |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 scoped_refptr<base::SingleThreadTaskRunner> filter_task_runner_; | 92 scoped_refptr<base::SingleThreadTaskRunner> filter_task_runner_; |
| 93 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; | 93 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner_; |
| 94 | 94 |
| 95 DISALLOW_COPY_AND_ASSIGN(IOMessageLoopObserver); | 95 DISALLOW_COPY_AND_ASSIGN(IOMessageLoopObserver); |
| 96 }; | 96 }; |
| 97 | 97 |
| 98 bool SyncMessageFilter::Send(Message* message) { | 98 bool SyncMessageFilter::Send(Message* message) { |
| 99 if (!message->is_sync()) { | 99 if (!message->is_sync()) { |
| 100 { | 100 { |
| 101 base::AutoLock auto_lock(lock_); | 101 base::AutoLock auto_lock(lock_); |
| 102 if (sender_ && is_channel_send_thread_safe_) { | 102 if (!io_task_runner_.get()) { |
| 103 sender_->Send(message); | |
| 104 return true; | |
| 105 } else if (!io_task_runner_.get()) { | |
| 106 pending_messages_.emplace_back(base::WrapUnique(message)); | 103 pending_messages_.emplace_back(base::WrapUnique(message)); |
| 107 return true; | 104 return true; |
| 108 } | 105 } |
| 109 } | 106 } |
| 110 io_task_runner_->PostTask( | 107 io_task_runner_->PostTask( |
| 111 FROM_HERE, | 108 FROM_HERE, |
| 112 base::Bind(&SyncMessageFilter::SendOnIOThread, this, message)); | 109 base::Bind(&SyncMessageFilter::SendOnIOThread, this, message)); |
| 113 return true; | 110 return true; |
| 114 } | 111 } |
| 115 | 112 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 "SyncMessageFilter::OnMessageReceived", | 210 "SyncMessageFilter::OnMessageReceived", |
| 214 (*iter)->done_event); | 211 (*iter)->done_event); |
| 215 (*iter)->done_event->Signal(); | 212 (*iter)->done_event->Signal(); |
| 216 return true; | 213 return true; |
| 217 } | 214 } |
| 218 } | 215 } |
| 219 | 216 |
| 220 return false; | 217 return false; |
| 221 } | 218 } |
| 222 | 219 |
| 223 SyncMessageFilter::SyncMessageFilter(base::WaitableEvent* shutdown_event, | 220 SyncMessageFilter::SyncMessageFilter(base::WaitableEvent* shutdown_event) |
| 224 bool is_channel_send_thread_safe) | |
| 225 : sender_(NULL), | 221 : sender_(NULL), |
| 226 is_channel_send_thread_safe_(is_channel_send_thread_safe), | |
| 227 listener_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 222 listener_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 228 shutdown_event_(shutdown_event), | 223 shutdown_event_(shutdown_event), |
| 229 weak_factory_(this) { | 224 weak_factory_(this) { |
| 230 io_message_loop_observer_ = new IOMessageLoopObserver( | 225 io_message_loop_observer_ = new IOMessageLoopObserver( |
| 231 weak_factory_.GetWeakPtr(), listener_task_runner_); | 226 weak_factory_.GetWeakPtr(), listener_task_runner_); |
| 232 } | 227 } |
| 233 | 228 |
| 234 SyncMessageFilter::~SyncMessageFilter() { | 229 SyncMessageFilter::~SyncMessageFilter() { |
| 235 io_message_loop_observer_->Stop(); | 230 io_message_loop_observer_->Stop(); |
| 236 } | 231 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 | 264 |
| 270 void SyncMessageFilter::OnIOMessageLoopDestroyed() { | 265 void SyncMessageFilter::OnIOMessageLoopDestroyed() { |
| 271 // Since we use an async WaitableEventWatcher to watch the shutdown event | 266 // Since we use an async WaitableEventWatcher to watch the shutdown event |
| 272 // from the IO thread, we can't forward the shutdown signal after the IO | 267 // from the IO thread, we can't forward the shutdown signal after the IO |
| 273 // message loop is destroyed. Since that destruction indicates shutdown | 268 // message loop is destroyed. Since that destruction indicates shutdown |
| 274 // anyway, we manually signal the shutdown event in this case. | 269 // anyway, we manually signal the shutdown event in this case. |
| 275 shutdown_mojo_event_.Signal(); | 270 shutdown_mojo_event_.Signal(); |
| 276 } | 271 } |
| 277 | 272 |
| 278 } // namespace IPC | 273 } // namespace IPC |
| OLD | NEW |