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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 SdchManager::~SdchManager() { | 227 SdchManager::~SdchManager() { |
228 DCHECK(CalledOnValidThread()); | 228 DCHECK(CalledOnValidThread()); |
229 while (!dictionaries_.empty()) { | 229 while (!dictionaries_.empty()) { |
230 DictionaryMap::iterator it = dictionaries_.begin(); | 230 DictionaryMap::iterator it = dictionaries_.begin(); |
231 dictionaries_.erase(it->first); | 231 dictionaries_.erase(it->first); |
232 } | 232 } |
233 } | 233 } |
234 | 234 |
235 void SdchManager::ClearData() { | 235 void SdchManager::ClearData() { |
236 blacklisted_domains_.clear(); | 236 blacklisted_domains_.clear(); |
237 exponential_blacklist_count_.clear(); | |
238 allow_latency_experiment_.clear(); | 237 allow_latency_experiment_.clear(); |
239 if (fetcher_.get()) | 238 if (fetcher_.get()) |
240 fetcher_->Cancel(); | 239 fetcher_->Cancel(); |
241 | 240 |
242 // Note that this may result in not having dictionaries we've advertised | 241 // Note that this may result in not having dictionaries we've advertised |
243 // for incoming responses. The window is relatively small (as ClearData() | 242 // for incoming responses. The window is relatively small (as ClearData() |
244 // is not expected to be called frequently), so we rely on meta-refresh | 243 // is not expected to be called frequently), so we rely on meta-refresh |
245 // to handle this case. | 244 // to handle this case. |
246 dictionaries_.clear(); | 245 dictionaries_.clear(); |
247 } | 246 } |
(...skipping 11 matching lines...) Expand all Loading... |
259 // static | 258 // static |
260 void SdchManager::EnableSdchSupport(bool enabled) { | 259 void SdchManager::EnableSdchSupport(bool enabled) { |
261 g_sdch_enabled_ = enabled; | 260 g_sdch_enabled_ = enabled; |
262 } | 261 } |
263 | 262 |
264 // static | 263 // static |
265 void SdchManager::EnableSecureSchemeSupport(bool enabled) { | 264 void SdchManager::EnableSecureSchemeSupport(bool enabled) { |
266 g_secure_scheme_supported_ = enabled; | 265 g_secure_scheme_supported_ = enabled; |
267 } | 266 } |
268 | 267 |
269 void SdchManager::BlacklistDomain(const GURL& url) { | 268 void SdchManager::BlacklistDomain(const GURL& url, |
| 269 ProblemCodes blacklist_reason) { |
270 SetAllowLatencyExperiment(url, false); | 270 SetAllowLatencyExperiment(url, false); |
271 | 271 |
272 std::string domain(base::StringToLowerASCII(url.host())); | 272 BlacklistInfo* blacklist_info = |
273 int count = blacklisted_domains_[domain]; | 273 &blacklisted_domains_[base::StringToLowerASCII(url.host())]; |
274 if (count > 0) | 274 |
| 275 if (blacklist_info->count > 0) |
275 return; // Domain is already blacklisted. | 276 return; // Domain is already blacklisted. |
276 | 277 |
277 count = 1 + 2 * exponential_blacklist_count_[domain]; | 278 if (blacklist_info->exponential_count > (INT_MAX - 1) / 2) { |
278 if (count > 0) | 279 blacklist_info->exponential_count = INT_MAX; |
279 exponential_blacklist_count_[domain] = count; | 280 } else { |
280 else | 281 blacklist_info->exponential_count = |
281 count = INT_MAX; | 282 blacklist_info->exponential_count * 2 + 1; |
| 283 } |
282 | 284 |
283 blacklisted_domains_[domain] = count; | 285 blacklist_info->count = blacklist_info->exponential_count; |
| 286 blacklist_info->reason = blacklist_reason; |
284 } | 287 } |
285 | 288 |
286 void SdchManager::BlacklistDomainForever(const GURL& url) { | 289 void SdchManager::BlacklistDomainForever(const GURL& url, |
| 290 ProblemCodes blacklist_reason) { |
287 SetAllowLatencyExperiment(url, false); | 291 SetAllowLatencyExperiment(url, false); |
288 | 292 |
289 std::string domain(base::StringToLowerASCII(url.host())); | 293 BlacklistInfo* blacklist_info = |
290 exponential_blacklist_count_[domain] = INT_MAX; | 294 &blacklisted_domains_[base::StringToLowerASCII(url.host())]; |
291 blacklisted_domains_[domain] = INT_MAX; | 295 blacklist_info->count = INT_MAX; |
| 296 blacklist_info->exponential_count = INT_MAX; |
| 297 blacklist_info->reason = blacklist_reason; |
292 } | 298 } |
293 | 299 |
294 void SdchManager::ClearBlacklistings() { | 300 void SdchManager::ClearBlacklistings() { |
295 blacklisted_domains_.clear(); | 301 blacklisted_domains_.clear(); |
296 exponential_blacklist_count_.clear(); | |
297 } | 302 } |
298 | 303 |
299 void SdchManager::ClearDomainBlacklisting(const std::string& domain) { | 304 void SdchManager::ClearDomainBlacklisting(const std::string& domain) { |
300 blacklisted_domains_.erase(base::StringToLowerASCII(domain)); | 305 BlacklistInfo* blacklist_info = &blacklisted_domains_[ |
| 306 base::StringToLowerASCII(domain)]; |
| 307 blacklist_info->count = 0; |
| 308 blacklist_info->reason = MIN_PROBLEM_CODE; |
301 } | 309 } |
302 | 310 |
303 int SdchManager::BlackListDomainCount(const std::string& domain) { | 311 int SdchManager::BlackListDomainCount(const std::string& domain) { |
304 if (blacklisted_domains_.end() == blacklisted_domains_.find(domain)) | 312 std::string domain_lower(base::StringToLowerASCII(domain)); |
| 313 |
| 314 if (blacklisted_domains_.end() == blacklisted_domains_.find(domain_lower)) |
305 return 0; | 315 return 0; |
306 return blacklisted_domains_[base::StringToLowerASCII(domain)]; | 316 return blacklisted_domains_[domain_lower].count; |
307 } | 317 } |
308 | 318 |
309 int SdchManager::BlacklistDomainExponential(const std::string& domain) { | 319 int SdchManager::BlacklistDomainExponential(const std::string& domain) { |
310 if (exponential_blacklist_count_.end() == | 320 std::string domain_lower(base::StringToLowerASCII(domain)); |
311 exponential_blacklist_count_.find(domain)) | 321 |
| 322 if (blacklisted_domains_.end() == blacklisted_domains_.find(domain_lower)) |
312 return 0; | 323 return 0; |
313 return exponential_blacklist_count_[base::StringToLowerASCII(domain)]; | 324 return blacklisted_domains_[domain_lower].exponential_count; |
314 } | 325 } |
315 | 326 |
316 bool SdchManager::IsInSupportedDomain(const GURL& url) { | 327 bool SdchManager::IsInSupportedDomain(const GURL& url) { |
317 DCHECK(CalledOnValidThread()); | 328 DCHECK(CalledOnValidThread()); |
318 if (!g_sdch_enabled_ ) | 329 if (!g_sdch_enabled_ ) |
319 return false; | 330 return false; |
320 | 331 |
321 if (!secure_scheme_supported() && url.SchemeIsSecure()) | 332 if (!secure_scheme_supported() && url.SchemeIsSecure()) |
322 return false; | 333 return false; |
323 | 334 |
324 if (blacklisted_domains_.empty()) | 335 if (blacklisted_domains_.empty()) |
325 return true; | 336 return true; |
326 | 337 |
327 std::string domain(base::StringToLowerASCII(url.host())); | 338 DomainBlacklistInfo::iterator it = |
328 DomainCounter::iterator it = blacklisted_domains_.find(domain); | 339 blacklisted_domains_.find(base::StringToLowerASCII(url.host())); |
329 if (blacklisted_domains_.end() == it) | 340 if (blacklisted_domains_.end() == it || it->second.count == 0) |
330 return true; | 341 return true; |
331 | 342 |
332 int count = it->second - 1; | 343 UMA_HISTOGRAM_ENUMERATION("Sdch3.BlacklistReason", it->second.reason, |
333 if (count > 0) | 344 MAX_PROBLEM_CODE); |
334 blacklisted_domains_[domain] = count; | |
335 else | |
336 blacklisted_domains_.erase(domain); | |
337 SdchErrorRecovery(DOMAIN_BLACKLIST_INCLUDES_TARGET); | 345 SdchErrorRecovery(DOMAIN_BLACKLIST_INCLUDES_TARGET); |
| 346 |
| 347 int count = it->second.count - 1; |
| 348 if (count > 0) { |
| 349 it->second.count = count; |
| 350 } else { |
| 351 it->second.count = 0; |
| 352 it->second.reason = MIN_PROBLEM_CODE; |
| 353 } |
| 354 |
338 return false; | 355 return false; |
339 } | 356 } |
340 | 357 |
341 void SdchManager::FetchDictionary(const GURL& request_url, | 358 void SdchManager::FetchDictionary(const GURL& request_url, |
342 const GURL& dictionary_url) { | 359 const GURL& dictionary_url) { |
343 DCHECK(CalledOnValidThread()); | 360 DCHECK(CalledOnValidThread()); |
344 if (CanFetchDictionary(request_url, dictionary_url) && fetcher_.get()) | 361 if (CanFetchDictionary(request_url, dictionary_url) && fetcher_.get()) |
345 fetcher_->Schedule(dictionary_url); | 362 fetcher_->Schedule(dictionary_url); |
346 } | 363 } |
347 | 364 |
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
573 case '/': | 590 case '/': |
574 (*output)[i] = '_'; | 591 (*output)[i] = '_'; |
575 continue; | 592 continue; |
576 default: | 593 default: |
577 continue; | 594 continue; |
578 } | 595 } |
579 } | 596 } |
580 } | 597 } |
581 | 598 |
582 } // namespace net | 599 } // namespace net |
OLD | NEW |