Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(368)

Side by Side Diff: net/tools/quic/quic_in_memory_cache.h

Issue 1819853003: QUIC - extend QuicInMemoryCache so that simple server can do server push. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix asan detected bug Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/quic_flags.cc ('k') | net/tools/quic/quic_in_memory_cache.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include <unordered_map> 10 #include <unordered_map>
11 11
12 #include "base/containers/hash_tables.h" 12 #include "base/containers/hash_tables.h"
13 #include "base/files/file_path.h"
13 #include "base/macros.h" 14 #include "base/macros.h"
14 #include "base/memory/singleton.h" 15 #include "base/memory/singleton.h"
15 #include "base/strings/string_piece.h" 16 #include "base/strings/string_piece.h"
17 #include "net/http/http_response_headers.h"
16 #include "net/quic/spdy_utils.h" 18 #include "net/quic/spdy_utils.h"
17 #include "net/spdy/spdy_framer.h" 19 #include "net/spdy/spdy_framer.h"
18 #include "url/gurl.h" 20 #include "url/gurl.h"
19 21
20 using base::StringPiece; 22 using base::StringPiece;
21 using std::string; 23 using std::string;
22 using std::list; 24 using std::list;
23 25
24 namespace base { 26 namespace base {
25 27
(...skipping 12 matching lines...) Expand all
38 40
39 // In-memory cache for HTTP responses. 41 // In-memory cache for HTTP responses.
40 // Reads from disk cache generated by: 42 // Reads from disk cache generated by:
41 // `wget -p --save_headers <url>` 43 // `wget -p --save_headers <url>`
42 class QuicInMemoryCache { 44 class QuicInMemoryCache {
43 public: 45 public:
44 // A ServerPushInfo contains path of the push request and everything needed in 46 // A ServerPushInfo contains path of the push request and everything needed in
45 // comprising a response for the push request. 47 // comprising a response for the push request.
46 struct ServerPushInfo { 48 struct ServerPushInfo {
47 ServerPushInfo(GURL request_url, 49 ServerPushInfo(GURL request_url,
48 const net::SpdyHeaderBlock& headers, 50 const SpdyHeaderBlock& headers,
49 net::SpdyPriority priority, 51 SpdyPriority priority,
50 string body); 52 string body);
51 ServerPushInfo(const ServerPushInfo& other); 53 ServerPushInfo(const ServerPushInfo& other);
52 GURL request_url; 54 GURL request_url;
53 net::SpdyHeaderBlock headers; 55 SpdyHeaderBlock headers;
54 net::SpdyPriority priority; 56 SpdyPriority priority;
55 string body; 57 string body;
56 }; 58 };
57 59
58 enum SpecialResponseType { 60 enum SpecialResponseType {
59 REGULAR_RESPONSE, // Send the headers and body like a server should. 61 REGULAR_RESPONSE, // Send the headers and body like a server should.
60 CLOSE_CONNECTION, // Close the connection (sending the close packet). 62 CLOSE_CONNECTION, // Close the connection (sending the close packet).
61 IGNORE_REQUEST, // Do nothing, expect the client to time out. 63 IGNORE_REQUEST, // Do nothing, expect the client to time out.
62 }; 64 };
63 65
64 // Container for response header/body pairs. 66 // Container for response header/body pairs.
(...skipping 16 matching lines...) Expand all
81 83
82 private: 84 private:
83 SpecialResponseType response_type_; 85 SpecialResponseType response_type_;
84 SpdyHeaderBlock headers_; 86 SpdyHeaderBlock headers_;
85 SpdyHeaderBlock trailers_; 87 SpdyHeaderBlock trailers_;
86 std::string body_; 88 std::string body_;
87 89
88 DISALLOW_COPY_AND_ASSIGN(Response); 90 DISALLOW_COPY_AND_ASSIGN(Response);
89 }; 91 };
90 92
93 // Class to manage loading a resource file into memory. There are
94 // two uses: called by InitializeFromDirectory to load resources
95 // from files, and recursively called when said resources specify
96 // server push associations.
97 class ResourceFile {
98 public:
99 explicit ResourceFile(const base::FilePath& file_name);
100 virtual ~ResourceFile();
101
102 // abstract: implementation details are chromium and internal
103 // version specific.
104 virtual void Read() = 0;
105 void SetHostPathFromBase(base::StringPiece base);
106
107 StringPiece host() { return host_; }
108 void set_host(base::StringPiece host) { host_ = host; }
109
110 StringPiece path() { return path_; }
111 void set_path(base::StringPiece path) { path_ = path; }
112
113 SpdyHeaderBlock spdy_headers() { return spdy_headers_; }
114
115 StringPiece body() { return body_; }
116
117 const std::vector<base::StringPiece>& push_urls() { return push_urls_; }
118
119 const std::string& file_name() { return file_name_string_; }
120
121 protected:
122 void HandleXOriginalUrl();
123 void HandlePushUrls(const std::vector<base::StringPiece>& push_urls);
124 StringPiece RemoveScheme(base::StringPiece url);
125
126 const string cache_directory_;
127 const base::FilePath file_name_;
128 const std::string file_name_string_;
129 string file_contents_;
130 base::StringPiece body_;
131 SpdyHeaderBlock spdy_headers_;
132 base::StringPiece x_original_url_;
133 std::vector<base::StringPiece> push_urls_;
134
135 private:
136 base::StringPiece host_;
137 base::StringPiece path_;
138 QuicInMemoryCache* cache_;
139
140 DISALLOW_COPY_AND_ASSIGN(ResourceFile);
141 };
142
91 // Returns the singleton instance of the cache. 143 // Returns the singleton instance of the cache.
92 static QuicInMemoryCache* GetInstance(); 144 static QuicInMemoryCache* GetInstance();
93 145
94 // Retrieve a response from this cache for a given host and path.. 146 // Retrieve a response from this cache for a given host and path..
95 // If no appropriate response exists, nullptr is returned. 147 // If no appropriate response exists, nullptr is returned.
96 const Response* GetResponse(base::StringPiece host, 148 const Response* GetResponse(base::StringPiece host,
97 base::StringPiece path) const; 149 base::StringPiece path) const;
98 150
99 // Adds a simple response to the cache. The response headers will 151 // Adds a simple response to the cache. The response headers will
100 // only contain the "content-length" header with the length of |body|. 152 // only contain the "content-length" header with the length of |body|.
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
181 233
182 // A map from request URL to associated server push responses (if any). 234 // A map from request URL to associated server push responses (if any).
183 std::multimap<string, ServerPushInfo> server_push_resources_; 235 std::multimap<string, ServerPushInfo> server_push_resources_;
184 236
185 DISALLOW_COPY_AND_ASSIGN(QuicInMemoryCache); 237 DISALLOW_COPY_AND_ASSIGN(QuicInMemoryCache);
186 }; 238 };
187 239
188 } // namespace net 240 } // namespace net
189 241
190 #endif // NET_TOOLS_QUIC_QUIC_IN_MEMORY_CACHE_H_ 242 #endif // NET_TOOLS_QUIC_QUIC_IN_MEMORY_CACHE_H_
OLDNEW
« no previous file with comments | « net/quic/quic_flags.cc ('k') | net/tools/quic/quic_in_memory_cache.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698