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

Unified Diff: net/tools/quic/quic_in_memory_cache.cc

Issue 1037533002: Make initialization of the QuicInMemoryCache explicit to avoid spooky action at a distance which co… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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/tools/quic/quic_in_memory_cache.h ('k') | net/tools/quic/quic_in_memory_cache_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/tools/quic/quic_in_memory_cache.cc
diff --git a/net/tools/quic/quic_in_memory_cache.cc b/net/tools/quic/quic_in_memory_cache.cc
index 1e314fc4da8cf977e04a22201e641367d869e5dc..503b91aa25b4a95dc8330ec4f8525d98e066921a 100644
--- a/net/tools/quic/quic_in_memory_cache.cc
+++ b/net/tools/quic/quic_in_memory_cache.cc
@@ -20,11 +20,6 @@ using std::string;
namespace net {
namespace tools {
-// Specifies the directory used during QuicInMemoryCache
-// construction to seed the cache. Cache directory can be
-// generated using `wget -p --save-headers <url>
-string FLAGS_quic_in_memory_cache_dir = "";
-
namespace {
// BalsaVisitor implementation (glue) which caches response bodies.
@@ -102,40 +97,41 @@ void QuicInMemoryCache::AddSpecialResponse(StringPiece host,
AddResponseImpl(host, path, response_type, SpdyHeaderBlock(), "");
}
-QuicInMemoryCache::QuicInMemoryCache() {
- Initialize();
-}
+QuicInMemoryCache::QuicInMemoryCache() {}
void QuicInMemoryCache::ResetForTests() {
STLDeleteValues(&responses_);
- Initialize();
}
-void QuicInMemoryCache::Initialize() {
- // If there's no defined cache dir, we have no initialization to do.
- if (FLAGS_quic_in_memory_cache_dir.empty()) {
- VLOG(1) << "No cache directory found. Skipping initialization.";
+void QuicInMemoryCache::InitializeFromDirectory(const string& cache_directory) {
+ if (cache_directory.empty()) {
+ LOG(DFATAL) << "cache_directory must not be empty.";
return;
}
VLOG(1) << "Attempting to initialize QuicInMemoryCache from directory: "
- << FLAGS_quic_in_memory_cache_dir;
-
- FilePath directory(FLAGS_quic_in_memory_cache_dir);
+ << cache_directory;
ramant (doing other things) 2015/03/24 21:49:36 nit: indentation.
Ryan Hamilton 2015/03/24 22:03:09 Done. (In final CL)
+ FilePath directory(cache_directory);
base::FileEnumerator file_list(directory,
true,
base::FileEnumerator::FILES);
- for (FilePath file = file_list.Next(); !file.empty();
- file = file_list.Next()) {
+ for (FilePath file_iter = file_list.Next(); !file_iter.empty();
+ file_iter = file_list.Next()) {
+ BalsaHeaders request_headers, response_headers;
// Need to skip files in .svn directories
- if (file.value().find("/.svn/") != string::npos) {
+ if (file_iter.value().find("/.svn/") != string::npos) {
continue;
}
- BalsaHeaders request_headers, response_headers;
+ // Tease apart filename into host and path.
+ StringPiece file(file_iter.value());
+ file.remove_prefix(cache_directory.length());
+ if (file[0] == '/') {
+ file.remove_prefix(1);
+ }
string file_contents;
- base::ReadFileToString(file, &file_contents);
+ base::ReadFileToString(file_iter, &file_contents);
// Frame HTTP.
CachingBalsaVisitor caching_visitor;
@@ -150,7 +146,7 @@ void QuicInMemoryCache::Initialize() {
}
if (!caching_visitor.done_framing()) {
- LOG(DFATAL) << "Did not frame entire message from file: " << file.value()
+ LOG(DFATAL) << "Did not frame entire message from file: " << file
<< " (" << processed << " of " << file_contents.length()
<< " bytes).";
}
@@ -163,7 +159,7 @@ void QuicInMemoryCache::Initialize() {
processed += file_contents.length();
}
- StringPiece base = file.value();
+ StringPiece base = file;
if (response_headers.HasHeader("X-Original-Url")) {
base = response_headers.GetHeader("X-Original-Url");
response_headers.RemoveAllOfHeader("X-Original-Url");
« no previous file with comments | « net/tools/quic/quic_in_memory_cache.h ('k') | net/tools/quic/quic_in_memory_cache_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698