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 #include "net/tools/quic/quic_in_memory_cache.h" | 5 #include "net/tools/quic/quic_in_memory_cache.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
9 | 9 |
10 using base::FilePath; | 10 using base::FilePath; |
11 using base::StringPiece; | 11 using base::StringPiece; |
12 using file_util::FileEnumerator; | 12 using file_util::FileEnumerator; |
13 using std::string; | 13 using std::string; |
14 | 14 |
15 // Specifies the directory used during QuicInMemoryCache | 15 // Specifies the directory used during QuicInMemoryCache |
16 // construction to seed the cache. Cache directory can be | 16 // construction to seed the cache. Cache directory can be |
17 // generated using `wget -p --save-headers <url> | 17 // generated using `wget -p --save-headers <url> |
18 string FLAGS_quic_in_memory_cache_dir; | 18 string FLAGS_quic_in_memory_cache_dir; |
19 | 19 |
20 namespace net { | 20 namespace net { |
21 namespace tools { | 21 namespace tools { |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 // BalsaVisitor implementation (glue) which caches response bodies. | 25 // BalsaVisitor implementation (glue) which caches response bodies. |
26 class CachingBalsaVisitor : public BalsaVisitorInterface { | 26 class CachingBalsaVisitor : public BalsaVisitorInterface { |
27 public: | 27 public: |
28 CachingBalsaVisitor() : done_framing_(false) {} | 28 CachingBalsaVisitor() : done_framing_(false) {} |
29 virtual void ProcessBodyData(const char* input, size_t size) { | 29 virtual void ProcessBodyData(const char* input, size_t size) OVERRIDE { |
30 AppendToBody(input, size); | 30 AppendToBody(input, size); |
31 } | 31 } |
32 virtual void ProcessTrailers(const BalsaHeaders& trailer) { | 32 virtual void ProcessTrailers(const BalsaHeaders& trailer) { |
33 LOG(DFATAL) << "Trailers not supported."; | 33 LOG(DFATAL) << "Trailers not supported."; |
34 } | 34 } |
35 virtual void MessageDone() { | 35 virtual void MessageDone() OVERRIDE { |
36 done_framing_ = true; | 36 done_framing_ = true; |
37 } | 37 } |
38 virtual void HandleHeaderError(BalsaFrame* framer) { UnhandledError(); } | 38 virtual void HandleHeaderError(BalsaFrame* framer) OVERRIDE { |
39 virtual void HandleHeaderWarning(BalsaFrame* framer) { UnhandledError(); } | 39 UnhandledError(); |
| 40 } |
| 41 virtual void HandleHeaderWarning(BalsaFrame* framer) OVERRIDE { |
| 42 UnhandledError(); |
| 43 } |
40 virtual void HandleTrailerError(BalsaFrame* framer) { UnhandledError(); } | 44 virtual void HandleTrailerError(BalsaFrame* framer) { UnhandledError(); } |
41 virtual void HandleTrailerWarning(BalsaFrame* framer) { UnhandledError(); } | 45 virtual void HandleTrailerWarning(BalsaFrame* framer) { UnhandledError(); } |
42 virtual void HandleChunkingError(BalsaFrame* framer) { UnhandledError(); } | 46 virtual void HandleChunkingError(BalsaFrame* framer) OVERRIDE { |
43 virtual void HandleBodyError(BalsaFrame* framer) { UnhandledError(); } | 47 UnhandledError(); |
| 48 } |
| 49 virtual void HandleBodyError(BalsaFrame* framer) OVERRIDE { |
| 50 UnhandledError(); |
| 51 } |
44 void UnhandledError() { | 52 void UnhandledError() { |
45 LOG(DFATAL) << "Unhandled error framing HTTP."; | 53 LOG(DFATAL) << "Unhandled error framing HTTP."; |
46 } | 54 } |
47 virtual void ProcessBodyInput(const char*, size_t) {} | 55 virtual void ProcessBodyInput(const char*, size_t) OVERRIDE {} |
48 virtual void ProcessHeaderInput(const char*, size_t) {} | 56 virtual void ProcessHeaderInput(const char*, size_t) OVERRIDE {} |
49 virtual void ProcessTrailerInput(const char*, size_t) {} | 57 virtual void ProcessTrailerInput(const char*, size_t) OVERRIDE {} |
50 virtual void ProcessHeaders(const net::BalsaHeaders&) {} | 58 virtual void ProcessHeaders(const net::BalsaHeaders&) OVERRIDE {} |
51 virtual void ProcessRequestFirstLine( | 59 virtual void ProcessRequestFirstLine( |
52 const char*, size_t, const char*, size_t, | 60 const char*, size_t, const char*, size_t, |
53 const char*, size_t, const char*, size_t) {} | 61 const char*, size_t, const char*, size_t) OVERRIDE {} |
54 virtual void ProcessResponseFirstLine( | 62 virtual void ProcessResponseFirstLine( |
55 const char*, size_t, const char*, | 63 const char*, size_t, const char*, |
56 size_t, const char*, size_t, const char*, size_t) {} | 64 size_t, const char*, size_t, const char*, size_t) OVERRIDE {} |
57 virtual void ProcessChunkLength(size_t) {} | 65 virtual void ProcessChunkLength(size_t) OVERRIDE {} |
58 virtual void ProcessChunkExtensions(const char*, size_t) {} | 66 virtual void ProcessChunkExtensions(const char*, size_t) OVERRIDE {} |
59 virtual void HeaderDone() {} | 67 virtual void HeaderDone() OVERRIDE {} |
60 | 68 |
61 void AppendToBody(const char* input, size_t size) { | 69 void AppendToBody(const char* input, size_t size) { |
62 body_.append(input, size); | 70 body_.append(input, size); |
63 } | 71 } |
64 bool done_framing() const { return done_framing_; } | 72 bool done_framing() const { return done_framing_; } |
65 const string& body() const { return body_; } | 73 const string& body() const { return body_; } |
66 | 74 |
67 private: | 75 private: |
68 bool done_framing_; | 76 bool done_framing_; |
69 string body_; | 77 string body_; |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 STLDeleteValues(&responses_); | 194 STLDeleteValues(&responses_); |
187 } | 195 } |
188 | 196 |
189 string QuicInMemoryCache::GetKey(const BalsaHeaders& request_headers) const { | 197 string QuicInMemoryCache::GetKey(const BalsaHeaders& request_headers) const { |
190 return request_headers.GetHeader("host").as_string() + | 198 return request_headers.GetHeader("host").as_string() + |
191 request_headers.request_uri().as_string(); | 199 request_headers.request_uri().as_string(); |
192 } | 200 } |
193 | 201 |
194 } // namespace tools | 202 } // namespace tools |
195 } // namespace net | 203 } // namespace net |
OLD | NEW |