| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/http/http_server_properties_manager.h" | 5 #include "net/http/http_server_properties_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 ScheduleUpdatePrefsOnNetworkThread(); | 197 ScheduleUpdatePrefsOnNetworkThread(); |
| 198 } | 198 } |
| 199 | 199 |
| 200 void HttpServerPropertiesManager::SetBrokenAlternateProtocol( | 200 void HttpServerPropertiesManager::SetBrokenAlternateProtocol( |
| 201 const HostPortPair& server) { | 201 const HostPortPair& server) { |
| 202 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 202 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 203 http_server_properties_impl_->SetBrokenAlternateProtocol(server); | 203 http_server_properties_impl_->SetBrokenAlternateProtocol(server); |
| 204 ScheduleUpdatePrefsOnNetworkThread(); | 204 ScheduleUpdatePrefsOnNetworkThread(); |
| 205 } | 205 } |
| 206 | 206 |
| 207 bool HttpServerPropertiesManager::IsAlternativeServiceBroken( |
| 208 const AlternativeService& alternative_service) { |
| 209 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 210 return http_server_properties_impl_->IsAlternativeServiceBroken( |
| 211 alternative_service); |
| 212 } |
| 213 |
| 207 bool HttpServerPropertiesManager::WasAlternateProtocolRecentlyBroken( | 214 bool HttpServerPropertiesManager::WasAlternateProtocolRecentlyBroken( |
| 208 const HostPortPair& server) { | 215 const HostPortPair& server) { |
| 209 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 216 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 210 return http_server_properties_impl_->WasAlternateProtocolRecentlyBroken( | 217 return http_server_properties_impl_->WasAlternateProtocolRecentlyBroken( |
| 211 server); | 218 server); |
| 212 } | 219 } |
| 213 | 220 |
| 214 void HttpServerPropertiesManager::ConfirmAlternateProtocol( | 221 void HttpServerPropertiesManager::ConfirmAlternateProtocol( |
| 215 const HostPortPair& server) { | 222 const HostPortPair& server) { |
| 216 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 223 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| (...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 spdy_settings_map->Put(server, settings_map); | 457 spdy_settings_map->Put(server, settings_map); |
| 451 } | 458 } |
| 452 | 459 |
| 453 AlternateProtocolInfo HttpServerPropertiesManager::ParseAlternateProtocolDict( | 460 AlternateProtocolInfo HttpServerPropertiesManager::ParseAlternateProtocolDict( |
| 454 const base::DictionaryValue& alternate_protocol_dict, | 461 const base::DictionaryValue& alternate_protocol_dict, |
| 455 const std::string& server_str) { | 462 const std::string& server_str) { |
| 456 AlternateProtocolInfo alternate_protocol; | 463 AlternateProtocolInfo alternate_protocol; |
| 457 int port = 0; | 464 int port = 0; |
| 458 if (!alternate_protocol_dict.GetInteger(kPortKey, &port) || | 465 if (!alternate_protocol_dict.GetInteger(kPortKey, &port) || |
| 459 !IsPortValid(port)) { | 466 !IsPortValid(port)) { |
| 460 DVLOG(1) << "Malformed AltSvc port for server: " << server_str; | 467 DVLOG(1) << "Malformed alternative service port for server: " << server_str; |
| 461 return alternate_protocol; | 468 return alternate_protocol; |
| 462 } | 469 } |
| 463 alternate_protocol.port = static_cast<uint16>(port); | 470 alternate_protocol.port = static_cast<uint16>(port); |
| 464 | 471 |
| 465 double probability = 1.0; | 472 double probability = 1.0; |
| 466 if (alternate_protocol_dict.HasKey(kProbabilityKey) && | 473 if (alternate_protocol_dict.HasKey(kProbabilityKey) && |
| 467 !alternate_protocol_dict.GetDoubleWithoutPathExpansion(kProbabilityKey, | 474 !alternate_protocol_dict.GetDoubleWithoutPathExpansion(kProbabilityKey, |
| 468 &probability)) { | 475 &probability)) { |
| 469 DVLOG(1) << "Malformed AltSvc probability for server: " << server_str; | 476 DVLOG(1) << "Malformed alternative service probability for server: " |
| 477 << server_str; |
| 470 return alternate_protocol; | 478 return alternate_protocol; |
| 471 } | 479 } |
| 472 alternate_protocol.probability = probability; | 480 alternate_protocol.probability = probability; |
| 473 | 481 |
| 474 std::string protocol_str; | 482 std::string protocol_str; |
| 475 if (!alternate_protocol_dict.GetStringWithoutPathExpansion(kProtocolKey, | 483 if (!alternate_protocol_dict.GetStringWithoutPathExpansion(kProtocolKey, |
| 476 &protocol_str)) { | 484 &protocol_str)) { |
| 477 DVLOG(1) << "Malformed AltSvc protocol string for server: " << server_str; | 485 DVLOG(1) << "Malformed alternative service protocol string for server: " |
| 486 << server_str; |
| 478 return alternate_protocol; | 487 return alternate_protocol; |
| 479 } | 488 } |
| 480 AlternateProtocol protocol = AlternateProtocolFromString(protocol_str); | 489 AlternateProtocol protocol = AlternateProtocolFromString(protocol_str); |
| 481 if (!IsAlternateProtocolValid(protocol)) { | 490 if (!IsAlternateProtocolValid(protocol)) { |
| 482 DVLOG(1) << "Invalid AltSvc protocol string for server: " << server_str; | 491 DVLOG(1) << "Invalid alternative service protocol string for server: " |
| 492 << server_str; |
| 483 return alternate_protocol; | 493 return alternate_protocol; |
| 484 } | 494 } |
| 485 alternate_protocol.protocol = protocol; | 495 alternate_protocol.protocol = protocol; |
| 486 | 496 |
| 487 return alternate_protocol; | 497 return alternate_protocol; |
| 488 } | 498 } |
| 489 | 499 |
| 490 bool HttpServerPropertiesManager::AddToAlternateProtocolMap( | 500 bool HttpServerPropertiesManager::AddToAlternateProtocolMap( |
| 491 const HostPortPair& server, | 501 const HostPortPair& server, |
| 492 const base::DictionaryValue& server_pref_dict, | 502 const base::DictionaryValue& server_pref_dict, |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 642 | 652 |
| 643 AlternateProtocolMap* alternate_protocol_map = | 653 AlternateProtocolMap* alternate_protocol_map = |
| 644 new AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist); | 654 new AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist); |
| 645 const AlternateProtocolMap& map = | 655 const AlternateProtocolMap& map = |
| 646 http_server_properties_impl_->alternate_protocol_map(); | 656 http_server_properties_impl_->alternate_protocol_map(); |
| 647 count = 0; | 657 count = 0; |
| 648 typedef std::map<std::string, bool> CanonicalHostPersistedMap; | 658 typedef std::map<std::string, bool> CanonicalHostPersistedMap; |
| 649 CanonicalHostPersistedMap persisted_map; | 659 CanonicalHostPersistedMap persisted_map; |
| 650 for (AlternateProtocolMap::const_iterator it = map.begin(); | 660 for (AlternateProtocolMap::const_iterator it = map.begin(); |
| 651 it != map.end() && count < kMaxAlternateProtocolHostsToPersist; ++it) { | 661 it != map.end() && count < kMaxAlternateProtocolHostsToPersist; ++it) { |
| 662 const AlternateProtocolInfo& alternate_protocol = it->second; |
| 663 if (!IsAlternateProtocolValid(alternate_protocol.protocol)) { |
| 664 continue; |
| 665 } |
| 652 const HostPortPair& server = it->first; | 666 const HostPortPair& server = it->first; |
| 667 if (IsAlternativeServiceBroken( |
| 668 AlternativeService(alternate_protocol.protocol, server.host(), |
| 669 alternate_protocol.port))) { |
| 670 continue; |
| 671 } |
| 653 std::string canonical_suffix = | 672 std::string canonical_suffix = |
| 654 http_server_properties_impl_->GetCanonicalSuffix(server.host()); | 673 http_server_properties_impl_->GetCanonicalSuffix(server.host()); |
| 655 if (!canonical_suffix.empty()) { | 674 if (!canonical_suffix.empty()) { |
| 656 if (persisted_map.find(canonical_suffix) != persisted_map.end()) | 675 if (persisted_map.find(canonical_suffix) != persisted_map.end()) |
| 657 continue; | 676 continue; |
| 658 persisted_map[canonical_suffix] = true; | 677 persisted_map[canonical_suffix] = true; |
| 659 } | 678 } |
| 660 alternate_protocol_map->Put(server, it->second); | 679 alternate_protocol_map->Put(server, alternate_protocol); |
| 661 ++count; | 680 ++count; |
| 662 } | 681 } |
| 663 | 682 |
| 664 ServerNetworkStatsMap* server_network_stats_map = | 683 ServerNetworkStatsMap* server_network_stats_map = |
| 665 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist); | 684 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist); |
| 666 const ServerNetworkStatsMap& main_server_network_stats_map = | 685 const ServerNetworkStatsMap& main_server_network_stats_map = |
| 667 http_server_properties_impl_->server_network_stats_map(); | 686 http_server_properties_impl_->server_network_stats_map(); |
| 668 for (ServerNetworkStatsMap::const_iterator it = | 687 for (ServerNetworkStatsMap::const_iterator it = |
| 669 main_server_network_stats_map.begin(); | 688 main_server_network_stats_map.begin(); |
| 670 it != main_server_network_stats_map.end(); ++it) { | 689 it != main_server_network_stats_map.end(); ++it) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 737 for (SpdySettingsMap::iterator map_it = spdy_settings_map->begin(); | 756 for (SpdySettingsMap::iterator map_it = spdy_settings_map->begin(); |
| 738 map_it != spdy_settings_map->end(); ++map_it) { | 757 map_it != spdy_settings_map->end(); ++map_it) { |
| 739 const HostPortPair& server = map_it->first; | 758 const HostPortPair& server = map_it->first; |
| 740 server_pref_map[server].settings_map = &map_it->second; | 759 server_pref_map[server].settings_map = &map_it->second; |
| 741 } | 760 } |
| 742 | 761 |
| 743 // Add AlternateProtocol servers to server_pref_map. | 762 // Add AlternateProtocol servers to server_pref_map. |
| 744 for (AlternateProtocolMap::const_iterator map_it = | 763 for (AlternateProtocolMap::const_iterator map_it = |
| 745 alternate_protocol_map->begin(); | 764 alternate_protocol_map->begin(); |
| 746 map_it != alternate_protocol_map->end(); ++map_it) { | 765 map_it != alternate_protocol_map->end(); ++map_it) { |
| 747 const HostPortPair& server = map_it->first; | 766 server_pref_map[map_it->first].alternate_protocol = &map_it->second; |
| 748 const AlternateProtocolInfo& port_alternate_protocol = map_it->second; | |
| 749 if (!IsAlternateProtocolValid(port_alternate_protocol.protocol)) { | |
| 750 continue; | |
| 751 } | |
| 752 server_pref_map[server].alternate_protocol = &map_it->second; | |
| 753 } | 767 } |
| 754 | 768 |
| 755 // Add ServerNetworkStats servers to server_pref_map. | 769 // Add ServerNetworkStats servers to server_pref_map. |
| 756 for (ServerNetworkStatsMap::const_iterator map_it = | 770 for (ServerNetworkStatsMap::const_iterator map_it = |
| 757 server_network_stats_map->begin(); | 771 server_network_stats_map->begin(); |
| 758 map_it != server_network_stats_map->end(); ++map_it) { | 772 map_it != server_network_stats_map->end(); ++map_it) { |
| 759 const HostPortPair& server = map_it->first; | 773 const HostPortPair& server = map_it->first; |
| 760 server_pref_map[server].server_network_stats = &map_it->second; | 774 server_pref_map[server].server_network_stats = &map_it->second; |
| 761 } | 775 } |
| 762 | 776 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 814 uint32 value = it->second.second; | 828 uint32 value = it->second.second; |
| 815 std::string key = base::StringPrintf("%u", id); | 829 std::string key = base::StringPrintf("%u", id); |
| 816 spdy_settings_dict->SetInteger(key, value); | 830 spdy_settings_dict->SetInteger(key, value); |
| 817 } | 831 } |
| 818 server_pref_dict->SetWithoutPathExpansion(kSettingsKey, spdy_settings_dict); | 832 server_pref_dict->SetWithoutPathExpansion(kSettingsKey, spdy_settings_dict); |
| 819 } | 833 } |
| 820 | 834 |
| 821 void HttpServerPropertiesManager::SaveAlternateProtocolToServerPrefs( | 835 void HttpServerPropertiesManager::SaveAlternateProtocolToServerPrefs( |
| 822 const AlternateProtocolInfo* port_alternate_protocol, | 836 const AlternateProtocolInfo* port_alternate_protocol, |
| 823 base::DictionaryValue* server_pref_dict) { | 837 base::DictionaryValue* server_pref_dict) { |
| 824 if (!port_alternate_protocol || port_alternate_protocol->is_broken) | 838 if (!port_alternate_protocol) |
| 825 return; | 839 return; |
| 826 | 840 |
| 827 base::DictionaryValue* port_alternate_protocol_dict = | 841 base::DictionaryValue* port_alternate_protocol_dict = |
| 828 new base::DictionaryValue; | 842 new base::DictionaryValue; |
| 829 port_alternate_protocol_dict->SetInteger(kPortKey, | 843 port_alternate_protocol_dict->SetInteger(kPortKey, |
| 830 port_alternate_protocol->port); | 844 port_alternate_protocol->port); |
| 831 const char* protocol_str = | 845 const char* protocol_str = |
| 832 AlternateProtocolToString(port_alternate_protocol->protocol); | 846 AlternateProtocolToString(port_alternate_protocol->protocol); |
| 833 port_alternate_protocol_dict->SetString(kProtocolKey, protocol_str); | 847 port_alternate_protocol_dict->SetString(kProtocolKey, protocol_str); |
| 834 port_alternate_protocol_dict->SetDouble(kProbabilityKey, | 848 port_alternate_protocol_dict->SetDouble(kProbabilityKey, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 867 server_network_stats_dict); | 881 server_network_stats_dict); |
| 868 } | 882 } |
| 869 | 883 |
| 870 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { | 884 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { |
| 871 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 885 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
| 872 if (!setting_prefs_) | 886 if (!setting_prefs_) |
| 873 ScheduleUpdateCacheOnPrefThread(); | 887 ScheduleUpdateCacheOnPrefThread(); |
| 874 } | 888 } |
| 875 | 889 |
| 876 } // namespace net | 890 } // namespace net |
| OLD | NEW |