Page Speed Optimization Libraries  1.13.35.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
in_place_resource_recorder.h
Go to the documentation of this file.
1 // Copyright 2013 Google Inc.
16 
17 #ifndef PAGESPEED_SYSTEM_IN_PLACE_RESOURCE_RECORDER_H_
18 #define PAGESPEED_SYSTEM_IN_PLACE_RESOURCE_RECORDER_H_
19 
23 #include "net/instaweb/http/public/request_context.h"
32 
33 namespace net_instaweb {
34 
35 class HTTPCache;
36 class MessageHandler;
37 class Statistics;
38 class Variable;
39 
44  public:
45  enum HeadersKind {
49 
52  };
53 
58  const RequestContextPtr& request_context,
59  StringPiece url, StringPiece fragment,
60  const RequestHeaders::Properties& request_properties,
61  int max_response_bytes, int max_concurrent_recordings,
62  HTTPCache* cache, Statistics* statistics, MessageHandler* handler);
63 
66  virtual ~InPlaceResourceRecorder();
67 
68  static void InitStats(Statistics* statistics);
69 
72  virtual bool Write(const StringPiece& contents, MessageHandler* handler);
73 
76  virtual bool Flush(MessageHandler* handler) { return true; }
77 
101  void ConsiderResponseHeaders(HeadersKind headers_kind,
102  ResponseHeaders* response_headers);
103 
115  void SaveCacheControl(const char* cache_control);
116 
119  void Fail() { failure_ = true; }
120 
133  void DoneAndSetHeaders(ResponseHeaders* response_headers,
134  bool entire_response_received);
135 
136  const GoogleString& url() const { return url_; }
137  MessageHandler* handler() { return handler_; }
138 
139  bool failed() { return failure_; }
140  bool limit_active_recordings() { return max_concurrent_recordings_ != 0; }
141 
142  const HttpOptions& http_options() const { return http_options_; }
143 
144  private:
145  class HTTPValueFetch : public AsyncFetchUsingWriter {
146  public:
147  HTTPValueFetch(const RequestContextPtr& request_context, HTTPValue* value)
148  : AsyncFetchUsingWriter(request_context, value) {}
149  virtual void HandleDone(bool ) {}
150  virtual void HandleHeadersComplete() {}
151  };
152 
153  bool IsIproContentType(ResponseHeaders* response_headers);
154 
155  void DroppedDueToSize();
156  void DroppedAsUncacheable();
157 
158  const GoogleString url_;
159  const GoogleString fragment_;
160  const RequestHeaders::Properties request_properties_;
161  const HttpOptions http_options_;
162 
163  int64 max_response_bytes_;
164  const int max_concurrent_recordings_;
165 
166  HTTPValue resource_value_;
167  HTTPValueFetch write_to_resource_value_;
168  InflatingFetch inflating_fetch_;
169 
170  HTTPCache* cache_;
171  MessageHandler* handler_;
172 
173  Variable* num_resources_;
174  Variable* num_inserted_into_cache_;
175  Variable* num_not_cacheable_;
176  Variable* num_failed_;
177  Variable* num_dropped_due_to_load_;
178  Variable* num_dropped_due_to_size_;
179 
182  static AtomicInt32 active_recordings_;
184  int status_code_;
186  bool failure_;
187 
190  bool full_response_headers_considered_;
191 
193  bool consider_response_headers_called_;
194 
198  bool cache_control_set_;
199  GoogleString cache_control_;
200 
201 
202 };
203 
204 }
205 
206 #endif
Definition: in_place_resource_recorder.h:43
Definition: request_headers.h:43
Definition: in_place_resource_recorder.h:48
Base class for implementations of monitoring statistics.
Definition: statistics.h:342
void SaveCacheControl(const char *cache_control)
Read/write API for HTTP response headers.
Definition: response_headers.h:37
HeadersKind
Definition: in_place_resource_recorder.h:45
void ConsiderResponseHeaders(HeadersKind headers_kind, ResponseHeaders *response_headers)
virtual bool Flush(MessageHandler *handler)
Definition: in_place_resource_recorder.h:76
std::string GoogleString
PAGESPEED_KERNEL_BASE_STRING_H_.
Definition: string.h:24
void DoneAndSetHeaders(ResponseHeaders *response_headers, bool entire_response_received)
Headers are complete.
Definition: in_place_resource_recorder.h:51
InPlaceResourceRecorder(const RequestContextPtr &request_context, StringPiece url, StringPiece fragment, const RequestHeaders::Properties &request_properties, int max_response_bytes, int max_concurrent_recordings, HTTPCache *cache, Statistics *statistics, MessageHandler *handler)
void Fail()
Definition: in_place_resource_recorder.h:119
Interface for writing bytes to an output stream.
Definition: writer.h:29
Definition: message_handler.h:39
virtual bool Write(const StringPiece &contents, MessageHandler *handler)
Definition: http_cache.h:67