OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "base/field_trial.h" | 5 #include "base/field_trial.h" |
6 #include "base/histogram.h" | 6 #include "base/histogram.h" |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/sha2.h" | 8 #include "base/sha2.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "net/base/base64.h" | 10 #include "net/base/base64.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 it->second->Release(); | 78 it->second->Release(); |
79 dictionaries_.erase(it->first); | 79 dictionaries_.erase(it->first); |
80 } | 80 } |
81 global_ = NULL; | 81 global_ = NULL; |
82 } | 82 } |
83 | 83 |
84 // static | 84 // static |
85 void SdchManager::BlacklistDomain(const GURL& url) { | 85 void SdchManager::BlacklistDomain(const GURL& url) { |
86 if (!global_ ) | 86 if (!global_ ) |
87 return; | 87 return; |
| 88 global_->SetAllowLatencyExperiment(url, false); |
88 | 89 |
89 std::string domain(StringToLowerASCII(url.host())); | 90 std::string domain(StringToLowerASCII(url.host())); |
90 int count = global_->blacklisted_domains_[domain]; | 91 int count = global_->blacklisted_domains_[domain]; |
91 if (count > 0) | 92 if (count > 0) |
92 return; // Domain is already blacklisted. | 93 return; // Domain is already blacklisted. |
93 | 94 |
94 count = 1 + 2 * global_->exponential_blacklist_count[domain]; | 95 count = 1 + 2 * global_->exponential_blacklist_count[domain]; |
95 if (count > 0) | 96 if (count > 0) |
96 global_->exponential_blacklist_count[domain] = count; | 97 global_->exponential_blacklist_count[domain] = count; |
97 else | 98 else |
98 count = INT_MAX; | 99 count = INT_MAX; |
99 | 100 |
100 global_->blacklisted_domains_[domain] = count; | 101 global_->blacklisted_domains_[domain] = count; |
101 } | 102 } |
102 | 103 |
103 // static | 104 // static |
104 void SdchManager::BlacklistDomainForever(const GURL& url) { | 105 void SdchManager::BlacklistDomainForever(const GURL& url) { |
105 if (!global_ ) | 106 if (!global_ ) |
106 return; | 107 return; |
| 108 global_->SetAllowLatencyExperiment(url, false); |
107 | 109 |
108 std::string domain(StringToLowerASCII(url.host())); | 110 std::string domain(StringToLowerASCII(url.host())); |
109 global_->exponential_blacklist_count[domain] = INT_MAX; | 111 global_->exponential_blacklist_count[domain] = INT_MAX; |
110 global_->blacklisted_domains_[domain] = INT_MAX; | 112 global_->blacklisted_domains_[domain] = INT_MAX; |
111 } | 113 } |
112 | 114 |
113 void SdchManager::EnableSdchSupport(const std::string& domain) { | 115 void SdchManager::EnableSdchSupport(const std::string& domain) { |
114 // We presume that there is a SDCH manager instance. | 116 // We presume that there is a SDCH manager instance. |
115 global_->supported_domain_ = domain; | 117 global_->supported_domain_ = domain; |
116 global_->sdch_enabled_ = true; | 118 global_->sdch_enabled_ = true; |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 void SdchManager::GenerateHash(const std::string& dictionary_text, | 326 void SdchManager::GenerateHash(const std::string& dictionary_text, |
325 std::string* client_hash, std::string* server_hash) { | 327 std::string* client_hash, std::string* server_hash) { |
326 char binary_hash[32]; | 328 char binary_hash[32]; |
327 base::SHA256HashString(dictionary_text, binary_hash, sizeof(binary_hash)); | 329 base::SHA256HashString(dictionary_text, binary_hash, sizeof(binary_hash)); |
328 | 330 |
329 std::string first_48_bits(&binary_hash[0], 6); | 331 std::string first_48_bits(&binary_hash[0], 6); |
330 std::string second_48_bits(&binary_hash[6], 6); | 332 std::string second_48_bits(&binary_hash[6], 6); |
331 UrlSafeBase64Encode(first_48_bits, client_hash); | 333 UrlSafeBase64Encode(first_48_bits, client_hash); |
332 UrlSafeBase64Encode(second_48_bits, server_hash); | 334 UrlSafeBase64Encode(second_48_bits, server_hash); |
333 | 335 |
334 DCHECK(server_hash->length() == 8); | 336 DCHECK_EQ(server_hash->length(), 8u); |
335 DCHECK(client_hash->length() == 8); | 337 DCHECK_EQ(client_hash->length(), 8u); |
336 } | 338 } |
337 | 339 |
338 // static | 340 // static |
339 void SdchManager::UrlSafeBase64Encode(const std::string& input, | 341 void SdchManager::UrlSafeBase64Encode(const std::string& input, |
340 std::string* output) { | 342 std::string* output) { |
341 // Since this is only done during a dictionary load, and hashes are only 8 | 343 // Since this is only done during a dictionary load, and hashes are only 8 |
342 // characters, we just do the simple fixup, rather than rewriting the encoder. | 344 // characters, we just do the simple fixup, rather than rewriting the encoder. |
343 net::Base64Encode(input, output); | 345 net::Base64Encode(input, output); |
344 for (size_t i = 0; i < output->size(); ++i) { | 346 for (size_t i = 0; i < output->size(); ++i) { |
345 switch (output->data()[i]) { | 347 switch (output->data()[i]) { |
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 return false; | 502 return false; |
501 return restriction[prefix_length - 1] == '/' || path[prefix_length] == '/'; | 503 return restriction[prefix_length - 1] == '/' || path[prefix_length] == '/'; |
502 } | 504 } |
503 | 505 |
504 // static | 506 // static |
505 bool SdchManager::Dictionary::DomainMatch(const GURL& gurl, | 507 bool SdchManager::Dictionary::DomainMatch(const GURL& gurl, |
506 const std::string& restriction) { | 508 const std::string& restriction) { |
507 // TODO(jar): This is not precisely a domain match definition. | 509 // TODO(jar): This is not precisely a domain match definition. |
508 return gurl.DomainIs(restriction.data(), restriction.size()); | 510 return gurl.DomainIs(restriction.data(), restriction.size()); |
509 } | 511 } |
| 512 |
| 513 //------------------------------------------------------------------------------ |
| 514 // Methods for supporting latency experiments. |
| 515 |
| 516 bool SdchManager::AllowLatencyExperiment(const GURL& url) const { |
| 517 return allow_latency_experiment_.end() != |
| 518 allow_latency_experiment_.find(url.host()); |
| 519 } |
| 520 |
| 521 void SdchManager::SetAllowLatencyExperiment(const GURL& url, bool enable) { |
| 522 if (enable) { |
| 523 allow_latency_experiment_.insert(url.host()); |
| 524 return; |
| 525 } |
| 526 ExperimentSet::iterator it = allow_latency_experiment_.find(url.host()); |
| 527 if (allow_latency_experiment_.end() == it) |
| 528 return; // It was already erased, or never allowed. |
| 529 SdchErrorRecovery(LATENCY_TEST_DISALLOWED); |
| 530 allow_latency_experiment_.erase(it); |
| 531 } |
OLD | NEW |