Page Speed Optimization Libraries
1.7.30.1
|
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 00050 static void InitStats(Statistics* statistics); 00051 00054 virtual bool Write(const StringPiece& contents, MessageHandler* handler); 00055 00058 virtual bool Flush(MessageHandler* handler) { return true; } 00059 00076 void ConsiderResponseHeaders(ResponseHeaders* response_headers); 00077 00080 void Fail() { failure_ = true; } 00081 00089 void DoneAndSetHeaders(ResponseHeaders* response_headers); 00090 00091 const GoogleString& url() const { return url_; } 00092 MessageHandler* handler() { return handler_; } 00093 00094 bool failed() { return failure_; } 00095 bool limit_active_recordings() { return max_concurrent_recordings_ != 0; } 00096 00097 private: 00098 virtual ~InPlaceResourceRecorder(); 00099 00100 bool IsIproContentType(ResponseHeaders* response_headers); 00101 00102 const GoogleString url_; 00103 const scoped_ptr<RequestHeaders> request_headers_; 00104 const bool respect_vary_; 00105 const unsigned int max_response_bytes_; 00106 const int max_concurrent_recordings_; 00107 00108 HTTPValue resource_value_; 00109 00110 HTTPCache* cache_; 00111 MessageHandler* handler_; 00112 00113 Variable* num_resources_; 00114 Variable* num_inserted_into_cache_; 00115 Variable* num_not_cacheable_; 00116 Variable* num_failed_; 00117 Variable* num_dropped_due_to_load_; 00118 Variable* num_dropped_due_to_size_; 00119 00122 static AtomicInt32 active_recordings_; 00124 int status_code_; 00126 bool failure_; 00127 00129 bool response_headers_considered_; 00130 00131 DISALLOW_COPY_AND_ASSIGN(InPlaceResourceRecorder); 00132 }; 00133 00134 } 00135 00136 #endif ///< NET_INSTAWEB_SYSTEM_PUBLIC_IN_PLACE_RESOURCE_RECORDER_H_