| 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 | 10 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 }; | 59 }; |
| 60 | 60 |
| 61 // Container for response header/body pairs. | 61 // Container for response header/body pairs. |
| 62 class Response { | 62 class Response { |
| 63 public: | 63 public: |
| 64 Response(); | 64 Response(); |
| 65 ~Response(); | 65 ~Response(); |
| 66 | 66 |
| 67 SpecialResponseType response_type() const { return response_type_; } | 67 SpecialResponseType response_type() const { return response_type_; } |
| 68 const SpdyHeaderBlock& headers() const { return headers_; } | 68 const SpdyHeaderBlock& headers() const { return headers_; } |
| 69 const SpdyHeaderBlock& trailers() const { return trailers_; } |
| 69 const base::StringPiece body() const { return base::StringPiece(body_); } | 70 const base::StringPiece body() const { return base::StringPiece(body_); } |
| 70 | 71 |
| 71 void set_response_type(SpecialResponseType response_type) { | 72 void set_response_type(SpecialResponseType response_type) { |
| 72 response_type_ = response_type; | 73 response_type_ = response_type; |
| 73 } | 74 } |
| 74 void set_headers(const SpdyHeaderBlock& headers) { | 75 void set_headers(const SpdyHeaderBlock& headers) { |
| 75 headers_ = headers; | 76 headers_ = headers; |
| 76 } | 77 } |
| 78 void set_trailers(const SpdyHeaderBlock& trailers) { trailers_ = trailers; } |
| 77 void set_body(base::StringPiece body) { | 79 void set_body(base::StringPiece body) { |
| 78 body.CopyToString(&body_); | 80 body.CopyToString(&body_); |
| 79 } | 81 } |
| 80 | 82 |
| 81 private: | 83 private: |
| 82 SpecialResponseType response_type_; | 84 SpecialResponseType response_type_; |
| 83 SpdyHeaderBlock headers_; | 85 SpdyHeaderBlock headers_; |
| 84 string body_; | 86 SpdyHeaderBlock trailers_; |
| 87 std::string body_; |
| 85 | 88 |
| 86 DISALLOW_COPY_AND_ASSIGN(Response); | 89 DISALLOW_COPY_AND_ASSIGN(Response); |
| 87 }; | 90 }; |
| 88 | 91 |
| 89 // Returns the singleton instance of the cache. | 92 // Returns the singleton instance of the cache. |
| 90 static QuicInMemoryCache* GetInstance(); | 93 static QuicInMemoryCache* GetInstance(); |
| 91 | 94 |
| 92 // Retrieve a response from this cache for a given host and path.. | 95 // Retrieve a response from this cache for a given host and path.. |
| 93 // If no appropriate response exists, nullptr is returned. | 96 // If no appropriate response exists, nullptr is returned. |
| 94 const Response* GetResponse(base::StringPiece host, | 97 const Response* GetResponse(base::StringPiece host, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 111 int response_code, | 114 int response_code, |
| 112 StringPiece body, | 115 StringPiece body, |
| 113 list<ServerPushInfo> push_resources); | 116 list<ServerPushInfo> push_resources); |
| 114 | 117 |
| 115 // Add a response to the cache. | 118 // Add a response to the cache. |
| 116 void AddResponse(base::StringPiece host, | 119 void AddResponse(base::StringPiece host, |
| 117 base::StringPiece path, | 120 base::StringPiece path, |
| 118 const SpdyHeaderBlock& response_headers, | 121 const SpdyHeaderBlock& response_headers, |
| 119 base::StringPiece response_body); | 122 base::StringPiece response_body); |
| 120 | 123 |
| 124 // Add a response, with trailers, to the cache. |
| 125 void AddResponse(base::StringPiece host, |
| 126 base::StringPiece path, |
| 127 const SpdyHeaderBlock& response_headers, |
| 128 base::StringPiece response_body, |
| 129 const SpdyHeaderBlock& response_trailers); |
| 130 |
| 121 // Simulate a special behavior at a particular path. | 131 // Simulate a special behavior at a particular path. |
| 122 void AddSpecialResponse(base::StringPiece host, | 132 void AddSpecialResponse(base::StringPiece host, |
| 123 base::StringPiece path, | 133 base::StringPiece path, |
| 124 SpecialResponseType response_type); | 134 SpecialResponseType response_type); |
| 125 | 135 |
| 126 // Sets a default response in case of cache misses. Takes ownership of | 136 // Sets a default response in case of cache misses. Takes ownership of |
| 127 // 'response'. | 137 // 'response'. |
| 128 void AddDefaultResponse(Response* response); | 138 void AddDefaultResponse(Response* response); |
| 129 | 139 |
| 130 // |cache_cirectory| can be generated using `wget -p --save-headers <url>`. | 140 // |cache_cirectory| can be generated using `wget -p --save-headers <url>`. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 141 | 151 |
| 142 QuicInMemoryCache(); | 152 QuicInMemoryCache(); |
| 143 ~QuicInMemoryCache(); | 153 ~QuicInMemoryCache(); |
| 144 | 154 |
| 145 void ResetForTests(); | 155 void ResetForTests(); |
| 146 | 156 |
| 147 void AddResponseImpl(base::StringPiece host, | 157 void AddResponseImpl(base::StringPiece host, |
| 148 base::StringPiece path, | 158 base::StringPiece path, |
| 149 SpecialResponseType response_type, | 159 SpecialResponseType response_type, |
| 150 const SpdyHeaderBlock& response_headers, | 160 const SpdyHeaderBlock& response_headers, |
| 151 base::StringPiece response_body); | 161 base::StringPiece response_body, |
| 162 const SpdyHeaderBlock& response_trailers); |
| 152 | 163 |
| 153 string GetKey(base::StringPiece host, base::StringPiece path) const; | 164 string GetKey(base::StringPiece host, base::StringPiece path) const; |
| 154 | 165 |
| 155 // Add some server push urls with given responses for specified | 166 // Add some server push urls with given responses for specified |
| 156 // request if these push resources are not associated with this request yet. | 167 // request if these push resources are not associated with this request yet. |
| 157 void MaybeAddServerPushResources(StringPiece request_host, | 168 void MaybeAddServerPushResources(StringPiece request_host, |
| 158 StringPiece request_path, | 169 StringPiece request_path, |
| 159 list<ServerPushInfo> push_resources); | 170 list<ServerPushInfo> push_resources); |
| 160 | 171 |
| 161 // Check if push resource(push_host/push_path) associated with given request | 172 // Check if push resource(push_host/push_path) associated with given request |
| (...skipping 10 matching lines...) Expand all Loading... |
| 172 // A map from request URL to associated server push responses (if any). | 183 // A map from request URL to associated server push responses (if any). |
| 173 std::multimap<string, ServerPushInfo> server_push_resources_; | 184 std::multimap<string, ServerPushInfo> server_push_resources_; |
| 174 | 185 |
| 175 DISALLOW_COPY_AND_ASSIGN(QuicInMemoryCache); | 186 DISALLOW_COPY_AND_ASSIGN(QuicInMemoryCache); |
| 176 }; | 187 }; |
| 177 | 188 |
| 178 } // namespace tools | 189 } // namespace tools |
| 179 } // namespace net | 190 } // namespace net |
| 180 | 191 |
| 181 #endif // NET_TOOLS_QUIC_QUIC_IN_MEMORY_CACHE_H_ | 192 #endif // NET_TOOLS_QUIC_QUIC_IN_MEMORY_CACHE_H_ |
| OLD | NEW |