Page Speed Optimization Libraries
1.8.31.3
|
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_REWRITER_PUBLIC_STATIC_ASSET_MANAGER_H_ 00020 #define NET_INSTAWEB_REWRITER_PUBLIC_STATIC_ASSET_MANAGER_H_ 00021 00022 #include <map> 00023 #include <vector> 00024 00025 #include "net/instaweb/util/public/basictypes.h" 00026 #include "net/instaweb/util/public/string.h" 00027 #include "net/instaweb/util/public/string_util.h" 00028 00029 namespace net_instaweb { 00030 00031 class Hasher; 00032 class HtmlElement; 00033 class MessageHandler; 00034 class RewriteDriver; 00035 class RewriteOptions; 00036 struct ContentType; 00037 00041 class StaticAssetManager { 00042 public: 00043 static const char kGStaticBase[]; 00044 static const char kDefaultLibraryUrlPrefix[]; 00045 00046 enum StaticAsset { 00047 kAddInstrumentationJs, 00048 kBlankGif, 00049 kBlinkJs, 00050 kClientDomainRewriter, 00051 kConsoleCss, 00052 kConsoleJs, 00053 kCriticalCssBeaconJs, 00054 kCriticalCssLoaderJs, 00055 kCriticalImagesBeaconJs, 00056 kDedupInlinedImagesJs, 00057 kDeferIframe, 00058 kDeferJs, 00059 kDelayImagesInlineJs, 00060 kDelayImagesJs, 00061 kDeterministicJs, 00062 kExtendedInstrumentationJs, 00063 kGhostClickBusterJs, 00064 kLazyloadImagesJs, 00065 kLocalStorageCacheJs, 00066 kSplitHtmlBeaconJs, 00067 kEndOfModules, 00068 }; 00069 00070 StaticAssetManager(const GoogleString& static_asset_base, 00071 Hasher* hasher, 00072 MessageHandler* message_handler); 00073 00074 ~StaticAssetManager(); 00075 00078 const GoogleString& GetAssetUrl(const StaticAsset& module, 00079 const RewriteOptions* options) const; 00080 00082 const char* GetAsset(const StaticAsset& module, 00083 const RewriteOptions* options) const; 00084 00090 bool GetAsset(StringPiece file_name, StringPiece* content, 00091 ContentType* content_type, StringPiece* cache_header) const; 00092 00096 void AddJsToElement(StringPiece js, HtmlElement* script, 00097 RewriteDriver* driver) const; 00098 00099 00102 void set_gstatic_hash(const StaticAsset& module, 00103 const GoogleString& gstatic_base, 00104 const GoogleString& hash); 00105 00111 void set_serve_asset_from_gstatic(bool serve_asset_from_gstatic) { 00112 serve_asset_from_gstatic_ = serve_asset_from_gstatic; 00113 } 00114 00116 void set_library_url_prefix(const StringPiece& url_prefix) { 00117 url_prefix.CopyToString(&library_url_prefix_); 00118 InitializeAssetUrls(); 00119 } 00120 00121 void set_static_asset_base(const StringPiece& x) { 00122 x.CopyToString(&static_asset_base_); 00123 InitializeAssetUrls(); 00124 } 00125 00126 private: 00127 class Asset; 00128 00129 typedef std::map<GoogleString, StaticAsset> FileNameToModuleMap; 00130 00131 void InitializeAssetStrings(); 00132 void InitializeAssetUrls(); 00133 00134 GoogleString static_asset_base_; 00136 Hasher* hasher_; 00137 MessageHandler* message_handler_; 00138 00139 std::vector<Asset*> assets_; 00140 FileNameToModuleMap file_name_to_module_map_; 00141 00142 bool serve_asset_from_gstatic_; 00143 GoogleString library_url_prefix_; 00144 GoogleString cache_header_with_long_ttl_; 00145 GoogleString cache_header_with_private_ttl_; 00146 00147 DISALLOW_COPY_AND_ASSIGN(StaticAssetManager); 00148 }; 00149 00150 } 00151 00152 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_STATIC_ASSET_MANAGER_H_