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> |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 // 'response'. | 188 // 'response'. |
189 void AddDefaultResponse(Response* response); | 189 void AddDefaultResponse(Response* response); |
190 | 190 |
191 // |cache_cirectory| can be generated using `wget -p --save-headers <url>`. | 191 // |cache_cirectory| can be generated using `wget -p --save-headers <url>`. |
192 void InitializeFromDirectory(const std::string& cache_directory); | 192 void InitializeFromDirectory(const std::string& cache_directory); |
193 | 193 |
194 // Find all the server push resources associated with |request_url|. | 194 // Find all the server push resources associated with |request_url|. |
195 std::list<ServerPushInfo> GetServerPushResources(std::string request_url); | 195 std::list<ServerPushInfo> GetServerPushResources(std::string request_url); |
196 | 196 |
197 private: | 197 private: |
198 typedef std::unordered_map<std::string, Response*> ResponseMap; | |
199 | |
200 friend struct base::DefaultSingletonTraits<QuicInMemoryCache>; | 198 friend struct base::DefaultSingletonTraits<QuicInMemoryCache>; |
201 friend class test::QuicInMemoryCachePeer; | 199 friend class test::QuicInMemoryCachePeer; |
202 | 200 |
203 QuicInMemoryCache(); | 201 QuicInMemoryCache(); |
204 ~QuicInMemoryCache(); | 202 ~QuicInMemoryCache(); |
205 | 203 |
206 void ResetForTests(); | 204 void ResetForTests(); |
207 | 205 |
208 void AddResponseImpl(base::StringPiece host, | 206 void AddResponseImpl(base::StringPiece host, |
209 base::StringPiece path, | 207 base::StringPiece path, |
210 SpecialResponseType response_type, | 208 SpecialResponseType response_type, |
211 SpdyHeaderBlock response_headers, | 209 SpdyHeaderBlock response_headers, |
212 base::StringPiece response_body, | 210 base::StringPiece response_body, |
213 SpdyHeaderBlock response_trailers); | 211 SpdyHeaderBlock response_trailers); |
214 | 212 |
215 std::string GetKey(base::StringPiece host, base::StringPiece path) const; | 213 std::string GetKey(base::StringPiece host, base::StringPiece path) const; |
216 | 214 |
217 // Add some server push urls with given responses for specified | 215 // Add some server push urls with given responses for specified |
218 // request if these push resources are not associated with this request yet. | 216 // request if these push resources are not associated with this request yet. |
219 void MaybeAddServerPushResources(base::StringPiece request_host, | 217 void MaybeAddServerPushResources(base::StringPiece request_host, |
220 base::StringPiece request_path, | 218 base::StringPiece request_path, |
221 std::list<ServerPushInfo> push_resources); | 219 std::list<ServerPushInfo> push_resources); |
222 | 220 |
223 // Check if push resource(push_host/push_path) associated with given request | 221 // Check if push resource(push_host/push_path) associated with given request |
224 // url already exists in server push map. | 222 // url already exists in server push map. |
225 bool PushResourceExistsInCache(std::string original_request_url, | 223 bool PushResourceExistsInCache(std::string original_request_url, |
226 ServerPushInfo resource); | 224 ServerPushInfo resource); |
227 | 225 |
228 // Cached responses. | 226 // Cached responses. |
229 ResponseMap responses_; | 227 std::unordered_map<std::string, std::unique_ptr<Response>> responses_; |
230 | 228 |
231 // The default response for cache misses, if set. | 229 // The default response for cache misses, if set. |
232 std::unique_ptr<Response> default_response_; | 230 std::unique_ptr<Response> default_response_; |
233 | 231 |
234 // A map from request URL to associated server push responses (if any). | 232 // A map from request URL to associated server push responses (if any). |
235 std::multimap<std::string, ServerPushInfo> server_push_resources_; | 233 std::multimap<std::string, ServerPushInfo> server_push_resources_; |
236 | 234 |
237 // Protects against concurrent access from test threads setting responses, and | 235 // Protects against concurrent access from test threads setting responses, and |
238 // server threads accessing those responses. | 236 // server threads accessing those responses. |
239 mutable base::Lock response_mutex_; | 237 mutable base::Lock response_mutex_; |
240 | 238 |
241 DISALLOW_COPY_AND_ASSIGN(QuicInMemoryCache); | 239 DISALLOW_COPY_AND_ASSIGN(QuicInMemoryCache); |
242 }; | 240 }; |
243 | 241 |
244 } // namespace net | 242 } // namespace net |
245 | 243 |
246 #endif // NET_TOOLS_QUIC_QUIC_IN_MEMORY_CACHE_H_ | 244 #endif // NET_TOOLS_QUIC_QUIC_IN_MEMORY_CACHE_H_ |
OLD | NEW |