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

Unified Diff: net/tools/dump_cache/cache_dumper.cc

Issue 11299239: Adding a simple class for dumping the contents of a cache. Use this new class in dump_cache. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 1 month 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/tools/dump_cache/cache_dumper.h ('k') | net/tools/dump_cache/dump_cache.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/tools/dump_cache/cache_dumper.cc
diff --git a/net/tools/dump_cache/cache_dumper.cc b/net/tools/dump_cache/cache_dumper.cc
index dbe827331ee6cb24d754213390871f74718f54af..7f2292bdd7a88f82376a31841dd7813f7b7b4342 100644
--- a/net/tools/dump_cache/cache_dumper.cc
+++ b/net/tools/dump_cache/cache_dumper.cc
@@ -13,6 +13,10 @@
#include "net/http/http_response_info.h"
#include "net/tools/dump_cache/url_to_filename_encoder.h"
+CacheDumper::CacheDumper(disk_cache::Backend* cache)
+ : cache_(cache) {
+}
+
int CacheDumper::CreateEntry(const std::string& key,
disk_cache::Entry** entry,
const net::CompletionCallback& callback) {
@@ -52,7 +56,7 @@ bool SafeCreateDirectory(const FilePath& path) {
// Create the subdirectories individually
while ((pos = path.value().find(backslash, pos)) != std::wstring::npos) {
- std::wstring subdir = path.value().substr(0, pos);
+ FilePath::StringType subdir = path.value().substr(0, pos);
CreateDirectoryW(subdir.c_str(), NULL);
// we keep going even if directory creation failed.
pos++;
@@ -64,16 +68,21 @@ bool SafeCreateDirectory(const FilePath& path) {
#endif
}
+DiskDumper::DiskDumper(const FilePath& path)
+ : path_(path), entry_(NULL) {
+ file_util::CreateDirectory(path);
+}
+
int DiskDumper::CreateEntry(const std::string& key,
disk_cache::Entry** entry,
const net::CompletionCallback& callback) {
// The URL may not start with a valid protocol; search for it.
int urlpos = key.find("http");
std::string url = urlpos > 0 ? key.substr(urlpos) : key;
- std::string base_path = WideToASCII(path_.value());
+ std::string base_path = path_.MaybeAsASCII();
std::string new_path =
net::UrlToFilenameEncoder::Encode(url, base_path, false);
- entry_path_ = FilePath(ASCIIToWide(new_path));
+ entry_path_ = FilePath::FromUTF8Unsafe(new_path);
#ifdef WIN32_LARGE_FILENAME_SUPPORT
// In order for long filenames to work, we'll need to prepend
@@ -90,7 +99,7 @@ int DiskDumper::CreateEntry(const std::string& key,
SafeCreateDirectory(entry_path_.DirName());
- std::wstring file = entry_path_.value();
+ FilePath::StringType file = entry_path_.value();
#ifdef WIN32_LARGE_FILENAME_SUPPORT
entry_ = CreateFileW(file.c_str(), GENERIC_WRITE|GENERIC_READ, 0, 0,
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
@@ -185,10 +194,13 @@ int DiskDumper::WriteEntry(disk_cache::Entry* entry, int index, int offset,
data = headers.c_str();
len = headers.size();
- } else if (index == 1) { // Stream 1 is the data.
+ } else if (index == 1) {
data = buf->data();
len = buf_len;
+ } else {
+ return 0;
}
+
#ifdef WIN32_LARGE_FILENAME_SUPPORT
DWORD bytes;
if (!WriteFile(entry_, data, len, &bytes, 0))
« no previous file with comments | « net/tools/dump_cache/cache_dumper.h ('k') | net/tools/dump_cache/dump_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698