Page Speed Optimization Libraries  1.3.25.1
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 HtmlElement;
00038 class RewriteDriver;
00039 class TimedVariable;
00040 class Writer;
00041 
00042 struct ResourceInfo;
00043 
00048 class FlushEarlyContentWriterFilter : public HtmlWriterFilter {
00049  public:
00050   static const char kPrefetchLinkRelSubresourceHtml[];
00051   static const char kPrefetchImageTagHtml[];
00052   static const char kPrefetchStartTimeScript[];
00053   static const char kNumResourcesFlushedEarly[];
00054   static const char kPrefetchScriptTagHtml[];
00055   static const char kPrefetchLinkTagHtml[];
00056 
00057   explicit FlushEarlyContentWriterFilter(RewriteDriver* driver);
00058 
00059   virtual void StartDocument();
00060   virtual void EndDocument();
00061 
00062   virtual void StartElement(HtmlElement* element);
00063   virtual void EndElement(HtmlElement* element);
00064 
00065  protected:
00066   virtual void Clear();
00067 
00068  private:
00070   void WriteToOriginalWriter(const GoogleString& in);
00071 
00073   bool IsFlushable(const GoogleUrl& gurl, bool is_pagespeed_resource);
00074 
00076   void FlushResources(
00077       StringPiece url,
00078       int64 time_to_download,
00079       bool is_pagespeed_resource,
00080       semantic_type::Category category);
00081 
00082   void TryFlushingDeferJavascriptEarly();
00083 
00085   FlushEarlyResourceInfo::ResourceType GetResourceType(
00086       const GoogleUrl& gurl, bool is_pagespeed_resource);
00087 
00088   RewriteDriver* driver_;
00089   TimedVariable* num_resources_flushed_early_;
00091   bool in_body_;
00092   bool insert_close_script_;
00093   int num_resources_flushed_;
00094   NullWriter null_writer_;
00095   Writer* original_writer_;
00096   HtmlElement* current_element_;
00097   UserAgentMatcher::PrefetchMechanism prefetch_mechanism_;
00098   scoped_ptr<StringSet> private_cacheable_resources_;
00099   int64 time_consumed_ms_;
00100   int64 max_available_time_ms_;
00101   typedef std::list<ResourceInfo*> ResourceInfoList;
00102   ResourceInfoList js_resources_info_;
00103   bool defer_javascript_enabled_;
00104   GoogleString flush_early_content_;
00105 
00106   DISALLOW_COPY_AND_ASSIGN(FlushEarlyContentWriterFilter);
00107 };
00108 
00109 }  
00110 
00111 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_FLUSH_EARLY_CONTENT_WRITER_FILTER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines