| 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> |
| 8 |
| 7 #include "base/bind.h" | 9 #include "base/bind.h" |
| 8 #include "base/location.h" | 10 #include "base/location.h" |
| 9 #include "base/logging.h" | 11 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 11 #include "base/single_thread_task_runner.h" | 13 #include "base/single_thread_task_runner.h" |
| 12 #include "base/stl_util.h" | 14 #include "base/stl_util.h" |
| 13 #include "base/strings/string_util.h" | 15 #include "base/strings/string_util.h" |
| 14 #include "base/strings/stringprintf.h" | 16 #include "base/strings/stringprintf.h" |
| 15 #include "base/thread_task_runner_handle.h" | 17 #include "base/thread_task_runner_handle.h" |
| 16 #include "base/values.h" | 18 #include "base/values.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 46 return; | 48 return; |
| 47 // Add the entries from persisted data. | 49 // Add the entries from persisted data. |
| 48 for (std::vector<std::string>::reverse_iterator it = spdy_servers->rbegin(); | 50 for (std::vector<std::string>::reverse_iterator it = spdy_servers->rbegin(); |
| 49 it != spdy_servers->rend(); ++it) { | 51 it != spdy_servers->rend(); ++it) { |
| 50 spdy_servers_map_.Put(*it, support_spdy); | 52 spdy_servers_map_.Put(*it, support_spdy); |
| 51 } | 53 } |
| 52 } | 54 } |
| 53 | 55 |
| 54 void HttpServerPropertiesImpl::InitializeAlternativeServiceServers( | 56 void HttpServerPropertiesImpl::InitializeAlternativeServiceServers( |
| 55 AlternativeServiceMap* alternative_service_map) { | 57 AlternativeServiceMap* alternative_service_map) { |
| 56 // Keep all the broken ones since those don't get persisted. | 58 for (AlternativeServiceMap::iterator map_it = |
| 57 for (AlternativeServiceMap::iterator it = alternative_service_map_.begin(); | 59 alternative_service_map_.begin(); |
| 58 it != alternative_service_map_.end();) { | 60 map_it != alternative_service_map_.end();) { |
| 59 AlternativeService alternative_service(it->second.alternative_service); | 61 for (AlternativeServiceInfoVector::iterator it = map_it->second.begin(); |
| 60 if (alternative_service.host.empty()) { | 62 it != map_it->second.end();) { |
| 61 alternative_service.host = it->first.host(); | 63 // Keep all the broken ones since those do not get persisted. |
| 64 AlternativeService alternative_service(it->alternative_service); |
| 65 if (alternative_service.host.empty()) { |
| 66 alternative_service.host = map_it->first.host(); |
| 67 } |
| 68 if (IsAlternativeServiceBroken(alternative_service)) { |
| 69 ++it; |
| 70 continue; |
| 71 } |
| 72 it = map_it->second.erase(it); |
| 62 } | 73 } |
| 63 if (IsAlternativeServiceBroken(alternative_service)) { | 74 if (map_it->second.empty()) { |
| 64 ++it; | 75 RemoveCanonicalHost(map_it->first); |
| 65 } else { | 76 map_it = alternative_service_map_.Erase(map_it); |
| 66 it = alternative_service_map_.Erase(it); | 77 continue; |
| 78 } |
| 79 ++map_it; |
| 80 } |
| 81 |
| 82 // Add the entries from persisted data. |
| 83 for (AlternativeServiceMap::reverse_iterator input_it = |
| 84 alternative_service_map->rbegin(); |
| 85 input_it != alternative_service_map->rend(); ++input_it) { |
| 86 AlternativeServiceMap::iterator output_it = |
| 87 alternative_service_map_.Peek(input_it->first); |
| 88 if (output_it == alternative_service_map_.end()) { |
| 89 // There is no value in alternative_service_map_ for input_it->first: |
| 90 // inserting in AlternativeServiceVectorInfo. |
| 91 alternative_service_map_.Put(input_it->first, input_it->second); |
| 92 continue; |
| 93 } |
| 94 // There are some broken alternative services in alternative_service_map_ |
| 95 // for input_it->first: appending AlternativeServiceInfo one by one. |
| 96 for (const AlternativeServiceInfo& alternative_service_info : |
| 97 input_it->second) { |
| 98 output_it->second.push_back(alternative_service_info); |
| 67 } | 99 } |
| 68 } | 100 } |
| 69 | 101 |
| 70 // Add the entries from persisted data. | |
| 71 for (AlternativeServiceMap::reverse_iterator it = | |
| 72 alternative_service_map->rbegin(); | |
| 73 it != alternative_service_map->rend(); ++it) { | |
| 74 alternative_service_map_.Put(it->first, it->second); | |
| 75 } | |
| 76 | |
| 77 // Attempt to find canonical servers. | 102 // Attempt to find canonical servers. |
| 78 uint16 canonical_ports[] = { 80, 443 }; | 103 uint16 canonical_ports[] = { 80, 443 }; |
| 79 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 104 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
| 80 std::string canonical_suffix = canonical_suffixes_[i]; | 105 std::string canonical_suffix = canonical_suffixes_[i]; |
| 81 for (size_t j = 0; j < arraysize(canonical_ports); ++j) { | 106 for (size_t j = 0; j < arraysize(canonical_ports); ++j) { |
| 82 HostPortPair canonical_host(canonical_suffix, canonical_ports[j]); | 107 HostPortPair canonical_host(canonical_suffix, canonical_ports[j]); |
| 83 // If we already have a valid canonical server, we're done. | 108 // If we already have a valid canonical server, we're done. |
| 84 if (ContainsKey(canonical_host_to_origin_map_, canonical_host) && | 109 if (ContainsKey(canonical_host_to_origin_map_, canonical_host) && |
| 85 (alternative_service_map_.Peek( | 110 (alternative_service_map_.Peek( |
| 86 canonical_host_to_origin_map_[canonical_host]) != | 111 canonical_host_to_origin_map_[canonical_host]) != |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 183 |
| 159 bool HttpServerPropertiesImpl::SupportsRequestPriority( | 184 bool HttpServerPropertiesImpl::SupportsRequestPriority( |
| 160 const HostPortPair& host_port_pair) { | 185 const HostPortPair& host_port_pair) { |
| 161 DCHECK(CalledOnValidThread()); | 186 DCHECK(CalledOnValidThread()); |
| 162 if (host_port_pair.host().empty()) | 187 if (host_port_pair.host().empty()) |
| 163 return false; | 188 return false; |
| 164 | 189 |
| 165 if (GetSupportsSpdy(host_port_pair)) | 190 if (GetSupportsSpdy(host_port_pair)) |
| 166 return true; | 191 return true; |
| 167 | 192 |
| 168 const AlternativeService alternative_service = | 193 const AlternativeServiceVector alternative_service_vector = |
| 169 GetAlternativeService(host_port_pair); | 194 GetAlternativeServices(host_port_pair); |
| 170 return alternative_service.protocol == QUIC; | 195 for (const AlternativeService& alternative_service : |
| 196 alternative_service_vector) { |
| 197 if (alternative_service.protocol == QUIC) { |
| 198 return true; |
| 199 } |
| 200 } |
| 201 return false; |
| 171 } | 202 } |
| 172 | 203 |
| 173 bool HttpServerPropertiesImpl::GetSupportsSpdy( | 204 bool HttpServerPropertiesImpl::GetSupportsSpdy( |
| 174 const HostPortPair& host_port_pair) { | 205 const HostPortPair& host_port_pair) { |
| 175 DCHECK(CalledOnValidThread()); | 206 DCHECK(CalledOnValidThread()); |
| 176 if (host_port_pair.host().empty()) | 207 if (host_port_pair.host().empty()) |
| 177 return false; | 208 return false; |
| 178 | 209 |
| 179 SpdyServerHostPortMap::iterator spdy_host_port = | 210 SpdyServerHostPortMap::iterator spdy_host_port = |
| 180 spdy_servers_map_.Get(host_port_pair.ToString()); | 211 spdy_servers_map_.Get(host_port_pair.ToString()); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 // suffix. | 260 // suffix. |
| 230 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 261 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
| 231 std::string canonical_suffix = canonical_suffixes_[i]; | 262 std::string canonical_suffix = canonical_suffixes_[i]; |
| 232 if (base::EndsWith(host, canonical_suffixes_[i], false)) { | 263 if (base::EndsWith(host, canonical_suffixes_[i], false)) { |
| 233 return canonical_suffix; | 264 return canonical_suffix; |
| 234 } | 265 } |
| 235 } | 266 } |
| 236 return std::string(); | 267 return std::string(); |
| 237 } | 268 } |
| 238 | 269 |
| 239 AlternativeService HttpServerPropertiesImpl::GetAlternativeService( | 270 AlternativeServiceVector HttpServerPropertiesImpl::GetAlternativeServices( |
| 240 const HostPortPair& origin) { | 271 const HostPortPair& origin) { |
| 272 // Copy alternative services with probability greater than or equal to the |
| 273 // threshold into |alternative_services_above_threshold|. |
| 274 AlternativeServiceVector alternative_services_above_threshold; |
| 241 AlternativeServiceMap::const_iterator it = | 275 AlternativeServiceMap::const_iterator it = |
| 242 alternative_service_map_.Get(origin); | 276 alternative_service_map_.Get(origin); |
| 243 if (it != alternative_service_map_.end()) { | 277 if (it != alternative_service_map_.end()) { |
| 244 if (it->second.probability < alternative_service_probability_threshold_) { | 278 for (const AlternativeServiceInfo& alternative_service_info : it->second) { |
| 245 return AlternativeService(); | 279 if (alternative_service_info.probability < |
| 280 alternative_service_probability_threshold_) { |
| 281 continue; |
| 282 } |
| 283 AlternativeService alternative_service( |
| 284 alternative_service_info.alternative_service); |
| 285 if (alternative_service.host.empty()) { |
| 286 alternative_service.host = origin.host(); |
| 287 } |
| 288 alternative_services_above_threshold.push_back(alternative_service); |
| 246 } | 289 } |
| 247 AlternativeService alternative_service(it->second.alternative_service); | 290 return alternative_services_above_threshold; |
| 248 if (alternative_service.host.empty()) { | |
| 249 alternative_service.host = origin.host(); | |
| 250 } | |
| 251 return alternative_service; | |
| 252 } | 291 } |
| 253 | 292 |
| 254 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(origin); | 293 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(origin); |
| 255 if (canonical == canonical_host_to_origin_map_.end()) { | 294 if (canonical == canonical_host_to_origin_map_.end()) { |
| 256 return AlternativeService(); | 295 return AlternativeServiceVector(); |
| 257 } | 296 } |
| 258 it = alternative_service_map_.Get(canonical->second); | 297 it = alternative_service_map_.Get(canonical->second); |
| 259 if (it == alternative_service_map_.end()) { | 298 if (it == alternative_service_map_.end()) { |
| 260 return AlternativeService(); | 299 return AlternativeServiceVector(); |
| 261 } | 300 } |
| 262 if (it->second.probability < alternative_service_probability_threshold_) { | 301 for (const AlternativeServiceInfo& alternative_service_info : it->second) { |
| 263 return AlternativeService(); | 302 if (alternative_service_info.probability < |
| 303 alternative_service_probability_threshold_) { |
| 304 continue; |
| 305 } |
| 306 AlternativeService alternative_service( |
| 307 alternative_service_info.alternative_service); |
| 308 if (alternative_service.host.empty()) { |
| 309 alternative_service.host = canonical->second.host(); |
| 310 if (IsAlternativeServiceBroken(alternative_service)) { |
| 311 continue; |
| 312 } |
| 313 alternative_service.host = origin.host(); |
| 314 } else if (IsAlternativeServiceBroken(alternative_service)) { |
| 315 continue; |
| 316 } |
| 317 alternative_services_above_threshold.push_back(alternative_service); |
| 264 } | 318 } |
| 265 AlternativeService alternative_service(it->second.alternative_service); | 319 return alternative_services_above_threshold; |
| 266 if (alternative_service.host.empty()) { | |
| 267 alternative_service.host = canonical->second.host(); | |
| 268 } | |
| 269 if (IsAlternativeServiceBroken(alternative_service)) { | |
| 270 RemoveCanonicalHost(canonical->second); | |
| 271 return AlternativeService(); | |
| 272 } | |
| 273 // Empty hostname: if alternative service for with hostname of canonical host | |
| 274 // is not broken, then return alternative service with hostname of origin. | |
| 275 if (it->second.alternative_service.host.empty()) { | |
| 276 alternative_service.host = origin.host(); | |
| 277 } | |
| 278 return alternative_service; | |
| 279 } | 320 } |
| 280 | 321 |
| 281 void HttpServerPropertiesImpl::SetAlternativeService( | 322 bool HttpServerPropertiesImpl::SetAlternativeService( |
| 282 const HostPortPair& origin, | 323 const HostPortPair& origin, |
| 283 const AlternativeService& alternative_service, | 324 const AlternativeService& alternative_service, |
| 284 double alternative_probability) { | 325 double alternative_probability) { |
| 285 const AlternativeServiceInfo alternative_service_info( | 326 return SetAlternativeServices( |
| 286 alternative_service, alternative_probability); | 327 origin, AlternativeServiceInfoVector( |
| 287 AlternativeServiceMap::const_iterator it = | 328 /*size=*/1, AlternativeServiceInfo(alternative_service, |
| 288 GetAlternateProtocolIterator(origin); | 329 alternative_probability))); |
| 289 if (it == alternative_service_map_.end() && | 330 } |
| 290 alternative_probability >= alternative_service_probability_threshold_) { | 331 |
| 332 bool HttpServerPropertiesImpl::SetAlternativeServices( |
| 333 const HostPortPair& origin, |
| 334 const AlternativeServiceInfoVector& alternative_service_info_vector) { |
| 335 AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin); |
| 336 |
| 337 if (alternative_service_info_vector.empty()) { |
| 338 if (it == alternative_service_map_.end()) { |
| 339 return false; |
| 340 } |
| 341 ClearAlternativeServices(origin); |
| 342 return true; |
| 343 } |
| 344 |
| 345 bool changed = true; |
| 346 if (it != alternative_service_map_.end()) { |
| 347 DCHECK(!it->second.empty()); |
| 348 if (it->second.size() == alternative_service_info_vector.size()) { |
| 349 changed = !std::equal(it->second.begin(), it->second.end(), |
| 350 alternative_service_info_vector.begin()); |
| 351 } |
| 352 } |
| 353 |
| 354 const bool previously_no_alternative_services = |
| 355 (GetAlternateProtocolIterator(origin) == alternative_service_map_.end()); |
| 356 |
| 357 alternative_service_map_.Put(origin, alternative_service_info_vector); |
| 358 |
| 359 if (previously_no_alternative_services && |
| 360 !GetAlternativeServices(origin).empty()) { |
| 291 // TODO(rch): Consider the case where multiple requests are started | 361 // TODO(rch): Consider the case where multiple requests are started |
| 292 // before the first completes. In this case, only one of the jobs | 362 // before the first completes. In this case, only one of the jobs |
| 293 // would reach this code, whereas all of them should should have. | 363 // would reach this code, whereas all of them should should have. |
| 294 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING); | 364 HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING); |
| 295 } | 365 } |
| 296 | 366 |
| 297 alternative_service_map_.Put(origin, alternative_service_info); | |
| 298 | |
| 299 // If this host ends with a canonical suffix, then set it as the | 367 // If this host ends with a canonical suffix, then set it as the |
| 300 // canonical host. | 368 // canonical host. |
| 301 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 369 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
| 302 std::string canonical_suffix = canonical_suffixes_[i]; | 370 std::string canonical_suffix = canonical_suffixes_[i]; |
| 303 if (base::EndsWith(origin.host(), canonical_suffixes_[i], false)) { | 371 if (base::EndsWith(origin.host(), canonical_suffixes_[i], false)) { |
| 304 HostPortPair canonical_host(canonical_suffix, origin.port()); | 372 HostPortPair canonical_host(canonical_suffix, origin.port()); |
| 305 canonical_host_to_origin_map_[canonical_host] = origin; | 373 canonical_host_to_origin_map_[canonical_host] = origin; |
| 306 break; | 374 break; |
| 307 } | 375 } |
| 308 } | 376 } |
| 377 |
| 378 return changed; |
| 309 } | 379 } |
| 310 | 380 |
| 311 void HttpServerPropertiesImpl::MarkAlternativeServiceBroken( | 381 void HttpServerPropertiesImpl::MarkAlternativeServiceBroken( |
| 312 const AlternativeService& alternative_service) { | 382 const AlternativeService& alternative_service) { |
| 313 // Empty host means use host of origin, callers are supposed to substitute. | 383 // Empty host means use host of origin, callers are supposed to substitute. |
| 314 DCHECK(!alternative_service.host.empty()); | 384 DCHECK(!alternative_service.host.empty()); |
| 315 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { | 385 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) { |
| 316 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; | 386 LOG(DFATAL) << "Trying to mark unknown alternate protocol broken."; |
| 317 return; | 387 return; |
| 318 } | 388 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 } | 426 } |
| 357 | 427 |
| 358 void HttpServerPropertiesImpl::ConfirmAlternativeService( | 428 void HttpServerPropertiesImpl::ConfirmAlternativeService( |
| 359 const AlternativeService& alternative_service) { | 429 const AlternativeService& alternative_service) { |
| 360 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) | 430 if (alternative_service.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL) |
| 361 return; | 431 return; |
| 362 broken_alternative_services_.erase(alternative_service); | 432 broken_alternative_services_.erase(alternative_service); |
| 363 recently_broken_alternative_services_.erase(alternative_service); | 433 recently_broken_alternative_services_.erase(alternative_service); |
| 364 } | 434 } |
| 365 | 435 |
| 366 void HttpServerPropertiesImpl::ClearAlternativeService( | 436 void HttpServerPropertiesImpl::ClearAlternativeServices( |
| 367 const HostPortPair& origin) { | 437 const HostPortPair& origin) { |
| 368 RemoveCanonicalHost(origin); | 438 RemoveCanonicalHost(origin); |
| 369 | 439 |
| 370 AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin); | 440 AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin); |
| 371 if (it == alternative_service_map_.end()) { | 441 if (it == alternative_service_map_.end()) { |
| 372 return; | 442 return; |
| 373 } | 443 } |
| 374 alternative_service_map_.Erase(it); | 444 alternative_service_map_.Erase(it); |
| 375 } | 445 } |
| 376 | 446 |
| 377 const AlternativeServiceMap& HttpServerPropertiesImpl::alternative_service_map() | 447 const AlternativeServiceMap& HttpServerPropertiesImpl::alternative_service_map() |
| 378 const { | 448 const { |
| 379 return alternative_service_map_; | 449 return alternative_service_map_; |
| 380 } | 450 } |
| 381 | 451 |
| 382 scoped_ptr<base::Value> | 452 scoped_ptr<base::Value> |
| 383 HttpServerPropertiesImpl::GetAlternativeServiceInfoAsValue() | 453 HttpServerPropertiesImpl::GetAlternativeServiceInfoAsValue() |
| 384 const { | 454 const { |
| 385 scoped_ptr<base::ListValue> dict_list(new base::ListValue()); | 455 scoped_ptr<base::ListValue> dict_list(new base::ListValue); |
| 386 for (const auto& alternative_service_map_item : alternative_service_map_) { | 456 for (const auto& alternative_service_map_item : alternative_service_map_) { |
| 457 scoped_ptr<base::ListValue> alternative_service_list(new base::ListValue); |
| 387 const HostPortPair& host_port_pair = alternative_service_map_item.first; | 458 const HostPortPair& host_port_pair = alternative_service_map_item.first; |
| 388 const AlternativeServiceInfo& alternative_service_info = | 459 for (const AlternativeServiceInfo& alternative_service_info : |
| 389 alternative_service_map_item.second; | 460 alternative_service_map_item.second) { |
| 390 std::string alternative_service_string(alternative_service_info.ToString()); | 461 std::string alternative_service_string( |
| 391 AlternativeService alternative_service( | 462 alternative_service_info.ToString()); |
| 392 alternative_service_info.alternative_service); | 463 AlternativeService alternative_service( |
| 393 if (alternative_service.host.empty()) { | 464 alternative_service_info.alternative_service); |
| 394 alternative_service.host = host_port_pair.host(); | 465 if (alternative_service.host.empty()) { |
| 466 alternative_service.host = host_port_pair.host(); |
| 467 } |
| 468 if (IsAlternativeServiceBroken(alternative_service)) { |
| 469 alternative_service_string.append(" (broken)"); |
| 470 } |
| 471 alternative_service_list->Append( |
| 472 new base::StringValue(alternative_service_string)); |
| 395 } | 473 } |
| 396 if (IsAlternativeServiceBroken(alternative_service)) { | 474 if (alternative_service_list->empty()) |
| 397 alternative_service_string.append(" (broken)"); | 475 continue; |
| 398 } | |
| 399 | |
| 400 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 476 scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 401 dict->SetString("host_port_pair", host_port_pair.ToString()); | 477 dict->SetString("host_port_pair", host_port_pair.ToString()); |
| 402 dict->SetString("alternative_service", alternative_service_string); | 478 dict->Set("alternative_service", |
| 479 scoped_ptr<base::Value>(alternative_service_list.Pass())); |
| 403 dict_list->Append(dict.Pass()); | 480 dict_list->Append(dict.Pass()); |
| 404 } | 481 } |
| 405 return dict_list.Pass(); | 482 return dict_list.Pass(); |
| 406 } | 483 } |
| 407 | 484 |
| 408 const SettingsMap& HttpServerPropertiesImpl::GetSpdySettings( | 485 const SettingsMap& HttpServerPropertiesImpl::GetSpdySettings( |
| 409 const HostPortPair& host_port_pair) { | 486 const HostPortPair& host_port_pair) { |
| 410 SpdySettingsMap::iterator it = spdy_settings_map_.Get(host_port_pair); | 487 SpdySettingsMap::iterator it = spdy_settings_map_.Get(host_port_pair); |
| 411 if (it == spdy_settings_map_.end()) { | 488 if (it == spdy_settings_map_.end()) { |
| 412 CR_DEFINE_STATIC_LOCAL(SettingsMap, kEmptySettingsMap, ()); | 489 CR_DEFINE_STATIC_LOCAL(SettingsMap, kEmptySettingsMap, ()); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 508 if (canonical == canonical_host_to_origin_map_.end()) { | 585 if (canonical == canonical_host_to_origin_map_.end()) { |
| 509 return alternative_service_map_.end(); | 586 return alternative_service_map_.end(); |
| 510 } | 587 } |
| 511 | 588 |
| 512 const HostPortPair canonical_host_port = canonical->second; | 589 const HostPortPair canonical_host_port = canonical->second; |
| 513 it = alternative_service_map_.Get(canonical_host_port); | 590 it = alternative_service_map_.Get(canonical_host_port); |
| 514 if (it == alternative_service_map_.end()) { | 591 if (it == alternative_service_map_.end()) { |
| 515 return alternative_service_map_.end(); | 592 return alternative_service_map_.end(); |
| 516 } | 593 } |
| 517 | 594 |
| 518 const AlternativeService alternative_service( | 595 for (const AlternativeServiceInfo& alternative_service_info : it->second) { |
| 519 it->second.alternative_service.protocol, canonical_host_port.host(), | 596 AlternativeService alternative_service( |
| 520 it->second.alternative_service.port); | 597 alternative_service_info.alternative_service); |
| 521 if (!IsAlternativeServiceBroken(alternative_service)) { | 598 if (alternative_service.host.empty()) { |
| 522 return it; | 599 alternative_service.host = canonical_host_port.host(); |
| 600 } |
| 601 if (!IsAlternativeServiceBroken(alternative_service)) { |
| 602 return it; |
| 603 } |
| 523 } | 604 } |
| 524 | 605 |
| 525 RemoveCanonicalHost(canonical_host_port); | 606 RemoveCanonicalHost(canonical_host_port); |
| 526 return alternative_service_map_.end(); | 607 return alternative_service_map_.end(); |
| 527 } | 608 } |
| 528 | 609 |
| 529 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator | 610 HttpServerPropertiesImpl::CanonicalHostMap::const_iterator |
| 530 HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const { | 611 HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const { |
| 531 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { | 612 for (size_t i = 0; i < canonical_suffixes_.size(); ++i) { |
| 532 std::string canonical_suffix = canonical_suffixes_[i]; | 613 std::string canonical_suffix = canonical_suffixes_[i]; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 556 while (!broken_alternative_services_.empty()) { | 637 while (!broken_alternative_services_.empty()) { |
| 557 BrokenAlternativeServices::iterator it = | 638 BrokenAlternativeServices::iterator it = |
| 558 broken_alternative_services_.begin(); | 639 broken_alternative_services_.begin(); |
| 559 if (now < it->second) { | 640 if (now < it->second) { |
| 560 break; | 641 break; |
| 561 } | 642 } |
| 562 | 643 |
| 563 const AlternativeService alternative_service = it->first; | 644 const AlternativeService alternative_service = it->first; |
| 564 broken_alternative_services_.erase(it); | 645 broken_alternative_services_.erase(it); |
| 565 // TODO(bnc): Make sure broken alternative services are not in the mapping. | 646 // TODO(bnc): Make sure broken alternative services are not in the mapping. |
| 566 ClearAlternativeService( | 647 ClearAlternativeServices( |
| 567 HostPortPair(alternative_service.host, alternative_service.port)); | 648 HostPortPair(alternative_service.host, alternative_service.port)); |
| 568 } | 649 } |
| 569 ScheduleBrokenAlternateProtocolMappingsExpiration(); | 650 ScheduleBrokenAlternateProtocolMappingsExpiration(); |
| 570 } | 651 } |
| 571 | 652 |
| 572 void | 653 void |
| 573 HttpServerPropertiesImpl::ScheduleBrokenAlternateProtocolMappingsExpiration() { | 654 HttpServerPropertiesImpl::ScheduleBrokenAlternateProtocolMappingsExpiration() { |
| 574 if (broken_alternative_services_.empty()) { | 655 if (broken_alternative_services_.empty()) { |
| 575 return; | 656 return; |
| 576 } | 657 } |
| 577 base::TimeTicks now = base::TimeTicks::Now(); | 658 base::TimeTicks now = base::TimeTicks::Now(); |
| 578 base::TimeTicks when = broken_alternative_services_.front().second; | 659 base::TimeTicks when = broken_alternative_services_.front().second; |
| 579 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); | 660 base::TimeDelta delay = when > now ? when - now : base::TimeDelta(); |
| 580 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( | 661 base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| 581 FROM_HERE, | 662 FROM_HERE, |
| 582 base::Bind( | 663 base::Bind( |
| 583 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, | 664 &HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings, |
| 584 weak_ptr_factory_.GetWeakPtr()), | 665 weak_ptr_factory_.GetWeakPtr()), |
| 585 delay); | 666 delay); |
| 586 } | 667 } |
| 587 | 668 |
| 588 } // namespace net | 669 } // namespace net |
| OLD | NEW |