Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_QUIC_QUIC_IN_MEMORY_CACHE_H_ | 5 #ifndef NET_QUIC_QUIC_IN_MEMORY_CACHE_H_ |
| 6 #define NET_QUIC_QUIC_IN_MEMORY_CACHE_H_ | 6 #define NET_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/file_util.h" | 11 #include "base/file_util.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
| 14 #include "net/http/http_response_headers.h" | 14 #include "net/http/http_response_headers.h" |
| 15 | 15 |
| 16 template <typename T> struct DefaultSingletonTraits; | 16 template <typename T> struct DefaultSingletonTraits; |
| 17 class GURL; | 17 class GURL; |
| 18 | 18 |
| 19 namespace net { | 19 namespace net { |
| 20 | 20 |
| 21 extern base::FilePath::StringType g_quic_in_memory_cache_dir; | 21 NET_EXPORT_PRIVATE extern base::FilePath::StringType* |
|
wtc
2014/07/02 19:39:08
The order probably doesn't matter, but please put
| |
| 22 g_quic_in_memory_cache_dir; | |
| 22 | 23 |
| 23 namespace test { | 24 namespace test { |
| 24 class QuicInMemoryCachePeer; | 25 class QuicInMemoryCachePeer; |
| 25 } // namespace | 26 } // namespace |
| 26 | 27 |
| 27 class QuicServer; | 28 class QuicServer; |
| 28 | 29 |
| 29 // In-memory cache for HTTP responses. | 30 // In-memory cache for HTTP responses. |
| 30 // Reads from disk cache generated by: | 31 // Reads from disk cache generated by: |
| 31 // `wget -p --save_headers <url>` | 32 // `wget -p --save_headers <url>` |
| 32 class QuicInMemoryCache { | 33 class QuicInMemoryCache { |
| 33 public: | 34 public: |
| 34 enum SpecialResponseType { | 35 enum SpecialResponseType { |
| 35 REGULAR_RESPONSE, // Send the headers and body like a server should. | 36 REGULAR_RESPONSE, // Send the headers and body like a server should. |
| 36 CLOSE_CONNECTION, // Close the connection (sending the close packet). | 37 CLOSE_CONNECTION, // Close the connection (sending the close packet). |
| 37 IGNORE_REQUEST, // Do nothing, expect the client to time out. | 38 IGNORE_REQUEST, // Do nothing, expect the client to time out. |
| 38 }; | 39 }; |
| 39 | 40 |
| 40 // Container for response header/body pairs. | 41 // Container for response header/body pairs. |
| 41 class Response { | 42 class Response { |
| 42 public: | 43 public: |
| 43 Response(); | 44 Response(); |
| 44 ~Response(); | 45 ~Response(); |
| 45 | 46 |
| 46 SpecialResponseType response_type() const { return response_type_; } | 47 SpecialResponseType response_type() const { return response_type_; } |
| 47 const HttpResponseHeaders& headers() const { return *headers_; } | 48 const HttpResponseHeaders* headers() const { return headers_.get(); } |
| 48 const base::StringPiece body() const { return base::StringPiece(body_); } | 49 const base::StringPiece body() const { return base::StringPiece(body_); } |
| 49 | 50 |
| 50 private: | 51 private: |
| 51 friend class QuicInMemoryCache; | 52 friend class QuicInMemoryCache; |
| 52 | 53 |
| 53 void set_headers(scoped_refptr<HttpResponseHeaders> headers) { | 54 void set_headers(scoped_refptr<HttpResponseHeaders> headers) { |
| 54 headers_ = headers; | 55 headers_ = headers; |
| 55 } | 56 } |
| 56 void set_body(base::StringPiece body) { | 57 void set_body(base::StringPiece body) { |
| 57 body.CopyToString(&body_); | 58 body.CopyToString(&body_); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 | 106 |
| 106 // Cached responses. | 107 // Cached responses. |
| 107 ResponseMap responses_; | 108 ResponseMap responses_; |
| 108 | 109 |
| 109 DISALLOW_COPY_AND_ASSIGN(QuicInMemoryCache); | 110 DISALLOW_COPY_AND_ASSIGN(QuicInMemoryCache); |
| 110 }; | 111 }; |
| 111 | 112 |
| 112 } // namespace net | 113 } // namespace net |
| 113 | 114 |
| 114 #endif // NET_QUIC_QUIC_IN_MEMORY_CACHE_H_ | 115 #endif // NET_QUIC_QUIC_IN_MEMORY_CACHE_H_ |
| OLD | NEW |