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

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

Issue 380003002: Improve testing for SDCH. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed braino: Added SDHC enable to the tests that need it. Created 6 years, 5 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
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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 } 211 }
212 212
213 // static 213 // static
214 bool SdchManager::Dictionary::DomainMatch(const GURL& gurl, 214 bool SdchManager::Dictionary::DomainMatch(const GURL& gurl,
215 const std::string& restriction) { 215 const std::string& restriction) {
216 // TODO(jar): This is not precisely a domain match definition. 216 // TODO(jar): This is not precisely a domain match definition.
217 return gurl.DomainIs(restriction.data(), restriction.size()); 217 return gurl.DomainIs(restriction.data(), restriction.size());
218 } 218 }
219 219
220 //------------------------------------------------------------------------------ 220 //------------------------------------------------------------------------------
221 SdchManager::SdchManager() { 221 SdchManager::SdchManager()
222 : fetches_requested_(0) {
222 DCHECK(CalledOnValidThread()); 223 DCHECK(CalledOnValidThread());
223 } 224 }
224 225
225 SdchManager::~SdchManager() { 226 SdchManager::~SdchManager() {
226 DCHECK(CalledOnValidThread()); 227 DCHECK(CalledOnValidThread());
227 while (!dictionaries_.empty()) { 228 while (!dictionaries_.empty()) {
228 DictionaryMap::iterator it = dictionaries_.begin(); 229 DictionaryMap::iterator it = dictionaries_.begin();
229 dictionaries_.erase(it->first); 230 dictionaries_.erase(it->first);
230 } 231 }
231 } 232 }
(...skipping 10 matching lines...) Expand all
242 // 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
243 // to handle this case. 244 // to handle this case.
244 dictionaries_.clear(); 245 dictionaries_.clear();
245 } 246 }
246 247
247 // static 248 // static
248 void SdchManager::SdchErrorRecovery(ProblemCodes problem) { 249 void SdchManager::SdchErrorRecovery(ProblemCodes problem) {
249 UMA_HISTOGRAM_ENUMERATION("Sdch3.ProblemCodes_4", problem, MAX_PROBLEM_CODE); 250 UMA_HISTOGRAM_ENUMERATION("Sdch3.ProblemCodes_4", problem, MAX_PROBLEM_CODE);
250 } 251 }
251 252
252 void SdchManager::set_sdch_fetcher(SdchFetcher* fetcher) { 253 void SdchManager::set_sdch_fetcher(scoped_ptr<SdchFetcher> fetcher) {
253 DCHECK(CalledOnValidThread()); 254 DCHECK(CalledOnValidThread());
254 fetcher_.reset(fetcher); 255 fetcher_ = fetcher.Pass();
255 } 256 }
256 257
257 // static 258 // static
258 void SdchManager::EnableSdchSupport(bool enabled) { 259 void SdchManager::EnableSdchSupport(bool enabled) {
259 g_sdch_enabled_ = enabled; 260 g_sdch_enabled_ = enabled;
260 } 261 }
261 262
262 // static 263 // static
263 void SdchManager::EnableSecureSchemeSupport(bool enabled) { 264 void SdchManager::EnableSecureSchemeSupport(bool enabled) {
264 g_secure_scheme_supported_ = enabled; 265 g_secure_scheme_supported_ = enabled;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
332 blacklisted_domains_[domain] = count; 333 blacklisted_domains_[domain] = count;
333 else 334 else
334 blacklisted_domains_.erase(domain); 335 blacklisted_domains_.erase(domain);
335 SdchErrorRecovery(DOMAIN_BLACKLIST_INCLUDES_TARGET); 336 SdchErrorRecovery(DOMAIN_BLACKLIST_INCLUDES_TARGET);
336 return false; 337 return false;
337 } 338 }
338 339
339 void SdchManager::FetchDictionary(const GURL& request_url, 340 void SdchManager::FetchDictionary(const GURL& request_url,
340 const GURL& dictionary_url) { 341 const GURL& dictionary_url) {
341 DCHECK(CalledOnValidThread()); 342 DCHECK(CalledOnValidThread());
342 if (CanFetchDictionary(request_url, dictionary_url) && fetcher_.get()) 343 if (CanFetchDictionary(request_url, dictionary_url) && fetcher_.get()) {
344 ++fetches_requested_;
343 fetcher_->Schedule(dictionary_url); 345 fetcher_->Schedule(dictionary_url);
346 }
344 } 347 }
345 348
346 bool SdchManager::CanFetchDictionary(const GURL& referring_url, 349 bool SdchManager::CanFetchDictionary(const GURL& referring_url,
347 const GURL& dictionary_url) const { 350 const GURL& dictionary_url) const {
348 DCHECK(CalledOnValidThread()); 351 DCHECK(CalledOnValidThread());
349 /* The user agent may retrieve a dictionary from the dictionary URL if all of 352 /* The user agent may retrieve a dictionary from the dictionary URL if all of
350 the following are true: 353 the following are true:
351 1 The dictionary URL host name matches the referrer URL host name and 354 1 The dictionary URL host name matches the referrer URL host name and
352 scheme. 355 scheme.
353 2 The dictionary URL host name domain matches the parent domain of the 356 2 The dictionary URL host name domain matches the parent domain of the
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
550 allow_latency_experiment_.insert(url.host()); 553 allow_latency_experiment_.insert(url.host());
551 return; 554 return;
552 } 555 }
553 ExperimentSet::iterator it = allow_latency_experiment_.find(url.host()); 556 ExperimentSet::iterator it = allow_latency_experiment_.find(url.host());
554 if (allow_latency_experiment_.end() == it) 557 if (allow_latency_experiment_.end() == it)
555 return; // It was already erased, or never allowed. 558 return; // It was already erased, or never allowed.
556 SdchErrorRecovery(LATENCY_TEST_DISALLOWED); 559 SdchErrorRecovery(LATENCY_TEST_DISALLOWED);
557 allow_latency_experiment_.erase(it); 560 allow_latency_experiment_.erase(it);
558 } 561 }
559 562
563 int SdchManager::GetFetchesRequestedForTesting() const {
mef 2014/07/23 18:34:29 nit: should this be inline in header? Also should
Randy Smith (Not in Mondays) 2014/07/29 23:44:21 I think there's some auto-analysis of method names
mef 2014/07/30 17:14:58 I see, nice to know.
564 return fetches_requested_;
565 }
566
560 // static 567 // static
561 void SdchManager::UrlSafeBase64Encode(const std::string& input, 568 void SdchManager::UrlSafeBase64Encode(const std::string& input,
562 std::string* output) { 569 std::string* output) {
563 // Since this is only done during a dictionary load, and hashes are only 8 570 // Since this is only done during a dictionary load, and hashes are only 8
564 // characters, we just do the simple fixup, rather than rewriting the encoder. 571 // characters, we just do the simple fixup, rather than rewriting the encoder.
565 base::Base64Encode(input, output); 572 base::Base64Encode(input, output);
566 for (size_t i = 0; i < output->size(); ++i) { 573 for (size_t i = 0; i < output->size(); ++i) {
567 switch (output->data()[i]) { 574 switch (output->data()[i]) {
568 case '+': 575 case '+':
569 (*output)[i] = '-'; 576 (*output)[i] = '-';
570 continue; 577 continue;
571 case '/': 578 case '/':
572 (*output)[i] = '_'; 579 (*output)[i] = '_';
573 continue; 580 continue;
574 default: 581 default:
575 continue; 582 continue;
576 } 583 }
577 } 584 }
578 } 585 }
579 586
580 } // namespace net 587 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698