| 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_http_response_cache.h" | 5 #include "net/tools/quic/quic_http_response_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/stl_util.h" | |
| 12 #include "net/http/http_util.h" | 11 #include "net/http/http_util.h" |
| 13 #include "net/quic/platform/api/quic_bug_tracker.h" | 12 #include "net/quic/platform/api/quic_bug_tracker.h" |
| 14 #include "net/quic/platform/api/quic_logging.h" | 13 #include "net/quic/platform/api/quic_logging.h" |
| 14 #include "net/quic/platform/api/quic_map_util.h" |
| 15 #include "net/quic/platform/api/quic_ptr_util.h" | 15 #include "net/quic/platform/api/quic_ptr_util.h" |
| 16 #include "net/quic/platform/api/quic_text_utils.h" | 16 #include "net/quic/platform/api/quic_text_utils.h" |
| 17 #include "net/spdy/spdy_http_utils.h" | 17 #include "net/spdy/spdy_http_utils.h" |
| 18 | 18 |
| 19 using base::FilePath; | 19 using base::FilePath; |
| 20 using base::IntToString; | 20 using base::IntToString; |
| 21 using base::StringPiece; | 21 using base::StringPiece; |
| 22 using std::string; | 22 using std::string; |
| 23 | 23 |
| 24 namespace net { | 24 namespace net { |
| (...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 309 void QuicHttpResponseCache::AddResponseImpl(StringPiece host, | 309 void QuicHttpResponseCache::AddResponseImpl(StringPiece host, |
| 310 StringPiece path, | 310 StringPiece path, |
| 311 SpecialResponseType response_type, | 311 SpecialResponseType response_type, |
| 312 SpdyHeaderBlock response_headers, | 312 SpdyHeaderBlock response_headers, |
| 313 StringPiece response_body, | 313 StringPiece response_body, |
| 314 SpdyHeaderBlock response_trailers) { | 314 SpdyHeaderBlock response_trailers) { |
| 315 QuicWriterMutexLock lock(&response_mutex_); | 315 QuicWriterMutexLock lock(&response_mutex_); |
| 316 | 316 |
| 317 DCHECK(!host.empty()) << "Host must be populated, e.g. \"www.google.com\""; | 317 DCHECK(!host.empty()) << "Host must be populated, e.g. \"www.google.com\""; |
| 318 string key = GetKey(host, path); | 318 string key = GetKey(host, path); |
| 319 if (base::ContainsKey(responses_, key)) { | 319 if (QuicContainsKey(responses_, key)) { |
| 320 QUIC_BUG << "Response for '" << key << "' already exists!"; | 320 QUIC_BUG << "Response for '" << key << "' already exists!"; |
| 321 return; | 321 return; |
| 322 } | 322 } |
| 323 std::unique_ptr<Response> new_response = QuicMakeUnique<Response>(); | 323 std::unique_ptr<Response> new_response = QuicMakeUnique<Response>(); |
| 324 new_response->set_response_type(response_type); | 324 new_response->set_response_type(response_type); |
| 325 new_response->set_headers(std::move(response_headers)); | 325 new_response->set_headers(std::move(response_headers)); |
| 326 new_response->set_body(response_body); | 326 new_response->set_body(response_body); |
| 327 new_response->set_trailers(std::move(response_trailers)); | 327 new_response->set_trailers(std::move(response_trailers)); |
| 328 QUIC_DVLOG(1) << "Add response with key " << key; | 328 QUIC_DVLOG(1) << "Add response with key " << key; |
| 329 responses_[key] = std::move(new_response); | 329 responses_[key] = std::move(new_response); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 353 server_push_resources_.insert(std::make_pair(request_url, push_resource)); | 353 server_push_resources_.insert(std::make_pair(request_url, push_resource)); |
| 354 } | 354 } |
| 355 string host = push_resource.request_url.host(); | 355 string host = push_resource.request_url.host(); |
| 356 if (host.empty()) { | 356 if (host.empty()) { |
| 357 host = request_host.as_string(); | 357 host = request_host.as_string(); |
| 358 } | 358 } |
| 359 string path = push_resource.request_url.path(); | 359 string path = push_resource.request_url.path(); |
| 360 bool found_existing_response = false; | 360 bool found_existing_response = false; |
| 361 { | 361 { |
| 362 QuicWriterMutexLock lock(&response_mutex_); | 362 QuicWriterMutexLock lock(&response_mutex_); |
| 363 found_existing_response = | 363 found_existing_response = QuicContainsKey(responses_, GetKey(host, path)); |
| 364 base::ContainsKey(responses_, GetKey(host, path)); | |
| 365 } | 364 } |
| 366 if (!found_existing_response) { | 365 if (!found_existing_response) { |
| 367 // Add a server push response to responses map, if it is not in the map. | 366 // Add a server push response to responses map, if it is not in the map. |
| 368 StringPiece body = push_resource.body; | 367 StringPiece body = push_resource.body; |
| 369 QUIC_DVLOG(1) << "Add response for push resource: host " << host | 368 QUIC_DVLOG(1) << "Add response for push resource: host " << host |
| 370 << " path " << path; | 369 << " path " << path; |
| 371 AddResponse(host, path, push_resource.headers.Clone(), body); | 370 AddResponse(host, path, push_resource.headers.Clone(), body); |
| 372 } | 371 } |
| 373 } | 372 } |
| 374 } | 373 } |
| 375 | 374 |
| 376 bool QuicHttpResponseCache::PushResourceExistsInCache( | 375 bool QuicHttpResponseCache::PushResourceExistsInCache( |
| 377 string original_request_url, | 376 string original_request_url, |
| 378 ServerPushInfo resource) { | 377 ServerPushInfo resource) { |
| 379 QuicWriterMutexLock lock(&response_mutex_); | 378 QuicWriterMutexLock lock(&response_mutex_); |
| 380 auto resource_range = | 379 auto resource_range = |
| 381 server_push_resources_.equal_range(original_request_url); | 380 server_push_resources_.equal_range(original_request_url); |
| 382 for (auto it = resource_range.first; it != resource_range.second; ++it) { | 381 for (auto it = resource_range.first; it != resource_range.second; ++it) { |
| 383 ServerPushInfo push_resource = it->second; | 382 ServerPushInfo push_resource = it->second; |
| 384 if (push_resource.request_url.spec() == resource.request_url.spec()) { | 383 if (push_resource.request_url.spec() == resource.request_url.spec()) { |
| 385 return true; | 384 return true; |
| 386 } | 385 } |
| 387 } | 386 } |
| 388 return false; | 387 return false; |
| 389 } | 388 } |
| 390 | 389 |
| 391 } // namespace net | 390 } // namespace net |
| OLD | NEW |