Page Speed Optimization Libraries
1.5.27.2
|
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 #include "net/instaweb/util/public/basictypes.h" 00025 #include "net/instaweb/util/public/string.h" 00026 #include "net/instaweb/util/public/string_util.h" 00027 00028 namespace net_instaweb { 00029 00030 class ContentType; 00031 class Hasher; 00032 class HtmlElement; 00033 class MessageHandler; 00034 class RewriteDriver; 00035 class RewriteOptions; 00036 class UrlNamer; 00037 00038 00042 class StaticAssetManager { 00043 public: 00044 static const char kGStaticBase[]; 00045 static const char kDefaultLibraryUrlPrefix[]; 00046 00047 enum StaticAsset { 00048 kAddInstrumentationJs, 00049 kBlankGif, 00050 kBlinkJs, 00051 kClientDomainRewriter, 00052 kCriticalCssBeaconJs, 00053 kCriticalImagesBeaconJs, 00054 kDeferIframe, 00055 kDeferJs, 00056 kDelayImagesJs, 00057 kDelayImagesInlineJs, 00058 kDeterministicJs, 00059 kLazyloadImagesJs, 00060 kDetectReflowJs, 00061 kLocalStorageCacheJs, 00062 kExtendedInstrumentationJs, 00063 kEndOfModules, 00064 }; 00065 00066 StaticAssetManager(UrlNamer* url_namer, Hasher* hasher, 00067 MessageHandler* message_handler); 00068 00069 ~StaticAssetManager(); 00070 00073 const GoogleString& GetAssetUrl(const StaticAsset& module, 00074 const RewriteOptions* options) const; 00075 00076 const char* GetAsset(const StaticAsset& module, 00077 const RewriteOptions* options) const; 00078 00084 bool GetAsset(StringPiece file_name, StringPiece* content, 00085 ContentType* content_type, 00086 StringPiece* cache_header) const; 00087 00091 void AddJsToElement(StringPiece js, HtmlElement* script, 00092 RewriteDriver* driver) const; 00093 00094 00097 void set_gstatic_hash(const StaticAsset& module, const GoogleString& hash); 00098 00104 void set_serve_asset_from_gstatic(bool serve_asset_from_gstatic) { 00105 serve_asset_from_gstatic_ = serve_asset_from_gstatic; 00106 } 00107 00109 void set_library_url_prefix(const StringPiece& url_prefix) { 00110 url_prefix.CopyToString(&library_url_prefix_); 00111 InitializeAssetUrls(); 00112 } 00113 00114 private: 00115 class Asset; 00116 00117 typedef std::map<GoogleString, StaticAsset> FileNameToModuleMap; 00118 00119 void InitializeAssetStrings(); 00120 void InitializeAssetUrls(); 00121 00123 UrlNamer* url_namer_; 00124 Hasher* hasher_; 00125 MessageHandler* message_handler_; 00126 00127 std::vector<Asset*> assets_; 00128 FileNameToModuleMap file_name_to_module_map_; 00129 00130 bool serve_asset_from_gstatic_; 00131 GoogleString library_url_prefix_; 00132 GoogleString cache_header_with_long_ttl_; 00133 GoogleString cache_header_with_private_ttl_; 00134 00135 DISALLOW_COPY_AND_ASSIGN(StaticAssetManager); 00136 }; 00137 00138 } 00139 00140 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_STATIC_ASSET_MANAGER_H_