summaryrefslogtreecommitdiffstats
path: root/ipc
diff options
context:
space:
mode:
authorteravest@chromium.org <teravest@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-04 18:14:28 +0000
committerteravest@chromium.org <teravest@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-02-04 18:14:28 +0000
commit329be0548058bf398a8bd87a425fe79372f1740e (patch)
tree80f84baa721700a4f4e0e4727697120584cbb38d /ipc
parentb02d89c3004cffd1e8a31432520f1ea97a6bc58e (diff)
downloadchromium_src-329be0548058bf398a8bd87a425fe79372f1740e.zip
chromium_src-329be0548058bf398a8bd87a425fe79372f1740e.tar.gz
chromium_src-329be0548058bf398a8bd87a425fe79372f1740e.tar.bz2
Refactor: Simplify WaitableEventWatcher.
This change uses a callback instead of a delegate for specifying what should be called when a WaitableEvent occurs. This simplifies the class and gets rid of a workaround internal to the class to prevent name collision on "Delegate" inner classes. Tested (linux and windows): out/Debug/base_unittests --gtest_filter=*WaitableEventWatcherTest* out/Release/ipc_tests with valgrind and leak-check=yes Previously reverted at: https://codereview.chromium.org/12087120/ BUG= Review URL: https://chromiumcodereview.appspot.com/12094106 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@180450 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ipc')
-rw-r--r--ipc/ipc_sync_channel.cc26
-rw-r--r--ipc/ipc_sync_channel.h16
2 files changed, 27 insertions, 15 deletions
diff --git a/ipc/ipc_sync_channel.cc b/ipc/ipc_sync_channel.cc
index a300c0f..1ce9f6c 100644
--- a/ipc/ipc_sync_channel.cc
+++ b/ipc/ipc_sync_channel.cc
@@ -353,7 +353,10 @@ void SyncChannel::SyncContext::OnChannelError() {
}
void SyncChannel::SyncContext::OnChannelOpened() {
- shutdown_watcher_.StartWatching(shutdown_event_, this);
+ shutdown_watcher_.StartWatching(
+ shutdown_event_,
+ base::Bind(&SyncChannel::SyncContext::OnWaitableEventSignaled,
+ base::Unretained(this)));
Context::OnChannelOpened();
}
@@ -396,6 +399,10 @@ void SyncChannel::SyncContext::OnWaitableEventSignaled(WaitableEvent* event) {
}
}
+base::WaitableEventWatcher::EventCallback
+ SyncChannel::SyncContext::MakeWaitableEventCallback() {
+ return base::Bind(&SyncChannel::SyncContext::OnWaitableEventSignaled, this);
+}
SyncChannel::SyncChannel(
const IPC::ChannelHandle& channel_handle,
@@ -517,21 +524,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();
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->MakeWaitableEventCallback());
{
MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current());
@@ -540,7 +548,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 +557,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 +568,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
diff --git a/ipc/ipc_sync_channel.h b/ipc/ipc_sync_channel.h
index 87fc1f4..8b66432 100644
--- a/ipc/ipc_sync_channel.h
+++ b/ipc/ipc_sync_channel.h
@@ -58,8 +58,7 @@ class SyncMessage;
// is more than this object. If the message loop goes away while this object
// is running and it's used to send a message, then it will use the invalid
// message loop pointer to proxy it to the ipc thread.
-class IPC_EXPORT SyncChannel : public ChannelProxy,
- public base::WaitableEventWatcher::Delegate {
+class IPC_EXPORT SyncChannel : public ChannelProxy {
public:
enum RestrictDispatchGroup {
kRestrictDispatchGroup_None = 0,
@@ -115,8 +114,7 @@ class IPC_EXPORT SyncChannel : public ChannelProxy,
// SyncContext holds the per object data for SyncChannel, so that SyncChannel
// can be deleted while it's being used in a different thread. See
// ChannelProxy::Context for more information.
- class SyncContext : public Context,
- public base::WaitableEventWatcher::Delegate {
+ class SyncContext : public Context {
public:
SyncContext(Listener* listener,
base::SingleThreadTaskRunner* ipc_task_runner,
@@ -163,6 +161,8 @@ class IPC_EXPORT SyncChannel : public ChannelProxy,
return restrict_dispatch_group_;
}
+ base::WaitableEventWatcher::EventCallback MakeWaitableEventCallback();
+
private:
virtual ~SyncContext();
// ChannelProxy methods that we override.
@@ -179,8 +179,7 @@ class IPC_EXPORT SyncChannel : public ChannelProxy,
// Cancels all pending Send calls.
void CancelPendingSends();
- // WaitableEventWatcher::Delegate implementation.
- virtual void OnWaitableEventSignaled(base::WaitableEvent* arg) OVERRIDE;
+ void OnWaitableEventSignaled(base::WaitableEvent* event);
typedef std::deque<PendingSyncMsg> PendingSyncMessageQueue;
PendingSyncMessageQueue deserializers_;
@@ -190,12 +189,12 @@ class IPC_EXPORT SyncChannel : public ChannelProxy,
base::WaitableEvent* shutdown_event_;
base::WaitableEventWatcher shutdown_watcher_;
+ base::WaitableEventWatcher::EventCallback shutdown_watcher_callback_;
int restrict_dispatch_group_;
};
private:
- // WaitableEventWatcher::Delegate implementation.
- virtual void OnWaitableEventSignaled(base::WaitableEvent* arg) OVERRIDE;
+ void OnWaitableEventSignaled(base::WaitableEvent* arg);
SyncContext* sync_context() {
return reinterpret_cast<SyncContext*>(context());
@@ -217,6 +216,7 @@ class IPC_EXPORT SyncChannel : public ChannelProxy,
// Used to signal events between the IPC and listener threads.
base::WaitableEventWatcher dispatch_watcher_;
+ base::WaitableEventWatcher::EventCallback dispatch_watcher_callback_;
DISALLOW_COPY_AND_ASSIGN(SyncChannel);
};