| 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 #ifndef NET_TOOLS_QUIC_QUIC_IN_MEMORY_CACHE_H_ | 5 #ifndef NET_TOOLS_QUIC_QUIC_IN_MEMORY_CACHE_H_ |
| 6 #define NET_TOOLS_QUIC_QUIC_IN_MEMORY_CACHE_H_ | 6 #define NET_TOOLS_QUIC_QUIC_IN_MEMORY_CACHE_H_ |
| 7 | 7 |
| 8 #include <list> | 8 #include <list> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <unordered_map> | 12 #include <unordered_map> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/strings/string_piece.h" | 17 #include "base/strings/string_piece.h" |
| 18 #include "net/http/http_response_headers.h" | 18 #include "net/http/http_response_headers.h" |
| 19 #include "net/quic/core/spdy_utils.h" | 19 #include "net/quic/core/spdy_utils.h" |
| 20 #include "net/quic/platform/api/quic_mutex.h" |
| 20 #include "net/spdy/spdy_framer.h" | 21 #include "net/spdy/spdy_framer.h" |
| 21 #include "url/gurl.h" | 22 #include "url/gurl.h" |
| 22 | 23 |
| 23 namespace net { | 24 namespace net { |
| 24 | 25 |
| 25 // In-memory cache for HTTP responses. | 26 // In-memory cache for HTTP responses. |
| 26 // Reads from disk cache generated by: | 27 // Reads from disk cache generated by: |
| 27 // `wget -p --save_headers <url>` | 28 // `wget -p --save_headers <url>` |
| 28 class QuicHttpResponseCache { | 29 class QuicHttpResponseCache { |
| 29 public: | 30 public: |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 void MaybeAddServerPushResources(base::StringPiece request_host, | 195 void MaybeAddServerPushResources(base::StringPiece request_host, |
| 195 base::StringPiece request_path, | 196 base::StringPiece request_path, |
| 196 std::list<ServerPushInfo> push_resources); | 197 std::list<ServerPushInfo> push_resources); |
| 197 | 198 |
| 198 // Check if push resource(push_host/push_path) associated with given request | 199 // Check if push resource(push_host/push_path) associated with given request |
| 199 // url already exists in server push map. | 200 // url already exists in server push map. |
| 200 bool PushResourceExistsInCache(std::string original_request_url, | 201 bool PushResourceExistsInCache(std::string original_request_url, |
| 201 ServerPushInfo resource); | 202 ServerPushInfo resource); |
| 202 | 203 |
| 203 // Cached responses. | 204 // Cached responses. |
| 204 std::unordered_map<std::string, std::unique_ptr<Response>> responses_; | 205 std::unordered_map<std::string, std::unique_ptr<Response>> responses_ |
| 206 GUARDED_BY(response_mutex_); |
| 205 | 207 |
| 206 // The default response for cache misses, if set. | 208 // The default response for cache misses, if set. |
| 207 std::unique_ptr<Response> default_response_; | 209 std::unique_ptr<Response> default_response_ GUARDED_BY(response_mutex_); |
| 208 | 210 |
| 209 // A map from request URL to associated server push responses (if any). | 211 // A map from request URL to associated server push responses (if any). |
| 210 std::multimap<std::string, ServerPushInfo> server_push_resources_; | 212 std::multimap<std::string, ServerPushInfo> server_push_resources_ |
| 213 GUARDED_BY(response_mutex_); |
| 211 | 214 |
| 212 // Protects against concurrent access from test threads setting responses, and | 215 // Protects against concurrent access from test threads setting responses, and |
| 213 // server threads accessing those responses. | 216 // server threads accessing those responses. |
| 214 mutable base::Lock response_mutex_; | 217 mutable QuicMutex response_mutex_; |
| 215 | 218 |
| 216 DISALLOW_COPY_AND_ASSIGN(QuicHttpResponseCache); | 219 DISALLOW_COPY_AND_ASSIGN(QuicHttpResponseCache); |
| 217 }; | 220 }; |
| 218 | 221 |
| 219 } // namespace net | 222 } // namespace net |
| 220 | 223 |
| 221 #endif // NET_TOOLS_QUIC_QUIC_IN_MEMORY_CACHE_H_ | 224 #endif // NET_TOOLS_QUIC_QUIC_IN_MEMORY_CACHE_H_ |
| OLD | NEW |