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 std::unique_ptr<base::Value> NetLogCallback( | 69 std::unique_ptr<base::Value> NetLogCallback( |
69 const base::DictionaryValue& http_server_properties_dict, | 70 const base::DictionaryValue& http_server_properties_dict, |
70 NetLogCaptureMode capture_mode) { | 71 NetLogCaptureMode capture_mode) { |
71 return base::WrapUnique<base::DictionaryValue>( | 72 return base::WrapUnique<base::DictionaryValue>( |
72 http_server_properties_dict.DeepCopy()); | 73 http_server_properties_dict.DeepCopy()); |
73 } | 74 } |
74 | 75 |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 http_server_properties_impl_->MaybeForceHTTP11(server, ssl_config); | 205 http_server_properties_impl_->MaybeForceHTTP11(server, ssl_config); |
205 } | 206 } |
206 | 207 |
207 AlternativeServiceInfoVector | 208 AlternativeServiceInfoVector |
208 HttpServerPropertiesManager::GetAlternativeServiceInfos( | 209 HttpServerPropertiesManager::GetAlternativeServiceInfos( |
209 const url::SchemeHostPort& origin) { | 210 const url::SchemeHostPort& origin) { |
210 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); | 211 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); |
211 return http_server_properties_impl_->GetAlternativeServiceInfos(origin); | 212 return http_server_properties_impl_->GetAlternativeServiceInfos(origin); |
212 } | 213 } |
213 | 214 |
214 bool HttpServerPropertiesManager::SetAlternativeService( | 215 bool HttpServerPropertiesManager::SetHttp2AlternativeService( |
215 const url::SchemeHostPort& origin, | 216 const url::SchemeHostPort& origin, |
216 const AlternativeService& alternative_service, | 217 const AlternativeService& alternative_service, |
217 base::Time expiration) { | 218 base::Time expiration) { |
218 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); | 219 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); |
219 const bool changed = http_server_properties_impl_->SetAlternativeService( | 220 const bool changed = http_server_properties_impl_->SetHttp2AlternativeService( |
220 origin, alternative_service, expiration); | 221 origin, alternative_service, expiration); |
221 if (changed) { | 222 if (changed) { |
222 ScheduleUpdatePrefsOnNetworkSequence(SET_ALTERNATIVE_SERVICES); | 223 ScheduleUpdatePrefsOnNetworkSequence(SET_ALTERNATIVE_SERVICES); |
223 } | 224 } |
224 return changed; | 225 return changed; |
225 } | 226 } |
226 | 227 |
| 228 bool HttpServerPropertiesManager::SetQuicAlternativeService( |
| 229 const url::SchemeHostPort& origin, |
| 230 const AlternativeService& alternative_service, |
| 231 base::Time expiration, |
| 232 const QuicVersionVector& advertised_versions) { |
| 233 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); |
| 234 const bool changed = http_server_properties_impl_->SetQuicAlternativeService( |
| 235 origin, alternative_service, expiration, advertised_versions); |
| 236 if (changed) { |
| 237 ScheduleUpdatePrefsOnNetworkSequence(SET_ALTERNATIVE_SERVICES); |
| 238 } |
| 239 return changed; |
| 240 } |
| 241 |
227 bool HttpServerPropertiesManager::SetAlternativeServices( | 242 bool HttpServerPropertiesManager::SetAlternativeServices( |
228 const url::SchemeHostPort& origin, | 243 const url::SchemeHostPort& origin, |
229 const AlternativeServiceInfoVector& alternative_service_info_vector) { | 244 const AlternativeServiceInfoVector& alternative_service_info_vector) { |
230 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); | 245 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); |
231 const bool changed = http_server_properties_impl_->SetAlternativeServices( | 246 const bool changed = http_server_properties_impl_->SetAlternativeServices( |
232 origin, alternative_service_info_vector); | 247 origin, alternative_service_info_vector); |
233 if (changed) { | 248 if (changed) { |
234 ScheduleUpdatePrefsOnNetworkSequence(SET_ALTERNATIVE_SERVICES); | 249 ScheduleUpdatePrefsOnNetworkSequence(SET_ALTERNATIVE_SERVICES); |
235 } | 250 } |
236 return changed; | 251 return changed; |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 | 644 |
630 // Expiration is optional, defaults to one day. | 645 // Expiration is optional, defaults to one day. |
631 base::Time expiration; | 646 base::Time expiration; |
632 if (!alternative_service_dict.HasKey(kExpirationKey)) { | 647 if (!alternative_service_dict.HasKey(kExpirationKey)) { |
633 alternative_service_info->set_expiration(base::Time::Now() + | 648 alternative_service_info->set_expiration(base::Time::Now() + |
634 base::TimeDelta::FromDays(1)); | 649 base::TimeDelta::FromDays(1)); |
635 return true; | 650 return true; |
636 } | 651 } |
637 | 652 |
638 std::string expiration_string; | 653 std::string expiration_string; |
639 if (alternative_service_dict.GetStringWithoutPathExpansion( | 654 if (!alternative_service_dict.GetStringWithoutPathExpansion( |
640 kExpirationKey, &expiration_string)) { | 655 kExpirationKey, &expiration_string)) { |
641 int64_t expiration_int64 = 0; | 656 DVLOG(1) << "Malformed alternative service expiration for server: " |
642 if (!base::StringToInt64(expiration_string, &expiration_int64)) { | 657 << server_str; |
643 DVLOG(1) << "Malformed alternative service expiration for server: " | 658 return false; |
| 659 } |
| 660 |
| 661 int64_t expiration_int64 = 0; |
| 662 if (!base::StringToInt64(expiration_string, &expiration_int64)) { |
| 663 DVLOG(1) << "Malformed alternative service expiration for server: " |
| 664 << server_str; |
| 665 return false; |
| 666 } |
| 667 alternative_service_info->set_expiration( |
| 668 base::Time::FromInternalValue(expiration_int64)); |
| 669 |
| 670 // Advertised versions list is optional. |
| 671 if (!alternative_service_dict.HasKey(kAdvertisedVersionsKey)) |
| 672 return true; |
| 673 |
| 674 const base::ListValue* versions_list = nullptr; |
| 675 if (!alternative_service_dict.GetListWithoutPathExpansion( |
| 676 kAdvertisedVersionsKey, &versions_list)) { |
| 677 DVLOG(1) |
| 678 << "Malformed alternative service advertised versions list for server: " |
| 679 << server_str; |
| 680 return false; |
| 681 } |
| 682 |
| 683 QuicVersionVector advertised_versions; |
| 684 for (const auto& value : *versions_list) { |
| 685 int version; |
| 686 if (!value.GetAsInteger(&version)) { |
| 687 DVLOG(1) << "Malformed alternative service version for server: " |
644 << server_str; | 688 << server_str; |
645 return false; | 689 return false; |
646 } | 690 } |
647 alternative_service_info->set_expiration( | 691 advertised_versions.push_back(QuicVersion(version)); |
648 base::Time::FromInternalValue(expiration_int64)); | |
649 return true; | |
650 } | 692 } |
| 693 alternative_service_info->set_advertised_versions(advertised_versions); |
651 | 694 |
652 DVLOG(1) << "Malformed alternative service expiration for server: " | 695 return true; |
653 << server_str; | |
654 return false; | |
655 } | 696 } |
656 | 697 |
657 bool HttpServerPropertiesManager::AddToAlternativeServiceMap( | 698 bool HttpServerPropertiesManager::AddToAlternativeServiceMap( |
658 const url::SchemeHostPort& server, | 699 const url::SchemeHostPort& server, |
659 const base::DictionaryValue& server_pref_dict, | 700 const base::DictionaryValue& server_pref_dict, |
660 AlternativeServiceMap* alternative_service_map) { | 701 AlternativeServiceMap* alternative_service_map) { |
661 DCHECK(alternative_service_map->Peek(server) == | 702 DCHECK(alternative_service_map->Peek(server) == |
662 alternative_service_map->end()); | 703 alternative_service_map->end()); |
663 const base::ListValue* alternative_service_list; | 704 const base::ListValue* alternative_service_list; |
664 if (!server_pref_dict.GetListWithoutPathExpansion( | 705 if (!server_pref_dict.GetListWithoutPathExpansion( |
(...skipping 449 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1114 if (!alternative_service.host.empty()) { | 1155 if (!alternative_service.host.empty()) { |
1115 alternative_service_dict->SetString(kHostKey, alternative_service.host); | 1156 alternative_service_dict->SetString(kHostKey, alternative_service.host); |
1116 } | 1157 } |
1117 alternative_service_dict->SetString( | 1158 alternative_service_dict->SetString( |
1118 kProtocolKey, NextProtoToString(alternative_service.protocol)); | 1159 kProtocolKey, NextProtoToString(alternative_service.protocol)); |
1119 // JSON cannot store int64_t, so expiration is converted to a string. | 1160 // JSON cannot store int64_t, so expiration is converted to a string. |
1120 alternative_service_dict->SetString( | 1161 alternative_service_dict->SetString( |
1121 kExpirationKey, | 1162 kExpirationKey, |
1122 base::Int64ToString( | 1163 base::Int64ToString( |
1123 alternative_service_info.expiration().ToInternalValue())); | 1164 alternative_service_info.expiration().ToInternalValue())); |
| 1165 std::unique_ptr<base::ListValue> advertised_versions_list = |
| 1166 base::MakeUnique<base::ListValue>(); |
| 1167 for (const auto& version : alternative_service_info.advertised_versions()) { |
| 1168 advertised_versions_list->AppendInteger(version); |
| 1169 } |
| 1170 alternative_service_dict->SetList(kAdvertisedVersionsKey, |
| 1171 std::move(advertised_versions_list)); |
1124 alternative_service_list->Append(std::move(alternative_service_dict)); | 1172 alternative_service_list->Append(std::move(alternative_service_dict)); |
1125 } | 1173 } |
1126 if (alternative_service_list->GetSize() == 0) | 1174 if (alternative_service_list->GetSize() == 0) |
1127 return; | 1175 return; |
1128 server_pref_dict->SetWithoutPathExpansion( | 1176 server_pref_dict->SetWithoutPathExpansion( |
1129 kAlternativeServiceKey, std::move(alternative_service_list)); | 1177 kAlternativeServiceKey, std::move(alternative_service_list)); |
1130 } | 1178 } |
1131 | 1179 |
1132 void HttpServerPropertiesManager::SaveSupportsQuicToPrefs( | 1180 void HttpServerPropertiesManager::SaveSupportsQuicToPrefs( |
1133 const IPAddress& last_quic_address, | 1181 const IPAddress& last_quic_address, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1179 ScheduleUpdateCacheOnPrefThread(); | 1227 ScheduleUpdateCacheOnPrefThread(); |
1180 } | 1228 } |
1181 | 1229 |
1182 void HttpServerPropertiesManager::SetInitialized() { | 1230 void HttpServerPropertiesManager::SetInitialized() { |
1183 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); | 1231 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); |
1184 is_initialized_ = true; | 1232 is_initialized_ = true; |
1185 net_log_.EndEvent(NetLogEventType::HTTP_SERVER_PROPERTIES_INITIALIZATION); | 1233 net_log_.EndEvent(NetLogEventType::HTTP_SERVER_PROPERTIES_INITIALIZATION); |
1186 } | 1234 } |
1187 | 1235 |
1188 } // namespace net | 1236 } // namespace net |
OLD | NEW |