Index: ipc/ipc_sync_message_filter.cc |
diff --git a/ipc/ipc_sync_message_filter.cc b/ipc/ipc_sync_message_filter.cc |
index 5fe03a269d948f0986156b0366f59f42462660ca..e917655cd85912b15210818516433c04cbeefa98 100644 |
--- a/ipc/ipc_sync_message_filter.cc |
+++ b/ipc/ipc_sync_message_filter.cc |
@@ -7,36 +7,20 @@ |
#include "base/bind.h" |
#include "base/location.h" |
#include "base/logging.h" |
-#include "base/memory/ptr_util.h" |
-#include "base/memory/ref_counted.h" |
-#include "base/message_loop/message_loop.h" |
#include "base/single_thread_task_runner.h" |
#include "base/synchronization/waitable_event.h" |
#include "base/threading/thread_task_runner_handle.h" |
#include "ipc/ipc_channel.h" |
#include "ipc/ipc_sync_message.h" |
-#include "ipc/mojo_event.h" |
-#include "mojo/public/cpp/bindings/sync_handle_registry.h" |
namespace IPC { |
- |
-namespace { |
- |
-// A generic callback used when watching handles synchronously. Sets |*signal| |
-// to true. Also sets |*error| to true in case of an error. |
-void OnSyncHandleReady(bool* signal, bool* error, MojoResult result) { |
- *signal = true; |
- *error = result != MOJO_RESULT_OK; |
-} |
- |
-} // namespace |
bool SyncMessageFilter::Send(Message* message) { |
if (!message->is_sync()) { |
{ |
base::AutoLock auto_lock(lock_); |
if (!io_task_runner_.get()) { |
- pending_messages_.emplace_back(base::WrapUnique(message)); |
+ pending_messages_.push_back(message); |
return true; |
} |
} |
@@ -46,7 +30,9 @@ |
return true; |
} |
- MojoEvent done_event; |
+ base::WaitableEvent done_event( |
+ base::WaitableEvent::ResetPolicy::MANUAL, |
+ base::WaitableEvent::InitialState::NOT_SIGNALED); |
PendingSyncMsg pending_message( |
SyncMessage::GetMessageId(*message), |
static_cast<SyncMessage*>(message)->GetReplyDeserializer(), |
@@ -67,33 +53,15 @@ |
FROM_HERE, |
base::Bind(&SyncMessageFilter::SendOnIOThread, this, message)); |
} else { |
- pending_messages_.emplace_back(base::WrapUnique(message)); |
+ pending_messages_.push_back(message); |
} |
} |
- bool done = false; |
- bool shutdown = false; |
- bool error = false; |
- scoped_refptr<mojo::SyncHandleRegistry> registry = |
- mojo::SyncHandleRegistry::current(); |
- registry->RegisterHandle(shutdown_mojo_event_.GetHandle(), |
- MOJO_HANDLE_SIGNAL_READABLE, |
- base::Bind(&OnSyncHandleReady, &shutdown, &error)); |
- registry->RegisterHandle(done_event.GetHandle(), |
- MOJO_HANDLE_SIGNAL_READABLE, |
- base::Bind(&OnSyncHandleReady, &done, &error)); |
- |
- const bool* stop_flags[] = { &done, &shutdown }; |
- bool result = registry->WatchAllHandles(stop_flags, 2); |
- DCHECK(result); |
- DCHECK(!error); |
- |
- if (done) { |
+ base::WaitableEvent* events[2] = { shutdown_event_, &done_event }; |
+ if (base::WaitableEvent::WaitMany(events, 2) == 1) { |
TRACE_EVENT_FLOW_END0(TRACE_DISABLED_BY_DEFAULT("ipc.flow"), |
"SyncMessageFilter::Send", &done_event); |
} |
- registry->UnregisterHandle(shutdown_mojo_event_.GetHandle()); |
- registry->UnregisterHandle(done_event.GetHandle()); |
{ |
base::AutoLock auto_lock(lock_); |
@@ -105,31 +73,26 @@ |
} |
void SyncMessageFilter::OnFilterAdded(Sender* sender) { |
- std::vector<std::unique_ptr<Message>> pending_messages; |
+ std::vector<Message*> pending_messages; |
{ |
base::AutoLock auto_lock(lock_); |
sender_ = sender; |
io_task_runner_ = base::ThreadTaskRunnerHandle::Get(); |
- shutdown_watcher_.StartWatching( |
- shutdown_event_, |
- base::Bind(&SyncMessageFilter::OnShutdownEventSignaled, this)); |
- std::swap(pending_messages_, pending_messages); |
+ pending_messages_.release(&pending_messages); |
} |
- for (auto& msg : pending_messages) |
- SendOnIOThread(msg.release()); |
+ for (auto* msg : pending_messages) |
+ SendOnIOThread(msg); |
} |
void SyncMessageFilter::OnChannelError() { |
base::AutoLock auto_lock(lock_); |
sender_ = NULL; |
- shutdown_watcher_.StopWatching(); |
SignalAllEvents(); |
} |
void SyncMessageFilter::OnChannelClosing() { |
base::AutoLock auto_lock(lock_); |
sender_ = NULL; |
- shutdown_watcher_.StopWatching(); |
SignalAllEvents(); |
} |
@@ -204,9 +167,4 @@ |
} |
} |
-void SyncMessageFilter::OnShutdownEventSignaled(base::WaitableEvent* event) { |
- DCHECK_EQ(event, shutdown_event_); |
- shutdown_mojo_event_.Signal(); |
-} |
- |
} // namespace IPC |