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