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

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

Issue 2901093004: Add and persist a new field in AlternativeServiceInfo to list QUIC verisons advertised (Closed)
Patch Set: fix cronet/grpc 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 const char kSupportsQuicKey[] = "supports_quic"; 55 const char kSupportsQuicKey[] = "supports_quic";
56 const char kQuicServers[] = "quic_servers"; 56 const char kQuicServers[] = "quic_servers";
57 const char kServerInfoKey[] = "server_info"; 57 const char kServerInfoKey[] = "server_info";
58 const char kUsedQuicKey[] = "used_quic"; 58 const char kUsedQuicKey[] = "used_quic";
59 const char kAddressKey[] = "address"; 59 const char kAddressKey[] = "address";
60 const char kAlternativeServiceKey[] = "alternative_service"; 60 const char kAlternativeServiceKey[] = "alternative_service";
61 const char kProtocolKey[] = "protocol_str"; 61 const char kProtocolKey[] = "protocol_str";
62 const char kHostKey[] = "host"; 62 const char kHostKey[] = "host";
63 const char kPortKey[] = "port"; 63 const char kPortKey[] = "port";
64 const char kExpirationKey[] = "expiration"; 64 const char kExpirationKey[] = "expiration";
65 const char kAdvertisedVersionsKey[] = "advertised_versions";
65 const char kNetworkStatsKey[] = "network_stats"; 66 const char kNetworkStatsKey[] = "network_stats";
66 const char kSrttKey[] = "srtt"; 67 const char kSrttKey[] = "srtt";
67 68
68 } // namespace 69 } // namespace
69 70
70 //////////////////////////////////////////////////////////////////////////////// 71 ////////////////////////////////////////////////////////////////////////////////
71 // HttpServerPropertiesManager 72 // HttpServerPropertiesManager
72 73
73 HttpServerPropertiesManager::PrefDelegate::~PrefDelegate() {} 74 HttpServerPropertiesManager::PrefDelegate::~PrefDelegate() {}
74 75
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 http_server_properties_impl_->MaybeForceHTTP11(server, ssl_config); 193 http_server_properties_impl_->MaybeForceHTTP11(server, ssl_config);
193 } 194 }
194 195
195 AlternativeServiceInfoVector 196 AlternativeServiceInfoVector
196 HttpServerPropertiesManager::GetAlternativeServiceInfos( 197 HttpServerPropertiesManager::GetAlternativeServiceInfos(
197 const url::SchemeHostPort& origin) { 198 const url::SchemeHostPort& origin) {
198 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); 199 DCHECK(network_task_runner_->RunsTasksInCurrentSequence());
199 return http_server_properties_impl_->GetAlternativeServiceInfos(origin); 200 return http_server_properties_impl_->GetAlternativeServiceInfos(origin);
200 } 201 }
201 202
202 bool HttpServerPropertiesManager::SetAlternativeService( 203 bool HttpServerPropertiesManager::SetHttp2AlternativeService(
203 const url::SchemeHostPort& origin, 204 const url::SchemeHostPort& origin,
204 const AlternativeService& alternative_service, 205 const AlternativeService& alternative_service,
205 base::Time expiration) { 206 base::Time expiration) {
206 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); 207 DCHECK(network_task_runner_->RunsTasksInCurrentSequence());
207 const bool changed = http_server_properties_impl_->SetAlternativeService( 208 const bool changed = http_server_properties_impl_->SetHttp2AlternativeService(
208 origin, alternative_service, expiration); 209 origin, alternative_service, expiration);
209 if (changed) { 210 if (changed) {
210 ScheduleUpdatePrefsOnNetworkSequence(SET_ALTERNATIVE_SERVICES); 211 ScheduleUpdatePrefsOnNetworkSequence(SET_ALTERNATIVE_SERVICES);
211 } 212 }
212 return changed; 213 return changed;
213 } 214 }
214 215
216 bool HttpServerPropertiesManager::SetQuicAlternativeService(
217 const url::SchemeHostPort& origin,
218 const AlternativeService& alternative_service,
219 base::Time expiration,
220 const QuicVersionVector& advertised_versions) {
221 DCHECK(network_task_runner_->RunsTasksInCurrentSequence());
222 const bool changed = http_server_properties_impl_->SetQuicAlternativeService(
223 origin, alternative_service, expiration, advertised_versions);
224 if (changed) {
225 ScheduleUpdatePrefsOnNetworkSequence(SET_ALTERNATIVE_SERVICES);
226 }
227 return changed;
228 }
229
215 bool HttpServerPropertiesManager::SetAlternativeServices( 230 bool HttpServerPropertiesManager::SetAlternativeServices(
216 const url::SchemeHostPort& origin, 231 const url::SchemeHostPort& origin,
217 const AlternativeServiceInfoVector& alternative_service_info_vector) { 232 const AlternativeServiceInfoVector& alternative_service_info_vector) {
218 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); 233 DCHECK(network_task_runner_->RunsTasksInCurrentSequence());
219 const bool changed = http_server_properties_impl_->SetAlternativeServices( 234 const bool changed = http_server_properties_impl_->SetAlternativeServices(
220 origin, alternative_service_info_vector); 235 origin, alternative_service_info_vector);
221 if (changed) { 236 if (changed) {
222 ScheduleUpdatePrefsOnNetworkSequence(SET_ALTERNATIVE_SERVICES); 237 ScheduleUpdatePrefsOnNetworkSequence(SET_ALTERNATIVE_SERVICES);
223 } 238 }
224 return changed; 239 return changed;
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 626
612 // Expiration is optional, defaults to one day. 627 // Expiration is optional, defaults to one day.
613 base::Time expiration; 628 base::Time expiration;
614 if (!alternative_service_dict.HasKey(kExpirationKey)) { 629 if (!alternative_service_dict.HasKey(kExpirationKey)) {
615 alternative_service_info->set_expiration(base::Time::Now() + 630 alternative_service_info->set_expiration(base::Time::Now() +
616 base::TimeDelta::FromDays(1)); 631 base::TimeDelta::FromDays(1));
617 return true; 632 return true;
618 } 633 }
619 634
620 std::string expiration_string; 635 std::string expiration_string;
621 if (alternative_service_dict.GetStringWithoutPathExpansion( 636 if (!alternative_service_dict.GetStringWithoutPathExpansion(
622 kExpirationKey, &expiration_string)) { 637 kExpirationKey, &expiration_string)) {
623 int64_t expiration_int64 = 0; 638 DVLOG(1) << "Malformed alternative service expiration for server: "
624 if (!base::StringToInt64(expiration_string, &expiration_int64)) { 639 << server_str;
625 DVLOG(1) << "Malformed alternative service expiration for server: " 640 return false;
641 }
642
643 int64_t expiration_int64 = 0;
644 if (!base::StringToInt64(expiration_string, &expiration_int64)) {
645 DVLOG(1) << "Malformed alternative service expiration for server: "
646 << server_str;
647 return false;
648 }
649 alternative_service_info->set_expiration(
650 base::Time::FromInternalValue(expiration_int64));
651
652 // Advertised versions list is optional.
653 if (!alternative_service_dict.HasKey(kAdvertisedVersionsKey))
654 return true;
655
656 const base::ListValue* versions_list = nullptr;
657 if (!alternative_service_dict.GetListWithoutPathExpansion(
658 kAdvertisedVersionsKey, &versions_list)) {
659 DVLOG(1)
660 << "Malformed alternative service advertised versions list for server: "
661 << server_str;
662 return false;
663 }
664
665 QuicVersionVector advertised_versions;
666 for (const auto& value : *versions_list) {
667 int version;
668 if (!value.GetAsInteger(&version)) {
669 DVLOG(1) << "Malformed alternative service version for server: "
626 << server_str; 670 << server_str;
627 return false; 671 return false;
628 } 672 }
629 alternative_service_info->set_expiration( 673 advertised_versions.push_back(QuicVersion(version));
630 base::Time::FromInternalValue(expiration_int64));
631 return true;
632 } 674 }
675 alternative_service_info->set_advertised_versions(advertised_versions);
633 676
634 DVLOG(1) << "Malformed alternative service expiration for server: " 677 return true;
635 << server_str;
636 return false;
637 } 678 }
638 679
639 bool HttpServerPropertiesManager::AddToAlternativeServiceMap( 680 bool HttpServerPropertiesManager::AddToAlternativeServiceMap(
640 const url::SchemeHostPort& server, 681 const url::SchemeHostPort& server,
641 const base::DictionaryValue& server_pref_dict, 682 const base::DictionaryValue& server_pref_dict,
642 AlternativeServiceMap* alternative_service_map) { 683 AlternativeServiceMap* alternative_service_map) {
643 DCHECK(alternative_service_map->Peek(server) == 684 DCHECK(alternative_service_map->Peek(server) ==
644 alternative_service_map->end()); 685 alternative_service_map->end());
645 const base::ListValue* alternative_service_list; 686 const base::ListValue* alternative_service_list;
646 if (!server_pref_dict.GetListWithoutPathExpansion( 687 if (!server_pref_dict.GetListWithoutPathExpansion(
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 if (!alternative_service.host.empty()) { 1121 if (!alternative_service.host.empty()) {
1081 alternative_service_dict->SetString(kHostKey, alternative_service.host); 1122 alternative_service_dict->SetString(kHostKey, alternative_service.host);
1082 } 1123 }
1083 alternative_service_dict->SetString( 1124 alternative_service_dict->SetString(
1084 kProtocolKey, NextProtoToString(alternative_service.protocol)); 1125 kProtocolKey, NextProtoToString(alternative_service.protocol));
1085 // JSON cannot store int64_t, so expiration is converted to a string. 1126 // JSON cannot store int64_t, so expiration is converted to a string.
1086 alternative_service_dict->SetString( 1127 alternative_service_dict->SetString(
1087 kExpirationKey, 1128 kExpirationKey,
1088 base::Int64ToString( 1129 base::Int64ToString(
1089 alternative_service_info.expiration().ToInternalValue())); 1130 alternative_service_info.expiration().ToInternalValue()));
1131 std::unique_ptr<base::ListValue> advertised_versions_list =
1132 base::MakeUnique<base::ListValue>();
1133 for (const auto& version : alternative_service_info.advertised_versions()) {
1134 advertised_versions_list->AppendInteger(version);
1135 }
1136 alternative_service_dict->SetList(kAdvertisedVersionsKey,
1137 std::move(advertised_versions_list));
1090 alternative_service_list->Append(std::move(alternative_service_dict)); 1138 alternative_service_list->Append(std::move(alternative_service_dict));
1091 } 1139 }
1092 if (alternative_service_list->GetSize() == 0) 1140 if (alternative_service_list->GetSize() == 0)
1093 return; 1141 return;
1094 server_pref_dict->SetWithoutPathExpansion( 1142 server_pref_dict->SetWithoutPathExpansion(
1095 kAlternativeServiceKey, std::move(alternative_service_list)); 1143 kAlternativeServiceKey, std::move(alternative_service_list));
1096 } 1144 }
1097 1145
1098 void HttpServerPropertiesManager::SaveSupportsQuicToPrefs( 1146 void HttpServerPropertiesManager::SaveSupportsQuicToPrefs(
1099 const IPAddress* last_quic_address, 1147 const IPAddress* last_quic_address,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 if (!setting_prefs_) 1197 if (!setting_prefs_)
1150 ScheduleUpdateCacheOnPrefThread(); 1198 ScheduleUpdateCacheOnPrefThread();
1151 } 1199 }
1152 1200
1153 void HttpServerPropertiesManager::SetInitialized() { 1201 void HttpServerPropertiesManager::SetInitialized() {
1154 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); 1202 DCHECK(network_task_runner_->RunsTasksInCurrentSequence());
1155 is_initialized_ = true; 1203 is_initialized_ = true;
1156 } 1204 }
1157 1205
1158 } // namespace net 1206 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698