summaryrefslogtreecommitdiffstats
path: root/net/tools
diff options
context:
space:
mode:
authorrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-15 19:31:51 +0000
committerrvargas@google.com <rvargas@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-15 19:31:51 +0000
commitec44a9a1abaf8ffdc001182b0345295081c6b714 (patch)
treea14fa1aa0cdee98b8257b5845499bf33e5a36394 /net/tools
parenteb69ca8e12e0d7a7d42ea328a4597475d5198bc7 (diff)
downloadchromium_src-ec44a9a1abaf8ffdc001182b0345295081c6b714.zip
chromium_src-ec44a9a1abaf8ffdc001182b0345295081c6b714.tar.gz
chromium_src-ec44a9a1abaf8ffdc001182b0345295081c6b714.tar.bz2
Disk cache: Update the disk cache tools and tests to use
the new interface (provide a cache thread and callback). BUG=26730 TEST=unit tests Review URL: http://codereview.chromium.org/2739007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@49819 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/tools')
-rw-r--r--net/tools/crash_cache/crash_cache.cc114
-rw-r--r--net/tools/dump_cache/cache_dumper.cc30
-rw-r--r--net/tools/dump_cache/cache_dumper.h33
-rw-r--r--net/tools/dump_cache/upgrade.cc101
4 files changed, 193 insertions, 85 deletions
diff --git a/net/tools/crash_cache/crash_cache.cc b/net/tools/crash_cache/crash_cache.cc
index 4686d13..a26c873 100644
--- a/net/tools/crash_cache/crash_cache.cc
+++ b/net/tools/crash_cache/crash_cache.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -17,7 +17,9 @@
#include "base/path_service.h"
#include "base/process_util.h"
#include "base/string_util.h"
-
+#include "base/thread.h"
+#include "net/base/net_errors.h"
+#include "net/base/test_completion_callback.h"
#include "net/disk_cache/backend_impl.h"
#include "net/disk_cache/disk_cache.h"
#include "net/disk_cache/disk_cache_test_util.h"
@@ -117,10 +119,14 @@ bool CreateTargetFolder(const FilePath& path, RankCrashes action,
}
// Generates the files for an empty and one item cache.
-int SimpleInsert(const FilePath& path, RankCrashes action) {
- disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0,
- net::DISK_CACHE);
- if (!cache || cache->GetEntryCount())
+int SimpleInsert(const FilePath& path, RankCrashes action,
+ base::Thread* cache_thread) {
+ TestCompletionCallback cb;
+ disk_cache::Backend* cache;
+ int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, path, 0, false,
+ cache_thread->message_loop_proxy(),
+ &cache, &cb);
+ if (cb.GetResult(rv) != net::OK || cache->GetEntryCount())
return GENERIC;
const char* test_name = "some other key";
@@ -131,7 +137,8 @@ int SimpleInsert(const FilePath& path, RankCrashes action) {
}
disk_cache::Entry* entry;
- if (!cache->CreateEntry(test_name, &entry))
+ rv = cache->CreateEntry(test_name, &entry, &cb);
+ if (cb.GetResult(rv) != net::OK)
return GENERIC;
entry->Close();
@@ -140,36 +147,44 @@ int SimpleInsert(const FilePath& path, RankCrashes action) {
g_rankings_crash = action;
test_name = kCrashEntryName;
- if (!cache->CreateEntry(test_name, &entry))
+ rv = cache->CreateEntry(test_name, &entry, &cb);
+ if (cb.GetResult(rv) != net::OK)
return GENERIC;
return NOT_REACHED;
}
// Generates the files for a one item cache, and removing the head.
-int SimpleRemove(const FilePath& path, RankCrashes action) {
+int SimpleRemove(const FilePath& path, RankCrashes action,
+ base::Thread* cache_thread) {
DCHECK(action >= disk_cache::REMOVE_ONE_1);
DCHECK(action <= disk_cache::REMOVE_TAIL_3);
- disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0,
- net::DISK_CACHE);
- if (!cache || cache->GetEntryCount())
+ TestCompletionCallback cb;
+ disk_cache::Backend* cache;
+ int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, path, 0, false,
+ cache_thread->message_loop_proxy(),
+ &cache, &cb);
+ if (cb.GetResult(rv) != net::OK || cache->GetEntryCount())
return GENERIC;
disk_cache::Entry* entry;
- if (!cache->CreateEntry(kCrashEntryName, &entry))
+ rv = cache->CreateEntry(kCrashEntryName, &entry, &cb);
+ if (cb.GetResult(rv) != net::OK)
return GENERIC;
entry->Close();
if (action >= disk_cache::REMOVE_TAIL_1) {
- if (!cache->CreateEntry("some other key", &entry))
+ rv = cache->CreateEntry("some other key", &entry, &cb);
+ if (cb.GetResult(rv) != net::OK)
return GENERIC;
entry->Close();
}
- if (!cache->OpenEntry(kCrashEntryName, &entry))
+ rv = cache->OpenEntry(kCrashEntryName, &entry, &cb);
+ if (cb.GetResult(rv) != net::OK)
return GENERIC;
g_rankings_crash = action;
@@ -179,26 +194,33 @@ int SimpleRemove(const FilePath& path, RankCrashes action) {
return NOT_REACHED;
}
-int HeadRemove(const FilePath& path, RankCrashes action) {
+int HeadRemove(const FilePath& path, RankCrashes action,
+ base::Thread* cache_thread) {
DCHECK(action >= disk_cache::REMOVE_HEAD_1);
DCHECK(action <= disk_cache::REMOVE_HEAD_4);
- disk_cache::Backend* cache = disk_cache::CreateCacheBackend(path, false, 0,
- net::DISK_CACHE);
- if (!cache || cache->GetEntryCount())
+ TestCompletionCallback cb;
+ disk_cache::Backend* cache;
+ int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, path, 0, false,
+ cache_thread->message_loop_proxy(),
+ &cache, &cb);
+ if (cb.GetResult(rv) != net::OK || cache->GetEntryCount())
return GENERIC;
disk_cache::Entry* entry;
- if (!cache->CreateEntry("some other key", &entry))
+ rv = cache->CreateEntry("some other key", &entry, &cb);
+ if (cb.GetResult(rv) != net::OK)
return GENERIC;
entry->Close();
- if (!cache->CreateEntry(kCrashEntryName, &entry))
+ rv = cache->CreateEntry(kCrashEntryName, &entry, &cb);
+ if (cb.GetResult(rv) != net::OK)
return GENERIC;
entry->Close();
- if (!cache->OpenEntry(kCrashEntryName, &entry))
+ rv = cache->OpenEntry(kCrashEntryName, &entry, &cb);
+ if (cb.GetResult(rv) != net::OK)
return GENERIC;
g_rankings_crash = action;
@@ -209,27 +231,34 @@ int HeadRemove(const FilePath& path, RankCrashes action) {
}
// Generates the files for insertion and removals on heavy loaded caches.
-int LoadOperations(const FilePath& path, RankCrashes action) {
+int LoadOperations(const FilePath& path, RankCrashes action,
+ base::Thread* cache_thread) {
DCHECK(action >= disk_cache::INSERT_LOAD_1);
- // Work with a tiny index table (16 entries)
- disk_cache::BackendImpl* cache =
- new disk_cache::BackendImpl(path, 0xf);
- if (!cache || !cache->SetMaxSize(0x100000) || !cache->Init() ||
- cache->GetEntryCount())
+ // Work with a tiny index table (16 entries).
+ disk_cache::BackendImpl* cache = new disk_cache::BackendImpl(
+ path, 0xf, cache_thread->message_loop_proxy());
+ if (!cache || !cache->SetMaxSize(0x100000))
+ return GENERIC;
+
+ if (!cache->Init() || cache->GetEntryCount())
return GENERIC;
int seed = static_cast<int>(Time::Now().ToInternalValue());
srand(seed);
+ TestCompletionCallback cb;
+ int rv;
disk_cache::Entry* entry;
for (int i = 0; i < 100; i++) {
std::string key = GenerateKey(true);
- if (!cache->CreateEntry(key, &entry))
+ rv = cache->CreateEntry(key, &entry, &cb);
+ if (cb.GetResult(rv) != net::OK)
return GENERIC;
entry->Close();
if (50 == i && action >= disk_cache::REMOVE_LOAD_1) {
- if (!cache->CreateEntry(kCrashEntryName, &entry))
+ rv = cache->CreateEntry(kCrashEntryName, &entry, &cb);
+ if (cb.GetResult(rv) != net::OK)
return GENERIC;
entry->Close();
}
@@ -238,11 +267,13 @@ int LoadOperations(const FilePath& path, RankCrashes action) {
if (action <= disk_cache::INSERT_LOAD_2) {
g_rankings_crash = action;
- if (!cache->CreateEntry(kCrashEntryName, &entry))
+ rv = cache->CreateEntry(kCrashEntryName, &entry, &cb);
+ if (cb.GetResult(rv) != net::OK)
return GENERIC;
}
- if (!cache->OpenEntry(kCrashEntryName, &entry))
+ rv = cache->OpenEntry(kCrashEntryName, &entry, &cb);
+ if (cb.GetResult(rv) != net::OK)
return GENERIC;
g_rankings_crash = action;
@@ -255,7 +286,7 @@ int LoadOperations(const FilePath& path, RankCrashes action) {
// Main function on the child process.
int SlaveCode(const FilePath& path, RankCrashes action) {
- MessageLoop message_loop;
+ MessageLoopForIO message_loop;
FilePath full_path;
if (!CreateTargetFolder(path, action, &full_path)) {
@@ -263,23 +294,28 @@ int SlaveCode(const FilePath& path, RankCrashes action) {
return CRASH_OVERWRITE;
}
+ base::Thread cache_thread("CacheThread");
+ if (!cache_thread.StartWithOptions(
+ base::Thread::Options(MessageLoop::TYPE_IO, 0)))
+ return GENERIC;
+
if (action <= disk_cache::INSERT_ONE_3)
- return SimpleInsert(full_path, action);
+ return SimpleInsert(full_path, action, &cache_thread);
if (action <= disk_cache::INSERT_LOAD_2)
- return LoadOperations(full_path, action);
+ return LoadOperations(full_path, action, &cache_thread);
if (action <= disk_cache::REMOVE_ONE_4)
- return SimpleRemove(full_path, action);
+ return SimpleRemove(full_path, action, &cache_thread);
if (action <= disk_cache::REMOVE_HEAD_4)
- return HeadRemove(full_path, action);
+ return HeadRemove(full_path, action, &cache_thread);
if (action <= disk_cache::REMOVE_TAIL_3)
- return SimpleRemove(full_path, action);
+ return SimpleRemove(full_path, action, &cache_thread);
if (action <= disk_cache::REMOVE_LOAD_3)
- return LoadOperations(full_path, action);
+ return LoadOperations(full_path, action, &cache_thread);
return NOT_REACHED;
}
diff --git a/net/tools/dump_cache/cache_dumper.cc b/net/tools/dump_cache/cache_dumper.cc
index 74f1482..71720af 100644
--- a/net/tools/dump_cache/cache_dumper.cc
+++ b/net/tools/dump_cache/cache_dumper.cc
@@ -16,10 +16,10 @@ bool CacheDumper::CreateEntry(const std::string& key,
return cache_->CreateEntry(key, entry);
}
-bool CacheDumper::WriteEntry(disk_cache::Entry* entry, int index, int offset,
- net::IOBuffer* buf, int buf_len) {
- int written = entry->WriteData(index, offset, buf, buf_len, NULL, false);
- return written == buf_len;
+int CacheDumper::WriteEntry(disk_cache::Entry* entry, int index, int offset,
+ net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* callback) {
+ return entry->WriteData(index, offset, buf, buf_len, callback, false);
}
void CacheDumper::CloseEntry(disk_cache::Entry* entry, base::Time last_used,
@@ -48,7 +48,7 @@ bool SafeCreateDirectory(const std::wstring& path) {
pos = 4;
// Create the subdirectories individually
- while((pos = path.find(backslash, pos)) != std::wstring::npos) {
+ while ((pos = path.find(backslash, pos)) != std::wstring::npos) {
std::wstring subdir = path.substr(0, pos);
CreateDirectoryW(subdir.c_str(), NULL);
// we keep going even if directory creation failed.
@@ -141,10 +141,11 @@ void GetNormalizedHeaders(const net::HttpResponseInfo& info,
output->append("\r\n");
}
-bool DiskDumper::WriteEntry(disk_cache::Entry* entry, int index, int offset,
- net::IOBuffer* buf, int buf_len) {
+int DiskDumper::WriteEntry(disk_cache::Entry* entry, int index, int offset,
+ net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* callback) {
if (!entry_)
- return false;
+ return 0;
std::string headers;
const char *data;
@@ -154,11 +155,11 @@ bool DiskDumper::WriteEntry(disk_cache::Entry* entry, int index, int offset,
bool truncated;
if (!net::HttpCache::ParseResponseInfo(buf->data(), buf_len,
&response_info, &truncated))
- return false;
+ return 0;
// Skip this entry if it was truncated (results in an empty file).
if (truncated)
- return true;
+ return buf_len;
// Remove the size headers.
response_info.headers->RemoveHeader("transfer-encoding");
@@ -188,11 +189,12 @@ bool DiskDumper::WriteEntry(disk_cache::Entry* entry, int index, int offset,
}
#ifdef WIN32_LARGE_FILENAME_SUPPORT
DWORD bytes;
- DWORD rv = WriteFile(entry_, data, len, &bytes, 0);
- return rv == TRUE && bytes == static_cast<DWORD>(len);
+ if (!WriteFile(entry_, data, len, &bytes, 0))
+ return 0;
+
+ return bytes;
#else
- int bytes = fwrite(data, 1, len, entry_);
- return bytes == len;
+ return fwrite(data, 1, len, entry_);
#endif
}
diff --git a/net/tools/dump_cache/cache_dumper.h b/net/tools/dump_cache/cache_dumper.h
index 916b1b4..1af8573 100644
--- a/net/tools/dump_cache/cache_dumper.h
+++ b/net/tools/dump_cache/cache_dumper.h
@@ -1,9 +1,9 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef NET_TOOLS_DUMP_CACHE_DUMPER_H_
-#define NET_TOOLS_DUMP_CACHE_DUMPER_H_
+#ifndef NET_TOOLS_DUMP_CACHE_CACHE_DUMPER_H_
+#define NET_TOOLS_DUMP_CACHE_CACHE_DUMPER_H_
#include <string>
#include "base/file_path.h"
@@ -22,6 +22,8 @@
// An abstract class for writing cache dump data.
class CacheDumpWriter {
public:
+ virtual ~CacheDumpWriter() {}
+
// Creates an entry to be written.
// On success, populates the |entry|.
// Returns true on success, false otherwise.
@@ -30,8 +32,9 @@ class CacheDumpWriter {
// Write to the current entry.
// Returns true on success, false otherwise.
- virtual bool WriteEntry(disk_cache::Entry* entry, int stream, int offset,
- net::IOBuffer* buf, int buf_len) = 0;
+ virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset,
+ net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* callback) = 0;
// Close the current entry.
virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used,
@@ -41,27 +44,29 @@ class CacheDumpWriter {
// Writes data to a cache.
class CacheDumper : public CacheDumpWriter {
public:
- CacheDumper(disk_cache::BackendImpl* cache) : cache_(cache) {};
+ explicit CacheDumper(disk_cache::Backend* cache) : cache_(cache) {}
virtual bool CreateEntry(const std::string& key, disk_cache::Entry** entry);
- virtual bool WriteEntry(disk_cache::Entry* entry, int stream, int offset,
- net::IOBuffer* buf, int buf_len);
+ virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset,
+ net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* callback);
virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used,
base::Time last_modified);
private:
- disk_cache::BackendImpl* cache_;
+ disk_cache::Backend* cache_;
};
// Writes data to a disk.
class DiskDumper : public CacheDumpWriter {
public:
- DiskDumper(const std::wstring& path) : path_(path), entry_(NULL) {
+ explicit DiskDumper(const std::wstring& path) : path_(path), entry_(NULL) {
file_util::CreateDirectory(FilePath(path));
- };
+ }
virtual bool CreateEntry(const std::string& key, disk_cache::Entry** entry);
- virtual bool WriteEntry(disk_cache::Entry* entry, int stream, int offset,
- net::IOBuffer* buf, int buf_len);
+ virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset,
+ net::IOBuffer* buf, int buf_len,
+ net::CompletionCallback* callback);
virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used,
base::Time last_modified);
@@ -79,4 +84,4 @@ class DiskDumper : public CacheDumpWriter {
#endif
};
-#endif // NET_TOOLS_DUMP_CACHE_DUMPER_H_
+#endif // NET_TOOLS_DUMP_CACHE_CACHE_DUMPER_H_
diff --git a/net/tools/dump_cache/upgrade.cc b/net/tools/dump_cache/upgrade.cc
index 71031dc..4f565fe 100644
--- a/net/tools/dump_cache/upgrade.cc
+++ b/net/tools/dump_cache/upgrade.cc
@@ -7,8 +7,10 @@
#include "base/message_loop.h"
#include "base/scoped_ptr.h"
#include "base/string_util.h"
+#include "base/thread.h"
#include "googleurl/src/gurl.h"
#include "net/base/io_buffer.h"
+#include "net/base/test_completion_callback.h"
#include "net/disk_cache/backend_impl.h"
#include "net/disk_cache/entry_impl.h"
#include "net/http/http_cache.h"
@@ -109,7 +111,7 @@ enum {
class BaseSM : public MessageLoopForIO::IOHandler {
public:
- BaseSM(HANDLE channel);
+ explicit BaseSM(HANDLE channel);
virtual ~BaseSM();
protected:
@@ -128,11 +130,14 @@ class BaseSM : public MessageLoopForIO::IOHandler {
scoped_array<char> out_buffer_;
IoBuffer* input_;
IoBuffer* output_;
+ base::Thread cache_thread_;
+
DISALLOW_COPY_AND_ASSIGN(BaseSM);
};
BaseSM::BaseSM(HANDLE channel)
- : entry_(NULL), channel_(channel), state_(0), pending_count_(0) {
+ : entry_(NULL), channel_(channel), state_(0), pending_count_(0),
+ cache_thread_("cache") {
in_buffer_.reset(new char[kChannelSize]);
out_buffer_.reset(new char[kChannelSize]);
input_ = reinterpret_cast<IoBuffer*>(in_buffer_.get());
@@ -143,6 +148,8 @@ BaseSM::BaseSM(HANDLE channel)
in_context_.handler = this;
out_context_.handler = this;
MessageLoopForIO::current()->RegisterIOHandler(channel_, this);
+ CHECK(cache_thread_.StartWithOptions(
+ base::Thread::Options(MessageLoop::TYPE_IO, 0)));
}
BaseSM::~BaseSM() {
@@ -200,8 +207,10 @@ bool BaseSM::IsPending() {
class MasterSM : public BaseSM {
public:
- MasterSM(const std::wstring& path, HANDLE channel, bool dump_to_disk)
- : BaseSM(channel), path_(path), dump_to_disk_(dump_to_disk) {
+ MasterSM(const std::wstring& path, HANDLE channel, bool dump_to_disk)
+ : BaseSM(channel), path_(path), dump_to_disk_(dump_to_disk),
+ ALLOW_THIS_IN_INITIALIZER_LIST(
+ write_callback_(this, &MasterSM::DoReadDataComplete)) {
}
virtual ~MasterSM() {
delete writer_;
@@ -233,6 +242,7 @@ class MasterSM : public BaseSM {
void CloseEntry();
void SendReadData();
void DoReadData(int bytes_read);
+ void DoReadDataComplete(int ret);
void SendQuit();
void DoEnd();
void Fail();
@@ -244,10 +254,12 @@ class MasterSM : public BaseSM {
int bytes_remaining_;
int offset_;
int copied_entries_;
- scoped_ptr<disk_cache::BackendImpl> cache_;
+ int read_size_;
+ scoped_ptr<disk_cache::Backend> cache_;
CacheDumpWriter* writer_;
const std::wstring& path_;
bool dump_to_disk_;
+ net::CompletionCallbackImpl<MasterSM> write_callback_;
};
void MasterSM::OnIOCompleted(MessageLoopForIO::IOContext* context,
@@ -302,11 +314,18 @@ bool MasterSM::DoInit() {
if (dump_to_disk_) {
writer_ = new DiskDumper(path_);
} else {
- cache_.reset(new disk_cache::BackendImpl(FilePath::FromWStringHack(path_)));
- if (!cache_->Init()) {
+ disk_cache::Backend* cache;
+ TestCompletionCallback cb;
+ int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE,
+ FilePath::FromWStringHack(path_), 0,
+ false,
+ cache_thread_.message_loop_proxy(),
+ &cache, &cb);
+ if (cb.GetResult(rv) != net::OK) {
printf("Unable to initialize new files\n");
return false;
}
+ cache_.reset(cache);
writer_ = new CacheDumper(cache_.get());
}
if (!writer_)
@@ -474,7 +493,15 @@ void MasterSM::DoReadData(int bytes_read) {
scoped_refptr<net::WrappedIOBuffer> buf =
new net::WrappedIOBuffer(input_->buffer);
- if (!writer_->WriteEntry(entry_, stream_, offset_, buf, read_size))
+ int rv = writer_->WriteEntry(entry_, stream_, offset_, buf, read_size,
+ &write_callback_);
+ if (rv == net::ERR_IO_PENDING) {
+ // We'll continue in DoReadDataComplete.
+ read_size_ = read_size;
+ return;
+ }
+
+ if (rv <= 0)
return Fail();
offset_ += read_size;
@@ -483,6 +510,16 @@ void MasterSM::DoReadData(int bytes_read) {
SendReadData();
}
+void MasterSM::DoReadDataComplete(int ret) {
+ if (ret != read_size_)
+ return Fail();
+
+ offset_ += ret;
+ bytes_remaining_ -= ret;
+ // Read some more.
+ SendReadData();
+}
+
void MasterSM::SendQuit() {
DEBUGMSG("Master SendQuit\n");
state_ = MASTER_END;
@@ -508,15 +545,7 @@ void MasterSM::Fail() {
class SlaveSM : public BaseSM {
public:
- SlaveSM(const std::wstring& path, HANDLE channel)
- : BaseSM(channel), iterator_(NULL) {
- cache_.reset(new disk_cache::BackendImpl(FilePath::FromWStringHack(path)));
- if (!cache_->Init()) {
- printf("Unable to open cache files\n");
- return;
- }
- cache_->SetUpgradeMode();
- }
+ SlaveSM(const std::wstring& path, HANDLE channel);
virtual ~SlaveSM();
bool DoInit();
@@ -538,14 +567,36 @@ class SlaveSM : public BaseSM {
void DoGetUseTimes();
void DoGetDataSize();
void DoReadData();
+ void DoReadDataComplete(int ret);
void DoEnd();
void Fail();
void* iterator_;
+ Message msg_; // Only used for DoReadDataComplete.
+ net::CompletionCallbackImpl<SlaveSM> read_callback_;
scoped_ptr<disk_cache::BackendImpl> cache_;
};
+SlaveSM::SlaveSM(const std::wstring& path, HANDLE channel)
+ : BaseSM(channel), iterator_(NULL),
+ ALLOW_THIS_IN_INITIALIZER_LIST(
+ read_callback_(this, &SlaveSM::DoReadDataComplete)) {
+ disk_cache::Backend* cache;
+ TestCompletionCallback cb;
+ int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE,
+ FilePath::FromWStringHack(path), 0,
+ false,
+ cache_thread_.message_loop_proxy(),
+ &cache, &cb);
+ if (cb.GetResult(rv) != net::OK) {
+ printf("Unable to open cache files\n");
+ return;
+ }
+ cache_.reset(reinterpret_cast<disk_cache::BackendImpl*>(cache));
+ cache_->SetUpgradeMode();
+}
+
SlaveSM::~SlaveSM() {
if (iterator_)
cache_->EndEnumeration(&iterator_);
@@ -753,7 +804,13 @@ void SlaveSM::DoReadData() {
} else {
scoped_refptr<net::WrappedIOBuffer> buf =
new net::WrappedIOBuffer(output_->buffer);
- int ret = entry_->ReadData(stream, input_->msg.arg3, buf, size, NULL);
+ int ret = entry_->ReadData(stream, input_->msg.arg3, buf, size,
+ &read_callback_);
+ if (ret == net::ERR_IO_PENDING) {
+ // Save the message so we can continue were we left.
+ msg_ = msg;
+ return;
+ }
msg.buffer_bytes = (ret < 0) ? 0 : ret;
msg.result = RESULT_OK;
@@ -761,6 +818,14 @@ void SlaveSM::DoReadData() {
SendMsg(msg);
}
+void SlaveSM::DoReadDataComplete(int ret) {
+ DEBUGMSG("\t\t\tSlave DoReadDataComplete\n");
+ DCHECK_EQ(READ_DATA, msg_.command);
+ msg_.buffer_bytes = (ret < 0) ? 0 : ret;
+ msg_.result = RESULT_OK;
+ SendMsg(msg_);
+}
+
void SlaveSM::DoEnd() {
DEBUGMSG("\t\t\tSlave DoEnd\n");
MessageLoop::current()->PostTask(FROM_HERE, new MessageLoop::QuitTask());