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