Page Speed Optimization Libraries
1.5.27.2
|
00001 // Copyright 2010 Google Inc. 00016 00017 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_NAMER_H_ 00018 #define NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_NAMER_H_ 00019 00020 #include "base/logging.h" 00021 #include "net/instaweb/util/public/basictypes.h" 00022 #include "net/instaweb/util/public/string.h" 00023 #include "net/instaweb/util/public/string_util.h" 00024 00025 namespace net_instaweb { 00026 00027 class ContentType; 00028 class Hasher; 00029 00033 class ResourceNamer { 00034 public: 00037 static const int kOverhead; 00038 00039 ResourceNamer() {} 00040 ~ResourceNamer() {} 00041 00043 00046 bool Decode(const StringPiece& encoded_string); 00047 00050 GoogleString Encode() const; 00051 00058 GoogleString EncodeIdName() const; 00059 00061 00064 int EventualSize(const Hasher& hasher) const; 00065 00067 StringPiece id() const { return id_; } 00068 StringPiece options() const { return options_; } 00069 StringPiece name() const { return name_; } 00070 StringPiece hash() const { return hash_; } 00071 StringPiece ext() const { return ext_; } 00072 StringPiece experiment() const { return experiment_; } 00073 00074 bool has_experiment() const { return !experiment_.empty(); } 00075 bool has_options() const { return !options_.empty(); } 00076 00078 void set_id(const StringPiece& p) { p.CopyToString(&id_); } 00079 void set_options(const StringPiece& opts) { opts.CopyToString(&options_); } 00080 void set_name(const StringPiece& n) { n.CopyToString(&name_); } 00081 void set_hash(const StringPiece& h) { h.CopyToString(&hash_); } 00082 void set_ext(const StringPiece& e) { 00085 CHECK(e.empty() || e[0] != '.'); 00086 e.CopyToString(&ext_); 00087 } 00088 void set_experiment(const StringPiece& e) { e.CopyToString(&experiment_); } 00089 00091 void ClearHash() { hash_.clear(); } 00092 void CopyFrom(const ResourceNamer& other); 00093 00095 00097 GoogleString PrettyName() const {return InternalEncode(); } 00098 00100 const ContentType* ContentTypeFromExt() const; 00101 00102 private: 00103 GoogleString InternalEncode() const; 00104 bool LegacyDecode(const StringPiece& encoded_string); 00105 00106 GoogleString id_; 00107 GoogleString options_; 00108 GoogleString name_; 00109 GoogleString hash_; 00110 GoogleString ext_; 00111 GoogleString experiment_; 00112 00113 DISALLOW_COPY_AND_ASSIGN(ResourceNamer); 00114 }; 00115 00116 } 00117 00118 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_NAMER_H_