summaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorrvargas <rvargas@chromium.org>2015-08-14 11:09:04 -0700
committerCommit bot <commit-bot@chromium.org>2015-08-14 18:09:45 +0000
commit145310f962c9efa62faa903d64d977203226cca4 (patch)
treee487c9999540d4dbfb894747b72e0362e7b84c9e /net
parent88916e308e286bfc87388ac642ef609a98003c6f (diff)
downloadchromium_src-145310f962c9efa62faa903d64d977203226cca4.zip
chromium_src-145310f962c9efa62faa903d64d977203226cca4.tar.gz
chromium_src-145310f962c9efa62faa903d64d977203226cca4.tar.bz2
net: Remove dump-to-files from dump_cache.
There's no need for this code. See the bug for more details. BUG=520712 Review URL: https://codereview.chromium.org/1292443003 Cr-Commit-Position: refs/heads/master@{#343433}
Diffstat (limited to 'net')
-rw-r--r--net/BUILD.gn18
-rw-r--r--net/net.gyp18
-rw-r--r--net/net.gypi6
-rw-r--r--net/tools/dump_cache/cache_dumper.cc222
-rw-r--r--net/tools/dump_cache/cache_dumper.h99
-rw-r--r--net/tools/dump_cache/dump_cache.cc22
-rw-r--r--net/tools/dump_cache/simple_cache_dumper.cc264
-rw-r--r--net/tools/dump_cache/simple_cache_dumper.h90
-rw-r--r--net/tools/flip_server/http_interface.cc2
-rw-r--r--net/tools/flip_server/mem_cache.cc4
-rw-r--r--net/tools/flip_server/spdy_interface.cc2
-rw-r--r--net/tools/flip_server/spdy_util.cc2
-rw-r--r--net/tools/flip_server/url_to_filename_encoder.cc (renamed from net/tools/dump_cache/url_to_filename_encoder.cc)15
-rw-r--r--net/tools/flip_server/url_to_filename_encoder.h (renamed from net/tools/dump_cache/url_to_filename_encoder.h)25
-rw-r--r--net/tools/flip_server/url_to_filename_encoder_unittest.cc (renamed from net/tools/dump_cache/url_to_filename_encoder_unittest.cc)133
-rw-r--r--net/tools/flip_server/url_utilities.cc (renamed from net/tools/dump_cache/url_utilities.cc)10
-rw-r--r--net/tools/flip_server/url_utilities.h (renamed from net/tools/dump_cache/url_utilities.h)6
-rw-r--r--net/tools/flip_server/url_utilities_unittest.cc (renamed from net/tools/dump_cache/url_utilities_unittest.cc)48
18 files changed, 131 insertions, 855 deletions
diff --git a/net/BUILD.gn b/net/BUILD.gn
index 823d869..e1e26e6 100644
--- a/net/BUILD.gn
+++ b/net/BUILD.gn
@@ -578,17 +578,9 @@ static_library("http_server") {
executable("dump_cache") {
testonly = true
sources = [
- "tools/dump_cache/cache_dumper.cc",
- "tools/dump_cache/cache_dumper.h",
"tools/dump_cache/dump_cache.cc",
"tools/dump_cache/dump_files.cc",
"tools/dump_cache/dump_files.h",
- "tools/dump_cache/simple_cache_dumper.cc",
- "tools/dump_cache/simple_cache_dumper.h",
- "tools/dump_cache/url_to_filename_encoder.cc",
- "tools/dump_cache/url_to_filename_encoder.h",
- "tools/dump_cache/url_utilities.cc",
- "tools/dump_cache/url_utilities.h",
]
# TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
@@ -1078,10 +1070,6 @@ if (is_linux) {
static_library("flip_in_mem_edsm_server_base") {
testonly = true
sources = [
- "tools/dump_cache/url_to_filename_encoder.cc",
- "tools/dump_cache/url_to_filename_encoder.h",
- "tools/dump_cache/url_utilities.cc",
- "tools/dump_cache/url_utilities.h",
"tools/flip_server/acceptor_thread.cc",
"tools/flip_server/acceptor_thread.h",
"tools/flip_server/constants.h",
@@ -1109,6 +1097,10 @@ if (is_linux) {
"tools/flip_server/spdy_util.h",
"tools/flip_server/streamer_interface.cc",
"tools/flip_server/streamer_interface.h",
+ "tools/flip_server/url_to_filename_encoder.cc",
+ "tools/flip_server/url_to_filename_encoder.h",
+ "tools/flip_server/url_utilities.cc",
+ "tools/flip_server/url_utilities.h",
]
deps = [
":balsa",
@@ -1128,6 +1120,8 @@ if (is_linux) {
"tools/flip_server/mem_cache_test.cc",
"tools/flip_server/run_all_tests.cc",
"tools/flip_server/spdy_interface_test.cc",
+ "tools/flip_server/url_to_filename_encoder_unittest.cc",
+ "tools/flip_server/url_utilities_unittest.cc",
]
deps = [
":balsa",
diff --git a/net/net.gyp b/net/net.gyp
index 7bc95ba3..0cef583 100644
--- a/net/net.gyp
+++ b/net/net.gyp
@@ -802,17 +802,9 @@
'net_test_support',
],
'sources': [
- 'tools/dump_cache/cache_dumper.cc',
- 'tools/dump_cache/cache_dumper.h',
'tools/dump_cache/dump_cache.cc',
'tools/dump_cache/dump_files.cc',
'tools/dump_cache/dump_files.h',
- 'tools/dump_cache/simple_cache_dumper.cc',
- 'tools/dump_cache/simple_cache_dumper.h',
- 'tools/dump_cache/url_to_filename_encoder.cc',
- 'tools/dump_cache/url_to_filename_encoder.h',
- 'tools/dump_cache/url_utilities.cc',
- 'tools/dump_cache/url_utilities.h',
],
# TODO(jschuh): crbug.com/167187 fix size_t to int truncations.
'msvs_disabled_warnings': [4267, ],
@@ -1202,10 +1194,6 @@
'net',
],
'sources': [
- 'tools/dump_cache/url_to_filename_encoder.cc',
- 'tools/dump_cache/url_to_filename_encoder.h',
- 'tools/dump_cache/url_utilities.cc',
- 'tools/dump_cache/url_utilities.h',
'tools/flip_server/acceptor_thread.cc',
'tools/flip_server/acceptor_thread.h',
'tools/flip_server/constants.h',
@@ -1233,6 +1221,10 @@
'tools/flip_server/spdy_util.h',
'tools/flip_server/streamer_interface.cc',
'tools/flip_server/streamer_interface.h',
+ 'tools/flip_server/url_to_filename_encoder.cc',
+ 'tools/flip_server/url_to_filename_encoder.h',
+ 'tools/flip_server/url_utilities.cc',
+ 'tools/flip_server/url_utilities.h',
],
},
{
@@ -1253,6 +1245,8 @@
'tools/flip_server/mem_cache_test.cc',
'tools/flip_server/run_all_tests.cc',
'tools/flip_server/spdy_interface_test.cc',
+ 'tools/flip_server/url_to_filename_encoder_unittest.cc',
+ 'tools/flip_server/url_utilities_unittest.cc',
],
},
{
diff --git a/net/net.gypi b/net/net.gypi
index 5ad6e7d..2e47698 100644
--- a/net/net.gypi
+++ b/net/net.gypi
@@ -1773,12 +1773,6 @@
'test/test_certificate_data.h',
'tools/balsa/balsa_frame_test.cc',
'tools/balsa/balsa_headers_test.cc',
- 'tools/dump_cache/url_to_filename_encoder.cc',
- 'tools/dump_cache/url_to_filename_encoder.h',
- 'tools/dump_cache/url_to_filename_encoder_unittest.cc',
- 'tools/dump_cache/url_utilities.cc',
- 'tools/dump_cache/url_utilities.h',
- 'tools/dump_cache/url_utilities_unittest.cc',
'tools/quic/quic_simple_client_test.cc',
'tools/tld_cleanup/tld_cleanup_util_unittest.cc',
'udp/udp_socket_unittest.cc',
diff --git a/net/tools/dump_cache/cache_dumper.cc b/net/tools/dump_cache/cache_dumper.cc
deleted file mode 100644
index 8820798..0000000
--- a/net/tools/dump_cache/cache_dumper.cc
+++ /dev/null
@@ -1,222 +0,0 @@
-// Copyright (c) 2012 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.
-
-#include "net/tools/dump_cache/cache_dumper.h"
-
-#include "base/files/file_util.h"
-#include "base/strings/utf_string_conversions.h"
-#include "net/base/io_buffer.h"
-#include "net/base/net_errors.h"
-#include "net/disk_cache/blockfile/entry_impl.h"
-#include "net/http/http_cache.h"
-#include "net/http/http_response_headers.h"
-#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) {
- return cache_->CreateEntry(key, entry, callback);
-}
-
-int CacheDumper::WriteEntry(disk_cache::Entry* entry, int index, int offset,
- net::IOBuffer* buf, int buf_len,
- const net::CompletionCallback& callback) {
- return entry->WriteData(index, offset, buf, buf_len, callback, false);
-}
-
-void CacheDumper::CloseEntry(disk_cache::Entry* entry, base::Time last_used,
- base::Time last_modified) {
- if (entry) {
- static_cast<disk_cache::EntryImpl*>(entry)->SetTimes(last_used,
- last_modified);
- entry->Close();
- }
-}
-
-// A version of CreateDirectory which supports lengthy filenames.
-// Returns true on success, false on failure.
-bool SafeCreateDirectory(const base::FilePath& path) {
-#ifdef WIN32_LARGE_FILENAME_SUPPORT
- // Due to large paths on windows, it can't simply do a
- // CreateDirectory("a/b/c"). Instead, create each subdirectory manually.
- std::wstring::size_type pos(0);
- std::wstring backslash(L"\\");
-
- // If the path starts with the long file header, skip over that
- const std::wstring kLargeFilenamePrefix(L"\\\\?\\");
- std::wstring header(kLargeFilenamePrefix);
- if (path.value().find(header) == 0)
- pos = 4;
-
- // Create the subdirectories individually
- while ((pos = path.value().find(backslash, pos)) != std::wstring::npos) {
- base::FilePath::StringType subdir = path.value().substr(0, pos);
- CreateDirectoryW(subdir.c_str(), NULL);
- // we keep going even if directory creation failed.
- pos++;
- }
- // Now create the full path
- return CreateDirectoryW(path.value().c_str(), NULL) == TRUE;
-#else
- return base::CreateDirectory(path);
-#endif
-}
-
-DiskDumper::DiskDumper(const base::FilePath& path)
- : path_(path.AsEndingWithSeparator()), entry_(NULL) {
- base::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 = path_.MaybeAsASCII();
- std::string new_path =
- net::UrlToFilenameEncoder::Encode(url, base_path, false);
- entry_path_ = base::FilePath::FromUTF8Unsafe(new_path);
-
-#ifdef WIN32_LARGE_FILENAME_SUPPORT
- // In order for long filenames to work, we'll need to prepend
- // the windows magic token.
- const std::wstring kLongFilenamePrefix(L"\\\\?\\");
- // There is no way to prepend to a filename. We simply *have*
- // to convert to a wstring to do this.
- std::wstring name = kLongFilenamePrefix;
- name.append(entry_path_.value());
- entry_path_ = base::FilePath(name);
-#endif
-
- entry_url_ = key;
-
- SafeCreateDirectory(entry_path_.DirName());
-
- base::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);
- if (entry_ == INVALID_HANDLE_VALUE)
- wprintf(L"CreateFileW (%s) failed: %d\n", file.c_str(), GetLastError());
- return (entry_ != INVALID_HANDLE_VALUE) ? net::OK : net::ERR_FAILED;
-#else
- entry_ = base::OpenFile(entry_path_, "w+");
- return (entry_ != NULL) ? net::OK : net::ERR_FAILED;
-#endif
-}
-
-// Utility Function to create a normalized header string from a
-// HttpResponseInfo. The output will be formatted exactly
-// like so:
-// HTTP/<version> <status_code> <status_text>\n
-// [<header-name>: <header-values>\n]*
-// meaning, each line is \n-terminated, and there is no extra whitespace
-// beyond the single space separators shown (of course, values can contain
-// whitespace within them). If a given header-name appears more than once
-// in the set of headers, they are combined into a single line like so:
-// <header-name>: <header-value1>, <header-value2>, ...<header-valueN>\n
-//
-// DANGER: For some headers (e.g., "Set-Cookie"), the normalized form can be
-// a lossy format. This is due to the fact that some servers generate
-// Set-Cookie headers that contain unquoted commas (usually as part of the
-// value of an "expires" attribute). So, use this function with caution. Do
-// not expect to be able to re-parse Set-Cookie headers from this output.
-//
-// NOTE: Do not make any assumptions about the encoding of this output
-// string. It may be non-ASCII, and the encoding used by the server is not
-// necessarily known to us. Do not assume that this output is UTF-8!
-void GetNormalizedHeaders(const net::HttpResponseInfo& info,
- std::string* output) {
- // Start with the status line
- output->assign(info.headers->GetStatusLine());
- output->append("\r\n");
-
- // Enumerate the headers
- void* iter = 0;
- std::string name, value;
- while (info.headers->EnumerateHeaderLines(&iter, &name, &value)) {
- output->append(name);
- output->append(": ");
- output->append(value);
- output->append("\r\n");
- }
-
- // Mark the end of headers
- output->append("\r\n");
-}
-
-int DiskDumper::WriteEntry(disk_cache::Entry* entry, int index, int offset,
- net::IOBuffer* buf, int buf_len,
- const net::CompletionCallback& callback) {
- if (!entry_)
- return 0;
-
- std::string headers;
- const char *data;
- size_t len;
- if (index == 0) { // Stream 0 is the headers.
- net::HttpResponseInfo response_info;
- bool truncated;
- if (!net::HttpCache::ParseResponseInfo(buf->data(), buf_len,
- &response_info, &truncated))
- return 0;
-
- // Skip this entry if it was truncated (results in an empty file).
- if (truncated)
- return buf_len;
-
- // Remove the size headers.
- response_info.headers->RemoveHeader("transfer-encoding");
- response_info.headers->RemoveHeader("content-length");
- response_info.headers->RemoveHeader("x-original-url");
-
- // Convert the headers into a string ending with LF.
- GetNormalizedHeaders(response_info, &headers);
-
- // Append a header for the original URL.
- std::string url = entry_url_;
- // strip off the "XXGET" which may be in the key.
- std::string::size_type pos(0);
- if ((pos = url.find("http")) != 0) {
- if (pos != std::string::npos)
- url = url.substr(pos);
- }
- std::string x_original_url = "X-Original-Url: " + url + "\r\n";
- // we know that the last two bytes are CRLF.
- headers.replace(headers.length() - 2, 0, x_original_url);
-
- data = headers.c_str();
- len = headers.size();
- } 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))
- return 0;
-
- return bytes;
-#else
- return fwrite(data, 1, len, entry_);
-#endif
-}
-
-void DiskDumper::CloseEntry(disk_cache::Entry* entry, base::Time last_used,
- base::Time last_modified) {
-#ifdef WIN32_LARGE_FILENAME_SUPPORT
- CloseHandle(entry_);
-#else
- base::CloseFile(entry_);
-#endif
-}
diff --git a/net/tools/dump_cache/cache_dumper.h b/net/tools/dump_cache/cache_dumper.h
deleted file mode 100644
index 9b071d7..0000000
--- a/net/tools/dump_cache/cache_dumper.h
+++ /dev/null
@@ -1,99 +0,0 @@
-// Copyright (c) 2012 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.
-
-#ifndef NET_TOOLS_DUMP_CACHE_CACHE_DUMPER_H_
-#define NET_TOOLS_DUMP_CACHE_CACHE_DUMPER_H_
-
-#include <string>
-
-#include "base/files/file_path.h"
-#include "net/disk_cache/blockfile/backend_impl.h"
-
-#ifdef WIN32
-// Dumping the cache often creates very large filenames, which are tricky
-// on windows. Most API calls don't support large filenames, including
-// most of the base library functions. Unfortunately, adding "\\?\" into
-// the filename support is tricky. Instead, if WIN32_LARGE_FILENAME_SUPPORT
-// is set, we use direct WIN32 APIs for manipulating the files.
-#define WIN32_LARGE_FILENAME_SUPPORT
-#endif
-
-// An abstract class for writing cache dump data.
-class CacheDumpWriter {
- public:
- virtual ~CacheDumpWriter() {}
-
- // Creates an entry to be written.
- // On success, populates the |entry|.
- // Returns a net error code.
- virtual int CreateEntry(const std::string& key,
- disk_cache::Entry** entry,
- const net::CompletionCallback& callback) = 0;
-
- // Write to the current entry.
- // Returns a net error code.
- virtual int WriteEntry(disk_cache::Entry* entry, int stream, int offset,
- net::IOBuffer* buf, int buf_len,
- const net::CompletionCallback& callback) = 0;
-
- // Close the current entry.
- virtual void CloseEntry(disk_cache::Entry* entry, base::Time last_used,
- base::Time last_modified) = 0;
-};
-
-// Writes data to a cache.
-class CacheDumper : public CacheDumpWriter {
- public:
- explicit CacheDumper(disk_cache::Backend* cache);
-
- int CreateEntry(const std::string& key,
- disk_cache::Entry** entry,
- const net::CompletionCallback& callback) override;
- int WriteEntry(disk_cache::Entry* entry,
- int stream,
- int offset,
- net::IOBuffer* buf,
- int buf_len,
- const net::CompletionCallback& callback) override;
- void CloseEntry(disk_cache::Entry* entry,
- base::Time last_used,
- base::Time last_modified) override;
-
- private:
- disk_cache::Backend* cache_;
-};
-
-// Writes data to a disk.
-class DiskDumper : public CacheDumpWriter {
- public:
- explicit DiskDumper(const base::FilePath& path);
-
- int CreateEntry(const std::string& key,
- disk_cache::Entry** entry,
- const net::CompletionCallback& callback) override;
- int WriteEntry(disk_cache::Entry* entry,
- int stream,
- int offset,
- net::IOBuffer* buf,
- int buf_len,
- const net::CompletionCallback& callback) override;
- void CloseEntry(disk_cache::Entry* entry,
- base::Time last_used,
- base::Time last_modified) override;
-
- private:
- base::FilePath path_;
- // This is a bit of a hack. As we get a CreateEntry, we coin the current
- // entry_path_ where we write that entry to disk. Subsequent calls to
- // WriteEntry() utilize this path for writing to disk.
- base::FilePath entry_path_;
- std::string entry_url_;
-#ifdef WIN32_LARGE_FILENAME_SUPPORT
- HANDLE entry_;
-#else
- FILE* entry_;
-#endif
-};
-
-#endif // NET_TOOLS_DUMP_CACHE_CACHE_DUMPER_H_
diff --git a/net/tools/dump_cache/dump_cache.cc b/net/tools/dump_cache/dump_cache.cc
index 96d47d0..15e859e 100644
--- a/net/tools/dump_cache/dump_cache.cc
+++ b/net/tools/dump_cache/dump_cache.cc
@@ -15,7 +15,6 @@
#include "base/strings/stringprintf.h"
#include "net/disk_cache/blockfile/disk_format.h"
#include "net/tools/dump_cache/dump_files.h"
-#include "net/tools/dump_cache/simple_cache_dumper.h"
enum Errors {
GENERIC = -1,
@@ -26,9 +25,8 @@ enum Errors {
TOOL_NOT_FOUND,
};
-// Folders to read and write cache files.
+// Folder to read cache files.
const char kInputPath[] = "input";
-const char kOutputPath[] = "output";
// Dumps the file headers to stdout.
const char kDumpHeaders[] = "dump-headers";
@@ -36,15 +34,11 @@ const char kDumpHeaders[] = "dump-headers";
// Dumps all entries to stdout.
const char kDumpContents[] = "dump-contents";
-// Convert the cache to files.
-const char kDumpToFiles[] = "dump-to-files";
-
int Help() {
printf("warning: input files are modified by this tool\n");
printf("dump_cache --input=path1 [--output=path2]\n");
printf("--dump-headers: display file headers\n");
printf("--dump-contents: display all entries\n");
- printf("--dump-to-files: write the contents of the cache to files\n");
return INVALID_ARGUMENT;
}
@@ -62,22 +56,10 @@ int main(int argc, const char* argv[]) {
if (input_path.empty())
return Help();
- bool dump_to_files = command_line.HasSwitch(kDumpToFiles);
-
- base::FilePath output_path = command_line.GetSwitchValuePath(kOutputPath);
- if (dump_to_files && output_path.empty())
- return Help();
-
int version = GetMajorVersion(input_path);
- if (!version)
+ if (version != 2)
return FILE_ACCESS_ERROR;
- if (dump_to_files) {
- net::SimpleCacheDumper dumper(input_path, output_path);
- dumper.Run();
- return ALL_GOOD;
- }
-
if (command_line.HasSwitch(kDumpContents))
return DumpContents(input_path);
diff --git a/net/tools/dump_cache/simple_cache_dumper.cc b/net/tools/dump_cache/simple_cache_dumper.cc
deleted file mode 100644
index 948de6a..0000000
--- a/net/tools/dump_cache/simple_cache_dumper.cc
+++ /dev/null
@@ -1,264 +0,0 @@
-// Copyright (c) 2012 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.
-
-#include "net/tools/dump_cache/simple_cache_dumper.h"
-
-#include "base/at_exit.h"
-#include "base/command_line.h"
-#include "base/logging.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/message_loop/message_loop.h"
-#include "base/threading/thread.h"
-#include "net/base/cache_type.h"
-#include "net/base/io_buffer.h"
-#include "net/base/net_errors.h"
-#include "net/disk_cache/disk_cache.h"
-#include "net/tools/dump_cache/cache_dumper.h"
-
-namespace net {
-
-SimpleCacheDumper::SimpleCacheDumper(base::FilePath input_path,
- base::FilePath output_path)
- : state_(STATE_NONE),
- input_path_(input_path),
- output_path_(output_path),
- writer_(new DiskDumper(output_path)),
- cache_thread_(new base::Thread("CacheThead")),
- src_entry_(NULL),
- dst_entry_(NULL),
- io_callback_(base::Bind(&SimpleCacheDumper::OnIOComplete,
- base::Unretained(this))),
- rv_(0) {
-}
-
-SimpleCacheDumper::~SimpleCacheDumper() {
-}
-
-int SimpleCacheDumper::Run() {
- base::MessageLoopForIO main_message_loop;
-
- LOG(INFO) << "Reading cache from: " << input_path_.value();
- LOG(INFO) << "Writing cache to: " << output_path_.value();
-
- if (!cache_thread_->StartWithOptions(
- base::Thread::Options(base::MessageLoop::TYPE_IO, 0))) {
- LOG(ERROR) << "Unable to start thread";
- return ERR_UNEXPECTED;
- }
- state_ = STATE_CREATE_CACHE;
- int rv = DoLoop(OK);
- if (rv == ERR_IO_PENDING) {
- main_message_loop.Run();
- return rv_;
- }
- return rv;
-}
-
-int SimpleCacheDumper::DoLoop(int rv) {
- do {
- State state = state_;
- state_ = STATE_NONE;
- switch (state) {
- case STATE_CREATE_CACHE:
- CHECK_EQ(OK, rv);
- rv = DoCreateCache();
- break;
- case STATE_CREATE_CACHE_COMPLETE:
- rv = DoCreateCacheComplete(rv);
- break;
- case STATE_OPEN_ENTRY:
- CHECK_EQ(OK, rv);
- rv = DoOpenEntry();
- break;
- case STATE_OPEN_ENTRY_COMPLETE:
- rv = DoOpenEntryComplete(rv);
- break;
- case STATE_CREATE_ENTRY:
- CHECK_EQ(OK, rv);
- rv = DoCreateEntry();
- break;
- case STATE_CREATE_ENTRY_COMPLETE:
- rv = DoCreateEntryComplete(rv);
- break;
- case STATE_READ_HEADERS:
- CHECK_EQ(OK, rv);
- rv = DoReadHeaders();
- break;
- case STATE_READ_HEADERS_COMPLETE:
- rv = DoReadHeadersComplete(rv);
- break;
- case STATE_WRITE_HEADERS:
- CHECK_EQ(OK, rv);
- rv = DoWriteHeaders();
- break;
- case STATE_WRITE_HEADERS_COMPLETE:
- rv = DoWriteHeadersComplete(rv);
- break;
- case STATE_READ_BODY:
- CHECK_EQ(OK, rv);
- rv = DoReadBody();
- break;
- case STATE_READ_BODY_COMPLETE:
- rv = DoReadBodyComplete(rv);
- break;
- case STATE_WRITE_BODY:
- CHECK_EQ(OK, rv);
- rv = DoWriteBody();
- break;
- case STATE_WRITE_BODY_COMPLETE:
- rv = DoWriteBodyComplete(rv);
- break;
- default:
- NOTREACHED() << "state_: " << state_;
- break;
- }
- } while (state_ != STATE_NONE && rv != ERR_IO_PENDING);
- return rv;
-}
-
-int SimpleCacheDumper::DoCreateCache() {
- DCHECK(!cache_);
- state_ = STATE_CREATE_CACHE_COMPLETE;
- return disk_cache::CreateCacheBackend(
- DISK_CACHE, CACHE_BACKEND_DEFAULT, input_path_, 0, false,
- cache_thread_->task_runner().get(), NULL, &cache_, io_callback_);
-}
-
-int SimpleCacheDumper::DoCreateCacheComplete(int rv) {
- if (rv < 0)
- return rv;
-
- reinterpret_cast<disk_cache::BackendImpl*>(cache_.get())->SetUpgradeMode();
- reinterpret_cast<disk_cache::BackendImpl*>(cache_.get())->SetFlags(
- disk_cache::kNoRandom);
-
- state_ = STATE_OPEN_ENTRY;
- return OK;
-}
-
-int SimpleCacheDumper::DoOpenEntry() {
- DCHECK(!dst_entry_);
- DCHECK(!src_entry_);
- state_ = STATE_OPEN_ENTRY_COMPLETE;
- if (!iter_)
- iter_ = cache_->CreateIterator();
- return iter_->OpenNextEntry(&src_entry_, io_callback_);
-}
-
-int SimpleCacheDumper::DoOpenEntryComplete(int rv) {
- // ERR_FAILED indicates iteration finished.
- if (rv == ERR_FAILED)
- return OK;
-
- if (rv < 0)
- return rv;
-
- state_ = STATE_CREATE_ENTRY;
- return OK;
-}
-
-int SimpleCacheDumper::DoCreateEntry() {
- DCHECK(!dst_entry_);
- state_ = STATE_CREATE_ENTRY_COMPLETE;
-
- return writer_->CreateEntry(src_entry_->GetKey(), &dst_entry_,
- io_callback_);
-}
-
-int SimpleCacheDumper::DoCreateEntryComplete(int rv) {
- if (rv < 0)
- return rv;
-
- state_ = STATE_READ_HEADERS;
- return OK;
-}
-
-int SimpleCacheDumper::DoReadHeaders() {
- state_ = STATE_READ_HEADERS_COMPLETE;
- int32 size = src_entry_->GetDataSize(0);
- buf_ = new IOBufferWithSize(size);
- return src_entry_->ReadData(0, 0, buf_.get(), size, io_callback_);
-}
-
-int SimpleCacheDumper::DoReadHeadersComplete(int rv) {
- if (rv < 0)
- return rv;
-
- state_ = STATE_WRITE_HEADERS;
- return OK;
-}
-
-int SimpleCacheDumper::DoWriteHeaders() {
- int rv = writer_->WriteEntry(
- dst_entry_, 0, 0, buf_.get(), buf_->size(), io_callback_);
- if (rv == 0)
- return ERR_FAILED;
-
- state_ = STATE_WRITE_HEADERS_COMPLETE;
- return OK;
-}
-
-int SimpleCacheDumper::DoWriteHeadersComplete(int rv) {
- if (rv < 0)
- return rv;
-
- state_ = STATE_READ_BODY;
- return OK;
-}
-
-int SimpleCacheDumper::DoReadBody() {
- state_ = STATE_READ_BODY_COMPLETE;
- int32 size = src_entry_->GetDataSize(1);
- // If the body is empty, we can neither read nor write it, so
- // just move to the next.
- if (size <= 0) {
- state_ = STATE_WRITE_BODY_COMPLETE;
- return OK;
- }
- buf_ = new IOBufferWithSize(size);
- return src_entry_->ReadData(1, 0, buf_.get(), size, io_callback_);
-}
-
-int SimpleCacheDumper::DoReadBodyComplete(int rv) {
- if (rv < 0)
- return rv;
-
- state_ = STATE_WRITE_BODY;
- return OK;
-}
-
-int SimpleCacheDumper::DoWriteBody() {
- int rv = writer_->WriteEntry(
- dst_entry_, 1, 0, buf_.get(), buf_->size(), io_callback_);
- if (rv == 0)
- return ERR_FAILED;
-
- state_ = STATE_WRITE_BODY_COMPLETE;
- return OK;
-}
-
-int SimpleCacheDumper::DoWriteBodyComplete(int rv) {
- if (rv < 0)
- return rv;
-
- src_entry_->Close();
- writer_->CloseEntry(dst_entry_, base::Time::Now(), base::Time::Now());
- src_entry_ = NULL;
- dst_entry_ = NULL;
-
- state_ = STATE_OPEN_ENTRY;
- return OK;
-}
-
-void SimpleCacheDumper::OnIOComplete(int rv) {
- rv = DoLoop(rv);
-
- if (rv != ERR_IO_PENDING) {
- rv_ = rv;
- cache_.reset();
- base::MessageLoop::current()->Quit();
- }
-}
-
-} // namespace net
diff --git a/net/tools/dump_cache/simple_cache_dumper.h b/net/tools/dump_cache/simple_cache_dumper.h
deleted file mode 100644
index cc865a3..0000000
--- a/net/tools/dump_cache/simple_cache_dumper.h
+++ /dev/null
@@ -1,90 +0,0 @@
-// Copyright (c) 2012 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.
-
-#ifndef NET_TOOLS_DUMP_CACHE_SIMPLE_CACHE_DUMPER_H_
-#define NET_TOOLS_DUMP_CACHE_SIMPLE_CACHE_DUMPER_H_
-
-#include "base/files/file_path.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/threading/thread.h"
-#include "net/base/completion_callback.h"
-#include "net/disk_cache/disk_cache.h"
-
-class DiskDumper;
-
-namespace net {
-
-class IOBufferWithSize;
-
-// A class for dumping the contents of a disk cache to a series of text
-// files. The files will contain the response headers, followed by the
-// response body, as if the HTTP response were written directly to disk.
-class SimpleCacheDumper {
- public:
- SimpleCacheDumper(base::FilePath input_path, base::FilePath output_path);
- ~SimpleCacheDumper();
-
- // Dumps the cache to disk. Returns OK if the operation was successful,
- // and a net error code otherwise.
- int Run();
-
- private:
- enum State {
- STATE_NONE,
- STATE_CREATE_CACHE,
- STATE_CREATE_CACHE_COMPLETE,
- STATE_OPEN_ENTRY,
- STATE_OPEN_ENTRY_COMPLETE,
- STATE_CREATE_ENTRY,
- STATE_CREATE_ENTRY_COMPLETE,
- STATE_READ_HEADERS,
- STATE_READ_HEADERS_COMPLETE,
- STATE_WRITE_HEADERS,
- STATE_WRITE_HEADERS_COMPLETE,
- STATE_READ_BODY,
- STATE_READ_BODY_COMPLETE,
- STATE_WRITE_BODY,
- STATE_WRITE_BODY_COMPLETE,
- STATE_DONE,
- };
-
- int DoLoop(int rv);
-
- int DoCreateCache();
- int DoCreateCacheComplete(int rv);
- int DoOpenEntry();
- int DoOpenEntryComplete(int rv);
- int DoCreateEntry();
- int DoCreateEntryComplete(int rv);
- int DoReadHeaders();
- int DoReadHeadersComplete(int rv);
- int DoWriteHeaders();
- int DoWriteHeadersComplete(int rv);
- int DoReadBody();
- int DoReadBodyComplete(int rv);
- int DoWriteBody();
- int DoWriteBodyComplete(int rv);
- int DoDone();
-
- void OnIOComplete(int rv);
-
- State state_;
- base::FilePath input_path_;
- base::FilePath output_path_;
- scoped_ptr<disk_cache::Backend> cache_;
- scoped_ptr<DiskDumper> writer_;
- base::Thread* cache_thread_;
- scoped_ptr<disk_cache::Backend::Iterator> iter_;
- disk_cache::Entry* src_entry_;
- disk_cache::Entry* dst_entry_;
- CompletionCallback io_callback_;
- scoped_refptr<IOBufferWithSize> buf_;
- int rv_;
-
- DISALLOW_COPY_AND_ASSIGN(SimpleCacheDumper);
-};
-
-} // namespace net
-
-#endif // NET_TOOLS_DUMP_CACHE_SIMPLE_CACHE_DUMPER_H_
diff --git a/net/tools/flip_server/http_interface.cc b/net/tools/flip_server/http_interface.cc
index b939c5f..576e912 100644
--- a/net/tools/flip_server/http_interface.cc
+++ b/net/tools/flip_server/http_interface.cc
@@ -5,10 +5,10 @@
#include "net/tools/flip_server/http_interface.h"
#include "net/tools/balsa/balsa_frame.h"
-#include "net/tools/dump_cache/url_utilities.h"
#include "net/tools/flip_server/flip_config.h"
#include "net/tools/flip_server/sm_connection.h"
#include "net/tools/flip_server/spdy_util.h"
+#include "net/tools/flip_server/url_utilities.h"
namespace net {
diff --git a/net/tools/flip_server/mem_cache.cc b/net/tools/flip_server/mem_cache.cc
index 485c91e..950a1a6 100644
--- a/net/tools/flip_server/mem_cache.cc
+++ b/net/tools/flip_server/mem_cache.cc
@@ -19,8 +19,8 @@
#include "base/strings/string_util.h"
#include "net/tools/balsa/balsa_frame.h"
#include "net/tools/balsa/balsa_headers.h"
-#include "net/tools/dump_cache/url_to_filename_encoder.h"
-#include "net/tools/dump_cache/url_utilities.h"
+#include "net/tools/flip_server/url_to_filename_encoder.h"
+#include "net/tools/flip_server/url_utilities.h"
namespace {
// The directory where cache locates);
diff --git a/net/tools/flip_server/spdy_interface.cc b/net/tools/flip_server/spdy_interface.cc
index 6217afb..b5701aa 100644
--- a/net/tools/flip_server/spdy_interface.cc
+++ b/net/tools/flip_server/spdy_interface.cc
@@ -9,11 +9,11 @@
#include "net/spdy/spdy_framer.h"
#include "net/spdy/spdy_protocol.h"
-#include "net/tools/dump_cache/url_utilities.h"
#include "net/tools/flip_server/constants.h"
#include "net/tools/flip_server/flip_config.h"
#include "net/tools/flip_server/http_interface.h"
#include "net/tools/flip_server/spdy_util.h"
+#include "net/tools/flip_server/url_utilities.h"
namespace net {
diff --git a/net/tools/flip_server/spdy_util.cc b/net/tools/flip_server/spdy_util.cc
index 311bdb9..a8cbd68 100644
--- a/net/tools/flip_server/spdy_util.cc
+++ b/net/tools/flip_server/spdy_util.cc
@@ -6,7 +6,7 @@
#include <string>
-#include "net/tools/dump_cache/url_to_filename_encoder.h"
+#include "net/tools/flip_server/url_to_filename_encoder.h"
namespace net {
diff --git a/net/tools/dump_cache/url_to_filename_encoder.cc b/net/tools/flip_server/url_to_filename_encoder.cc
index 083b9c5..5383cc8 100644
--- a/net/tools/dump_cache/url_to_filename_encoder.cc
+++ b/net/tools/flip_server/url_to_filename_encoder.cc
@@ -7,7 +7,7 @@
#include "base/logging.h"
#include "base/strings/string_util.h"
#include "net/base/net_util.h"
-#include "net/tools/dump_cache/url_to_filename_encoder.h"
+#include "net/tools/flip_server/url_to_filename_encoder.h"
using std::string;
@@ -31,12 +31,11 @@ int HexDigitsPrefix(const char* buf, int num_digits) {
// A simple parser for long long values. Returns the parsed value if a
// valid integer is found; else returns deflt
// UInt64 and Int64 cannot handle decimal numbers with leading 0s.
-uint64 ParseLeadingHex64Value(const char *str, uint64 deflt) {
- char *error = NULL;
+uint64 ParseLeadingHex64Value(const char* str, uint64 deflt) {
+ char* error = NULL;
const uint64 value = strtoull(str, &error, 16);
return (error == str) ? deflt : value;
}
-
}
namespace net {
@@ -169,13 +168,7 @@ void UrlToFilenameEncoder::EncodeSegment(const string& filename_prefix,
bool UrlToFilenameEncoder::Decode(const string& encoded_filename,
char dir_separator,
string* decoded_url) {
- enum State {
- kStart,
- kEscape,
- kFirstDigit,
- kTruncate,
- kEscapeDot
- };
+ enum State { kStart, kEscape, kFirstDigit, kTruncate, kEscapeDot };
State state = kStart;
char hex_buffer[3];
hex_buffer[2] = '\0';
diff --git a/net/tools/dump_cache/url_to_filename_encoder.h b/net/tools/flip_server/url_to_filename_encoder.h
index 7918418..d07c129 100644
--- a/net/tools/dump_cache/url_to_filename_encoder.h
+++ b/net/tools/flip_server/url_to_filename_encoder.h
@@ -76,13 +76,13 @@
// NOTE: we avoid using some classes here (like FilePath and GURL) because we
// share this code with other projects externally.
-#ifndef NET_TOOLS_DUMP_CACHE_URL_TO_FILENAME_ENCODER_H_
-#define NET_TOOLS_DUMP_CACHE_URL_TO_FILENAME_ENCODER_H_
+#ifndef NET_TOOLS_FLIP_SERVER_URL_TO_FILENAME_ENCODER_H_
+#define NET_TOOLS_FLIP_SERVER_URL_TO_FILENAME_ENCODER_H_
#include <string>
#include "base/strings/string_util.h"
-#include "net/tools/dump_cache/url_utilities.h"
+#include "net/tools/flip_server/url_utilities.h"
namespace net {
@@ -94,7 +94,8 @@ class UrlToFilenameEncoder {
// |legacy_escape| indicates that this function should use the old-style
// of encoding.
// TODO(mbelshe): delete the legacy_escape code.
- static std::string Encode(const std::string& url, std::string base_path,
+ static std::string Encode(const std::string& url,
+ std::string base_path,
bool legacy_escape) {
std::string filename;
if (!legacy_escape) {
@@ -105,7 +106,7 @@ class UrlToFilenameEncoder {
#endif
} else {
std::string clean_url(url);
- if (clean_url.length() && clean_url[clean_url.length()-1] == '/')
+ if (clean_url.length() && clean_url[clean_url.length() - 1] == '/')
clean_url.append("index.html");
std::string host = UrlUtilities::GetUrlHost(clean_url);
@@ -150,11 +151,10 @@ class UrlToFilenameEncoder {
// escaped characters (like %21 for !).
// |dir_separator| is "/" on Unix, "\" on Windows.
// |encoded_filename| is the resultant filename.
- static void EncodeSegment(
- const std::string& filename_prefix,
- const std::string& escaped_ending,
- char dir_separator,
- std::string* encoded_filename);
+ static void EncodeSegment(const std::string& filename_prefix,
+ const std::string& escaped_ending,
+ char dir_separator,
+ std::string* encoded_filename);
// Decodes a filename that was encoded with EncodeSegment,
// yielding back the original URL.
@@ -182,7 +182,8 @@ class UrlToFilenameEncoder {
static std::string LegacyEscape(const std::string& path);
// Replace all instances of |from| within |str| as |to|.
- static void ReplaceAll(std::string* str, const std::string& from,
+ static void ReplaceAll(std::string* str,
+ const std::string& from,
const std::string& to) {
std::string::size_type pos(0);
while ((pos = str->find(from, pos)) != std::string::npos) {
@@ -208,4 +209,4 @@ class UrlToFilenameEncoder {
} // namespace net
-#endif // NET_TOOLS_DUMP_CACHE_URL_TO_FILENAME_ENCODER_H_
+#endif // NET_TOOLS_FLIP_SERVER_URL_TO_FILENAME_ENCODER_H_
diff --git a/net/tools/dump_cache/url_to_filename_encoder_unittest.cc b/net/tools/flip_server/url_to_filename_encoder_unittest.cc
index e4d866f..2662f75 100644
--- a/net/tools/dump_cache/url_to_filename_encoder_unittest.cc
+++ b/net/tools/flip_server/url_to_filename_encoder_unittest.cc
@@ -2,15 +2,15 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "net/tools/dump_cache/url_to_filename_encoder.h"
+#include "net/tools/flip_server/url_to_filename_encoder.h"
#include <string>
#include <vector>
+#include "base/strings/string_piece.h"
#include "base/strings/string_split.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
-#include "base/strings/string_piece.h"
#include "testing/gtest/include/gtest/gtest.h"
using base::StringPiece;
@@ -28,9 +28,9 @@ char kOtherDirSeparator = '\\';
class UrlToFilenameEncoderTest : public ::testing::Test {
protected:
- UrlToFilenameEncoderTest() : escape_(1, UrlToFilenameEncoder::kEscapeChar),
- dir_sep_(1, kDirSeparator) {
- }
+ UrlToFilenameEncoderTest()
+ : escape_(1, UrlToFilenameEncoder::kEscapeChar),
+ dir_sep_(1, kDirSeparator) {}
void CheckSegmentLength(const StringPiece& escaped_word) {
for (const base::StringPiece& component :
@@ -58,8 +58,8 @@ class UrlToFilenameEncoderTest : public ::testing::Test {
void Validate(const string& in_word, const string& gold_word) {
string escaped_word, url;
- UrlToFilenameEncoder::EncodeSegment(
- std::string(), in_word, '/', &escaped_word);
+ UrlToFilenameEncoder::EncodeSegment(std::string(), in_word, '/',
+ &escaped_word);
EXPECT_EQ(gold_word, escaped_word);
CheckSegmentLength(escaped_word);
CheckValidChars(escaped_word, '\\');
@@ -69,8 +69,8 @@ class UrlToFilenameEncoderTest : public ::testing::Test {
void ValidateAllSegmentsSmall(const string& in_word) {
string escaped_word, url;
- UrlToFilenameEncoder::EncodeSegment(
- std::string(), in_word, '/', &escaped_word);
+ UrlToFilenameEncoder::EncodeSegment(std::string(), in_word, '/',
+ &escaped_word);
CheckSegmentLength(escaped_word);
CheckValidChars(escaped_word, '\\');
UrlToFilenameEncoder::Decode(escaped_word, '/', &url);
@@ -90,10 +90,12 @@ class UrlToFilenameEncoderTest : public ::testing::Test {
Validate(string(1, ch), escaped);
}
- void ValidateUrl(const string& url, const string& base_path,
- bool legacy_escape, const string& gold_filename) {
- string encoded_filename = UrlToFilenameEncoder::Encode(
- url, base_path, legacy_escape);
+ void ValidateUrl(const string& url,
+ const string& base_path,
+ bool legacy_escape,
+ const string& gold_filename) {
+ string encoded_filename =
+ UrlToFilenameEncoder::Encode(url, base_path, legacy_escape);
EXPECT_EQ(gold_filename, encoded_filename);
if (!legacy_escape) {
CheckSegmentLength(encoded_filename);
@@ -107,7 +109,8 @@ class UrlToFilenameEncoderTest : public ::testing::Test {
}
}
- void ValidateUrlOldNew(const string& url, const string& gold_old_filename,
+ void ValidateUrlOldNew(const string& url,
+ const string& gold_old_filename,
const string& gold_new_filename) {
ValidateUrl(url, std::string(), true, gold_old_filename);
ValidateUrl(url, std::string(), false, gold_new_filename);
@@ -131,8 +134,9 @@ TEST_F(UrlToFilenameEncoderTest, DoesNotEscape) {
ValidateNoChange("ZYXWVUTSRQPONMLKJIHGFEDCBA");
ValidateNoChange("01234567689");
ValidateNoChange("_.=+-");
- ValidateNoChange("abcdefghijklmnopqrstuvwxyzZYXWVUTSRQPONMLKJIHGFEDCBA"
- "01234567689_.=+-");
+ ValidateNoChange(
+ "abcdefghijklmnopqrstuvwxyzZYXWVUTSRQPONMLKJIHGFEDCBA"
+ "01234567689_.=+-");
ValidateNoChange("index.html");
ValidateNoChange("/");
ValidateNoChange("/.");
@@ -167,15 +171,14 @@ TEST_F(UrlToFilenameEncoderTest, DoesEscapeCorrectly) {
Validate("/./leaf", "/" + escape_ + "./leaf" + escape_);
Validate("/../leaf", "/" + escape_ + "../leaf" + escape_);
Validate("//leaf", "/" + escape_ + "2Fleaf" + escape_);
- Validate("mysite/u?param1=x&param2=y",
- "mysite/u" + escape_ + "3Fparam1=x" + escape_ + "26param2=y" +
- escape_);
+ Validate("mysite/u?param1=x&param2=y", "mysite/u" + escape_ + "3Fparam1=x" +
+ escape_ + "26param2=y" + escape_);
Validate("search?q=dogs&go=&form=QBLH&qs=n", // from Latency Labs bing test.
"search" + escape_ + "3Fq=dogs" + escape_ + "26go=" + escape_ +
- "26form=QBLH" + escape_ + "26qs=n" + escape_);
+ "26form=QBLH" + escape_ + "26qs=n" + escape_);
Validate("~joebob/my_neeto-website+with_stuff.asp?id=138&content=true",
"" + escape_ + "7Ejoebob/my_neeto-website+with_stuff.asp" + escape_ +
- "3Fid=138" + escape_ + "26content=true" + escape_);
+ "3Fid=138" + escape_ + "26content=true" + escape_);
}
TEST_F(UrlToFilenameEncoderTest, EncodeUrlCorrectly) {
@@ -184,33 +187,34 @@ TEST_F(UrlToFilenameEncoderTest, EncodeUrlCorrectly) {
"www.google.com" + dir_sep_ + "index.html" + escape_);
ValidateUrlOldNew("http://www.google.com/x/search?hl=en&q=dogs&oq=",
"www.google.com" + dir_sep_ + "x" + dir_sep_ +
- "searchx3Fhlx3Denx26qx3Ddogsx26oqx3D",
+ "searchx3Fhlx3Denx26qx3Ddogsx26oqx3D",
"www.google.com" + dir_sep_ + "x" + dir_sep_ + "search" +
- escape_ + "3Fhl=en" + escape_ + "26q=dogs" + escape_ +
- "26oq=" + escape_);
- ValidateUrlOldNew("http://www.foo.com/a//",
- "www.foo.com" + dir_sep_ + "ax255Cx255Cindexx2Ehtml",
- "www.foo.com" + dir_sep_ + "a" + dir_sep_ + escape_ + "2F" +
- escape_);
+ escape_ + "3Fhl=en" + escape_ + "26q=dogs" + escape_ +
+ "26oq=" + escape_);
+ ValidateUrlOldNew(
+ "http://www.foo.com/a//",
+ "www.foo.com" + dir_sep_ + "ax255Cx255Cindexx2Ehtml",
+ "www.foo.com" + dir_sep_ + "a" + dir_sep_ + escape_ + "2F" + escape_);
// From bug: Double slash preserved.
ValidateUrl("http://www.foo.com/u?site=http://www.google.com/index.html",
- std::string(),
- false,
+ std::string(), false,
"www.foo.com" + dir_sep_ + "u" + escape_ + "3Fsite=http" +
- escape_ + "3A" + dir_sep_ + escape_ + "2Fwww.google.com" +
- dir_sep_ + "index.html" + escape_);
+ escape_ + "3A" + dir_sep_ + escape_ + "2Fwww.google.com" +
+ dir_sep_ + "index.html" + escape_);
ValidateUrlOldNew(
"http://blogutils.net/olct/online.php?"
"site=http://thelwordfanfics.blogspot.&interval=600",
- "blogutils.net" + dir_sep_ + "olct" + dir_sep_ + "onlinex2Ephpx3F"
- "sitex3Dhttpx3Ax255Cx255Cthelwordfanficsx2Eblogspotx2Ex26intervalx3D600",
+ "blogutils.net" + dir_sep_ + "olct" + dir_sep_ +
+ "onlinex2Ephpx3F"
+ "sitex3Dhttpx3Ax255Cx255Cthelwordfanficsx2Eblogspotx2Ex26intervalx3D6"
+ "00",
"blogutils.net" + dir_sep_ + "olct" + dir_sep_ + "online.php" + escape_ +
- "3Fsite=http" + escape_ + "3A" + dir_sep_ + escape_ +
- "2Fthelwordfanfics.blogspot." + escape_ + "26interval=600" + escape_);
+ "3Fsite=http" + escape_ + "3A" + dir_sep_ + escape_ +
+ "2Fthelwordfanfics.blogspot." + escape_ + "26interval=600" + escape_);
}
// From bug: Escapes treated the same as normal char.
@@ -248,17 +252,22 @@ TEST_F(UrlToFilenameEncoderTest, LongTail) {
// the long lines in the string below are 64 characters, so we can see
// the slashes every 128.
string gold_long_word =
- escape_ + "7Ejoebob/briggs/"
+ escape_ +
+ "7Ejoebob/briggs/"
"1234567890123456789012345678901234567890123456789012345678901234"
"56789012345678901234567890123456789012345678901234567890123456" +
- escape_ + "-/"
+ escape_ +
+ "-/"
"7890123456789012345678901234567890123456789012345678901234567890"
"12345678901234567890123456789012345678901234567890123456789012" +
- escape_ + "-/"
+ escape_ +
+ "-/"
"3456789012345678901234567890123456789012345678901234567890123456"
"78901234567890123456789012345678901234567890123456789012345678" +
- escape_ + "-/"
- "9012345678901234567890" + escape_;
+ escape_ +
+ "-/"
+ "9012345678901234567890" +
+ escape_;
EXPECT_LT(UrlToFilenameEncoder::kMaximumSubdirectoryLength,
sizeof(long_word));
Validate(long_word, gold_long_word);
@@ -280,19 +289,23 @@ TEST_F(UrlToFilenameEncoderTest, LongTailQuestion) {
// only 127 characters.
string pattern = "1234567" + escape_ + "3F"; // 10 characters
string gold_long_word =
- escape_ + "7Ejoebob/briggs/" +
- pattern + pattern + pattern + pattern + pattern + pattern + "1234"
- "567" + escape_ + "3F" + pattern + pattern + pattern + pattern + pattern +
- "123456" + escape_ + "-/"
- "7" + escape_ + "3F" + pattern + pattern + pattern + pattern + pattern +
+ escape_ + "7Ejoebob/briggs/" + pattern + pattern + pattern + pattern +
+ pattern + pattern +
+ "1234"
+ "567" +
+ escape_ + "3F" + pattern + pattern + pattern + pattern + pattern +
+ "123456" + escape_ +
+ "-/"
+ "7" +
+ escape_ + "3F" + pattern + pattern + pattern + pattern + pattern +
pattern + pattern + pattern + pattern + pattern + pattern + pattern +
- "12" +
- escape_ + "-/"
- "34567" + escape_ + "3F" + pattern + pattern + pattern + pattern + pattern
- + "1234567" + escape_ + "3F" + pattern + pattern + pattern + pattern
- + pattern + "1234567" +
- escape_ + "-/" +
- escape_ + "3F" + pattern + pattern + escape_;
+ "12" + escape_ +
+ "-/"
+ "34567" +
+ escape_ + "3F" + pattern + pattern + pattern + pattern + pattern +
+ "1234567" + escape_ + "3F" + pattern + pattern + pattern + pattern +
+ pattern + "1234567" + escape_ + "-/" + escape_ + "3F" + pattern +
+ pattern + escape_;
EXPECT_LT(UrlToFilenameEncoder::kMaximumSubdirectoryLength,
sizeof(long_word));
Validate(long_word, gold_long_word);
@@ -320,27 +333,25 @@ TEST_F(UrlToFilenameEncoderTest, CornerCasesNearMaxLenWithEscape) {
}
TEST_F(UrlToFilenameEncoderTest, LeafBranchAlias) {
- Validate("/a/b/c", "/a/b/c" + escape_); // c is leaf file "c,"
- Validate("/a/b/c/d", "/a/b/c/d" + escape_); // c is directory "c"
+ Validate("/a/b/c", "/a/b/c" + escape_); // c is leaf file "c,"
+ Validate("/a/b/c/d", "/a/b/c/d" + escape_); // c is directory "c"
Validate("/a/b/c/d/", "/a/b/c/d/" + escape_);
}
-
TEST_F(UrlToFilenameEncoderTest, BackslashSeparator) {
string long_word;
string escaped_word;
long_word.append(UrlToFilenameEncoder::kMaximumSubdirectoryLength + 1, 'x');
- UrlToFilenameEncoder::EncodeSegment(
- std::string(), long_word, '\\', &escaped_word);
+ UrlToFilenameEncoder::EncodeSegment(std::string(), long_word, '\\',
+ &escaped_word);
// check that one backslash, plus the escape ",-", and the ending , got added.
EXPECT_EQ(long_word.size() + 4, escaped_word.size());
ASSERT_LT(UrlToFilenameEncoder::kMaximumSubdirectoryLength,
escaped_word.size());
// Check that the backslash got inserted at the correct spot.
- EXPECT_EQ('\\', escaped_word[
- UrlToFilenameEncoder::kMaximumSubdirectoryLength]);
+ EXPECT_EQ('\\',
+ escaped_word[UrlToFilenameEncoder::kMaximumSubdirectoryLength]);
}
} // namespace net
-
diff --git a/net/tools/dump_cache/url_utilities.cc b/net/tools/flip_server/url_utilities.cc
index 807f187..735fb8e 100644
--- a/net/tools/dump_cache/url_utilities.cc
+++ b/net/tools/flip_server/url_utilities.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "net/tools/dump_cache/url_utilities.h"
+#include "net/tools/flip_server/url_utilities.h"
#include "base/logging.h"
#include "base/strings/string_number_conversions.h"
@@ -18,9 +18,8 @@ std::string UrlUtilities::GetUrlHost(const std::string& url) {
b += 2;
size_t next_slash = url.find_first_of('/', b);
size_t next_colon = url.find_first_of(':', b);
- if (next_slash != std::string::npos
- && next_colon != std::string::npos
- && next_colon < next_slash) {
+ if (next_slash != std::string::npos && next_colon != std::string::npos &&
+ next_colon < next_slash) {
return std::string(url, b, next_colon - b);
}
if (next_slash == std::string::npos) {
@@ -52,7 +51,7 @@ std::string UrlUtilities::GetUrlPath(const std::string& url) {
if (b == std::string::npos)
return "/";
- size_t e = url.find("#", b+1);
+ size_t e = url.find("#", b + 1);
if (e != std::string::npos)
return std::string(url, b, (e - b));
return std::string(url, b);
@@ -123,4 +122,3 @@ std::string UrlUtilities::Unescape(const std::string& escaped_url) {
}
} // namespace net
-
diff --git a/net/tools/dump_cache/url_utilities.h b/net/tools/flip_server/url_utilities.h
index c9d8ea5..318c087 100644
--- a/net/tools/dump_cache/url_utilities.h
+++ b/net/tools/flip_server/url_utilities.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef NET_TOOLS_DUMP_CACHE_URL_UTILITIES_H_
-#define NET_TOOLS_DUMP_CACHE_URL_UTILITIES_H_
+#ifndef NET_TOOLS_FLIP_SERVER_URL_UTILITIES_H_
+#define NET_TOOLS_FLIP_SERVER_URL_UTILITIES_H_
#include <string>
@@ -32,4 +32,4 @@ struct UrlUtilities {
} // namespace net
-#endif // NET_TOOLS_DUMP_CACHE_URL_UTILITIES_H_
+#endif // NET_TOOLS_FLIP_SERVER_URL_UTILITIES_H_
diff --git a/net/tools/dump_cache/url_utilities_unittest.cc b/net/tools/flip_server/url_utilities_unittest.cc
index 3220472..cd44f9c 100644
--- a/net/tools/dump_cache/url_utilities_unittest.cc
+++ b/net/tools/flip_server/url_utilities_unittest.cc
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "net/tools/dump_cache/url_utilities.h"
+#include "net/tools/flip_server/url_utilities.h"
#include <string>
@@ -13,25 +13,18 @@
namespace net {
TEST(UrlUtilitiesTest, GetUrlHost) {
- EXPECT_EQ("www.foo.com",
- UrlUtilities::GetUrlHost("http://www.foo.com"));
- EXPECT_EQ("www.foo.com",
- UrlUtilities::GetUrlHost("http://www.foo.com:80"));
- EXPECT_EQ("www.foo.com",
- UrlUtilities::GetUrlHost("http://www.foo.com:80/"));
- EXPECT_EQ("www.foo.com",
- UrlUtilities::GetUrlHost("http://www.foo.com/news"));
+ EXPECT_EQ("www.foo.com", UrlUtilities::GetUrlHost("http://www.foo.com"));
+ EXPECT_EQ("www.foo.com", UrlUtilities::GetUrlHost("http://www.foo.com:80"));
+ EXPECT_EQ("www.foo.com", UrlUtilities::GetUrlHost("http://www.foo.com:80/"));
+ EXPECT_EQ("www.foo.com", UrlUtilities::GetUrlHost("http://www.foo.com/news"));
EXPECT_EQ("www.foo.com",
UrlUtilities::GetUrlHost("www.foo.com:80/news?q=hello"));
- EXPECT_EQ("www.foo.com",
- UrlUtilities::GetUrlHost("www.foo.com/news?q=a:b"));
- EXPECT_EQ("www.foo.com",
- UrlUtilities::GetUrlHost("www.foo.com:80"));
+ EXPECT_EQ("www.foo.com", UrlUtilities::GetUrlHost("www.foo.com/news?q=a:b"));
+ EXPECT_EQ("www.foo.com", UrlUtilities::GetUrlHost("www.foo.com:80"));
}
TEST(UrlUtilitiesTest, GetUrlHostPath) {
- EXPECT_EQ("www.foo.com",
- UrlUtilities::GetUrlHostPath("http://www.foo.com"));
+ EXPECT_EQ("www.foo.com", UrlUtilities::GetUrlHostPath("http://www.foo.com"));
EXPECT_EQ("www.foo.com:80",
UrlUtilities::GetUrlHostPath("http://www.foo.com:80"));
EXPECT_EQ("www.foo.com:80/",
@@ -42,31 +35,23 @@ TEST(UrlUtilitiesTest, GetUrlHostPath) {
UrlUtilities::GetUrlHostPath("www.foo.com:80/news?q=hello"));
EXPECT_EQ("www.foo.com/news?q=a:b",
UrlUtilities::GetUrlHostPath("www.foo.com/news?q=a:b"));
- EXPECT_EQ("www.foo.com:80",
- UrlUtilities::GetUrlHostPath("www.foo.com:80"));
+ EXPECT_EQ("www.foo.com:80", UrlUtilities::GetUrlHostPath("www.foo.com:80"));
}
TEST(UrlUtilitiesTest, GetUrlPath) {
- EXPECT_EQ("/",
- UrlUtilities::GetUrlPath("http://www.foo.com"));
- EXPECT_EQ("/",
- UrlUtilities::GetUrlPath("http://www.foo.com:80"));
- EXPECT_EQ("/",
- UrlUtilities::GetUrlPath("http://www.foo.com:80/"));
- EXPECT_EQ("/news",
- UrlUtilities::GetUrlPath("http://www.foo.com/news"));
+ EXPECT_EQ("/", UrlUtilities::GetUrlPath("http://www.foo.com"));
+ EXPECT_EQ("/", UrlUtilities::GetUrlPath("http://www.foo.com:80"));
+ EXPECT_EQ("/", UrlUtilities::GetUrlPath("http://www.foo.com:80/"));
+ EXPECT_EQ("/news", UrlUtilities::GetUrlPath("http://www.foo.com/news"));
EXPECT_EQ("/news?q=hello",
UrlUtilities::GetUrlPath("www.foo.com:80/news?q=hello"));
- EXPECT_EQ("/news?q=a:b",
- UrlUtilities::GetUrlPath("www.foo.com/news?q=a:b"));
- EXPECT_EQ("/",
- UrlUtilities::GetUrlPath("www.foo.com:80"));
+ EXPECT_EQ("/news?q=a:b", UrlUtilities::GetUrlPath("www.foo.com/news?q=a:b"));
+ EXPECT_EQ("/", UrlUtilities::GetUrlPath("www.foo.com:80"));
}
TEST(UrlUtilitiesTest, Unescape) {
// Basic examples are left alone.
- EXPECT_EQ("http://www.foo.com",
- UrlUtilities::Unescape("http://www.foo.com"));
+ EXPECT_EQ("http://www.foo.com", UrlUtilities::Unescape("http://www.foo.com"));
EXPECT_EQ("www.foo.com:80/news?q=hello",
UrlUtilities::Unescape("www.foo.com:80/news?q=hello"));
@@ -111,4 +96,3 @@ TEST(UrlUtilitiesTest, Unescape) {
}
} // namespace net
-