summaryrefslogtreecommitdiffstats
path: root/net/tools
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/tools
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/tools')
-rw-r--r--net/tools/crash_cache/crash_cache.cc30
-rw-r--r--net/tools/dump_cache/upgrade.cc45
2 files changed, 58 insertions, 17 deletions
diff --git a/net/tools/crash_cache/crash_cache.cc b/net/tools/crash_cache/crash_cache.cc
index a26c873..1d11013 100644
--- a/net/tools/crash_cache/crash_cache.cc
+++ b/net/tools/crash_cache/crash_cache.cc
@@ -118,6 +118,14 @@ bool CreateTargetFolder(const FilePath& path, RankCrashes action,
return file_util::CreateDirectory(*full_path);
}
+// Makes sure that any pending task is processed.
+void FlushQueue(disk_cache::Backend* cache) {
+ TestCompletionCallback cb;
+ int rv =
+ reinterpret_cast<disk_cache::BackendImpl*>(cache)->FlushQueueForTest(&cb);
+ cb.GetResult(rv); // Ignore the result;
+}
+
// Generates the files for an empty and one item cache.
int SimpleInsert(const FilePath& path, RankCrashes action,
base::Thread* cache_thread) {
@@ -142,6 +150,7 @@ int SimpleInsert(const FilePath& path, RankCrashes action,
return GENERIC;
entry->Close();
+ FlushQueue(cache);
DCHECK(action <= disk_cache::INSERT_ONE_3);
g_rankings_crash = action;
@@ -162,7 +171,8 @@ int SimpleRemove(const FilePath& path, RankCrashes action,
TestCompletionCallback cb;
disk_cache::Backend* cache;
- int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, path, 0, false,
+ // Use a simple LRU for eviction.
+ int rv = disk_cache::CreateCacheBackend(net::MEDIA_CACHE, path, 0, false,
cache_thread->message_loop_proxy(),
&cache, &cb);
if (cb.GetResult(rv) != net::OK || cache->GetEntryCount())
@@ -174,6 +184,7 @@ int SimpleRemove(const FilePath& path, RankCrashes action,
return GENERIC;
entry->Close();
+ FlushQueue(cache);
if (action >= disk_cache::REMOVE_TAIL_1) {
rv = cache->CreateEntry("some other key", &entry, &cb);
@@ -181,6 +192,7 @@ int SimpleRemove(const FilePath& path, RankCrashes action,
return GENERIC;
entry->Close();
+ FlushQueue(cache);
}
rv = cache->OpenEntry(kCrashEntryName, &entry, &cb);
@@ -190,6 +202,7 @@ int SimpleRemove(const FilePath& path, RankCrashes action,
g_rankings_crash = action;
entry->Doom();
entry->Close();
+ FlushQueue(cache);
return NOT_REACHED;
}
@@ -201,7 +214,8 @@ int HeadRemove(const FilePath& path, RankCrashes action,
TestCompletionCallback cb;
disk_cache::Backend* cache;
- int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE, path, 0, false,
+ // Use a simple LRU for eviction.
+ int rv = disk_cache::CreateCacheBackend(net::MEDIA_CACHE, path, 0, false,
cache_thread->message_loop_proxy(),
&cache, &cb);
if (cb.GetResult(rv) != net::OK || cache->GetEntryCount())
@@ -213,11 +227,13 @@ int HeadRemove(const FilePath& path, RankCrashes action,
return GENERIC;
entry->Close();
+ FlushQueue(cache);
rv = cache->CreateEntry(kCrashEntryName, &entry, &cb);
if (cb.GetResult(rv) != net::OK)
return GENERIC;
entry->Close();
+ FlushQueue(cache);
rv = cache->OpenEntry(kCrashEntryName, &entry, &cb);
if (cb.GetResult(rv) != net::OK)
@@ -226,6 +242,7 @@ int HeadRemove(const FilePath& path, RankCrashes action,
g_rankings_crash = action;
entry->Doom();
entry->Close();
+ FlushQueue(cache);
return NOT_REACHED;
}
@@ -241,14 +258,14 @@ int LoadOperations(const FilePath& path, RankCrashes action,
if (!cache || !cache->SetMaxSize(0x100000))
return GENERIC;
- if (!cache->Init() || cache->GetEntryCount())
+ TestCompletionCallback cb;
+ int rv = cache->Init(&cb);
+ if (cb.GetResult(rv) != net::OK || 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);
@@ -256,11 +273,13 @@ int LoadOperations(const FilePath& path, RankCrashes action,
if (cb.GetResult(rv) != net::OK)
return GENERIC;
entry->Close();
+ FlushQueue(cache);
if (50 == i && action >= disk_cache::REMOVE_LOAD_1) {
rv = cache->CreateEntry(kCrashEntryName, &entry, &cb);
if (cb.GetResult(rv) != net::OK)
return GENERIC;
entry->Close();
+ FlushQueue(cache);
}
}
@@ -280,6 +299,7 @@ int LoadOperations(const FilePath& path, RankCrashes action,
entry->Doom();
entry->Close();
+ FlushQueue(cache);
return NOT_REACHED;
}
diff --git a/net/tools/dump_cache/upgrade.cc b/net/tools/dump_cache/upgrade.cc
index 5a3cd67..60099b2 100644
--- a/net/tools/dump_cache/upgrade.cc
+++ b/net/tools/dump_cache/upgrade.cc
@@ -104,7 +104,8 @@ enum {
RESULT_OK = 0,
RESULT_UNKNOWN_COMMAND,
RESULT_INVALID_PARAMETER,
- RESULT_NAME_OVERFLOW
+ RESULT_NAME_OVERFLOW,
+ RESULT_PENDING // This error code is NOT expected by the master process.
};
// -----------------------------------------------------------------------
@@ -575,6 +576,7 @@ class SlaveSM : public BaseSM {
void DoGetNextEntry();
void DoGetPrevEntry();
int32 GetEntryFromList();
+ void DoGetEntryComplete(int result);
void DoCloseEntry();
void DoGetKey();
void DoGetUseTimes();
@@ -585,16 +587,19 @@ class SlaveSM : public BaseSM {
void Fail();
void* iterator_;
- Message msg_; // Only used for DoReadDataComplete.
+ Message msg_; // Used for DoReadDataComplete and DoGetEntryComplete.
net::CompletionCallbackImpl<SlaveSM> read_callback_;
+ net::CompletionCallbackImpl<SlaveSM> next_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)) {
+ read_callback_(this, &SlaveSM::DoReadDataComplete)),
+ ALLOW_THIS_IN_INITIALIZER_LIST(
+ next_callback_(this, &SlaveSM::DoGetEntryComplete)) {
disk_cache::Backend* cache;
TestCompletionCallback cb;
int rv = disk_cache::CreateCacheBackend(net::DISK_CACHE,
@@ -672,6 +677,9 @@ bool SlaveSM::DoInit() {
DEBUGMSG("\t\t\tSlave DoInit\n");
DCHECK(state_ == SLAVE_INITIAL);
state_ = SLAVE_WAITING;
+ if (!cache_.get())
+ return false;
+
return ReceiveMsg();
}
@@ -700,6 +708,11 @@ void SlaveSM::DoGetPrevEntry() {
msg.result = RESULT_UNKNOWN_COMMAND;
} else {
msg.result = GetEntryFromList();
+ if (msg.result == RESULT_PENDING) {
+ // We are not done yet.
+ msg_ = msg;
+ return;
+ }
msg.long_arg1 = reinterpret_cast<int64>(entry_);
}
SendMsg(msg);
@@ -715,23 +728,31 @@ int32 SlaveSM::GetEntryFromList() {
if (entry_)
entry_->Close();
- bool ret;
+ int rv;
if (input_->msg.command == GET_NEXT_ENTRY) {
- ret = cache_->OpenNextEntry(&iterator_,
- reinterpret_cast<disk_cache::Entry**>(&entry_));
+ rv = cache_->OpenNextEntry(&iterator_,
+ reinterpret_cast<disk_cache::Entry**>(&entry_),
+ &next_callback_);
} else {
DCHECK(input_->msg.command == GET_PREV_ENTRY);
- ret = cache_->OpenPrevEntry(&iterator_,
- reinterpret_cast<disk_cache::Entry**>(&entry_));
+ rv = cache_->OpenPrevEntry(&iterator_,
+ reinterpret_cast<disk_cache::Entry**>(&entry_),
+ &next_callback_);
}
+ DCHECK_EQ(net::ERR_IO_PENDING, rv);
+ return RESULT_PENDING;
+}
- if (!ret)
+void SlaveSM::DoGetEntryComplete(int result) {
+ DEBUGMSG("\t\t\tSlave DoGetEntryComplete\n");
+ if (result != net::OK) {
entry_ = NULL;
-
- if (!entry_)
DEBUGMSG("\t\t\tSlave end of list\n");
+ }
- return RESULT_OK;
+ msg_.result = RESULT_OK;
+ msg_.long_arg1 = reinterpret_cast<int64>(entry_);
+ SendMsg(msg_);
}
void SlaveSM::DoCloseEntry() {