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 <string> | 8 #include <string> |
9 | 9 |
10 #include "base/containers/hash_tables.h" | 10 #include "base/containers/hash_tables.h" |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 | 51 |
52 DISALLOW_COPY_AND_ASSIGN(Response); | 52 DISALLOW_COPY_AND_ASSIGN(Response); |
53 }; | 53 }; |
54 static QuicInMemoryCache* GetInstance(); | 54 static QuicInMemoryCache* GetInstance(); |
55 | 55 |
56 // Retrieve a response from this cache for a given request. | 56 // Retrieve a response from this cache for a given request. |
57 // If no appropriate response exists, NULL is returned. | 57 // If no appropriate response exists, NULL is returned. |
58 // Currently, responses are selected based on request URI only. | 58 // Currently, responses are selected based on request URI only. |
59 const Response* GetResponse(const BalsaHeaders& request_headers) const; | 59 const Response* GetResponse(const BalsaHeaders& request_headers) const; |
60 | 60 |
| 61 // Adds a response to the cache if no matching entry exists. |
| 62 // Otherwise it verifies that the existing entry matches. |
| 63 void AddOrVerifyResponse(base::StringPiece method, |
| 64 base::StringPiece path, |
| 65 base::StringPiece version, |
| 66 base::StringPiece response_code, |
| 67 base::StringPiece response_detail, |
| 68 base::StringPiece body); |
| 69 |
61 // Add a response to the cache. | 70 // Add a response to the cache. |
62 void AddResponse(const BalsaHeaders& request_headers, | 71 void AddResponse(const BalsaHeaders& request_headers, |
63 const BalsaHeaders& response_headers, | 72 const BalsaHeaders& response_headers, |
64 base::StringPiece response_body); | 73 base::StringPiece response_body); |
65 | 74 |
66 void ResetForTests(); | 75 void ResetForTests(); |
67 | 76 |
68 private: | 77 private: |
69 typedef base::hash_map<std::string, Response*> ResponseMap; | 78 typedef base::hash_map<std::string, Response*> ResponseMap; |
70 | 79 friend struct DefaultSingletonTraits<QuicInMemoryCache>; |
71 | 80 |
72 QuicInMemoryCache(); | 81 QuicInMemoryCache(); |
73 friend struct DefaultSingletonTraits<QuicInMemoryCache>; | |
74 ~QuicInMemoryCache(); | 82 ~QuicInMemoryCache(); |
75 | 83 |
76 void Initialize(); | 84 void Initialize(); |
77 std::string GetKey(const BalsaHeaders& response_headers) const; | 85 std::string GetKey(const BalsaHeaders& response_headers) const; |
78 | 86 |
79 // Cached responses. | 87 // Cached responses. |
80 ResponseMap responses_; | 88 ResponseMap responses_; |
81 | 89 |
82 DISALLOW_COPY_AND_ASSIGN(QuicInMemoryCache); | 90 DISALLOW_COPY_AND_ASSIGN(QuicInMemoryCache); |
83 }; | 91 }; |
84 | 92 |
85 } // namespace tools | 93 } // namespace tools |
86 } // namespace net | 94 } // namespace net |
87 | 95 |
88 #endif // NET_TOOLS_QUIC_QUIC_IN_MEMORY_CACHE_H_ | 96 #endif // NET_TOOLS_QUIC_QUIC_IN_MEMORY_CACHE_H_ |
OLD | NEW |