Commit 36df43b1 authored by rvargas@google.com's avatar rvargas@google.com

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
parent 6b8c2fb4
......@@ -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"
......
......@@ -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);
}
......
......@@ -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.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment