Index: net/tools/quic/quic_http_response_cache.cc |
diff --git a/net/tools/quic/quic_http_response_cache.cc b/net/tools/quic/quic_http_response_cache.cc |
index 68c57defa65f3df572bcbc26ecadff10f635362d..4d2543e8aa03dd38cb09ea87382e4f921665e3fd 100644 |
--- a/net/tools/quic/quic_http_response_cache.cc |
+++ b/net/tools/quic/quic_http_response_cache.cc |
@@ -6,6 +6,8 @@ |
#include <utility> |
+#include "base/base_paths.h" |
+#include "base/path_service.h" |
#include "base/files/file_enumerator.h" |
#include "base/files/file_util.h" |
#include "net/http/http_util.h" |
@@ -14,6 +16,7 @@ |
#include "net/quic/platform/api/quic_map_util.h" |
#include "net/quic/platform/api/quic_ptr_util.h" |
#include "net/quic/platform/api/quic_text_utils.h" |
+#include "base/threading/thread_restrictions.h" |
#include "net/spdy/spdy_http_utils.h" |
using base::FilePath; |
@@ -230,17 +233,86 @@ void QuicHttpResponseCache::AddSpecialResponse( |
QuicHttpResponseCache::QuicHttpResponseCache() {} |
void QuicHttpResponseCache::InitializeFromDirectory( |
- const string& cache_directory) { |
+ const string& cache_directory, const FilePath& directory) { |
if (cache_directory.empty()) { |
QUIC_BUG << "cache_directory must not be empty."; |
return; |
} |
- QUIC_LOG(INFO) |
+ LOG(ERROR) |
<< "Attempting to initialize QuicHttpResponseCache from directory: " |
<< cache_directory; |
- FilePath directory(FilePath::FromUTF8Unsafe(cache_directory)); |
+ // FilePath directory(FilePath::FromUTF8Unsafe(cache_directory)); |
+ |
+ base::FileEnumerator iter(directory, true, base::FileEnumerator::FILES); |
+ int count = 0; |
+ for (base::FilePath file = iter.Next(); !file.value().empty(); file = iter.Next()) { |
+ count ++; |
+ } |
+ LOG(ERROR) << "@@@@ Inside QUIC of the file size: " << count; |
+ |
base::FileEnumerator file_list(directory, true, base::FileEnumerator::FILES); |
std::list<std::unique_ptr<ResourceFile>> resource_files; |
+ int i = 0; |
+ |
+ for (FilePath file_iter = file_list.Next(); !file_iter.empty(); |
+ file_iter = file_list.Next()) { |
+ LOG(ERROR) << i++; |
+ // Need to skip files in .svn directories |
+ if (file_iter.value().find(FILE_PATH_LITERAL("/.svn/")) != string::npos) { |
+ LOG(ERROR) << "skipped /.svn/"; |
+ continue; |
+ } |
+ LOG(ERROR) << "entered here"; |
+ std::unique_ptr<ResourceFile> resource_file(new ResourceFile(file_iter)); |
+ |
+ // Tease apart filename into host and path. |
+ StringPiece base(resource_file->file_name()); |
+ base.remove_prefix(cache_directory.length()); |
+ if (base[0] == '/') { |
+ base.remove_prefix(1); |
+ } |
+ |
+ resource_file->SetHostPathFromBase(base); |
+ resource_file->Read(); |
+ |
+ AddResponse(resource_file->host(), resource_file->path(), |
+ resource_file->spdy_headers().Clone(), resource_file->body()); |
+ |
+ resource_files.push_back(std::move(resource_file)); |
+ } |
+ |
+ LOG(ERROR) << "size of resource files " << resource_files.size(); |
+ for (const auto& resource_file : resource_files) { |
+ std::list<ServerPushInfo> push_resources; |
+ for (const auto& push_url : resource_file->push_urls()) { |
+ QuicUrl url(push_url); |
+ const Response* response = GetResponse(url.host(), url.path()); |
+ if (!response) { |
+ QUIC_BUG << "Push URL '" << push_url << "' not found."; |
+ return; |
+ } |
+ push_resources.push_back(ServerPushInfo(url, response->headers().Clone(), |
+ kV3LowestPriority, |
+ response->body().as_string())); |
+ } |
+ MaybeAddServerPushResources(resource_file->host(), resource_file->path(), |
+ push_resources); |
+ } |
+} |
+ |
+void QuicHttpResponseCache::InitializeFromDirectory( |
+ const string& cache_directory) { |
+ if (cache_directory.empty()) { |
+ QUIC_BUG << "cache_directory must not be empty."; |
+ return; |
+ } |
+ LOG(ERROR) |
+ << "Attempting to initialize QuicHttpResponseCache from directory: " |
+ << cache_directory; |
+ FilePath directory(FilePath::FromUTF8Unsafe(cache_directory)); |
+ |
+ base::FileEnumerator file_list(directory, true, base::FileEnumerator::FILES); |
+ std::list<std::unique_ptr<ResourceFile>> resource_files; |
for (FilePath file_iter = file_list.Next(); !file_iter.empty(); |
file_iter = file_list.Next()) { |
// Need to skip files in .svn directories |
@@ -284,6 +356,8 @@ void QuicHttpResponseCache::InitializeFromDirectory( |
} |
} |
+ |
+ |
std::list<ServerPushInfo> QuicHttpResponseCache::GetServerPushResources( |
string request_url) { |
QuicWriterMutexLock lock(&response_mutex_); |
@@ -338,12 +412,14 @@ void QuicHttpResponseCache::MaybeAddServerPushResources( |
std::list<ServerPushInfo> push_resources) { |
string request_url = GetKey(request_host, request_path); |
+ LOG(ERROR) << "====== zhongyi: maybe add server push resource " << request_url; |
for (const auto& push_resource : push_resources) { |
if (PushResourceExistsInCache(request_url, push_resource)) { |
+ LOG(ERROR) << "push resource exists in cache"; |
continue; |
} |
- QUIC_DVLOG(1) << "Add request-resource association: request url " |
+ LOG(ERROR) << "Add request-resource association: request url " |
<< request_url << " push url " |
<< push_resource.request_url.ToString() |
<< " response headers " |
@@ -365,7 +441,7 @@ void QuicHttpResponseCache::MaybeAddServerPushResources( |
if (!found_existing_response) { |
// Add a server push response to responses map, if it is not in the map. |
StringPiece body = push_resource.body; |
- QUIC_DVLOG(1) << "Add response for push resource: host " << host |
+ LOG(ERROR) << "Add response for push resource: host " << host |
<< " path " << path; |
AddResponse(host, path, push_resource.headers.Clone(), body); |
} |
@@ -380,6 +456,7 @@ bool QuicHttpResponseCache::PushResourceExistsInCache( |
server_push_resources_.equal_range(original_request_url); |
for (auto it = resource_range.first; it != resource_range.second; ++it) { |
ServerPushInfo push_resource = it->second; |
+ LOG(ERROR) << "#1: " << push_resource.request_url.ToString(); |
if (push_resource.request_url.ToString() == |
resource.request_url.ToString()) { |
return true; |