| 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_macros.h" | 9 #include "base/metrics/histogram_macros.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 GURL::Replacements replacements; | 31 GURL::Replacements replacements; |
| 32 replacements.SetHostStr(host); | 32 replacements.SetHostStr(host); |
| 33 *gurl = gurl->ReplaceComponents(replacements); | 33 *gurl = gurl->ReplaceComponents(replacements); |
| 34 return; | 34 return; |
| 35 } | 35 } |
| 36 | 36 |
| 37 } // namespace | 37 } // namespace |
| 38 | 38 |
| 39 namespace net { | 39 namespace net { |
| 40 | 40 |
| 41 // static | |
| 42 bool SdchManager::g_sdch_enabled_ = true; | |
| 43 | |
| 44 SdchManager::DictionarySet::DictionarySet() {} | 41 SdchManager::DictionarySet::DictionarySet() {} |
| 45 | 42 |
| 46 SdchManager::DictionarySet::~DictionarySet() {} | 43 SdchManager::DictionarySet::~DictionarySet() {} |
| 47 | 44 |
| 48 std::string SdchManager::DictionarySet::GetDictionaryClientHashList() const { | 45 std::string SdchManager::DictionarySet::GetDictionaryClientHashList() const { |
| 49 std::string result; | 46 std::string result; |
| 50 bool first = true; | 47 bool first = true; |
| 51 for (const auto& entry: dictionaries_) { | 48 for (const auto& entry: dictionaries_) { |
| 52 if (!first) | 49 if (!first) |
| 53 result.append(","); | 50 result.append(","); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 dictionaries_.clear(); | 93 dictionaries_.clear(); |
| 97 FOR_EACH_OBSERVER(SdchObserver, observers_, OnClearDictionaries()); | 94 FOR_EACH_OBSERVER(SdchObserver, observers_, OnClearDictionaries()); |
| 98 } | 95 } |
| 99 | 96 |
| 100 // static | 97 // static |
| 101 void SdchManager::SdchErrorRecovery(SdchProblemCode problem) { | 98 void SdchManager::SdchErrorRecovery(SdchProblemCode problem) { |
| 102 UMA_HISTOGRAM_ENUMERATION("Sdch3.ProblemCodes_5", problem, | 99 UMA_HISTOGRAM_ENUMERATION("Sdch3.ProblemCodes_5", problem, |
| 103 SDCH_MAX_PROBLEM_CODE); | 100 SDCH_MAX_PROBLEM_CODE); |
| 104 } | 101 } |
| 105 | 102 |
| 106 // static | |
| 107 void SdchManager::EnableSdchSupport(bool enabled) { | |
| 108 g_sdch_enabled_ = enabled; | |
| 109 } | |
| 110 | |
| 111 void SdchManager::BlacklistDomain(const GURL& url, | 103 void SdchManager::BlacklistDomain(const GURL& url, |
| 112 SdchProblemCode blacklist_reason) { | 104 SdchProblemCode blacklist_reason) { |
| 113 SetAllowLatencyExperiment(url, false); | 105 SetAllowLatencyExperiment(url, false); |
| 114 | 106 |
| 115 BlacklistInfo* blacklist_info = &blacklisted_domains_[url.host()]; | 107 BlacklistInfo* blacklist_info = &blacklisted_domains_[url.host()]; |
| 116 | 108 |
| 117 if (blacklist_info->count > 0) | 109 if (blacklist_info->count > 0) |
| 118 return; // Domain is already blacklisted. | 110 return; // Domain is already blacklisted. |
| 119 | 111 |
| 120 if (blacklist_info->exponential_count > (INT_MAX - 1) / 2) { | 112 if (blacklist_info->exponential_count > (INT_MAX - 1) / 2) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 int SdchManager::BlacklistDomainExponential(const std::string& domain) { | 152 int SdchManager::BlacklistDomainExponential(const std::string& domain) { |
| 161 std::string domain_lower(base::ToLowerASCII(domain)); | 153 std::string domain_lower(base::ToLowerASCII(domain)); |
| 162 | 154 |
| 163 if (blacklisted_domains_.end() == blacklisted_domains_.find(domain_lower)) | 155 if (blacklisted_domains_.end() == blacklisted_domains_.find(domain_lower)) |
| 164 return 0; | 156 return 0; |
| 165 return blacklisted_domains_[domain_lower].exponential_count; | 157 return blacklisted_domains_[domain_lower].exponential_count; |
| 166 } | 158 } |
| 167 | 159 |
| 168 SdchProblemCode SdchManager::IsInSupportedDomain(const GURL& url) { | 160 SdchProblemCode SdchManager::IsInSupportedDomain(const GURL& url) { |
| 169 DCHECK(thread_checker_.CalledOnValidThread()); | 161 DCHECK(thread_checker_.CalledOnValidThread()); |
| 170 if (!g_sdch_enabled_ ) | |
| 171 return SDCH_DISABLED; | |
| 172 | |
| 173 if (blacklisted_domains_.empty()) | 162 if (blacklisted_domains_.empty()) |
| 174 return SDCH_OK; | 163 return SDCH_OK; |
| 175 | 164 |
| 176 auto it = blacklisted_domains_.find(url.host()); | 165 auto it = blacklisted_domains_.find(url.host()); |
| 177 if (blacklisted_domains_.end() == it || it->second.count == 0) | 166 if (blacklisted_domains_.end() == it || it->second.count == 0) |
| 178 return SDCH_OK; | 167 return SDCH_OK; |
| 179 | 168 |
| 180 UMA_HISTOGRAM_ENUMERATION("Sdch3.BlacklistReason", it->second.reason, | 169 UMA_HISTOGRAM_ENUMERATION("Sdch3.BlacklistReason", it->second.reason, |
| 181 SDCH_MAX_PROBLEM_CODE); | 170 SDCH_MAX_PROBLEM_CODE); |
| 182 | 171 |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 // Since this is only done during a dictionary load, and hashes are only 8 | 438 // Since this is only done during a dictionary load, and hashes are only 8 |
| 450 // characters, we just do the simple fixup, rather than rewriting the encoder. | 439 // characters, we just do the simple fixup, rather than rewriting the encoder. |
| 451 base::Base64Encode(input, output); | 440 base::Base64Encode(input, output); |
| 452 std::replace(output->begin(), output->end(), '+', '-'); | 441 std::replace(output->begin(), output->end(), '+', '-'); |
| 453 std::replace(output->begin(), output->end(), '/', '_'); | 442 std::replace(output->begin(), output->end(), '/', '_'); |
| 454 } | 443 } |
| 455 | 444 |
| 456 scoped_ptr<base::Value> SdchManager::SdchInfoToValue() const { | 445 scoped_ptr<base::Value> SdchManager::SdchInfoToValue() const { |
| 457 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 446 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
| 458 | 447 |
| 459 value->SetBoolean("sdch_enabled", sdch_enabled()); | 448 value->SetBoolean("sdch_enabled", true); |
| 460 | 449 |
| 461 scoped_ptr<base::ListValue> entry_list(new base::ListValue()); | 450 scoped_ptr<base::ListValue> entry_list(new base::ListValue()); |
| 462 for (const auto& entry: dictionaries_) { | 451 for (const auto& entry: dictionaries_) { |
| 463 scoped_ptr<base::DictionaryValue> entry_dict(new base::DictionaryValue()); | 452 scoped_ptr<base::DictionaryValue> entry_dict(new base::DictionaryValue()); |
| 464 entry_dict->SetString("url", entry.second->data.url().spec()); | 453 entry_dict->SetString("url", entry.second->data.url().spec()); |
| 465 entry_dict->SetString("client_hash", entry.second->data.client_hash()); | 454 entry_dict->SetString("client_hash", entry.second->data.client_hash()); |
| 466 entry_dict->SetString("domain", entry.second->data.domain()); | 455 entry_dict->SetString("domain", entry.second->data.domain()); |
| 467 entry_dict->SetString("path", entry.second->data.path()); | 456 entry_dict->SetString("path", entry.second->data.path()); |
| 468 scoped_ptr<base::ListValue> port_list(new base::ListValue()); | 457 scoped_ptr<base::ListValue> port_list(new base::ListValue()); |
| 469 for (std::set<int>::const_iterator port_it = | 458 for (std::set<int>::const_iterator port_it = |
| (...skipping 18 matching lines...) Expand all Loading... |
| 488 entry_dict->SetInteger("tries", it->second.count); | 477 entry_dict->SetInteger("tries", it->second.count); |
| 489 entry_dict->SetInteger("reason", it->second.reason); | 478 entry_dict->SetInteger("reason", it->second.reason); |
| 490 entry_list->Append(entry_dict.Pass()); | 479 entry_list->Append(entry_dict.Pass()); |
| 491 } | 480 } |
| 492 value->Set("blacklisted", entry_list.Pass()); | 481 value->Set("blacklisted", entry_list.Pass()); |
| 493 | 482 |
| 494 return value.Pass(); | 483 return value.Pass(); |
| 495 } | 484 } |
| 496 | 485 |
| 497 } // namespace net | 486 } // namespace net |
| OLD | NEW |