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 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 } | 215 } |
| 216 | 216 |
| 217 bool HttpServerPropertiesImpl::SupportsRequestPriority( | 217 bool HttpServerPropertiesImpl::SupportsRequestPriority( |
| 218 const url::SchemeHostPort& server) { | 218 const url::SchemeHostPort& server) { |
| 219 DCHECK(CalledOnValidThread()); | 219 DCHECK(CalledOnValidThread()); |
| 220 if (server.host().empty()) | 220 if (server.host().empty()) |
| 221 return false; | 221 return false; |
| 222 | 222 |
| 223 if (GetSupportsSpdy(server)) | 223 if (GetSupportsSpdy(server)) |
| 224 return true; | 224 return true; |
| 225 const AlternativeServiceVector alternative_service_vector = | 225 const AlternativeServiceInfoVector alternative_service_info_vector = |
| 226 GetAlternativeServices(server); | 226 GetAlternativeServiceInfos(server); |
| 227 for (const AlternativeService& alternative_service : | 227 for (const AlternativeServiceInfo& alternative_service_info : |
| 228 alternative_service_vector) { | 228 alternative_service_info_vector) { |
| 229 if (alternative_service.protocol == kProtoQUIC) { | 229 if (alternative_service_info.alternative_service.protocol == kProtoQUIC) { |
| 230 return true; | 230 return true; |
| 231 } | 231 } |
| 232 } | 232 } |
| 233 return false; | 233 return false; |
| 234 } | 234 } |
| 235 | 235 |
| 236 bool HttpServerPropertiesImpl::GetSupportsSpdy( | 236 bool HttpServerPropertiesImpl::GetSupportsSpdy( |
| 237 const url::SchemeHostPort& server) { | 237 const url::SchemeHostPort& server) { |
| 238 DCHECK(CalledOnValidThread()); | 238 DCHECK(CalledOnValidThread()); |
| 239 if (server.host().empty()) | 239 if (server.host().empty()) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 292 // suffix. | 292 // suffix. |
| 293 for (const std::string& canonical_suffix : canonical_suffixes_) { | 293 for (const std::string& canonical_suffix : canonical_suffixes_) { |
| 294 if (base::EndsWith(host, canonical_suffix, | 294 if (base::EndsWith(host, canonical_suffix, |
| 295 base::CompareCase::INSENSITIVE_ASCII)) { | 295 base::CompareCase::INSENSITIVE_ASCII)) { |
| 296 return &canonical_suffix; | 296 return &canonical_suffix; |
| 297 } | 297 } |
| 298 } | 298 } |
| 299 return nullptr; | 299 return nullptr; |
| 300 } | 300 } |
| 301 | 301 |
| 302 AlternativeServiceVector HttpServerPropertiesImpl::GetAlternativeServices( | 302 AlternativeServiceInfoVector |
| 303 HttpServerPropertiesImpl::GetAlternativeServiceInfos( | |
| 303 const url::SchemeHostPort& origin) { | 304 const url::SchemeHostPort& origin) { |
| 304 // Copy valid alternative services into |valid_alternative_services|. | 305 // Copy valid alternative service infos into |
| 305 AlternativeServiceVector valid_alternative_services; | 306 // |valid_alternative_service_infos|. |
| 307 AlternativeServiceInfoVector valid_alternative_service_infos; | |
| 306 const base::Time now = base::Time::Now(); | 308 const base::Time now = base::Time::Now(); |
| 307 AlternativeServiceMap::iterator map_it = alternative_service_map_.Get(origin); | 309 AlternativeServiceMap::iterator map_it = alternative_service_map_.Get(origin); |
| 308 if (map_it != alternative_service_map_.end()) { | 310 if (map_it != alternative_service_map_.end()) { |
| 309 HostPortPair host_port_pair(origin.host(), origin.port()); | 311 HostPortPair host_port_pair(origin.host(), origin.port()); |
| 310 for (AlternativeServiceInfoVector::iterator it = map_it->second.begin(); | 312 for (AlternativeServiceInfoVector::iterator it = map_it->second.begin(); |
| 311 it != map_it->second.end();) { | 313 it != map_it->second.end();) { |
| 312 if (it->expiration < now) { | 314 if (it->expiration < now) { |
| 313 it = map_it->second.erase(it); | 315 it = map_it->second.erase(it); |
| 314 continue; | 316 continue; |
| 315 } | 317 } |
| 316 AlternativeService alternative_service(it->alternative_service); | 318 AlternativeService alternative_service(it->alternative_service); |
| 317 if (alternative_service.host.empty()) { | 319 if (alternative_service.host.empty()) { |
| 318 alternative_service.host = origin.host(); | 320 alternative_service.host = origin.host(); |
| 319 } | 321 } |
| 320 // 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 |
| 321 // port, and both TCP), skip it. | 323 // port, and both TCP), skip it. |
| 322 if (host_port_pair.Equals(alternative_service.host_port_pair()) && | 324 if (host_port_pair.Equals(alternative_service.host_port_pair()) && |
| 323 alternative_service.protocol == kProtoHTTP2) { | 325 alternative_service.protocol == kProtoHTTP2) { |
| 324 ++it; | 326 ++it; |
| 325 continue; | 327 continue; |
| 326 } | 328 } |
| 327 valid_alternative_services.push_back(alternative_service); | 329 valid_alternative_service_infos.push_back( |
| 330 AlternativeServiceInfo(alternative_service, it->expiration)); | |
|
Ryan Hamilton
2017/05/18 17:45:33
Can you just push_back(*it)?
Zhongyi Shi
2017/05/18 19:24:38
Unfortunately, I couldn't. If the it->alternative_
Ryan Hamilton
2017/05/18 19:59:46
Ah, yes. Good point.
| |
| 328 ++it; | 331 ++it; |
| 329 } | 332 } |
| 330 if (map_it->second.empty()) { | 333 if (map_it->second.empty()) { |
| 331 alternative_service_map_.Erase(map_it); | 334 alternative_service_map_.Erase(map_it); |
| 332 } | 335 } |
| 333 return valid_alternative_services; | 336 return valid_alternative_service_infos; |
| 334 } | 337 } |
| 335 | 338 |
| 336 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(origin); | 339 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(origin); |
| 337 if (canonical == canonical_host_to_origin_map_.end()) { | 340 if (canonical == canonical_host_to_origin_map_.end()) { |
| 338 return AlternativeServiceVector(); | 341 return AlternativeServiceInfoVector(); |
| 339 } | 342 } |
| 340 map_it = alternative_service_map_.Get(canonical->second); | 343 map_it = alternative_service_map_.Get(canonical->second); |
| 341 if (map_it == alternative_service_map_.end()) { | 344 if (map_it == alternative_service_map_.end()) { |
| 342 return AlternativeServiceVector(); | 345 return AlternativeServiceInfoVector(); |
| 343 } | 346 } |
| 344 for (AlternativeServiceInfoVector::iterator it = map_it->second.begin(); | 347 for (AlternativeServiceInfoVector::iterator it = map_it->second.begin(); |
| 345 it != map_it->second.end();) { | 348 it != map_it->second.end();) { |
| 346 if (it->expiration < now) { | 349 if (it->expiration < now) { |
| 347 it = map_it->second.erase(it); | 350 it = map_it->second.erase(it); |
| 348 continue; | 351 continue; |
| 349 } | 352 } |
| 350 AlternativeService alternative_service(it->alternative_service); | 353 AlternativeService alternative_service(it->alternative_service); |
| 351 if (alternative_service.host.empty()) { | 354 if (alternative_service.host.empty()) { |
| 352 alternative_service.host = canonical->second.host(); | 355 alternative_service.host = canonical->second.host(); |
| 353 if (IsAlternativeServiceBroken(alternative_service)) { | 356 if (IsAlternativeServiceBroken(alternative_service)) { |
| 354 ++it; | 357 ++it; |
| 355 continue; | 358 continue; |
| 356 } | 359 } |
| 357 alternative_service.host = origin.host(); | 360 alternative_service.host = origin.host(); |
| 358 } else if (IsAlternativeServiceBroken(alternative_service)) { | 361 } else if (IsAlternativeServiceBroken(alternative_service)) { |
| 359 ++it; | 362 ++it; |
| 360 continue; | 363 continue; |
| 361 } | 364 } |
| 362 valid_alternative_services.push_back(alternative_service); | 365 valid_alternative_service_infos.push_back( |
| 366 AlternativeServiceInfo(alternative_service, it->expiration)); | |
| 363 ++it; | 367 ++it; |
| 364 } | 368 } |
| 365 if (map_it->second.empty()) { | 369 if (map_it->second.empty()) { |
| 366 alternative_service_map_.Erase(map_it); | 370 alternative_service_map_.Erase(map_it); |
| 367 } | 371 } |
| 368 return valid_alternative_services; | 372 return valid_alternative_service_infos; |
| 369 } | 373 } |
| 370 | 374 |
| 371 bool HttpServerPropertiesImpl::SetAlternativeService( | 375 bool HttpServerPropertiesImpl::SetAlternativeService( |
| 372 const url::SchemeHostPort& origin, | 376 const url::SchemeHostPort& origin, |
| 373 const AlternativeService& alternative_service, | 377 const AlternativeService& alternative_service, |
| 374 base::Time expiration) { | 378 base::Time expiration) { |
| 375 return SetAlternativeServices( | 379 return SetAlternativeServices( |
| 376 origin, | 380 origin, |
| 377 AlternativeServiceInfoVector( | 381 AlternativeServiceInfoVector( |
| 378 /*size=*/1, AlternativeServiceInfo(alternative_service, expiration))); | 382 /*size=*/1, AlternativeServiceInfo(alternative_service, expiration))); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 419 } | 423 } |
| 420 } | 424 } |
| 421 } | 425 } |
| 422 | 426 |
| 423 const bool previously_no_alternative_services = | 427 const bool previously_no_alternative_services = |
| 424 (GetAlternateProtocolIterator(origin) == alternative_service_map_.end()); | 428 (GetAlternateProtocolIterator(origin) == alternative_service_map_.end()); |
| 425 | 429 |
| 426 alternative_service_map_.Put(origin, alternative_service_info_vector); | 430 alternative_service_map_.Put(origin, alternative_service_info_vector); |
| 427 | 431 |
| 428 if (previously_no_alternative_services && | 432 if (previously_no_alternative_services && |
| 429 !GetAlternativeServices(origin).empty()) { | 433 !GetAlternativeServiceInfos(origin).empty()) { |
| 430 // TODO(rch): Consider the case where multiple requests are started | 434 // TODO(rch): Consider the case where multiple requests are started |
| 431 // before the first completes. In this case, only one of the jobs | 435 // before the first completes. In this case, only one of the jobs |
| 432 // would reach this code, whereas all of them should should have. | 436 // would reach this code, whereas all of them should should have. |
| 433 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING, | 437 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING, |
| 434 false); | 438 false); |
| 435 } | 439 } |
| 436 | 440 |
| 437 // If this host ends with a canonical suffix, then set it as the | 441 // If this host ends with a canonical suffix, then set it as the |
| 438 // canonical host. | 442 // canonical host. |
| 439 const char* kCanonicalScheme = "https"; | 443 const char* kCanonicalScheme = "https"; |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 763 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 767 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
| 764 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 768 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 765 FROM_HERE, | 769 FROM_HERE, |
| 766 base::Bind( | 770 base::Bind( |
| 767 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 771 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
| 768 weak_ptr_factory_.GetWeakPtr()), | 772 weak_ptr_factory_.GetWeakPtr()), |
| 769 delay); | 773 delay); |
| 770 } | 774 } |
| 771 | 775 |
| 772 } // namespace net | 776 } // namespace net |
| OLD | NEW |