| 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_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 IPAddress old_last_quic_addr; | 338 IPAddress old_last_quic_addr; |
| 339 http_server_properties_impl_->GetSupportsQuic(&old_last_quic_addr); | 339 http_server_properties_impl_->GetSupportsQuic(&old_last_quic_addr); |
| 340 http_server_properties_impl_->SetSupportsQuic(used_quic, address); | 340 http_server_properties_impl_->SetSupportsQuic(used_quic, address); |
| 341 IPAddress new_last_quic_addr; | 341 IPAddress new_last_quic_addr; |
| 342 http_server_properties_impl_->GetSupportsQuic(&new_last_quic_addr); | 342 http_server_properties_impl_->GetSupportsQuic(&new_last_quic_addr); |
| 343 if (old_last_quic_addr != new_last_quic_addr) | 343 if (old_last_quic_addr != new_last_quic_addr) |
| 344 ScheduleUpdatePrefsOnNetworkThread(SET_SUPPORTS_QUIC); | 344 ScheduleUpdatePrefsOnNetworkThread(SET_SUPPORTS_QUIC); |
| 345 } | 345 } |
| 346 | 346 |
| 347 void HttpServerPropertiesManager::SetServerNetworkStats( | 347 void HttpServerPropertiesManager::SetServerNetworkStats( |
| 348 const HostPortPair& host_port_pair, | 348 const url::SchemeHostPort& server, |
| 349 ServerNetworkStats stats) { | 349 ServerNetworkStats stats) { |
| 350 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 350 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 351 ServerNetworkStats old_stats; | 351 ServerNetworkStats old_stats; |
| 352 const ServerNetworkStats* old_stats_ptr = | 352 const ServerNetworkStats* old_stats_ptr = |
| 353 http_server_properties_impl_->GetServerNetworkStats(host_port_pair); | 353 http_server_properties_impl_->GetServerNetworkStats(server); |
| 354 if (http_server_properties_impl_->GetServerNetworkStats(host_port_pair)) | 354 if (http_server_properties_impl_->GetServerNetworkStats(server)) |
| 355 old_stats = *old_stats_ptr; | 355 old_stats = *old_stats_ptr; |
| 356 http_server_properties_impl_->SetServerNetworkStats(host_port_pair, stats); | 356 http_server_properties_impl_->SetServerNetworkStats(server, stats); |
| 357 ServerNetworkStats new_stats = | 357 ServerNetworkStats new_stats = |
| 358 *(http_server_properties_impl_->GetServerNetworkStats(host_port_pair)); | 358 *(http_server_properties_impl_->GetServerNetworkStats(server)); |
| 359 if (old_stats != new_stats) | 359 if (old_stats != new_stats) |
| 360 ScheduleUpdatePrefsOnNetworkThread(SET_SERVER_NETWORK_STATS); | 360 ScheduleUpdatePrefsOnNetworkThread(SET_SERVER_NETWORK_STATS); |
| 361 } | 361 } |
| 362 | 362 |
| 363 const ServerNetworkStats* HttpServerPropertiesManager::GetServerNetworkStats( | 363 const ServerNetworkStats* HttpServerPropertiesManager::GetServerNetworkStats( |
| 364 const HostPortPair& host_port_pair) { | 364 const url::SchemeHostPort& server) { |
| 365 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 365 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 366 return http_server_properties_impl_->GetServerNetworkStats(host_port_pair); | 366 return http_server_properties_impl_->GetServerNetworkStats(server); |
| 367 } | 367 } |
| 368 | 368 |
| 369 const ServerNetworkStatsMap& | 369 const ServerNetworkStatsMap& |
| 370 HttpServerPropertiesManager::server_network_stats_map() const { | 370 HttpServerPropertiesManager::server_network_stats_map() const { |
| 371 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 371 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 372 return http_server_properties_impl_->server_network_stats_map(); | 372 return http_server_properties_impl_->server_network_stats_map(); |
| 373 } | 373 } |
| 374 | 374 |
| 375 bool HttpServerPropertiesManager::SetQuicServerInfo( | 375 bool HttpServerPropertiesManager::SetQuicServerInfo( |
| 376 const QuicServerId& server_id, | 376 const QuicServerId& server_id, |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 // Get if server supports Spdy. | 571 // Get if server supports Spdy. |
| 572 bool supports_spdy = false; | 572 bool supports_spdy = false; |
| 573 if ((server_pref_dict->GetBoolean(kSupportsSpdyKey, &supports_spdy)) && | 573 if ((server_pref_dict->GetBoolean(kSupportsSpdyKey, &supports_spdy)) && |
| 574 supports_spdy) { | 574 supports_spdy) { |
| 575 spdy_servers->push_back(spdy_server.Serialize()); | 575 spdy_servers->push_back(spdy_server.Serialize()); |
| 576 } | 576 } |
| 577 | 577 |
| 578 AddToSpdySettingsMap(spdy_server, *server_pref_dict, spdy_settings_map); | 578 AddToSpdySettingsMap(spdy_server, *server_pref_dict, spdy_settings_map); |
| 579 if (!AddToAlternativeServiceMap(server, *server_pref_dict, | 579 if (!AddToAlternativeServiceMap(server, *server_pref_dict, |
| 580 alternative_service_map) || | 580 alternative_service_map) || |
| 581 !AddToNetworkStatsMap(server, *server_pref_dict, network_stats_map)) { | 581 !AddToNetworkStatsMap(spdy_server, *server_pref_dict, |
| 582 network_stats_map)) { |
| 582 return false; | 583 return false; |
| 583 } | 584 } |
| 584 } | 585 } |
| 585 return true; | 586 return true; |
| 586 } | 587 } |
| 587 | 588 |
| 588 void HttpServerPropertiesManager::AddToSpdySettingsMap( | 589 void HttpServerPropertiesManager::AddToSpdySettingsMap( |
| 589 const url::SchemeHostPort& server, | 590 const url::SchemeHostPort& server, |
| 590 const base::DictionaryValue& server_pref_dict, | 591 const base::DictionaryValue& server_pref_dict, |
| 591 SpdySettingsMap* spdy_settings_map) { | 592 SpdySettingsMap* spdy_settings_map) { |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 746 if (!supports_quic_dict->GetStringWithoutPathExpansion(kAddressKey, | 747 if (!supports_quic_dict->GetStringWithoutPathExpansion(kAddressKey, |
| 747 &address) || | 748 &address) || |
| 748 !last_quic_address->AssignFromIPLiteral(address)) { | 749 !last_quic_address->AssignFromIPLiteral(address)) { |
| 749 DVLOG(1) << "Malformed SupportsQuic"; | 750 DVLOG(1) << "Malformed SupportsQuic"; |
| 750 return false; | 751 return false; |
| 751 } | 752 } |
| 752 return true; | 753 return true; |
| 753 } | 754 } |
| 754 | 755 |
| 755 bool HttpServerPropertiesManager::AddToNetworkStatsMap( | 756 bool HttpServerPropertiesManager::AddToNetworkStatsMap( |
| 756 const HostPortPair& server, | 757 const url::SchemeHostPort& server, |
| 757 const base::DictionaryValue& server_pref_dict, | 758 const base::DictionaryValue& server_pref_dict, |
| 758 ServerNetworkStatsMap* network_stats_map) { | 759 ServerNetworkStatsMap* network_stats_map) { |
| 759 DCHECK(network_stats_map->Peek(server) == network_stats_map->end()); | 760 DCHECK(network_stats_map->Peek(server) == network_stats_map->end()); |
| 760 const base::DictionaryValue* server_network_stats_dict = nullptr; | 761 const base::DictionaryValue* server_network_stats_dict = nullptr; |
| 761 if (!server_pref_dict.GetDictionaryWithoutPathExpansion( | 762 if (!server_pref_dict.GetDictionaryWithoutPathExpansion( |
| 762 kNetworkStatsKey, &server_network_stats_dict)) { | 763 kNetworkStatsKey, &server_network_stats_dict)) { |
| 763 return true; | 764 return true; |
| 764 } | 765 } |
| 765 int srtt; | 766 int srtt; |
| 766 if (!server_network_stats_dict->GetIntegerWithoutPathExpansion(kSrttKey, | 767 if (!server_network_stats_dict->GetIntegerWithoutPathExpansion(kSrttKey, |
| 767 &srtt)) { | 768 &srtt)) { |
| 768 DVLOG(1) << "Malformed ServerNetworkStats for server: " | 769 DVLOG(1) << "Malformed ServerNetworkStats for server: " |
| 769 << server.ToString(); | 770 << server.Serialize(); |
| 770 return false; | 771 return false; |
| 771 } | 772 } |
| 772 ServerNetworkStats server_network_stats; | 773 ServerNetworkStats server_network_stats; |
| 773 server_network_stats.srtt = base::TimeDelta::FromInternalValue(srtt); | 774 server_network_stats.srtt = base::TimeDelta::FromInternalValue(srtt); |
| 774 // TODO(rtenneti): When QUIC starts using bandwidth_estimate, then persist | 775 // TODO(rtenneti): When QUIC starts using bandwidth_estimate, then persist |
| 775 // bandwidth_estimate. | 776 // bandwidth_estimate. |
| 776 network_stats_map->Put(server, server_network_stats); | 777 network_stats_map->Put(server, server_network_stats); |
| 777 return true; | 778 return true; |
| 778 } | 779 } |
| 779 | 780 |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1085 server_pref_map.Put(server, server_pref); | 1086 server_pref_map.Put(server, server_pref); |
| 1086 } else { | 1087 } else { |
| 1087 it->second.alternative_service_info_vector = &map_it->second; | 1088 it->second.alternative_service_info_vector = &map_it->second; |
| 1088 } | 1089 } |
| 1089 } | 1090 } |
| 1090 | 1091 |
| 1091 // Add ServerNetworkStats servers to server_pref_map in the MRU order. | 1092 // Add ServerNetworkStats servers to server_pref_map in the MRU order. |
| 1092 for (ServerNetworkStatsMap::const_reverse_iterator map_it = | 1093 for (ServerNetworkStatsMap::const_reverse_iterator map_it = |
| 1093 server_network_stats_map->rbegin(); | 1094 server_network_stats_map->rbegin(); |
| 1094 map_it != server_network_stats_map->rend(); ++map_it) { | 1095 map_it != server_network_stats_map->rend(); ++map_it) { |
| 1095 const HostPortPair& server = map_it->first; | 1096 // TODO(zhongyi): use memory data once disk data is migrated. |
| 1097 const url::SchemeHostPort spdy_server = map_it->first; |
| 1098 const HostPortPair server(spdy_server.host(), spdy_server.port()); |
| 1096 ServerPrefMap::iterator it = server_pref_map.Get(server); | 1099 ServerPrefMap::iterator it = server_pref_map.Get(server); |
| 1097 if (it == server_pref_map.end()) { | 1100 if (it == server_pref_map.end()) { |
| 1098 ServerPref server_pref; | 1101 ServerPref server_pref; |
| 1099 server_pref.server_network_stats = &map_it->second; | 1102 server_pref.server_network_stats = &map_it->second; |
| 1100 server_pref_map.Put(server, server_pref); | 1103 server_pref_map.Put(server, server_pref); |
| 1101 } else { | 1104 } else { |
| 1102 it->second.server_network_stats = &map_it->second; | 1105 it->second.server_network_stats = &map_it->second; |
| 1103 } | 1106 } |
| 1104 } | 1107 } |
| 1105 | 1108 |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1249 quic_servers_dict); | 1252 quic_servers_dict); |
| 1250 } | 1253 } |
| 1251 | 1254 |
| 1252 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { | 1255 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { |
| 1253 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 1256 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
| 1254 if (!setting_prefs_) | 1257 if (!setting_prefs_) |
| 1255 ScheduleUpdateCacheOnPrefThread(); | 1258 ScheduleUpdateCacheOnPrefThread(); |
| 1256 } | 1259 } |
| 1257 | 1260 |
| 1258 } // namespace net | 1261 } // namespace net |
| OLD | NEW |