Page Speed Optimization Libraries  1.6.29.3
net/instaweb/rewriter/public/static_asset_manager.h
Go to the documentation of this file.
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 Hasher;
00031 class HtmlElement;
00032 class MessageHandler;
00033 class RewriteDriver;
00034 class RewriteOptions;
00035 class UrlNamer;
00036 struct ContentType;
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     kDedupInlinedImagesJs,
00055     kDeferIframe,
00056     kDeferJs,
00057     kDelayImagesJs,
00058     kDelayImagesInlineJs,
00059     kDetectReflowJs,
00060     kDeterministicJs,
00061     kGhostClickBusterJs,
00062     kLazyloadImagesJs,
00063     kLocalStorageCacheJs,
00064     kExtendedInstrumentationJs,
00065     kEndOfModules,  
00066   };
00067 
00068   StaticAssetManager(UrlNamer* url_namer, Hasher* hasher,
00069                      MessageHandler* message_handler);
00070 
00071   ~StaticAssetManager();
00072 
00075   const GoogleString& GetAssetUrl(const StaticAsset& module,
00076                                   const RewriteOptions* options) const;
00077 
00078   const char* GetAsset(const StaticAsset& module,
00079                               const RewriteOptions* options) const;
00080 
00086   bool GetAsset(StringPiece file_name, StringPiece* content,
00087                        ContentType* content_type,
00088                        StringPiece* cache_header) const;
00089 
00093   void AddJsToElement(StringPiece js, HtmlElement* script,
00094                       RewriteDriver* driver) const;
00095 
00096 
00099   void set_gstatic_hash(const StaticAsset& module,
00100                         const GoogleString& gstatic_base,
00101                         const GoogleString& hash);
00102 
00108   void set_serve_asset_from_gstatic(bool serve_asset_from_gstatic) {
00109     serve_asset_from_gstatic_ = serve_asset_from_gstatic;
00110   }
00111 
00113   void set_library_url_prefix(const StringPiece& url_prefix) {
00114     url_prefix.CopyToString(&library_url_prefix_);
00115     InitializeAssetUrls();
00116   }
00117 
00118  private:
00119   class Asset;
00120 
00121   typedef std::map<GoogleString, StaticAsset> FileNameToModuleMap;
00122 
00123   void InitializeAssetStrings();
00124   void InitializeAssetUrls();
00125 
00127   UrlNamer* url_namer_;
00128   Hasher* hasher_;
00129   MessageHandler* message_handler_;
00130 
00131   std::vector<Asset*> assets_;
00132   FileNameToModuleMap file_name_to_module_map_;
00133 
00134   bool serve_asset_from_gstatic_;
00135   GoogleString library_url_prefix_;
00136   GoogleString cache_header_with_long_ttl_;
00137   GoogleString cache_header_with_private_ttl_;
00138 
00139   DISALLOW_COPY_AND_ASSIGN(StaticAssetManager);
00140 };
00141 
00142 }  
00143 
00144 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_STATIC_ASSET_MANAGER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines