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 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 http_server_properties_impl_->SetSupportsSpdy(server, support_spdy); | 150 http_server_properties_impl_->SetSupportsSpdy(server, support_spdy); |
151 ScheduleUpdatePrefsOnNetworkThread(); | 151 ScheduleUpdatePrefsOnNetworkThread(); |
152 } | 152 } |
153 | 153 |
154 bool HttpServerPropertiesManager::HasAlternateProtocol( | 154 bool HttpServerPropertiesManager::HasAlternateProtocol( |
155 const net::HostPortPair& server) { | 155 const net::HostPortPair& server) { |
156 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 156 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
157 return http_server_properties_impl_->HasAlternateProtocol(server); | 157 return http_server_properties_impl_->HasAlternateProtocol(server); |
158 } | 158 } |
159 | 159 |
160 net::AlternateProtocolInfo | 160 const net::AlternateProtocols& |
161 HttpServerPropertiesManager::GetAlternateProtocol( | 161 HttpServerPropertiesManager::GetAlternateProtocols( |
162 const net::HostPortPair& server) { | 162 const net::HostPortPair& server) { |
163 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 163 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
164 return http_server_properties_impl_->GetAlternateProtocol(server); | 164 return http_server_properties_impl_->GetAlternateProtocols(server); |
165 } | 165 } |
166 | 166 |
167 void HttpServerPropertiesManager::SetAlternateProtocol( | 167 void HttpServerPropertiesManager::AddAlternateProtocol( |
168 const net::HostPortPair& server, | 168 const net::HostPortPair& server, |
169 uint16 alternate_port, | 169 uint16 alternate_port, |
170 AlternateProtocol alternate_protocol, | 170 AlternateProtocol alternate_protocol, |
171 double alternate_probability) { | 171 double alternate_probability) { |
172 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 172 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
173 http_server_properties_impl_->SetAlternateProtocol( | 173 http_server_properties_impl_->AddAlternateProtocol( |
174 server, alternate_port, alternate_protocol, alternate_probability); | 174 server, alternate_port, alternate_protocol, alternate_probability); |
175 ScheduleUpdatePrefsOnNetworkThread(); | 175 ScheduleUpdatePrefsOnNetworkThread(); |
176 } | 176 } |
177 | 177 |
178 void HttpServerPropertiesManager::SetBrokenAlternateProtocol( | 178 void HttpServerPropertiesManager::SetBrokenAlternateProtocol( |
179 const net::HostPortPair& server) { | 179 const net::HostPortPair& server, |
| 180 const AlternateProtocolInfo& broken_alternate_protocol) { |
180 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 181 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
181 http_server_properties_impl_->SetBrokenAlternateProtocol(server); | 182 http_server_properties_impl_->SetBrokenAlternateProtocol( |
| 183 server, broken_alternate_protocol); |
182 ScheduleUpdatePrefsOnNetworkThread(); | 184 ScheduleUpdatePrefsOnNetworkThread(); |
183 } | 185 } |
184 | 186 |
185 bool HttpServerPropertiesManager::WasAlternateProtocolRecentlyBroken( | 187 bool HttpServerPropertiesManager::WasAlternateProtocolRecentlyBroken( |
186 const net::HostPortPair& server) { | 188 const HostPortPair& server, |
| 189 const AlternateProtocolInfo& alternate_protocol) { |
187 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 190 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
188 return http_server_properties_impl_->WasAlternateProtocolRecentlyBroken( | 191 return http_server_properties_impl_->WasAlternateProtocolRecentlyBroken( |
189 server); | 192 server, alternate_protocol); |
190 } | 193 } |
191 | 194 |
192 void HttpServerPropertiesManager::ConfirmAlternateProtocol( | 195 void HttpServerPropertiesManager::ConfirmAlternateProtocol( |
193 const net::HostPortPair& server) { | 196 const HostPortPair& server, |
| 197 const AlternateProtocolInfo& alternate_protocol) { |
194 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 198 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
195 http_server_properties_impl_->ConfirmAlternateProtocol(server); | 199 http_server_properties_impl_->ConfirmAlternateProtocol(server, |
| 200 alternate_protocol); |
196 ScheduleUpdatePrefsOnNetworkThread(); | 201 ScheduleUpdatePrefsOnNetworkThread(); |
197 } | 202 } |
198 | 203 |
199 void HttpServerPropertiesManager::ClearAlternateProtocol( | 204 void HttpServerPropertiesManager::ClearAlternateProtocol( |
200 const net::HostPortPair& server) { | 205 const net::HostPortPair& server) { |
201 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 206 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
202 http_server_properties_impl_->ClearAlternateProtocol(server); | 207 http_server_properties_impl_->ClearAlternateProtocol(server); |
203 ScheduleUpdatePrefsOnNetworkThread(); | 208 ScheduleUpdatePrefsOnNetworkThread(); |
204 } | 209 } |
205 | 210 |
| 211 void HttpServerPropertiesManager::RemoveAlternateProtocol( |
| 212 const net::HostPortPair& server, |
| 213 const AlternateProtocolInfo& alternate_protocol) { |
| 214 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 215 http_server_properties_impl_->RemoveAlternateProtocol(server, |
| 216 alternate_protocol); |
| 217 ScheduleUpdatePrefsOnNetworkThread(); |
| 218 } |
| 219 |
206 const net::AlternateProtocolMap& | 220 const net::AlternateProtocolMap& |
207 HttpServerPropertiesManager::alternate_protocol_map() const { | 221 HttpServerPropertiesManager::alternate_protocol_map() const { |
208 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 222 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
209 return http_server_properties_impl_->alternate_protocol_map(); | 223 return http_server_properties_impl_->alternate_protocol_map(); |
210 } | 224 } |
211 | 225 |
212 void HttpServerPropertiesManager::SetAlternateProtocolProbabilityThreshold( | 226 void HttpServerPropertiesManager::SetAlternateProtocolProbabilityThreshold( |
213 double threshold) { | 227 double threshold) { |
214 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 228 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
215 http_server_properties_impl_->SetAlternateProtocolProbabilityThreshold( | 229 http_server_properties_impl_->SetAlternateProtocolProbabilityThreshold( |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
444 !port_alternate_protocol_dict->GetDoubleWithoutPathExpansion( | 458 !port_alternate_protocol_dict->GetDoubleWithoutPathExpansion( |
445 "probability", &probability)) { | 459 "probability", &probability)) { |
446 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; | 460 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; |
447 detected_corrupted_prefs = true; | 461 detected_corrupted_prefs = true; |
448 continue; | 462 continue; |
449 } | 463 } |
450 | 464 |
451 net::AlternateProtocolInfo port_alternate_protocol(port, | 465 net::AlternateProtocolInfo port_alternate_protocol(port, |
452 protocol, | 466 protocol, |
453 probability); | 467 probability); |
454 alternate_protocol_map->Put(server, port_alternate_protocol); | 468 alternate_protocol_map->Put( |
| 469 server, AlternateProtocols(/*size=*/1, port_alternate_protocol)); |
455 ++count; | 470 ++count; |
456 } while (false); | 471 } while (false); |
457 | 472 |
458 // Get SupportsQuic. | 473 // Get SupportsQuic. |
459 DCHECK(supports_quic_map->find(server) == supports_quic_map->end()); | 474 DCHECK(supports_quic_map->find(server) == supports_quic_map->end()); |
460 const base::DictionaryValue* supports_quic_dict = NULL; | 475 const base::DictionaryValue* supports_quic_dict = NULL; |
461 if (!server_pref_dict->GetDictionaryWithoutPathExpansion( | 476 if (!server_pref_dict->GetDictionaryWithoutPathExpansion( |
462 "supports_quic", &supports_quic_dict)) { | 477 "supports_quic", &supports_quic_dict)) { |
463 continue; | 478 continue; |
464 } | 479 } |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 base::Bind(&HttpServerPropertiesManager::UpdatePrefsOnPrefThread, | 623 base::Bind(&HttpServerPropertiesManager::UpdatePrefsOnPrefThread, |
609 pref_weak_ptr_, | 624 pref_weak_ptr_, |
610 base::Owned(spdy_server_list), | 625 base::Owned(spdy_server_list), |
611 base::Owned(spdy_settings_map), | 626 base::Owned(spdy_settings_map), |
612 base::Owned(alternate_protocol_map), | 627 base::Owned(alternate_protocol_map), |
613 base::Owned(supports_quic_map), | 628 base::Owned(supports_quic_map), |
614 completion)); | 629 completion)); |
615 } | 630 } |
616 | 631 |
617 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, | 632 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, |
618 // AlternateProtocolInfo and SupportsQuic preferences for a server. This is used | 633 // AlternateProtocols and SupportsQuic preferences for a server. This is used |
619 // only in UpdatePrefsOnPrefThread. | 634 // only in UpdatePrefsOnPrefThread. |
620 struct ServerPref { | 635 struct ServerPref { |
621 ServerPref() : supports_spdy(false), | 636 ServerPref() : supports_spdy(false), |
622 settings_map(NULL), | 637 settings_map(NULL), |
623 alternate_protocol(NULL), | 638 alternate_protocols(NULL), |
624 supports_quic(NULL) {} | 639 supports_quic(NULL) {} |
625 ServerPref(bool supports_spdy, | 640 ServerPref(bool supports_spdy, |
626 const net::SettingsMap* settings_map, | 641 const net::SettingsMap* settings_map, |
627 const net::AlternateProtocolInfo* alternate_protocol, | 642 const net::AlternateProtocols* alternate_protocols, |
628 const net::SupportsQuic* supports_quic) | 643 const net::SupportsQuic* supports_quic) |
629 : supports_spdy(supports_spdy), | 644 : supports_spdy(supports_spdy), |
630 settings_map(settings_map), | 645 settings_map(settings_map), |
631 alternate_protocol(alternate_protocol), | 646 alternate_protocols(alternate_protocols), |
632 supports_quic(supports_quic) {} | 647 supports_quic(supports_quic) {} |
633 bool supports_spdy; | 648 bool supports_spdy; |
634 const net::SettingsMap* settings_map; | 649 const net::SettingsMap* settings_map; |
635 const net::AlternateProtocolInfo* alternate_protocol; | 650 const net::AlternateProtocols* alternate_protocols; |
636 const net::SupportsQuic* supports_quic; | 651 const net::SupportsQuic* supports_quic; |
637 }; | 652 }; |
638 | 653 |
639 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( | 654 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( |
640 base::ListValue* spdy_server_list, | 655 base::ListValue* spdy_server_list, |
641 net::SpdySettingsMap* spdy_settings_map, | 656 net::SpdySettingsMap* spdy_settings_map, |
642 net::AlternateProtocolMap* alternate_protocol_map, | 657 net::AlternateProtocolMap* alternate_protocol_map, |
643 net::SupportsQuicMap* supports_quic_map, | 658 net::SupportsQuicMap* supports_quic_map, |
644 const base::Closure& completion) { | 659 const base::Closure& completion) { |
645 typedef std::map<net::HostPortPair, ServerPref> ServerPrefMap; | 660 typedef std::map<net::HostPortPair, ServerPref> ServerPrefMap; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 it->second.settings_map = &map_it->second; | 694 it->second.settings_map = &map_it->second; |
680 } | 695 } |
681 } | 696 } |
682 | 697 |
683 // Add AlternateProtocol servers to server_pref_map. | 698 // Add AlternateProtocol servers to server_pref_map. |
684 for (net::AlternateProtocolMap::const_iterator map_it = | 699 for (net::AlternateProtocolMap::const_iterator map_it = |
685 alternate_protocol_map->begin(); | 700 alternate_protocol_map->begin(); |
686 map_it != alternate_protocol_map->end(); | 701 map_it != alternate_protocol_map->end(); |
687 ++map_it) { | 702 ++map_it) { |
688 const net::HostPortPair& server = map_it->first; | 703 const net::HostPortPair& server = map_it->first; |
689 const net::AlternateProtocolInfo& port_alternate_protocol = | 704 const net::AlternateProtocols alternate_protocols = map_it->second; |
690 map_it->second; | 705 AlternateProtocols::const_iterator alternate_protocol; |
691 if (!net::IsAlternateProtocolValid(port_alternate_protocol.protocol)) { | 706 for (alternate_protocol = alternate_protocols.begin(); |
692 continue; | 707 alternate_protocol != alternate_protocols.end(); |
| 708 ++alternate_protocol) { |
| 709 if (!net::IsAlternateProtocolValid(alternate_protocol->protocol)) { |
| 710 break; |
| 711 } |
| 712 } |
| 713 // Do not add AlternateProtocols unless all of them have a valid protocol. |
| 714 if (alternate_protocol != alternate_protocols.end()) { |
| 715 break; |
693 } | 716 } |
694 | 717 |
695 ServerPrefMap::iterator it = server_pref_map.find(server); | 718 ServerPrefMap::iterator it = server_pref_map.find(server); |
696 if (it == server_pref_map.end()) { | 719 if (it == server_pref_map.end()) { |
697 ServerPref server_pref(false, NULL, &map_it->second, NULL); | 720 ServerPref server_pref(false, NULL, &map_it->second, NULL); |
698 server_pref_map[server] = server_pref; | 721 server_pref_map[server] = server_pref; |
699 } else { | 722 } else { |
700 it->second.alternate_protocol = &map_it->second; | 723 it->second.alternate_protocols = &map_it->second; |
701 } | 724 } |
702 } | 725 } |
703 | 726 |
704 // Add SupportsQuic servers to server_pref_map. | 727 // Add SupportsQuic servers to server_pref_map. |
705 for (net::SupportsQuicMap::const_iterator map_it = supports_quic_map->begin(); | 728 for (net::SupportsQuicMap::const_iterator map_it = supports_quic_map->begin(); |
706 map_it != supports_quic_map->end(); ++map_it) { | 729 map_it != supports_quic_map->end(); ++map_it) { |
707 const net::HostPortPair& server = map_it->first; | 730 const net::HostPortPair& server = map_it->first; |
708 | 731 |
709 ServerPrefMap::iterator it = server_pref_map.find(server); | 732 ServerPrefMap::iterator it = server_pref_map.find(server); |
710 if (it == server_pref_map.end()) { | 733 if (it == server_pref_map.end()) { |
(...skipping 28 matching lines...) Expand all Loading... |
739 ++it) { | 762 ++it) { |
740 net::SpdySettingsIds id = it->first; | 763 net::SpdySettingsIds id = it->first; |
741 uint32 value = it->second.second; | 764 uint32 value = it->second.second; |
742 std::string key = base::StringPrintf("%u", id); | 765 std::string key = base::StringPrintf("%u", id); |
743 spdy_settings_dict->SetInteger(key, value); | 766 spdy_settings_dict->SetInteger(key, value); |
744 } | 767 } |
745 server_pref_dict->SetWithoutPathExpansion("settings", spdy_settings_dict); | 768 server_pref_dict->SetWithoutPathExpansion("settings", spdy_settings_dict); |
746 } | 769 } |
747 | 770 |
748 // Save alternate_protocol. | 771 // Save alternate_protocol. |
749 if (server_pref.alternate_protocol) { | 772 if (server_pref.alternate_protocols && |
| 773 server_pref.alternate_protocols->size() >= 1) { |
750 base::DictionaryValue* port_alternate_protocol_dict = | 774 base::DictionaryValue* port_alternate_protocol_dict = |
751 new base::DictionaryValue; | 775 new base::DictionaryValue; |
752 const net::AlternateProtocolInfo* port_alternate_protocol = | 776 const net::AlternateProtocolInfo& port_alternate_protocol = |
753 server_pref.alternate_protocol; | 777 server_pref.alternate_protocols->at(0); |
754 port_alternate_protocol_dict->SetInteger("port", | 778 port_alternate_protocol_dict->SetInteger("port", |
755 port_alternate_protocol->port); | 779 port_alternate_protocol.port); |
756 const char* protocol_str = | 780 const char* protocol_str = |
757 net::AlternateProtocolToString(port_alternate_protocol->protocol); | 781 net::AlternateProtocolToString(port_alternate_protocol.protocol); |
758 port_alternate_protocol_dict->SetString("protocol_str", protocol_str); | 782 port_alternate_protocol_dict->SetString("protocol_str", protocol_str); |
759 port_alternate_protocol_dict->SetDouble( | 783 port_alternate_protocol_dict->SetDouble( |
760 "probability", port_alternate_protocol->probability); | 784 "probability", port_alternate_protocol.probability); |
761 server_pref_dict->SetWithoutPathExpansion( | 785 server_pref_dict->SetWithoutPathExpansion( |
762 "alternate_protocol", port_alternate_protocol_dict); | 786 "alternate_protocol", port_alternate_protocol_dict); |
763 } | 787 } |
764 | 788 |
765 // Save supports_quic. | 789 // Save supports_quic. |
766 if (server_pref.supports_quic) { | 790 if (server_pref.supports_quic) { |
767 base::DictionaryValue* supports_quic_dict = new base::DictionaryValue; | 791 base::DictionaryValue* supports_quic_dict = new base::DictionaryValue; |
768 const net::SupportsQuic* supports_quic = server_pref.supports_quic; | 792 const net::SupportsQuic* supports_quic = server_pref.supports_quic; |
769 supports_quic_dict->SetBoolean("used_quic", supports_quic->used_quic); | 793 supports_quic_dict->SetBoolean("used_quic", supports_quic->used_quic); |
770 supports_quic_dict->SetString("address", supports_quic->address); | 794 supports_quic_dict->SetString("address", supports_quic->address); |
(...skipping 18 matching lines...) Expand all Loading... |
789 completion.Run(); | 813 completion.Run(); |
790 } | 814 } |
791 | 815 |
792 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { | 816 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { |
793 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 817 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
794 if (!setting_prefs_) | 818 if (!setting_prefs_) |
795 ScheduleUpdateCacheOnPrefThread(); | 819 ScheduleUpdateCacheOnPrefThread(); |
796 } | 820 } |
797 | 821 |
798 } // namespace net | 822 } // namespace net |
OLD | NEW |