| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "net/base/sdch_manager.h" | 5 #include "net/base/sdch_manager.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } | 262 } |
| 263 | 263 |
| 264 // static | 264 // static |
| 265 void SdchManager::EnableSecureSchemeSupport(bool enabled) { | 265 void SdchManager::EnableSecureSchemeSupport(bool enabled) { |
| 266 g_secure_scheme_supported_ = enabled; | 266 g_secure_scheme_supported_ = enabled; |
| 267 } | 267 } |
| 268 | 268 |
| 269 void SdchManager::BlacklistDomain(const GURL& url) { | 269 void SdchManager::BlacklistDomain(const GURL& url) { |
| 270 SetAllowLatencyExperiment(url, false); | 270 SetAllowLatencyExperiment(url, false); |
| 271 | 271 |
| 272 std::string domain(StringToLowerASCII(url.host())); | 272 std::string domain(base::StringToLowerASCII(url.host())); |
| 273 int count = blacklisted_domains_[domain]; | 273 int count = blacklisted_domains_[domain]; |
| 274 if (count > 0) | 274 if (count > 0) |
| 275 return; // Domain is already blacklisted. | 275 return; // Domain is already blacklisted. |
| 276 | 276 |
| 277 count = 1 + 2 * exponential_blacklist_count_[domain]; | 277 count = 1 + 2 * exponential_blacklist_count_[domain]; |
| 278 if (count > 0) | 278 if (count > 0) |
| 279 exponential_blacklist_count_[domain] = count; | 279 exponential_blacklist_count_[domain] = count; |
| 280 else | 280 else |
| 281 count = INT_MAX; | 281 count = INT_MAX; |
| 282 | 282 |
| 283 blacklisted_domains_[domain] = count; | 283 blacklisted_domains_[domain] = count; |
| 284 } | 284 } |
| 285 | 285 |
| 286 void SdchManager::BlacklistDomainForever(const GURL& url) { | 286 void SdchManager::BlacklistDomainForever(const GURL& url) { |
| 287 SetAllowLatencyExperiment(url, false); | 287 SetAllowLatencyExperiment(url, false); |
| 288 | 288 |
| 289 std::string domain(StringToLowerASCII(url.host())); | 289 std::string domain(base::StringToLowerASCII(url.host())); |
| 290 exponential_blacklist_count_[domain] = INT_MAX; | 290 exponential_blacklist_count_[domain] = INT_MAX; |
| 291 blacklisted_domains_[domain] = INT_MAX; | 291 blacklisted_domains_[domain] = INT_MAX; |
| 292 } | 292 } |
| 293 | 293 |
| 294 void SdchManager::ClearBlacklistings() { | 294 void SdchManager::ClearBlacklistings() { |
| 295 blacklisted_domains_.clear(); | 295 blacklisted_domains_.clear(); |
| 296 exponential_blacklist_count_.clear(); | 296 exponential_blacklist_count_.clear(); |
| 297 } | 297 } |
| 298 | 298 |
| 299 void SdchManager::ClearDomainBlacklisting(const std::string& domain) { | 299 void SdchManager::ClearDomainBlacklisting(const std::string& domain) { |
| 300 blacklisted_domains_.erase(StringToLowerASCII(domain)); | 300 blacklisted_domains_.erase(base::StringToLowerASCII(domain)); |
| 301 } | 301 } |
| 302 | 302 |
| 303 int SdchManager::BlackListDomainCount(const std::string& domain) { | 303 int SdchManager::BlackListDomainCount(const std::string& domain) { |
| 304 if (blacklisted_domains_.end() == blacklisted_domains_.find(domain)) | 304 if (blacklisted_domains_.end() == blacklisted_domains_.find(domain)) |
| 305 return 0; | 305 return 0; |
| 306 return blacklisted_domains_[StringToLowerASCII(domain)]; | 306 return blacklisted_domains_[base::StringToLowerASCII(domain)]; |
| 307 } | 307 } |
| 308 | 308 |
| 309 int SdchManager::BlacklistDomainExponential(const std::string& domain) { | 309 int SdchManager::BlacklistDomainExponential(const std::string& domain) { |
| 310 if (exponential_blacklist_count_.end() == | 310 if (exponential_blacklist_count_.end() == |
| 311 exponential_blacklist_count_.find(domain)) | 311 exponential_blacklist_count_.find(domain)) |
| 312 return 0; | 312 return 0; |
| 313 return exponential_blacklist_count_[StringToLowerASCII(domain)]; | 313 return exponential_blacklist_count_[base::StringToLowerASCII(domain)]; |
| 314 } | 314 } |
| 315 | 315 |
| 316 bool SdchManager::IsInSupportedDomain(const GURL& url) { | 316 bool SdchManager::IsInSupportedDomain(const GURL& url) { |
| 317 DCHECK(CalledOnValidThread()); | 317 DCHECK(CalledOnValidThread()); |
| 318 if (!g_sdch_enabled_ ) | 318 if (!g_sdch_enabled_ ) |
| 319 return false; | 319 return false; |
| 320 | 320 |
| 321 if (!secure_scheme_supported() && url.SchemeIsSecure()) | 321 if (!secure_scheme_supported() && url.SchemeIsSecure()) |
| 322 return false; | 322 return false; |
| 323 | 323 |
| 324 if (blacklisted_domains_.empty()) | 324 if (blacklisted_domains_.empty()) |
| 325 return true; | 325 return true; |
| 326 | 326 |
| 327 std::string domain(StringToLowerASCII(url.host())); | 327 std::string domain(base::StringToLowerASCII(url.host())); |
| 328 DomainCounter::iterator it = blacklisted_domains_.find(domain); | 328 DomainCounter::iterator it = blacklisted_domains_.find(domain); |
| 329 if (blacklisted_domains_.end() == it) | 329 if (blacklisted_domains_.end() == it) |
| 330 return true; | 330 return true; |
| 331 | 331 |
| 332 int count = it->second - 1; | 332 int count = it->second - 1; |
| 333 if (count > 0) | 333 if (count > 0) |
| 334 blacklisted_domains_[domain] = count; | 334 blacklisted_domains_[domain] = count; |
| 335 else | 335 else |
| 336 blacklisted_domains_.erase(domain); | 336 blacklisted_domains_.erase(domain); |
| 337 SdchErrorRecovery(DOMAIN_BLACKLIST_INCLUDES_TARGET); | 337 SdchErrorRecovery(DOMAIN_BLACKLIST_INCLUDES_TARGET); |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 420 if (colon_index > line_end) | 420 if (colon_index > line_end) |
| 421 break; | 421 break; |
| 422 | 422 |
| 423 size_t value_start = dictionary_text.find_first_not_of(" \t", | 423 size_t value_start = dictionary_text.find_first_not_of(" \t", |
| 424 colon_index + 1); | 424 colon_index + 1); |
| 425 if (std::string::npos != value_start) { | 425 if (std::string::npos != value_start) { |
| 426 if (value_start >= line_end) | 426 if (value_start >= line_end) |
| 427 break; | 427 break; |
| 428 std::string name(dictionary_text, line_start, colon_index - line_start); | 428 std::string name(dictionary_text, line_start, colon_index - line_start); |
| 429 std::string value(dictionary_text, value_start, line_end - value_start); | 429 std::string value(dictionary_text, value_start, line_end - value_start); |
| 430 name = StringToLowerASCII(name); | 430 name = base::StringToLowerASCII(name); |
| 431 if (name == "domain") { | 431 if (name == "domain") { |
| 432 domain = value; | 432 domain = value; |
| 433 } else if (name == "path") { | 433 } else if (name == "path") { |
| 434 path = value; | 434 path = value; |
| 435 } else if (name == "format-version") { | 435 } else if (name == "format-version") { |
| 436 if (value != "1.0") | 436 if (value != "1.0") |
| 437 return false; | 437 return false; |
| 438 } else if (name == "max-age") { | 438 } else if (name == "max-age") { |
| 439 int64 seconds; | 439 int64 seconds; |
| 440 base::StringToInt64(value, &seconds); | 440 base::StringToInt64(value, &seconds); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 case '/': | 573 case '/': |
| 574 (*output)[i] = '_'; | 574 (*output)[i] = '_'; |
| 575 continue; | 575 continue; |
| 576 default: | 576 default: |
| 577 continue; | 577 continue; |
| 578 } | 578 } |
| 579 } | 579 } |
| 580 } | 580 } |
| 581 | 581 |
| 582 } // namespace net | 582 } // namespace net |
| OLD | NEW |