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

Side by Side Diff: net/http/http_server_properties_manager.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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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_manager.h" 5 #include "net/http/http_server_properties_manager.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 DVLOG(1) << "Malformed alternative service protocol string for server: " 580 DVLOG(1) << "Malformed alternative service protocol string for server: "
581 << server_str; 581 << server_str;
582 return false; 582 return false;
583 } 583 }
584 NextProto protocol = NextProtoFromString(protocol_str); 584 NextProto protocol = NextProtoFromString(protocol_str);
585 if (!IsAlternateProtocolValid(protocol)) { 585 if (!IsAlternateProtocolValid(protocol)) {
586 DVLOG(1) << "Invalid alternative service protocol string for server: " 586 DVLOG(1) << "Invalid alternative service protocol string for server: "
587 << server_str; 587 << server_str;
588 return false; 588 return false;
589 } 589 }
590 alternative_service_info->alternative_service.protocol = protocol; 590 alternative_service_info->set_protocol(protocol);
591 591
592 // Host is optional, defaults to "". 592 // Host is optional, defaults to "".
593 alternative_service_info->alternative_service.host.clear(); 593 std::string host = "";
594 if (alternative_service_dict.HasKey(kHostKey) && 594 if (alternative_service_dict.HasKey(kHostKey) &&
595 !alternative_service_dict.GetStringWithoutPathExpansion( 595 !alternative_service_dict.GetStringWithoutPathExpansion(kHostKey,
596 kHostKey, &(alternative_service_info->alternative_service.host))) { 596 &host)) {
597 DVLOG(1) << "Malformed alternative service host string for server: " 597 DVLOG(1) << "Malformed alternative service host string for server: "
598 << server_str; 598 << server_str;
599 return false; 599 return false;
600 } 600 }
601 alternative_service_info->set_host(host);
601 602
602 // Port is mandatory. 603 // Port is mandatory.
603 int port = 0; 604 int port = 0;
604 if (!alternative_service_dict.GetInteger(kPortKey, &port) || 605 if (!alternative_service_dict.GetInteger(kPortKey, &port) ||
605 !IsPortValid(port)) { 606 !IsPortValid(port)) {
606 DVLOG(1) << "Malformed alternative service port for server: " << server_str; 607 DVLOG(1) << "Malformed alternative service port for server: " << server_str;
607 return false; 608 return false;
608 } 609 }
609 alternative_service_info->alternative_service.port = 610 alternative_service_info->set_port(static_cast<uint32_t>(port));
610 static_cast<uint32_t>(port);
611 611
612 // Expiration is optional, defaults to one day. 612 // Expiration is optional, defaults to one day.
613 base::Time expiration; 613 base::Time expiration;
614 if (!alternative_service_dict.HasKey(kExpirationKey)) { 614 if (!alternative_service_dict.HasKey(kExpirationKey)) {
615 alternative_service_info->expiration = 615 alternative_service_info->set_expiration(base::Time::Now() +
616 base::Time::Now() + base::TimeDelta::FromDays(1); 616 base::TimeDelta::FromDays(1));
617 return true; 617 return true;
618 } 618 }
619 619
620 std::string expiration_string; 620 std::string expiration_string;
621 if (alternative_service_dict.GetStringWithoutPathExpansion( 621 if (alternative_service_dict.GetStringWithoutPathExpansion(
622 kExpirationKey, &expiration_string)) { 622 kExpirationKey, &expiration_string)) {
623 int64_t expiration_int64 = 0; 623 int64_t expiration_int64 = 0;
624 if (!base::StringToInt64(expiration_string, &expiration_int64)) { 624 if (!base::StringToInt64(expiration_string, &expiration_int64)) {
625 DVLOG(1) << "Malformed alternative service expiration for server: " 625 DVLOG(1) << "Malformed alternative service expiration for server: "
626 << server_str; 626 << server_str;
627 return false; 627 return false;
628 } 628 }
629 alternative_service_info->expiration = 629 alternative_service_info->set_expiration(
630 base::Time::FromInternalValue(expiration_int64); 630 base::Time::FromInternalValue(expiration_int64));
631 return true; 631 return true;
632 } 632 }
633 633
634 DVLOG(1) << "Malformed alternative service expiration for server: " 634 DVLOG(1) << "Malformed alternative service expiration for server: "
635 << server_str; 635 << server_str;
636 return false; 636 return false;
637 } 637 }
638 638
639 bool HttpServerPropertiesManager::AddToAlternativeServiceMap( 639 bool HttpServerPropertiesManager::AddToAlternativeServiceMap(
640 const url::SchemeHostPort& server, 640 const url::SchemeHostPort& server,
(...skipping 15 matching lines...) Expand all
656 const base::DictionaryValue* alternative_service_dict; 656 const base::DictionaryValue* alternative_service_dict;
657 if (!alternative_service_list_item.GetAsDictionary( 657 if (!alternative_service_list_item.GetAsDictionary(
658 &alternative_service_dict)) 658 &alternative_service_dict))
659 return false; 659 return false;
660 AlternativeServiceInfo alternative_service_info; 660 AlternativeServiceInfo alternative_service_info;
661 if (!ParseAlternativeServiceDict(*alternative_service_dict, 661 if (!ParseAlternativeServiceDict(*alternative_service_dict,
662 server.Serialize(), 662 server.Serialize(),
663 &alternative_service_info)) { 663 &alternative_service_info)) {
664 return false; 664 return false;
665 } 665 }
666 if (base::Time::Now() < alternative_service_info.expiration) { 666 if (base::Time::Now() < alternative_service_info.expiration()) {
667 alternative_service_info_vector.push_back(alternative_service_info); 667 alternative_service_info_vector.push_back(alternative_service_info);
668 } 668 }
669 } 669 }
670 670
671 if (alternative_service_info_vector.empty()) { 671 if (alternative_service_info_vector.empty()) {
672 return false; 672 return false;
673 } 673 }
674 674
675 alternative_service_map->Put(server, alternative_service_info_vector); 675 alternative_service_map->Put(server, alternative_service_info_vector);
676 return true; 676 return true;
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 int count = 0; 851 int count = 0;
852 typedef std::map<std::string, bool> CanonicalHostPersistedMap; 852 typedef std::map<std::string, bool> CanonicalHostPersistedMap;
853 CanonicalHostPersistedMap persisted_map; 853 CanonicalHostPersistedMap persisted_map;
854 // Maintain MRU order. 854 // Maintain MRU order.
855 for (AlternativeServiceMap::const_reverse_iterator it = map.rbegin(); 855 for (AlternativeServiceMap::const_reverse_iterator it = map.rbegin();
856 it != map.rend() && count < kMaxAlternateProtocolHostsToPersist; ++it) { 856 it != map.rend() && count < kMaxAlternateProtocolHostsToPersist; ++it) {
857 const url::SchemeHostPort& server = it->first; 857 const url::SchemeHostPort& server = it->first;
858 AlternativeServiceInfoVector notbroken_alternative_service_info_vector; 858 AlternativeServiceInfoVector notbroken_alternative_service_info_vector;
859 for (const AlternativeServiceInfo& alternative_service_info : it->second) { 859 for (const AlternativeServiceInfo& alternative_service_info : it->second) {
860 // Do not persist expired entries. 860 // Do not persist expired entries.
861 if (alternative_service_info.expiration < base::Time::Now()) { 861 if (alternative_service_info.expiration() < base::Time::Now()) {
862 continue; 862 continue;
863 } 863 }
864 AlternativeService alternative_service( 864 AlternativeService alternative_service(
865 alternative_service_info.alternative_service); 865 alternative_service_info.alternative_service());
866 if (!IsAlternateProtocolValid(alternative_service.protocol)) { 866 if (!IsAlternateProtocolValid(alternative_service.protocol)) {
867 continue; 867 continue;
868 } 868 }
869 if (alternative_service.host.empty()) { 869 if (alternative_service.host.empty()) {
870 alternative_service.host = server.host(); 870 alternative_service.host = server.host();
871 } 871 }
872 if (IsAlternativeServiceBroken(alternative_service)) { 872 if (IsAlternativeServiceBroken(alternative_service)) {
873 continue; 873 continue;
874 } 874 }
875 notbroken_alternative_service_info_vector.push_back( 875 notbroken_alternative_service_info_vector.push_back(
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
1065 base::DictionaryValue* server_pref_dict) { 1065 base::DictionaryValue* server_pref_dict) {
1066 if (!alternative_service_info_vector || 1066 if (!alternative_service_info_vector ||
1067 alternative_service_info_vector->empty()) { 1067 alternative_service_info_vector->empty()) {
1068 return; 1068 return;
1069 } 1069 }
1070 std::unique_ptr<base::ListValue> alternative_service_list( 1070 std::unique_ptr<base::ListValue> alternative_service_list(
1071 new base::ListValue); 1071 new base::ListValue);
1072 for (const AlternativeServiceInfo& alternative_service_info : 1072 for (const AlternativeServiceInfo& alternative_service_info :
1073 *alternative_service_info_vector) { 1073 *alternative_service_info_vector) {
1074 const AlternativeService alternative_service = 1074 const AlternativeService alternative_service =
1075 alternative_service_info.alternative_service; 1075 alternative_service_info.alternative_service();
1076 DCHECK(IsAlternateProtocolValid(alternative_service.protocol)); 1076 DCHECK(IsAlternateProtocolValid(alternative_service.protocol));
1077 std::unique_ptr<base::DictionaryValue> alternative_service_dict( 1077 std::unique_ptr<base::DictionaryValue> alternative_service_dict(
1078 new base::DictionaryValue); 1078 new base::DictionaryValue);
1079 alternative_service_dict->SetInteger(kPortKey, alternative_service.port); 1079 alternative_service_dict->SetInteger(kPortKey, alternative_service.port);
1080 if (!alternative_service.host.empty()) { 1080 if (!alternative_service.host.empty()) {
1081 alternative_service_dict->SetString(kHostKey, alternative_service.host); 1081 alternative_service_dict->SetString(kHostKey, alternative_service.host);
1082 } 1082 }
1083 alternative_service_dict->SetString( 1083 alternative_service_dict->SetString(
1084 kProtocolKey, NextProtoToString(alternative_service.protocol)); 1084 kProtocolKey, NextProtoToString(alternative_service.protocol));
1085 // JSON cannot store int64_t, so expiration is converted to a string. 1085 // JSON cannot store int64_t, so expiration is converted to a string.
1086 alternative_service_dict->SetString( 1086 alternative_service_dict->SetString(
1087 kExpirationKey, 1087 kExpirationKey,
1088 base::Int64ToString( 1088 base::Int64ToString(
1089 alternative_service_info.expiration.ToInternalValue())); 1089 alternative_service_info.expiration().ToInternalValue()));
1090 alternative_service_list->Append(std::move(alternative_service_dict)); 1090 alternative_service_list->Append(std::move(alternative_service_dict));
1091 } 1091 }
1092 if (alternative_service_list->GetSize() == 0) 1092 if (alternative_service_list->GetSize() == 0)
1093 return; 1093 return;
1094 server_pref_dict->SetWithoutPathExpansion( 1094 server_pref_dict->SetWithoutPathExpansion(
1095 kAlternativeServiceKey, std::move(alternative_service_list)); 1095 kAlternativeServiceKey, std::move(alternative_service_list));
1096 } 1096 }
1097 1097
1098 void HttpServerPropertiesManager::SaveSupportsQuicToPrefs( 1098 void HttpServerPropertiesManager::SaveSupportsQuicToPrefs(
1099 const IPAddress* last_quic_address, 1099 const IPAddress* last_quic_address,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 if (!setting_prefs_) 1149 if (!setting_prefs_)
1150 ScheduleUpdateCacheOnPrefThread(); 1150 ScheduleUpdateCacheOnPrefThread();
1151 } 1151 }
1152 1152
1153 void HttpServerPropertiesManager::SetInitialized() { 1153 void HttpServerPropertiesManager::SetInitialized() {
1154 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); 1154 DCHECK(network_task_runner_->RunsTasksInCurrentSequence());
1155 is_initialized_ = true; 1155 is_initialized_ = true;
1156 } 1156 }
1157 1157
1158 } // namespace net 1158 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties_impl_unittest.cc ('k') | net/http/http_server_properties_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698