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 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 | 258 |
259 static bool secure_scheme_supported() { return g_secure_scheme_supported_; } | 259 static bool secure_scheme_supported() { return g_secure_scheme_supported_; } |
260 | 260 |
261 // Briefly prevent further advertising of SDCH on this domain (if SDCH is | 261 // Briefly prevent further advertising of SDCH on this domain (if SDCH is |
262 // enabled). After enough calls to IsInSupportedDomain() the blacklisting | 262 // enabled). After enough calls to IsInSupportedDomain() the blacklisting |
263 // will be removed. Additional blacklists take exponentially more calls | 263 // will be removed. Additional blacklists take exponentially more calls |
264 // to IsInSupportedDomain() before the blacklisting is undone. | 264 // to IsInSupportedDomain() before the blacklisting is undone. |
265 // Used when filter errors are found from a given domain, but it is plausible | 265 // Used when filter errors are found from a given domain, but it is plausible |
266 // that the cause is temporary (such as application startup, where cached | 266 // that the cause is temporary (such as application startup, where cached |
267 // entries are used, but a dictionary is not yet loaded). | 267 // entries are used, but a dictionary is not yet loaded). |
268 void BlacklistDomain(const GURL& url); | 268 void BlacklistDomain(const GURL& url, ProblemCodes blacklist_reason); |
269 | 269 |
270 // Used when SEVERE filter errors are found from a given domain, to prevent | 270 // Used when SEVERE filter errors are found from a given domain, to prevent |
271 // further use of SDCH on that domain. | 271 // further use of SDCH on that domain. |
272 void BlacklistDomainForever(const GURL& url); | 272 void BlacklistDomainForever(const GURL& url, ProblemCodes blacklist_reason); |
273 | 273 |
274 // Unit test only, this function resets enabling of sdch, and clears the | 274 // Unit test only, this function resets enabling of sdch, and clears the |
275 // blacklist. | 275 // blacklist. |
276 void ClearBlacklistings(); | 276 void ClearBlacklistings(); |
277 | 277 |
278 // Unit test only, this function resets the blacklisting count for a domain. | 278 // Unit test only, this function resets the blacklisting count for a domain. |
279 void ClearDomainBlacklisting(const std::string& domain); | 279 void ClearDomainBlacklisting(const std::string& domain); |
280 | 280 |
281 // Unit test only: indicate how many more times a domain will be blacklisted. | 281 // Unit test only: indicate how many more times a domain will be blacklisted. |
282 int BlackListDomainCount(const std::string& domain); | 282 int BlackListDomainCount(const std::string& domain); |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
330 | 330 |
331 // 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 |
332 // round trip before starting our comparative tests. If ever we encounter | 332 // round trip before starting our comparative tests. If ever we encounter |
333 // 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 |
334 // complete SDCH decoding. | 334 // complete SDCH decoding. |
335 bool AllowLatencyExperiment(const GURL& url) const; | 335 bool AllowLatencyExperiment(const GURL& url) const; |
336 | 336 |
337 void SetAllowLatencyExperiment(const GURL& url, bool enable); | 337 void SetAllowLatencyExperiment(const GURL& url, bool enable); |
338 | 338 |
339 private: | 339 private: |
340 typedef std::map<std::string, int> DomainCounter; | 340 struct BlacklistInfo { |
| 341 BlacklistInfo() |
| 342 : count(0), |
| 343 exponential_count(0), |
| 344 reason(MIN_PROBLEM_CODE) {} |
| 345 |
| 346 int count; // # of times to refuse SDCH advertisement. |
| 347 int exponential_count; // Current exponential backoff ratchet. |
| 348 ProblemCodes reason; // Why domain was blacklisted. |
| 349 |
| 350 }; |
| 351 typedef std::map<std::string, BlacklistInfo> DomainBlacklistInfo; |
341 typedef std::set<std::string> ExperimentSet; | 352 typedef std::set<std::string> ExperimentSet; |
342 | 353 |
343 // A map of dictionaries info indexed by the hash that the server provides. | 354 // A map of dictionaries info indexed by the hash that the server provides. |
344 typedef std::map<std::string, scoped_refptr<Dictionary> > DictionaryMap; | 355 typedef std::map<std::string, scoped_refptr<Dictionary> > DictionaryMap; |
345 | 356 |
346 // Support SDCH compression, by advertising in headers. | 357 // Support SDCH compression, by advertising in headers. |
347 static bool g_sdch_enabled_; | 358 static bool g_sdch_enabled_; |
348 | 359 |
349 // Support SDCH compression for HTTPS requests and responses. When supported, | 360 // Support SDCH compression for HTTPS requests and responses. When supported, |
350 // HTTPS applicable dictionaries MUST have been acquired securely via HTTPS. | 361 // HTTPS applicable dictionaries MUST have been acquired securely via HTTPS. |
351 static bool g_secure_scheme_supported_; | 362 static bool g_secure_scheme_supported_; |
352 | 363 |
353 // A simple implementation of a RFC 3548 "URL safe" base64 encoder. | 364 // A simple implementation of a RFC 3548 "URL safe" base64 encoder. |
354 static void UrlSafeBase64Encode(const std::string& input, | 365 static void UrlSafeBase64Encode(const std::string& input, |
355 std::string* output); | 366 std::string* output); |
356 DictionaryMap dictionaries_; | 367 DictionaryMap dictionaries_; |
357 | 368 |
358 // An instance that can fetch a dictionary given a URL. | 369 // An instance that can fetch a dictionary given a URL. |
359 scoped_ptr<SdchFetcher> fetcher_; | 370 scoped_ptr<SdchFetcher> fetcher_; |
360 | 371 |
361 // List domains where decode failures have required disabling sdch, along with | 372 // List domains where decode failures have required disabling sdch. |
362 // count of how many additonal uses should be blacklisted. | 373 DomainBlacklistInfo blacklisted_domains_; |
363 DomainCounter blacklisted_domains_; | |
364 | |
365 // Support exponential backoff in number of domain accesses before | |
366 // blacklisting expires. | |
367 DomainCounter exponential_blacklist_count_; | |
368 | 374 |
369 // List of hostnames for which a latency experiment is allowed (because a | 375 // List of hostnames for which a latency experiment is allowed (because a |
370 // round trip test has recently passed). | 376 // round trip test has recently passed). |
371 ExperimentSet allow_latency_experiment_; | 377 ExperimentSet allow_latency_experiment_; |
372 | 378 |
373 DISALLOW_COPY_AND_ASSIGN(SdchManager); | 379 DISALLOW_COPY_AND_ASSIGN(SdchManager); |
374 }; | 380 }; |
375 | 381 |
376 } // namespace net | 382 } // namespace net |
377 | 383 |
378 #endif // NET_BASE_SDCH_MANAGER_H_ | 384 #endif // NET_BASE_SDCH_MANAGER_H_ |
OLD | NEW |