diff options
author | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-19 18:55:04 +0000 |
---|---|---|
committer | rvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-19 18:55:04 +0000 |
commit | 36df43b17c30bc9d9ddba3130d087b9c96af9b5f (patch) | |
tree | f7924dcee1f3fb63eb5e89f506d1c31449a6097e | |
parent | 6b8c2fb4723a7d9da5703f3d13526f136874e21f (diff) | |
download | chromium_src-36df43b17c30bc9d9ddba3130d087b9c96af9b5f.zip chromium_src-36df43b17c30bc9d9ddba3130d087b9c96af9b5f.tar.gz chromium_src-36df43b17c30bc9d9ddba3130d087b9c96af9b5f.tar.bz2 |
Disk cache: Protect the code against misuse...
So avoid crashing even if the destructor is not
called before killing the IO thread.
BUG=49271
TEST=none
Review URL: http://codereview.chromium.org/3044006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52924 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | net/disk_cache/in_flight_backend_io.h | 1 | ||||
-rw-r--r-- | net/disk_cache/in_flight_io.cc | 4 | ||||
-rw-r--r-- | net/disk_cache/in_flight_io.h | 8 |
3 files changed, 7 insertions, 6 deletions
diff --git a/net/disk_cache/in_flight_backend_io.h b/net/disk_cache/in_flight_backend_io.h index 4db2d11..1cd0d41 100644 --- a/net/disk_cache/in_flight_backend_io.h +++ b/net/disk_cache/in_flight_backend_io.h @@ -5,6 +5,7 @@ #ifndef NET_DISK_CACHE_IN_FLIGHT_BACKEND_IO_H_ #define NET_DISK_CACHE_IN_FLIGHT_BACKEND_IO_H_ +#include <list> #include <string> #include "base/message_loop_proxy.h" diff --git a/net/disk_cache/in_flight_io.cc b/net/disk_cache/in_flight_io.cc index 24b0e9c..6112a9c 100644 --- a/net/disk_cache/in_flight_io.cc +++ b/net/disk_cache/in_flight_io.cc @@ -37,7 +37,7 @@ void InFlightIO::WaitForPendingIO() { // Runs on a background thread. void InFlightIO::OnIOComplete(BackgroundIO* operation) { #ifndef NDEBUG - if (callback_thread_ == MessageLoop::current()) { + if (callback_thread_->BelongsToCurrentThread()) { DCHECK(single_thread_ || !running_); single_thread_ = true; } @@ -66,7 +66,7 @@ void InFlightIO::InvokeCallback(BackgroundIO* operation, bool cancel_task) { // Runs on the primary thread. void InFlightIO::OnOperationPosted(BackgroundIO* operation) { - DCHECK(callback_thread_ == MessageLoop::current()); + DCHECK(callback_thread_->BelongsToCurrentThread()); io_list_.insert(operation); } diff --git a/net/disk_cache/in_flight_io.h b/net/disk_cache/in_flight_io.h index 75552cb7..4486f44 100644 --- a/net/disk_cache/in_flight_io.h +++ b/net/disk_cache/in_flight_io.h @@ -7,7 +7,7 @@ #include <set> -#include "base/message_loop.h" +#include "base/message_loop_proxy.h" #include "base/waitable_event.h" namespace disk_cache { @@ -89,8 +89,8 @@ class BackgroundIO : public base::RefCountedThreadSafe<BackgroundIO> { class InFlightIO { public: InFlightIO() - : callback_thread_(MessageLoop::current()), running_(false), - single_thread_(false) {} + : callback_thread_(base::MessageLoopProxy::CreateForCurrentThread()), + running_(false), single_thread_(false) {} virtual ~InFlightIO() {} // Blocks the current thread until all IO operations tracked by this object @@ -121,7 +121,7 @@ class InFlightIO { typedef std::set<scoped_refptr<BackgroundIO> > IOList; IOList io_list_; // List of pending, in-flight io operations. - MessageLoop* callback_thread_; + scoped_refptr<base::MessageLoopProxy> callback_thread_; bool running_; // True after the first posted operation completes. bool single_thread_; // True if we only have one thread. |