| 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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 | 217 |
| 218 SdchManager::~SdchManager() { | 218 SdchManager::~SdchManager() { |
| 219 DCHECK(CalledOnValidThread()); | 219 DCHECK(CalledOnValidThread()); |
| 220 while (!dictionaries_.empty()) { | 220 while (!dictionaries_.empty()) { |
| 221 DictionaryMap::iterator it = dictionaries_.begin(); | 221 DictionaryMap::iterator it = dictionaries_.begin(); |
| 222 it->second->Release(); | 222 it->second->Release(); |
| 223 dictionaries_.erase(it->first); | 223 dictionaries_.erase(it->first); |
| 224 } | 224 } |
| 225 } | 225 } |
| 226 | 226 |
| 227 void SdchManager::ClearData() { |
| 228 blacklisted_domains_.clear(); |
| 229 exponential_blacklist_count_.clear(); |
| 230 allow_latency_experiment_.clear(); |
| 231 if (fetcher_.get()) |
| 232 fetcher_->Cancel(); |
| 233 |
| 234 // Note that this may result in not having dictionaries we've advertised |
| 235 // for incoming responses. The window is relatively small (as ClearData() |
| 236 // is not expected to be called frequently), so we rely on meta-refresh |
| 237 // to handle this case. |
| 238 dictionaries_.clear(); |
| 239 } |
| 240 |
| 227 // static | 241 // static |
| 228 void SdchManager::SdchErrorRecovery(ProblemCodes problem) { | 242 void SdchManager::SdchErrorRecovery(ProblemCodes problem) { |
| 229 UMA_HISTOGRAM_ENUMERATION("Sdch3.ProblemCodes_4", problem, MAX_PROBLEM_CODE); | 243 UMA_HISTOGRAM_ENUMERATION("Sdch3.ProblemCodes_4", problem, MAX_PROBLEM_CODE); |
| 230 } | 244 } |
| 231 | 245 |
| 232 void SdchManager::set_sdch_fetcher(SdchFetcher* fetcher) { | 246 void SdchManager::set_sdch_fetcher(SdchFetcher* fetcher) { |
| 233 DCHECK(CalledOnValidThread()); | 247 DCHECK(CalledOnValidThread()); |
| 234 fetcher_.reset(fetcher); | 248 fetcher_.reset(fetcher); |
| 235 } | 249 } |
| 236 | 250 |
| 237 // static | 251 // static |
| 238 void SdchManager::EnableSdchSupport(bool enabled) { | 252 void SdchManager::EnableSdchSupport(bool enabled) { |
| 239 g_sdch_enabled_ = enabled; | 253 g_sdch_enabled_ = enabled; |
| 240 } | 254 } |
| 241 | 255 |
| 242 // static | 256 // static |
| 243 void SdchManager::EnableSecureSchemeSupport(bool enabled) { | 257 void SdchManager::EnableSecureSchemeSupport(bool enabled) { |
| 244 g_secure_scheme_supported_ = enabled; | 258 g_secure_scheme_supported_ = enabled; |
| 245 } | 259 } |
| 246 | 260 |
| 247 void SdchManager::BlacklistDomain(const GURL& url) { | 261 void SdchManager::BlacklistDomain(const GURL& url) { |
| 248 SetAllowLatencyExperiment(url, false); | 262 SetAllowLatencyExperiment(url, false); |
| 249 | 263 |
| 250 std::string domain(StringToLowerASCII(url.host())); | 264 std::string domain(StringToLowerASCII(url.host())); |
| 251 int count = blacklisted_domains_[domain]; | 265 int count = blacklisted_domains_[domain]; |
| 252 if (count > 0) | 266 if (count > 0) |
| 253 return; // Domain is already blacklisted. | 267 return; // Domain is already blacklisted. |
| 254 | 268 |
| 255 count = 1 + 2 * exponential_blacklist_count[domain]; | 269 count = 1 + 2 * exponential_blacklist_count_[domain]; |
| 256 if (count > 0) | 270 if (count > 0) |
| 257 exponential_blacklist_count[domain] = count; | 271 exponential_blacklist_count_[domain] = count; |
| 258 else | 272 else |
| 259 count = INT_MAX; | 273 count = INT_MAX; |
| 260 | 274 |
| 261 blacklisted_domains_[domain] = count; | 275 blacklisted_domains_[domain] = count; |
| 262 } | 276 } |
| 263 | 277 |
| 264 void SdchManager::BlacklistDomainForever(const GURL& url) { | 278 void SdchManager::BlacklistDomainForever(const GURL& url) { |
| 265 SetAllowLatencyExperiment(url, false); | 279 SetAllowLatencyExperiment(url, false); |
| 266 | 280 |
| 267 std::string domain(StringToLowerASCII(url.host())); | 281 std::string domain(StringToLowerASCII(url.host())); |
| 268 exponential_blacklist_count[domain] = INT_MAX; | 282 exponential_blacklist_count_[domain] = INT_MAX; |
| 269 blacklisted_domains_[domain] = INT_MAX; | 283 blacklisted_domains_[domain] = INT_MAX; |
| 270 } | 284 } |
| 271 | 285 |
| 272 void SdchManager::ClearBlacklistings() { | 286 void SdchManager::ClearBlacklistings() { |
| 273 blacklisted_domains_.clear(); | 287 blacklisted_domains_.clear(); |
| 274 exponential_blacklist_count.clear(); | 288 exponential_blacklist_count_.clear(); |
| 275 } | 289 } |
| 276 | 290 |
| 277 void SdchManager::ClearDomainBlacklisting(const std::string& domain) { | 291 void SdchManager::ClearDomainBlacklisting(const std::string& domain) { |
| 278 blacklisted_domains_.erase(StringToLowerASCII(domain)); | 292 blacklisted_domains_.erase(StringToLowerASCII(domain)); |
| 279 } | 293 } |
| 280 | 294 |
| 281 int SdchManager::BlackListDomainCount(const std::string& domain) { | 295 int SdchManager::BlackListDomainCount(const std::string& domain) { |
| 282 if (blacklisted_domains_.end() == blacklisted_domains_.find(domain)) | 296 if (blacklisted_domains_.end() == blacklisted_domains_.find(domain)) |
| 283 return 0; | 297 return 0; |
| 284 return blacklisted_domains_[StringToLowerASCII(domain)]; | 298 return blacklisted_domains_[StringToLowerASCII(domain)]; |
| 285 } | 299 } |
| 286 | 300 |
| 287 int SdchManager::BlacklistDomainExponential(const std::string& domain) { | 301 int SdchManager::BlacklistDomainExponential(const std::string& domain) { |
| 288 if (exponential_blacklist_count.end() == | 302 if (exponential_blacklist_count_.end() == |
| 289 exponential_blacklist_count.find(domain)) | 303 exponential_blacklist_count_.find(domain)) |
| 290 return 0; | 304 return 0; |
| 291 return exponential_blacklist_count[StringToLowerASCII(domain)]; | 305 return exponential_blacklist_count_[StringToLowerASCII(domain)]; |
| 292 } | 306 } |
| 293 | 307 |
| 294 bool SdchManager::IsInSupportedDomain(const GURL& url) { | 308 bool SdchManager::IsInSupportedDomain(const GURL& url) { |
| 295 DCHECK(CalledOnValidThread()); | 309 DCHECK(CalledOnValidThread()); |
| 296 if (!g_sdch_enabled_ ) | 310 if (!g_sdch_enabled_ ) |
| 297 return false; | 311 return false; |
| 298 | 312 |
| 299 if (blacklisted_domains_.empty()) | 313 if (blacklisted_domains_.empty()) |
| 300 return true; | 314 return true; |
| 301 | 315 |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 case '/': | 561 case '/': |
| 548 (*output)[i] = '_'; | 562 (*output)[i] = '_'; |
| 549 continue; | 563 continue; |
| 550 default: | 564 default: |
| 551 continue; | 565 continue; |
| 552 } | 566 } |
| 553 } | 567 } |
| 554 } | 568 } |
| 555 | 569 |
| 556 } // namespace net | 570 } // namespace net |
| OLD | NEW |