diff options
author | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-18 01:50:39 +0000 |
---|---|---|
committer | dumi@chromium.org <dumi@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-18 01:50:39 +0000 |
commit | 5407356b8d313cfdcc8816b67c463791077b56e7 (patch) | |
tree | cdd0e3b0db173e4a99491eae91377007ac484df3 /chrome | |
parent | 80d0d16733726a5b80c7e5a9213f3fc3af3fdf25 (diff) | |
download | chromium_src-5407356b8d313cfdcc8816b67c463791077b56e7.zip chromium_src-5407356b8d313cfdcc8816b67c463791077b56e7.tar.gz chromium_src-5407356b8d313cfdcc8816b67c463791077b56e7.tar.bz2 |
Remove the state associated with an IPC we're waiting for when the
shutdown event was signaled.
TEST=none
BUG=32023
Review URL: http://codereview.chromium.org/607014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39316 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/common/db_message_filter.cc | 9 | ||||
-rw-r--r-- | chrome/common/db_message_filter.h | 26 |
2 files changed, 24 insertions, 11 deletions
diff --git a/chrome/common/db_message_filter.cc b/chrome/common/db_message_filter.cc index fb1944b..39c4120 100644 --- a/chrome/common/db_message_filter.cc +++ b/chrome/common/db_message_filter.cc @@ -13,7 +13,6 @@ DBMessageFilter* DBMessageFilter::instance_ = NULL; DBMessageFilter::DBMessageFilter() : io_thread_message_loop_(ChildProcess::current()->io_message_loop()), channel_(NULL), - channel_lock_(new Lock()), shutdown_event_(ChildProcess::current()->GetShutDownEvent()), messages_awaiting_replies_(new IDMap<DBMessageState>()), unique_id_generator_(new base::AtomicSequenceNumber()) { @@ -38,21 +37,21 @@ static void SendMessageOnIOThread(IPC::Message* message, void DBMessageFilter::Send(IPC::Message* message) { io_thread_message_loop_->PostTask(FROM_HERE, NewRunnableFunction(SendMessageOnIOThread, message, channel_, - channel_lock_.get())); + &channel_lock_)); } void DBMessageFilter::OnFilterAdded(IPC::Channel* channel) { - AutoLock channel_auto_lock(*channel_lock_); + AutoLock channel_auto_lock(channel_lock_); channel_ = channel; } void DBMessageFilter::OnChannelError() { - AutoLock channel_auto_lock(*channel_lock_); + AutoLock channel_auto_lock(channel_lock_); channel_ = NULL; } void DBMessageFilter::OnChannelClosing() { - AutoLock channel_auto_lock(*channel_lock_); + AutoLock channel_auto_lock(channel_lock_); channel_ = NULL; } diff --git a/chrome/common/db_message_filter.h b/chrome/common/db_message_filter.h index aaf468f..f2612fb 100644 --- a/chrome/common/db_message_filter.h +++ b/chrome/common/db_message_filter.h @@ -7,6 +7,7 @@ #include "base/atomic_sequence_num.h" #include "base/id_map.h" +#include "base/lock.h" #include "base/scoped_ptr.h" #include "base/waitable_event.h" #include "ipc/ipc_channel_proxy.h" @@ -26,12 +27,12 @@ class Channel; // use GetInstance(). class DBMessageFilter : public IPC::ChannelProxy::MessageFilter { public: - // Creates a new DBMessageFilter instance. - DBMessageFilter(); - // Returns the DBMessageFilter singleton created in this renderer process. static DBMessageFilter* GetInstance() { return instance_; } + // Creates a new DBMessageFilter instance. + DBMessageFilter(); + // Returns a unique ID for use when calling the SendAndWait() method. virtual int GetUniqueID(); @@ -49,12 +50,21 @@ class DBMessageFilter : public IPC::ChannelProxy::MessageFilter { base::WaitableEvent waitable_event(false, false); DBMessageState state = { reinterpret_cast<intptr_t>(&result), &waitable_event }; - messages_awaiting_replies_->AddWithID(&state, message_id); + { + AutoLock msgs_awaiting_replies_autolock(messages_awaiting_replies_lock_); + messages_awaiting_replies_->AddWithID(&state, message_id); + } Send(message); base::WaitableEvent* events[2] = { shutdown_event_, &waitable_event }; - return (base::WaitableEvent::WaitMany(events, 2) ? result : default_result); + if (base::WaitableEvent::WaitMany(events, 2)) { + return result; + } else { + AutoLock msgs_awaiting_replies_autolock(messages_awaiting_replies_lock_); + messages_awaiting_replies_->Remove(message_id); + return default_result; + } } // Processes incoming message |message| from the browser process. @@ -84,6 +94,7 @@ class DBMessageFilter : public IPC::ChannelProxy::MessageFilter { // Processes the reply to a sync DB request. template<class ResultType> void OnResponse(int32 message_id, ResultType result) { + AutoLock msgs_awaiting_replies_autolock(messages_awaiting_replies_lock_); DBMessageState *state = messages_awaiting_replies_->Lookup(message_id); if (state) { messages_awaiting_replies_->Remove(message_id); @@ -109,7 +120,7 @@ class DBMessageFilter : public IPC::ChannelProxy::MessageFilter { IPC::Channel* channel_; // A lock around the channel. - scoped_ptr<Lock> channel_lock_; + Lock channel_lock_; // The shutdown event. base::WaitableEvent* shutdown_event_; @@ -118,6 +129,9 @@ class DBMessageFilter : public IPC::ChannelProxy::MessageFilter { // DBMessageState instance. scoped_ptr<IDMap<DBMessageState> > messages_awaiting_replies_; + // The lock for 'messages_awaiting_replies_'. + Lock messages_awaiting_replies_lock_; + // A thread-safe unique number generator. scoped_ptr<base::AtomicSequenceNumber> unique_id_generator_; |