Page Speed Optimization Libraries  1.9.32.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
static_asset_manager.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  */
16 
18 
19 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_STATIC_ASSET_MANAGER_H_
20 #define NET_INSTAWEB_REWRITER_PUBLIC_STATIC_ASSET_MANAGER_H_
21 
22 #include <map>
23 #include <vector>
24 
28 
29 namespace net_instaweb {
30 
31 class Hasher;
32 class HtmlElement;
33 class MessageHandler;
34 class RewriteDriver;
35 class RewriteOptions;
36 struct ContentType;
37 
45  public:
46  static const char kGStaticBase[];
47  static const char kDefaultLibraryUrlPrefix[];
48 
49  enum StaticAsset {
50  kAddInstrumentationJs,
51  kBlankGif,
52  kBlinkJs,
53  kClientDomainRewriter,
54  kCriticalCssBeaconJs,
55  kCriticalCssLoaderJs,
56  kCriticalImagesBeaconJs,
57  kDedupInlinedImagesJs,
58  kDeferIframe,
59  kDeferJs,
60  kDelayImagesInlineJs,
61  kDelayImagesJs,
62  kDeterministicJs,
63  kExtendedInstrumentationJs,
64  kGhostClickBusterJs,
65  kLazyloadImagesJs,
66  kLocalStorageCacheJs,
67  kSplitHtmlBeaconJs,
69  };
70 
71  StaticAssetManager(const GoogleString& static_asset_base,
72  Hasher* hasher,
73  MessageHandler* message_handler);
74 
76 
79  const GoogleString& GetAssetUrl(const StaticAsset& module,
80  const RewriteOptions* options) const;
81 
83  const char* GetAsset(const StaticAsset& module,
84  const RewriteOptions* options) const;
85 
91  bool GetAsset(StringPiece file_name, StringPiece* content,
92  ContentType* content_type, StringPiece* cache_header) const;
93 
97  void AddJsToElement(StringPiece js, HtmlElement* script,
98  RewriteDriver* driver) const;
99 
100 
103  void set_gstatic_hash(const StaticAsset& module,
104  const GoogleString& gstatic_base,
105  const GoogleString& hash);
106 
112  void set_serve_asset_from_gstatic(bool serve_asset_from_gstatic) {
113  serve_asset_from_gstatic_ = serve_asset_from_gstatic;
114  }
115 
117  void set_library_url_prefix(const StringPiece& url_prefix) {
118  url_prefix.CopyToString(&library_url_prefix_);
119  InitializeAssetUrls();
120  }
121 
122  void set_static_asset_base(const StringPiece& x) {
123  x.CopyToString(&static_asset_base_);
124  InitializeAssetUrls();
125  }
126 
127  private:
128  class Asset;
129 
130  typedef std::map<GoogleString, StaticAsset> FileNameToModuleMap;
131 
132  void InitializeAssetStrings();
133  void InitializeAssetUrls();
134 
135  GoogleString static_asset_base_;
137  Hasher* hasher_;
138  MessageHandler* message_handler_;
139 
140  std::vector<Asset*> assets_;
141  FileNameToModuleMap file_name_to_module_map_;
142 
143  bool serve_asset_from_gstatic_;
144  GoogleString library_url_prefix_;
145  GoogleString cache_header_with_long_ttl_;
146  GoogleString cache_header_with_private_ttl_;
147 
148  DISALLOW_COPY_AND_ASSIGN(StaticAssetManager);
149 };
150 
151 }
152 
153 #endif
void set_serve_asset_from_gstatic(bool serve_asset_from_gstatic)
Definition: static_asset_manager.h:112
const char * GetAsset(const StaticAsset &module, const RewriteOptions *options) const
Returns the contents of the asset.
void AddJsToElement(StringPiece js, HtmlElement *script, RewriteDriver *driver) const
Definition: static_asset_manager.h:44
const GoogleString & GetAssetUrl(const StaticAsset &module, const RewriteOptions *options) const
void set_gstatic_hash(const StaticAsset &module, const GoogleString &gstatic_base, const GoogleString &hash)
void set_library_url_prefix(const StringPiece &url_prefix)
Set the prefix for the URLs of assets.
Definition: static_asset_manager.h:117
Definition: rewrite_driver.h:98
StaticAsset
Definition: static_asset_manager.h:49
Definition: rewrite_options.h:81
Keep this as the last enum value.
Definition: static_asset_manager.h:68