Page Speed Optimization Libraries  1.9.32.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
flush_early_content_writer_filter.h
Go to the documentation of this file.
1 /*
2  * Copyright 2012 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http:///www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
17 
18 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_FLUSH_EARLY_CONTENT_WRITER_FILTER_H_
19 #define NET_INSTAWEB_REWRITER_PUBLIC_FLUSH_EARLY_CONTENT_WRITER_FILTER_H_
20 
21 #include <list>
22 
23 #include "net/instaweb/htmlparse/public/html_writer_filter.h"
26 #include "net/instaweb/http/public/semantic_type.h"
27 #include "net/instaweb/http/public/user_agent_matcher.h"
29 #include "net/instaweb/util/public/null_writer.h"
33 
34 namespace net_instaweb {
35 
36 class GoogleUrl;
37 class HtmlCharactersNode;
38 class HtmlElement;
39 class RewriteDriver;
40 class TimedVariable;
41 class Writer;
42 
43 struct ResourceInfo;
44 
49 class FlushEarlyContentWriterFilter : public HtmlWriterFilter {
50  public:
51  static const char kDisableLinkTag[];
52  static const char kPrefetchImageTagHtml[];
53  static const char kPrefetchStartTimeScript[];
54  static const char kNumResourcesFlushedEarly[];
55  static const char kPrefetchScriptTagHtml[];
56  static const char kPrefetchLinkTagHtml[];
57  static const char kFlushEarlyStyleTemplate[];
58 
60 
61  virtual void StartDocument();
62  virtual void EndDocument();
63 
64  virtual void StartElement(HtmlElement* element);
65  virtual void EndElement(HtmlElement* element);
66 
67  virtual void Characters(HtmlCharactersNode* characters_node);
68 
69  protected:
70  virtual void Clear();
71 
72  private:
74  void WriteToOriginalWriter(const GoogleString& in);
75 
77  bool IsFlushable(const GoogleUrl& gurl,
78  const FlushEarlyResourceInfo::ResourceType& resource_type);
79 
81  void FlushResourceAsImage(StringPiece url);
82 
84  void FlushResources(
85  StringPiece url,
86  int64 time_to_download,
87  bool is_pagespeed_resource,
88  semantic_type::Category category);
89 
90  void FlushDeferJavascriptEarly();
91  void UpdateStats(int64 time_to_download, bool is_pagespeed_resource);
92  GoogleString ComputeFlushEarlyCriticalCss(const GoogleString& style_id);
93 
95  FlushEarlyResourceInfo::ResourceType GetResourceType(
96  const GoogleUrl& gurl, bool is_pagespeed_resource);
97 
98  RewriteDriver* driver_;
99  TimedVariable* num_resources_flushed_early_;
101  bool in_body_;
102  bool insert_close_script_;
103  int num_resources_flushed_;
104  NullWriter null_writer_;
105  Writer* original_writer_;
106  HtmlElement* current_element_;
107  UserAgentMatcher::PrefetchMechanism prefetch_mechanism_;
108  scoped_ptr<StringSet> private_cacheable_resources_;
109  scoped_ptr<StringSet> public_cacheable_resources_;
110  int64 time_consumed_ms_;
111  int64 max_available_time_ms_;
112  typedef std::list<ResourceInfo*> ResourceInfoList;
113  ResourceInfoList js_resources_info_;
114  bool defer_javascript_enabled_;
115  bool split_html_enabled_;
116  bool is_flushing_critical_style_element_;
117  GoogleString css_output_content_;
118  GoogleString flush_early_content_;
119  bool flush_more_resources_early_if_time_permits_;
120  bool stylesheets_flushed_;
121 
122  DISALLOW_COPY_AND_ASSIGN(FlushEarlyContentWriterFilter);
123 };
124 
125 }
126 
127 #endif
Definition: rewrite_driver.h:98
Definition: flush_early_content_writer_filter.h:49