Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(623)

Side by Side Diff: net/base/sdch_manager.cc

Issue 321283002: Clear SDCH information on "Clear browsing data" path. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Incorporated comments and expanded scoped_refptr<> usage. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/base/sdch_manager.h ('k') | net/base/sdch_manager_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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();
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
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();
459 dictionaries_[server_hash] = dictionary; 471 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(
464 const GURL& referring_url, Dictionary** dictionary) { 476 const std::string& server_hash,
477 const GURL& referring_url, scoped_refptr<Dictionary>* dictionary) {
jar (doing other things) 2014/06/18 01:52:33 nit: one arg per line when you overflow in declati
Randy Smith (Not in Mondays) 2014/06/18 18:12:38 Done.
465 DCHECK(CalledOnValidThread()); 478 DCHECK(CalledOnValidThread());
466 *dictionary = NULL; 479 *dictionary = NULL;
467 DictionaryMap::iterator it = dictionaries_.find(server_hash); 480 DictionaryMap::iterator it = dictionaries_.find(server_hash);
468 if (it == dictionaries_.end()) { 481 if (it == dictionaries_.end()) {
469 return; 482 return;
470 } 483 }
471 Dictionary* matching_dictionary = it->second; 484 scoped_refptr<Dictionary> matching_dictionary = it->second;
472 if (!IsInSupportedDomain(referring_url)) 485 if (!IsInSupportedDomain(referring_url))
473 return; 486 return;
474 if (!matching_dictionary->CanUse(referring_url)) 487 if (!matching_dictionary->CanUse(referring_url))
475 return; 488 return;
476 *dictionary = matching_dictionary; 489 *dictionary = matching_dictionary;
477 } 490 }
478 491
479 // TODO(jar): If we have evictions from the dictionaries_, then we need to 492 // TODO(jar): If we have evictions from the dictionaries_, then we need to
480 // change this interface to return a list of reference counted Dictionary 493 // change this interface to return a list of reference counted Dictionary
481 // instances that can be used if/when a server specifies one. 494 // instances that can be used if/when a server specifies one.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 case '/': 563 case '/':
551 (*output)[i] = '_'; 564 (*output)[i] = '_';
552 continue; 565 continue;
553 default: 566 default:
554 continue; 567 continue;
555 } 568 }
556 } 569 }
557 } 570 }
558 571
559 } // namespace net 572 } // namespace net
OLDNEW
« no previous file with comments | « net/base/sdch_manager.h ('k') | net/base/sdch_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698