Chromium Code Reviews| 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 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 138 } | 138 } |
| 139 | 139 |
| 140 void HttpServerPropertiesManager::Clear(const base::Closure& completion) { | 140 void HttpServerPropertiesManager::Clear(const base::Closure& completion) { |
| 141 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 141 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 142 | 142 |
| 143 http_server_properties_impl_->Clear(); | 143 http_server_properties_impl_->Clear(); |
| 144 UpdatePrefsFromCacheOnNetworkThread(completion); | 144 UpdatePrefsFromCacheOnNetworkThread(completion); |
| 145 } | 145 } |
| 146 | 146 |
| 147 bool HttpServerPropertiesManager::SupportsRequestPriority( | 147 bool HttpServerPropertiesManager::SupportsRequestPriority( |
| 148 const HostPortPair& server) { | 148 const url::SchemeHostPort& server) { |
| 149 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 149 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 150 return http_server_properties_impl_->SupportsRequestPriority(server); | 150 return http_server_properties_impl_->SupportsRequestPriority(server); |
| 151 } | 151 } |
| 152 | 152 |
| 153 bool HttpServerPropertiesManager::GetSupportsSpdy(const HostPortPair& server) { | 153 bool HttpServerPropertiesManager::GetSupportsSpdy( |
| 154 const url::SchemeHostPort& server) { | |
| 154 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 155 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 155 return http_server_properties_impl_->GetSupportsSpdy(server); | 156 return http_server_properties_impl_->GetSupportsSpdy(server); |
| 156 } | 157 } |
| 157 | 158 |
| 158 void HttpServerPropertiesManager::SetSupportsSpdy(const HostPortPair& server, | 159 void HttpServerPropertiesManager::SetSupportsSpdy( |
| 159 bool support_spdy) { | 160 const url::SchemeHostPort& server, |
| 161 bool support_spdy) { | |
| 160 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 162 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 161 | 163 |
| 162 bool old_support_spdy = http_server_properties_impl_->GetSupportsSpdy(server); | 164 bool old_support_spdy = http_server_properties_impl_->GetSupportsSpdy(server); |
| 163 http_server_properties_impl_->SetSupportsSpdy(server, support_spdy); | 165 http_server_properties_impl_->SetSupportsSpdy(server, support_spdy); |
| 164 bool new_support_spdy = http_server_properties_impl_->GetSupportsSpdy(server); | 166 bool new_support_spdy = http_server_properties_impl_->GetSupportsSpdy(server); |
| 165 if (old_support_spdy != new_support_spdy) | 167 if (old_support_spdy != new_support_spdy) |
| 166 ScheduleUpdatePrefsOnNetworkThread(SUPPORTS_SPDY); | 168 ScheduleUpdatePrefsOnNetworkThread(SUPPORTS_SPDY); |
| 167 } | 169 } |
| 168 | 170 |
| 169 bool HttpServerPropertiesManager::RequiresHTTP11(const HostPortPair& server) { | 171 bool HttpServerPropertiesManager::RequiresHTTP11(const HostPortPair& server) { |
| (...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 if (!http_server_properties_dict.GetListWithoutPathExpansion( | 484 if (!http_server_properties_dict.GetListWithoutPathExpansion( |
| 483 kServersKey, &servers_list)) { | 485 kServersKey, &servers_list)) { |
| 484 DVLOG(1) << "Malformed http_server_properties for servers list."; | 486 DVLOG(1) << "Malformed http_server_properties for servers list."; |
| 485 return; | 487 return; |
| 486 } | 488 } |
| 487 } | 489 } |
| 488 | 490 |
| 489 IPAddress* addr = new IPAddress; | 491 IPAddress* addr = new IPAddress; |
| 490 ReadSupportsQuic(http_server_properties_dict, addr); | 492 ReadSupportsQuic(http_server_properties_dict, addr); |
| 491 | 493 |
| 492 // String is host/port pair of spdy server. | 494 // String is "scheme://host:port" tuple of spdy server. |
| 493 scoped_ptr<ServerList> spdy_servers(new ServerList); | 495 scoped_ptr<ServerList> spdy_servers(new ServerList); |
| 494 scoped_ptr<SpdySettingsMap> spdy_settings_map( | 496 scoped_ptr<SpdySettingsMap> spdy_settings_map( |
| 495 new SpdySettingsMap(kMaxSpdySettingsHostsToPersist)); | 497 new SpdySettingsMap(kMaxSpdySettingsHostsToPersist)); |
| 496 scoped_ptr<AlternativeServiceMap> alternative_service_map( | 498 scoped_ptr<AlternativeServiceMap> alternative_service_map( |
| 497 new AlternativeServiceMap(kMaxAlternateProtocolHostsToPersist)); | 499 new AlternativeServiceMap(kMaxAlternateProtocolHostsToPersist)); |
| 498 scoped_ptr<ServerNetworkStatsMap> server_network_stats_map( | 500 scoped_ptr<ServerNetworkStatsMap> server_network_stats_map( |
| 499 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist)); | 501 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist)); |
| 500 scoped_ptr<QuicServerInfoMap> quic_server_info_map( | 502 scoped_ptr<QuicServerInfoMap> quic_server_info_map( |
| 501 new QuicServerInfoMap(QuicServerInfoMap::NO_AUTO_EVICT)); | 503 new QuicServerInfoMap(QuicServerInfoMap::NO_AUTO_EVICT)); |
| 502 | 504 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 540 } | 542 } |
| 541 | 543 |
| 542 bool HttpServerPropertiesManager::AddServersData( | 544 bool HttpServerPropertiesManager::AddServersData( |
| 543 const base::DictionaryValue& servers_dict, | 545 const base::DictionaryValue& servers_dict, |
| 544 ServerList* spdy_servers, | 546 ServerList* spdy_servers, |
| 545 SpdySettingsMap* spdy_settings_map, | 547 SpdySettingsMap* spdy_settings_map, |
| 546 AlternativeServiceMap* alternative_service_map, | 548 AlternativeServiceMap* alternative_service_map, |
| 547 ServerNetworkStatsMap* network_stats_map) { | 549 ServerNetworkStatsMap* network_stats_map) { |
| 548 for (base::DictionaryValue::Iterator it(servers_dict); !it.IsAtEnd(); | 550 for (base::DictionaryValue::Iterator it(servers_dict); !it.IsAtEnd(); |
| 549 it.Advance()) { | 551 it.Advance()) { |
| 552 // TODO(zhongyi): get server's scheme/host/port when servers_dict migrates | |
| 553 // to SchemeHostPort. | |
| 550 // Get server's host/pair. | 554 // Get server's host/pair. |
| 551 const std::string& server_str = it.key(); | 555 const std::string& server_str = it.key(); |
| 552 HostPortPair server = HostPortPair::FromString(server_str); | 556 HostPortPair server = HostPortPair::FromString(server_str); |
| 553 if (server.host().empty()) { | 557 if (server.host().empty()) { |
| 554 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; | 558 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; |
| 555 return false; | 559 return false; |
| 556 } | 560 } |
| 557 | 561 |
| 558 const base::DictionaryValue* server_pref_dict = nullptr; | 562 const base::DictionaryValue* server_pref_dict = nullptr; |
| 559 if (!it.value().GetAsDictionary(&server_pref_dict)) { | 563 if (!it.value().GetAsDictionary(&server_pref_dict)) { |
| 560 DVLOG(1) << "Malformed http_server_properties server: " << server_str; | 564 DVLOG(1) << "Malformed http_server_properties server: " << server_str; |
| 561 return false; | 565 return false; |
| 562 } | 566 } |
| 563 | 567 |
| 564 // Get if server supports Spdy. | 568 // Get if server supports Spdy. |
| 565 bool supports_spdy = false; | 569 bool supports_spdy = false; |
| 566 if ((server_pref_dict->GetBoolean(kSupportsSpdyKey, &supports_spdy)) && | 570 if ((server_pref_dict->GetBoolean(kSupportsSpdyKey, &supports_spdy)) && |
| 567 supports_spdy) { | 571 supports_spdy) { |
| 568 spdy_servers->push_back(server_str); | 572 // TODO(zhongyi): fill in the scheme field when servers_dict has scheme. |
| 573 std::string server_scheme_host_port = "http://" + server_str; | |
|
Ryan Hamilton
2016/04/06 19:16:08
Hm. Seems like we should convert servers_dict at t
Zhongyi Shi
2016/04/07 00:31:18
Will do when we migrating servers_dict!:D
| |
| 574 spdy_servers->push_back(server_scheme_host_port); | |
| 569 } | 575 } |
| 570 | 576 |
| 571 AddToSpdySettingsMap(server, *server_pref_dict, spdy_settings_map); | 577 AddToSpdySettingsMap(server, *server_pref_dict, spdy_settings_map); |
| 572 if (!AddToAlternativeServiceMap(server, *server_pref_dict, | 578 if (!AddToAlternativeServiceMap(server, *server_pref_dict, |
| 573 alternative_service_map) || | 579 alternative_service_map) || |
| 574 !AddToNetworkStatsMap(server, *server_pref_dict, network_stats_map)) { | 580 !AddToNetworkStatsMap(server, *server_pref_dict, network_stats_map)) { |
| 575 return false; | 581 return false; |
| 576 } | 582 } |
| 577 } | 583 } |
| 578 return true; | 584 return true; |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1239 quic_servers_dict); | 1245 quic_servers_dict); |
| 1240 } | 1246 } |
| 1241 | 1247 |
| 1242 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { | 1248 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { |
| 1243 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 1249 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
| 1244 if (!setting_prefs_) | 1250 if (!setting_prefs_) |
| 1245 ScheduleUpdateCacheOnPrefThread(); | 1251 ScheduleUpdateCacheOnPrefThread(); |
| 1246 } | 1252 } |
| 1247 | 1253 |
| 1248 } // namespace net | 1254 } // namespace net |
| OLD | NEW |