Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1664)

Unified Diff: net/tools/crash_cache/crash_cache.cc

Issue 2739007: Disk cache: Update the disk cache tools and tests to use... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/disk_cache/stress_cache.cc ('k') | net/tools/dump_cache/cache_dumper.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/tools/crash_cache/crash_cache.cc
===================================================================
--- net/tools/crash_cache/crash_cache.cc (revision 49603)
+++ net/tools/crash_cache/crash_cache.cc (working copy)
@@ -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 @@
}
// 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 @@
}
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 @@
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 @@
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 @@
}
// 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 @@
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 @@
// 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 @@
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;
}
« no previous file with comments | « net/disk_cache/stress_cache.cc ('k') | net/tools/dump_cache/cache_dumper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698