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" |
11 #include "base/memory/singleton.h" | 11 #include "base/memory/singleton.h" |
12 #include "base/strings/string_piece.h" | 12 #include "base/strings/string_piece.h" |
13 #include "net/spdy/spdy_framer.h" | 13 #include "net/spdy/spdy_framer.h" |
14 | 14 |
| 15 namespace base { |
| 16 |
15 template <typename Type> struct DefaultSingletonTraits; | 17 template <typename Type> struct DefaultSingletonTraits; |
16 | 18 |
| 19 } // namespace base |
| 20 |
17 namespace net { | 21 namespace net { |
18 namespace tools { | 22 namespace tools { |
19 | 23 |
20 namespace test { | 24 namespace test { |
21 class QuicInMemoryCachePeer; | 25 class QuicInMemoryCachePeer; |
22 } // namespace test | 26 } // namespace test |
23 | 27 |
24 class QuicServer; | 28 class QuicServer; |
25 | 29 |
26 // In-memory cache for HTTP responses. | 30 // In-memory cache for HTTP responses. |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 // Sets a default response in case of cache misses. Takes ownership of | 96 // Sets a default response in case of cache misses. Takes ownership of |
93 // 'response'. | 97 // 'response'. |
94 void AddDefaultResponse(Response* response); | 98 void AddDefaultResponse(Response* response); |
95 | 99 |
96 // |cache_cirectory| can be generated using `wget -p --save-headers <url>`. | 100 // |cache_cirectory| can be generated using `wget -p --save-headers <url>`. |
97 void InitializeFromDirectory(const std::string& cache_directory); | 101 void InitializeFromDirectory(const std::string& cache_directory); |
98 | 102 |
99 private: | 103 private: |
100 typedef base::hash_map<std::string, Response*> ResponseMap; | 104 typedef base::hash_map<std::string, Response*> ResponseMap; |
101 | 105 |
102 friend struct DefaultSingletonTraits<QuicInMemoryCache>; | 106 friend struct base::DefaultSingletonTraits<QuicInMemoryCache>; |
103 friend class test::QuicInMemoryCachePeer; | 107 friend class test::QuicInMemoryCachePeer; |
104 | 108 |
105 QuicInMemoryCache(); | 109 QuicInMemoryCache(); |
106 ~QuicInMemoryCache(); | 110 ~QuicInMemoryCache(); |
107 | 111 |
108 void ResetForTests(); | 112 void ResetForTests(); |
109 | 113 |
110 void AddResponseImpl(base::StringPiece host, | 114 void AddResponseImpl(base::StringPiece host, |
111 base::StringPiece path, | 115 base::StringPiece path, |
112 SpecialResponseType response_type, | 116 SpecialResponseType response_type, |
113 const SpdyHeaderBlock& response_headers, | 117 const SpdyHeaderBlock& response_headers, |
114 base::StringPiece response_body); | 118 base::StringPiece response_body); |
115 | 119 |
116 std::string GetKey(base::StringPiece host, base::StringPiece path) const; | 120 std::string GetKey(base::StringPiece host, base::StringPiece path) const; |
117 | 121 |
118 // Cached responses. | 122 // Cached responses. |
119 ResponseMap responses_; | 123 ResponseMap responses_; |
120 | 124 |
121 // The default response for cache misses, if set. | 125 // The default response for cache misses, if set. |
122 scoped_ptr<Response> default_response_; | 126 scoped_ptr<Response> default_response_; |
123 | 127 |
124 DISALLOW_COPY_AND_ASSIGN(QuicInMemoryCache); | 128 DISALLOW_COPY_AND_ASSIGN(QuicInMemoryCache); |
125 }; | 129 }; |
126 | 130 |
127 } // namespace tools | 131 } // namespace tools |
128 } // namespace net | 132 } // namespace net |
129 | 133 |
130 #endif // NET_TOOLS_QUIC_QUIC_IN_MEMORY_CACHE_H_ | 134 #endif // NET_TOOLS_QUIC_QUIC_IN_MEMORY_CACHE_H_ |
OLD | NEW |