| 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 "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 const char kSettingsKey[] = "settings"; | 54 const char kSettingsKey[] = "settings"; |
| 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 kProbabilityKey[] = "probability"; |
| 64 const char kExpirationKey[] = "expiration"; | 65 const char kExpirationKey[] = "expiration"; |
| 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() {} |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 | 188 |
| 188 AlternativeServiceVector HttpServerPropertiesManager::GetAlternativeServices( | 189 AlternativeServiceVector HttpServerPropertiesManager::GetAlternativeServices( |
| 189 const HostPortPair& origin) { | 190 const HostPortPair& origin) { |
| 190 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 191 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 191 return http_server_properties_impl_->GetAlternativeServices(origin); | 192 return http_server_properties_impl_->GetAlternativeServices(origin); |
| 192 } | 193 } |
| 193 | 194 |
| 194 bool HttpServerPropertiesManager::SetAlternativeService( | 195 bool HttpServerPropertiesManager::SetAlternativeService( |
| 195 const HostPortPair& origin, | 196 const HostPortPair& origin, |
| 196 const AlternativeService& alternative_service, | 197 const AlternativeService& alternative_service, |
| 198 double alternative_probability, |
| 197 base::Time expiration) { | 199 base::Time expiration) { |
| 198 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 200 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 199 const bool changed = http_server_properties_impl_->SetAlternativeService( | 201 const bool changed = http_server_properties_impl_->SetAlternativeService( |
| 200 origin, alternative_service, expiration); | 202 origin, alternative_service, alternative_probability, expiration); |
| 201 if (changed) { | 203 if (changed) { |
| 202 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES); | 204 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES); |
| 203 } | 205 } |
| 204 return changed; | 206 return changed; |
| 205 } | 207 } |
| 206 | 208 |
| 207 bool HttpServerPropertiesManager::SetAlternativeServices( | 209 bool HttpServerPropertiesManager::SetAlternativeServices( |
| 208 const HostPortPair& origin, | 210 const HostPortPair& origin, |
| 209 const AlternativeServiceInfoVector& alternative_service_info_vector) { | 211 const AlternativeServiceInfoVector& alternative_service_info_vector) { |
| 210 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 212 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 return http_server_properties_impl_->alternative_service_map(); | 281 return http_server_properties_impl_->alternative_service_map(); |
| 280 } | 282 } |
| 281 | 283 |
| 282 scoped_ptr<base::Value> | 284 scoped_ptr<base::Value> |
| 283 HttpServerPropertiesManager::GetAlternativeServiceInfoAsValue() | 285 HttpServerPropertiesManager::GetAlternativeServiceInfoAsValue() |
| 284 const { | 286 const { |
| 285 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 287 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 286 return http_server_properties_impl_->GetAlternativeServiceInfoAsValue(); | 288 return http_server_properties_impl_->GetAlternativeServiceInfoAsValue(); |
| 287 } | 289 } |
| 288 | 290 |
| 291 void HttpServerPropertiesManager::SetAlternativeServiceProbabilityThreshold( |
| 292 double threshold) { |
| 293 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 294 http_server_properties_impl_->SetAlternativeServiceProbabilityThreshold( |
| 295 threshold); |
| 296 } |
| 297 |
| 289 const SettingsMap& HttpServerPropertiesManager::GetSpdySettings( | 298 const SettingsMap& HttpServerPropertiesManager::GetSpdySettings( |
| 290 const HostPortPair& host_port_pair) { | 299 const HostPortPair& host_port_pair) { |
| 291 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 300 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 292 return http_server_properties_impl_->GetSpdySettings(host_port_pair); | 301 return http_server_properties_impl_->GetSpdySettings(host_port_pair); |
| 293 } | 302 } |
| 294 | 303 |
| 295 bool HttpServerPropertiesManager::SetSpdySetting( | 304 bool HttpServerPropertiesManager::SetSpdySetting( |
| 296 const HostPortPair& host_port_pair, | 305 const HostPortPair& host_port_pair, |
| 297 SpdySettingsIds id, | 306 SpdySettingsIds id, |
| 298 SpdySettingsFlags flags, | 307 SpdySettingsFlags flags, |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 646 // Port is mandatory. | 655 // Port is mandatory. |
| 647 int port = 0; | 656 int port = 0; |
| 648 if (!alternative_service_dict.GetInteger(kPortKey, &port) || | 657 if (!alternative_service_dict.GetInteger(kPortKey, &port) || |
| 649 !IsPortValid(port)) { | 658 !IsPortValid(port)) { |
| 650 DVLOG(1) << "Malformed alternative service port for server: " << server_str; | 659 DVLOG(1) << "Malformed alternative service port for server: " << server_str; |
| 651 return false; | 660 return false; |
| 652 } | 661 } |
| 653 alternative_service_info->alternative_service.port = | 662 alternative_service_info->alternative_service.port = |
| 654 static_cast<uint32_t>(port); | 663 static_cast<uint32_t>(port); |
| 655 | 664 |
| 665 // Probability is optional, defaults to 1.0. |
| 666 alternative_service_info->probability = 1.0; |
| 667 if (alternative_service_dict.HasKey(kProbabilityKey) && |
| 668 !alternative_service_dict.GetDoubleWithoutPathExpansion( |
| 669 kProbabilityKey, &(alternative_service_info->probability))) { |
| 670 DVLOG(1) << "Malformed alternative service probability for server: " |
| 671 << server_str; |
| 672 return false; |
| 673 } |
| 674 |
| 656 // Expiration is optional, defaults to one day. | 675 // Expiration is optional, defaults to one day. |
| 657 base::Time expiration; | 676 base::Time expiration; |
| 658 if (!alternative_service_dict.HasKey(kExpirationKey)) { | 677 if (!alternative_service_dict.HasKey(kExpirationKey)) { |
| 659 alternative_service_info->expiration = | 678 alternative_service_info->expiration = |
| 660 base::Time::Now() + base::TimeDelta::FromDays(1); | 679 base::Time::Now() + base::TimeDelta::FromDays(1); |
| 661 return true; | 680 return true; |
| 662 } | 681 } |
| 663 | 682 |
| 664 std::string expiration_string; | 683 std::string expiration_string; |
| 665 if (alternative_service_dict.GetStringWithoutPathExpansion( | 684 if (alternative_service_dict.GetStringWithoutPathExpansion( |
| (...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1170 const AlternativeService alternative_service = | 1189 const AlternativeService alternative_service = |
| 1171 alternative_service_info.alternative_service; | 1190 alternative_service_info.alternative_service; |
| 1172 DCHECK(IsAlternateProtocolValid(alternative_service.protocol)); | 1191 DCHECK(IsAlternateProtocolValid(alternative_service.protocol)); |
| 1173 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; | 1192 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; |
| 1174 alternative_service_dict->SetInteger(kPortKey, alternative_service.port); | 1193 alternative_service_dict->SetInteger(kPortKey, alternative_service.port); |
| 1175 if (!alternative_service.host.empty()) { | 1194 if (!alternative_service.host.empty()) { |
| 1176 alternative_service_dict->SetString(kHostKey, alternative_service.host); | 1195 alternative_service_dict->SetString(kHostKey, alternative_service.host); |
| 1177 } | 1196 } |
| 1178 alternative_service_dict->SetString( | 1197 alternative_service_dict->SetString( |
| 1179 kProtocolKey, AlternateProtocolToString(alternative_service.protocol)); | 1198 kProtocolKey, AlternateProtocolToString(alternative_service.protocol)); |
| 1199 alternative_service_dict->SetDouble(kProbabilityKey, |
| 1200 alternative_service_info.probability); |
| 1180 // JSON cannot store int64_t, so expiration is converted to a string. | 1201 // JSON cannot store int64_t, so expiration is converted to a string. |
| 1181 alternative_service_dict->SetString( | 1202 alternative_service_dict->SetString( |
| 1182 kExpirationKey, | 1203 kExpirationKey, |
| 1183 base::Int64ToString( | 1204 base::Int64ToString( |
| 1184 alternative_service_info.expiration.ToInternalValue())); | 1205 alternative_service_info.expiration.ToInternalValue())); |
| 1185 alternative_service_list->Append(alternative_service_dict); | 1206 alternative_service_list->Append(alternative_service_dict); |
| 1186 } | 1207 } |
| 1187 if (alternative_service_list->GetSize() == 0) | 1208 if (alternative_service_list->GetSize() == 0) |
| 1188 return; | 1209 return; |
| 1189 server_pref_dict->SetWithoutPathExpansion(kAlternativeServiceKey, | 1210 server_pref_dict->SetWithoutPathExpansion(kAlternativeServiceKey, |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1239 quic_servers_dict); | 1260 quic_servers_dict); |
| 1240 } | 1261 } |
| 1241 | 1262 |
| 1242 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { | 1263 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { |
| 1243 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 1264 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
| 1244 if (!setting_prefs_) | 1265 if (!setting_prefs_) |
| 1245 ScheduleUpdateCacheOnPrefThread(); | 1266 ScheduleUpdateCacheOnPrefThread(); |
| 1246 } | 1267 } |
| 1247 | 1268 |
| 1248 } // namespace net | 1269 } // namespace net |
| OLD | NEW |