| 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" |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 } | 78 } |
| 79 | 79 |
| 80 void QuicInMemoryCache::AddDefaultResponse(Response* response) { | 80 void QuicInMemoryCache::AddDefaultResponse(Response* response) { |
| 81 default_response_.reset(response); | 81 default_response_.reset(response); |
| 82 } | 82 } |
| 83 | 83 |
| 84 void QuicInMemoryCache::AddResponse(StringPiece host, | 84 void QuicInMemoryCache::AddResponse(StringPiece host, |
| 85 StringPiece path, | 85 StringPiece path, |
| 86 const SpdyHeaderBlock& response_headers, | 86 const SpdyHeaderBlock& response_headers, |
| 87 StringPiece response_body) { | 87 StringPiece response_body) { |
| 88 AddResponseImpl(host, path, REGULAR_RESPONSE, response_headers, | 88 AddResponseImpl(host, path, REGULAR_RESPONSE, response_headers, response_body, |
| 89 response_body); | 89 SpdyHeaderBlock()); |
| 90 } |
| 91 |
| 92 void QuicInMemoryCache::AddResponse(StringPiece host, |
| 93 StringPiece path, |
| 94 const SpdyHeaderBlock& response_headers, |
| 95 StringPiece response_body, |
| 96 const SpdyHeaderBlock& response_trailers) { |
| 97 AddResponseImpl(host, path, REGULAR_RESPONSE, response_headers, response_body, |
| 98 response_trailers); |
| 90 } | 99 } |
| 91 | 100 |
| 92 void QuicInMemoryCache::AddSpecialResponse(StringPiece host, | 101 void QuicInMemoryCache::AddSpecialResponse(StringPiece host, |
| 93 StringPiece path, | 102 StringPiece path, |
| 94 SpecialResponseType response_type) { | 103 SpecialResponseType response_type) { |
| 95 AddResponseImpl(host, path, response_type, SpdyHeaderBlock(), ""); | 104 AddResponseImpl(host, path, response_type, SpdyHeaderBlock(), "", |
| 105 SpdyHeaderBlock()); |
| 96 } | 106 } |
| 97 | 107 |
| 98 QuicInMemoryCache::QuicInMemoryCache() {} | 108 QuicInMemoryCache::QuicInMemoryCache() {} |
| 99 | 109 |
| 100 void QuicInMemoryCache::ResetForTests() { | 110 void QuicInMemoryCache::ResetForTests() { |
| 101 STLDeleteValues(&responses_); | 111 STLDeleteValues(&responses_); |
| 102 server_push_resources_.clear(); | 112 server_push_resources_.clear(); |
| 103 } | 113 } |
| 104 | 114 |
| 105 void QuicInMemoryCache::InitializeFromDirectory(const string& cache_directory) { | 115 void QuicInMemoryCache::InitializeFromDirectory(const string& cache_directory) { |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 for (auto it = resource_range.first; it != resource_range.second; ++it) { | 190 for (auto it = resource_range.first; it != resource_range.second; ++it) { |
| 181 resources.push_back(it->second); | 191 resources.push_back(it->second); |
| 182 } | 192 } |
| 183 return resources; | 193 return resources; |
| 184 } | 194 } |
| 185 | 195 |
| 186 QuicInMemoryCache::~QuicInMemoryCache() { | 196 QuicInMemoryCache::~QuicInMemoryCache() { |
| 187 STLDeleteValues(&responses_); | 197 STLDeleteValues(&responses_); |
| 188 } | 198 } |
| 189 | 199 |
| 190 void QuicInMemoryCache::AddResponseImpl(StringPiece host, | 200 void QuicInMemoryCache::AddResponseImpl( |
| 191 StringPiece path, | 201 StringPiece host, |
| 192 SpecialResponseType response_type, | 202 StringPiece path, |
| 193 const SpdyHeaderBlock& response_headers, | 203 SpecialResponseType response_type, |
| 194 StringPiece response_body) { | 204 const SpdyHeaderBlock& response_headers, |
| 205 StringPiece response_body, |
| 206 const SpdyHeaderBlock& response_trailers) { |
| 195 string key = GetKey(host, path); | 207 string key = GetKey(host, path); |
| 196 if (ContainsKey(responses_, key)) { | 208 if (ContainsKey(responses_, key)) { |
| 197 LOG(DFATAL) << "Response for '" << key << "' already exists!"; | 209 LOG(DFATAL) << "Response for '" << key << "' already exists!"; |
| 198 return; | 210 return; |
| 199 } | 211 } |
| 200 Response* new_response = new Response(); | 212 Response* new_response = new Response(); |
| 201 new_response->set_response_type(response_type); | 213 new_response->set_response_type(response_type); |
| 202 new_response->set_headers(response_headers); | 214 new_response->set_headers(response_headers); |
| 203 new_response->set_body(response_body); | 215 new_response->set_body(response_body); |
| 216 new_response->set_trailers(response_trailers); |
| 204 responses_[key] = new_response; | 217 responses_[key] = new_response; |
| 205 } | 218 } |
| 206 | 219 |
| 207 string QuicInMemoryCache::GetKey(StringPiece host, StringPiece path) const { | 220 string QuicInMemoryCache::GetKey(StringPiece host, StringPiece path) const { |
| 208 return host.as_string() + path.as_string(); | 221 return host.as_string() + path.as_string(); |
| 209 } | 222 } |
| 210 | 223 |
| 211 void QuicInMemoryCache::MaybeAddServerPushResources( | 224 void QuicInMemoryCache::MaybeAddServerPushResources( |
| 212 StringPiece request_host, | 225 StringPiece request_host, |
| 213 StringPiece request_path, | 226 StringPiece request_path, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 240 ServerPushInfo push_resource = it->second; | 253 ServerPushInfo push_resource = it->second; |
| 241 if (push_resource.request_url.spec() == resource.request_url.spec()) { | 254 if (push_resource.request_url.spec() == resource.request_url.spec()) { |
| 242 return true; | 255 return true; |
| 243 } | 256 } |
| 244 } | 257 } |
| 245 return false; | 258 return false; |
| 246 } | 259 } |
| 247 | 260 |
| 248 } // namespace tools | 261 } // namespace tools |
| 249 } // namespace net | 262 } // namespace net |
| OLD | NEW |