Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(456)

Unified Diff: ipc/ipc_sync_channel.cc

Issue 12094106: Refactor: Simplify WaitableEventWatcher. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« ipc/ipc_sync_channel.h ('K') | « ipc/ipc_sync_channel.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ipc/ipc_sync_channel.cc
diff --git a/ipc/ipc_sync_channel.cc b/ipc/ipc_sync_channel.cc
index a300c0f786702843e48c23ab73069f9fab3e0b42..dfce49315c249b7264baaf3db3ede27083846600 100644
--- a/ipc/ipc_sync_channel.cc
+++ b/ipc/ipc_sync_channel.cc
@@ -234,6 +234,9 @@ SyncChannel::SyncContext::SyncContext(
received_sync_msgs_(ReceivedSyncMsgQueue::AddContext()),
shutdown_event_(shutdown_event),
restrict_dispatch_group_(kRestrictDispatchGroup_None) {
+ shutdown_watcher_callback_ = base::Bind(
+ &SyncChannel::SyncContext::OnWaitableEventSignaled,
+ base::Unretained(this));
dmichael (off chromium) 2013/02/01 17:27:18 Okay, so the problem is if you don't use base::Unr
}
SyncChannel::SyncContext::~SyncContext() {
@@ -353,7 +356,7 @@ void SyncChannel::SyncContext::OnChannelError() {
}
void SyncChannel::SyncContext::OnChannelOpened() {
- shutdown_watcher_.StartWatching(shutdown_event_, this);
+ shutdown_watcher_.StartWatching(shutdown_event_, shutdown_watcher_callback_);
Context::OnChannelOpened();
}
@@ -517,21 +520,22 @@ void SyncChannel::WaitForReplyWithNestedMessageLoop(SyncContext* context) {
base::WaitableEventWatcher* old_send_done_event_watcher =
sync_msg_queue->top_send_done_watcher();
- base::WaitableEventWatcher::Delegate* old_delegate = NULL;
+ base::WaitableEventWatcher::EventCallback old_callback;
base::WaitableEvent* old_event = NULL;
// Maintain a local global stack of send done delegates to ensure that
// nested sync calls complete in the correct sequence, i.e. the
// outermost call completes first, etc.
if (old_send_done_event_watcher) {
- old_delegate = old_send_done_event_watcher->delegate();
+ old_callback = old_send_done_event_watcher->callback();
dmichael (off chromium) 2013/02/01 17:27:18 If you instead just make the callback here (e.g.,
old_event = old_send_done_event_watcher->GetWatchedEvent();
old_send_done_event_watcher->StopWatching();
}
sync_msg_queue->set_top_send_done_watcher(&send_done_watcher);
- send_done_watcher.StartWatching(context->GetSendDoneEvent(), context);
+ send_done_watcher.StartWatching(context->GetSendDoneEvent(),
+ context->shutdown_watcher_callback());
{
MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
@@ -540,7 +544,7 @@ void SyncChannel::WaitForReplyWithNestedMessageLoop(SyncContext* context) {
sync_msg_queue->set_top_send_done_watcher(old_send_done_event_watcher);
if (old_send_done_event_watcher && old_event) {
- old_send_done_event_watcher->StartWatching(old_event, old_delegate);
+ old_send_done_event_watcher->StartWatching(old_event, old_callback);
}
}
@@ -549,7 +553,7 @@ void SyncChannel::OnWaitableEventSignaled(WaitableEvent* event) {
// The call to DispatchMessages might delete this object, so reregister
// the object watcher first.
event->Reset();
- dispatch_watcher_.StartWatching(event, this);
+ dispatch_watcher_.StartWatching(event, dispatch_watcher_callback_);
sync_context()->DispatchMessages();
}
@@ -560,7 +564,11 @@ void SyncChannel::StartWatching() {
// stop or keep watching. So we always watch it, and create the event as
// manual reset since the object watcher might otherwise reset the event
// when we're doing a WaitMany.
- dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(), this);
+ dispatch_watcher_callback_ =
+ base::Bind(&SyncChannel::OnWaitableEventSignaled,
+ base::Unretained(this));
+ dispatch_watcher_.StartWatching(sync_context()->GetDispatchEvent(),
+ dispatch_watcher_callback_);
}
} // namespace IPC
« ipc/ipc_sync_channel.h ('K') | « ipc/ipc_sync_channel.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698