Page Speed Optimization Libraries
1.3.25.1
|
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 kCriticalImagesBeaconJs, 00053 kDeferIframe, 00054 kDeferJs, 00055 kDelayImagesJs, 00056 kDelayImagesInlineJs, 00057 kDeterministicJs, 00058 kLazyloadImagesJs, 00059 kDetectReflowJs, 00060 kLocalStorageCacheJs, 00061 kEndOfModules, 00062 }; 00063 00064 StaticAssetManager(UrlNamer* url_namer, Hasher* hasher, 00065 MessageHandler* message_handler); 00066 00067 ~StaticAssetManager(); 00068 00071 const GoogleString& GetAssetUrl(const StaticAsset& module, 00072 const RewriteOptions* options) const; 00073 00074 const char* GetAsset(const StaticAsset& module, 00075 const RewriteOptions* options) const; 00076 00082 bool GetAsset(StringPiece file_name, StringPiece* content, 00083 ContentType* content_type, 00084 StringPiece* cache_header) const; 00085 00089 void AddJsToElement(StringPiece js, HtmlElement* script, 00090 RewriteDriver* driver) const; 00091 00092 00095 void set_gstatic_hash(const StaticAsset& module, const GoogleString& hash); 00096 00102 void set_serve_asset_from_gstatic(bool serve_asset_from_gstatic) { 00103 serve_asset_from_gstatic_ = serve_asset_from_gstatic; 00104 } 00105 00107 void set_library_url_prefix(const StringPiece& url_prefix) { 00108 url_prefix.CopyToString(&library_url_prefix_); 00109 InitializeAssetUrls(); 00110 } 00111 00112 private: 00113 class Asset; 00114 00115 typedef std::map<GoogleString, StaticAsset> FileNameToModuleMap; 00116 00117 void InitializeAssetStrings(); 00118 void InitializeAssetUrls(); 00119 00121 UrlNamer* url_namer_; 00122 Hasher* hasher_; 00123 MessageHandler* message_handler_; 00124 00125 std::vector<Asset*> assets_; 00126 FileNameToModuleMap file_name_to_module_map_; 00127 00128 bool serve_asset_from_gstatic_; 00129 GoogleString library_url_prefix_; 00130 GoogleString cache_header_with_long_ttl_; 00131 GoogleString cache_header_with_private_ttl_; 00132 00133 DISALLOW_COPY_AND_ASSIGN(StaticAssetManager); 00134 }; 00135 00136 } 00137 00138 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_STATIC_ASSET_MANAGER_H_