| 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 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 | 742 |
| 753 // Add AlternateProtocol servers to server_pref_map. | 743 // Add AlternateProtocol servers to server_pref_map. |
| 754 for (AlternateProtocolMap::const_iterator map_it = | 744 for (AlternateProtocolMap::const_iterator map_it = |
| 755 alternate_protocol_map->begin(); | 745 alternate_protocol_map->begin(); |
| 756 map_it != alternate_protocol_map->end(); ++map_it) { | 746 map_it != alternate_protocol_map->end(); ++map_it) { |
| 757 const HostPortPair& server = map_it->first; | 747 const HostPortPair& server = map_it->first; |
| 758 const AlternateProtocolInfo& port_alternate_protocol = map_it->second; | 748 const AlternateProtocolInfo& port_alternate_protocol = map_it->second; |
| 759 if (!IsAlternateProtocolValid(port_alternate_protocol.protocol)) { | 749 if (!IsAlternateProtocolValid(port_alternate_protocol.protocol)) { |
| 760 continue; | 750 continue; |
| 761 } | 751 } |
| 762 const AlternativeService alternative_service( | |
| 763 port_alternate_protocol.protocol, server.host(), | |
| 764 port_alternate_protocol.port); | |
| 765 if (IsAlternativeServiceBroken(alternative_service)) { | |
| 766 continue; | |
| 767 } | |
| 768 | |
| 769 server_pref_map[server].alternate_protocol = &map_it->second; | 752 server_pref_map[server].alternate_protocol = &map_it->second; |
| 770 } | 753 } |
| 771 | 754 |
| 772 // Add ServerNetworkStats servers to server_pref_map. | 755 // Add ServerNetworkStats servers to server_pref_map. |
| 773 for (ServerNetworkStatsMap::const_iterator map_it = | 756 for (ServerNetworkStatsMap::const_iterator map_it = |
| 774 server_network_stats_map->begin(); | 757 server_network_stats_map->begin(); |
| 775 map_it != server_network_stats_map->end(); ++map_it) { | 758 map_it != server_network_stats_map->end(); ++map_it) { |
| 776 const HostPortPair& server = map_it->first; | 759 const HostPortPair& server = map_it->first; |
| 777 server_pref_map[server].server_network_stats = &map_it->second; | 760 server_pref_map[server].server_network_stats = &map_it->second; |
| 778 } | 761 } |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 831 uint32 value = it->second.second; | 814 uint32 value = it->second.second; |
| 832 std::string key = base::StringPrintf("%u", id); | 815 std::string key = base::StringPrintf("%u", id); |
| 833 spdy_settings_dict->SetInteger(key, value); | 816 spdy_settings_dict->SetInteger(key, value); |
| 834 } | 817 } |
| 835 server_pref_dict->SetWithoutPathExpansion(kSettingsKey, spdy_settings_dict); | 818 server_pref_dict->SetWithoutPathExpansion(kSettingsKey, spdy_settings_dict); |
| 836 } | 819 } |
| 837 | 820 |
| 838 void HttpServerPropertiesManager::SaveAlternateProtocolToServerPrefs( | 821 void HttpServerPropertiesManager::SaveAlternateProtocolToServerPrefs( |
| 839 const AlternateProtocolInfo* port_alternate_protocol, | 822 const AlternateProtocolInfo* port_alternate_protocol, |
| 840 base::DictionaryValue* server_pref_dict) { | 823 base::DictionaryValue* server_pref_dict) { |
| 841 if (!port_alternate_protocol) | 824 if (!port_alternate_protocol || port_alternate_protocol->is_broken) |
| 842 return; | 825 return; |
| 843 | 826 |
| 844 base::DictionaryValue* port_alternate_protocol_dict = | 827 base::DictionaryValue* port_alternate_protocol_dict = |
| 845 new base::DictionaryValue; | 828 new base::DictionaryValue; |
| 846 port_alternate_protocol_dict->SetInteger(kPortKey, | 829 port_alternate_protocol_dict->SetInteger(kPortKey, |
| 847 port_alternate_protocol->port); | 830 port_alternate_protocol->port); |
| 848 const char* protocol_str = | 831 const char* protocol_str = |
| 849 AlternateProtocolToString(port_alternate_protocol->protocol); | 832 AlternateProtocolToString(port_alternate_protocol->protocol); |
| 850 port_alternate_protocol_dict->SetString(kProtocolKey, protocol_str); | 833 port_alternate_protocol_dict->SetString(kProtocolKey, protocol_str); |
| 851 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... |
| 884 server_network_stats_dict); | 867 server_network_stats_dict); |
| 885 } | 868 } |
| 886 | 869 |
| 887 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { | 870 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { |
| 888 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 871 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
| 889 if (!setting_prefs_) | 872 if (!setting_prefs_) |
| 890 ScheduleUpdateCacheOnPrefThread(); | 873 ScheduleUpdateCacheOnPrefThread(); |
| 891 } | 874 } |
| 892 | 875 |
| 893 } // namespace net | 876 } // namespace net |
| OLD | NEW |