| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file contains the SdchManager class and two nested classes | 5 // This file contains the SdchManager class and two nested classes |
| 6 // (Dictionary, DictionarySet). SdchManager::Dictionary contains all | 6 // (Dictionary, DictionarySet). SdchManager::Dictionary contains all |
| 7 // of the information about an SDCH dictionary. The manager is | 7 // of the information about an SDCH dictionary. The manager is |
| 8 // responsible for storing those dictionaries, and provides access to | 8 // responsible for storing those dictionaries, and provides access to |
| 9 // them through DictionarySet objects. A DictionarySet is an object | 9 // them through DictionarySet objects. A DictionarySet is an object |
| 10 // whose lifetime is under the control of the consumer. It is a | 10 // whose lifetime is under the control of the consumer. It is a |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 // module) to decompress data. | 52 // module) to decompress data. |
| 53 // | 53 // |
| 54 // A dictionary held by the manager may nonetheless outlive the manager if | 54 // A dictionary held by the manager may nonetheless outlive the manager if |
| 55 // a DictionarySet object refers to it; see below. | 55 // a DictionarySet object refers to it; see below. |
| 56 class NET_EXPORT SdchManager { | 56 class NET_EXPORT SdchManager { |
| 57 public: | 57 public: |
| 58 class Dictionary; | 58 class Dictionary; |
| 59 typedef std::map<std::string, scoped_refptr<base::RefCountedData<Dictionary>>> | 59 typedef std::map<std::string, scoped_refptr<base::RefCountedData<Dictionary>>> |
| 60 DictionaryMap; | 60 DictionaryMap; |
| 61 | 61 |
| 62 // Use the following static limits to block DOS attacks until we implement | |
| 63 // a cached dictionary evicition strategy. | |
| 64 static const size_t kMaxDictionarySize; | |
| 65 static const size_t kMaxDictionaryCount; | |
| 66 | |
| 67 class NET_EXPORT_PRIVATE Dictionary { | 62 class NET_EXPORT_PRIVATE Dictionary { |
| 68 public: | 63 public: |
| 69 // Construct a vc-diff usable dictionary from the dictionary_text starting | 64 // Construct a vc-diff usable dictionary from the dictionary_text starting |
| 70 // at the given offset. The supplied client_hash should be used to | 65 // at the given offset. The supplied client_hash should be used to |
| 71 // advertise the dictionary's availability relative to the suppplied URL. | 66 // advertise the dictionary's availability relative to the suppplied URL. |
| 72 Dictionary(const std::string& dictionary_text, | 67 Dictionary(const std::string& dictionary_text, |
| 73 size_t offset, | 68 size_t offset, |
| 74 const std::string& client_hash, | 69 const std::string& client_hash, |
| 70 const std::string& server_hash, |
| 75 const GURL& url, | 71 const GURL& url, |
| 76 const std::string& domain, | 72 const std::string& domain, |
| 77 const std::string& path, | 73 const std::string& path, |
| 78 const base::Time& expiration, | 74 const base::Time& expiration, |
| 79 const std::set<int>& ports); | 75 const std::set<int>& ports); |
| 80 | 76 |
| 81 ~Dictionary(); | 77 ~Dictionary(); |
| 82 | 78 |
| 83 // Sdch filters can get our text to use in decoding compressed data. | 79 // Sdch filters can get our text to use in decoding compressed data. |
| 84 const std::string& text() const { return text_; } | 80 const std::string& text() const { return text_; } |
| 85 | 81 |
| 86 const GURL& url() const { return url_; } | 82 const GURL& url() const { return url_; } |
| 87 const std::string& client_hash() const { return client_hash_; } | 83 const std::string& client_hash() const { return client_hash_; } |
| 84 const std::string& server_hash() const { return server_hash_; } |
| 88 const std::string& domain() const { return domain_; } | 85 const std::string& domain() const { return domain_; } |
| 89 const std::string& path() const { return path_; } | 86 const std::string& path() const { return path_; } |
| 90 const base::Time& expiration() const { return expiration_; } | 87 const base::Time& expiration() const { return expiration_; } |
| 91 const std::set<int>& ports() const { return ports_; } | 88 const std::set<int>& ports() const { return ports_; } |
| 92 | 89 |
| 93 // Security methods to check if we can establish a new dictionary with the | 90 // Security methods to check if we can establish a new dictionary with the |
| 94 // given data, that arrived in response to get of dictionary_url. | 91 // given data, that arrived in response to get of dictionary_url. |
| 95 static SdchProblemCode CanSet(const std::string& domain, | 92 static SdchProblemCode CanSet(const std::string& domain, |
| 96 const std::string& path, | 93 const std::string& path, |
| 97 const std::set<int>& ports, | 94 const std::set<int>& ports, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 121 // CopyConstructible | 118 // CopyConstructible |
| 122 Dictionary(const Dictionary& rhs); | 119 Dictionary(const Dictionary& rhs); |
| 123 | 120 |
| 124 // The actual text of the dictionary. | 121 // The actual text of the dictionary. |
| 125 std::string text_; | 122 std::string text_; |
| 126 | 123 |
| 127 // Part of the hash of text_ that the client uses to advertise the fact that | 124 // Part of the hash of text_ that the client uses to advertise the fact that |
| 128 // it has a specific dictionary pre-cached. | 125 // it has a specific dictionary pre-cached. |
| 129 std::string client_hash_; | 126 std::string client_hash_; |
| 130 | 127 |
| 128 // Part of the hash of text_ that the server uses to identify the |
| 129 // dictionary it wants used for decoding. |
| 130 std::string server_hash_; |
| 131 |
| 131 // The GURL that arrived with the text_ in a URL request to specify where | 132 // The GURL that arrived with the text_ in a URL request to specify where |
| 132 // this dictionary may be used. | 133 // this dictionary may be used. |
| 133 const GURL url_; | 134 const GURL url_; |
| 134 | 135 |
| 135 // Metadate "headers" in before dictionary text contained the following: | 136 // Metadate "headers" in before dictionary text contained the following: |
| 136 // Each dictionary payload consists of several headers, followed by the text | 137 // Each dictionary payload consists of several headers, followed by the text |
| 137 // of the dictionary. The following are the known headers. | 138 // of the dictionary. The following are the known headers. |
| 138 const std::string domain_; | 139 const std::string domain_; |
| 139 const std::string path_; | 140 const std::string path_; |
| 140 const base::Time expiration_; // Implied by max-age. | 141 const base::Time expiration_; // Implied by max-age. |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 // supported domain (i.e., not blacklisted, and either the specific supported | 227 // supported domain (i.e., not blacklisted, and either the specific supported |
| 227 // domain, or all domains were assumed supported). If it is blacklist, reduce | 228 // domain, or all domains were assumed supported). If it is blacklist, reduce |
| 228 // by 1 the number of times it will be reported as blacklisted. | 229 // by 1 the number of times it will be reported as blacklisted. |
| 229 SdchProblemCode IsInSupportedDomain(const GURL& url); | 230 SdchProblemCode IsInSupportedDomain(const GURL& url); |
| 230 | 231 |
| 231 // Send out appropriate events notifying observers that a Get-Dictionary | 232 // Send out appropriate events notifying observers that a Get-Dictionary |
| 232 // header has been seen. | 233 // header has been seen. |
| 233 SdchProblemCode OnGetDictionary(const GURL& request_url, | 234 SdchProblemCode OnGetDictionary(const GURL& request_url, |
| 234 const GURL& dictionary_url); | 235 const GURL& dictionary_url); |
| 235 | 236 |
| 237 // Send out appropriate events notifying observers that a dictionary |
| 238 // was successfully used to decode a request. |
| 239 void OnDictionaryUsed(const std::string& server_hash); |
| 240 |
| 236 // Get a handle to the available dictionaries that might be used | 241 // Get a handle to the available dictionaries that might be used |
| 237 // for encoding responses for the given URL. The return set will not | 242 // for encoding responses for the given URL. The return set will not |
| 238 // include expired dictionaries. If no dictionaries | 243 // include expired dictionaries. If no dictionaries |
| 239 // are appropriate to use with the target_url, NULL is returned. | 244 // are appropriate to use with the target_url, NULL is returned. |
| 240 scoped_ptr<DictionarySet> GetDictionarySet(const GURL& target_url); | 245 scoped_ptr<DictionarySet> GetDictionarySet(const GURL& target_url); |
| 241 | 246 |
| 242 // Get a handle to a specific dictionary, by its server hash, confirming | 247 // Get a handle to a specific dictionary, by its server hash, confirming |
| 243 // that that specific dictionary is appropriate to use with |target_url|. | 248 // that that specific dictionary is appropriate to use with |target_url|. |
| 244 // Expired dictionaries will be returned. If no dictionary with that | 249 // Expired dictionaries will be returned. If no dictionary with that |
| 245 // hash exists that is usable with |target_url|, NULL is returned. | 250 // hash exists that is usable with |target_url|, NULL is returned. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 263 bool AllowLatencyExperiment(const GURL& url) const; | 268 bool AllowLatencyExperiment(const GURL& url) const; |
| 264 | 269 |
| 265 void SetAllowLatencyExperiment(const GURL& url, bool enable); | 270 void SetAllowLatencyExperiment(const GURL& url, bool enable); |
| 266 | 271 |
| 267 base::Value* SdchInfoToValue() const; | 272 base::Value* SdchInfoToValue() const; |
| 268 | 273 |
| 269 // Add an SDCH dictionary to our list of availible | 274 // Add an SDCH dictionary to our list of availible |
| 270 // dictionaries. This addition will fail if addition is illegal | 275 // dictionaries. This addition will fail if addition is illegal |
| 271 // (data in the dictionary is not acceptable from the | 276 // (data in the dictionary is not acceptable from the |
| 272 // dictionary_url; dictionary already added, etc.). | 277 // dictionary_url; dictionary already added, etc.). |
| 278 // If |server_hash| is non-null, returns the server hash that may be |
| 279 // used as an argument to GetDictionarySetByHash. |
| 273 // Returns SDCH_OK if the addition was successfull, and corresponding error | 280 // Returns SDCH_OK if the addition was successfull, and corresponding error |
| 274 // code otherwise. | 281 // code otherwise. |
| 275 SdchProblemCode AddSdchDictionary(const std::string& dictionary_text, | 282 SdchProblemCode AddSdchDictionary(const std::string& dictionary_text, |
| 276 const GURL& dictionary_url); | 283 const GURL& dictionary_url, |
| 284 std::string* server_hash_p); |
| 285 |
| 286 // Remove an SDCH dictionary |
| 287 SdchProblemCode RemoveSdchDictionary(const std::string& server_hash); |
| 277 | 288 |
| 278 // Registration for events generated by the SDCH subsystem. | 289 // Registration for events generated by the SDCH subsystem. |
| 279 void AddObserver(SdchObserver* observer); | 290 void AddObserver(SdchObserver* observer); |
| 280 void RemoveObserver(SdchObserver* observer); | 291 void RemoveObserver(SdchObserver* observer); |
| 281 | 292 |
| 282 static scoped_ptr<DictionarySet> CreateEmptyDictionarySetForTesting(); | 293 static scoped_ptr<DictionarySet> CreateEmptyDictionarySetForTesting(); |
| 283 | 294 |
| 284 private: | 295 private: |
| 285 struct BlacklistInfo { | 296 struct BlacklistInfo { |
| 286 BlacklistInfo() : count(0), exponential_count(0), reason(SDCH_OK) {} | 297 BlacklistInfo() : count(0), exponential_count(0), reason(SDCH_OK) {} |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 ObserverList<SdchObserver, true> observers_; | 337 ObserverList<SdchObserver, true> observers_; |
| 327 | 338 |
| 328 base::ThreadChecker thread_checker_; | 339 base::ThreadChecker thread_checker_; |
| 329 | 340 |
| 330 DISALLOW_COPY_AND_ASSIGN(SdchManager); | 341 DISALLOW_COPY_AND_ASSIGN(SdchManager); |
| 331 }; | 342 }; |
| 332 | 343 |
| 333 } // namespace net | 344 } // namespace net |
| 334 | 345 |
| 335 #endif // NET_BASE_SDCH_MANAGER_H_ | 346 #endif // NET_BASE_SDCH_MANAGER_H_ |
| OLD | NEW |