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.
5 #ifndef NET_TOOLS_FLIP_SERVER_MEM_CACHE_H_
6 #define NET_TOOLS_FLIP_SERVER_MEM_CACHE_H_
11 #include "base/compiler_specific.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "net/tools/balsa/balsa_headers.h"
14 #include "net/tools/balsa/balsa_visitor_interface.h"
15 #include "net/tools/flip_server/constants.h"
19 class StoreBodyAndHeadersVisitor
: public BalsaVisitorInterface
{
21 void HandleError() { error_
= true; }
23 // BalsaVisitorInterface:
24 virtual void ProcessBodyInput(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
{}
27 virtual void ProcessTrailerInput(const char* input
, size_t size
) override
{}
28 virtual void ProcessHeaders(const BalsaHeaders
& headers
) override
{
29 // nothing to do here-- we're assuming that the BalsaFrame has
30 // been handed our headers.
32 virtual void ProcessRequestFirstLine(const char* line_input
,
34 const char* method_input
,
36 const char* request_uri_input
,
37 size_t request_uri_length
,
38 const char* version_input
,
39 size_t version_length
) override
{}
40 virtual void ProcessResponseFirstLine(const char* line_input
,
42 const char* version_input
,
43 size_t version_length
,
44 const char* status_input
,
46 const char* reason_input
,
47 size_t reason_length
) override
{}
48 virtual void ProcessChunkLength(size_t chunk_length
) override
{}
49 virtual void ProcessChunkExtensions(const char* input
, size_t size
) override
{
51 virtual void HeaderDone() override
{}
52 virtual void MessageDone() override
{}
53 virtual void HandleHeaderError(BalsaFrame
* framer
) override
;
54 virtual void HandleHeaderWarning(BalsaFrame
* framer
) override
;
55 virtual void HandleChunkingError(BalsaFrame
* framer
) override
;
56 virtual void HandleBodyError(BalsaFrame
* framer
) override
;
66 FileData(const BalsaHeaders
* headers
,
67 const std::string
& filename
,
68 const std::string
& body
);
71 BalsaHeaders
* headers() { return headers_
.get(); }
72 const BalsaHeaders
* headers() const { return headers_
.get(); }
74 const std::string
& filename() { return filename_
; }
75 const std::string
& body() { return body_
; }
78 scoped_ptr
<BalsaHeaders
> headers_
;
79 std::string filename_
;
82 DISALLOW_COPY_AND_ASSIGN(FileData
);
90 transformed_header(false),
91 body_bytes_consumed(0),
93 max_segment_size(kInitialDataSendersThreshold
),
95 explicit MemCacheIter(FileData
* fd
)
98 transformed_header(false),
99 body_bytes_consumed(0),
101 max_segment_size(kInitialDataSendersThreshold
),
105 bool transformed_header
;
106 size_t body_bytes_consumed
;
108 uint32 max_segment_size
;
114 typedef std::map
<std::string
, FileData
*> Files
;
118 virtual ~MemoryCache();
120 void CloneFrom(const MemoryCache
& mc
);
124 // virtual for unittests
125 virtual void ReadToString(const char* filename
, std::string
* output
);
127 void ReadAndStoreFileContents(const char* filename
);
129 FileData
* GetFileData(const std::string
& filename
);
131 bool AssignFileData(const std::string
& filename
, MemCacheIter
* mci
);
134 void InsertFile(const BalsaHeaders
* headers
,
135 const std::string
& filename
,
136 const std::string
& body
);
139 void InsertFile(FileData
* file_data
);
146 class NotifierInterface
{
148 virtual ~NotifierInterface() {}
149 virtual void Notify() = 0;
154 #endif // NET_TOOLS_FLIP_SERVER_MEM_CACHE_H_