| 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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 if (alternative_service.host.empty()) { | 312 if (alternative_service.host.empty()) { |
| 313 alternative_service.host = origin.host(); | 313 alternative_service.host = origin.host(); |
| 314 } | 314 } |
| 315 // If the alternative service is equivalent to the origin (same host, same | 315 // If the alternative service is equivalent to the origin (same host, same |
| 316 // port, and both TCP), skip it. | 316 // port, and both TCP), skip it. |
| 317 if (host_port_pair.Equals(alternative_service.host_port_pair()) && | 317 if (host_port_pair.Equals(alternative_service.host_port_pair()) && |
| 318 alternative_service.protocol == kProtoHTTP2) { | 318 alternative_service.protocol == kProtoHTTP2) { |
| 319 ++it; | 319 ++it; |
| 320 continue; | 320 continue; |
| 321 } | 321 } |
| 322 valid_alternative_service_infos.push_back( | 322 valid_alternative_service_infos.push_back(AlternativeServiceInfo( |
| 323 AlternativeServiceInfo(alternative_service, it->expiration)); | 323 alternative_service, it->expiration, it->advertised_versions())); |
| 324 ++it; | 324 ++it; |
| 325 } | 325 } |
| 326 if (map_it->second.empty()) { | 326 if (map_it->second.empty()) { |
| 327 alternative_service_map_.Erase(map_it); | 327 alternative_service_map_.Erase(map_it); |
| 328 } | 328 } |
| 329 return valid_alternative_service_infos; | 329 return valid_alternative_service_infos; |
| 330 } | 330 } |
| 331 | 331 |
| 332 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(origin); | 332 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(origin); |
| 333 if (canonical == canonical_host_to_origin_map_.end()) { | 333 if (canonical == canonical_host_to_origin_map_.end()) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 348 alternative_service.host = canonical->second.host(); | 348 alternative_service.host = canonical->second.host(); |
| 349 if (IsAlternativeServiceBroken(alternative_service)) { | 349 if (IsAlternativeServiceBroken(alternative_service)) { |
| 350 ++it; | 350 ++it; |
| 351 continue; | 351 continue; |
| 352 } | 352 } |
| 353 alternative_service.host = origin.host(); | 353 alternative_service.host = origin.host(); |
| 354 } else if (IsAlternativeServiceBroken(alternative_service)) { | 354 } else if (IsAlternativeServiceBroken(alternative_service)) { |
| 355 ++it; | 355 ++it; |
| 356 continue; | 356 continue; |
| 357 } | 357 } |
| 358 valid_alternative_service_infos.push_back( | 358 valid_alternative_service_infos.push_back(AlternativeServiceInfo( |
| 359 AlternativeServiceInfo(alternative_service, it->expiration)); | 359 alternative_service, it->expiration, it->advertised_versions())); |
| 360 ++it; | 360 ++it; |
| 361 } | 361 } |
| 362 if (map_it->second.empty()) { | 362 if (map_it->second.empty()) { |
| 363 alternative_service_map_.Erase(map_it); | 363 alternative_service_map_.Erase(map_it); |
| 364 } | 364 } |
| 365 return valid_alternative_service_infos; | 365 return valid_alternative_service_infos; |
| 366 } | 366 } |
| 367 | 367 |
| 368 bool HttpServerPropertiesImpl::SetAlternativeService( | 368 bool HttpServerPropertiesImpl::SetAlternativeService( |
| 369 const url::SchemeHostPort& origin, | 369 const url::SchemeHostPort& origin, |
| 370 const AlternativeService& alternative_service, | 370 const AlternativeService& alternative_service, |
| 371 base::Time expiration) { | 371 base::Time expiration, |
| 372 const QuicVersionVector& advertised_versions) { |
| 373 // Alternative service has Non-QUIC protocol should not have any QUIC version |
| 374 // listed in advertised versions. |
| 375 if (alternative_service.protocol != kProtoQUIC) |
| 376 DCHECK(advertised_versions.empty()); |
| 377 |
| 372 return SetAlternativeServices( | 378 return SetAlternativeServices( |
| 373 origin, | 379 origin, |
| 374 AlternativeServiceInfoVector( | 380 AlternativeServiceInfoVector( |
| 375 /*size=*/1, AlternativeServiceInfo(alternative_service, expiration))); | 381 /*size=*/1, AlternativeServiceInfo(alternative_service, expiration, |
| 382 advertised_versions))); |
| 376 } | 383 } |
| 377 | 384 |
| 378 bool HttpServerPropertiesImpl::SetAlternativeServices( | 385 bool HttpServerPropertiesImpl::SetAlternativeServices( |
| 379 const url::SchemeHostPort& origin, | 386 const url::SchemeHostPort& origin, |
| 380 const AlternativeServiceInfoVector& alternative_service_info_vector) { | 387 const AlternativeServiceInfoVector& alternative_service_info_vector) { |
| 381 AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin); | 388 AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin); |
| 382 | 389 |
| 383 if (alternative_service_info_vector.empty()) { | 390 if (alternative_service_info_vector.empty()) { |
| 384 RemoveCanonicalHost(origin); | 391 RemoveCanonicalHost(origin); |
| 385 if (it == alternative_service_map_.end()) | 392 if (it == alternative_service_map_.end()) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 405 } | 412 } |
| 406 // Also persist to disk if new expiration it more that twice as far or | 413 // Also persist to disk if new expiration it more that twice as far or |
| 407 // less than half as far in the future. | 414 // less than half as far in the future. |
| 408 base::Time old_time = old.expiration; | 415 base::Time old_time = old.expiration; |
| 409 base::Time new_time = new_it->expiration; | 416 base::Time new_time = new_it->expiration; |
| 410 if (new_time - now > 2 * (old_time - now) || | 417 if (new_time - now > 2 * (old_time - now) || |
| 411 2 * (new_time - now) < (old_time - now)) { | 418 2 * (new_time - now) < (old_time - now)) { |
| 412 changed = true; | 419 changed = true; |
| 413 break; | 420 break; |
| 414 } | 421 } |
| 422 // Also persist to disk if new entry has a different list of advertised |
| 423 // versions. |
| 424 if (old.advertised_versions() != new_it->advertised_versions()) { |
| 425 changed = true; |
| 426 break; |
| 427 } |
| 415 ++new_it; | 428 ++new_it; |
| 416 } | 429 } |
| 417 } | 430 } |
| 418 } | 431 } |
| 419 | 432 |
| 420 const bool previously_no_alternative_services = | 433 const bool previously_no_alternative_services = |
| 421 (GetAlternateProtocolIterator(origin) == alternative_service_map_.end()); | 434 (GetAlternateProtocolIterator(origin) == alternative_service_map_.end()); |
| 422 | 435 |
| 423 alternative_service_map_.Put(origin, alternative_service_info_vector); | 436 alternative_service_map_.Put(origin, alternative_service_info_vector); |
| 424 | 437 |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 692 if (map_it->second.empty()) { | 705 if (map_it->second.empty()) { |
| 693 RemoveCanonicalHost(map_it->first); | 706 RemoveCanonicalHost(map_it->first); |
| 694 map_it = alternative_service_map_.Erase(map_it); | 707 map_it = alternative_service_map_.Erase(map_it); |
| 695 continue; | 708 continue; |
| 696 } | 709 } |
| 697 ++map_it; | 710 ++map_it; |
| 698 } | 711 } |
| 699 } | 712 } |
| 700 | 713 |
| 701 } // namespace net | 714 } // namespace net |
| OLD | NEW |