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 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 165 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
166 http_server_properties_impl_->MaybeForceHTTP11(server, ssl_config); | 166 http_server_properties_impl_->MaybeForceHTTP11(server, ssl_config); |
167 } | 167 } |
168 | 168 |
169 bool HttpServerPropertiesManager::HasAlternateProtocol( | 169 bool HttpServerPropertiesManager::HasAlternateProtocol( |
170 const HostPortPair& server) { | 170 const HostPortPair& server) { |
171 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 171 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
172 return http_server_properties_impl_->HasAlternateProtocol(server); | 172 return http_server_properties_impl_->HasAlternateProtocol(server); |
173 } | 173 } |
174 | 174 |
175 AlternateProtocolInfo HttpServerPropertiesManager::GetAlternateProtocol( | 175 const net::AlternateProtocols& |
176 const HostPortPair& server) { | 176 HttpServerPropertiesManager::GetAlternateProtocols( |
| 177 const net::HostPortPair& server) { |
177 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 178 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
178 return http_server_properties_impl_->GetAlternateProtocol(server); | 179 return http_server_properties_impl_->GetAlternateProtocols(server); |
179 } | 180 } |
180 | 181 |
181 void HttpServerPropertiesManager::SetAlternateProtocol( | 182 void HttpServerPropertiesManager::AddAlternateProtocol( |
182 const HostPortPair& server, | 183 const net::HostPortPair& server, |
183 uint16 alternate_port, | 184 uint16 alternate_port, |
184 AlternateProtocol alternate_protocol, | 185 AlternateProtocol alternate_protocol, |
185 double alternate_probability) { | 186 double alternate_probability) { |
186 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 187 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
187 http_server_properties_impl_->SetAlternateProtocol( | 188 http_server_properties_impl_->AddAlternateProtocol( |
188 server, alternate_port, alternate_protocol, alternate_probability); | 189 server, alternate_port, alternate_protocol, alternate_probability); |
189 ScheduleUpdatePrefsOnNetworkThread(); | 190 ScheduleUpdatePrefsOnNetworkThread(); |
190 } | 191 } |
191 | 192 |
192 void HttpServerPropertiesManager::SetBrokenAlternateProtocol( | 193 void HttpServerPropertiesManager::SetBrokenAlternateProtocol( |
193 const HostPortPair& server) { | 194 const HostPortPair& server, |
| 195 const AlternateProtocolInfo& broken_alternate_protocol) { |
194 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 196 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
195 http_server_properties_impl_->SetBrokenAlternateProtocol(server); | 197 http_server_properties_impl_->SetBrokenAlternateProtocol( |
| 198 server, broken_alternate_protocol); |
196 ScheduleUpdatePrefsOnNetworkThread(); | 199 ScheduleUpdatePrefsOnNetworkThread(); |
197 } | 200 } |
198 | 201 |
199 bool HttpServerPropertiesManager::WasAlternateProtocolRecentlyBroken( | 202 bool HttpServerPropertiesManager::WasAlternateProtocolRecentlyBroken( |
200 const HostPortPair& server) { | 203 const HostPortPair& server, |
| 204 const AlternateProtocolInfo& alternate_protocol) { |
201 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 205 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
202 return http_server_properties_impl_->WasAlternateProtocolRecentlyBroken( | 206 return http_server_properties_impl_->WasAlternateProtocolRecentlyBroken( |
203 server); | 207 server, alternate_protocol); |
204 } | 208 } |
205 | 209 |
206 void HttpServerPropertiesManager::ConfirmAlternateProtocol( | 210 void HttpServerPropertiesManager::ConfirmAlternateProtocol( |
207 const HostPortPair& server) { | 211 const HostPortPair& server, |
| 212 const AlternateProtocolInfo& alternate_protocol) { |
208 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 213 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
209 http_server_properties_impl_->ConfirmAlternateProtocol(server); | 214 http_server_properties_impl_->ConfirmAlternateProtocol(server, |
| 215 alternate_protocol); |
210 ScheduleUpdatePrefsOnNetworkThread(); | 216 ScheduleUpdatePrefsOnNetworkThread(); |
211 } | 217 } |
212 | 218 |
213 void HttpServerPropertiesManager::ClearAlternateProtocol( | 219 void HttpServerPropertiesManager::ClearAlternateProtocol( |
214 const HostPortPair& server) { | 220 const HostPortPair& server) { |
215 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 221 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
216 http_server_properties_impl_->ClearAlternateProtocol(server); | 222 http_server_properties_impl_->ClearAlternateProtocol(server); |
217 ScheduleUpdatePrefsOnNetworkThread(); | 223 ScheduleUpdatePrefsOnNetworkThread(); |
218 } | 224 } |
219 | 225 |
| 226 void HttpServerPropertiesManager::ClearNonBrokenAlternateProtocols( |
| 227 const net::HostPortPair& server) { |
| 228 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 229 http_server_properties_impl_->ClearNonBrokenAlternateProtocols(server); |
| 230 ScheduleUpdatePrefsOnNetworkThread(); |
| 231 } |
| 232 |
| 233 void HttpServerPropertiesManager::RemoveAlternateProtocol( |
| 234 const net::HostPortPair& server, |
| 235 const AlternateProtocolInfo& alternate_protocol) { |
| 236 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 237 http_server_properties_impl_->RemoveAlternateProtocol(server, |
| 238 alternate_protocol); |
| 239 ScheduleUpdatePrefsOnNetworkThread(); |
| 240 } |
| 241 |
220 const AlternateProtocolMap& | 242 const AlternateProtocolMap& |
221 HttpServerPropertiesManager::alternate_protocol_map() const { | 243 HttpServerPropertiesManager::alternate_protocol_map() const { |
222 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 244 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
223 return http_server_properties_impl_->alternate_protocol_map(); | 245 return http_server_properties_impl_->alternate_protocol_map(); |
224 } | 246 } |
225 | 247 |
226 void HttpServerPropertiesManager::SetAlternateProtocolProbabilityThreshold( | 248 void HttpServerPropertiesManager::SetAlternateProtocolProbabilityThreshold( |
227 double threshold) { | 249 double threshold) { |
228 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 250 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
229 http_server_properties_impl_->SetAlternateProtocolProbabilityThreshold( | 251 http_server_properties_impl_->SetAlternateProtocolProbabilityThreshold( |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 if (port_alternate_protocol_dict->HasKey("probability") && | 476 if (port_alternate_protocol_dict->HasKey("probability") && |
455 !port_alternate_protocol_dict->GetDoubleWithoutPathExpansion( | 477 !port_alternate_protocol_dict->GetDoubleWithoutPathExpansion( |
456 "probability", &probability)) { | 478 "probability", &probability)) { |
457 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; | 479 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; |
458 detected_corrupted_prefs = true; | 480 detected_corrupted_prefs = true; |
459 continue; | 481 continue; |
460 } | 482 } |
461 | 483 |
462 AlternateProtocolInfo port_alternate_protocol(static_cast<uint16>(port), | 484 AlternateProtocolInfo port_alternate_protocol(static_cast<uint16>(port), |
463 protocol, probability); | 485 protocol, probability); |
464 alternate_protocol_map->Put(server, port_alternate_protocol); | 486 alternate_protocol_map->Put( |
| 487 server, AlternateProtocols(/*size=*/1, port_alternate_protocol)); |
465 } | 488 } |
466 | 489 |
467 // Get SupportsQuic. | 490 // Get SupportsQuic. |
468 DCHECK(supports_quic_map->find(server) == supports_quic_map->end()); | 491 DCHECK(supports_quic_map->find(server) == supports_quic_map->end()); |
469 const base::DictionaryValue* supports_quic_dict = NULL; | 492 const base::DictionaryValue* supports_quic_dict = NULL; |
470 if (server_pref_dict->GetDictionaryWithoutPathExpansion( | 493 if (server_pref_dict->GetDictionaryWithoutPathExpansion( |
471 "supports_quic", &supports_quic_dict)) { | 494 "supports_quic", &supports_quic_dict)) { |
472 bool used_quic = 0; | 495 bool used_quic = 0; |
473 if (!supports_quic_dict->GetBooleanWithoutPathExpansion( | 496 if (!supports_quic_dict->GetBooleanWithoutPathExpansion( |
474 "used_quic", &used_quic)) { | 497 "used_quic", &used_quic)) { |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
645 pref_task_runner_->PostTask( | 668 pref_task_runner_->PostTask( |
646 FROM_HERE, | 669 FROM_HERE, |
647 base::Bind( | 670 base::Bind( |
648 &HttpServerPropertiesManager::UpdatePrefsOnPrefThread, pref_weak_ptr_, | 671 &HttpServerPropertiesManager::UpdatePrefsOnPrefThread, pref_weak_ptr_, |
649 base::Owned(spdy_server_list), base::Owned(spdy_settings_map), | 672 base::Owned(spdy_server_list), base::Owned(spdy_settings_map), |
650 base::Owned(alternate_protocol_map), base::Owned(supports_quic_map), | 673 base::Owned(alternate_protocol_map), base::Owned(supports_quic_map), |
651 base::Owned(server_network_stats_map), completion)); | 674 base::Owned(server_network_stats_map), completion)); |
652 } | 675 } |
653 | 676 |
654 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, | 677 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, |
655 // AlternateProtocolInfo and SupportsQuic preferences for a server. This is used | 678 // AlternateProtocols and SupportsQuic preferences for a server. This is used |
656 // only in UpdatePrefsOnPrefThread. | 679 // only in UpdatePrefsOnPrefThread. |
657 struct ServerPref { | 680 struct ServerPref { |
658 ServerPref() | 681 ServerPref() |
659 : supports_spdy(false), | 682 : supports_spdy(false), |
660 settings_map(NULL), | 683 settings_map(NULL), |
661 alternate_protocol(NULL), | 684 alternate_protocols(NULL), |
662 supports_quic(NULL), | 685 supports_quic(NULL), |
663 server_network_stats(NULL) {} | 686 server_network_stats(NULL) {} |
664 ServerPref(bool supports_spdy, | 687 ServerPref(bool supports_spdy, |
665 const SettingsMap* settings_map, | 688 const SettingsMap* settings_map, |
666 const AlternateProtocolInfo* alternate_protocol, | 689 const AlternateProtocols* alternate_protocols, |
667 const SupportsQuic* supports_quic, | 690 const SupportsQuic* supports_quic, |
668 const ServerNetworkStats* server_network_stats) | 691 const ServerNetworkStats* server_network_stats) |
669 : supports_spdy(supports_spdy), | 692 : supports_spdy(supports_spdy), |
670 settings_map(settings_map), | 693 settings_map(settings_map), |
671 alternate_protocol(alternate_protocol), | 694 alternate_protocols(alternate_protocols), |
672 supports_quic(supports_quic), | 695 supports_quic(supports_quic), |
673 server_network_stats(server_network_stats) {} | 696 server_network_stats(server_network_stats) {} |
674 bool supports_spdy; | 697 bool supports_spdy; |
675 const SettingsMap* settings_map; | 698 const SettingsMap* settings_map; |
676 const AlternateProtocolInfo* alternate_protocol; | 699 const AlternateProtocols* alternate_protocols; |
677 const SupportsQuic* supports_quic; | 700 const SupportsQuic* supports_quic; |
678 const ServerNetworkStats* server_network_stats; | 701 const ServerNetworkStats* server_network_stats; |
679 }; | 702 }; |
680 | 703 |
681 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( | 704 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( |
682 base::ListValue* spdy_server_list, | 705 base::ListValue* spdy_server_list, |
683 SpdySettingsMap* spdy_settings_map, | 706 SpdySettingsMap* spdy_settings_map, |
684 AlternateProtocolMap* alternate_protocol_map, | 707 AlternateProtocolMap* alternate_protocol_map, |
685 SupportsQuicMap* supports_quic_map, | 708 SupportsQuicMap* supports_quic_map, |
686 ServerNetworkStatsMap* server_network_stats_map, | 709 ServerNetworkStatsMap* server_network_stats_map, |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 } else { | 743 } else { |
721 it->second.settings_map = &map_it->second; | 744 it->second.settings_map = &map_it->second; |
722 } | 745 } |
723 } | 746 } |
724 | 747 |
725 // Add AlternateProtocol servers to server_pref_map. | 748 // Add AlternateProtocol servers to server_pref_map. |
726 for (AlternateProtocolMap::const_iterator map_it = | 749 for (AlternateProtocolMap::const_iterator map_it = |
727 alternate_protocol_map->begin(); | 750 alternate_protocol_map->begin(); |
728 map_it != alternate_protocol_map->end(); ++map_it) { | 751 map_it != alternate_protocol_map->end(); ++map_it) { |
729 const HostPortPair& server = map_it->first; | 752 const HostPortPair& server = map_it->first; |
730 const AlternateProtocolInfo& port_alternate_protocol = map_it->second; | 753 const AlternateProtocols alternate_protocols = map_it->second; |
731 if (!IsAlternateProtocolValid(port_alternate_protocol.protocol)) { | 754 AlternateProtocols::const_iterator alternate_protocol; |
732 continue; | 755 for (alternate_protocol = alternate_protocols.begin(); |
| 756 alternate_protocol != alternate_protocols.end(); |
| 757 ++alternate_protocol) { |
| 758 if (!net::IsAlternateProtocolValid(alternate_protocol->protocol)) { |
| 759 break; |
| 760 } |
| 761 } |
| 762 // Do not add AlternateProtocols unless all of them have a valid protocol. |
| 763 if (alternate_protocol != alternate_protocols.end()) { |
| 764 break; |
733 } | 765 } |
734 | 766 |
735 ServerPrefMap::iterator it = server_pref_map.find(server); | 767 ServerPrefMap::iterator it = server_pref_map.find(server); |
736 if (it == server_pref_map.end()) { | 768 if (it == server_pref_map.end()) { |
737 ServerPref server_pref(false, NULL, &map_it->second, NULL, NULL); | 769 ServerPref server_pref(false, NULL, &map_it->second, NULL, NULL); |
738 server_pref_map[server] = server_pref; | 770 server_pref_map[server] = server_pref; |
739 } else { | 771 } else { |
740 it->second.alternate_protocol = &map_it->second; | 772 it->second.alternate_protocols = &map_it->second; |
741 } | 773 } |
742 } | 774 } |
743 | 775 |
744 // Add SupportsQuic servers to server_pref_map. | 776 // Add SupportsQuic servers to server_pref_map. |
745 for (SupportsQuicMap::const_iterator map_it = supports_quic_map->begin(); | 777 for (SupportsQuicMap::const_iterator map_it = supports_quic_map->begin(); |
746 map_it != supports_quic_map->end(); ++map_it) { | 778 map_it != supports_quic_map->end(); ++map_it) { |
747 const HostPortPair& server = map_it->first; | 779 const HostPortPair& server = map_it->first; |
748 | 780 |
749 ServerPrefMap::iterator it = server_pref_map.find(server); | 781 ServerPrefMap::iterator it = server_pref_map.find(server); |
750 if (it == server_pref_map.end()) { | 782 if (it == server_pref_map.end()) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
792 it != server_pref.settings_map->end(); ++it) { | 824 it != server_pref.settings_map->end(); ++it) { |
793 SpdySettingsIds id = it->first; | 825 SpdySettingsIds id = it->first; |
794 uint32 value = it->second.second; | 826 uint32 value = it->second.second; |
795 std::string key = base::StringPrintf("%u", id); | 827 std::string key = base::StringPrintf("%u", id); |
796 spdy_settings_dict->SetInteger(key, value); | 828 spdy_settings_dict->SetInteger(key, value); |
797 } | 829 } |
798 server_pref_dict->SetWithoutPathExpansion("settings", spdy_settings_dict); | 830 server_pref_dict->SetWithoutPathExpansion("settings", spdy_settings_dict); |
799 } | 831 } |
800 | 832 |
801 // Save alternate_protocol. | 833 // Save alternate_protocol. |
802 const AlternateProtocolInfo* port_alternate_protocol = | 834 if (server_pref.alternate_protocols && |
803 server_pref.alternate_protocol; | 835 server_pref.alternate_protocols->size() >= 1) { |
804 if (port_alternate_protocol && !port_alternate_protocol->is_broken) { | |
805 base::DictionaryValue* port_alternate_protocol_dict = | 836 base::DictionaryValue* port_alternate_protocol_dict = |
806 new base::DictionaryValue; | 837 new base::DictionaryValue; |
| 838 const net::AlternateProtocolInfo& port_alternate_protocol = |
| 839 server_pref.alternate_protocols->at(0); |
807 port_alternate_protocol_dict->SetInteger("port", | 840 port_alternate_protocol_dict->SetInteger("port", |
808 port_alternate_protocol->port); | 841 port_alternate_protocol.port); |
809 const char* protocol_str = | 842 const char* protocol_str = |
810 AlternateProtocolToString(port_alternate_protocol->protocol); | 843 AlternateProtocolToString(port_alternate_protocol.protocol); |
811 port_alternate_protocol_dict->SetString("protocol_str", protocol_str); | 844 port_alternate_protocol_dict->SetString("protocol_str", protocol_str); |
812 port_alternate_protocol_dict->SetDouble( | 845 port_alternate_protocol_dict->SetDouble( |
813 "probability", port_alternate_protocol->probability); | 846 "probability", port_alternate_protocol.probability); |
814 server_pref_dict->SetWithoutPathExpansion( | 847 server_pref_dict->SetWithoutPathExpansion( |
815 "alternate_protocol", port_alternate_protocol_dict); | 848 "alternate_protocol", port_alternate_protocol_dict); |
816 } | 849 } |
817 | 850 |
818 // Save supports_quic. | 851 // Save supports_quic. |
819 if (server_pref.supports_quic) { | 852 if (server_pref.supports_quic) { |
820 base::DictionaryValue* supports_quic_dict = new base::DictionaryValue; | 853 base::DictionaryValue* supports_quic_dict = new base::DictionaryValue; |
821 const SupportsQuic* supports_quic = server_pref.supports_quic; | 854 const SupportsQuic* supports_quic = server_pref.supports_quic; |
822 supports_quic_dict->SetBoolean("used_quic", supports_quic->used_quic); | 855 supports_quic_dict->SetBoolean("used_quic", supports_quic->used_quic); |
823 supports_quic_dict->SetString("address", supports_quic->address); | 856 supports_quic_dict->SetString("address", supports_quic->address); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 completion.Run(); | 891 completion.Run(); |
859 } | 892 } |
860 | 893 |
861 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { | 894 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { |
862 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 895 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
863 if (!setting_prefs_) | 896 if (!setting_prefs_) |
864 ScheduleUpdateCacheOnPrefThread(); | 897 ScheduleUpdateCacheOnPrefThread(); |
865 } | 898 } |
866 | 899 |
867 } // namespace net | 900 } // namespace net |
OLD | NEW |