| 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 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 319 if (alternative_service.host.empty()) { | 319 if (alternative_service.host.empty()) { |
| 320 alternative_service.host = origin.host(); | 320 alternative_service.host = origin.host(); |
| 321 } | 321 } |
| 322 // If the alternative service is equivalent to the origin (same host, same | 322 // If the alternative service is equivalent to the origin (same host, same |
| 323 // port, and both TCP), skip it. | 323 // port, and both TCP), skip it. |
| 324 if (host_port_pair.Equals(alternative_service.host_port_pair()) && | 324 if (host_port_pair.Equals(alternative_service.host_port_pair()) && |
| 325 alternative_service.protocol == kProtoHTTP2) { | 325 alternative_service.protocol == kProtoHTTP2) { |
| 326 ++it; | 326 ++it; |
| 327 continue; | 327 continue; |
| 328 } | 328 } |
| 329 valid_alternative_service_infos.push_back( | 329 valid_alternative_service_infos.push_back(AlternativeServiceInfo( |
| 330 AlternativeServiceInfo(alternative_service, it->expiration)); | 330 alternative_service, it->expiration, it->advertised_versions())); |
| 331 ++it; | 331 ++it; |
| 332 } | 332 } |
| 333 if (map_it->second.empty()) { | 333 if (map_it->second.empty()) { |
| 334 alternative_service_map_.Erase(map_it); | 334 alternative_service_map_.Erase(map_it); |
| 335 } | 335 } |
| 336 return valid_alternative_service_infos; | 336 return valid_alternative_service_infos; |
| 337 } | 337 } |
| 338 | 338 |
| 339 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(origin); | 339 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(origin); |
| 340 if (canonical == canonical_host_to_origin_map_.end()) { | 340 if (canonical == canonical_host_to_origin_map_.end()) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 355 alternative_service.host = canonical->second.host(); | 355 alternative_service.host = canonical->second.host(); |
| 356 if (IsAlternativeServiceBroken(alternative_service)) { | 356 if (IsAlternativeServiceBroken(alternative_service)) { |
| 357 ++it; | 357 ++it; |
| 358 continue; | 358 continue; |
| 359 } | 359 } |
| 360 alternative_service.host = origin.host(); | 360 alternative_service.host = origin.host(); |
| 361 } else if (IsAlternativeServiceBroken(alternative_service)) { | 361 } else if (IsAlternativeServiceBroken(alternative_service)) { |
| 362 ++it; | 362 ++it; |
| 363 continue; | 363 continue; |
| 364 } | 364 } |
| 365 valid_alternative_service_infos.push_back( | 365 valid_alternative_service_infos.push_back(AlternativeServiceInfo( |
| 366 AlternativeServiceInfo(alternative_service, it->expiration)); | 366 alternative_service, it->expiration, it->advertised_versions())); |
| 367 ++it; | 367 ++it; |
| 368 } | 368 } |
| 369 if (map_it->second.empty()) { | 369 if (map_it->second.empty()) { |
| 370 alternative_service_map_.Erase(map_it); | 370 alternative_service_map_.Erase(map_it); |
| 371 } | 371 } |
| 372 return valid_alternative_service_infos; | 372 return valid_alternative_service_infos; |
| 373 } | 373 } |
| 374 | 374 |
| 375 bool HttpServerPropertiesImpl::SetAlternativeService( | 375 bool HttpServerPropertiesImpl::SetAlternativeService( |
| 376 const url::SchemeHostPort& origin, | 376 const url::SchemeHostPort& origin, |
| 377 const AlternativeService& alternative_service, | 377 const AlternativeService& alternative_service, |
| 378 base::Time expiration) { | 378 base::Time expiration, |
| 379 const QuicVersionVector& advertised_versions) { |
| 379 return SetAlternativeServices( | 380 return SetAlternativeServices( |
| 380 origin, | 381 origin, |
| 381 AlternativeServiceInfoVector( | 382 AlternativeServiceInfoVector( |
| 382 /*size=*/1, AlternativeServiceInfo(alternative_service, expiration))); | 383 /*size=*/1, AlternativeServiceInfo(alternative_service, expiration, |
| 384 advertised_versions))); |
| 383 } | 385 } |
| 384 | 386 |
| 385 bool HttpServerPropertiesImpl::SetAlternativeServices( | 387 bool HttpServerPropertiesImpl::SetAlternativeServices( |
| 386 const url::SchemeHostPort& origin, | 388 const url::SchemeHostPort& origin, |
| 387 const AlternativeServiceInfoVector& alternative_service_info_vector) { | 389 const AlternativeServiceInfoVector& alternative_service_info_vector) { |
| 388 AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin); | 390 AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin); |
| 389 | 391 |
| 390 if (alternative_service_info_vector.empty()) { | 392 if (alternative_service_info_vector.empty()) { |
| 391 RemoveCanonicalHost(origin); | 393 RemoveCanonicalHost(origin); |
| 392 if (it == alternative_service_map_.end()) | 394 if (it == alternative_service_map_.end()) |
| (...skipping 19 matching lines...) Expand all Loading... |
| 412 } | 414 } |
| 413 // Also persist to disk if new expiration it more that twice as far or | 415 // Also persist to disk if new expiration it more that twice as far or |
| 414 // less than half as far in the future. | 416 // less than half as far in the future. |
| 415 base::Time old_time = old.expiration; | 417 base::Time old_time = old.expiration; |
| 416 base::Time new_time = new_it->expiration; | 418 base::Time new_time = new_it->expiration; |
| 417 if (new_time - now > 2 * (old_time - now) || | 419 if (new_time - now > 2 * (old_time - now) || |
| 418 2 * (new_time - now) < (old_time - now)) { | 420 2 * (new_time - now) < (old_time - now)) { |
| 419 changed = true; | 421 changed = true; |
| 420 break; | 422 break; |
| 421 } | 423 } |
| 424 // Also persist to disk if advertised versions change significantly for |
| 425 // QUIC. |
| 426 if (!old.EqualAdvertisedVersions(*new_it)) { |
| 427 changed = true; |
| 428 break; |
| 429 } |
| 422 ++new_it; | 430 ++new_it; |
| 423 } | 431 } |
| 424 } | 432 } |
| 425 } | 433 } |
| 426 | 434 |
| 427 const bool previously_no_alternative_services = | 435 const bool previously_no_alternative_services = |
| 428 (GetAlternateProtocolIterator(origin) == alternative_service_map_.end()); | 436 (GetAlternateProtocolIterator(origin) == alternative_service_map_.end()); |
| 429 | 437 |
| 430 alternative_service_map_.Put(origin, alternative_service_info_vector); | 438 alternative_service_map_.Put(origin, alternative_service_info_vector); |
| 431 | 439 |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 775 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
| 768 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 776 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 769 FROM_HERE, | 777 FROM_HERE, |
| 770 base::Bind( | 778 base::Bind( |
| 771 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 779 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
| 772 weak_ptr_factory_.GetWeakPtr()), | 780 weak_ptr_factory_.GetWeakPtr()), |
| 773 delay); | 781 delay); |
| 774 } | 782 } |
| 775 | 783 |
| 776 } // namespace net | 784 } // namespace net |
| OLD | NEW |