Page Speed Optimization Libraries  1.4.26.1
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 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     kEndOfModules,  
00063   };
00064 
00065   StaticAssetManager(UrlNamer* url_namer, Hasher* hasher,
00066                      MessageHandler* message_handler);
00067 
00068   ~StaticAssetManager();
00069 
00072   const GoogleString& GetAssetUrl(const StaticAsset& module,
00073                                   const RewriteOptions* options) const;
00074 
00075   const char* GetAsset(const StaticAsset& module,
00076                               const RewriteOptions* options) const;
00077 
00083   bool GetAsset(StringPiece file_name, StringPiece* content,
00084                        ContentType* content_type,
00085                        StringPiece* cache_header) const;
00086 
00090   void AddJsToElement(StringPiece js, HtmlElement* script,
00091                       RewriteDriver* driver) const;
00092 
00093 
00096   void set_gstatic_hash(const StaticAsset& module, const GoogleString& hash);
00097 
00103   void set_serve_asset_from_gstatic(bool serve_asset_from_gstatic) {
00104     serve_asset_from_gstatic_ = serve_asset_from_gstatic;
00105   }
00106 
00108   void set_library_url_prefix(const StringPiece& url_prefix) {
00109     url_prefix.CopyToString(&library_url_prefix_);
00110     InitializeAssetUrls();
00111   }
00112 
00113  private:
00114   class Asset;
00115 
00116   typedef std::map<GoogleString, StaticAsset> FileNameToModuleMap;
00117 
00118   void InitializeAssetStrings();
00119   void InitializeAssetUrls();
00120 
00122   UrlNamer* url_namer_;
00123   Hasher* hasher_;
00124   MessageHandler* message_handler_;
00125 
00126   std::vector<Asset*> assets_;
00127   FileNameToModuleMap file_name_to_module_map_;
00128 
00129   bool serve_asset_from_gstatic_;
00130   GoogleString library_url_prefix_;
00131   GoogleString cache_header_with_long_ttl_;
00132   GoogleString cache_header_with_private_ttl_;
00133 
00134   DISALLOW_COPY_AND_ASSIGN(StaticAssetManager);
00135 };
00136 
00137 }  
00138 
00139 #endif  ///< NET_INSTAWEB_REWRITER_PUBLIC_STATIC_ASSET_MANAGER_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines