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 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
212 | 212 |
213 //------------------------------------------------------------------------------ | 213 //------------------------------------------------------------------------------ |
214 SdchManager::SdchManager() { | 214 SdchManager::SdchManager() { |
215 DCHECK(CalledOnValidThread()); | 215 DCHECK(CalledOnValidThread()); |
216 } | 216 } |
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(); | |
223 dictionaries_.erase(it->first); | 222 dictionaries_.erase(it->first); |
224 } | 223 } |
225 } | 224 } |
226 | 225 |
226 void SdchManager::ClearData() { | |
227 blacklisted_domains_.clear(); | |
228 exponential_blacklist_count_.clear(); | |
229 allow_latency_experiment_.clear(); | |
230 if (fetcher_.get()) | |
231 fetcher_->Cancel(); | |
232 | |
233 // Note that this may result in not having dictionaries we've advertised | |
234 // for incoming responses. The window is relatively small (as ClearData() | |
235 // is not expected to be called frequently), so we rely on meta-refresh | |
236 // to handle this case. | |
237 dictionaries_.clear(); | |
jar (doing other things)
2014/06/17 05:48:55
I suspect this is the source of the leak. You are
jar (doing other things)
2014/06/17 17:03:28
(comment): Using the scoped_refptr<>.... this cons
Randy Smith (Not in Mondays)
2014/06/17 18:33:11
Done.
Randy Smith (Not in Mondays)
2014/06/17 18:33:11
Done.
| |
238 } | |
239 | |
227 // static | 240 // static |
228 void SdchManager::SdchErrorRecovery(ProblemCodes problem) { | 241 void SdchManager::SdchErrorRecovery(ProblemCodes problem) { |
229 UMA_HISTOGRAM_ENUMERATION("Sdch3.ProblemCodes_4", problem, MAX_PROBLEM_CODE); | 242 UMA_HISTOGRAM_ENUMERATION("Sdch3.ProblemCodes_4", problem, MAX_PROBLEM_CODE); |
230 } | 243 } |
231 | 244 |
232 void SdchManager::set_sdch_fetcher(SdchFetcher* fetcher) { | 245 void SdchManager::set_sdch_fetcher(SdchFetcher* fetcher) { |
233 DCHECK(CalledOnValidThread()); | 246 DCHECK(CalledOnValidThread()); |
234 fetcher_.reset(fetcher); | 247 fetcher_.reset(fetcher); |
235 } | 248 } |
236 | 249 |
237 // static | 250 // static |
238 void SdchManager::EnableSdchSupport(bool enabled) { | 251 void SdchManager::EnableSdchSupport(bool enabled) { |
239 g_sdch_enabled_ = enabled; | 252 g_sdch_enabled_ = enabled; |
240 } | 253 } |
241 | 254 |
242 // static | 255 // static |
243 void SdchManager::EnableSecureSchemeSupport(bool enabled) { | 256 void SdchManager::EnableSecureSchemeSupport(bool enabled) { |
244 g_secure_scheme_supported_ = enabled; | 257 g_secure_scheme_supported_ = enabled; |
245 } | 258 } |
246 | 259 |
247 void SdchManager::BlacklistDomain(const GURL& url) { | 260 void SdchManager::BlacklistDomain(const GURL& url) { |
248 SetAllowLatencyExperiment(url, false); | 261 SetAllowLatencyExperiment(url, false); |
249 | 262 |
250 std::string domain(StringToLowerASCII(url.host())); | 263 std::string domain(StringToLowerASCII(url.host())); |
251 int count = blacklisted_domains_[domain]; | 264 int count = blacklisted_domains_[domain]; |
252 if (count > 0) | 265 if (count > 0) |
253 return; // Domain is already blacklisted. | 266 return; // Domain is already blacklisted. |
254 | 267 |
255 count = 1 + 2 * exponential_blacklist_count[domain]; | 268 count = 1 + 2 * exponential_blacklist_count_[domain]; |
256 if (count > 0) | 269 if (count > 0) |
257 exponential_blacklist_count[domain] = count; | 270 exponential_blacklist_count_[domain] = count; |
258 else | 271 else |
259 count = INT_MAX; | 272 count = INT_MAX; |
260 | 273 |
261 blacklisted_domains_[domain] = count; | 274 blacklisted_domains_[domain] = count; |
262 } | 275 } |
263 | 276 |
264 void SdchManager::BlacklistDomainForever(const GURL& url) { | 277 void SdchManager::BlacklistDomainForever(const GURL& url) { |
265 SetAllowLatencyExperiment(url, false); | 278 SetAllowLatencyExperiment(url, false); |
266 | 279 |
267 std::string domain(StringToLowerASCII(url.host())); | 280 std::string domain(StringToLowerASCII(url.host())); |
268 exponential_blacklist_count[domain] = INT_MAX; | 281 exponential_blacklist_count_[domain] = INT_MAX; |
269 blacklisted_domains_[domain] = INT_MAX; | 282 blacklisted_domains_[domain] = INT_MAX; |
270 } | 283 } |
271 | 284 |
272 void SdchManager::ClearBlacklistings() { | 285 void SdchManager::ClearBlacklistings() { |
273 blacklisted_domains_.clear(); | 286 blacklisted_domains_.clear(); |
274 exponential_blacklist_count.clear(); | 287 exponential_blacklist_count_.clear(); |
275 } | 288 } |
276 | 289 |
277 void SdchManager::ClearDomainBlacklisting(const std::string& domain) { | 290 void SdchManager::ClearDomainBlacklisting(const std::string& domain) { |
278 blacklisted_domains_.erase(StringToLowerASCII(domain)); | 291 blacklisted_domains_.erase(StringToLowerASCII(domain)); |
279 } | 292 } |
280 | 293 |
281 int SdchManager::BlackListDomainCount(const std::string& domain) { | 294 int SdchManager::BlackListDomainCount(const std::string& domain) { |
282 if (blacklisted_domains_.end() == blacklisted_domains_.find(domain)) | 295 if (blacklisted_domains_.end() == blacklisted_domains_.find(domain)) |
283 return 0; | 296 return 0; |
284 return blacklisted_domains_[StringToLowerASCII(domain)]; | 297 return blacklisted_domains_[StringToLowerASCII(domain)]; |
285 } | 298 } |
286 | 299 |
287 int SdchManager::BlacklistDomainExponential(const std::string& domain) { | 300 int SdchManager::BlacklistDomainExponential(const std::string& domain) { |
288 if (exponential_blacklist_count.end() == | 301 if (exponential_blacklist_count_.end() == |
289 exponential_blacklist_count.find(domain)) | 302 exponential_blacklist_count_.find(domain)) |
290 return 0; | 303 return 0; |
291 return exponential_blacklist_count[StringToLowerASCII(domain)]; | 304 return exponential_blacklist_count_[StringToLowerASCII(domain)]; |
292 } | 305 } |
293 | 306 |
294 bool SdchManager::IsInSupportedDomain(const GURL& url) { | 307 bool SdchManager::IsInSupportedDomain(const GURL& url) { |
295 DCHECK(CalledOnValidThread()); | 308 DCHECK(CalledOnValidThread()); |
296 if (!g_sdch_enabled_ ) | 309 if (!g_sdch_enabled_ ) |
297 return false; | 310 return false; |
298 | 311 |
299 if (!secure_scheme_supported() && url.SchemeIsSecure()) | 312 if (!secure_scheme_supported() && url.SchemeIsSecure()) |
300 return false; | 313 return false; |
301 | 314 |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
448 SdchErrorRecovery(DICTIONARY_COUNT_EXCEEDED); | 461 SdchErrorRecovery(DICTIONARY_COUNT_EXCEEDED); |
449 return false; | 462 return false; |
450 } | 463 } |
451 | 464 |
452 UMA_HISTOGRAM_COUNTS("Sdch3.Dictionary size loaded", dictionary_text.size()); | 465 UMA_HISTOGRAM_COUNTS("Sdch3.Dictionary size loaded", dictionary_text.size()); |
453 DVLOG(1) << "Loaded dictionary with client hash " << client_hash | 466 DVLOG(1) << "Loaded dictionary with client hash " << client_hash |
454 << " and server hash " << server_hash; | 467 << " and server hash " << server_hash; |
455 Dictionary* dictionary = | 468 Dictionary* dictionary = |
456 new Dictionary(dictionary_text, header_end + 2, client_hash, | 469 new Dictionary(dictionary_text, header_end + 2, client_hash, |
457 dictionary_url, domain, path, expiration, ports); | 470 dictionary_url, domain, path, expiration, ports); |
458 dictionary->AddRef(); | 471 dictionaries_[server_hash] = scoped_refptr<Dictionary>(dictionary); |
jar (doing other things)
2014/06/17 05:48:55
This is actually a bad pattern. You typically can'
jar (doing other things)
2014/06/17 17:03:28
nit: If you're going to use scoped_refptr, there i
Randy Smith (Not in Mondays)
2014/06/17 18:33:11
Done.
Randy Smith (Not in Mondays)
2014/06/17 18:33:11
Really done (to distinguish from the other "Done"s
| |
459 dictionaries_[server_hash] = dictionary; | |
460 return true; | 472 return true; |
461 } | 473 } |
462 | 474 |
463 void SdchManager::GetVcdiffDictionary(const std::string& server_hash, | 475 void SdchManager::GetVcdiffDictionary(const std::string& server_hash, |
464 const GURL& referring_url, Dictionary** dictionary) { | 476 const GURL& referring_url, Dictionary** dictionary) { |
465 DCHECK(CalledOnValidThread()); | 477 DCHECK(CalledOnValidThread()); |
466 *dictionary = NULL; | 478 *dictionary = NULL; |
467 DictionaryMap::iterator it = dictionaries_.find(server_hash); | 479 DictionaryMap::iterator it = dictionaries_.find(server_hash); |
468 if (it == dictionaries_.end()) { | 480 if (it == dictionaries_.end()) { |
469 return; | 481 return; |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
550 case '/': | 562 case '/': |
551 (*output)[i] = '_'; | 563 (*output)[i] = '_'; |
552 continue; | 564 continue; |
553 default: | 565 default: |
554 continue; | 566 continue; |
555 } | 567 } |
556 } | 568 } |
557 } | 569 } |
558 | 570 |
559 } // namespace net | 571 } // namespace net |
OLD | NEW |