| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef NET_TOOLS_FLIP_SERVER_MEM_CACHE_H_ | |
| 6 #define NET_TOOLS_FLIP_SERVER_MEM_CACHE_H_ | |
| 7 | |
| 8 #include <stddef.h> | |
| 9 #include <stdint.h> | |
| 10 | |
| 11 #include <map> | |
| 12 #include <memory> | |
| 13 #include <string> | |
| 14 | |
| 15 #include "base/compiler_specific.h" | |
| 16 #include "base/macros.h" | |
| 17 #include "net/tools/balsa/balsa_headers.h" | |
| 18 #include "net/tools/balsa/balsa_visitor_interface.h" | |
| 19 #include "net/tools/flip_server/constants.h" | |
| 20 | |
| 21 namespace net { | |
| 22 | |
| 23 class StoreBodyAndHeadersVisitor : public BalsaVisitorInterface { | |
| 24 public: | |
| 25 void HandleError() { error_ = true; } | |
| 26 | |
| 27 // BalsaVisitorInterface: | |
| 28 void ProcessBodyInput(const char* input, size_t size) override {} | |
| 29 void ProcessBodyData(const char* input, size_t size) override; | |
| 30 void ProcessHeaderInput(const char* input, size_t size) override {} | |
| 31 void ProcessTrailerInput(const char* input, size_t size) override {} | |
| 32 void ProcessHeaders(const BalsaHeaders& headers) override { | |
| 33 // nothing to do here-- we're assuming that the BalsaFrame has | |
| 34 // been handed our headers. | |
| 35 } | |
| 36 void ProcessRequestFirstLine(const char* line_input, | |
| 37 size_t line_length, | |
| 38 const char* method_input, | |
| 39 size_t method_length, | |
| 40 const char* request_uri_input, | |
| 41 size_t request_uri_length, | |
| 42 const char* version_input, | |
| 43 size_t version_length) override {} | |
| 44 void ProcessResponseFirstLine(const char* line_input, | |
| 45 size_t line_length, | |
| 46 const char* version_input, | |
| 47 size_t version_length, | |
| 48 const char* status_input, | |
| 49 size_t status_length, | |
| 50 const char* reason_input, | |
| 51 size_t reason_length) override {} | |
| 52 void ProcessChunkLength(size_t chunk_length) override {} | |
| 53 void ProcessChunkExtensions(const char* input, size_t size) override {} | |
| 54 void HeaderDone() override {} | |
| 55 void MessageDone() override {} | |
| 56 void HandleHeaderError(BalsaFrame* framer) override; | |
| 57 void HandleHeaderWarning(BalsaFrame* framer) override; | |
| 58 void HandleChunkingError(BalsaFrame* framer) override; | |
| 59 void HandleBodyError(BalsaFrame* framer) override; | |
| 60 | |
| 61 BalsaHeaders headers; | |
| 62 std::string body; | |
| 63 bool error_; | |
| 64 }; | |
| 65 | |
| 66 class FileData { | |
| 67 public: | |
| 68 FileData(); | |
| 69 FileData(const BalsaHeaders* headers, | |
| 70 const std::string& filename, | |
| 71 const std::string& body); | |
| 72 ~FileData(); | |
| 73 | |
| 74 BalsaHeaders* headers() { return headers_.get(); } | |
| 75 const BalsaHeaders* headers() const { return headers_.get(); } | |
| 76 | |
| 77 const std::string& filename() { return filename_; } | |
| 78 const std::string& body() { return body_; } | |
| 79 | |
| 80 private: | |
| 81 std::unique_ptr<BalsaHeaders> headers_; | |
| 82 std::string filename_; | |
| 83 std::string body_; | |
| 84 | |
| 85 DISALLOW_COPY_AND_ASSIGN(FileData); | |
| 86 }; | |
| 87 | |
| 88 class MemCacheIter { | |
| 89 public: | |
| 90 MemCacheIter() | |
| 91 : file_data(NULL), | |
| 92 priority(0), | |
| 93 transformed_header(false), | |
| 94 body_bytes_consumed(0), | |
| 95 stream_id(0), | |
| 96 max_segment_size(kInitialDataSendersThreshold), | |
| 97 bytes_sent(0) {} | |
| 98 explicit MemCacheIter(FileData* fd) | |
| 99 : file_data(fd), | |
| 100 priority(0), | |
| 101 transformed_header(false), | |
| 102 body_bytes_consumed(0), | |
| 103 stream_id(0), | |
| 104 max_segment_size(kInitialDataSendersThreshold), | |
| 105 bytes_sent(0) {} | |
| 106 FileData* file_data; | |
| 107 int priority; | |
| 108 bool transformed_header; | |
| 109 size_t body_bytes_consumed; | |
| 110 uint32_t stream_id; | |
| 111 uint32_t max_segment_size; | |
| 112 size_t bytes_sent; | |
| 113 }; | |
| 114 | |
| 115 class MemoryCache { | |
| 116 public: | |
| 117 using Files = std::map<std::string, std::unique_ptr<FileData>>; | |
| 118 | |
| 119 public: | |
| 120 MemoryCache(); | |
| 121 virtual ~MemoryCache(); | |
| 122 | |
| 123 void AddFiles(); | |
| 124 | |
| 125 // virtual for unittests | |
| 126 virtual void ReadToString(const char* filename, std::string* output); | |
| 127 | |
| 128 void ReadAndStoreFileContents(const char* filename); | |
| 129 | |
| 130 FileData* GetFileData(const std::string& filename); | |
| 131 | |
| 132 bool AssignFileData(const std::string& filename, MemCacheIter* mci); | |
| 133 | |
| 134 // For unittests | |
| 135 void InsertFile(const BalsaHeaders* headers, | |
| 136 const std::string& filename, | |
| 137 const std::string& body); | |
| 138 | |
| 139 private: | |
| 140 void InsertFile(FileData* file_data); | |
| 141 | |
| 142 Files files_; | |
| 143 std::string cwd_; | |
| 144 }; | |
| 145 | |
| 146 class NotifierInterface { | |
| 147 public: | |
| 148 virtual ~NotifierInterface() {} | |
| 149 virtual void Notify() = 0; | |
| 150 }; | |
| 151 | |
| 152 } // namespace net | |
| 153 | |
| 154 #endif // NET_TOOLS_FLIP_SERVER_MEM_CACHE_H_ | |
| OLD | NEW |