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 214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
225 SdchManager::~SdchManager() { | 225 SdchManager::~SdchManager() { |
226 DCHECK(CalledOnValidThread()); | 226 DCHECK(CalledOnValidThread()); |
227 while (!dictionaries_.empty()) { | 227 while (!dictionaries_.empty()) { |
228 DictionaryMap::iterator it = dictionaries_.begin(); | 228 DictionaryMap::iterator it = dictionaries_.begin(); |
229 dictionaries_.erase(it->first); | 229 dictionaries_.erase(it->first); |
230 } | 230 } |
231 } | 231 } |
232 | 232 |
233 void SdchManager::ClearData() { | 233 void SdchManager::ClearData() { |
234 blacklisted_domains_.clear(); | 234 blacklisted_domains_.clear(); |
235 exponential_blacklist_count_.clear(); | |
236 allow_latency_experiment_.clear(); | 235 allow_latency_experiment_.clear(); |
237 if (fetcher_.get()) | 236 if (fetcher_.get()) |
238 fetcher_->Cancel(); | 237 fetcher_->Cancel(); |
239 | 238 |
240 // Note that this may result in not having dictionaries we've advertised | 239 // Note that this may result in not having dictionaries we've advertised |
241 // for incoming responses. The window is relatively small (as ClearData() | 240 // for incoming responses. The window is relatively small (as ClearData() |
242 // is not expected to be called frequently), so we rely on meta-refresh | 241 // is not expected to be called frequently), so we rely on meta-refresh |
243 // to handle this case. | 242 // to handle this case. |
244 dictionaries_.clear(); | 243 dictionaries_.clear(); |
245 } | 244 } |
(...skipping 11 matching lines...) Expand all Loading... | |
257 // static | 256 // static |
258 void SdchManager::EnableSdchSupport(bool enabled) { | 257 void SdchManager::EnableSdchSupport(bool enabled) { |
259 g_sdch_enabled_ = enabled; | 258 g_sdch_enabled_ = enabled; |
260 } | 259 } |
261 | 260 |
262 // static | 261 // static |
263 void SdchManager::EnableSecureSchemeSupport(bool enabled) { | 262 void SdchManager::EnableSecureSchemeSupport(bool enabled) { |
264 g_secure_scheme_supported_ = enabled; | 263 g_secure_scheme_supported_ = enabled; |
265 } | 264 } |
266 | 265 |
267 void SdchManager::BlacklistDomain(const GURL& url) { | 266 void SdchManager::BlacklistDomain(const GURL& url, |
267 ProblemCodes blacklist_reason) { | |
268 SetAllowLatencyExperiment(url, false); | 268 SetAllowLatencyExperiment(url, false); |
269 | 269 |
270 std::string domain(StringToLowerASCII(url.host())); | 270 std::string domain(StringToLowerASCII(url.host())); |
271 int count = blacklisted_domains_[domain]; | 271 BlacklistInfo* blacklist_info = &blacklisted_domains_[domain]; |
272 if (count > 0) | 272 |
273 if (blacklist_info->count > 0) | |
273 return; // Domain is already blacklisted. | 274 return; // Domain is already blacklisted. |
274 | 275 |
275 count = 1 + 2 * exponential_blacklist_count_[domain]; | 276 int count = 1 + 2 * blacklist_info->exponential_count; |
276 if (count > 0) | 277 if (count > 0) |
277 exponential_blacklist_count_[domain] = count; | 278 blacklist_info->exponential_count = count; |
278 else | 279 else |
279 count = INT_MAX; | 280 blacklist_info->exponential_count = INT_MAX; |
280 | 281 |
281 blacklisted_domains_[domain] = count; | 282 blacklist_info->count = blacklist_info->exponential_count; |
283 blacklist_info->reason = blacklist_reason; | |
282 } | 284 } |
283 | 285 |
284 void SdchManager::BlacklistDomainForever(const GURL& url) { | 286 void SdchManager::BlacklistDomainForever(const GURL& url, |
287 ProblemCodes blacklist_reason) { | |
285 SetAllowLatencyExperiment(url, false); | 288 SetAllowLatencyExperiment(url, false); |
286 | 289 |
287 std::string domain(StringToLowerASCII(url.host())); | 290 std::string domain(StringToLowerASCII(url.host())); |
288 exponential_blacklist_count_[domain] = INT_MAX; | 291 BlacklistInfo* blacklist_info = &blacklisted_domains_[domain]; |
289 blacklisted_domains_[domain] = INT_MAX; | 292 blacklist_info->count = INT_MAX; |
293 blacklist_info->exponential_count = INT_MAX; | |
294 blacklist_info->reason = blacklist_reason; | |
290 } | 295 } |
291 | 296 |
292 void SdchManager::ClearBlacklistings() { | 297 void SdchManager::ClearBlacklistings() { |
293 blacklisted_domains_.clear(); | 298 blacklisted_domains_.clear(); |
294 exponential_blacklist_count_.clear(); | |
295 } | 299 } |
296 | 300 |
297 void SdchManager::ClearDomainBlacklisting(const std::string& domain) { | 301 void SdchManager::ClearDomainBlacklisting(const std::string& domain) { |
298 blacklisted_domains_.erase(StringToLowerASCII(domain)); | 302 BlacklistInfo* blacklist_info = &blacklisted_domains_[ |
303 StringToLowerASCII(domain)]; | |
304 blacklist_info->count = 0; | |
305 blacklist_info->reason = MIN_PROBLEM_CODE; | |
jar (doing other things)
2014/08/05 23:33:30
Why did you change to leaving the entry in the map
Randy Smith (Not in Mondays)
2014/08/11 20:46:39
Because the map now contains the exponential backo
| |
299 } | 306 } |
300 | 307 |
301 int SdchManager::BlackListDomainCount(const std::string& domain) { | 308 int SdchManager::BlackListDomainCount(const std::string& domain) { |
302 if (blacklisted_domains_.end() == blacklisted_domains_.find(domain)) | 309 std::string domain_lower(StringToLowerASCII(domain)); |
jar (doing other things)
2014/08/05 23:33:30
Good bug fix! Old code assumed it was already lowe
Randy Smith (Not in Mondays)
2014/08/11 20:46:39
Done (or got rid of any variable at all), everywhe
| |
310 | |
311 if (blacklisted_domains_.end() == blacklisted_domains_.find(domain_lower)) | |
303 return 0; | 312 return 0; |
304 return blacklisted_domains_[StringToLowerASCII(domain)]; | 313 return blacklisted_domains_[domain_lower].count; |
305 } | 314 } |
306 | 315 |
307 int SdchManager::BlacklistDomainExponential(const std::string& domain) { | 316 int SdchManager::BlacklistDomainExponential(const std::string& domain) { |
308 if (exponential_blacklist_count_.end() == | 317 std::string domain_lower(StringToLowerASCII(domain)); |
309 exponential_blacklist_count_.find(domain)) | 318 |
319 if (blacklisted_domains_.end() == blacklisted_domains_.find(domain_lower)) | |
310 return 0; | 320 return 0; |
311 return exponential_blacklist_count_[StringToLowerASCII(domain)]; | 321 return blacklisted_domains_[domain_lower].exponential_count; |
312 } | 322 } |
313 | 323 |
314 bool SdchManager::IsInSupportedDomain(const GURL& url) { | 324 bool SdchManager::IsInSupportedDomain(const GURL& url) { |
315 DCHECK(CalledOnValidThread()); | 325 DCHECK(CalledOnValidThread()); |
316 if (!g_sdch_enabled_ ) | 326 if (!g_sdch_enabled_ ) |
317 return false; | 327 return false; |
318 | 328 |
319 if (!secure_scheme_supported() && url.SchemeIsSecure()) | 329 if (!secure_scheme_supported() && url.SchemeIsSecure()) |
320 return false; | 330 return false; |
321 | 331 |
322 if (blacklisted_domains_.empty()) | 332 if (blacklisted_domains_.empty()) |
323 return true; | 333 return true; |
324 | 334 |
325 std::string domain(StringToLowerASCII(url.host())); | 335 std::string domain(StringToLowerASCII(url.host())); |
326 DomainCounter::iterator it = blacklisted_domains_.find(domain); | 336 DomainBlacklistInfo::iterator it = blacklisted_domains_.find(domain); |
327 if (blacklisted_domains_.end() == it) | 337 if (blacklisted_domains_.end() == it || it->second.count == 0) |
328 return true; | 338 return true; |
329 | 339 |
330 int count = it->second - 1; | 340 int count = it->second.count - 1; |
331 if (count > 0) | 341 if (count > 0) { |
332 blacklisted_domains_[domain] = count; | 342 it->second.count = count; |
333 else | 343 } else { |
334 blacklisted_domains_.erase(domain); | 344 it->second.count = 0; |
345 it->second.reason = MIN_PROBLEM_CODE; | |
346 } | |
347 | |
348 UMA_HISTOGRAM_ENUMERATION("Sdch3.BlacklistReason", it->second.reason, | |
jar (doing other things)
2014/08/05 23:33:30
Maybe this should go before line 343, since it may
Randy Smith (Not in Mondays)
2014/08/11 20:46:39
Ooops; thanks for the catch. No, I think we still
| |
349 MAX_PROBLEM_CODE); | |
335 SdchErrorRecovery(DOMAIN_BLACKLIST_INCLUDES_TARGET); | 350 SdchErrorRecovery(DOMAIN_BLACKLIST_INCLUDES_TARGET); |
336 return false; | 351 return false; |
337 } | 352 } |
338 | 353 |
339 void SdchManager::FetchDictionary(const GURL& request_url, | 354 void SdchManager::FetchDictionary(const GURL& request_url, |
340 const GURL& dictionary_url) { | 355 const GURL& dictionary_url) { |
341 DCHECK(CalledOnValidThread()); | 356 DCHECK(CalledOnValidThread()); |
342 if (CanFetchDictionary(request_url, dictionary_url) && fetcher_.get()) | 357 if (CanFetchDictionary(request_url, dictionary_url) && fetcher_.get()) |
343 fetcher_->Schedule(dictionary_url); | 358 fetcher_->Schedule(dictionary_url); |
344 } | 359 } |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
571 case '/': | 586 case '/': |
572 (*output)[i] = '_'; | 587 (*output)[i] = '_'; |
573 continue; | 588 continue; |
574 default: | 589 default: |
575 continue; | 590 continue; |
576 } | 591 } |
577 } | 592 } |
578 } | 593 } |
579 | 594 |
580 } // namespace net | 595 } // namespace net |
OLD | NEW |