| 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 <memory> | 8 #include <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 // Add the entries from the memory cache. | 98 // Add the entries from the memory cache. |
| 99 for (AlternativeServiceMap::reverse_iterator input_it = | 99 for (AlternativeServiceMap::reverse_iterator input_it = |
| 100 new_alternative_service_map.rbegin(); | 100 new_alternative_service_map.rbegin(); |
| 101 input_it != new_alternative_service_map.rend(); ++input_it) { | 101 input_it != new_alternative_service_map.rend(); ++input_it) { |
| 102 if (alternative_service_map_.Get(input_it->first) == | 102 if (alternative_service_map_.Get(input_it->first) == |
| 103 alternative_service_map_.end()) { | 103 alternative_service_map_.end()) { |
| 104 alternative_service_map_.Put(input_it->first, input_it->second); | 104 alternative_service_map_.Put(input_it->first, input_it->second); |
| 105 } | 105 } |
| 106 } | 106 } |
| 107 | 107 |
| 108 // Attempt to find canonical servers. | 108 // Attempt to find canonical servers. Canonical suffix only apply to HTTPS. |
| 109 uint16_t canonical_ports[] = {80, 443}; | 109 uint16_t canonical_port = 443; |
| 110 const char* canonical_scheme = "https"; |
| 110 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 111 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
| 111 std::string canonical_suffix = canonical_suffixes_[i]; | 112 std::string canonical_suffix = canonical_suffixes_[i]; |
| 112 for (size_t j = 0; j < arraysize(canonical_ports); ++j) { | 113 url::SchemeHostPort canonical_server(canonical_scheme, canonical_suffix, |
| 113 HostPortPair canonical_host(canonical_suffix, canonical_ports[j]); | 114 canonical_port); |
| 114 // If we already have a valid canonical server, we're done. | 115 // If we already have a valid canonical server, we're done. |
| 115 if (ContainsKey(canonical_host_to_origin_map_, canonical_host) && | 116 if (ContainsKey(canonical_host_to_origin_map_, canonical_server) && |
| 116 (alternative_service_map_.Peek( | 117 (alternative_service_map_.Peek( |
| 117 canonical_host_to_origin_map_[canonical_host]) != | 118 canonical_host_to_origin_map_[canonical_server]) != |
| 118 alternative_service_map_.end())) { | 119 alternative_service_map_.end())) { |
| 119 continue; | 120 continue; |
| 120 } | 121 } |
| 121 // Now attempt to find a server which matches this origin and set it as | 122 // Now attempt to find a server which matches this origin and set it as |
| 122 // canonical. | 123 // canonical. |
| 123 for (AlternativeServiceMap::const_iterator it = | 124 for (AlternativeServiceMap::const_iterator it = |
| 124 alternative_service_map_.begin(); | 125 alternative_service_map_.begin(); |
| 125 it != alternative_service_map_.end(); ++it) { | 126 it != alternative_service_map_.end(); ++it) { |
| 126 if (base::EndsWith(it->first.host(), canonical_suffixes_[i], | 127 if (base::EndsWith(it->first.host(), canonical_suffixes_[i], |
| 127 base::CompareCase::INSENSITIVE_ASCII)) { | 128 base::CompareCase::INSENSITIVE_ASCII) && |
| 128 canonical_host_to_origin_map_[canonical_host] = it->first; | 129 it->first.scheme() == canonical_server.scheme()) { |
| 129 break; | 130 canonical_host_to_origin_map_[canonical_server] = it->first; |
| 130 } | 131 break; |
| 131 } | 132 } |
| 132 } | 133 } |
| 133 } | 134 } |
| 134 } | 135 } |
| 135 | 136 |
| 136 void HttpServerPropertiesImpl::InitializeSpdySettingsServers( | 137 void HttpServerPropertiesImpl::InitializeSpdySettingsServers( |
| 137 SpdySettingsMap* spdy_settings_map) { | 138 SpdySettingsMap* spdy_settings_map) { |
| 138 // Add the entries from persisted data. | 139 // Add the entries from persisted data. |
| 139 SpdySettingsMap new_spdy_settings_map(SpdySettingsMap::NO_AUTO_EVICT); | 140 SpdySettingsMap new_spdy_settings_map(SpdySettingsMap::NO_AUTO_EVICT); |
| 140 for (SpdySettingsMap::reverse_iterator it = spdy_settings_map->rbegin(); | 141 for (SpdySettingsMap::reverse_iterator it = spdy_settings_map->rbegin(); |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 alternative_service_map_.Clear(); | 230 alternative_service_map_.Clear(); |
| 230 canonical_host_to_origin_map_.clear(); | 231 canonical_host_to_origin_map_.clear(); |
| 231 spdy_settings_map_.Clear(); | 232 spdy_settings_map_.Clear(); |
| 232 last_quic_address_ = IPAddress(); | 233 last_quic_address_ = IPAddress(); |
| 233 server_network_stats_map_.Clear(); | 234 server_network_stats_map_.Clear(); |
| 234 quic_server_info_map_.Clear(); | 235 quic_server_info_map_.Clear(); |
| 235 } | 236 } |
| 236 | 237 |
| 237 bool HttpServerPropertiesImpl::SupportsRequestPriority( | 238 bool HttpServerPropertiesImpl::SupportsRequestPriority( |
| 238 const url::SchemeHostPort& server) { | 239 const url::SchemeHostPort& server) { |
| 239 HostPortPair host_port_pair(server.host(), server.port()); | |
| 240 DCHECK(CalledOnValidThread()); | 240 DCHECK(CalledOnValidThread()); |
| 241 if (server.host().empty()) | 241 if (server.host().empty()) |
| 242 return false; | 242 return false; |
| 243 | 243 |
| 244 if (GetSupportsSpdy(server)) | 244 if (GetSupportsSpdy(server)) |
| 245 return true; | 245 return true; |
| 246 const AlternativeServiceVector alternative_service_vector = | 246 const AlternativeServiceVector alternative_service_vector = |
| 247 GetAlternativeServices(host_port_pair); | 247 GetAlternativeServices(server); |
| 248 for (const AlternativeService& alternative_service : | 248 for (const AlternativeService& alternative_service : |
| 249 alternative_service_vector) { | 249 alternative_service_vector) { |
| 250 if (alternative_service.protocol == QUIC) { | 250 if (alternative_service.protocol == QUIC) { |
| 251 return true; | 251 return true; |
| 252 } | 252 } |
| 253 } | 253 } |
| 254 return false; | 254 return false; |
| 255 } | 255 } |
| 256 | 256 |
| 257 bool HttpServerPropertiesImpl::GetSupportsSpdy( | 257 bool HttpServerPropertiesImpl::GetSupportsSpdy( |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 std::string canonical_suffix = canonical_suffixes_[i]; | 315 std::string canonical_suffix = canonical_suffixes_[i]; |
| 316 if (base::EndsWith(host, canonical_suffixes_[i], | 316 if (base::EndsWith(host, canonical_suffixes_[i], |
| 317 base::CompareCase::INSENSITIVE_ASCII)) { | 317 base::CompareCase::INSENSITIVE_ASCII)) { |
| 318 return canonical_suffix; | 318 return canonical_suffix; |
| 319 } | 319 } |
| 320 } | 320 } |
| 321 return std::string(); | 321 return std::string(); |
| 322 } | 322 } |
| 323 | 323 |
| 324 AlternativeServiceVector HttpServerPropertiesImpl::GetAlternativeServices( | 324 AlternativeServiceVector HttpServerPropertiesImpl::GetAlternativeServices( |
| 325 const HostPortPair& origin) { | 325 const url::SchemeHostPort& origin) { |
| 326 // Copy valid alternative services into |valid_alternative_services|. | 326 // Copy valid alternative services into |valid_alternative_services|. |
| 327 AlternativeServiceVector valid_alternative_services; | 327 AlternativeServiceVector valid_alternative_services; |
| 328 const base::Time now = base::Time::Now(); | 328 const base::Time now = base::Time::Now(); |
| 329 AlternativeServiceMap::iterator map_it = alternative_service_map_.Get(origin); | 329 AlternativeServiceMap::iterator map_it = alternative_service_map_.Get(origin); |
| 330 if (map_it != alternative_service_map_.end()) { | 330 if (map_it != alternative_service_map_.end()) { |
| 331 HostPortPair host_port_pair(origin.host(), origin.port()); |
| 331 for (AlternativeServiceInfoVector::iterator it = map_it->second.begin(); | 332 for (AlternativeServiceInfoVector::iterator it = map_it->second.begin(); |
| 332 it != map_it->second.end();) { | 333 it != map_it->second.end();) { |
| 333 if (it->expiration < now) { | 334 if (it->expiration < now) { |
| 334 it = map_it->second.erase(it); | 335 it = map_it->second.erase(it); |
| 335 continue; | 336 continue; |
| 336 } | 337 } |
| 337 AlternativeService alternative_service(it->alternative_service); | 338 AlternativeService alternative_service(it->alternative_service); |
| 338 if (alternative_service.host.empty()) { | 339 if (alternative_service.host.empty()) { |
| 339 alternative_service.host = origin.host(); | 340 alternative_service.host = origin.host(); |
| 340 } | 341 } |
| 341 // If the alternative service is equivalent to the origin (same host, same | 342 // If the alternative service is equivalent to the origin (same host, same |
| 342 // port, and both TCP), then there is already a Job for it, so do not | 343 // port, and both TCP), skip it. |
| 343 // return it here. | 344 if (host_port_pair.Equals(alternative_service.host_port_pair()) && |
| 344 if (origin.Equals(alternative_service.host_port_pair()) && | |
| 345 NPN_SPDY_MINIMUM_VERSION <= alternative_service.protocol && | 345 NPN_SPDY_MINIMUM_VERSION <= alternative_service.protocol && |
| 346 alternative_service.protocol <= NPN_SPDY_MAXIMUM_VERSION) { | 346 alternative_service.protocol <= NPN_SPDY_MAXIMUM_VERSION) { |
| 347 ++it; | 347 ++it; |
| 348 continue; | 348 continue; |
| 349 } | 349 } |
| 350 valid_alternative_services.push_back(alternative_service); | 350 valid_alternative_services.push_back(alternative_service); |
| 351 ++it; | 351 ++it; |
| 352 } | 352 } |
| 353 if (map_it->second.empty()) { | 353 if (map_it->second.empty()) { |
| 354 alternative_service_map_.Erase(map_it); | 354 alternative_service_map_.Erase(map_it); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 385 valid_alternative_services.push_back(alternative_service); | 385 valid_alternative_services.push_back(alternative_service); |
| 386 ++it; | 386 ++it; |
| 387 } | 387 } |
| 388 if (map_it->second.empty()) { | 388 if (map_it->second.empty()) { |
| 389 alternative_service_map_.Erase(map_it); | 389 alternative_service_map_.Erase(map_it); |
| 390 } | 390 } |
| 391 return valid_alternative_services; | 391 return valid_alternative_services; |
| 392 } | 392 } |
| 393 | 393 |
| 394 bool HttpServerPropertiesImpl::SetAlternativeService( | 394 bool HttpServerPropertiesImpl::SetAlternativeService( |
| 395 const HostPortPair& origin, | 395 const url::SchemeHostPort& origin, |
| 396 const AlternativeService& alternative_service, | 396 const AlternativeService& alternative_service, |
| 397 base::Time expiration) { | 397 base::Time expiration) { |
| 398 return SetAlternativeServices( | 398 return SetAlternativeServices( |
| 399 origin, | 399 origin, |
| 400 AlternativeServiceInfoVector( | 400 AlternativeServiceInfoVector( |
| 401 /*size=*/1, AlternativeServiceInfo(alternative_service, expiration))); | 401 /*size=*/1, AlternativeServiceInfo(alternative_service, expiration))); |
| 402 } | 402 } |
| 403 | 403 |
| 404 bool HttpServerPropertiesImpl::SetAlternativeServices( | 404 bool HttpServerPropertiesImpl::SetAlternativeServices( |
| 405 const HostPortPair& origin, | 405 const url::SchemeHostPort& origin, |
| 406 const AlternativeServiceInfoVector& alternative_service_info_vector) { | 406 const AlternativeServiceInfoVector& alternative_service_info_vector) { |
| 407 AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin); | 407 AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin); |
| 408 | 408 |
| 409 if (alternative_service_info_vector.empty()) { | 409 if (alternative_service_info_vector.empty()) { |
| 410 if (it == alternative_service_map_.end()) { | 410 if (it == alternative_service_map_.end()) { |
| 411 return false; | 411 return false; |
| 412 } | 412 } |
| 413 ClearAlternativeServices(origin); | 413 ClearAlternativeServices(origin); |
| 414 return true; | 414 return true; |
| 415 } | 415 } |
| (...skipping 15 matching lines...) Expand all Loading... |
| 431 if (previously_no_alternative_services && | 431 if (previously_no_alternative_services && |
| 432 !GetAlternativeServices(origin).empty()) { | 432 !GetAlternativeServices(origin).empty()) { |
| 433 // TODO(rch): Consider the case where multiple requests are started | 433 // TODO(rch): Consider the case where multiple requests are started |
| 434 // before the first completes. In this case, only one of the jobs | 434 // before the first completes. In this case, only one of the jobs |
| 435 // would reach this code, whereas all of them should should have. | 435 // would reach this code, whereas all of them should should have. |
| 436 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING); | 436 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING); |
| 437 } | 437 } |
| 438 | 438 |
| 439 // If this host ends with a canonical suffix, then set it as the | 439 // If this host ends with a canonical suffix, then set it as the |
| 440 // canonical host. | 440 // canonical host. |
| 441 const char* canonical_scheme = "https"; |
| 441 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 442 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
| 442 std::string canonical_suffix = canonical_suffixes_[i]; | 443 std::string canonical_suffix = canonical_suffixes_[i]; |
| 443 if (base::EndsWith(origin.host(), canonical_suffixes_[i], | 444 // canonical suffixes only apply to HTTPS. |
| 445 if (origin.scheme() == canonical_scheme && |
| 446 base::EndsWith(origin.host(), canonical_suffixes_[i], |
| 444 base::CompareCase::INSENSITIVE_ASCII)) { | 447 base::CompareCase::INSENSITIVE_ASCII)) { |
| 445 HostPortPair canonical_host(canonical_suffix, origin.port()); | 448 url::SchemeHostPort canonical_server(canonical_scheme, canonical_suffix, |
| 446 canonical_host_to_origin_map_[canonical_host] = origin; | 449 origin.port()); |
| 450 canonical_host_to_origin_map_[canonical_server] = origin; |
| 447 break; | 451 break; |
| 448 } | 452 } |
| 449 } | 453 } |
| 450 | 454 |
| 451 return changed; | 455 return changed; |
| 452 } | 456 } |
| 453 | 457 |
| 454 void HttpServerPropertiesImpl::MarkAlternativeServiceBroken( | 458 void HttpServerPropertiesImpl::MarkAlternativeServiceBroken( |
| 455 const AlternativeService& alternative_service) { | 459 const AlternativeService& alternative_service) { |
| 456 // Empty host means use host of origin, callers are supposed to substitute. | 460 // Empty host means use host of origin, callers are supposed to substitute. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 | 504 |
| 501 void HttpServerPropertiesImpl::ConfirmAlternativeService( | 505 void HttpServerPropertiesImpl::ConfirmAlternativeService( |
| 502 const AlternativeService& alternative_service) { | 506 const AlternativeService& alternative_service) { |
| 503 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) | 507 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) |
| 504 return; | 508 return; |
| 505 broken_alternative_services_.erase(alternative_service); | 509 broken_alternative_services_.erase(alternative_service); |
| 506 recently_broken_alternative_services_.erase(alternative_service); | 510 recently_broken_alternative_services_.erase(alternative_service); |
| 507 } | 511 } |
| 508 | 512 |
| 509 void HttpServerPropertiesImpl::ClearAlternativeServices( | 513 void HttpServerPropertiesImpl::ClearAlternativeServices( |
| 510 const HostPortPair& origin) { | 514 const url::SchemeHostPort& origin) { |
| 511 RemoveCanonicalHost(origin); | 515 RemoveCanonicalHost(origin); |
| 512 | 516 |
| 513 AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin); | 517 AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin); |
| 514 if (it == alternative_service_map_.end()) { | 518 if (it == alternative_service_map_.end()) { |
| 515 return; | 519 return; |
| 516 } | 520 } |
| 517 alternative_service_map_.Erase(it); | 521 alternative_service_map_.Erase(it); |
| 518 } | 522 } |
| 519 | 523 |
| 520 const AlternativeServiceMap& HttpServerPropertiesImpl::alternative_service_map() | 524 const AlternativeServiceMap& HttpServerPropertiesImpl::alternative_service_map() |
| 521 const { | 525 const { |
| 522 return alternative_service_map_; | 526 return alternative_service_map_; |
| 523 } | 527 } |
| 524 | 528 |
| 525 std::unique_ptr<base::Value> | 529 std::unique_ptr<base::Value> |
| 526 HttpServerPropertiesImpl::GetAlternativeServiceInfoAsValue() const { | 530 HttpServerPropertiesImpl::GetAlternativeServiceInfoAsValue() const { |
| 527 std::unique_ptr<base::ListValue> dict_list(new base::ListValue); | 531 std::unique_ptr<base::ListValue> dict_list(new base::ListValue); |
| 528 for (const auto& alternative_service_map_item : alternative_service_map_) { | 532 for (const auto& alternative_service_map_item : alternative_service_map_) { |
| 529 std::unique_ptr<base::ListValue> alternative_service_list( | 533 std::unique_ptr<base::ListValue> alternative_service_list( |
| 530 new base::ListValue); | 534 new base::ListValue); |
| 531 const HostPortPair& host_port_pair = alternative_service_map_item.first; | 535 const url::SchemeHostPort& server = alternative_service_map_item.first; |
| 532 for (const AlternativeServiceInfo& alternative_service_info : | 536 for (const AlternativeServiceInfo& alternative_service_info : |
| 533 alternative_service_map_item.second) { | 537 alternative_service_map_item.second) { |
| 534 std::string alternative_service_string( | 538 std::string alternative_service_string( |
| 535 alternative_service_info.ToString()); | 539 alternative_service_info.ToString()); |
| 536 AlternativeService alternative_service( | 540 AlternativeService alternative_service( |
| 537 alternative_service_info.alternative_service); | 541 alternative_service_info.alternative_service); |
| 538 if (alternative_service.host.empty()) { | 542 if (alternative_service.host.empty()) { |
| 539 alternative_service.host = host_port_pair.host(); | 543 alternative_service.host = server.host(); |
| 540 } | 544 } |
| 541 if (IsAlternativeServiceBroken(alternative_service)) { | 545 if (IsAlternativeServiceBroken(alternative_service)) { |
| 542 alternative_service_string.append(" (broken)"); | 546 alternative_service_string.append(" (broken)"); |
| 543 } | 547 } |
| 544 alternative_service_list->Append( | 548 alternative_service_list->Append( |
| 545 new base::StringValue(alternative_service_string)); | 549 new base::StringValue(alternative_service_string)); |
| 546 } | 550 } |
| 547 if (alternative_service_list->empty()) | 551 if (alternative_service_list->empty()) |
| 548 continue; | 552 continue; |
| 549 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 553 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 550 dict->SetString("host_port_pair", host_port_pair.ToString()); | 554 dict->SetString("server", server.Serialize()); |
| 551 dict->Set("alternative_service", std::unique_ptr<base::Value>( | 555 dict->Set("alternative_service", std::unique_ptr<base::Value>( |
| 552 std::move(alternative_service_list))); | 556 std::move(alternative_service_list))); |
| 553 dict_list->Append(std::move(dict)); | 557 dict_list->Append(std::move(dict)); |
| 554 } | 558 } |
| 555 return std::move(dict_list); | 559 return std::move(dict_list); |
| 556 } | 560 } |
| 557 | 561 |
| 558 const SettingsMap& HttpServerPropertiesImpl::GetSpdySettings( | 562 const SettingsMap& HttpServerPropertiesImpl::GetSpdySettings( |
| 559 const url::SchemeHostPort& server) { | 563 const url::SchemeHostPort& server) { |
| 560 SpdySettingsMap::iterator it = spdy_settings_map_.Get(server); | 564 SpdySettingsMap::iterator it = spdy_settings_map_.Get(server); |
| 561 if (it == spdy_settings_map_.end()) { | 565 if (it == spdy_settings_map_.end()) { |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 for (QuicServerInfoMap::reverse_iterator it = quic_server_info_map_.rbegin(); | 682 for (QuicServerInfoMap::reverse_iterator it = quic_server_info_map_.rbegin(); |
| 679 it != quic_server_info_map_.rend(); ++it) { | 683 it != quic_server_info_map_.rend(); ++it) { |
| 680 temp_map.Put(it->first, it->second); | 684 temp_map.Put(it->first, it->second); |
| 681 } | 685 } |
| 682 | 686 |
| 683 quic_server_info_map_.Swap(temp_map); | 687 quic_server_info_map_.Swap(temp_map); |
| 684 } | 688 } |
| 685 | 689 |
| 686 AlternativeServiceMap::const_iterator | 690 AlternativeServiceMap::const_iterator |
| 687 HttpServerPropertiesImpl::GetAlternateProtocolIterator( | 691 HttpServerPropertiesImpl::GetAlternateProtocolIterator( |
| 688 const HostPortPair& server) { | 692 const url::SchemeHostPort& server) { |
| 689 AlternativeServiceMap::const_iterator it = | 693 AlternativeServiceMap::const_iterator it = |
| 690 alternative_service_map_.Get(server); | 694 alternative_service_map_.Get(server); |
| 691 if (it != alternative_service_map_.end()) | 695 if (it != alternative_service_map_.end()) |
| 692 return it; | 696 return it; |
| 693 | 697 |
| 694 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(server); | 698 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(server); |
| 695 if (canonical == canonical_host_to_origin_map_.end()) { | 699 if (canonical == canonical_host_to_origin_map_.end()) { |
| 696 return alternative_service_map_.end(); | 700 return alternative_service_map_.end(); |
| 697 } | 701 } |
| 698 | 702 |
| 699 const HostPortPair canonical_host_port = canonical->second; | 703 const url::SchemeHostPort canonical_server = canonical->second; |
| 700 it = alternative_service_map_.Get(canonical_host_port); | 704 it = alternative_service_map_.Get(canonical_server); |
| 701 if (it == alternative_service_map_.end()) { | 705 if (it == alternative_service_map_.end()) { |
| 702 return alternative_service_map_.end(); | 706 return alternative_service_map_.end(); |
| 703 } | 707 } |
| 704 | 708 |
| 705 for (const AlternativeServiceInfo& alternative_service_info : it->second) { | 709 for (const AlternativeServiceInfo& alternative_service_info : it->second) { |
| 706 AlternativeService alternative_service( | 710 AlternativeService alternative_service( |
| 707 alternative_service_info.alternative_service); | 711 alternative_service_info.alternative_service); |
| 708 if (alternative_service.host.empty()) { | 712 if (alternative_service.host.empty()) { |
| 709 alternative_service.host = canonical_host_port.host(); | 713 alternative_service.host = canonical_server.host(); |
| 710 } | 714 } |
| 711 if (!IsAlternativeServiceBroken(alternative_service)) { | 715 if (!IsAlternativeServiceBroken(alternative_service)) { |
| 712 return it; | 716 return it; |
| 713 } | 717 } |
| 714 } | 718 } |
| 715 | 719 |
| 716 RemoveCanonicalHost(canonical_host_port); | 720 RemoveCanonicalHost(canonical_server); |
| 717 return alternative_service_map_.end(); | 721 return alternative_service_map_.end(); |
| 718 } | 722 } |
| 719 | 723 |
| 720 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator | 724 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator |
| 721 HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const { | 725 HttpServerPropertiesImpl::GetCanonicalHost( |
| 726 const url::SchemeHostPort& server) const { |
| 727 const char* canonical_scheme = "https"; |
| 728 if (server.scheme() != canonical_scheme) |
| 729 return canonical_host_to_origin_map_.end(); |
| 730 |
| 722 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 731 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
| 723 std::string canonical_suffix = canonical_suffixes_[i]; | 732 std::string canonical_suffix = canonical_suffixes_[i]; |
| 724 if (base::EndsWith(server.host(), canonical_suffixes_[i], | 733 if (base::EndsWith(server.host(), canonical_suffixes_[i], |
| 725 base::CompareCase::INSENSITIVE_ASCII)) { | 734 base::CompareCase::INSENSITIVE_ASCII)) { |
| 726 HostPortPair canonical_host(canonical_suffix, server.port()); | 735 url::SchemeHostPort canonical_server(canonical_scheme, canonical_suffix, |
| 727 return canonical_host_to_origin_map_.find(canonical_host); | 736 server.port()); |
| 737 return canonical_host_to_origin_map_.find(canonical_server); |
| 728 } | 738 } |
| 729 } | 739 } |
| 730 | 740 |
| 731 return canonical_host_to_origin_map_.end(); | 741 return canonical_host_to_origin_map_.end(); |
| 732 } | 742 } |
| 733 | 743 |
| 734 void HttpServerPropertiesImpl::RemoveCanonicalHost( | 744 void HttpServerPropertiesImpl::RemoveCanonicalHost( |
| 735 const HostPortPair& server) { | 745 const url::SchemeHostPort& server) { |
| 736 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(server); | 746 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(server); |
| 737 if (canonical == canonical_host_to_origin_map_.end()) | 747 if (canonical == canonical_host_to_origin_map_.end()) |
| 738 return; | 748 return; |
| 739 | 749 |
| 740 if (!canonical->second.Equals(server)) | 750 if (!canonical->second.Equals(server)) |
| 741 return; | 751 return; |
| 742 | 752 |
| 743 canonical_host_to_origin_map_.erase(canonical->first); | 753 canonical_host_to_origin_map_.erase(canonical->first); |
| 744 } | 754 } |
| 745 | 755 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 798 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 808 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
| 799 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 809 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 800 FROM_HERE, | 810 FROM_HERE, |
| 801 base::Bind( | 811 base::Bind( |
| 802 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 812 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
| 803 weak_ptr_factory_.GetWeakPtr()), | 813 weak_ptr_factory_.GetWeakPtr()), |
| 804 delay); | 814 delay); |
| 805 } | 815 } |
| 806 | 816 |
| 807 } // namespace net | 817 } // namespace net |
| OLD | NEW |