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 template <typename T> struct DefaultSingletonTraits; | 15 template <typename T> struct DefaultSingletonTraits; |
16 | 16 |
17 namespace net { | 17 namespace net { |
18 namespace tools { | 18 namespace tools { |
19 | 19 |
20 namespace test { | 20 namespace test { |
21 class QuicInMemoryCachePeer; | 21 class QuicInMemoryCachePeer; |
22 } // namespace | 22 } // namespace |
23 | 23 |
24 extern std::string FLAGS_quic_in_memory_cache_dir; | |
25 | |
26 class QuicServer; | 24 class QuicServer; |
27 | 25 |
28 // In-memory cache for HTTP responses. | 26 // In-memory cache for HTTP responses. |
29 // Reads from disk cache generated by: | 27 // Reads from disk cache generated by: |
30 // `wget -p --save_headers <url>` | 28 // `wget -p --save_headers <url>` |
31 class QuicInMemoryCache { | 29 class QuicInMemoryCache { |
32 public: | 30 public: |
33 enum SpecialResponseType { | 31 enum SpecialResponseType { |
34 REGULAR_RESPONSE, // Send the headers and body like a server should. | 32 REGULAR_RESPONSE, // Send the headers and body like a server should. |
35 CLOSE_CONNECTION, // Close the connection (sending the close packet). | 33 CLOSE_CONNECTION, // Close the connection (sending the close packet). |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 void AddResponse(base::StringPiece host, | 84 void AddResponse(base::StringPiece host, |
87 base::StringPiece path, | 85 base::StringPiece path, |
88 const SpdyHeaderBlock& response_headers, | 86 const SpdyHeaderBlock& response_headers, |
89 base::StringPiece response_body); | 87 base::StringPiece response_body); |
90 | 88 |
91 // Simulate a special behavior at a particular path. | 89 // Simulate a special behavior at a particular path. |
92 void AddSpecialResponse(base::StringPiece host, | 90 void AddSpecialResponse(base::StringPiece host, |
93 base::StringPiece path, | 91 base::StringPiece path, |
94 SpecialResponseType response_type); | 92 SpecialResponseType response_type); |
95 | 93 |
| 94 // |cache_cirectory| can be generated using `wget -p --save-headers <url>`. |
| 95 void InitializeFromDirectory(const std::string& cache_directory); |
| 96 |
96 private: | 97 private: |
97 typedef base::hash_map<std::string, Response*> ResponseMap; | 98 typedef base::hash_map<std::string, Response*> ResponseMap; |
98 friend struct DefaultSingletonTraits<QuicInMemoryCache>; | 99 friend struct DefaultSingletonTraits<QuicInMemoryCache>; |
99 friend class test::QuicInMemoryCachePeer; | 100 friend class test::QuicInMemoryCachePeer; |
100 | 101 |
101 QuicInMemoryCache(); | 102 QuicInMemoryCache(); |
102 ~QuicInMemoryCache(); | 103 ~QuicInMemoryCache(); |
103 | 104 |
104 void ResetForTests(); | 105 void ResetForTests(); |
105 | 106 |
106 void Initialize(); | |
107 | |
108 void AddResponseImpl(base::StringPiece host, | 107 void AddResponseImpl(base::StringPiece host, |
109 base::StringPiece path, | 108 base::StringPiece path, |
110 SpecialResponseType response_type, | 109 SpecialResponseType response_type, |
111 const SpdyHeaderBlock& response_headers, | 110 const SpdyHeaderBlock& response_headers, |
112 base::StringPiece response_body); | 111 base::StringPiece response_body); |
113 | 112 |
114 std::string GetKey(base::StringPiece host, base::StringPiece path) const; | 113 std::string GetKey(base::StringPiece host, base::StringPiece path) const; |
115 | 114 |
116 // Cached responses. | 115 // Cached responses. |
117 ResponseMap responses_; | 116 ResponseMap responses_; |
118 | 117 |
119 DISALLOW_COPY_AND_ASSIGN(QuicInMemoryCache); | 118 DISALLOW_COPY_AND_ASSIGN(QuicInMemoryCache); |
120 }; | 119 }; |
121 | 120 |
122 } // namespace tools | 121 } // namespace tools |
123 } // namespace net | 122 } // namespace net |
124 | 123 |
125 #endif // NET_TOOLS_QUIC_QUIC_IN_MEMORY_CACHE_H_ | 124 #endif // NET_TOOLS_QUIC_QUIC_IN_MEMORY_CACHE_H_ |
OLD | NEW |