| 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 | 105 |
| 106 // static | 106 // static |
| 107 void SdchManager::EnableSdchSupport(bool enabled) { | 107 void SdchManager::EnableSdchSupport(bool enabled) { |
| 108 g_sdch_enabled_ = enabled; | 108 g_sdch_enabled_ = enabled; |
| 109 } | 109 } |
| 110 | 110 |
| 111 void SdchManager::BlacklistDomain(const GURL& url, | 111 void SdchManager::BlacklistDomain(const GURL& url, |
| 112 SdchProblemCode blacklist_reason) { | 112 SdchProblemCode blacklist_reason) { |
| 113 SetAllowLatencyExperiment(url, false); | 113 SetAllowLatencyExperiment(url, false); |
| 114 | 114 |
| 115 BlacklistInfo* blacklist_info = | 115 BlacklistInfo* blacklist_info = &blacklisted_domains_[url.host()]; |
| 116 &blacklisted_domains_[base::StringToLowerASCII(url.host())]; | |
| 117 | 116 |
| 118 if (blacklist_info->count > 0) | 117 if (blacklist_info->count > 0) |
| 119 return; // Domain is already blacklisted. | 118 return; // Domain is already blacklisted. |
| 120 | 119 |
| 121 if (blacklist_info->exponential_count > (INT_MAX - 1) / 2) { | 120 if (blacklist_info->exponential_count > (INT_MAX - 1) / 2) { |
| 122 blacklist_info->exponential_count = INT_MAX; | 121 blacklist_info->exponential_count = INT_MAX; |
| 123 } else { | 122 } else { |
| 124 blacklist_info->exponential_count = | 123 blacklist_info->exponential_count = |
| 125 blacklist_info->exponential_count * 2 + 1; | 124 blacklist_info->exponential_count * 2 + 1; |
| 126 } | 125 } |
| 127 | 126 |
| 128 blacklist_info->count = blacklist_info->exponential_count; | 127 blacklist_info->count = blacklist_info->exponential_count; |
| 129 blacklist_info->reason = blacklist_reason; | 128 blacklist_info->reason = blacklist_reason; |
| 130 } | 129 } |
| 131 | 130 |
| 132 void SdchManager::BlacklistDomainForever(const GURL& url, | 131 void SdchManager::BlacklistDomainForever(const GURL& url, |
| 133 SdchProblemCode blacklist_reason) { | 132 SdchProblemCode blacklist_reason) { |
| 134 SetAllowLatencyExperiment(url, false); | 133 SetAllowLatencyExperiment(url, false); |
| 135 | 134 |
| 136 BlacklistInfo* blacklist_info = | 135 BlacklistInfo* blacklist_info = &blacklisted_domains_[url.host()]; |
| 137 &blacklisted_domains_[base::StringToLowerASCII(url.host())]; | |
| 138 blacklist_info->count = INT_MAX; | 136 blacklist_info->count = INT_MAX; |
| 139 blacklist_info->exponential_count = INT_MAX; | 137 blacklist_info->exponential_count = INT_MAX; |
| 140 blacklist_info->reason = blacklist_reason; | 138 blacklist_info->reason = blacklist_reason; |
| 141 } | 139 } |
| 142 | 140 |
| 143 void SdchManager::ClearBlacklistings() { | 141 void SdchManager::ClearBlacklistings() { |
| 144 blacklisted_domains_.clear(); | 142 blacklisted_domains_.clear(); |
| 145 } | 143 } |
| 146 | 144 |
| 147 void SdchManager::ClearDomainBlacklisting(const std::string& domain) { | 145 void SdchManager::ClearDomainBlacklisting(const std::string& domain) { |
| 148 BlacklistInfo* blacklist_info = &blacklisted_domains_[ | 146 BlacklistInfo* blacklist_info = |
| 149 base::StringToLowerASCII(domain)]; | 147 &blacklisted_domains_[base::ToLowerASCII(domain)]; |
| 150 blacklist_info->count = 0; | 148 blacklist_info->count = 0; |
| 151 blacklist_info->reason = SDCH_OK; | 149 blacklist_info->reason = SDCH_OK; |
| 152 } | 150 } |
| 153 | 151 |
| 154 int SdchManager::BlackListDomainCount(const std::string& domain) { | 152 int SdchManager::BlackListDomainCount(const std::string& domain) { |
| 155 std::string domain_lower(base::StringToLowerASCII(domain)); | 153 std::string domain_lower(base::ToLowerASCII(domain)); |
| 156 | 154 |
| 157 if (blacklisted_domains_.end() == blacklisted_domains_.find(domain_lower)) | 155 if (blacklisted_domains_.end() == blacklisted_domains_.find(domain_lower)) |
| 158 return 0; | 156 return 0; |
| 159 return blacklisted_domains_[domain_lower].count; | 157 return blacklisted_domains_[domain_lower].count; |
| 160 } | 158 } |
| 161 | 159 |
| 162 int SdchManager::BlacklistDomainExponential(const std::string& domain) { | 160 int SdchManager::BlacklistDomainExponential(const std::string& domain) { |
| 163 std::string domain_lower(base::StringToLowerASCII(domain)); | 161 std::string domain_lower(base::ToLowerASCII(domain)); |
| 164 | 162 |
| 165 if (blacklisted_domains_.end() == blacklisted_domains_.find(domain_lower)) | 163 if (blacklisted_domains_.end() == blacklisted_domains_.find(domain_lower)) |
| 166 return 0; | 164 return 0; |
| 167 return blacklisted_domains_[domain_lower].exponential_count; | 165 return blacklisted_domains_[domain_lower].exponential_count; |
| 168 } | 166 } |
| 169 | 167 |
| 170 SdchProblemCode SdchManager::IsInSupportedDomain(const GURL& url) { | 168 SdchProblemCode SdchManager::IsInSupportedDomain(const GURL& url) { |
| 171 DCHECK(thread_checker_.CalledOnValidThread()); | 169 DCHECK(thread_checker_.CalledOnValidThread()); |
| 172 if (!g_sdch_enabled_ ) | 170 if (!g_sdch_enabled_ ) |
| 173 return SDCH_DISABLED; | 171 return SDCH_DISABLED; |
| 174 | 172 |
| 175 if (blacklisted_domains_.empty()) | 173 if (blacklisted_domains_.empty()) |
| 176 return SDCH_OK; | 174 return SDCH_OK; |
| 177 | 175 |
| 178 DomainBlacklistInfo::iterator it = | 176 auto it = blacklisted_domains_.find(url.host()); |
| 179 blacklisted_domains_.find(base::StringToLowerASCII(url.host())); | |
| 180 if (blacklisted_domains_.end() == it || it->second.count == 0) | 177 if (blacklisted_domains_.end() == it || it->second.count == 0) |
| 181 return SDCH_OK; | 178 return SDCH_OK; |
| 182 | 179 |
| 183 UMA_HISTOGRAM_ENUMERATION("Sdch3.BlacklistReason", it->second.reason, | 180 UMA_HISTOGRAM_ENUMERATION("Sdch3.BlacklistReason", it->second.reason, |
| 184 SDCH_MAX_PROBLEM_CODE); | 181 SDCH_MAX_PROBLEM_CODE); |
| 185 | 182 |
| 186 int count = it->second.count - 1; | 183 int count = it->second.count - 1; |
| 187 if (count > 0) { | 184 if (count > 0) { |
| 188 it->second.count = count; | 185 it->second.count = count; |
| 189 } else { | 186 } else { |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 if (colon_index > line_end) | 364 if (colon_index > line_end) |
| 368 break; | 365 break; |
| 369 | 366 |
| 370 size_t value_start = dictionary_text.find_first_not_of(" \t", | 367 size_t value_start = dictionary_text.find_first_not_of(" \t", |
| 371 colon_index + 1); | 368 colon_index + 1); |
| 372 if (std::string::npos != value_start) { | 369 if (std::string::npos != value_start) { |
| 373 if (value_start >= line_end) | 370 if (value_start >= line_end) |
| 374 break; | 371 break; |
| 375 std::string name(dictionary_text, line_start, colon_index - line_start); | 372 std::string name(dictionary_text, line_start, colon_index - line_start); |
| 376 std::string value(dictionary_text, value_start, line_end - value_start); | 373 std::string value(dictionary_text, value_start, line_end - value_start); |
| 377 name = base::StringToLowerASCII(name); | 374 name = base::ToLowerASCII(name); |
| 378 if (name == "domain") { | 375 if (name == "domain") { |
| 379 domain = value; | 376 domain = value; |
| 380 } else if (name == "path") { | 377 } else if (name == "path") { |
| 381 path = value; | 378 path = value; |
| 382 } else if (name == "format-version") { | 379 } else if (name == "format-version") { |
| 383 if (value != "1.0") | 380 if (value != "1.0") |
| 384 return SDCH_DICTIONARY_UNSUPPORTED_VERSION; | 381 return SDCH_DICTIONARY_UNSUPPORTED_VERSION; |
| 385 } else if (name == "max-age") { | 382 } else if (name == "max-age") { |
| 386 int64_t seconds; | 383 int64_t seconds; |
| 387 base::StringToInt64(value, &seconds); | 384 base::StringToInt64(value, &seconds); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 entry_dict->SetInteger("tries", it->second.count); | 488 entry_dict->SetInteger("tries", it->second.count); |
| 492 entry_dict->SetInteger("reason", it->second.reason); | 489 entry_dict->SetInteger("reason", it->second.reason); |
| 493 entry_list->Append(entry_dict.Pass()); | 490 entry_list->Append(entry_dict.Pass()); |
| 494 } | 491 } |
| 495 value->Set("blacklisted", entry_list.Pass()); | 492 value->Set("blacklisted", entry_list.Pass()); |
| 496 | 493 |
| 497 return value.Pass(); | 494 return value.Pass(); |
| 498 } | 495 } |
| 499 | 496 |
| 500 } // namespace net | 497 } // namespace net |
| OLD | NEW |