Page Speed Optimization Libraries  1.8.31.2
net/instaweb/rewriter/public/flush_early_content_writer_filter.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  */
00017 
00018 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_FLUSH_EARLY_CONTENT_WRITER_FILTER_H_
00019 #define NET_INSTAWEB_REWRITER_PUBLIC_FLUSH_EARLY_CONTENT_WRITER_FILTER_H_
00020 
00021 #include <list>
00022 
00023 #include "net/instaweb/htmlparse/public/html_writer_filter.h"
00024 #include "net/instaweb/http/public/logging_proto.h"
00025 #include "net/instaweb/http/public/logging_proto_impl.h"
00026 #include "net/instaweb/http/public/semantic_type.h"
00027 #include "net/instaweb/http/public/user_agent_matcher.h"
00028 #include "net/instaweb/util/public/basictypes.h"
00029 #include "net/instaweb/util/public/null_writer.h"
00030 #include "net/instaweb/util/public/scoped_ptr.h"
00031 #include "net/instaweb/util/public/string.h"
00032 #include "net/instaweb/util/public/string_util.h"
00033 
00034 namespace net_instaweb {
00035 
00036 class GoogleUrl;
00037 class HtmlCharactersNode;
00038 class HtmlElement;
00039 class RewriteDriver;
00040 class TimedVariable;
00041 class Writer;
00042 
00043 struct ResourceInfo;
00044 
00049 class FlushEarlyContentWriterFilter : public HtmlWriterFilter {
00050  public:
00051   static const char kDisableLinkTag[];
00052   static const char kPrefetchImageTagHtml[];
00053   static const char kPrefetchStartTimeScript[];
00054   static const char kNumResourcesFlushedEarly[];
00055   static const char kPrefetchScriptTagHtml[];
00056   static const char kPrefetchLinkTagHtml[];
00057   static const char kFlushEarlyStyleTemplate[];
00058 
00059   explicit FlushEarlyContentWriterFilter(RewriteDriver* driver);
00060 
00061   virtual void StartDocument();
00062   virtual void EndDocument();
00063 
00064   virtual void StartElement(HtmlElement* element);
00065   virtual void EndElement(HtmlElement* element);
00066 
00067   virtual void Characters(HtmlCharactersNode* characters_node);
00068 
00069  protected:
00070   virtual void Clear();
00071 
00072  private:
00074   void WriteToOriginalWriter(const GoogleString& in);
00075 
00077   bool IsFlushable(const GoogleUrl& gurl,
00078                    const FlushEarlyResourceInfo::ResourceType& resource_type);
00079 
00081   void FlushResourceAsImage(StringPiece url);
00082 
00084   void FlushResources(
00085       StringPiece url,
00086       int64 time_to_download,
00087       bool is_pagespeed_resource,
00088       semantic_type::Category category);
00089 
00090   void FlushDeferJavascriptEarly();
00091   void UpdateStats(int64 time_to_download, bool is_pagespeed_resource);
00092   GoogleString ComputeFlushEarlyCriticalCss(const GoogleString& style_id);
00093 
00095   FlushEarlyResourceInfo::ResourceType GetResourceType(
00096       const GoogleUrl& gurl, bool is_pagespeed_resource);
00097 
00098   RewriteDriver* driver_;
00099   TimedVariable* num_resources_flushed_early_;
00101   bool in_body_;
00102   bool insert_close_script_;
00103   int num_resources_flushed_;
00104   NullWriter null_writer_;
00105   Writer* original_writer_;
00106   HtmlElement* current_element_;
00107   UserAgentMatcher::PrefetchMechanism prefetch_mechanism_;
00108   scoped_ptr<StringSet> private_cacheable_resources_;
00109   scoped_ptr<StringSet> public_cacheable_resources_;
00110   int64 time_consumed_ms_;
00111   int64 max_available_time_ms_;
00112   typedef std::list<ResourceInfo*> ResourceInfoList;
00113   ResourceInfoList js_resources_info_;
00114   bool defer_javascript_enabled_;
00115   bool split_html_enabled_;
00116   bool is_flushing_critical_style_element_;
00117   GoogleString css_output_content_;
00118   GoogleString flush_early_content_;
00119   bool flush_more_resources_early_if_time_permits_;
00120   bool stylesheets_flushed_;
00121 
00122   DISALLOW_COPY_AND_ASSIGN(FlushEarlyContentWriterFilter);
00123 };
00124 
00125 }  
00126 
00127 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_FLUSH_EARLY_CONTENT_WRITER_FILTER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines