Page Speed Optimization Libraries  1.9.32.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 NET_INSTAWEB_SYSTEM_PUBLIC_IN_PLACE_RESOURCE_RECORDER_H_
18 #define NET_INSTAWEB_SYSTEM_PUBLIC_IN_PLACE_RESOURCE_RECORDER_H_
19 
28 #include "pagespeed/kernel/base/atomic_int32.h"
29 #include "pagespeed/kernel/http/http_options.h"
30 #include "pagespeed/kernel/http/request_headers.h"
31 
32 namespace net_instaweb {
33 
34 class HTTPCache;
35 class MessageHandler;
36 class ResponseHeaders;
37 class Statistics;
38 class Variable;
39 
43 class InPlaceResourceRecorder : public Writer {
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 
106  void Fail() { failure_ = true; }
107 
115  void DoneAndSetHeaders(ResponseHeaders* response_headers);
116 
117  const GoogleString& url() const { return url_; }
118  MessageHandler* handler() { return handler_; }
119 
120  bool failed() { return failure_; }
121  bool limit_active_recordings() { return max_concurrent_recordings_ != 0; }
122 
123  const HttpOptions& http_options() const { return http_options_; }
124 
125  private:
126  class HTTPValueFetch : public AsyncFetchUsingWriter {
127  public:
128  HTTPValueFetch(const RequestContextPtr& request_context, HTTPValue* value)
129  : AsyncFetchUsingWriter(request_context, value) {}
130  virtual void HandleDone(bool ) {}
131  virtual void HandleHeadersComplete() {}
132  };
133 
134  bool IsIproContentType(ResponseHeaders* response_headers);
135 
136  void DroppedDueToSize();
137 
138  const GoogleString url_;
139  const GoogleString fragment_;
140  const RequestHeaders::Properties request_properties_;
141  const HttpOptions http_options_;
142 
143  int64 max_response_bytes_;
144  const int max_concurrent_recordings_;
145 
146  HTTPValue resource_value_;
147  HTTPValueFetch write_to_resource_value_;
148  InflatingFetch inflating_fetch_;
149 
150  HTTPCache* cache_;
151  MessageHandler* handler_;
152 
153  Variable* num_resources_;
154  Variable* num_inserted_into_cache_;
155  Variable* num_not_cacheable_;
156  Variable* num_failed_;
157  Variable* num_dropped_due_to_load_;
158  Variable* num_dropped_due_to_size_;
159 
162  static AtomicInt32 active_recordings_;
164  int status_code_;
166  bool failure_;
167 
170  bool full_response_headers_considered_;
171 
173  bool consider_response_headers_called_;
174 
175  DISALLOW_COPY_AND_ASSIGN(InPlaceResourceRecorder);
176 };
177 
178 }
179 
180 #endif
Definition: in_place_resource_recorder.h:43
Definition: in_place_resource_recorder.h:48
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
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:106
void DoneAndSetHeaders(ResponseHeaders *response_headers)
virtual bool Write(const StringPiece &contents, MessageHandler *handler)
Definition: http_cache.h:46