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