summaryrefslogtreecommitdiffstats
path: root/net/tools/crash_cache
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/crash_cache
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/crash_cache')
-rw-r--r--net/tools/crash_cache/crash_cache.cc114
1 files changed, 75 insertions, 39 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;
}