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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(); | 222 it->second->Release(); |
223 dictionaries_.erase(it->first); | 223 dictionaries_.erase(it->first); |
224 } | 224 } |
225 } | 225 } |
226 | 226 |
227 void SdchManager::ClearData() { | |
228 blacklisted_domains_.clear(); | |
229 exponential_blacklist_count_.clear(); | |
230 allow_latency_experiment_.clear(); | |
231 if (fetcher_.get()) | |
232 fetcher_->Cancel(); | |
233 | |
234 // Note that this may result in not having dictionaries we've advertised | |
235 // for incoming responses. The window is relatively small (as ClearData() | |
236 // is not expected to be called frequently), so we rely on meta-refresh | |
237 // to handle this case. | |
238 dictionaries_.clear(); | |
239 } | |
240 | |
241 // static | 227 // static |
242 void SdchManager::SdchErrorRecovery(ProblemCodes problem) { | 228 void SdchManager::SdchErrorRecovery(ProblemCodes problem) { |
243 UMA_HISTOGRAM_ENUMERATION("Sdch3.ProblemCodes_4", problem, MAX_PROBLEM_CODE); | 229 UMA_HISTOGRAM_ENUMERATION("Sdch3.ProblemCodes_4", problem, MAX_PROBLEM_CODE); |
244 } | 230 } |
245 | 231 |
246 void SdchManager::set_sdch_fetcher(SdchFetcher* fetcher) { | 232 void SdchManager::set_sdch_fetcher(SdchFetcher* fetcher) { |
247 DCHECK(CalledOnValidThread()); | 233 DCHECK(CalledOnValidThread()); |
248 fetcher_.reset(fetcher); | 234 fetcher_.reset(fetcher); |
249 } | 235 } |
250 | 236 |
251 // static | 237 // static |
252 void SdchManager::EnableSdchSupport(bool enabled) { | 238 void SdchManager::EnableSdchSupport(bool enabled) { |
253 g_sdch_enabled_ = enabled; | 239 g_sdch_enabled_ = enabled; |
254 } | 240 } |
255 | 241 |
256 // static | 242 // static |
257 void SdchManager::EnableSecureSchemeSupport(bool enabled) { | 243 void SdchManager::EnableSecureSchemeSupport(bool enabled) { |
258 g_secure_scheme_supported_ = enabled; | 244 g_secure_scheme_supported_ = enabled; |
259 } | 245 } |
260 | 246 |
261 void SdchManager::BlacklistDomain(const GURL& url) { | 247 void SdchManager::BlacklistDomain(const GURL& url) { |
262 SetAllowLatencyExperiment(url, false); | 248 SetAllowLatencyExperiment(url, false); |
263 | 249 |
264 std::string domain(StringToLowerASCII(url.host())); | 250 std::string domain(StringToLowerASCII(url.host())); |
265 int count = blacklisted_domains_[domain]; | 251 int count = blacklisted_domains_[domain]; |
266 if (count > 0) | 252 if (count > 0) |
267 return; // Domain is already blacklisted. | 253 return; // Domain is already blacklisted. |
268 | 254 |
269 count = 1 + 2 * exponential_blacklist_count_[domain]; | 255 count = 1 + 2 * exponential_blacklist_count[domain]; |
270 if (count > 0) | 256 if (count > 0) |
271 exponential_blacklist_count_[domain] = count; | 257 exponential_blacklist_count[domain] = count; |
272 else | 258 else |
273 count = INT_MAX; | 259 count = INT_MAX; |
274 | 260 |
275 blacklisted_domains_[domain] = count; | 261 blacklisted_domains_[domain] = count; |
276 } | 262 } |
277 | 263 |
278 void SdchManager::BlacklistDomainForever(const GURL& url) { | 264 void SdchManager::BlacklistDomainForever(const GURL& url) { |
279 SetAllowLatencyExperiment(url, false); | 265 SetAllowLatencyExperiment(url, false); |
280 | 266 |
281 std::string domain(StringToLowerASCII(url.host())); | 267 std::string domain(StringToLowerASCII(url.host())); |
282 exponential_blacklist_count_[domain] = INT_MAX; | 268 exponential_blacklist_count[domain] = INT_MAX; |
283 blacklisted_domains_[domain] = INT_MAX; | 269 blacklisted_domains_[domain] = INT_MAX; |
284 } | 270 } |
285 | 271 |
286 void SdchManager::ClearBlacklistings() { | 272 void SdchManager::ClearBlacklistings() { |
287 blacklisted_domains_.clear(); | 273 blacklisted_domains_.clear(); |
288 exponential_blacklist_count_.clear(); | 274 exponential_blacklist_count.clear(); |
289 } | 275 } |
290 | 276 |
291 void SdchManager::ClearDomainBlacklisting(const std::string& domain) { | 277 void SdchManager::ClearDomainBlacklisting(const std::string& domain) { |
292 blacklisted_domains_.erase(StringToLowerASCII(domain)); | 278 blacklisted_domains_.erase(StringToLowerASCII(domain)); |
293 } | 279 } |
294 | 280 |
295 int SdchManager::BlackListDomainCount(const std::string& domain) { | 281 int SdchManager::BlackListDomainCount(const std::string& domain) { |
296 if (blacklisted_domains_.end() == blacklisted_domains_.find(domain)) | 282 if (blacklisted_domains_.end() == blacklisted_domains_.find(domain)) |
297 return 0; | 283 return 0; |
298 return blacklisted_domains_[StringToLowerASCII(domain)]; | 284 return blacklisted_domains_[StringToLowerASCII(domain)]; |
299 } | 285 } |
300 | 286 |
301 int SdchManager::BlacklistDomainExponential(const std::string& domain) { | 287 int SdchManager::BlacklistDomainExponential(const std::string& domain) { |
302 if (exponential_blacklist_count_.end() == | 288 if (exponential_blacklist_count.end() == |
303 exponential_blacklist_count_.find(domain)) | 289 exponential_blacklist_count.find(domain)) |
304 return 0; | 290 return 0; |
305 return exponential_blacklist_count_[StringToLowerASCII(domain)]; | 291 return exponential_blacklist_count[StringToLowerASCII(domain)]; |
306 } | 292 } |
307 | 293 |
308 bool SdchManager::IsInSupportedDomain(const GURL& url) { | 294 bool SdchManager::IsInSupportedDomain(const GURL& url) { |
309 DCHECK(CalledOnValidThread()); | 295 DCHECK(CalledOnValidThread()); |
310 if (!g_sdch_enabled_ ) | 296 if (!g_sdch_enabled_ ) |
311 return false; | 297 return false; |
312 | 298 |
313 if (!secure_scheme_supported() && url.SchemeIsSecure()) | 299 if (!secure_scheme_supported() && url.SchemeIsSecure()) |
314 return false; | 300 return false; |
315 | 301 |
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 case '/': | 550 case '/': |
565 (*output)[i] = '_'; | 551 (*output)[i] = '_'; |
566 continue; | 552 continue; |
567 default: | 553 default: |
568 continue; | 554 continue; |
569 } | 555 } |
570 } | 556 } |
571 } | 557 } |
572 | 558 |
573 } // namespace net | 559 } // namespace net |
OLD | NEW |