Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Side by Side Diff: net/http/http_server_properties_impl.cc

Issue 1802893002: Revert of Remove support for Alt-Svc/Alternate Protocol Probability (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 14 matching lines...) Expand all
25 25
26 const uint64_t kBrokenAlternativeProtocolDelaySecs = 300; 26 const uint64_t kBrokenAlternativeProtocolDelaySecs = 300;
27 27
28 } // namespace 28 } // namespace
29 29
30 HttpServerPropertiesImpl::HttpServerPropertiesImpl() 30 HttpServerPropertiesImpl::HttpServerPropertiesImpl()
31 : spdy_servers_map_(SpdyServerHostPortMap::NO_AUTO_EVICT), 31 : spdy_servers_map_(SpdyServerHostPortMap::NO_AUTO_EVICT),
32 alternative_service_map_(AlternativeServiceMap::NO_AUTO_EVICT), 32 alternative_service_map_(AlternativeServiceMap::NO_AUTO_EVICT),
33 spdy_settings_map_(SpdySettingsMap::NO_AUTO_EVICT), 33 spdy_settings_map_(SpdySettingsMap::NO_AUTO_EVICT),
34 server_network_stats_map_(ServerNetworkStatsMap::NO_AUTO_EVICT), 34 server_network_stats_map_(ServerNetworkStatsMap::NO_AUTO_EVICT),
35 alternative_service_probability_threshold_(1.0),
35 quic_server_info_map_(QuicServerInfoMap::NO_AUTO_EVICT), 36 quic_server_info_map_(QuicServerInfoMap::NO_AUTO_EVICT),
36 max_server_configs_stored_in_properties_(kMaxQuicServersToPersist), 37 max_server_configs_stored_in_properties_(kMaxQuicServersToPersist),
37 weak_ptr_factory_(this) { 38 weak_ptr_factory_(this) {
38 canonical_suffixes_.push_back(".c.youtube.com"); 39 canonical_suffixes_.push_back(".c.youtube.com");
39 canonical_suffixes_.push_back(".googlevideo.com"); 40 canonical_suffixes_.push_back(".googlevideo.com");
40 canonical_suffixes_.push_back(".googleusercontent.com"); 41 canonical_suffixes_.push_back(".googleusercontent.com");
41 } 42 }
42 43
43 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() { 44 HttpServerPropertiesImpl::~HttpServerPropertiesImpl() {
44 } 45 }
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 if (base::EndsWith(host, canonical_suffixes_[i], 316 if (base::EndsWith(host, canonical_suffixes_[i],
316 base::CompareCase::INSENSITIVE_ASCII)) { 317 base::CompareCase::INSENSITIVE_ASCII)) {
317 return canonical_suffix; 318 return canonical_suffix;
318 } 319 }
319 } 320 }
320 return std::string(); 321 return std::string();
321 } 322 }
322 323
323 AlternativeServiceVector HttpServerPropertiesImpl::GetAlternativeServices( 324 AlternativeServiceVector HttpServerPropertiesImpl::GetAlternativeServices(
324 const HostPortPair& origin) { 325 const HostPortPair& origin) {
325 // Copy valid alternative services into |valid_alternative_services|. 326 // Copy alternative services with probability greater than or equal to the
326 AlternativeServiceVector valid_alternative_services; 327 // threshold into |alternative_services_above_threshold|.
328 AlternativeServiceVector alternative_services_above_threshold;
327 const base::Time now = base::Time::Now(); 329 const base::Time now = base::Time::Now();
328 AlternativeServiceMap::iterator map_it = alternative_service_map_.Get(origin); 330 AlternativeServiceMap::iterator map_it = alternative_service_map_.Get(origin);
329 if (map_it != alternative_service_map_.end()) { 331 if (map_it != alternative_service_map_.end()) {
330 for (AlternativeServiceInfoVector::iterator it = map_it->second.begin(); 332 for (AlternativeServiceInfoVector::iterator it = map_it->second.begin();
331 it != map_it->second.end();) { 333 it != map_it->second.end();) {
332 if (it->expiration < now) { 334 if (it->expiration < now) {
333 it = map_it->second.erase(it); 335 it = map_it->second.erase(it);
334 continue; 336 continue;
335 } 337 }
338 if (it->probability == 0 ||
339 it->probability < alternative_service_probability_threshold_) {
340 ++it;
341 continue;
342 }
336 AlternativeService alternative_service(it->alternative_service); 343 AlternativeService alternative_service(it->alternative_service);
337 if (alternative_service.host.empty()) { 344 if (alternative_service.host.empty()) {
338 alternative_service.host = origin.host(); 345 alternative_service.host = origin.host();
339 } 346 }
340 // If the alternative service is equivalent to the origin (same host, same 347 // If the alternative service is equivalent to the origin (same host, same
341 // port, and both TCP), then there is already a Job for it, so do not 348 // port, and both TCP), then there is already a Job for it, so do not
342 // return it here. 349 // return it here.
343 if (origin.Equals(alternative_service.host_port_pair()) && 350 if (origin.Equals(alternative_service.host_port_pair()) &&
344 NPN_SPDY_MINIMUM_VERSION <= alternative_service.protocol && 351 NPN_SPDY_MINIMUM_VERSION <= alternative_service.protocol &&
345 alternative_service.protocol <= NPN_SPDY_MAXIMUM_VERSION) { 352 alternative_service.protocol <= NPN_SPDY_MAXIMUM_VERSION) {
346 ++it; 353 ++it;
347 continue; 354 continue;
348 } 355 }
349 valid_alternative_services.push_back(alternative_service); 356 alternative_services_above_threshold.push_back(alternative_service);
350 ++it; 357 ++it;
351 } 358 }
352 if (map_it->second.empty()) { 359 if (map_it->second.empty()) {
353 alternative_service_map_.Erase(map_it); 360 alternative_service_map_.Erase(map_it);
354 } 361 }
355 return valid_alternative_services; 362 return alternative_services_above_threshold;
356 } 363 }
357 364
358 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(origin); 365 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(origin);
359 if (canonical == canonical_host_to_origin_map_.end()) { 366 if (canonical == canonical_host_to_origin_map_.end()) {
360 return AlternativeServiceVector(); 367 return AlternativeServiceVector();
361 } 368 }
362 map_it = alternative_service_map_.Get(canonical->second); 369 map_it = alternative_service_map_.Get(canonical->second);
363 if (map_it == alternative_service_map_.end()) { 370 if (map_it == alternative_service_map_.end()) {
364 return AlternativeServiceVector(); 371 return AlternativeServiceVector();
365 } 372 }
366 for (AlternativeServiceInfoVector::iterator it = map_it->second.begin(); 373 for (AlternativeServiceInfoVector::iterator it = map_it->second.begin();
367 it != map_it->second.end();) { 374 it != map_it->second.end();) {
368 if (it->expiration < now) { 375 if (it->expiration < now) {
369 it = map_it->second.erase(it); 376 it = map_it->second.erase(it);
370 continue; 377 continue;
371 } 378 }
379 if (it->probability < alternative_service_probability_threshold_) {
380 ++it;
381 continue;
382 }
372 AlternativeService alternative_service(it->alternative_service); 383 AlternativeService alternative_service(it->alternative_service);
373 if (alternative_service.host.empty()) { 384 if (alternative_service.host.empty()) {
374 alternative_service.host = canonical->second.host(); 385 alternative_service.host = canonical->second.host();
375 if (IsAlternativeServiceBroken(alternative_service)) { 386 if (IsAlternativeServiceBroken(alternative_service)) {
376 ++it; 387 ++it;
377 continue; 388 continue;
378 } 389 }
379 alternative_service.host = origin.host(); 390 alternative_service.host = origin.host();
380 } else if (IsAlternativeServiceBroken(alternative_service)) { 391 } else if (IsAlternativeServiceBroken(alternative_service)) {
381 ++it; 392 ++it;
382 continue; 393 continue;
383 } 394 }
384 valid_alternative_services.push_back(alternative_service); 395 alternative_services_above_threshold.push_back(alternative_service);
385 ++it; 396 ++it;
386 } 397 }
387 if (map_it->second.empty()) { 398 if (map_it->second.empty()) {
388 alternative_service_map_.Erase(map_it); 399 alternative_service_map_.Erase(map_it);
389 } 400 }
390 return valid_alternative_services; 401 return alternative_services_above_threshold;
391 } 402 }
392 403
393 bool HttpServerPropertiesImpl::SetAlternativeService( 404 bool HttpServerPropertiesImpl::SetAlternativeService(
394 const HostPortPair& origin, 405 const HostPortPair& origin,
395 const AlternativeService& alternative_service, 406 const AlternativeService& alternative_service,
407 double alternative_probability,
396 base::Time expiration) { 408 base::Time expiration) {
397 return SetAlternativeServices( 409 return SetAlternativeServices(
398 origin, 410 origin, AlternativeServiceInfoVector(
399 AlternativeServiceInfoVector( 411 /*size=*/1,
400 /*size=*/1, AlternativeServiceInfo(alternative_service, expiration))); 412 AlternativeServiceInfo(alternative_service,
413 alternative_probability, expiration)));
401 } 414 }
402 415
403 bool HttpServerPropertiesImpl::SetAlternativeServices( 416 bool HttpServerPropertiesImpl::SetAlternativeServices(
404 const HostPortPair& origin, 417 const HostPortPair& origin,
405 const AlternativeServiceInfoVector& alternative_service_info_vector) { 418 const AlternativeServiceInfoVector& alternative_service_info_vector) {
406 AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin); 419 AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin);
407 420
408 if (alternative_service_info_vector.empty()) { 421 if (alternative_service_info_vector.empty()) {
409 if (it == alternative_service_map_.end()) { 422 if (it == alternative_service_map_.end()) {
410 return false; 423 return false;
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 quic_server_info_map_.ShrinkToSize(max_server_configs_stored_in_properties_); 690 quic_server_info_map_.ShrinkToSize(max_server_configs_stored_in_properties_);
678 QuicServerInfoMap temp_map(max_server_configs_stored_in_properties_); 691 QuicServerInfoMap temp_map(max_server_configs_stored_in_properties_);
679 for (QuicServerInfoMap::reverse_iterator it = quic_server_info_map_.rbegin(); 692 for (QuicServerInfoMap::reverse_iterator it = quic_server_info_map_.rbegin();
680 it != quic_server_info_map_.rend(); ++it) { 693 it != quic_server_info_map_.rend(); ++it) {
681 temp_map.Put(it->first, it->second); 694 temp_map.Put(it->first, it->second);
682 } 695 }
683 696
684 quic_server_info_map_.Swap(temp_map); 697 quic_server_info_map_.Swap(temp_map);
685 } 698 }
686 699
700 void HttpServerPropertiesImpl::SetAlternativeServiceProbabilityThreshold(
701 double threshold) {
702 alternative_service_probability_threshold_ = threshold;
703 }
704
687 AlternativeServiceMap::const_iterator 705 AlternativeServiceMap::const_iterator
688 HttpServerPropertiesImpl::GetAlternateProtocolIterator( 706 HttpServerPropertiesImpl::GetAlternateProtocolIterator(
689 const HostPortPair& server) { 707 const HostPortPair& server) {
690 AlternativeServiceMap::const_iterator it = 708 AlternativeServiceMap::const_iterator it =
691 alternative_service_map_.Get(server); 709 alternative_service_map_.Get(server);
692 if (it != alternative_service_map_.end()) 710 if (it != alternative_service_map_.end())
693 return it; 711 return it;
694 712
695 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(server); 713 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(server);
696 if (canonical == canonical_host_to_origin_map_.end()) { 714 if (canonical == canonical_host_to_origin_map_.end()) {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
799 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); 817 base::TimeDelta delay = when > now ? when - now : base::TimeDelta();
800 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( 818 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask(
801 FROM_HERE, 819 FROM_HERE,
802 base::Bind( 820 base::Bind(
803 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, 821 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings,
804 weak_ptr_factory_.GetWeakPtr()), 822 weak_ptr_factory_.GetWeakPtr()),
805 delay); 823 delay);
806 } 824 }
807 825
808 } // namespace net 826 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties_impl.h ('k') | net/http/http_server_properties_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698