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/message_loop_proxy.h" | 10 #include "base/message_loop_proxy.h" |
11 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
12 #include "ipc/ipc_sync_message.h" | 12 #include "ipc/ipc_sync_message.h" |
13 | 13 |
14 using base::MessageLoopProxy; | 14 using base::MessageLoopProxy; |
15 | 15 |
16 namespace IPC { | 16 namespace IPC { |
17 | 17 |
18 SyncMessageFilter::SyncMessageFilter(base::WaitableEvent* shutdown_event) | 18 SyncMessageFilter::SyncMessageFilter(base::WaitableEvent* shutdown_event) |
19 : channel_(NULL), | 19 : channel_(NULL), |
20 listener_loop_(MessageLoopProxy::current()), | 20 listener_loop_(MessageLoopProxy::current()), |
21 shutdown_event_(shutdown_event) { | 21 shutdown_event_(shutdown_event) { |
22 } | 22 } |
23 | 23 |
24 bool SyncMessageFilter::Send(Message* message) { | 24 bool SyncMessageFilter::Send(Message* message) { |
25 { | 25 { |
26 base::AutoLock auto_lock(lock_); | 26 base::AutoLock auto_lock(lock_); |
27 if (!io_loop_) { | 27 if (!io_loop_.get()) { |
28 delete message; | 28 delete message; |
29 return false; | 29 return false; |
30 } | 30 } |
31 } | 31 } |
32 | 32 |
33 if (!message->is_sync()) { | 33 if (!message->is_sync()) { |
34 io_loop_->PostTask( | 34 io_loop_->PostTask( |
35 FROM_HERE, base::Bind(&SyncMessageFilter::SendOnIOThread, this, message)); | 35 FROM_HERE, base::Bind(&SyncMessageFilter::SendOnIOThread, this, message)); |
36 return true; | 36 return true; |
37 } | 37 } |
38 | 38 |
39 base::WaitableEvent done_event(true, false); | 39 base::WaitableEvent done_event(true, false); |
40 PendingSyncMsg pending_message( | 40 PendingSyncMsg pending_message( |
41 SyncMessage::GetMessageId(*message), | 41 SyncMessage::GetMessageId(*message), |
42 reinterpret_cast<SyncMessage*>(message)->GetReplyDeserializer(), | 42 reinterpret_cast<SyncMessage*>(message)->GetReplyDeserializer(), |
43 &done_event); | 43 &done_event); |
44 | 44 |
45 { | 45 { |
46 base::AutoLock auto_lock(lock_); | 46 base::AutoLock auto_lock(lock_); |
47 // Can't use this class on the main thread or else it can lead to deadlocks. | 47 // Can't use this class on the main thread or else it can lead to deadlocks. |
48 // Also by definition, can't use this on IO thread since we're blocking it. | 48 // Also by definition, can't use this on IO thread since we're blocking it. |
49 DCHECK(MessageLoopProxy::current() != listener_loop_); | 49 DCHECK(MessageLoopProxy::current().get() != listener_loop_.get()); |
50 DCHECK(MessageLoopProxy::current() != io_loop_); | 50 DCHECK(MessageLoopProxy::current().get() != io_loop_.get()); |
51 pending_sync_messages_.insert(&pending_message); | 51 pending_sync_messages_.insert(&pending_message); |
52 } | 52 } |
53 | 53 |
54 io_loop_->PostTask( | 54 io_loop_->PostTask( |
55 FROM_HERE, base::Bind(&SyncMessageFilter::SendOnIOThread, this, message)); | 55 FROM_HERE, base::Bind(&SyncMessageFilter::SendOnIOThread, this, message)); |
56 | 56 |
57 base::WaitableEvent* events[2] = { shutdown_event_, &done_event }; | 57 base::WaitableEvent* events[2] = { shutdown_event_, &done_event }; |
58 base::WaitableEvent::WaitMany(events, 2); | 58 base::WaitableEvent::WaitMany(events, 2); |
59 | 59 |
60 { | 60 { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 | 119 |
120 void SyncMessageFilter::SignalAllEvents() { | 120 void SyncMessageFilter::SignalAllEvents() { |
121 base::AutoLock auto_lock(lock_); | 121 base::AutoLock auto_lock(lock_); |
122 for (PendingSyncMessages::iterator iter = pending_sync_messages_.begin(); | 122 for (PendingSyncMessages::iterator iter = pending_sync_messages_.begin(); |
123 iter != pending_sync_messages_.end(); ++iter) { | 123 iter != pending_sync_messages_.end(); ++iter) { |
124 (*iter)->done_event->Signal(); | 124 (*iter)->done_event->Signal(); |
125 } | 125 } |
126 } | 126 } |
127 | 127 |
128 } // namespace IPC | 128 } // namespace IPC |
OLD | NEW |