Page Speed Optimization Libraries  1.2.24.1
net/instaweb/automatic/public/flush_early_flow.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2012 Google Inc.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http:///www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00018 
00019 #ifndef NET_INSTAWEB_AUTOMATIC_PUBLIC_FLUSH_EARLY_FLOW_H_
00020 #define NET_INSTAWEB_AUTOMATIC_PUBLIC_FLUSH_EARLY_FLOW_H_
00021 
00022 #include "net/instaweb/util/public/basictypes.h"
00023 #include "net/instaweb/util/public/string.h"
00024 #include "net/instaweb/util/public/string_util.h"
00025 #include "net/instaweb/util/public/string_writer.h"
00026 
00027 namespace net_instaweb {
00028 
00029 class AsyncFetch;
00030 class FlushEarlyInfo;
00031 class Histogram;
00032 class MessageHandler;
00033 class ProxyFetchPropertyCallbackCollector;
00034 class ProxyFetchFactory;
00035 class ServerContext;
00036 class RewriteDriver;
00037 class Statistics;
00038 class TimedVariable;
00039 
00045 class FlushEarlyFlow {
00046  public:
00047   static const char kNumRequestsFlushedEarly[];
00048   static const char kNumResourcesFlushedEarly[];
00049   static const char kFlushEarlyRewriteLatencyMs[];
00050   static const char kNumFlushEarlyHttpStatusCodeDeemedUnstable[];
00051 
00052   static void Start(
00053       const GoogleString& url,
00054       AsyncFetch** base_fetch,
00055       RewriteDriver* driver,
00056       ProxyFetchFactory* factory,
00057       ProxyFetchPropertyCallbackCollector* property_callback);
00058 
00059   static void InitStats(Statistics* stats);
00060 
00061   virtual ~FlushEarlyFlow();
00062 
00063  private:
00064   class FlushEarlyAsyncFetch;
00067   void FlushEarly();
00068 
00070   void Cancel();
00071 
00072   FlushEarlyFlow(const GoogleString& url,
00073                  AsyncFetch* base_fetch,
00074                  FlushEarlyAsyncFetch* flush_early_fetch,
00075                  RewriteDriver* driver,
00076                  ProxyFetchFactory* factory,
00077                  ProxyFetchPropertyCallbackCollector* property_cache_callback);
00078 
00081   void GenerateDummyHeadAndCountResources(
00082       const FlushEarlyInfo& flush_early_info);
00083 
00085   void GenerateResponseHeaders(const FlushEarlyInfo& flush_early_info);
00086 
00087   GoogleString GetHeadString(const FlushEarlyInfo& flush_early_info,
00088                              const char* css_format,
00089                              const char* js_format);
00090 
00094   void FlushEarlyRewriteDone(int64 start_time_ms,
00095                              RewriteDriver* flush_early_driver);
00096 
00097   void Write(const StringPiece& val);
00098 
00100   void WriteScript(const GoogleString& script_content);
00101 
00103   void WriteExternalScript(const GoogleString& script_url);
00104 
00105   GoogleString url_;
00106   GoogleString dummy_head_;
00107   StringWriter dummy_head_writer_;
00108   int num_resources_flushed_;
00109   int num_rewritten_resources_;
00110   int64 average_fetch_time_;
00111 
00112   AsyncFetch* base_fetch_;
00113   FlushEarlyAsyncFetch* flush_early_fetch_;
00114   RewriteDriver* driver_;
00115   ProxyFetchFactory* factory_;
00116   ServerContext* manager_;
00117   ProxyFetchPropertyCallbackCollector* property_cache_callback_;
00118   bool should_flush_early_lazyload_script_;
00119   bool should_flush_early_js_defer_script_;
00120   MessageHandler* handler_;
00121 
00122   TimedVariable* num_requests_flushed_early_;
00123   TimedVariable* num_resources_flushed_early_;
00124   TimedVariable* num_flush_early_http_status_code_deemed_unstable_;
00125   Histogram* flush_early_rewrite_latency_ms_;
00126 
00127   DISALLOW_COPY_AND_ASSIGN(FlushEarlyFlow);
00128 };
00129 
00130 }  
00131 
00132 #endif  ///< NET_INSTAWEB_AUTOMATIC_PUBLIC_FLUSH_EARLY_FLOW_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines