summaryrefslogtreecommitdiffstats
path: root/net/disk_cache/file_posix.cc
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-13 18:00:56 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-13 18:00:56 +0000
commitfb2622f6816ed20ffd8a35994f7372b67613ba92 (patch)
tree2aa33016e72361032264904916c4374e4784fd11 /net/disk_cache/file_posix.cc
parentea9a4ee67732b90e834def1cf98be1d047a93063 (diff)
downloadchromium_src-fb2622f6816ed20ffd8a35994f7372b67613ba92.zip
chromium_src-fb2622f6816ed20ffd8a35994f7372b67613ba92.tar.gz
chromium_src-fb2622f6816ed20ffd8a35994f7372b67613ba92.tar.bz2
Disk cache: Switch the disk cache to use the cache_thread.
Add an InFlightBackendIO class that handles posting of cacheoperations back and forth between the IO thread and the cachethread. BUG=26730 TEST=unit tests Review URL: http://codereview.chromium.org/2945002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52185 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache/file_posix.cc')
-rw-r--r--net/disk_cache/file_posix.cc13
1 files changed, 11 insertions, 2 deletions
diff --git a/net/disk_cache/file_posix.cc b/net/disk_cache/file_posix.cc
index cf621f4..295f744 100644
--- a/net/disk_cache/file_posix.cc
+++ b/net/disk_cache/file_posix.cc
@@ -193,6 +193,9 @@ void InFlightIO::PostRead(disk_cache::File *file, void* buf, size_t buf_len,
io_list_.insert(operation.get());
file->AddRef(); // Balanced on InvokeCallback()
+ if (!callback_thread_)
+ callback_thread_ = MessageLoop::current();
+
WorkerPool::PostTask(FROM_HERE,
NewRunnableMethod(operation.get(), &BackgroundIO::Read),
true);
@@ -207,6 +210,9 @@ void InFlightIO::PostWrite(disk_cache::File* file, const void* buf,
io_list_.insert(operation.get());
file->AddRef(); // Balanced on InvokeCallback()
+ if (!callback_thread_)
+ callback_thread_ = MessageLoop::current();
+
WorkerPool::PostTask(FROM_HERE,
NewRunnableMethod(operation.get(), &BackgroundIO::Write,
delete_buffer),
@@ -219,6 +225,8 @@ void InFlightIO::WaitForPendingIO() {
IOList::iterator it = io_list_.begin();
InvokeCallback(*it, true);
}
+ // Unit tests can use different threads.
+ callback_thread_ = NULL;
}
// Runs on a worker thread.
@@ -372,8 +380,9 @@ size_t File::GetLength() {
// Static.
void File::WaitForPendingIO(int* num_pending_io) {
- if (*num_pending_io)
- Singleton<InFlightIO>::get()->WaitForPendingIO();
+ // We may be running unit tests so we should allow InFlightIO to reset the
+ // message loop.
+ Singleton<InFlightIO>::get()->WaitForPendingIO();
}
} // namespace disk_cache