Page Speed Optimization Libraries
1.2.24.1
|
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 name() const { return name_; } 00069 StringPiece hash() const { return hash_; } 00070 StringPiece ext() const { return ext_; } 00071 StringPiece experiment() const { return experiment_; } 00072 00073 bool has_experiment() const { return !experiment_.empty(); } 00074 00076 void set_id(const StringPiece& p) { p.CopyToString(&id_); } 00077 void set_name(const StringPiece& n) { n.CopyToString(&name_); } 00078 void set_hash(const StringPiece& h) { h.CopyToString(&hash_); } 00079 void set_ext(const StringPiece& e) { 00082 CHECK(e.empty() || e[0] != '.'); 00083 e.CopyToString(&ext_); 00084 } 00085 void set_experiment(const StringPiece& e) { e.CopyToString(&experiment_); } 00086 00088 void ClearHash() { hash_.clear(); } 00089 void CopyFrom(const ResourceNamer& other); 00090 00092 00094 GoogleString PrettyName() const {return InternalEncode(); } 00095 00097 const ContentType* ContentTypeFromExt() const; 00098 00099 private: 00100 GoogleString InternalEncode() const; 00101 bool LegacyDecode(const StringPiece& encoded_string); 00102 00103 GoogleString id_; 00104 GoogleString name_; 00105 GoogleString hash_; 00106 GoogleString ext_; 00107 GoogleString experiment_; 00108 00109 DISALLOW_COPY_AND_ASSIGN(ResourceNamer); 00110 }; 00111 00112 } 00113 00114 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_RESOURCE_NAMER_H_