OLD | NEW |
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 Loading... |
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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
194 AlternativeServiceInfoVector | 195 AlternativeServiceInfoVector |
195 HttpServerPropertiesManager::GetAlternativeServiceInfos( | 196 HttpServerPropertiesManager::GetAlternativeServiceInfos( |
196 const url::SchemeHostPort& origin) { | 197 const url::SchemeHostPort& origin) { |
197 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 198 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
198 return http_server_properties_impl_->GetAlternativeServiceInfos(origin); | 199 return http_server_properties_impl_->GetAlternativeServiceInfos(origin); |
199 } | 200 } |
200 | 201 |
201 bool HttpServerPropertiesManager::SetAlternativeService( | 202 bool HttpServerPropertiesManager::SetAlternativeService( |
202 const url::SchemeHostPort& origin, | 203 const url::SchemeHostPort& origin, |
203 const AlternativeService& alternative_service, | 204 const AlternativeService& alternative_service, |
204 base::Time expiration) { | 205 base::Time expiration, |
| 206 const QuicVersionVector& advertised_versions) { |
205 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 207 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
206 const bool changed = http_server_properties_impl_->SetAlternativeService( | 208 const bool changed = http_server_properties_impl_->SetAlternativeService( |
207 origin, alternative_service, expiration); | 209 origin, alternative_service, expiration, advertised_versions); |
208 if (changed) { | 210 if (changed) { |
209 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES); | 211 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES); |
210 } | 212 } |
211 return changed; | 213 return changed; |
212 } | 214 } |
213 | 215 |
214 bool HttpServerPropertiesManager::SetAlternativeServices( | 216 bool HttpServerPropertiesManager::SetAlternativeServices( |
215 const url::SchemeHostPort& origin, | 217 const url::SchemeHostPort& origin, |
216 const AlternativeServiceInfoVector& alternative_service_info_vector) { | 218 const AlternativeServiceInfoVector& alternative_service_info_vector) { |
217 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 219 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 | 611 |
610 // Expiration is optional, defaults to one day. | 612 // Expiration is optional, defaults to one day. |
611 base::Time expiration; | 613 base::Time expiration; |
612 if (!alternative_service_dict.HasKey(kExpirationKey)) { | 614 if (!alternative_service_dict.HasKey(kExpirationKey)) { |
613 alternative_service_info->expiration = | 615 alternative_service_info->expiration = |
614 base::Time::Now() + base::TimeDelta::FromDays(1); | 616 base::Time::Now() + base::TimeDelta::FromDays(1); |
615 return true; | 617 return true; |
616 } | 618 } |
617 | 619 |
618 std::string expiration_string; | 620 std::string expiration_string; |
619 if (alternative_service_dict.GetStringWithoutPathExpansion( | 621 if (!alternative_service_dict.GetStringWithoutPathExpansion( |
620 kExpirationKey, &expiration_string)) { | 622 kExpirationKey, &expiration_string)) { |
621 int64_t expiration_int64 = 0; | 623 DVLOG(1) << "Malformed alternative service expiration for server: " |
622 if (!base::StringToInt64(expiration_string, &expiration_int64)) { | 624 << server_str; |
623 DVLOG(1) << "Malformed alternative service expiration for server: " | 625 return false; |
| 626 } |
| 627 |
| 628 int64_t expiration_int64 = 0; |
| 629 if (!base::StringToInt64(expiration_string, &expiration_int64)) { |
| 630 DVLOG(1) << "Malformed alternative service expiration for server: " |
| 631 << server_str; |
| 632 return false; |
| 633 } |
| 634 alternative_service_info->expiration = |
| 635 base::Time::FromInternalValue(expiration_int64); |
| 636 |
| 637 // Advertised versions list is optional. |
| 638 if (!alternative_service_dict.HasKey(kAdvertisedVersionsKey)) |
| 639 return true; |
| 640 |
| 641 const base::ListValue* versions_list = nullptr; |
| 642 if (!alternative_service_dict.GetListWithoutPathExpansion( |
| 643 kAdvertisedVersionsKey, &versions_list)) { |
| 644 DVLOG(1) |
| 645 << "Malformed alternative service advertised versions list for server: " |
| 646 << server_str; |
| 647 return false; |
| 648 } |
| 649 |
| 650 QuicVersionVector advertised_versions; |
| 651 for (const auto& value : *versions_list) { |
| 652 int version_int; |
| 653 if (!value.GetAsInteger(&version_int)) { |
| 654 DVLOG(1) << "Malformed alternative service version for server: " |
624 << server_str; | 655 << server_str; |
625 return false; | 656 return false; |
626 } | 657 } |
627 alternative_service_info->expiration = | 658 advertised_versions.push_back(QuicVersion(version_int)); |
628 base::Time::FromInternalValue(expiration_int64); | |
629 return true; | |
630 } | 659 } |
| 660 alternative_service_info->set_advertised_versions(advertised_versions); |
631 | 661 |
632 DVLOG(1) << "Malformed alternative service expiration for server: " | 662 return true; |
633 << server_str; | |
634 return false; | |
635 } | 663 } |
636 | 664 |
637 bool HttpServerPropertiesManager::AddToAlternativeServiceMap( | 665 bool HttpServerPropertiesManager::AddToAlternativeServiceMap( |
638 const url::SchemeHostPort& server, | 666 const url::SchemeHostPort& server, |
639 const base::DictionaryValue& server_pref_dict, | 667 const base::DictionaryValue& server_pref_dict, |
640 AlternativeServiceMap* alternative_service_map) { | 668 AlternativeServiceMap* alternative_service_map) { |
641 DCHECK(alternative_service_map->Peek(server) == | 669 DCHECK(alternative_service_map->Peek(server) == |
642 alternative_service_map->end()); | 670 alternative_service_map->end()); |
643 const base::ListValue* alternative_service_list; | 671 const base::ListValue* alternative_service_list; |
644 if (!server_pref_dict.GetListWithoutPathExpansion( | 672 if (!server_pref_dict.GetListWithoutPathExpansion( |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1078 if (!alternative_service.host.empty()) { | 1106 if (!alternative_service.host.empty()) { |
1079 alternative_service_dict->SetString(kHostKey, alternative_service.host); | 1107 alternative_service_dict->SetString(kHostKey, alternative_service.host); |
1080 } | 1108 } |
1081 alternative_service_dict->SetString( | 1109 alternative_service_dict->SetString( |
1082 kProtocolKey, NextProtoToString(alternative_service.protocol)); | 1110 kProtocolKey, NextProtoToString(alternative_service.protocol)); |
1083 // JSON cannot store int64_t, so expiration is converted to a string. | 1111 // JSON cannot store int64_t, so expiration is converted to a string. |
1084 alternative_service_dict->SetString( | 1112 alternative_service_dict->SetString( |
1085 kExpirationKey, | 1113 kExpirationKey, |
1086 base::Int64ToString( | 1114 base::Int64ToString( |
1087 alternative_service_info.expiration.ToInternalValue())); | 1115 alternative_service_info.expiration.ToInternalValue())); |
| 1116 std::unique_ptr<base::ListValue> advertised_versions_list( |
| 1117 new base::ListValue); |
| 1118 for (const auto& version : alternative_service_info.advertised_versions()) { |
| 1119 advertised_versions_list->AppendInteger(version); |
| 1120 } |
| 1121 alternative_service_dict->SetList(kAdvertisedVersionsKey, |
| 1122 std::move(advertised_versions_list)); |
1088 alternative_service_list->Append(std::move(alternative_service_dict)); | 1123 alternative_service_list->Append(std::move(alternative_service_dict)); |
1089 } | 1124 } |
1090 if (alternative_service_list->GetSize() == 0) | 1125 if (alternative_service_list->GetSize() == 0) |
1091 return; | 1126 return; |
1092 server_pref_dict->SetWithoutPathExpansion( | 1127 server_pref_dict->SetWithoutPathExpansion( |
1093 kAlternativeServiceKey, std::move(alternative_service_list)); | 1128 kAlternativeServiceKey, std::move(alternative_service_list)); |
1094 } | 1129 } |
1095 | 1130 |
1096 void HttpServerPropertiesManager::SaveSupportsQuicToPrefs( | 1131 void HttpServerPropertiesManager::SaveSupportsQuicToPrefs( |
1097 const IPAddress* last_quic_address, | 1132 const IPAddress* last_quic_address, |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1147 if (!setting_prefs_) | 1182 if (!setting_prefs_) |
1148 ScheduleUpdateCacheOnPrefThread(); | 1183 ScheduleUpdateCacheOnPrefThread(); |
1149 } | 1184 } |
1150 | 1185 |
1151 void HttpServerPropertiesManager::SetInitialized() { | 1186 void HttpServerPropertiesManager::SetInitialized() { |
1152 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 1187 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
1153 is_initialized_ = true; | 1188 is_initialized_ = true; |
1154 } | 1189 } |
1155 | 1190 |
1156 } // namespace net | 1191 } // namespace net |
OLD | NEW |