| 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 <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <unordered_map> |
| 10 | 11 |
| 11 #include "base/containers/hash_tables.h" | 12 #include "base/containers/hash_tables.h" |
| 12 #include "base/macros.h" | 13 #include "base/macros.h" |
| 13 #include "base/memory/singleton.h" | 14 #include "base/memory/singleton.h" |
| 14 #include "base/strings/string_piece.h" | 15 #include "base/strings/string_piece.h" |
| 15 #include "net/quic/spdy_utils.h" | 16 #include "net/quic/spdy_utils.h" |
| 16 #include "net/spdy/spdy_framer.h" | 17 #include "net/spdy/spdy_framer.h" |
| 17 #include "url/gurl.h" | 18 #include "url/gurl.h" |
| 18 | 19 |
| 19 using base::StringPiece; | 20 using base::StringPiece; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 void AddSimpleResponse(base::StringPiece host, | 100 void AddSimpleResponse(base::StringPiece host, |
| 100 base::StringPiece path, | 101 base::StringPiece path, |
| 101 int response_code, | 102 int response_code, |
| 102 base::StringPiece body); | 103 base::StringPiece body); |
| 103 | 104 |
| 104 // Add a simple response to the cache as AddSimpleResponse() does, and add | 105 // Add a simple response to the cache as AddSimpleResponse() does, and add |
| 105 // some server push resources(resource path, corresponding response status and | 106 // some server push resources(resource path, corresponding response status and |
| 106 // path) associated with it. | 107 // path) associated with it. |
| 107 // Push resource implicitly come from the same host. | 108 // Push resource implicitly come from the same host. |
| 108 void AddSimpleResponseWithServerPushResources( | 109 void AddSimpleResponseWithServerPushResources( |
| 109 StringPiece host, | 110 base::StringPiece host, |
| 110 StringPiece path, | 111 base::StringPiece path, |
| 111 int response_code, | 112 int response_code, |
| 112 StringPiece body, | 113 base::StringPiece body, |
| 113 list<ServerPushInfo> push_resources); | 114 std::list<ServerPushInfo> push_resources); |
| 114 | 115 |
| 115 // Add a response to the cache. | 116 // Add a response to the cache. |
| 116 void AddResponse(base::StringPiece host, | 117 void AddResponse(base::StringPiece host, |
| 117 base::StringPiece path, | 118 base::StringPiece path, |
| 118 const SpdyHeaderBlock& response_headers, | 119 const SpdyHeaderBlock& response_headers, |
| 119 base::StringPiece response_body); | 120 base::StringPiece response_body); |
| 120 | 121 |
| 121 // Add a response, with trailers, to the cache. | 122 // Add a response, with trailers, to the cache. |
| 122 void AddResponse(base::StringPiece host, | 123 void AddResponse(base::StringPiece host, |
| 123 base::StringPiece path, | 124 base::StringPiece path, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 134 // 'response'. | 135 // 'response'. |
| 135 void AddDefaultResponse(Response* response); | 136 void AddDefaultResponse(Response* response); |
| 136 | 137 |
| 137 // |cache_cirectory| can be generated using `wget -p --save-headers <url>`. | 138 // |cache_cirectory| can be generated using `wget -p --save-headers <url>`. |
| 138 void InitializeFromDirectory(const string& cache_directory); | 139 void InitializeFromDirectory(const string& cache_directory); |
| 139 | 140 |
| 140 // Find all the server push resources associated with |request_url|. | 141 // Find all the server push resources associated with |request_url|. |
| 141 list<ServerPushInfo> GetServerPushResources(string request_url); | 142 list<ServerPushInfo> GetServerPushResources(string request_url); |
| 142 | 143 |
| 143 private: | 144 private: |
| 144 typedef base::hash_map<string, Response*> ResponseMap; | 145 typedef std::unordered_map<std::string, Response*> ResponseMap; |
| 145 | 146 |
| 146 friend struct base::DefaultSingletonTraits<QuicInMemoryCache>; | 147 friend struct base::DefaultSingletonTraits<QuicInMemoryCache>; |
| 147 friend class test::QuicInMemoryCachePeer; | 148 friend class test::QuicInMemoryCachePeer; |
| 148 | 149 |
| 149 QuicInMemoryCache(); | 150 QuicInMemoryCache(); |
| 150 ~QuicInMemoryCache(); | 151 ~QuicInMemoryCache(); |
| 151 | 152 |
| 152 void ResetForTests(); | 153 void ResetForTests(); |
| 153 | 154 |
| 154 void AddResponseImpl(base::StringPiece host, | 155 void AddResponseImpl(base::StringPiece host, |
| 155 base::StringPiece path, | 156 base::StringPiece path, |
| 156 SpecialResponseType response_type, | 157 SpecialResponseType response_type, |
| 157 const SpdyHeaderBlock& response_headers, | 158 const SpdyHeaderBlock& response_headers, |
| 158 base::StringPiece response_body, | 159 base::StringPiece response_body, |
| 159 const SpdyHeaderBlock& response_trailers); | 160 const SpdyHeaderBlock& response_trailers); |
| 160 | 161 |
| 161 string GetKey(base::StringPiece host, base::StringPiece path) const; | 162 string GetKey(base::StringPiece host, base::StringPiece path) const; |
| 162 | 163 |
| 163 // Add some server push urls with given responses for specified | 164 // Add some server push urls with given responses for specified |
| 164 // request if these push resources are not associated with this request yet. | 165 // request if these push resources are not associated with this request yet. |
| 165 void MaybeAddServerPushResources(StringPiece request_host, | 166 void MaybeAddServerPushResources(base::StringPiece request_host, |
| 166 StringPiece request_path, | 167 base::StringPiece request_path, |
| 167 list<ServerPushInfo> push_resources); | 168 std::list<ServerPushInfo> push_resources); |
| 168 | 169 |
| 169 // Check if push resource(push_host/push_path) associated with given request | 170 // Check if push resource(push_host/push_path) associated with given request |
| 170 // url already exists in server push map. | 171 // url already exists in server push map. |
| 171 bool PushResourceExistsInCache(string original_request_url, | 172 bool PushResourceExistsInCache(string original_request_url, |
| 172 ServerPushInfo resource); | 173 ServerPushInfo resource); |
| 173 | 174 |
| 174 // Cached responses. | 175 // Cached responses. |
| 175 ResponseMap responses_; | 176 ResponseMap responses_; |
| 176 | 177 |
| 177 // The default response for cache misses, if set. | 178 // The default response for cache misses, if set. |
| 178 scoped_ptr<Response> default_response_; | 179 scoped_ptr<Response> default_response_; |
| 179 | 180 |
| 180 // A map from request URL to associated server push responses (if any). | 181 // A map from request URL to associated server push responses (if any). |
| 181 std::multimap<string, ServerPushInfo> server_push_resources_; | 182 std::multimap<string, ServerPushInfo> server_push_resources_; |
| 182 | 183 |
| 183 DISALLOW_COPY_AND_ASSIGN(QuicInMemoryCache); | 184 DISALLOW_COPY_AND_ASSIGN(QuicInMemoryCache); |
| 184 }; | 185 }; |
| 185 | 186 |
| 186 } // namespace net | 187 } // namespace net |
| 187 | 188 |
| 188 #endif // NET_TOOLS_QUIC_QUIC_IN_MEMORY_CACHE_H_ | 189 #endif // NET_TOOLS_QUIC_QUIC_IN_MEMORY_CACHE_H_ |
| OLD | NEW |