Page Speed Optimization Libraries
1.8.31.3
|
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 Hasher; 00028 00032 class ResourceNamer { 00033 public: 00036 static const int kOverhead; 00037 00038 ResourceNamer() {} 00039 ~ResourceNamer() {} 00040 00042 00045 bool Decode(const StringPiece& encoded_string); 00046 00049 GoogleString Encode() const; 00050 00057 GoogleString EncodeIdName() const; 00058 00060 00063 int EventualSize(const Hasher& hasher) const; 00064 00066 StringPiece id() const { return id_; } 00067 StringPiece options() const { return options_; } 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 bool has_options() const { return !options_.empty(); } 00075 00077 void set_id(const StringPiece& p) { p.CopyToString(&id_); } 00078 void set_options(const StringPiece& opts) { opts.CopyToString(&options_); } 00079 void set_name(const StringPiece& n) { n.CopyToString(&name_); } 00080 void set_hash(const StringPiece& h) { h.CopyToString(&hash_); } 00081 void set_ext(const StringPiece& e) { 00084 CHECK(e.empty() || e[0] != '.'); 00085 e.CopyToString(&ext_); 00086 } 00087 void set_experiment(const StringPiece& e) { e.CopyToString(&experiment_); } 00088 00090 void ClearHash() { hash_.clear(); } 00091 void CopyFrom(const ResourceNamer& other); 00092 00094 00096 GoogleString PrettyName() const {return InternalEncode(); } 00097 00098 private: 00099 GoogleString InternalEncode() const; 00100 bool LegacyDecode(const StringPiece& encoded_string); 00101 00102 GoogleString id_; 00103 GoogleString options_; 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_