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; |
} |