| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/tools/quic/quic_in_memory_cache.h" | 5 #include "net/tools/quic/quic_in_memory_cache.h" |
| 6 | 6 |
| 7 #include "base/files/file_enumerator.h" | 7 #include "base/files/file_enumerator.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_util.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "net/http/http_response_headers.h" | 13 #include "net/http/http_response_headers.h" |
| 14 #include "net/http/http_util.h" | 14 #include "net/http/http_util.h" |
| 15 #include "net/quic/quic_bug_tracker.h" |
| 15 #include "net/spdy/spdy_http_utils.h" | 16 #include "net/spdy/spdy_http_utils.h" |
| 16 | 17 |
| 17 using base::FilePath; | 18 using base::FilePath; |
| 18 using base::IntToString; | 19 using base::IntToString; |
| 19 using base::StringPiece; | 20 using base::StringPiece; |
| 20 using std::string; | 21 using std::string; |
| 21 | 22 |
| 22 namespace net { | 23 namespace net { |
| 23 namespace tools { | 24 namespace tools { |
| 24 | 25 |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 | 108 |
| 108 QuicInMemoryCache::QuicInMemoryCache() {} | 109 QuicInMemoryCache::QuicInMemoryCache() {} |
| 109 | 110 |
| 110 void QuicInMemoryCache::ResetForTests() { | 111 void QuicInMemoryCache::ResetForTests() { |
| 111 STLDeleteValues(&responses_); | 112 STLDeleteValues(&responses_); |
| 112 server_push_resources_.clear(); | 113 server_push_resources_.clear(); |
| 113 } | 114 } |
| 114 | 115 |
| 115 void QuicInMemoryCache::InitializeFromDirectory(const string& cache_directory) { | 116 void QuicInMemoryCache::InitializeFromDirectory(const string& cache_directory) { |
| 116 if (cache_directory.empty()) { | 117 if (cache_directory.empty()) { |
| 117 LOG(DFATAL) << "cache_directory must not be empty."; | 118 QUIC_BUG << "cache_directory must not be empty."; |
| 118 return; | 119 return; |
| 119 } | 120 } |
| 120 VLOG(1) << "Attempting to initialize QuicInMemoryCache from directory: " | 121 VLOG(1) << "Attempting to initialize QuicInMemoryCache from directory: " |
| 121 << cache_directory; | 122 << cache_directory; |
| 122 FilePath directory(FilePath::FromUTF8Unsafe(cache_directory)); | 123 FilePath directory(FilePath::FromUTF8Unsafe(cache_directory)); |
| 123 base::FileEnumerator file_list(directory, true, base::FileEnumerator::FILES); | 124 base::FileEnumerator file_list(directory, true, base::FileEnumerator::FILES); |
| 124 | 125 |
| 125 for (FilePath file_iter = file_list.Next(); !file_iter.empty(); | 126 for (FilePath file_iter = file_list.Next(); !file_iter.empty(); |
| 126 file_iter = file_list.Next()) { | 127 file_iter = file_list.Next()) { |
| 127 // Need to skip files in .svn directories | 128 // Need to skip files in .svn directories |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 void QuicInMemoryCache::AddResponseImpl( | 199 void QuicInMemoryCache::AddResponseImpl( |
| 199 StringPiece host, | 200 StringPiece host, |
| 200 StringPiece path, | 201 StringPiece path, |
| 201 SpecialResponseType response_type, | 202 SpecialResponseType response_type, |
| 202 const SpdyHeaderBlock& response_headers, | 203 const SpdyHeaderBlock& response_headers, |
| 203 StringPiece response_body, | 204 StringPiece response_body, |
| 204 const SpdyHeaderBlock& response_trailers) { | 205 const SpdyHeaderBlock& response_trailers) { |
| 205 DCHECK(!host.empty()) << "Host must be populated, e.g. \"www.google.com\""; | 206 DCHECK(!host.empty()) << "Host must be populated, e.g. \"www.google.com\""; |
| 206 string key = GetKey(host, path); | 207 string key = GetKey(host, path); |
| 207 if (ContainsKey(responses_, key)) { | 208 if (ContainsKey(responses_, key)) { |
| 208 LOG(DFATAL) << "Response for '" << key << "' already exists!"; | 209 QUIC_BUG << "Response for '" << key << "' already exists!"; |
| 209 return; | 210 return; |
| 210 } | 211 } |
| 211 Response* new_response = new Response(); | 212 Response* new_response = new Response(); |
| 212 new_response->set_response_type(response_type); | 213 new_response->set_response_type(response_type); |
| 213 new_response->set_headers(response_headers); | 214 new_response->set_headers(response_headers); |
| 214 new_response->set_body(response_body); | 215 new_response->set_body(response_body); |
| 215 new_response->set_trailers(response_trailers); | 216 new_response->set_trailers(response_trailers); |
| 216 responses_[key] = new_response; | 217 responses_[key] = new_response; |
| 217 } | 218 } |
| 218 | 219 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 ServerPushInfo push_resource = it->second; | 253 ServerPushInfo push_resource = it->second; |
| 253 if (push_resource.request_url.spec() == resource.request_url.spec()) { | 254 if (push_resource.request_url.spec() == resource.request_url.spec()) { |
| 254 return true; | 255 return true; |
| 255 } | 256 } |
| 256 } | 257 } |
| 257 return false; | 258 return false; |
| 258 } | 259 } |
| 259 | 260 |
| 260 } // namespace tools | 261 } // namespace tools |
| 261 } // namespace net | 262 } // namespace net |
| OLD | NEW |