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 <utility> |
| 8 |
7 #include "base/base64url.h" | 9 #include "base/base64url.h" |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
9 #include "base/metrics/histogram_macros.h" | 11 #include "base/metrics/histogram_macros.h" |
10 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
11 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
12 #include "base/time/default_clock.h" | 14 #include "base/time/default_clock.h" |
13 #include "base/values.h" | 15 #include "base/values.h" |
14 #include "crypto/sha2.h" | 16 #include "crypto/sha2.h" |
15 #include "net/base/sdch_observer.h" | 17 #include "net/base/sdch_observer.h" |
16 #include "net/url_request/url_request_http_job.h" | 18 #include "net/url_request/url_request_http_job.h" |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
240 continue; | 242 continue; |
241 ++count; | 243 ++count; |
242 result->AddDictionary(entry.first, entry.second); | 244 result->AddDictionary(entry.first, entry.second); |
243 } | 245 } |
244 | 246 |
245 if (count == 0) | 247 if (count == 0) |
246 return NULL; | 248 return NULL; |
247 | 249 |
248 UMA_HISTOGRAM_COUNTS("Sdch3.Advertisement_Count", count); | 250 UMA_HISTOGRAM_COUNTS("Sdch3.Advertisement_Count", count); |
249 | 251 |
250 return result.Pass(); | 252 return result; |
251 } | 253 } |
252 | 254 |
253 scoped_ptr<SdchManager::DictionarySet> | 255 scoped_ptr<SdchManager::DictionarySet> |
254 SdchManager::GetDictionarySetByHash( | 256 SdchManager::GetDictionarySetByHash( |
255 const GURL& target_url, | 257 const GURL& target_url, |
256 const std::string& server_hash, | 258 const std::string& server_hash, |
257 SdchProblemCode* problem_code) { | 259 SdchProblemCode* problem_code) { |
258 scoped_ptr<SdchManager::DictionarySet> result; | 260 scoped_ptr<SdchManager::DictionarySet> result; |
259 | 261 |
260 *problem_code = SDCH_DICTIONARY_HASH_NOT_FOUND; | 262 *problem_code = SDCH_DICTIONARY_HASH_NOT_FOUND; |
261 const auto& it = dictionaries_.find(server_hash); | 263 const auto& it = dictionaries_.find(server_hash); |
262 if (it == dictionaries_.end()) | 264 if (it == dictionaries_.end()) |
263 return result.Pass(); | 265 return result; |
264 | 266 |
265 *problem_code = it->second->data.CanUse(target_url); | 267 *problem_code = it->second->data.CanUse(target_url); |
266 if (*problem_code != SDCH_OK) | 268 if (*problem_code != SDCH_OK) |
267 return result.Pass(); | 269 return result; |
268 | 270 |
269 result.reset(new DictionarySet); | 271 result.reset(new DictionarySet); |
270 result->AddDictionary(it->first, it->second); | 272 result->AddDictionary(it->first, it->second); |
271 return result.Pass(); | 273 return result; |
272 } | 274 } |
273 | 275 |
274 // static | 276 // static |
275 void SdchManager::GenerateHash(const std::string& dictionary_text, | 277 void SdchManager::GenerateHash(const std::string& dictionary_text, |
276 std::string* client_hash, std::string* server_hash) { | 278 std::string* client_hash, std::string* server_hash) { |
277 char binary_hash[32]; | 279 char binary_hash[32]; |
278 crypto::SHA256HashString(dictionary_text, binary_hash, sizeof(binary_hash)); | 280 crypto::SHA256HashString(dictionary_text, binary_hash, sizeof(binary_hash)); |
279 | 281 |
280 base::StringPiece first_48_bits(&binary_hash[0], 6); | 282 base::StringPiece first_48_bits(&binary_hash[0], 6); |
281 base::StringPiece second_48_bits(&binary_hash[6], 6); | 283 base::StringPiece second_48_bits(&binary_hash[6], 6); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 dictionaries_.erase(server_hash); | 426 dictionaries_.erase(server_hash); |
425 | 427 |
426 FOR_EACH_OBSERVER(SdchObserver, observers_, OnDictionaryRemoved(server_hash)); | 428 FOR_EACH_OBSERVER(SdchObserver, observers_, OnDictionaryRemoved(server_hash)); |
427 | 429 |
428 return SDCH_OK; | 430 return SDCH_OK; |
429 } | 431 } |
430 | 432 |
431 // static | 433 // static |
432 scoped_ptr<SdchManager::DictionarySet> | 434 scoped_ptr<SdchManager::DictionarySet> |
433 SdchManager::CreateEmptyDictionarySetForTesting() { | 435 SdchManager::CreateEmptyDictionarySetForTesting() { |
434 return scoped_ptr<DictionarySet>(new DictionarySet).Pass(); | 436 return scoped_ptr<DictionarySet>(new DictionarySet); |
435 } | 437 } |
436 | 438 |
437 scoped_ptr<base::Value> SdchManager::SdchInfoToValue() const { | 439 scoped_ptr<base::Value> SdchManager::SdchInfoToValue() const { |
438 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); | 440 scoped_ptr<base::DictionaryValue> value(new base::DictionaryValue()); |
439 | 441 |
440 value->SetBoolean("sdch_enabled", true); | 442 value->SetBoolean("sdch_enabled", true); |
441 | 443 |
442 scoped_ptr<base::ListValue> entry_list(new base::ListValue()); | 444 scoped_ptr<base::ListValue> entry_list(new base::ListValue()); |
443 for (const auto& entry: dictionaries_) { | 445 for (const auto& entry: dictionaries_) { |
444 scoped_ptr<base::DictionaryValue> entry_dict(new base::DictionaryValue()); | 446 scoped_ptr<base::DictionaryValue> entry_dict(new base::DictionaryValue()); |
445 entry_dict->SetString("url", entry.second->data.url().spec()); | 447 entry_dict->SetString("url", entry.second->data.url().spec()); |
446 entry_dict->SetString("client_hash", entry.second->data.client_hash()); | 448 entry_dict->SetString("client_hash", entry.second->data.client_hash()); |
447 entry_dict->SetString("domain", entry.second->data.domain()); | 449 entry_dict->SetString("domain", entry.second->data.domain()); |
448 entry_dict->SetString("path", entry.second->data.path()); | 450 entry_dict->SetString("path", entry.second->data.path()); |
449 scoped_ptr<base::ListValue> port_list(new base::ListValue()); | 451 scoped_ptr<base::ListValue> port_list(new base::ListValue()); |
450 for (std::set<int>::const_iterator port_it = | 452 for (std::set<int>::const_iterator port_it = |
451 entry.second->data.ports().begin(); | 453 entry.second->data.ports().begin(); |
452 port_it != entry.second->data.ports().end(); ++port_it) { | 454 port_it != entry.second->data.ports().end(); ++port_it) { |
453 port_list->AppendInteger(*port_it); | 455 port_list->AppendInteger(*port_it); |
454 } | 456 } |
455 entry_dict->Set("ports", port_list.Pass()); | 457 entry_dict->Set("ports", std::move(port_list)); |
456 entry_dict->SetString("server_hash", entry.first); | 458 entry_dict->SetString("server_hash", entry.first); |
457 entry_list->Append(entry_dict.Pass()); | 459 entry_list->Append(std::move(entry_dict)); |
458 } | 460 } |
459 value->Set("dictionaries", entry_list.Pass()); | 461 value->Set("dictionaries", std::move(entry_list)); |
460 | 462 |
461 entry_list.reset(new base::ListValue()); | 463 entry_list.reset(new base::ListValue()); |
462 for (DomainBlacklistInfo::const_iterator it = blacklisted_domains_.begin(); | 464 for (DomainBlacklistInfo::const_iterator it = blacklisted_domains_.begin(); |
463 it != blacklisted_domains_.end(); ++it) { | 465 it != blacklisted_domains_.end(); ++it) { |
464 if (it->second.count == 0) | 466 if (it->second.count == 0) |
465 continue; | 467 continue; |
466 scoped_ptr<base::DictionaryValue> entry_dict(new base::DictionaryValue()); | 468 scoped_ptr<base::DictionaryValue> entry_dict(new base::DictionaryValue()); |
467 entry_dict->SetString("domain", it->first); | 469 entry_dict->SetString("domain", it->first); |
468 if (it->second.count != INT_MAX) | 470 if (it->second.count != INT_MAX) |
469 entry_dict->SetInteger("tries", it->second.count); | 471 entry_dict->SetInteger("tries", it->second.count); |
470 entry_dict->SetInteger("reason", it->second.reason); | 472 entry_dict->SetInteger("reason", it->second.reason); |
471 entry_list->Append(entry_dict.Pass()); | 473 entry_list->Append(std::move(entry_dict)); |
472 } | 474 } |
473 value->Set("blacklisted", entry_list.Pass()); | 475 value->Set("blacklisted", std::move(entry_list)); |
474 | 476 |
475 return value.Pass(); | 477 return std::move(value); |
476 } | 478 } |
477 | 479 |
478 } // namespace net | 480 } // namespace net |
OLD | NEW |