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

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

Issue 2932503005: Change AlternativeServiceInfo to a class (Closed)
Patch Set: Created 3 years, 6 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
« no previous file with comments | « net/http/http_server_properties.cc ('k') | net/http/http_server_properties_impl_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); 212 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
213 if (server.host().empty()) 213 if (server.host().empty())
214 return false; 214 return false;
215 215
216 if (GetSupportsSpdy(server)) 216 if (GetSupportsSpdy(server))
217 return true; 217 return true;
218 const AlternativeServiceInfoVector alternative_service_info_vector = 218 const AlternativeServiceInfoVector alternative_service_info_vector =
219 GetAlternativeServiceInfos(server); 219 GetAlternativeServiceInfos(server);
220 for (const AlternativeServiceInfo& alternative_service_info : 220 for (const AlternativeServiceInfo& alternative_service_info :
221 alternative_service_info_vector) { 221 alternative_service_info_vector) {
222 if (alternative_service_info.alternative_service.protocol == kProtoQUIC) { 222 if (alternative_service_info.alternative_service().protocol == kProtoQUIC) {
223 return true; 223 return true;
224 } 224 }
225 } 225 }
226 return false; 226 return false;
227 } 227 }
228 228
229 bool HttpServerPropertiesImpl::GetSupportsSpdy( 229 bool HttpServerPropertiesImpl::GetSupportsSpdy(
230 const url::SchemeHostPort& server) { 230 const url::SchemeHostPort& server) {
231 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_); 231 DCHECK_CALLED_ON_VALID_THREAD(thread_checker_);
232 if (server.host().empty()) 232 if (server.host().empty())
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 const url::SchemeHostPort& origin) { 297 const url::SchemeHostPort& origin) {
298 // Copy valid alternative service infos into 298 // Copy valid alternative service infos into
299 // |valid_alternative_service_infos|. 299 // |valid_alternative_service_infos|.
300 AlternativeServiceInfoVector valid_alternative_service_infos; 300 AlternativeServiceInfoVector valid_alternative_service_infos;
301 const base::Time now = base::Time::Now(); 301 const base::Time now = base::Time::Now();
302 AlternativeServiceMap::iterator map_it = alternative_service_map_.Get(origin); 302 AlternativeServiceMap::iterator map_it = alternative_service_map_.Get(origin);
303 if (map_it != alternative_service_map_.end()) { 303 if (map_it != alternative_service_map_.end()) {
304 HostPortPair host_port_pair(origin.host(), origin.port()); 304 HostPortPair host_port_pair(origin.host(), origin.port());
305 for (AlternativeServiceInfoVector::iterator it = map_it->second.begin(); 305 for (AlternativeServiceInfoVector::iterator it = map_it->second.begin();
306 it != map_it->second.end();) { 306 it != map_it->second.end();) {
307 if (it->expiration < now) { 307 if (it->expiration() < now) {
308 it = map_it->second.erase(it); 308 it = map_it->second.erase(it);
309 continue; 309 continue;
310 } 310 }
311 AlternativeService alternative_service(it->alternative_service); 311 AlternativeService alternative_service(it->alternative_service());
312 if (alternative_service.host.empty()) { 312 if (alternative_service.host.empty()) {
313 alternative_service.host = origin.host(); 313 alternative_service.host = origin.host();
314 } 314 }
315 // If the alternative service is equivalent to the origin (same host, same 315 // If the alternative service is equivalent to the origin (same host, same
316 // port, and both TCP), skip it. 316 // port, and both TCP), skip it.
317 if (host_port_pair.Equals(alternative_service.host_port_pair()) && 317 if (host_port_pair.Equals(alternative_service.host_port_pair()) &&
318 alternative_service.protocol == kProtoHTTP2) { 318 alternative_service.protocol == kProtoHTTP2) {
319 ++it; 319 ++it;
320 continue; 320 continue;
321 } 321 }
322 valid_alternative_service_infos.push_back( 322 valid_alternative_service_infos.push_back(
323 AlternativeServiceInfo(alternative_service, it->expiration)); 323 AlternativeServiceInfo(alternative_service, it->expiration()));
324 ++it; 324 ++it;
325 } 325 }
326 if (map_it->second.empty()) { 326 if (map_it->second.empty()) {
327 alternative_service_map_.Erase(map_it); 327 alternative_service_map_.Erase(map_it);
328 } 328 }
329 return valid_alternative_service_infos; 329 return valid_alternative_service_infos;
330 } 330 }
331 331
332 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(origin); 332 CanonicalHostMap::const_iterator canonical = GetCanonicalHost(origin);
333 if (canonical == canonical_host_to_origin_map_.end()) { 333 if (canonical == canonical_host_to_origin_map_.end()) {
334 return AlternativeServiceInfoVector(); 334 return AlternativeServiceInfoVector();
335 } 335 }
336 map_it = alternative_service_map_.Get(canonical->second); 336 map_it = alternative_service_map_.Get(canonical->second);
337 if (map_it == alternative_service_map_.end()) { 337 if (map_it == alternative_service_map_.end()) {
338 return AlternativeServiceInfoVector(); 338 return AlternativeServiceInfoVector();
339 } 339 }
340 for (AlternativeServiceInfoVector::iterator it = map_it->second.begin(); 340 for (AlternativeServiceInfoVector::iterator it = map_it->second.begin();
341 it != map_it->second.end();) { 341 it != map_it->second.end();) {
342 if (it->expiration < now) { 342 if (it->expiration() < now) {
343 it = map_it->second.erase(it); 343 it = map_it->second.erase(it);
344 continue; 344 continue;
345 } 345 }
346 AlternativeService alternative_service(it->alternative_service); 346 AlternativeService alternative_service(it->alternative_service());
347 if (alternative_service.host.empty()) { 347 if (alternative_service.host.empty()) {
348 alternative_service.host = canonical->second.host(); 348 alternative_service.host = canonical->second.host();
349 if (IsAlternativeServiceBroken(alternative_service)) { 349 if (IsAlternativeServiceBroken(alternative_service)) {
350 ++it; 350 ++it;
351 continue; 351 continue;
352 } 352 }
353 alternative_service.host = origin.host(); 353 alternative_service.host = origin.host();
354 } else if (IsAlternativeServiceBroken(alternative_service)) { 354 } else if (IsAlternativeServiceBroken(alternative_service)) {
355 ++it; 355 ++it;
356 continue; 356 continue;
357 } 357 }
358 valid_alternative_service_infos.push_back( 358 valid_alternative_service_infos.push_back(
359 AlternativeServiceInfo(alternative_service, it->expiration)); 359 AlternativeServiceInfo(alternative_service, it->expiration()));
360 ++it; 360 ++it;
361 } 361 }
362 if (map_it->second.empty()) { 362 if (map_it->second.empty()) {
363 alternative_service_map_.Erase(map_it); 363 alternative_service_map_.Erase(map_it);
364 } 364 }
365 return valid_alternative_service_infos; 365 return valid_alternative_service_infos;
366 } 366 }
367 367
368 bool HttpServerPropertiesImpl::SetAlternativeService( 368 bool HttpServerPropertiesImpl::SetAlternativeService(
369 const url::SchemeHostPort& origin, 369 const url::SchemeHostPort& origin,
(...skipping 22 matching lines...) Expand all
392 bool changed = true; 392 bool changed = true;
393 if (it != alternative_service_map_.end()) { 393 if (it != alternative_service_map_.end()) {
394 DCHECK(!it->second.empty()); 394 DCHECK(!it->second.empty());
395 if (it->second.size() == alternative_service_info_vector.size()) { 395 if (it->second.size() == alternative_service_info_vector.size()) {
396 const base::Time now = base::Time::Now(); 396 const base::Time now = base::Time::Now();
397 changed = false; 397 changed = false;
398 auto new_it = alternative_service_info_vector.begin(); 398 auto new_it = alternative_service_info_vector.begin();
399 for (const auto& old : it->second) { 399 for (const auto& old : it->second) {
400 // Persist to disk immediately if new entry has different scheme, host, 400 // Persist to disk immediately if new entry has different scheme, host,
401 // or port. 401 // or port.
402 if (old.alternative_service != new_it->alternative_service) { 402 if (old.alternative_service() != new_it->alternative_service()) {
403 changed = true; 403 changed = true;
404 break; 404 break;
405 } 405 }
406 // Also persist to disk if new expiration it more that twice as far or 406 // Also persist to disk if new expiration it more that twice as far or
407 // less than half as far in the future. 407 // less than half as far in the future.
408 base::Time old_time = old.expiration; 408 base::Time old_time = old.expiration();
409 base::Time new_time = new_it->expiration; 409 base::Time new_time = new_it->expiration();
410 if (new_time - now > 2 * (old_time - now) || 410 if (new_time - now > 2 * (old_time - now) ||
411 2 * (new_time - now) < (old_time - now)) { 411 2 * (new_time - now) < (old_time - now)) {
412 changed = true; 412 changed = true;
413 break; 413 break;
414 } 414 }
415 ++new_it; 415 ++new_it;
416 } 416 }
417 } 417 }
418 } 418 }
419 419
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 std::unique_ptr<base::ListValue> dict_list(new base::ListValue); 484 std::unique_ptr<base::ListValue> dict_list(new base::ListValue);
485 for (const auto& alternative_service_map_item : alternative_service_map_) { 485 for (const auto& alternative_service_map_item : alternative_service_map_) {
486 std::unique_ptr<base::ListValue> alternative_service_list( 486 std::unique_ptr<base::ListValue> alternative_service_list(
487 new base::ListValue); 487 new base::ListValue);
488 const url::SchemeHostPort& server = alternative_service_map_item.first; 488 const url::SchemeHostPort& server = alternative_service_map_item.first;
489 for (const AlternativeServiceInfo& alternative_service_info : 489 for (const AlternativeServiceInfo& alternative_service_info :
490 alternative_service_map_item.second) { 490 alternative_service_map_item.second) {
491 std::string alternative_service_string( 491 std::string alternative_service_string(
492 alternative_service_info.ToString()); 492 alternative_service_info.ToString());
493 AlternativeService alternative_service( 493 AlternativeService alternative_service(
494 alternative_service_info.alternative_service); 494 alternative_service_info.alternative_service());
495 if (alternative_service.host.empty()) { 495 if (alternative_service.host.empty()) {
496 alternative_service.host = server.host(); 496 alternative_service.host = server.host();
497 } 497 }
498 if (IsAlternativeServiceBroken(alternative_service)) { 498 if (IsAlternativeServiceBroken(alternative_service)) {
499 alternative_service_string.append(" (broken)"); 499 alternative_service_string.append(" (broken)");
500 } 500 }
501 alternative_service_list->AppendString(alternative_service_string); 501 alternative_service_list->AppendString(alternative_service_string);
502 } 502 }
503 if (alternative_service_list->empty()) 503 if (alternative_service_list->empty())
504 continue; 504 continue;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 } 620 }
621 621
622 const url::SchemeHostPort canonical_server = canonical->second; 622 const url::SchemeHostPort canonical_server = canonical->second;
623 it = alternative_service_map_.Get(canonical_server); 623 it = alternative_service_map_.Get(canonical_server);
624 if (it == alternative_service_map_.end()) { 624 if (it == alternative_service_map_.end()) {
625 return alternative_service_map_.end(); 625 return alternative_service_map_.end();
626 } 626 }
627 627
628 for (const AlternativeServiceInfo& alternative_service_info : it->second) { 628 for (const AlternativeServiceInfo& alternative_service_info : it->second) {
629 AlternativeService alternative_service( 629 AlternativeService alternative_service(
630 alternative_service_info.alternative_service); 630 alternative_service_info.alternative_service());
631 if (alternative_service.host.empty()) { 631 if (alternative_service.host.empty()) {
632 alternative_service.host = canonical_server.host(); 632 alternative_service.host = canonical_server.host();
633 } 633 }
634 if (!IsAlternativeServiceBroken(alternative_service)) { 634 if (!IsAlternativeServiceBroken(alternative_service)) {
635 return it; 635 return it;
636 } 636 }
637 } 637 }
638 638
639 RemoveCanonicalHost(canonical_server); 639 RemoveCanonicalHost(canonical_server);
640 return alternative_service_map_.end(); 640 return alternative_service_map_.end();
(...skipping 26 matching lines...) Expand all
667 667
668 void HttpServerPropertiesImpl::OnExpireBrokenAlternativeService( 668 void HttpServerPropertiesImpl::OnExpireBrokenAlternativeService(
669 const AlternativeService& expired_alternative_service) { 669 const AlternativeService& expired_alternative_service) {
670 // Remove every occurrence of |expired_alternative_service| from 670 // Remove every occurrence of |expired_alternative_service| from
671 // |alternative_service_map_|. 671 // |alternative_service_map_|.
672 for (AlternativeServiceMap::iterator map_it = 672 for (AlternativeServiceMap::iterator map_it =
673 alternative_service_map_.begin(); 673 alternative_service_map_.begin();
674 map_it != alternative_service_map_.end();) { 674 map_it != alternative_service_map_.end();) {
675 for (AlternativeServiceInfoVector::iterator it = map_it->second.begin(); 675 for (AlternativeServiceInfoVector::iterator it = map_it->second.begin();
676 it != map_it->second.end();) { 676 it != map_it->second.end();) {
677 AlternativeService alternative_service(it->alternative_service); 677 AlternativeService alternative_service(it->alternative_service());
678 // Empty hostname in map means hostname of key: substitute before 678 // Empty hostname in map means hostname of key: substitute before
679 // comparing to |expired_alternative_service|. 679 // comparing to |expired_alternative_service|.
680 if (alternative_service.host.empty()) { 680 if (alternative_service.host.empty()) {
681 alternative_service.host = map_it->first.host(); 681 alternative_service.host = map_it->first.host();
682 } 682 }
683 if (alternative_service == expired_alternative_service) { 683 if (alternative_service == expired_alternative_service) {
684 it = map_it->second.erase(it); 684 it = map_it->second.erase(it);
685 continue; 685 continue;
686 } 686 }
687 ++it; 687 ++it;
688 } 688 }
689 // If an origin has an empty list of alternative services, then remove it 689 // If an origin has an empty list of alternative services, then remove it
690 // from both |canonical_host_to_origin_map_| and 690 // from both |canonical_host_to_origin_map_| and
691 // |alternative_service_map_|. 691 // |alternative_service_map_|.
692 if (map_it->second.empty()) { 692 if (map_it->second.empty()) {
693 RemoveCanonicalHost(map_it->first); 693 RemoveCanonicalHost(map_it->first);
694 map_it = alternative_service_map_.Erase(map_it); 694 map_it = alternative_service_map_.Erase(map_it);
695 continue; 695 continue;
696 } 696 }
697 ++map_it; 697 ++map_it;
698 } 698 }
699 } 699 }
700 700
701 } // namespace net 701 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties.cc ('k') | net/http/http_server_properties_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698