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