Chromium Code Reviews| 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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 if (alternative_service.host.empty()) { | 315 if (alternative_service.host.empty()) { |
| 316 alternative_service.host = origin.host(); | 316 alternative_service.host = origin.host(); |
| 317 } | 317 } |
| 318 // If the alternative service is equivalent to the origin (same host, same | 318 // If the alternative service is equivalent to the origin (same host, same |
| 319 // port, and both TCP), skip it. | 319 // port, and both TCP), skip it. |
| 320 if (host_port_pair.Equals(alternative_service.host_port_pair()) && | 320 if (host_port_pair.Equals(alternative_service.host_port_pair()) && |
| 321 alternative_service.protocol == kProtoHTTP2) { | 321 alternative_service.protocol == kProtoHTTP2) { |
| 322 ++it; | 322 ++it; |
| 323 continue; | 323 continue; |
| 324 } | 324 } |
| 325 valid_alternative_service_infos.push_back( | 325 if (alternative_service.protocol == kProtoQUIC) { |
| 326 AlternativeServiceInfo(alternative_service, it->expiration())); | 326 valid_alternative_service_infos.push_back( |
| 327 AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( | |
| 328 alternative_service, it->expiration(), | |
| 329 it->advertised_versions())); | |
| 330 } else { | |
| 331 valid_alternative_service_infos.push_back( | |
| 332 AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo( | |
| 333 alternative_service, it->expiration())); | |
| 334 } | |
| 327 ++it; | 335 ++it; |
| 328 } | 336 } |
| 329 if (map_it->second.empty()) { | 337 if (map_it->second.empty()) { |
| 330 alternative_service_map_.Erase(map_it); | 338 alternative_service_map_.Erase(map_it); |
| 331 } | 339 } |
| 332 return valid_alternative_service_infos; | 340 return valid_alternative_service_infos; |
| 333 } | 341 } |
| 334 | 342 |
| 335 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(origin); | 343 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(origin); |
| 336 if (canonical == canonical_host_to_origin_map_.end()) { | 344 if (canonical == canonical_host_to_origin_map_.end()) { |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 351 alternative_service.host = canonical->second.host(); | 359 alternative_service.host = canonical->second.host(); |
| 352 if (IsAlternativeServiceBroken(alternative_service)) { | 360 if (IsAlternativeServiceBroken(alternative_service)) { |
| 353 ++it; | 361 ++it; |
| 354 continue; | 362 continue; |
| 355 } | 363 } |
| 356 alternative_service.host = origin.host(); | 364 alternative_service.host = origin.host(); |
| 357 } else if (IsAlternativeServiceBroken(alternative_service)) { | 365 } else if (IsAlternativeServiceBroken(alternative_service)) { |
| 358 ++it; | 366 ++it; |
| 359 continue; | 367 continue; |
| 360 } | 368 } |
| 361 valid_alternative_service_infos.push_back( | 369 if (alternative_service.protocol == kProtoQUIC) { |
| 362 AlternativeServiceInfo(alternative_service, it->expiration())); | 370 valid_alternative_service_infos.push_back( |
| 371 AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( | |
| 372 alternative_service, it->expiration(), | |
| 373 it->advertised_versions())); | |
| 374 } else { | |
| 375 valid_alternative_service_infos.push_back( | |
| 376 AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo( | |
| 377 alternative_service, it->expiration())); | |
| 378 } | |
| 363 ++it; | 379 ++it; |
| 364 } | 380 } |
| 365 if (map_it->second.empty()) { | 381 if (map_it->second.empty()) { |
| 366 alternative_service_map_.Erase(map_it); | 382 alternative_service_map_.Erase(map_it); |
| 367 } | 383 } |
| 368 return valid_alternative_service_infos; | 384 return valid_alternative_service_infos; |
| 369 } | 385 } |
| 370 | 386 |
| 371 bool HttpServerPropertiesImpl::SetAlternativeService( | 387 bool HttpServerPropertiesImpl::SetHttp2AlternativeService( |
| 372 const url::SchemeHostPort& origin, | 388 const url::SchemeHostPort& origin, |
| 373 const AlternativeService& alternative_service, | 389 const AlternativeService& alternative_service, |
| 374 base::Time expiration) { | 390 base::Time expiration) { |
| 391 DCHECK(alternative_service.protocol != kProtoQUIC); | |
|
Bence
2017/06/16 14:43:40
Optional: this is not necessary, as CreateHttp2Alt
Zhongyi Shi
2017/06/20 23:23:37
Done.
| |
| 392 | |
| 375 return SetAlternativeServices( | 393 return SetAlternativeServices( |
| 376 origin, | 394 origin, |
| 377 AlternativeServiceInfoVector( | 395 AlternativeServiceInfoVector( |
| 378 /*size=*/1, AlternativeServiceInfo(alternative_service, expiration))); | 396 /*size=*/1, AlternativeServiceInfo::CreateHttp2AlternativeServiceInfo( |
| 397 alternative_service, expiration))); | |
| 398 } | |
| 399 | |
| 400 bool HttpServerPropertiesImpl::SetQuicAlternativeService( | |
| 401 const url::SchemeHostPort& origin, | |
| 402 const AlternativeService& alternative_service, | |
| 403 base::Time expiration, | |
| 404 const QuicVersionVector& advertised_versions) { | |
| 405 DCHECK(alternative_service.protocol == kProtoQUIC); | |
| 406 | |
| 407 return SetAlternativeServices( | |
| 408 origin, AlternativeServiceInfoVector( | |
| 409 /*size=*/1, | |
| 410 AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( | |
| 411 alternative_service, expiration, advertised_versions))); | |
| 379 } | 412 } |
| 380 | 413 |
| 381 bool HttpServerPropertiesImpl::SetAlternativeServices( | 414 bool HttpServerPropertiesImpl::SetAlternativeServices( |
| 382 const url::SchemeHostPort& origin, | 415 const url::SchemeHostPort& origin, |
| 383 const AlternativeServiceInfoVector& alternative_service_info_vector) { | 416 const AlternativeServiceInfoVector& alternative_service_info_vector) { |
| 384 AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin); | 417 AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin); |
| 385 | 418 |
| 386 if (alternative_service_info_vector.empty()) { | 419 if (alternative_service_info_vector.empty()) { |
| 387 RemoveCanonicalHost(origin); | 420 RemoveCanonicalHost(origin); |
| 388 if (it == alternative_service_map_.end()) | 421 if (it == alternative_service_map_.end()) |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 408 } | 441 } |
| 409 // Also persist to disk if new expiration it more that twice as far or | 442 // Also persist to disk if new expiration it more that twice as far or |
| 410 // less than half as far in the future. | 443 // less than half as far in the future. |
| 411 base::Time old_time = old.expiration(); | 444 base::Time old_time = old.expiration(); |
| 412 base::Time new_time = new_it->expiration(); | 445 base::Time new_time = new_it->expiration(); |
| 413 if (new_time - now > 2 * (old_time - now) || | 446 if (new_time - now > 2 * (old_time - now) || |
| 414 2 * (new_time - now) < (old_time - now)) { | 447 2 * (new_time - now) < (old_time - now)) { |
| 415 changed = true; | 448 changed = true; |
| 416 break; | 449 break; |
| 417 } | 450 } |
| 451 // Also persist to disk if new entry has a different list of advertised | |
| 452 // versions. | |
| 453 if (old.advertised_versions() != new_it->advertised_versions()) { | |
| 454 changed = true; | |
| 455 break; | |
| 456 } | |
| 418 ++new_it; | 457 ++new_it; |
| 419 } | 458 } |
| 420 } | 459 } |
| 421 } | 460 } |
| 422 | 461 |
| 423 const bool previously_no_alternative_services = | 462 const bool previously_no_alternative_services = |
| 424 (GetAlternateProtocolIterator(origin) == alternative_service_map_.end()); | 463 (GetAlternateProtocolIterator(origin) == alternative_service_map_.end()); |
| 425 | 464 |
| 426 alternative_service_map_.Put(origin, alternative_service_info_vector); | 465 alternative_service_map_.Put(origin, alternative_service_info_vector); |
| 427 | 466 |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 695 if (map_it->second.empty()) { | 734 if (map_it->second.empty()) { |
| 696 RemoveCanonicalHost(map_it->first); | 735 RemoveCanonicalHost(map_it->first); |
| 697 map_it = alternative_service_map_.Erase(map_it); | 736 map_it = alternative_service_map_.Erase(map_it); |
| 698 continue; | 737 continue; |
| 699 } | 738 } |
| 700 ++map_it; | 739 ++map_it; |
| 701 } | 740 } |
| 702 } | 741 } |
| 703 | 742 |
| 704 } // namespace net | 743 } // namespace net |
| OLD | NEW |