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

Side by Side Diff: net/tools/quic/quic_in_memory_cache.cc

Issue 2417183003: Remove stl_util's deletion functions from remaining quic code. (Closed)
Patch Set: rebase Created 4 years, 2 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 unified diff | Download patch
« no previous file with comments | « net/tools/quic/quic_in_memory_cache.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/files/file_enumerator.h" 9 #include "base/files/file_enumerator.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/memory/ptr_util.h"
11 #include "base/stl_util.h" 12 #include "base/stl_util.h"
12 #include "base/strings/string_number_conversions.h" 13 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
14 #include "base/strings/stringprintf.h" 15 #include "base/strings/stringprintf.h"
15 #include "net/http/http_response_headers.h" 16 #include "net/http/http_response_headers.h"
16 #include "net/http/http_util.h" 17 #include "net/http/http_util.h"
17 #include "net/quic/core/quic_bug_tracker.h" 18 #include "net/quic/core/quic_bug_tracker.h"
18 #include "net/spdy/spdy_http_utils.h" 19 #include "net/spdy/spdy_http_utils.h"
19 20
20 using base::FilePath; 21 using base::FilePath;
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 // static 139 // static
139 QuicInMemoryCache* QuicInMemoryCache::GetInstance() { 140 QuicInMemoryCache* QuicInMemoryCache::GetInstance() {
140 return base::Singleton<QuicInMemoryCache>::get(); 141 return base::Singleton<QuicInMemoryCache>::get();
141 } 142 }
142 143
143 const QuicInMemoryCache::Response* QuicInMemoryCache::GetResponse( 144 const QuicInMemoryCache::Response* QuicInMemoryCache::GetResponse(
144 StringPiece host, 145 StringPiece host,
145 StringPiece path) const { 146 StringPiece path) const {
146 base::AutoLock lock(response_mutex_); 147 base::AutoLock lock(response_mutex_);
147 148
148 ResponseMap::const_iterator it = responses_.find(GetKey(host, path)); 149 auto it = responses_.find(GetKey(host, path));
149 if (it == responses_.end()) { 150 if (it == responses_.end()) {
150 DVLOG(1) << "Get response for resource failed: host " << host << " path " 151 DVLOG(1) << "Get response for resource failed: host " << host << " path "
151 << path; 152 << path;
152 if (default_response_.get()) { 153 if (default_response_.get()) {
153 return default_response_.get(); 154 return default_response_.get();
154 } 155 }
155 return nullptr; 156 return nullptr;
156 } 157 }
157 return it->second; 158 return it->second.get();
158 } 159 }
159 160
160 typedef QuicInMemoryCache::ServerPushInfo ServerPushInfo; 161 typedef QuicInMemoryCache::ServerPushInfo ServerPushInfo;
161 162
162 void QuicInMemoryCache::AddSimpleResponse(StringPiece host, 163 void QuicInMemoryCache::AddSimpleResponse(StringPiece host,
163 StringPiece path, 164 StringPiece path,
164 int response_code, 165 int response_code,
165 StringPiece body) { 166 StringPiece body) {
166 SpdyHeaderBlock response_headers; 167 SpdyHeaderBlock response_headers;
167 response_headers[":status"] = IntToString(response_code); 168 response_headers[":status"] = IntToString(response_code);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 StringPiece path, 207 StringPiece path,
207 SpecialResponseType response_type) { 208 SpecialResponseType response_type) {
208 AddResponseImpl(host, path, response_type, SpdyHeaderBlock(), "", 209 AddResponseImpl(host, path, response_type, SpdyHeaderBlock(), "",
209 SpdyHeaderBlock()); 210 SpdyHeaderBlock());
210 } 211 }
211 212
212 QuicInMemoryCache::QuicInMemoryCache() {} 213 QuicInMemoryCache::QuicInMemoryCache() {}
213 214
214 void QuicInMemoryCache::ResetForTests() { 215 void QuicInMemoryCache::ResetForTests() {
215 base::AutoLock lock(response_mutex_); 216 base::AutoLock lock(response_mutex_);
216 base::STLDeleteValues(&responses_); 217 responses_.clear();
217 server_push_resources_.clear(); 218 server_push_resources_.clear();
218 } 219 }
219 220
220 void QuicInMemoryCache::InitializeFromDirectory(const string& cache_directory) { 221 void QuicInMemoryCache::InitializeFromDirectory(const string& cache_directory) {
221 if (cache_directory.empty()) { 222 if (cache_directory.empty()) {
222 QUIC_BUG << "cache_directory must not be empty."; 223 QUIC_BUG << "cache_directory must not be empty.";
223 return; 224 return;
224 } 225 }
225 VLOG(1) << "Attempting to initialize QuicInMemoryCache from directory: " 226 VLOG(1) << "Attempting to initialize QuicInMemoryCache from directory: "
226 << cache_directory; 227 << cache_directory;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 resources.push_back(it->second); 282 resources.push_back(it->second);
282 } 283 }
283 DVLOG(1) << "Found " << resources.size() << " push resources for " 284 DVLOG(1) << "Found " << resources.size() << " push resources for "
284 << request_url; 285 << request_url;
285 return resources; 286 return resources;
286 } 287 }
287 288
288 QuicInMemoryCache::~QuicInMemoryCache() { 289 QuicInMemoryCache::~QuicInMemoryCache() {
289 { 290 {
290 base::AutoLock lock(response_mutex_); 291 base::AutoLock lock(response_mutex_);
291 base::STLDeleteValues(&responses_); 292 responses_.clear();
292 } 293 }
293 } 294 }
294 295
295 void QuicInMemoryCache::AddResponseImpl(StringPiece host, 296 void QuicInMemoryCache::AddResponseImpl(StringPiece host,
296 StringPiece path, 297 StringPiece path,
297 SpecialResponseType response_type, 298 SpecialResponseType response_type,
298 SpdyHeaderBlock response_headers, 299 SpdyHeaderBlock response_headers,
299 StringPiece response_body, 300 StringPiece response_body,
300 SpdyHeaderBlock response_trailers) { 301 SpdyHeaderBlock response_trailers) {
301 base::AutoLock lock(response_mutex_); 302 base::AutoLock lock(response_mutex_);
302 303
303 DCHECK(!host.empty()) << "Host must be populated, e.g. \"www.google.com\""; 304 DCHECK(!host.empty()) << "Host must be populated, e.g. \"www.google.com\"";
304 string key = GetKey(host, path); 305 string key = GetKey(host, path);
305 if (base::ContainsKey(responses_, key)) { 306 if (base::ContainsKey(responses_, key)) {
306 QUIC_BUG << "Response for '" << key << "' already exists!"; 307 QUIC_BUG << "Response for '" << key << "' already exists!";
307 return; 308 return;
308 } 309 }
309 Response* new_response = new Response(); 310 std::unique_ptr<Response> new_response = base::MakeUnique<Response>();
310 new_response->set_response_type(response_type); 311 new_response->set_response_type(response_type);
311 new_response->set_headers(std::move(response_headers)); 312 new_response->set_headers(std::move(response_headers));
312 new_response->set_body(response_body); 313 new_response->set_body(response_body);
313 new_response->set_trailers(std::move(response_trailers)); 314 new_response->set_trailers(std::move(response_trailers));
314 DVLOG(1) << "Add response with key " << key; 315 DVLOG(1) << "Add response with key " << key;
315 responses_[key] = new_response; 316 responses_[key] = std::move(new_response);
316 } 317 }
317 318
318 string QuicInMemoryCache::GetKey(StringPiece host, StringPiece path) const { 319 string QuicInMemoryCache::GetKey(StringPiece host, StringPiece path) const {
319 return host.as_string() + path.as_string(); 320 return host.as_string() + path.as_string();
320 } 321 }
321 322
322 void QuicInMemoryCache::MaybeAddServerPushResources( 323 void QuicInMemoryCache::MaybeAddServerPushResources(
323 StringPiece request_host, 324 StringPiece request_host,
324 StringPiece request_path, 325 StringPiece request_path,
325 list<ServerPushInfo> push_resources) { 326 list<ServerPushInfo> push_resources) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 for (auto it = resource_range.first; it != resource_range.second; ++it) { 367 for (auto it = resource_range.first; it != resource_range.second; ++it) {
367 ServerPushInfo push_resource = it->second; 368 ServerPushInfo push_resource = it->second;
368 if (push_resource.request_url.spec() == resource.request_url.spec()) { 369 if (push_resource.request_url.spec() == resource.request_url.spec()) {
369 return true; 370 return true;
370 } 371 }
371 } 372 }
372 return false; 373 return false;
373 } 374 }
374 375
375 } // namespace net 376 } // namespace net
OLDNEW
« no previous file with comments | « net/tools/quic/quic_in_memory_cache.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698