| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_impl.h" | 5 #include "net/http/http_server_properties_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 } | 200 } |
| 201 } | 201 } |
| 202 | 202 |
| 203 void HttpServerPropertiesImpl::GetSpdyServerList( | 203 void HttpServerPropertiesImpl::GetSpdyServerList( |
| 204 base::ListValue* spdy_server_list, | 204 base::ListValue* spdy_server_list, |
| 205 size_t max_size) const { | 205 size_t max_size) const { |
| 206 DCHECK(CalledOnValidThread()); | 206 DCHECK(CalledOnValidThread()); |
| 207 DCHECK(spdy_server_list); | 207 DCHECK(spdy_server_list); |
| 208 spdy_server_list->Clear(); | 208 spdy_server_list->Clear(); |
| 209 size_t count = 0; | 209 size_t count = 0; |
| 210 // Get the list of servers (host/port) that support SPDY. | 210 // Get the list of servers (scheme/host/port) that support SPDY. |
| 211 for (SpdyServerHostPortMap::const_iterator it = spdy_servers_map_.begin(); | 211 for (SpdyServerHostPortMap::const_iterator it = spdy_servers_map_.begin(); |
| 212 it != spdy_servers_map_.end() && count < max_size; ++it) { | 212 it != spdy_servers_map_.end() && count < max_size; ++it) { |
| 213 const std::string spdy_server_host_port = it->first; | 213 const std::string spdy_server_host_port = it->first; |
| 214 if (it->second) { | 214 if (it->second) { |
| 215 spdy_server_list->Append(new base::StringValue(spdy_server_host_port)); | 215 spdy_server_list->Append(new base::StringValue(spdy_server_host_port)); |
| 216 ++count; | 216 ++count; |
| 217 } | 217 } |
| 218 } | 218 } |
| 219 } | 219 } |
| 220 | 220 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 231 last_quic_address_ = IPAddress(); | 231 last_quic_address_ = IPAddress(); |
| 232 server_network_stats_map_.Clear(); | 232 server_network_stats_map_.Clear(); |
| 233 quic_server_info_map_.Clear(); | 233 quic_server_info_map_.Clear(); |
| 234 } | 234 } |
| 235 | 235 |
| 236 bool HttpServerPropertiesImpl::SupportsRequestPriority( | 236 bool HttpServerPropertiesImpl::SupportsRequestPriority( |
| 237 const url::SchemeHostPort& server) { | 237 const url::SchemeHostPort& server) { |
| 238 DCHECK(CalledOnValidThread()); | 238 DCHECK(CalledOnValidThread()); |
| 239 if (server.host().empty()) | 239 if (server.host().empty()) |
| 240 return false; | 240 return false; |
| 241 if (GetSupportsSpdy(HostPortPair::FromSchemeHostPort(server))) | 241 |
| 242 if (GetSupportsSpdy(server)) |
| 242 return true; | 243 return true; |
| 243 | 244 |
| 244 const AlternativeServiceVector alternative_service_vector = | 245 const AlternativeServiceVector alternative_service_vector = |
| 245 GetAlternativeServices(server); | 246 GetAlternativeServices(server); |
| 246 for (const AlternativeService& alternative_service : | 247 for (const AlternativeService& alternative_service : |
| 247 alternative_service_vector) { | 248 alternative_service_vector) { |
| 248 if (alternative_service.protocol == QUIC) { | 249 if (alternative_service.protocol == QUIC) { |
| 249 return true; | 250 return true; |
| 250 } | 251 } |
| 251 } | 252 } |
| 252 return false; | 253 return false; |
| 253 } | 254 } |
| 254 | 255 |
| 255 bool HttpServerPropertiesImpl::GetSupportsSpdy( | 256 bool HttpServerPropertiesImpl::GetSupportsSpdy( |
| 256 const HostPortPair& host_port_pair) { | 257 const url::SchemeHostPort& server) { |
| 257 DCHECK(CalledOnValidThread()); | 258 DCHECK(CalledOnValidThread()); |
| 258 if (host_port_pair.host().empty()) | 259 if (server.host().empty()) |
| 259 return false; | 260 return false; |
| 260 | 261 |
| 261 SpdyServerHostPortMap::iterator spdy_host_port = | 262 SpdyServerHostPortMap::iterator spdy_host_port = |
| 262 spdy_servers_map_.Get(host_port_pair.ToString()); | 263 spdy_servers_map_.Get(server.ToString()); |
| 263 return spdy_host_port != spdy_servers_map_.end() && spdy_host_port->second; | 264 return spdy_host_port != spdy_servers_map_.end() && spdy_host_port->second; |
| 264 } | 265 } |
| 265 | 266 |
| 266 void HttpServerPropertiesImpl::SetSupportsSpdy( | 267 void HttpServerPropertiesImpl::SetSupportsSpdy( |
| 267 const HostPortPair& host_port_pair, | 268 const url::SchemeHostPort& server, |
| 268 bool support_spdy) { | 269 bool support_spdy) { |
| 269 DCHECK(CalledOnValidThread()); | 270 DCHECK(CalledOnValidThread()); |
| 270 if (host_port_pair.host().empty()) | 271 if (server.host().empty()) |
| 271 return; | 272 return; |
| 272 | 273 |
| 273 SpdyServerHostPortMap::iterator spdy_host_port = | 274 SpdyServerHostPortMap::iterator spdy_host_port = |
| 274 spdy_servers_map_.Get(host_port_pair.ToString()); | 275 spdy_servers_map_.Get(server.ToString()); |
| 275 if ((spdy_host_port != spdy_servers_map_.end()) && | 276 if ((spdy_host_port != spdy_servers_map_.end()) && |
| 276 (spdy_host_port->second == support_spdy)) { | 277 (spdy_host_port->second == support_spdy)) { |
| 277 return; | 278 return; |
| 278 } | 279 } |
| 279 // Cache the data. | 280 // Cache the data. |
| 280 spdy_servers_map_.Put(host_port_pair.ToString(), support_spdy); | 281 spdy_servers_map_.Put(server.ToString(), support_spdy); |
| 281 } | 282 } |
| 282 | 283 |
| 283 bool HttpServerPropertiesImpl::RequiresHTTP11( | 284 bool HttpServerPropertiesImpl::RequiresHTTP11( |
| 284 const HostPortPair& host_port_pair) { | 285 const HostPortPair& host_port_pair) { |
| 285 DCHECK(CalledOnValidThread()); | 286 DCHECK(CalledOnValidThread()); |
| 286 if (host_port_pair.host().empty()) | 287 if (host_port_pair.host().empty()) |
| 287 return false; | 288 return false; |
| 288 | 289 |
| 289 return (http11_servers_.find(host_port_pair) != http11_servers_.end()); | 290 return (http11_servers_.find(host_port_pair) != http11_servers_.end()); |
| 290 } | 291 } |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 552 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 553 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 553 dict->SetString("host_port_pair", host_port_pair.ToString()); | 554 dict->SetString("host_port_pair", host_port_pair.ToString()); |
| 554 dict->Set("alternative_service", | 555 dict->Set("alternative_service", |
| 555 scoped_ptr<base::Value>(std::move(alternative_service_list))); | 556 scoped_ptr<base::Value>(std::move(alternative_service_list))); |
| 556 dict_list->Append(std::move(dict)); | 557 dict_list->Append(std::move(dict)); |
| 557 } | 558 } |
| 558 return std::move(dict_list); | 559 return std::move(dict_list); |
| 559 } | 560 } |
| 560 | 561 |
| 561 const SettingsMap& HttpServerPropertiesImpl::GetSpdySettings( | 562 const SettingsMap& HttpServerPropertiesImpl::GetSpdySettings( |
| 562 const HostPortPair& host_port_pair) { | 563 const url::SchemeHostPort& origin) { |
| 563 SpdySettingsMap::iterator it = spdy_settings_map_.Get(host_port_pair); | 564 SpdySettingsMap::iterator it = spdy_settings_map_.Get(origin); |
| 564 if (it == spdy_settings_map_.end()) { | 565 if (it == spdy_settings_map_.end()) { |
| 565 CR_DEFINE_STATIC_LOCAL(SettingsMap, kEmptySettingsMap, ()); | 566 CR_DEFINE_STATIC_LOCAL(SettingsMap, kEmptySettingsMap, ()); |
| 566 return kEmptySettingsMap; | 567 return kEmptySettingsMap; |
| 567 } | 568 } |
| 568 return it->second; | 569 return it->second; |
| 569 } | 570 } |
| 570 | 571 |
| 571 bool HttpServerPropertiesImpl::SetSpdySetting( | 572 bool HttpServerPropertiesImpl::SetSpdySetting(const url::SchemeHostPort& origin, |
| 572 const HostPortPair& host_port_pair, | 573 SpdySettingsIds id, |
| 573 SpdySettingsIds id, | 574 SpdySettingsFlags flags, |
| 574 SpdySettingsFlags flags, | 575 uint32_t value) { |
| 575 uint32_t value) { | |
| 576 if (!(flags & SETTINGS_FLAG_PLEASE_PERSIST)) | 576 if (!(flags & SETTINGS_FLAG_PLEASE_PERSIST)) |
| 577 return false; | 577 return false; |
| 578 | 578 |
| 579 SettingsFlagsAndValue flags_and_value(SETTINGS_FLAG_PERSISTED, value); | 579 SettingsFlagsAndValue flags_and_value(SETTINGS_FLAG_PERSISTED, value); |
| 580 SpdySettingsMap::iterator it = spdy_settings_map_.Get(host_port_pair); | 580 SpdySettingsMap::iterator it = spdy_settings_map_.Get(origin); |
| 581 if (it == spdy_settings_map_.end()) { | 581 if (it == spdy_settings_map_.end()) { |
| 582 SettingsMap settings_map; | 582 SettingsMap settings_map; |
| 583 settings_map[id] = flags_and_value; | 583 settings_map[id] = flags_and_value; |
| 584 spdy_settings_map_.Put(host_port_pair, settings_map); | 584 spdy_settings_map_.Put(origin, settings_map); |
| 585 } else { | 585 } else { |
| 586 SettingsMap& settings_map = it->second; | 586 SettingsMap& settings_map = it->second; |
| 587 settings_map[id] = flags_and_value; | 587 settings_map[id] = flags_and_value; |
| 588 } | 588 } |
| 589 return true; | 589 return true; |
| 590 } | 590 } |
| 591 | 591 |
| 592 void HttpServerPropertiesImpl::ClearSpdySettings( | 592 void HttpServerPropertiesImpl::ClearSpdySettings( |
| 593 const HostPortPair& host_port_pair) { | 593 const url::SchemeHostPort& origin) { |
| 594 SpdySettingsMap::iterator it = spdy_settings_map_.Peek(host_port_pair); | 594 SpdySettingsMap::iterator it = spdy_settings_map_.Peek(origin); |
| 595 if (it != spdy_settings_map_.end()) | 595 if (it != spdy_settings_map_.end()) |
| 596 spdy_settings_map_.Erase(it); | 596 spdy_settings_map_.Erase(it); |
| 597 } | 597 } |
| 598 | 598 |
| 599 void HttpServerPropertiesImpl::ClearAllSpdySettings() { | 599 void HttpServerPropertiesImpl::ClearAllSpdySettings() { |
| 600 spdy_settings_map_.Clear(); | 600 spdy_settings_map_.Clear(); |
| 601 } | 601 } |
| 602 | 602 |
| 603 const SpdySettingsMap& | 603 const SpdySettingsMap& |
| 604 HttpServerPropertiesImpl::spdy_settings_map() const { | 604 HttpServerPropertiesImpl::spdy_settings_map() const { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 616 void HttpServerPropertiesImpl::SetSupportsQuic(bool used_quic, | 616 void HttpServerPropertiesImpl::SetSupportsQuic(bool used_quic, |
| 617 const IPAddress& address) { | 617 const IPAddress& address) { |
| 618 if (!used_quic) { | 618 if (!used_quic) { |
| 619 last_quic_address_ = IPAddress(); | 619 last_quic_address_ = IPAddress(); |
| 620 } else { | 620 } else { |
| 621 last_quic_address_ = address; | 621 last_quic_address_ = address; |
| 622 } | 622 } |
| 623 } | 623 } |
| 624 | 624 |
| 625 void HttpServerPropertiesImpl::SetServerNetworkStats( | 625 void HttpServerPropertiesImpl::SetServerNetworkStats( |
| 626 const HostPortPair& host_port_pair, | 626 const url::SchemeHostPort& origin, |
| 627 ServerNetworkStats stats) { | 627 ServerNetworkStats stats) { |
| 628 server_network_stats_map_.Put(host_port_pair, stats); | 628 server_network_stats_map_.Put(origin, stats); |
| 629 } | 629 } |
| 630 | 630 |
| 631 const ServerNetworkStats* HttpServerPropertiesImpl::GetServerNetworkStats( | 631 const ServerNetworkStats* HttpServerPropertiesImpl::GetServerNetworkStats( |
| 632 const HostPortPair& host_port_pair) { | 632 const url::SchemeHostPort& origin) { |
| 633 ServerNetworkStatsMap::iterator it = | 633 ServerNetworkStatsMap::iterator it = server_network_stats_map_.Get(origin); |
| 634 server_network_stats_map_.Get(host_port_pair); | |
| 635 if (it == server_network_stats_map_.end()) { | 634 if (it == server_network_stats_map_.end()) { |
| 636 return NULL; | 635 return NULL; |
| 637 } | 636 } |
| 638 return &it->second; | 637 return &it->second; |
| 639 } | 638 } |
| 640 | 639 |
| 641 const ServerNetworkStatsMap& | 640 const ServerNetworkStatsMap& |
| 642 HttpServerPropertiesImpl::server_network_stats_map() const { | 641 HttpServerPropertiesImpl::server_network_stats_map() const { |
| 643 return server_network_stats_map_; | 642 return server_network_stats_map_; |
| 644 } | 643 } |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 807 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 806 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
| 808 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 807 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 809 FROM_HERE, | 808 FROM_HERE, |
| 810 base::Bind( | 809 base::Bind( |
| 811 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 810 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
| 812 weak_ptr_factory_.GetWeakPtr()), | 811 weak_ptr_factory_.GetWeakPtr()), |
| 813 delay); | 812 delay); |
| 814 } | 813 } |
| 815 | 814 |
| 816 } // namespace net | 815 } // namespace net |
| OLD | NEW |