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 // Provides global database of differential decompression dictionaries for the | 5 // Provides global database of differential decompression dictionaries for the |
6 // SDCH filter (processes sdch enconded content). | 6 // SDCH filter (processes sdch enconded content). |
7 | 7 |
8 // Exactly one instance of SdchManager is built, and all references are made | 8 // Exactly one instance of SdchManager is built, and all references are made |
9 // into that collection. | 9 // into that collection. |
10 // | 10 // |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 // functionality in this base (when the functionaity can be provided). | 42 // functionality in this base (when the functionaity can be provided). |
43 class SdchFetcher { | 43 class SdchFetcher { |
44 public: | 44 public: |
45 SdchFetcher() {} | 45 SdchFetcher() {} |
46 virtual ~SdchFetcher() {} | 46 virtual ~SdchFetcher() {} |
47 | 47 |
48 // The Schedule() method is called when there is a need to get a dictionary | 48 // The Schedule() method is called when there is a need to get a dictionary |
49 // from a server. The callee is responsible for getting that dictionary_text, | 49 // from a server. The callee is responsible for getting that dictionary_text, |
50 // and then calling back to AddSdchDictionary() to the SdchManager instance. | 50 // and then calling back to AddSdchDictionary() to the SdchManager instance. |
51 virtual void Schedule(const GURL& dictionary_url) = 0; | 51 virtual void Schedule(const GURL& dictionary_url) = 0; |
| 52 |
| 53 // The Cancel() method is called to cancel all pending dictionary fetches. |
| 54 // This is used for implementation of ClearData() below. |
| 55 virtual void Cancel() = 0; |
| 56 |
52 private: | 57 private: |
53 DISALLOW_COPY_AND_ASSIGN(SdchFetcher); | 58 DISALLOW_COPY_AND_ASSIGN(SdchFetcher); |
54 }; | 59 }; |
55 | 60 |
56 //------------------------------------------------------------------------------ | 61 //------------------------------------------------------------------------------ |
57 | 62 |
58 class NET_EXPORT SdchManager : public NON_EXPORTED_BASE(base::NonThreadSafe) { | 63 class NET_EXPORT SdchManager : public NON_EXPORTED_BASE(base::NonThreadSafe) { |
59 public: | 64 public: |
60 // A list of errors that appeared and were either resolved, or used to turn | 65 // A list of errors that appeared and were either resolved, or used to turn |
61 // off sdch encoding. | 66 // off sdch encoding. |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 const std::string path_; | 232 const std::string path_; |
228 const base::Time expiration_; // Implied by max-age. | 233 const base::Time expiration_; // Implied by max-age. |
229 const std::set<int> ports_; | 234 const std::set<int> ports_; |
230 | 235 |
231 DISALLOW_COPY_AND_ASSIGN(Dictionary); | 236 DISALLOW_COPY_AND_ASSIGN(Dictionary); |
232 }; | 237 }; |
233 | 238 |
234 SdchManager(); | 239 SdchManager(); |
235 ~SdchManager(); | 240 ~SdchManager(); |
236 | 241 |
| 242 // Clear data (for browser data removal). |
| 243 void ClearData(); |
| 244 |
237 // Record stats on various errors. | 245 // Record stats on various errors. |
238 static void SdchErrorRecovery(ProblemCodes problem); | 246 static void SdchErrorRecovery(ProblemCodes problem); |
239 | 247 |
240 // Register a fetcher that this class can use to obtain dictionaries. | 248 // Register a fetcher that this class can use to obtain dictionaries. |
241 void set_sdch_fetcher(SdchFetcher* fetcher); | 249 void set_sdch_fetcher(SdchFetcher* fetcher); |
242 | 250 |
243 // Enables or disables SDCH compression. | 251 // Enables or disables SDCH compression. |
244 static void EnableSdchSupport(bool enabled); | 252 static void EnableSdchSupport(bool enabled); |
245 | 253 |
246 static bool sdch_enabled() { return g_sdch_enabled_; } | 254 static bool sdch_enabled() { return g_sdch_enabled_; } |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 // will fail (return false) if addition is illegal (data in the dictionary is | 305 // will fail (return false) if addition is illegal (data in the dictionary is |
298 // not acceptable from the dictionary_url; dictionary already added, etc.). | 306 // not acceptable from the dictionary_url; dictionary already added, etc.). |
299 bool AddSdchDictionary(const std::string& dictionary_text, | 307 bool AddSdchDictionary(const std::string& dictionary_text, |
300 const GURL& dictionary_url); | 308 const GURL& dictionary_url); |
301 | 309 |
302 // Find the vcdiff dictionary (the body of the sdch dictionary that appears | 310 // Find the vcdiff dictionary (the body of the sdch dictionary that appears |
303 // after the meta-data headers like Domain:...) with the given |server_hash| | 311 // after the meta-data headers like Domain:...) with the given |server_hash| |
304 // to use to decompreses data that arrived as SDCH encoded content. Check to | 312 // to use to decompreses data that arrived as SDCH encoded content. Check to |
305 // be sure the returned |dictionary| can be used for decoding content supplied | 313 // be sure the returned |dictionary| can be used for decoding content supplied |
306 // in response to a request for |referring_url|. | 314 // in response to a request for |referring_url|. |
307 // Caller is responsible for AddRef()ing the dictionary, and Release()ing it | |
308 // when done. | |
309 // Return null in |dictionary| if there is no matching legal dictionary. | 315 // Return null in |dictionary| if there is no matching legal dictionary. |
310 void GetVcdiffDictionary(const std::string& server_hash, | 316 void GetVcdiffDictionary(const std::string& server_hash, |
311 const GURL& referring_url, | 317 const GURL& referring_url, |
312 Dictionary** dictionary); | 318 scoped_refptr<Dictionary>* dictionary); |
313 | 319 |
314 // Get list of available (pre-cached) dictionaries that we have already loaded | 320 // Get list of available (pre-cached) dictionaries that we have already loaded |
315 // into memory. The list is a comma separated list of (client) hashes per | 321 // into memory. The list is a comma separated list of (client) hashes per |
316 // the SDCH spec. | 322 // the SDCH spec. |
317 void GetAvailDictionaryList(const GURL& target_url, std::string* list); | 323 void GetAvailDictionaryList(const GURL& target_url, std::string* list); |
318 | 324 |
319 // Construct the pair of hashes for client and server to identify an SDCH | 325 // Construct the pair of hashes for client and server to identify an SDCH |
320 // dictionary. This is only made public to facilitate unit testing, but is | 326 // dictionary. This is only made public to facilitate unit testing, but is |
321 // otherwise private | 327 // otherwise private |
322 static void GenerateHash(const std::string& dictionary_text, | 328 static void GenerateHash(const std::string& dictionary_text, |
323 std::string* client_hash, std::string* server_hash); | 329 std::string* client_hash, std::string* server_hash); |
324 | 330 |
325 // For Latency testing only, we need to know if we've succeeded in doing a | 331 // For Latency testing only, we need to know if we've succeeded in doing a |
326 // round trip before starting our comparative tests. If ever we encounter | 332 // round trip before starting our comparative tests. If ever we encounter |
327 // problems with SDCH, we opt-out of the test unless/until we perform a | 333 // problems with SDCH, we opt-out of the test unless/until we perform a |
328 // complete SDCH decoding. | 334 // complete SDCH decoding. |
329 bool AllowLatencyExperiment(const GURL& url) const; | 335 bool AllowLatencyExperiment(const GURL& url) const; |
330 | 336 |
331 void SetAllowLatencyExperiment(const GURL& url, bool enable); | 337 void SetAllowLatencyExperiment(const GURL& url, bool enable); |
332 | 338 |
333 private: | 339 private: |
334 typedef std::map<std::string, int> DomainCounter; | 340 typedef std::map<std::string, int> DomainCounter; |
335 typedef std::set<std::string> ExperimentSet; | 341 typedef std::set<std::string> ExperimentSet; |
336 | 342 |
337 // A map of dictionaries info indexed by the hash that the server provides. | 343 // A map of dictionaries info indexed by the hash that the server provides. |
338 typedef std::map<std::string, Dictionary*> DictionaryMap; | 344 typedef std::map<std::string, scoped_refptr<Dictionary> > DictionaryMap; |
339 | 345 |
340 // Support SDCH compression, by advertising in headers. | 346 // Support SDCH compression, by advertising in headers. |
341 static bool g_sdch_enabled_; | 347 static bool g_sdch_enabled_; |
342 | 348 |
343 // Support SDCH compression for HTTPS requests and responses. When supported, | 349 // Support SDCH compression for HTTPS requests and responses. When supported, |
344 // HTTPS applicable dictionaries MUST have been acquired securely via HTTPS. | 350 // HTTPS applicable dictionaries MUST have been acquired securely via HTTPS. |
345 static bool g_secure_scheme_supported_; | 351 static bool g_secure_scheme_supported_; |
346 | 352 |
347 // A simple implementation of a RFC 3548 "URL safe" base64 encoder. | 353 // A simple implementation of a RFC 3548 "URL safe" base64 encoder. |
348 static void UrlSafeBase64Encode(const std::string& input, | 354 static void UrlSafeBase64Encode(const std::string& input, |
349 std::string* output); | 355 std::string* output); |
350 DictionaryMap dictionaries_; | 356 DictionaryMap dictionaries_; |
351 | 357 |
352 // An instance that can fetch a dictionary given a URL. | 358 // An instance that can fetch a dictionary given a URL. |
353 scoped_ptr<SdchFetcher> fetcher_; | 359 scoped_ptr<SdchFetcher> fetcher_; |
354 | 360 |
355 // List domains where decode failures have required disabling sdch, along with | 361 // List domains where decode failures have required disabling sdch, along with |
356 // count of how many additonal uses should be blacklisted. | 362 // count of how many additonal uses should be blacklisted. |
357 DomainCounter blacklisted_domains_; | 363 DomainCounter blacklisted_domains_; |
358 | 364 |
359 // Support exponential backoff in number of domain accesses before | 365 // Support exponential backoff in number of domain accesses before |
360 // blacklisting expires. | 366 // blacklisting expires. |
361 DomainCounter exponential_blacklist_count; | 367 DomainCounter exponential_blacklist_count_; |
362 | 368 |
363 // List of hostnames for which a latency experiment is allowed (because a | 369 // List of hostnames for which a latency experiment is allowed (because a |
364 // round trip test has recently passed). | 370 // round trip test has recently passed). |
365 ExperimentSet allow_latency_experiment_; | 371 ExperimentSet allow_latency_experiment_; |
366 | 372 |
367 DISALLOW_COPY_AND_ASSIGN(SdchManager); | 373 DISALLOW_COPY_AND_ASSIGN(SdchManager); |
368 }; | 374 }; |
369 | 375 |
370 } // namespace net | 376 } // namespace net |
371 | 377 |
372 #endif // NET_BASE_SDCH_MANAGER_H_ | 378 #endif // NET_BASE_SDCH_MANAGER_H_ |
OLD | NEW |