| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_FLIP_SERVER_MEM_CACHE_H_ | 5 #ifndef NET_TOOLS_FLIP_SERVER_MEM_CACHE_H_ |
| 6 #define NET_TOOLS_FLIP_SERVER_MEM_CACHE_H_ | 6 #define NET_TOOLS_FLIP_SERVER_MEM_CACHE_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "net/tools/balsa/balsa_headers.h" | 13 #include "net/tools/balsa/balsa_headers.h" |
| 14 #include "net/tools/balsa/balsa_visitor_interface.h" | 14 #include "net/tools/balsa/balsa_visitor_interface.h" |
| 15 #include "net/tools/flip_server/constants.h" | 15 #include "net/tools/flip_server/constants.h" |
| 16 | 16 |
| 17 namespace net { | 17 namespace net { |
| 18 | 18 |
| 19 class StoreBodyAndHeadersVisitor: public BalsaVisitorInterface { | 19 class StoreBodyAndHeadersVisitor : public BalsaVisitorInterface { |
| 20 public: | 20 public: |
| 21 void HandleError() { error_ = true; } | 21 void HandleError() { error_ = true; } |
| 22 | 22 |
| 23 // BalsaVisitorInterface: | 23 // BalsaVisitorInterface: |
| 24 virtual void ProcessBodyInput(const char *input, size_t size) OVERRIDE {} | 24 virtual void ProcessBodyInput(const char* input, size_t size) OVERRIDE {} |
| 25 virtual void ProcessBodyData(const char *input, size_t size) OVERRIDE; | 25 virtual void ProcessBodyData(const char* input, size_t size) OVERRIDE; |
| 26 virtual void ProcessHeaderInput(const char *input, size_t size) OVERRIDE {} | 26 virtual void ProcessHeaderInput(const char* input, size_t size) OVERRIDE {} |
| 27 virtual void ProcessTrailerInput(const char *input, size_t size) OVERRIDE {} | 27 virtual void ProcessTrailerInput(const char* input, size_t size) OVERRIDE {} |
| 28 virtual void ProcessHeaders(const BalsaHeaders& headers) OVERRIDE { | 28 virtual void ProcessHeaders(const BalsaHeaders& headers) OVERRIDE { |
| 29 // nothing to do here-- we're assuming that the BalsaFrame has | 29 // nothing to do here-- we're assuming that the BalsaFrame has |
| 30 // been handed our headers. | 30 // been handed our headers. |
| 31 } | 31 } |
| 32 virtual void ProcessRequestFirstLine(const char* line_input, | 32 virtual void ProcessRequestFirstLine(const char* line_input, |
| 33 size_t line_length, | 33 size_t line_length, |
| 34 const char* method_input, | 34 const char* method_input, |
| 35 size_t method_length, | 35 size_t method_length, |
| 36 const char* request_uri_input, | 36 const char* request_uri_input, |
| 37 size_t request_uri_length, | 37 size_t request_uri_length, |
| 38 const char* version_input, | 38 const char* version_input, |
| 39 size_t version_length) OVERRIDE {} | 39 size_t version_length) OVERRIDE {} |
| 40 virtual void ProcessResponseFirstLine(const char *line_input, | 40 virtual void ProcessResponseFirstLine(const char* line_input, |
| 41 size_t line_length, | 41 size_t line_length, |
| 42 const char *version_input, | 42 const char* version_input, |
| 43 size_t version_length, | 43 size_t version_length, |
| 44 const char *status_input, | 44 const char* status_input, |
| 45 size_t status_length, | 45 size_t status_length, |
| 46 const char *reason_input, | 46 const char* reason_input, |
| 47 size_t reason_length) OVERRIDE {} | 47 size_t reason_length) OVERRIDE {} |
| 48 virtual void ProcessChunkLength(size_t chunk_length) OVERRIDE {} | 48 virtual void ProcessChunkLength(size_t chunk_length) OVERRIDE {} |
| 49 virtual void ProcessChunkExtensions(const char *input, | 49 virtual void ProcessChunkExtensions(const char* input, size_t size) OVERRIDE { |
| 50 size_t size) OVERRIDE {} | 50 } |
| 51 virtual void HeaderDone() OVERRIDE {} | 51 virtual void HeaderDone() OVERRIDE {} |
| 52 virtual void MessageDone() OVERRIDE {} | 52 virtual void MessageDone() OVERRIDE {} |
| 53 virtual void HandleHeaderError(BalsaFrame* framer) OVERRIDE; | 53 virtual void HandleHeaderError(BalsaFrame* framer) OVERRIDE; |
| 54 virtual void HandleHeaderWarning(BalsaFrame* framer) OVERRIDE; | 54 virtual void HandleHeaderWarning(BalsaFrame* framer) OVERRIDE; |
| 55 virtual void HandleChunkingError(BalsaFrame* framer) OVERRIDE; | 55 virtual void HandleChunkingError(BalsaFrame* framer) OVERRIDE; |
| 56 virtual void HandleBodyError(BalsaFrame* framer) OVERRIDE; | 56 virtual void HandleBodyError(BalsaFrame* framer) OVERRIDE; |
| 57 | 57 |
| 58 BalsaHeaders headers; | 58 BalsaHeaders headers; |
| 59 std::string body; | 59 std::string body; |
| 60 bool error_; | 60 bool error_; |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 //////////////////////////////////////////////////////////////////////////////// | |
| 64 class FileData { | 63 class FileData { |
| 65 public: | 64 public: |
| 66 FileData(); | 65 FileData(); |
| 67 FileData(const BalsaHeaders* headers, | 66 FileData(const BalsaHeaders* headers, |
| 68 const std::string& filename, | 67 const std::string& filename, |
| 69 const std::string& body); | 68 const std::string& body); |
| 70 ~FileData(); | 69 ~FileData(); |
| 71 | 70 |
| 72 BalsaHeaders* headers() { return headers_.get(); } | 71 BalsaHeaders* headers() { return headers_.get(); } |
| 73 const BalsaHeaders* headers() const { return headers_.get(); } | 72 const BalsaHeaders* headers() const { return headers_.get(); } |
| 74 | 73 |
| 75 const std::string& filename() { return filename_; } | 74 const std::string& filename() { return filename_; } |
| 76 const std::string& body() { return body_; } | 75 const std::string& body() { return body_; } |
| 77 | 76 |
| 78 private: | 77 private: |
| 79 scoped_ptr<BalsaHeaders> headers_; | 78 scoped_ptr<BalsaHeaders> headers_; |
| 80 std::string filename_; | 79 std::string filename_; |
| 81 std::string body_; | 80 std::string body_; |
| 82 | 81 |
| 83 DISALLOW_COPY_AND_ASSIGN(FileData); | 82 DISALLOW_COPY_AND_ASSIGN(FileData); |
| 84 }; | 83 }; |
| 85 | 84 |
| 86 //////////////////////////////////////////////////////////////////////////////// | |
| 87 | |
| 88 class MemCacheIter { | 85 class MemCacheIter { |
| 89 public: | 86 public: |
| 90 MemCacheIter() : | 87 MemCacheIter() |
| 91 file_data(NULL), | 88 : file_data(NULL), |
| 92 priority(0), | 89 priority(0), |
| 93 transformed_header(false), | 90 transformed_header(false), |
| 94 body_bytes_consumed(0), | 91 body_bytes_consumed(0), |
| 95 stream_id(0), | 92 stream_id(0), |
| 96 max_segment_size(kInitialDataSendersThreshold), | 93 max_segment_size(kInitialDataSendersThreshold), |
| 97 bytes_sent(0) {} | 94 bytes_sent(0) {} |
| 98 explicit MemCacheIter(FileData* fd) : | 95 explicit MemCacheIter(FileData* fd) |
| 99 file_data(fd), | 96 : file_data(fd), |
| 100 priority(0), | 97 priority(0), |
| 101 transformed_header(false), | 98 transformed_header(false), |
| 102 body_bytes_consumed(0), | 99 body_bytes_consumed(0), |
| 103 stream_id(0), | 100 stream_id(0), |
| 104 max_segment_size(kInitialDataSendersThreshold), | 101 max_segment_size(kInitialDataSendersThreshold), |
| 105 bytes_sent(0) {} | 102 bytes_sent(0) {} |
| 106 FileData* file_data; | 103 FileData* file_data; |
| 107 int priority; | 104 int priority; |
| 108 bool transformed_header; | 105 bool transformed_header; |
| 109 size_t body_bytes_consumed; | 106 size_t body_bytes_consumed; |
| 110 uint32 stream_id; | 107 uint32 stream_id; |
| 111 uint32 max_segment_size; | 108 uint32 max_segment_size; |
| 112 size_t bytes_sent; | 109 size_t bytes_sent; |
| 113 }; | 110 }; |
| 114 | 111 |
| 115 //////////////////////////////////////////////////////////////////////////////// | |
| 116 | |
| 117 class MemoryCache { | 112 class MemoryCache { |
| 118 public: | 113 public: |
| 119 typedef std::map<std::string, FileData*> Files; | 114 typedef std::map<std::string, FileData*> Files; |
| 120 | 115 |
| 121 public: | 116 public: |
| 122 MemoryCache(); | 117 MemoryCache(); |
| 123 virtual ~MemoryCache(); | 118 virtual ~MemoryCache(); |
| 124 | 119 |
| 125 void CloneFrom(const MemoryCache& mc); | 120 void CloneFrom(const MemoryCache& mc); |
| 126 | 121 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 150 | 145 |
| 151 class NotifierInterface { | 146 class NotifierInterface { |
| 152 public: | 147 public: |
| 153 virtual ~NotifierInterface() {} | 148 virtual ~NotifierInterface() {} |
| 154 virtual void Notify() = 0; | 149 virtual void Notify() = 0; |
| 155 }; | 150 }; |
| 156 | 151 |
| 157 } // namespace net | 152 } // namespace net |
| 158 | 153 |
| 159 #endif // NET_TOOLS_FLIP_SERVER_MEM_CACHE_H_ | 154 #endif // NET_TOOLS_FLIP_SERVER_MEM_CACHE_H_ |
| OLD | NEW |