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

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 compile in components 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 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::SetAlternativeService(
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,
207 const QuicVersionVector& advertised_versions) {
206 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); 208 DCHECK(network_task_runner_->RunsTasksInCurrentSequence());
207 const bool changed = http_server_properties_impl_->SetAlternativeService( 209 const bool changed = http_server_properties_impl_->SetAlternativeService(
208 origin, alternative_service, expiration); 210 origin, alternative_service, expiration, advertised_versions);
209 if (changed) { 211 if (changed) {
210 ScheduleUpdatePrefsOnNetworkSequence(SET_ALTERNATIVE_SERVICES); 212 ScheduleUpdatePrefsOnNetworkSequence(SET_ALTERNATIVE_SERVICES);
211 } 213 }
212 return changed; 214 return changed;
213 } 215 }
214 216
215 bool HttpServerPropertiesManager::SetAlternativeServices( 217 bool HttpServerPropertiesManager::SetAlternativeServices(
216 const url::SchemeHostPort& origin, 218 const url::SchemeHostPort& origin,
217 const AlternativeServiceInfoVector& alternative_service_info_vector) { 219 const AlternativeServiceInfoVector& alternative_service_info_vector) {
218 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); 220 DCHECK(network_task_runner_->RunsTasksInCurrentSequence());
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
611 613
612 // Expiration is optional, defaults to one day. 614 // Expiration is optional, defaults to one day.
613 base::Time expiration; 615 base::Time expiration;
614 if (!alternative_service_dict.HasKey(kExpirationKey)) { 616 if (!alternative_service_dict.HasKey(kExpirationKey)) {
615 alternative_service_info->expiration = 617 alternative_service_info->expiration =
616 base::Time::Now() + base::TimeDelta::FromDays(1); 618 base::Time::Now() + base::TimeDelta::FromDays(1);
617 return true; 619 return true;
618 } 620 }
619 621
620 std::string expiration_string; 622 std::string expiration_string;
621 if (alternative_service_dict.GetStringWithoutPathExpansion( 623 if (!alternative_service_dict.GetStringWithoutPathExpansion(
622 kExpirationKey, &expiration_string)) { 624 kExpirationKey, &expiration_string)) {
623 int64_t expiration_int64 = 0; 625 DVLOG(1) << "Malformed alternative service expiration for server: "
624 if (!base::StringToInt64(expiration_string, &expiration_int64)) { 626 << server_str;
625 DVLOG(1) << "Malformed alternative service expiration for server: " 627 return false;
Ryan Hamilton 2017/06/07 20:52:24 Yay, early return!
628 }
629
630 int64_t expiration_int64 = 0;
631 if (!base::StringToInt64(expiration_string, &expiration_int64)) {
632 DVLOG(1) << "Malformed alternative service expiration for server: "
633 << server_str;
634 return false;
635 }
636 alternative_service_info->expiration =
637 base::Time::FromInternalValue(expiration_int64);
638
639 // Advertised versions list is optional.
640 if (!alternative_service_dict.HasKey(kAdvertisedVersionsKey))
641 return true;
642
643 const base::ListValue* versions_list = nullptr;
644 if (!alternative_service_dict.GetListWithoutPathExpansion(
645 kAdvertisedVersionsKey, &versions_list)) {
646 DVLOG(1)
647 << "Malformed alternative service advertised versions list for server: "
648 << server_str;
649 return false;
650 }
651
652 QuicVersionVector advertised_versions;
653 for (const auto& value : *versions_list) {
654 int version_int;
Ryan Hamilton 2017/06/07 20:52:23 nit: since the loop variable is |value|, I think y
Zhongyi Shi 2017/06/08 23:11:16 Done.
655 if (!value.GetAsInteger(&version_int)) {
656 DVLOG(1) << "Malformed alternative service version for server: "
626 << server_str; 657 << server_str;
627 return false; 658 return false;
628 } 659 }
629 alternative_service_info->expiration = 660 advertised_versions.push_back(QuicVersion(version_int));
630 base::Time::FromInternalValue(expiration_int64);
631 return true;
632 } 661 }
662 alternative_service_info->set_advertised_versions(advertised_versions);
633 663
634 DVLOG(1) << "Malformed alternative service expiration for server: " 664 return true;
635 << server_str;
636 return false;
637 } 665 }
638 666
639 bool HttpServerPropertiesManager::AddToAlternativeServiceMap( 667 bool HttpServerPropertiesManager::AddToAlternativeServiceMap(
640 const url::SchemeHostPort& server, 668 const url::SchemeHostPort& server,
641 const base::DictionaryValue& server_pref_dict, 669 const base::DictionaryValue& server_pref_dict,
642 AlternativeServiceMap* alternative_service_map) { 670 AlternativeServiceMap* alternative_service_map) {
643 DCHECK(alternative_service_map->Peek(server) == 671 DCHECK(alternative_service_map->Peek(server) ==
644 alternative_service_map->end()); 672 alternative_service_map->end());
645 const base::ListValue* alternative_service_list; 673 const base::ListValue* alternative_service_list;
646 if (!server_pref_dict.GetListWithoutPathExpansion( 674 if (!server_pref_dict.GetListWithoutPathExpansion(
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 if (!alternative_service.host.empty()) { 1108 if (!alternative_service.host.empty()) {
1081 alternative_service_dict->SetString(kHostKey, alternative_service.host); 1109 alternative_service_dict->SetString(kHostKey, alternative_service.host);
1082 } 1110 }
1083 alternative_service_dict->SetString( 1111 alternative_service_dict->SetString(
1084 kProtocolKey, NextProtoToString(alternative_service.protocol)); 1112 kProtocolKey, NextProtoToString(alternative_service.protocol));
1085 // JSON cannot store int64_t, so expiration is converted to a string. 1113 // JSON cannot store int64_t, so expiration is converted to a string.
1086 alternative_service_dict->SetString( 1114 alternative_service_dict->SetString(
1087 kExpirationKey, 1115 kExpirationKey,
1088 base::Int64ToString( 1116 base::Int64ToString(
1089 alternative_service_info.expiration.ToInternalValue())); 1117 alternative_service_info.expiration.ToInternalValue()));
1118 std::unique_ptr<base::ListValue> advertised_versions_list(
Bence 2017/06/08 17:44:51 Optional: According to https://groups.google.com/a
Zhongyi Shi 2017/06/08 23:11:16 Done.
1119 new base::ListValue);
1120 for (const auto& version : alternative_service_info.advertised_versions()) {
1121 advertised_versions_list->AppendInteger(version);
1122 }
1123 alternative_service_dict->SetList(kAdvertisedVersionsKey,
1124 std::move(advertised_versions_list));
1090 alternative_service_list->Append(std::move(alternative_service_dict)); 1125 alternative_service_list->Append(std::move(alternative_service_dict));
1091 } 1126 }
1092 if (alternative_service_list->GetSize() == 0) 1127 if (alternative_service_list->GetSize() == 0)
1093 return; 1128 return;
1094 server_pref_dict->SetWithoutPathExpansion( 1129 server_pref_dict->SetWithoutPathExpansion(
1095 kAlternativeServiceKey, std::move(alternative_service_list)); 1130 kAlternativeServiceKey, std::move(alternative_service_list));
1096 } 1131 }
1097 1132
1098 void HttpServerPropertiesManager::SaveSupportsQuicToPrefs( 1133 void HttpServerPropertiesManager::SaveSupportsQuicToPrefs(
1099 const IPAddress* last_quic_address, 1134 const IPAddress* last_quic_address,
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 if (!setting_prefs_) 1184 if (!setting_prefs_)
1150 ScheduleUpdateCacheOnPrefThread(); 1185 ScheduleUpdateCacheOnPrefThread();
1151 } 1186 }
1152 1187
1153 void HttpServerPropertiesManager::SetInitialized() { 1188 void HttpServerPropertiesManager::SetInitialized() {
1154 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); 1189 DCHECK(network_task_runner_->RunsTasksInCurrentSequence());
1155 is_initialized_ = true; 1190 is_initialized_ = true;
1156 } 1191 }
1157 1192
1158 } // namespace net 1193 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698