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 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 } | 213 } |
214 | 214 |
215 // static | 215 // static |
216 bool SdchManager::Dictionary::DomainMatch(const GURL& gurl, | 216 bool SdchManager::Dictionary::DomainMatch(const GURL& gurl, |
217 const std::string& restriction) { | 217 const std::string& restriction) { |
218 // TODO(jar): This is not precisely a domain match definition. | 218 // TODO(jar): This is not precisely a domain match definition. |
219 return gurl.DomainIs(restriction.data(), restriction.size()); | 219 return gurl.DomainIs(restriction.data(), restriction.size()); |
220 } | 220 } |
221 | 221 |
222 //------------------------------------------------------------------------------ | 222 //------------------------------------------------------------------------------ |
223 SdchManager::SdchManager() { | 223 SdchManager::SdchManager() |
| 224 : fetches_count_for_testing_(0) { |
224 DCHECK(CalledOnValidThread()); | 225 DCHECK(CalledOnValidThread()); |
225 } | 226 } |
226 | 227 |
227 SdchManager::~SdchManager() { | 228 SdchManager::~SdchManager() { |
228 DCHECK(CalledOnValidThread()); | 229 DCHECK(CalledOnValidThread()); |
229 while (!dictionaries_.empty()) { | 230 while (!dictionaries_.empty()) { |
230 DictionaryMap::iterator it = dictionaries_.begin(); | 231 DictionaryMap::iterator it = dictionaries_.begin(); |
231 dictionaries_.erase(it->first); | 232 dictionaries_.erase(it->first); |
232 } | 233 } |
233 } | 234 } |
234 | 235 |
235 void SdchManager::ClearData() { | 236 void SdchManager::ClearData() { |
236 blacklisted_domains_.clear(); | 237 blacklisted_domains_.clear(); |
237 allow_latency_experiment_.clear(); | 238 allow_latency_experiment_.clear(); |
238 if (fetcher_.get()) | 239 if (fetcher_.get()) |
239 fetcher_->Cancel(); | 240 fetcher_->Cancel(); |
240 | 241 |
241 // Note that this may result in not having dictionaries we've advertised | 242 // Note that this may result in not having dictionaries we've advertised |
242 // for incoming responses. The window is relatively small (as ClearData() | 243 // for incoming responses. The window is relatively small (as ClearData() |
243 // is not expected to be called frequently), so we rely on meta-refresh | 244 // is not expected to be called frequently), so we rely on meta-refresh |
244 // to handle this case. | 245 // to handle this case. |
245 dictionaries_.clear(); | 246 dictionaries_.clear(); |
246 } | 247 } |
247 | 248 |
248 // static | 249 // static |
249 void SdchManager::SdchErrorRecovery(ProblemCodes problem) { | 250 void SdchManager::SdchErrorRecovery(ProblemCodes problem) { |
250 UMA_HISTOGRAM_ENUMERATION("Sdch3.ProblemCodes_4", problem, MAX_PROBLEM_CODE); | 251 UMA_HISTOGRAM_ENUMERATION("Sdch3.ProblemCodes_4", problem, MAX_PROBLEM_CODE); |
251 } | 252 } |
252 | 253 |
253 void SdchManager::set_sdch_fetcher(SdchFetcher* fetcher) { | 254 void SdchManager::set_sdch_fetcher(scoped_ptr<SdchFetcher> fetcher) { |
254 DCHECK(CalledOnValidThread()); | 255 DCHECK(CalledOnValidThread()); |
255 fetcher_.reset(fetcher); | 256 fetcher_ = fetcher.Pass(); |
256 } | 257 } |
257 | 258 |
258 // static | 259 // static |
259 void SdchManager::EnableSdchSupport(bool enabled) { | 260 void SdchManager::EnableSdchSupport(bool enabled) { |
260 g_sdch_enabled_ = enabled; | 261 g_sdch_enabled_ = enabled; |
261 } | 262 } |
262 | 263 |
263 // static | 264 // static |
264 void SdchManager::EnableSecureSchemeSupport(bool enabled) { | 265 void SdchManager::EnableSecureSchemeSupport(bool enabled) { |
265 g_secure_scheme_supported_ = enabled; | 266 g_secure_scheme_supported_ = enabled; |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 it->second.count = 0; | 352 it->second.count = 0; |
352 it->second.reason = MIN_PROBLEM_CODE; | 353 it->second.reason = MIN_PROBLEM_CODE; |
353 } | 354 } |
354 | 355 |
355 return false; | 356 return false; |
356 } | 357 } |
357 | 358 |
358 void SdchManager::FetchDictionary(const GURL& request_url, | 359 void SdchManager::FetchDictionary(const GURL& request_url, |
359 const GURL& dictionary_url) { | 360 const GURL& dictionary_url) { |
360 DCHECK(CalledOnValidThread()); | 361 DCHECK(CalledOnValidThread()); |
361 if (CanFetchDictionary(request_url, dictionary_url) && fetcher_.get()) | 362 if (CanFetchDictionary(request_url, dictionary_url) && fetcher_.get()) { |
| 363 ++fetches_count_for_testing_; |
362 fetcher_->Schedule(dictionary_url); | 364 fetcher_->Schedule(dictionary_url); |
| 365 } |
363 } | 366 } |
364 | 367 |
365 bool SdchManager::CanFetchDictionary(const GURL& referring_url, | 368 bool SdchManager::CanFetchDictionary(const GURL& referring_url, |
366 const GURL& dictionary_url) const { | 369 const GURL& dictionary_url) const { |
367 DCHECK(CalledOnValidThread()); | 370 DCHECK(CalledOnValidThread()); |
368 /* The user agent may retrieve a dictionary from the dictionary URL if all of | 371 /* The user agent may retrieve a dictionary from the dictionary URL if all of |
369 the following are true: | 372 the following are true: |
370 1 The dictionary URL host name matches the referrer URL host name and | 373 1 The dictionary URL host name matches the referrer URL host name and |
371 scheme. | 374 scheme. |
372 2 The dictionary URL host name domain matches the parent domain of the | 375 2 The dictionary URL host name domain matches the parent domain of the |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
575 SdchErrorRecovery(LATENCY_TEST_DISALLOWED); | 578 SdchErrorRecovery(LATENCY_TEST_DISALLOWED); |
576 allow_latency_experiment_.erase(it); | 579 allow_latency_experiment_.erase(it); |
577 } | 580 } |
578 | 581 |
579 // static | 582 // static |
580 void SdchManager::UrlSafeBase64Encode(const std::string& input, | 583 void SdchManager::UrlSafeBase64Encode(const std::string& input, |
581 std::string* output) { | 584 std::string* output) { |
582 // Since this is only done during a dictionary load, and hashes are only 8 | 585 // Since this is only done during a dictionary load, and hashes are only 8 |
583 // characters, we just do the simple fixup, rather than rewriting the encoder. | 586 // characters, we just do the simple fixup, rather than rewriting the encoder. |
584 base::Base64Encode(input, output); | 587 base::Base64Encode(input, output); |
585 for (size_t i = 0; i < output->size(); ++i) { | 588 std::replace(output->begin(), output->end(), '+', '-'); |
586 switch (output->data()[i]) { | 589 std::replace(output->begin(), output->end(), '/', '_'); |
587 case '+': | |
588 (*output)[i] = '-'; | |
589 continue; | |
590 case '/': | |
591 (*output)[i] = '_'; | |
592 continue; | |
593 default: | |
594 continue; | |
595 } | |
596 } | |
597 } | 590 } |
598 | 591 |
599 } // namespace net | 592 } // namespace net |
OLD | NEW |