Page Speed Optimization Libraries
1.7.30.3
|
00001 // Copyright 2013 Google Inc. 00016 00017 #ifndef NET_INSTAWEB_SYSTEM_PUBLIC_IN_PLACE_RESOURCE_RECORDER_H_ 00018 #define NET_INSTAWEB_SYSTEM_PUBLIC_IN_PLACE_RESOURCE_RECORDER_H_ 00019 00020 #include "net/instaweb/http/public/http_value.h" 00021 #include "net/instaweb/util/public/basictypes.h" 00022 #include "net/instaweb/util/public/scoped_ptr.h" 00023 #include "net/instaweb/util/public/string.h" 00024 #include "net/instaweb/util/public/string_util.h" 00025 #include "net/instaweb/util/public/writer.h" 00026 #include "pagespeed/kernel/base/atomic_int32.h" 00027 00028 namespace net_instaweb { 00029 00030 class HTTPCache; 00031 class MessageHandler; 00032 class RequestHeaders; 00033 class ResponseHeaders; 00034 class Statistics; 00035 class Variable; 00036 00040 class InPlaceResourceRecorder : public Writer { 00041 public: 00045 InPlaceResourceRecorder( 00046 StringPiece url, RequestHeaders* request_headers, bool respect_vary, 00047 int max_response_bytes, int max_concurrent_recordings, HTTPCache* cache, 00048 Statistics* statistics, MessageHandler* handler); 00049 00052 virtual ~InPlaceResourceRecorder(); 00053 00054 static void InitStats(Statistics* statistics); 00055 00058 virtual bool Write(const StringPiece& contents, MessageHandler* handler); 00059 00062 virtual bool Flush(MessageHandler* handler) { return true; } 00063 00080 void ConsiderResponseHeaders(ResponseHeaders* response_headers); 00081 00084 void Fail() { failure_ = true; } 00085 00093 void DoneAndSetHeaders(ResponseHeaders* response_headers); 00094 00095 const GoogleString& url() const { return url_; } 00096 MessageHandler* handler() { return handler_; } 00097 00098 bool failed() { return failure_; } 00099 bool limit_active_recordings() { return max_concurrent_recordings_ != 0; } 00100 00101 private: 00102 bool IsIproContentType(ResponseHeaders* response_headers); 00103 00104 const GoogleString url_; 00105 const scoped_ptr<RequestHeaders> request_headers_; 00106 const bool respect_vary_; 00107 const unsigned int max_response_bytes_; 00108 const int max_concurrent_recordings_; 00109 00110 HTTPValue resource_value_; 00111 00112 HTTPCache* cache_; 00113 MessageHandler* handler_; 00114 00115 Variable* num_resources_; 00116 Variable* num_inserted_into_cache_; 00117 Variable* num_not_cacheable_; 00118 Variable* num_failed_; 00119 Variable* num_dropped_due_to_load_; 00120 Variable* num_dropped_due_to_size_; 00121 00124 static AtomicInt32 active_recordings_; 00126 int status_code_; 00128 bool failure_; 00129 00131 bool response_headers_considered_; 00132 00133 DISALLOW_COPY_AND_ASSIGN(InPlaceResourceRecorder); 00134 }; 00135 00136 } 00137 00138 #endif ///< NET_INSTAWEB_SYSTEM_PUBLIC_IN_PLACE_RESOURCE_RECORDER_H_