| 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" |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/stringprintf.h" | 12 #include "base/strings/stringprintf.h" |
| 13 #include "base/thread_task_runner_handle.h" | 13 #include "base/thread_task_runner_handle.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "net/base/ip_address.h" | 15 #include "net/base/ip_address.h" |
| 16 #include "net/base/port_util.h" | 16 #include "net/base/port_util.h" |
| 17 #include "url/gurl.h" |
| 17 | 18 |
| 18 namespace net { | 19 namespace net { |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 22 // Time to wait before starting an update the http_server_properties_impl_ cache | 23 // Time to wait before starting an update the http_server_properties_impl_ cache |
| 23 // from preferences. Scheduling another update during this period will reset the | 24 // from preferences. Scheduling another update during this period will reset the |
| 24 // timer. | 25 // timer. |
| 25 const int64_t kUpdateCacheDelayMs = 1000; | 26 const int64_t kUpdateCacheDelayMs = 1000; |
| 26 | 27 |
| 27 // Time to wait before starting an update the preferences from the | 28 // Time to wait before starting an update the preferences from the |
| 28 // http_server_properties_impl_ cache. Scheduling another update during this | 29 // http_server_properties_impl_ cache. Scheduling another update during this |
| 29 // period will reset the timer. | 30 // period will reset the timer. |
| 30 const int64_t kUpdatePrefsDelayMs = 60000; | 31 const int64_t kUpdatePrefsDelayMs = 60000; |
| 31 | 32 |
| 32 // "version" 0 indicates, http_server_properties doesn't have "version" | 33 // "version" 0 indicates, http_server_properties doesn't have "version" |
| 33 // property. | 34 // property. |
| 34 const int kMissingVersion = 0; | 35 const int kMissingVersion = 0; |
| 35 | 36 |
| 36 // The version number of persisted http_server_properties. | 37 // The version number of persisted http_server_properties. |
| 37 const int kVersionNumber = 4; | 38 const int kVersionNumber = 5; |
| 38 | 39 |
| 39 // Persist 200 MRU AlternateProtocolHostPortPairs. | 40 // Persist 200 MRU AlternateProtocolHostPortPairs. |
| 40 const int kMaxAlternateProtocolHostsToPersist = 200; | 41 const int kMaxAlternateProtocolHostsToPersist = 200; |
| 41 | 42 |
| 42 // Persist 200 MRU SpdySettingsHostPortPairs. | 43 // Persist 200 MRU SpdySettingsHostPortPairs. |
| 43 const int kMaxSpdySettingsHostsToPersist = 200; | 44 const int kMaxSpdySettingsHostsToPersist = 200; |
| 44 | 45 |
| 45 // Persist 300 MRU SupportsSpdyServerHostPortPairs. | 46 // Persist 300 MRU SupportsSpdyServerHostPortPairs. |
| 46 const int kMaxSupportsSpdyServerHostsToPersist = 300; | 47 const int kMaxSupportsSpdyServerHostsToPersist = 300; |
| 47 | 48 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 138 } | 139 } |
| 139 | 140 |
| 140 void HttpServerPropertiesManager::Clear(const base::Closure& completion) { | 141 void HttpServerPropertiesManager::Clear(const base::Closure& completion) { |
| 141 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 142 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 142 | 143 |
| 143 http_server_properties_impl_->Clear(); | 144 http_server_properties_impl_->Clear(); |
| 144 UpdatePrefsFromCacheOnNetworkThread(completion); | 145 UpdatePrefsFromCacheOnNetworkThread(completion); |
| 145 } | 146 } |
| 146 | 147 |
| 147 bool HttpServerPropertiesManager::SupportsRequestPriority( | 148 bool HttpServerPropertiesManager::SupportsRequestPriority( |
| 148 const HostPortPair& server) { | 149 const url::SchemeHostPort& server) { |
| 149 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 150 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 150 return http_server_properties_impl_->SupportsRequestPriority(server); | 151 return http_server_properties_impl_->SupportsRequestPriority(server); |
| 151 } | 152 } |
| 152 | 153 |
| 153 bool HttpServerPropertiesManager::GetSupportsSpdy(const HostPortPair& server) { | 154 bool HttpServerPropertiesManager::GetSupportsSpdy( |
| 155 const url::SchemeHostPort& server) { |
| 154 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 156 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 155 return http_server_properties_impl_->GetSupportsSpdy(server); | 157 return http_server_properties_impl_->GetSupportsSpdy(server); |
| 156 } | 158 } |
| 157 | 159 |
| 158 void HttpServerPropertiesManager::SetSupportsSpdy(const HostPortPair& server, | 160 void HttpServerPropertiesManager::SetSupportsSpdy( |
| 159 bool support_spdy) { | 161 const url::SchemeHostPort& server, |
| 162 bool support_spdy) { |
| 160 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 163 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 161 | 164 |
| 162 bool old_support_spdy = http_server_properties_impl_->GetSupportsSpdy(server); | 165 bool old_support_spdy = http_server_properties_impl_->GetSupportsSpdy(server); |
| 163 http_server_properties_impl_->SetSupportsSpdy(server, support_spdy); | 166 http_server_properties_impl_->SetSupportsSpdy(server, support_spdy); |
| 164 bool new_support_spdy = http_server_properties_impl_->GetSupportsSpdy(server); | 167 bool new_support_spdy = http_server_properties_impl_->GetSupportsSpdy(server); |
| 165 if (old_support_spdy != new_support_spdy) | 168 if (old_support_spdy != new_support_spdy) |
| 166 ScheduleUpdatePrefsOnNetworkThread(SUPPORTS_SPDY); | 169 ScheduleUpdatePrefsOnNetworkThread(SUPPORTS_SPDY); |
| 167 } | 170 } |
| 168 | 171 |
| 169 bool HttpServerPropertiesManager::RequiresHTTP11(const HostPortPair& server) { | 172 bool HttpServerPropertiesManager::RequiresHTTP11(const HostPortPair& server) { |
| 170 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 173 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 171 return http_server_properties_impl_->RequiresHTTP11(server); | 174 return http_server_properties_impl_->RequiresHTTP11(server); |
| 172 } | 175 } |
| 173 | 176 |
| 174 void HttpServerPropertiesManager::SetHTTP11Required( | 177 void HttpServerPropertiesManager::SetHTTP11Required( |
| 175 const HostPortPair& server) { | 178 const HostPortPair& server) { |
| 176 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 179 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 177 | 180 |
| 178 http_server_properties_impl_->SetHTTP11Required(server); | 181 http_server_properties_impl_->SetHTTP11Required(server); |
| 179 ScheduleUpdatePrefsOnNetworkThread(HTTP_11_REQUIRED); | 182 ScheduleUpdatePrefsOnNetworkThread(HTTP_11_REQUIRED); |
| 180 } | 183 } |
| 181 | 184 |
| 182 void HttpServerPropertiesManager::MaybeForceHTTP11(const HostPortPair& server, | 185 void HttpServerPropertiesManager::MaybeForceHTTP11(const HostPortPair& server, |
| 183 SSLConfig* ssl_config) { | 186 SSLConfig* ssl_config) { |
| 184 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 187 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 185 http_server_properties_impl_->MaybeForceHTTP11(server, ssl_config); | 188 http_server_properties_impl_->MaybeForceHTTP11(server, ssl_config); |
| 186 } | 189 } |
| 187 | 190 |
| 188 AlternativeServiceVector HttpServerPropertiesManager::GetAlternativeServices( | 191 AlternativeServiceVector HttpServerPropertiesManager::GetAlternativeServices( |
| 189 const HostPortPair& origin) { | 192 const url::SchemeHostPort& origin) { |
| 190 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 193 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 191 return http_server_properties_impl_->GetAlternativeServices(origin); | 194 return http_server_properties_impl_->GetAlternativeServices(origin); |
| 192 } | 195 } |
| 193 | 196 |
| 194 bool HttpServerPropertiesManager::SetAlternativeService( | 197 bool HttpServerPropertiesManager::SetAlternativeService( |
| 195 const HostPortPair& origin, | 198 const url::SchemeHostPort& origin, |
| 196 const AlternativeService& alternative_service, | 199 const AlternativeService& alternative_service, |
| 197 base::Time expiration) { | 200 base::Time expiration) { |
| 198 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 201 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 199 const bool changed = http_server_properties_impl_->SetAlternativeService( | 202 const bool changed = http_server_properties_impl_->SetAlternativeService( |
| 200 origin, alternative_service, expiration); | 203 origin, alternative_service, expiration); |
| 201 if (changed) { | 204 if (changed) { |
| 202 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES); | 205 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES); |
| 203 } | 206 } |
| 204 return changed; | 207 return changed; |
| 205 } | 208 } |
| 206 | 209 |
| 207 bool HttpServerPropertiesManager::SetAlternativeServices( | 210 bool HttpServerPropertiesManager::SetAlternativeServices( |
| 208 const HostPortPair& origin, | 211 const url::SchemeHostPort& origin, |
| 209 const AlternativeServiceInfoVector& alternative_service_info_vector) { | 212 const AlternativeServiceInfoVector& alternative_service_info_vector) { |
| 210 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 213 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 211 const bool changed = http_server_properties_impl_->SetAlternativeServices( | 214 const bool changed = http_server_properties_impl_->SetAlternativeServices( |
| 212 origin, alternative_service_info_vector); | 215 origin, alternative_service_info_vector); |
| 213 if (changed) { | 216 if (changed) { |
| 214 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES); | 217 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES); |
| 215 } | 218 } |
| 216 return changed; | 219 return changed; |
| 217 } | 220 } |
| 218 | 221 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 http_server_properties_impl_->ConfirmAlternativeService(alternative_service); | 257 http_server_properties_impl_->ConfirmAlternativeService(alternative_service); |
| 255 bool new_value = http_server_properties_impl_->IsAlternativeServiceBroken( | 258 bool new_value = http_server_properties_impl_->IsAlternativeServiceBroken( |
| 256 alternative_service); | 259 alternative_service); |
| 257 // For persisting, we only care about the value returned by | 260 // For persisting, we only care about the value returned by |
| 258 // IsAlternativeServiceBroken. If that value changes, then call persist. | 261 // IsAlternativeServiceBroken. If that value changes, then call persist. |
| 259 if (old_value != new_value) | 262 if (old_value != new_value) |
| 260 ScheduleUpdatePrefsOnNetworkThread(CONFIRM_ALTERNATIVE_SERVICE); | 263 ScheduleUpdatePrefsOnNetworkThread(CONFIRM_ALTERNATIVE_SERVICE); |
| 261 } | 264 } |
| 262 | 265 |
| 263 void HttpServerPropertiesManager::ClearAlternativeServices( | 266 void HttpServerPropertiesManager::ClearAlternativeServices( |
| 264 const HostPortPair& origin) { | 267 const url::SchemeHostPort& origin) { |
| 265 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 268 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 266 const AlternativeServiceMap& map = | 269 const AlternativeServiceMap& map = |
| 267 http_server_properties_impl_->alternative_service_map(); | 270 http_server_properties_impl_->alternative_service_map(); |
| 268 size_t old_size = map.size(); | 271 size_t old_size = map.size(); |
| 269 http_server_properties_impl_->ClearAlternativeServices(origin); | 272 http_server_properties_impl_->ClearAlternativeServices(origin); |
| 270 size_t new_size = map.size(); | 273 size_t new_size = map.size(); |
| 271 // Persist only if we have deleted an entry. | 274 // Persist only if we have deleted an entry. |
| 272 if (old_size != new_size) | 275 if (old_size != new_size) |
| 273 ScheduleUpdatePrefsOnNetworkThread(CLEAR_ALTERNATIVE_SERVICE); | 276 ScheduleUpdatePrefsOnNetworkThread(CLEAR_ALTERNATIVE_SERVICE); |
| 274 } | 277 } |
| 275 | 278 |
| 276 const AlternativeServiceMap& | 279 const AlternativeServiceMap& |
| 277 HttpServerPropertiesManager::alternative_service_map() const { | 280 HttpServerPropertiesManager::alternative_service_map() const { |
| 278 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 281 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 279 return http_server_properties_impl_->alternative_service_map(); | 282 return http_server_properties_impl_->alternative_service_map(); |
| 280 } | 283 } |
| 281 | 284 |
| 282 std::unique_ptr<base::Value> | 285 std::unique_ptr<base::Value> |
| 283 HttpServerPropertiesManager::GetAlternativeServiceInfoAsValue() const { | 286 HttpServerPropertiesManager::GetAlternativeServiceInfoAsValue() const { |
| 284 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 287 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 285 return http_server_properties_impl_->GetAlternativeServiceInfoAsValue(); | 288 return http_server_properties_impl_->GetAlternativeServiceInfoAsValue(); |
| 286 } | 289 } |
| 287 | 290 |
| 288 const SettingsMap& HttpServerPropertiesManager::GetSpdySettings( | 291 const SettingsMap& HttpServerPropertiesManager::GetSpdySettings( |
| 289 const HostPortPair& host_port_pair) { | 292 const url::SchemeHostPort& server) { |
| 290 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 293 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 291 return http_server_properties_impl_->GetSpdySettings(host_port_pair); | 294 return http_server_properties_impl_->GetSpdySettings(server); |
| 292 } | 295 } |
| 293 | 296 |
| 294 bool HttpServerPropertiesManager::SetSpdySetting( | 297 bool HttpServerPropertiesManager::SetSpdySetting( |
| 295 const HostPortPair& host_port_pair, | 298 const url::SchemeHostPort& server, |
| 296 SpdySettingsIds id, | 299 SpdySettingsIds id, |
| 297 SpdySettingsFlags flags, | 300 SpdySettingsFlags flags, |
| 298 uint32_t value) { | 301 uint32_t value) { |
| 299 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 302 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 300 bool persist = http_server_properties_impl_->SetSpdySetting( | 303 bool persist = |
| 301 host_port_pair, id, flags, value); | 304 http_server_properties_impl_->SetSpdySetting(server, id, flags, value); |
| 302 if (persist) | 305 if (persist) |
| 303 ScheduleUpdatePrefsOnNetworkThread(SET_SPDY_SETTING); | 306 ScheduleUpdatePrefsOnNetworkThread(SET_SPDY_SETTING); |
| 304 return persist; | 307 return persist; |
| 305 } | 308 } |
| 306 | 309 |
| 307 void HttpServerPropertiesManager::ClearSpdySettings( | 310 void HttpServerPropertiesManager::ClearSpdySettings( |
| 308 const HostPortPair& host_port_pair) { | 311 const url::SchemeHostPort& server) { |
| 309 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 312 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 310 http_server_properties_impl_->ClearSpdySettings(host_port_pair); | 313 http_server_properties_impl_->ClearSpdySettings(server); |
| 311 ScheduleUpdatePrefsOnNetworkThread(CLEAR_SPDY_SETTINGS); | 314 ScheduleUpdatePrefsOnNetworkThread(CLEAR_SPDY_SETTINGS); |
| 312 } | 315 } |
| 313 | 316 |
| 314 void HttpServerPropertiesManager::ClearAllSpdySettings() { | 317 void HttpServerPropertiesManager::ClearAllSpdySettings() { |
| 315 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 318 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 316 http_server_properties_impl_->ClearAllSpdySettings(); | 319 http_server_properties_impl_->ClearAllSpdySettings(); |
| 317 ScheduleUpdatePrefsOnNetworkThread(CLEAR_ALL_SPDY_SETTINGS); | 320 ScheduleUpdatePrefsOnNetworkThread(CLEAR_ALL_SPDY_SETTINGS); |
| 318 } | 321 } |
| 319 | 322 |
| 320 const SpdySettingsMap& HttpServerPropertiesManager::spdy_settings_map() | 323 const SpdySettingsMap& HttpServerPropertiesManager::spdy_settings_map() |
| (...skipping 14 matching lines...) Expand all Loading... |
| 335 IPAddress old_last_quic_addr; | 338 IPAddress old_last_quic_addr; |
| 336 http_server_properties_impl_->GetSupportsQuic(&old_last_quic_addr); | 339 http_server_properties_impl_->GetSupportsQuic(&old_last_quic_addr); |
| 337 http_server_properties_impl_->SetSupportsQuic(used_quic, address); | 340 http_server_properties_impl_->SetSupportsQuic(used_quic, address); |
| 338 IPAddress new_last_quic_addr; | 341 IPAddress new_last_quic_addr; |
| 339 http_server_properties_impl_->GetSupportsQuic(&new_last_quic_addr); | 342 http_server_properties_impl_->GetSupportsQuic(&new_last_quic_addr); |
| 340 if (old_last_quic_addr != new_last_quic_addr) | 343 if (old_last_quic_addr != new_last_quic_addr) |
| 341 ScheduleUpdatePrefsOnNetworkThread(SET_SUPPORTS_QUIC); | 344 ScheduleUpdatePrefsOnNetworkThread(SET_SUPPORTS_QUIC); |
| 342 } | 345 } |
| 343 | 346 |
| 344 void HttpServerPropertiesManager::SetServerNetworkStats( | 347 void HttpServerPropertiesManager::SetServerNetworkStats( |
| 345 const HostPortPair& host_port_pair, | 348 const url::SchemeHostPort& server, |
| 346 ServerNetworkStats stats) { | 349 ServerNetworkStats stats) { |
| 347 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 350 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 348 ServerNetworkStats old_stats; | 351 ServerNetworkStats old_stats; |
| 349 const ServerNetworkStats* old_stats_ptr = | 352 const ServerNetworkStats* old_stats_ptr = |
| 350 http_server_properties_impl_->GetServerNetworkStats(host_port_pair); | 353 http_server_properties_impl_->GetServerNetworkStats(server); |
| 351 if (http_server_properties_impl_->GetServerNetworkStats(host_port_pair)) | 354 if (http_server_properties_impl_->GetServerNetworkStats(server)) |
| 352 old_stats = *old_stats_ptr; | 355 old_stats = *old_stats_ptr; |
| 353 http_server_properties_impl_->SetServerNetworkStats(host_port_pair, stats); | 356 http_server_properties_impl_->SetServerNetworkStats(server, stats); |
| 354 ServerNetworkStats new_stats = | 357 ServerNetworkStats new_stats = |
| 355 *(http_server_properties_impl_->GetServerNetworkStats(host_port_pair)); | 358 *(http_server_properties_impl_->GetServerNetworkStats(server)); |
| 356 if (old_stats != new_stats) | 359 if (old_stats != new_stats) |
| 357 ScheduleUpdatePrefsOnNetworkThread(SET_SERVER_NETWORK_STATS); | 360 ScheduleUpdatePrefsOnNetworkThread(SET_SERVER_NETWORK_STATS); |
| 358 } | 361 } |
| 359 | 362 |
| 360 const ServerNetworkStats* HttpServerPropertiesManager::GetServerNetworkStats( | 363 const ServerNetworkStats* HttpServerPropertiesManager::GetServerNetworkStats( |
| 361 const HostPortPair& host_port_pair) { | 364 const url::SchemeHostPort& server) { |
| 362 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 365 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 363 return http_server_properties_impl_->GetServerNetworkStats(host_port_pair); | 366 return http_server_properties_impl_->GetServerNetworkStats(server); |
| 364 } | 367 } |
| 365 | 368 |
| 366 const ServerNetworkStatsMap& | 369 const ServerNetworkStatsMap& |
| 367 HttpServerPropertiesManager::server_network_stats_map() const { | 370 HttpServerPropertiesManager::server_network_stats_map() const { |
| 368 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 371 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 369 return http_server_properties_impl_->server_network_stats_map(); | 372 return http_server_properties_impl_->server_network_stats_map(); |
| 370 } | 373 } |
| 371 | 374 |
| 372 bool HttpServerPropertiesManager::SetQuicServerInfo( | 375 bool HttpServerPropertiesManager::SetQuicServerInfo( |
| 373 const QuicServerId& server_id, | 376 const QuicServerId& server_id, |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 450 if (version < 4) { | 453 if (version < 4) { |
| 451 // The properties for a given server is in | 454 // The properties for a given server is in |
| 452 // http_server_properties_dict["servers"][server]. | 455 // http_server_properties_dict["servers"][server]. |
| 453 // Before Version 4, server data was stored in the following format in | 456 // Before Version 4, server data was stored in the following format in |
| 454 // alphabetical order. | 457 // alphabetical order. |
| 455 // | 458 // |
| 456 // "http_server_properties": { | 459 // "http_server_properties": { |
| 457 // "servers": { | 460 // "servers": { |
| 458 // "0-edge-chat.facebook.com:443" : {...}, | 461 // "0-edge-chat.facebook.com:443" : {...}, |
| 459 // "0.client-channel.google.com:443" : {...}, | 462 // "0.client-channel.google.com:443" : {...}, |
| 460 // "yt3.ggpht.com:443" : {...}, | 463 // "yt3.ggpht.com:80" : {...}, |
| 461 // ... | 464 // ... |
| 462 // }, ... | 465 // }, ... |
| 463 // }, | 466 // }, |
| 464 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion( | 467 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion( |
| 465 kServersKey, &servers_dict)) { | 468 kServersKey, &servers_dict)) { |
| 466 DVLOG(1) << "Malformed http_server_properties for servers."; | 469 DVLOG(1) << "Malformed http_server_properties for servers."; |
| 467 return; | 470 return; |
| 468 } | 471 } |
| 469 } else { | 472 } else { |
| 470 // From Version 4 onwards, data was stored in the following format. | 473 // For Version 4, data was stored in the following format. |
| 471 // |servers| are saved in MRU order. | 474 // |servers| are saved in MRU order. |
| 472 // | 475 // |
| 473 // "http_server_properties": { | 476 // "http_server_properties": { |
| 474 // "servers": [ | 477 // "servers": [ |
| 475 // {"yt3.ggpht.com:443" : {...}}, | 478 // {"yt3.ggpht.com:443" : {...}}, |
| 476 // {"0.client-channel.google.com:443" : {...}}, | 479 // {"0.client-channel.google.com:443" : {...}}, |
| 477 // {"0-edge-chat.facebook.com:443" : {...}}, | 480 // {"0-edge-chat.facebook.com:80" : {...}}, |
| 478 // ... | 481 // ... |
| 479 // ], ... | 482 // ], ... |
| 480 // }, | 483 // }, |
| 484 // For Version 5, data was stored in the following format. |
| 485 // |servers| are saved in MRU order. |servers| are in the format flattened |
| 486 // representation of (scheme/host/port) where port might be ignored if is |
| 487 // default with scheme. |
| 488 // |
| 489 // "http_server_properties": { |
| 490 // "servers": [ |
| 491 // {"https://yt3.ggpht.com" : {...}}, |
| 492 // {"http://0.client-channel.google.com:443" : {...}}, |
| 493 // {"http://0-edge-chat.facebook.com" : {...}}, |
| 494 // ... |
| 495 // ], ... |
| 496 // }, |
| 481 if (!http_server_properties_dict.GetListWithoutPathExpansion( | 497 if (!http_server_properties_dict.GetListWithoutPathExpansion( |
| 482 kServersKey, &servers_list)) { | 498 kServersKey, &servers_list)) { |
| 483 DVLOG(1) << "Malformed http_server_properties for servers list."; | 499 DVLOG(1) << "Malformed http_server_properties for servers list."; |
| 484 return; | 500 return; |
| 485 } | 501 } |
| 486 } | 502 } |
| 487 | 503 |
| 488 IPAddress* addr = new IPAddress; | 504 IPAddress* addr = new IPAddress; |
| 489 ReadSupportsQuic(http_server_properties_dict, addr); | 505 ReadSupportsQuic(http_server_properties_dict, addr); |
| 490 | 506 |
| 491 // String is host/port pair of spdy server. | 507 // String is "scheme://host:port" tuple of spdy server. |
| 492 std::unique_ptr<ServerList> spdy_servers(new ServerList); | 508 std::unique_ptr<ServerList> spdy_servers(new ServerList); |
| 493 std::unique_ptr<SpdySettingsMap> spdy_settings_map( | 509 std::unique_ptr<SpdySettingsMap> spdy_settings_map( |
| 494 new SpdySettingsMap(kMaxSpdySettingsHostsToPersist)); | 510 new SpdySettingsMap(kMaxSpdySettingsHostsToPersist)); |
| 495 std::unique_ptr<AlternativeServiceMap> alternative_service_map( | 511 std::unique_ptr<AlternativeServiceMap> alternative_service_map( |
| 496 new AlternativeServiceMap(kMaxAlternateProtocolHostsToPersist)); | 512 new AlternativeServiceMap(kMaxAlternateProtocolHostsToPersist)); |
| 497 std::unique_ptr<ServerNetworkStatsMap> server_network_stats_map( | 513 std::unique_ptr<ServerNetworkStatsMap> server_network_stats_map( |
| 498 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist)); | 514 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist)); |
| 499 std::unique_ptr<QuicServerInfoMap> quic_server_info_map( | 515 std::unique_ptr<QuicServerInfoMap> quic_server_info_map( |
| 500 new QuicServerInfoMap(QuicServerInfoMap::NO_AUTO_EVICT)); | 516 new QuicServerInfoMap(QuicServerInfoMap::NO_AUTO_EVICT)); |
| 501 | 517 |
| 502 if (version < 4) { | 518 if (version < 4) { |
| 503 if (!AddServersData(*servers_dict, spdy_servers.get(), | 519 if (!AddServersData(*servers_dict, spdy_servers.get(), |
| 504 spdy_settings_map.get(), alternative_service_map.get(), | 520 spdy_settings_map.get(), alternative_service_map.get(), |
| 505 server_network_stats_map.get())) { | 521 server_network_stats_map.get(), version)) { |
| 506 detected_corrupted_prefs = true; | 522 detected_corrupted_prefs = true; |
| 507 } | 523 } |
| 508 } else { | 524 } else { |
| 509 for (base::ListValue::const_iterator it = servers_list->begin(); | 525 for (base::ListValue::const_iterator it = servers_list->begin(); |
| 510 it != servers_list->end(); ++it) { | 526 it != servers_list->end(); ++it) { |
| 511 if (!(*it)->GetAsDictionary(&servers_dict)) { | 527 if (!(*it)->GetAsDictionary(&servers_dict)) { |
| 512 DVLOG(1) << "Malformed http_server_properties for servers dictionary."; | 528 DVLOG(1) << "Malformed http_server_properties for servers dictionary."; |
| 513 detected_corrupted_prefs = true; | 529 detected_corrupted_prefs = true; |
| 514 continue; | 530 continue; |
| 515 } | 531 } |
| 516 if (!AddServersData( | 532 if (!AddServersData(*servers_dict, spdy_servers.get(), |
| 517 *servers_dict, spdy_servers.get(), spdy_settings_map.get(), | 533 spdy_settings_map.get(), |
| 518 alternative_service_map.get(), server_network_stats_map.get())) { | 534 alternative_service_map.get(), |
| 535 server_network_stats_map.get(), version)) { |
| 519 detected_corrupted_prefs = true; | 536 detected_corrupted_prefs = true; |
| 520 } | 537 } |
| 521 } | 538 } |
| 522 } | 539 } |
| 523 | 540 |
| 524 if (!AddToQuicServerInfoMap(http_server_properties_dict, | 541 if (!AddToQuicServerInfoMap(http_server_properties_dict, |
| 525 quic_server_info_map.get())) { | 542 quic_server_info_map.get())) { |
| 526 detected_corrupted_prefs = true; | 543 detected_corrupted_prefs = true; |
| 527 } | 544 } |
| 528 | 545 |
| 529 network_task_runner_->PostTask( | 546 network_task_runner_->PostTask( |
| 530 FROM_HERE, | 547 FROM_HERE, |
| 531 base::Bind( | 548 base::Bind( |
| 532 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread, | 549 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread, |
| 533 base::Unretained(this), base::Owned(spdy_servers.release()), | 550 base::Unretained(this), base::Owned(spdy_servers.release()), |
| 534 base::Owned(spdy_settings_map.release()), | 551 base::Owned(spdy_settings_map.release()), |
| 535 base::Owned(alternative_service_map.release()), base::Owned(addr), | 552 base::Owned(alternative_service_map.release()), base::Owned(addr), |
| 536 base::Owned(server_network_stats_map.release()), | 553 base::Owned(server_network_stats_map.release()), |
| 537 base::Owned(quic_server_info_map.release()), | 554 base::Owned(quic_server_info_map.release()), |
| 538 detected_corrupted_prefs)); | 555 detected_corrupted_prefs)); |
| 539 } | 556 } |
| 540 | 557 |
| 541 bool HttpServerPropertiesManager::AddServersData( | 558 bool HttpServerPropertiesManager::AddServersData( |
| 542 const base::DictionaryValue& servers_dict, | 559 const base::DictionaryValue& servers_dict, |
| 543 ServerList* spdy_servers, | 560 ServerList* spdy_servers, |
| 544 SpdySettingsMap* spdy_settings_map, | 561 SpdySettingsMap* spdy_settings_map, |
| 545 AlternativeServiceMap* alternative_service_map, | 562 AlternativeServiceMap* alternative_service_map, |
| 546 ServerNetworkStatsMap* network_stats_map) { | 563 ServerNetworkStatsMap* network_stats_map, |
| 564 int version) { |
| 547 for (base::DictionaryValue::Iterator it(servers_dict); !it.IsAtEnd(); | 565 for (base::DictionaryValue::Iterator it(servers_dict); !it.IsAtEnd(); |
| 548 it.Advance()) { | 566 it.Advance()) { |
| 549 // Get server's host/pair. | 567 // Get server's scheme/host/pair. |
| 550 const std::string& server_str = it.key(); | 568 const std::string& server_str = it.key(); |
| 551 HostPortPair server = HostPortPair::FromString(server_str); | 569 std::string spdy_server_url = server_str; |
| 552 if (server.host().empty()) { | 570 if (version < 5) { |
| 571 // For old version disk data, always use HTTPS as the scheme. |
| 572 spdy_server_url.insert(0, "https://"); |
| 573 } |
| 574 url::SchemeHostPort spdy_server((GURL(spdy_server_url))); |
| 575 if (spdy_server.host().empty()) { |
| 553 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; | 576 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; |
| 554 return false; | 577 return false; |
| 555 } | 578 } |
| 556 | 579 |
| 557 const base::DictionaryValue* server_pref_dict = nullptr; | 580 const base::DictionaryValue* server_pref_dict = nullptr; |
| 558 if (!it.value().GetAsDictionary(&server_pref_dict)) { | 581 if (!it.value().GetAsDictionary(&server_pref_dict)) { |
| 559 DVLOG(1) << "Malformed http_server_properties server: " << server_str; | 582 DVLOG(1) << "Malformed http_server_properties server: " << server_str; |
| 560 return false; | 583 return false; |
| 561 } | 584 } |
| 562 | 585 |
| 563 // Get if server supports Spdy. | 586 // Get if server supports Spdy. |
| 564 bool supports_spdy = false; | 587 bool supports_spdy = false; |
| 565 if ((server_pref_dict->GetBoolean(kSupportsSpdyKey, &supports_spdy)) && | 588 if ((server_pref_dict->GetBoolean(kSupportsSpdyKey, &supports_spdy)) && |
| 566 supports_spdy) { | 589 supports_spdy) { |
| 567 spdy_servers->push_back(server_str); | 590 spdy_servers->push_back(spdy_server.Serialize()); |
| 568 } | 591 } |
| 569 | 592 |
| 570 AddToSpdySettingsMap(server, *server_pref_dict, spdy_settings_map); | 593 AddToSpdySettingsMap(spdy_server, *server_pref_dict, spdy_settings_map); |
| 571 if (!AddToAlternativeServiceMap(server, *server_pref_dict, | 594 if (!AddToAlternativeServiceMap(spdy_server, *server_pref_dict, |
| 572 alternative_service_map) || | 595 alternative_service_map) || |
| 573 !AddToNetworkStatsMap(server, *server_pref_dict, network_stats_map)) { | 596 !AddToNetworkStatsMap(spdy_server, *server_pref_dict, |
| 597 network_stats_map)) { |
| 574 return false; | 598 return false; |
| 575 } | 599 } |
| 576 } | 600 } |
| 577 return true; | 601 return true; |
| 578 } | 602 } |
| 579 | 603 |
| 580 void HttpServerPropertiesManager::AddToSpdySettingsMap( | 604 void HttpServerPropertiesManager::AddToSpdySettingsMap( |
| 581 const HostPortPair& server, | 605 const url::SchemeHostPort& server, |
| 582 const base::DictionaryValue& server_pref_dict, | 606 const base::DictionaryValue& server_pref_dict, |
| 583 SpdySettingsMap* spdy_settings_map) { | 607 SpdySettingsMap* spdy_settings_map) { |
| 584 // Get SpdySettings. | 608 // Get SpdySettings. |
| 585 DCHECK(spdy_settings_map->Peek(server) == spdy_settings_map->end()); | 609 DCHECK(spdy_settings_map->Peek(server) == spdy_settings_map->end()); |
| 586 const base::DictionaryValue* spdy_settings_dict = nullptr; | 610 const base::DictionaryValue* spdy_settings_dict = nullptr; |
| 587 if (!server_pref_dict.GetDictionaryWithoutPathExpansion( | 611 if (!server_pref_dict.GetDictionaryWithoutPathExpansion( |
| 588 kSettingsKey, &spdy_settings_dict)) { | 612 kSettingsKey, &spdy_settings_dict)) { |
| 589 return; | 613 return; |
| 590 } | 614 } |
| 591 SettingsMap settings_map; | 615 SettingsMap settings_map; |
| 592 for (base::DictionaryValue::Iterator dict_it(*spdy_settings_dict); | 616 for (base::DictionaryValue::Iterator dict_it(*spdy_settings_dict); |
| 593 !dict_it.IsAtEnd(); dict_it.Advance()) { | 617 !dict_it.IsAtEnd(); dict_it.Advance()) { |
| 594 const std::string& id_str = dict_it.key(); | 618 const std::string& id_str = dict_it.key(); |
| 595 int id = 0; | 619 int id = 0; |
| 596 if (!base::StringToInt(id_str, &id)) { | 620 if (!base::StringToInt(id_str, &id)) { |
| 597 DVLOG(1) << "Malformed id in SpdySettings for server: " | 621 DVLOG(1) << "Malformed id in SpdySettings for server: " |
| 598 << server.ToString(); | 622 << server.Serialize(); |
| 599 NOTREACHED(); | 623 NOTREACHED(); |
| 600 continue; | 624 continue; |
| 601 } | 625 } |
| 602 int value = 0; | 626 int value = 0; |
| 603 if (!dict_it.value().GetAsInteger(&value)) { | 627 if (!dict_it.value().GetAsInteger(&value)) { |
| 604 DVLOG(1) << "Malformed value in SpdySettings for server: " | 628 DVLOG(1) << "Malformed value in SpdySettings for server: " |
| 605 << server.ToString(); | 629 << server.Serialize(); |
| 606 NOTREACHED(); | 630 NOTREACHED(); |
| 607 continue; | 631 continue; |
| 608 } | 632 } |
| 609 SettingsFlagsAndValue flags_and_value(SETTINGS_FLAG_PERSISTED, value); | 633 SettingsFlagsAndValue flags_and_value(SETTINGS_FLAG_PERSISTED, value); |
| 610 settings_map[static_cast<SpdySettingsIds>(id)] = flags_and_value; | 634 settings_map[static_cast<SpdySettingsIds>(id)] = flags_and_value; |
| 611 } | 635 } |
| 612 spdy_settings_map->Put(server, settings_map); | 636 spdy_settings_map->Put(server, settings_map); |
| 613 } | 637 } |
| 614 | 638 |
| 615 bool HttpServerPropertiesManager::ParseAlternativeServiceDict( | 639 bool HttpServerPropertiesManager::ParseAlternativeServiceDict( |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 base::Time::FromInternalValue(expiration_int64); | 697 base::Time::FromInternalValue(expiration_int64); |
| 674 return true; | 698 return true; |
| 675 } | 699 } |
| 676 | 700 |
| 677 DVLOG(1) << "Malformed alternative service expiration for server: " | 701 DVLOG(1) << "Malformed alternative service expiration for server: " |
| 678 << server_str; | 702 << server_str; |
| 679 return false; | 703 return false; |
| 680 } | 704 } |
| 681 | 705 |
| 682 bool HttpServerPropertiesManager::AddToAlternativeServiceMap( | 706 bool HttpServerPropertiesManager::AddToAlternativeServiceMap( |
| 683 const HostPortPair& server, | 707 const url::SchemeHostPort& server, |
| 684 const base::DictionaryValue& server_pref_dict, | 708 const base::DictionaryValue& server_pref_dict, |
| 685 AlternativeServiceMap* alternative_service_map) { | 709 AlternativeServiceMap* alternative_service_map) { |
| 686 DCHECK(alternative_service_map->Peek(server) == | 710 DCHECK(alternative_service_map->Peek(server) == |
| 687 alternative_service_map->end()); | 711 alternative_service_map->end()); |
| 688 const base::ListValue* alternative_service_list; | 712 const base::ListValue* alternative_service_list; |
| 689 if (!server_pref_dict.GetListWithoutPathExpansion( | 713 if (!server_pref_dict.GetListWithoutPathExpansion( |
| 690 kAlternativeServiceKey, &alternative_service_list)) { | 714 kAlternativeServiceKey, &alternative_service_list)) { |
| 691 return true; | 715 return true; |
| 692 } | 716 } |
| 693 | 717 |
| 694 AlternativeServiceInfoVector alternative_service_info_vector; | 718 AlternativeServiceInfoVector alternative_service_info_vector; |
| 695 for (const base::Value* alternative_service_list_item : | 719 for (const base::Value* alternative_service_list_item : |
| 696 *alternative_service_list) { | 720 *alternative_service_list) { |
| 697 const base::DictionaryValue* alternative_service_dict; | 721 const base::DictionaryValue* alternative_service_dict; |
| 698 if (!alternative_service_list_item->GetAsDictionary( | 722 if (!alternative_service_list_item->GetAsDictionary( |
| 699 &alternative_service_dict)) | 723 &alternative_service_dict)) |
| 700 return false; | 724 return false; |
| 701 AlternativeServiceInfo alternative_service_info; | 725 AlternativeServiceInfo alternative_service_info; |
| 702 if (!ParseAlternativeServiceDict(*alternative_service_dict, | 726 if (!ParseAlternativeServiceDict(*alternative_service_dict, |
| 703 server.ToString(), | 727 server.Serialize(), |
| 704 &alternative_service_info)) { | 728 &alternative_service_info)) { |
| 705 return false; | 729 return false; |
| 706 } | 730 } |
| 707 if (base::Time::Now() < alternative_service_info.expiration) { | 731 if (base::Time::Now() < alternative_service_info.expiration) { |
| 708 alternative_service_info_vector.push_back(alternative_service_info); | 732 alternative_service_info_vector.push_back(alternative_service_info); |
| 709 } | 733 } |
| 710 } | 734 } |
| 711 | 735 |
| 712 if (alternative_service_info_vector.empty()) { | 736 if (alternative_service_info_vector.empty()) { |
| 713 return false; | 737 return false; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 738 if (!supports_quic_dict->GetStringWithoutPathExpansion(kAddressKey, | 762 if (!supports_quic_dict->GetStringWithoutPathExpansion(kAddressKey, |
| 739 &address) || | 763 &address) || |
| 740 !last_quic_address->AssignFromIPLiteral(address)) { | 764 !last_quic_address->AssignFromIPLiteral(address)) { |
| 741 DVLOG(1) << "Malformed SupportsQuic"; | 765 DVLOG(1) << "Malformed SupportsQuic"; |
| 742 return false; | 766 return false; |
| 743 } | 767 } |
| 744 return true; | 768 return true; |
| 745 } | 769 } |
| 746 | 770 |
| 747 bool HttpServerPropertiesManager::AddToNetworkStatsMap( | 771 bool HttpServerPropertiesManager::AddToNetworkStatsMap( |
| 748 const HostPortPair& server, | 772 const url::SchemeHostPort& server, |
| 749 const base::DictionaryValue& server_pref_dict, | 773 const base::DictionaryValue& server_pref_dict, |
| 750 ServerNetworkStatsMap* network_stats_map) { | 774 ServerNetworkStatsMap* network_stats_map) { |
| 751 DCHECK(network_stats_map->Peek(server) == network_stats_map->end()); | 775 DCHECK(network_stats_map->Peek(server) == network_stats_map->end()); |
| 752 const base::DictionaryValue* server_network_stats_dict = nullptr; | 776 const base::DictionaryValue* server_network_stats_dict = nullptr; |
| 753 if (!server_pref_dict.GetDictionaryWithoutPathExpansion( | 777 if (!server_pref_dict.GetDictionaryWithoutPathExpansion( |
| 754 kNetworkStatsKey, &server_network_stats_dict)) { | 778 kNetworkStatsKey, &server_network_stats_dict)) { |
| 755 return true; | 779 return true; |
| 756 } | 780 } |
| 757 int srtt; | 781 int srtt; |
| 758 if (!server_network_stats_dict->GetIntegerWithoutPathExpansion(kSrttKey, | 782 if (!server_network_stats_dict->GetIntegerWithoutPathExpansion(kSrttKey, |
| 759 &srtt)) { | 783 &srtt)) { |
| 760 DVLOG(1) << "Malformed ServerNetworkStats for server: " | 784 DVLOG(1) << "Malformed ServerNetworkStats for server: " |
| 761 << server.ToString(); | 785 << server.Serialize(); |
| 762 return false; | 786 return false; |
| 763 } | 787 } |
| 764 ServerNetworkStats server_network_stats; | 788 ServerNetworkStats server_network_stats; |
| 765 server_network_stats.srtt = base::TimeDelta::FromInternalValue(srtt); | 789 server_network_stats.srtt = base::TimeDelta::FromInternalValue(srtt); |
| 766 // TODO(rtenneti): When QUIC starts using bandwidth_estimate, then persist | 790 // TODO(rtenneti): When QUIC starts using bandwidth_estimate, then persist |
| 767 // bandwidth_estimate. | 791 // bandwidth_estimate. |
| 768 network_stats_map->Put(server, server_network_stats); | 792 network_stats_map->Put(server, server_network_stats); |
| 769 return true; | 793 return true; |
| 770 } | 794 } |
| 771 | 795 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 const AlternativeServiceMap& map = | 934 const AlternativeServiceMap& map = |
| 911 http_server_properties_impl_->alternative_service_map(); | 935 http_server_properties_impl_->alternative_service_map(); |
| 912 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers.Memory", | 936 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers.Memory", |
| 913 map.size()); | 937 map.size()); |
| 914 count = 0; | 938 count = 0; |
| 915 typedef std::map<std::string, bool> CanonicalHostPersistedMap; | 939 typedef std::map<std::string, bool> CanonicalHostPersistedMap; |
| 916 CanonicalHostPersistedMap persisted_map; | 940 CanonicalHostPersistedMap persisted_map; |
| 917 // Maintain MRU order. | 941 // Maintain MRU order. |
| 918 for (AlternativeServiceMap::const_reverse_iterator it = map.rbegin(); | 942 for (AlternativeServiceMap::const_reverse_iterator it = map.rbegin(); |
| 919 it != map.rend() && count < kMaxAlternateProtocolHostsToPersist; ++it) { | 943 it != map.rend() && count < kMaxAlternateProtocolHostsToPersist; ++it) { |
| 920 const HostPortPair& server = it->first; | 944 const url::SchemeHostPort& server = it->first; |
| 921 AlternativeServiceInfoVector notbroken_alternative_service_info_vector; | 945 AlternativeServiceInfoVector notbroken_alternative_service_info_vector; |
| 922 for (const AlternativeServiceInfo& alternative_service_info : it->second) { | 946 for (const AlternativeServiceInfo& alternative_service_info : it->second) { |
| 923 // Do not persist expired entries. | 947 // Do not persist expired entries. |
| 924 if (alternative_service_info.expiration < base::Time::Now()) { | 948 if (alternative_service_info.expiration < base::Time::Now()) { |
| 925 continue; | 949 continue; |
| 926 } | 950 } |
| 927 AlternativeService alternative_service( | 951 AlternativeService alternative_service( |
| 928 alternative_service_info.alternative_service); | 952 alternative_service_info.alternative_service); |
| 929 if (!IsAlternateProtocolValid(alternative_service.protocol)) { | 953 if (!IsAlternateProtocolValid(alternative_service.protocol)) { |
| 930 continue; | 954 continue; |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 | 1045 |
| 1022 // All maps and lists are in MRU order. | 1046 // All maps and lists are in MRU order. |
| 1023 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( | 1047 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( |
| 1024 base::ListValue* spdy_server_list, | 1048 base::ListValue* spdy_server_list, |
| 1025 SpdySettingsMap* spdy_settings_map, | 1049 SpdySettingsMap* spdy_settings_map, |
| 1026 AlternativeServiceMap* alternative_service_map, | 1050 AlternativeServiceMap* alternative_service_map, |
| 1027 IPAddress* last_quic_address, | 1051 IPAddress* last_quic_address, |
| 1028 ServerNetworkStatsMap* server_network_stats_map, | 1052 ServerNetworkStatsMap* server_network_stats_map, |
| 1029 QuicServerInfoMap* quic_server_info_map, | 1053 QuicServerInfoMap* quic_server_info_map, |
| 1030 const base::Closure& completion) { | 1054 const base::Closure& completion) { |
| 1031 typedef base::MRUCache<HostPortPair, ServerPref> ServerPrefMap; | 1055 typedef base::MRUCache<url::SchemeHostPort, ServerPref> ServerPrefMap; |
| 1032 ServerPrefMap server_pref_map(ServerPrefMap::NO_AUTO_EVICT); | 1056 ServerPrefMap server_pref_map(ServerPrefMap::NO_AUTO_EVICT); |
| 1033 | 1057 |
| 1034 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 1058 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
| 1035 | 1059 |
| 1036 // Add servers that support spdy to server_pref_map in the MRU order. | 1060 // Add servers that support spdy to server_pref_map in the MRU order. |
| 1037 for (size_t index = spdy_server_list->GetSize(); index > 0; --index) { | 1061 for (size_t index = spdy_server_list->GetSize(); index > 0; --index) { |
| 1038 std::string s; | 1062 std::string server_str; |
| 1039 if (spdy_server_list->GetString(index - 1, &s)) { | 1063 if (spdy_server_list->GetString(index - 1, &server_str)) { |
| 1040 HostPortPair server = HostPortPair::FromString(s); | 1064 url::SchemeHostPort server((GURL(server_str))); |
| 1041 ServerPrefMap::iterator it = server_pref_map.Get(server); | 1065 ServerPrefMap::iterator it = server_pref_map.Get(server); |
| 1042 if (it == server_pref_map.end()) { | 1066 if (it == server_pref_map.end()) { |
| 1043 ServerPref server_pref; | 1067 ServerPref server_pref; |
| 1044 server_pref.supports_spdy = true; | 1068 server_pref.supports_spdy = true; |
| 1045 server_pref_map.Put(server, server_pref); | 1069 server_pref_map.Put(server, server_pref); |
| 1046 } else { | 1070 } else { |
| 1047 it->second.supports_spdy = true; | 1071 it->second.supports_spdy = true; |
| 1048 } | 1072 } |
| 1049 } | 1073 } |
| 1050 } | 1074 } |
| 1051 | 1075 |
| 1052 // Add servers that have SpdySettings to server_pref_map in the MRU order. | 1076 // Add servers that have SpdySettings to server_pref_map in the MRU order. |
| 1053 for (SpdySettingsMap::reverse_iterator map_it = spdy_settings_map->rbegin(); | 1077 for (SpdySettingsMap::reverse_iterator map_it = spdy_settings_map->rbegin(); |
| 1054 map_it != spdy_settings_map->rend(); ++map_it) { | 1078 map_it != spdy_settings_map->rend(); ++map_it) { |
| 1055 const HostPortPair& server = map_it->first; | 1079 const url::SchemeHostPort server = map_it->first; |
| 1056 ServerPrefMap::iterator it = server_pref_map.Get(server); | 1080 ServerPrefMap::iterator it = server_pref_map.Get(server); |
| 1057 if (it == server_pref_map.end()) { | 1081 if (it == server_pref_map.end()) { |
| 1058 ServerPref server_pref; | 1082 ServerPref server_pref; |
| 1059 server_pref.settings_map = &map_it->second; | 1083 server_pref.settings_map = &map_it->second; |
| 1060 server_pref_map.Put(server, server_pref); | 1084 server_pref_map.Put(server, server_pref); |
| 1061 } else { | 1085 } else { |
| 1062 it->second.settings_map = &map_it->second; | 1086 it->second.settings_map = &map_it->second; |
| 1063 } | 1087 } |
| 1064 } | 1088 } |
| 1065 | 1089 |
| 1066 // Add alternative services to server_pref_map in the MRU order. | 1090 // Add alternative services to server_pref_map in the MRU order. |
| 1067 for (AlternativeServiceMap::const_reverse_iterator map_it = | 1091 for (AlternativeServiceMap::const_reverse_iterator map_it = |
| 1068 alternative_service_map->rbegin(); | 1092 alternative_service_map->rbegin(); |
| 1069 map_it != alternative_service_map->rend(); ++map_it) { | 1093 map_it != alternative_service_map->rend(); ++map_it) { |
| 1070 const HostPortPair& server = map_it->first; | 1094 const url::SchemeHostPort server = map_it->first; |
| 1071 ServerPrefMap::iterator it = server_pref_map.Get(server); | 1095 ServerPrefMap::iterator it = server_pref_map.Get(server); |
| 1072 if (it == server_pref_map.end()) { | 1096 if (it == server_pref_map.end()) { |
| 1073 ServerPref server_pref; | 1097 ServerPref server_pref; |
| 1074 server_pref.alternative_service_info_vector = &map_it->second; | 1098 server_pref.alternative_service_info_vector = &map_it->second; |
| 1075 server_pref_map.Put(server, server_pref); | 1099 server_pref_map.Put(server, server_pref); |
| 1076 } else { | 1100 } else { |
| 1077 it->second.alternative_service_info_vector = &map_it->second; | 1101 it->second.alternative_service_info_vector = &map_it->second; |
| 1078 } | 1102 } |
| 1079 } | 1103 } |
| 1080 | 1104 |
| 1081 // Add ServerNetworkStats servers to server_pref_map in the MRU order. | 1105 // Add ServerNetworkStats servers to server_pref_map in the MRU order. |
| 1082 for (ServerNetworkStatsMap::const_reverse_iterator map_it = | 1106 for (ServerNetworkStatsMap::const_reverse_iterator map_it = |
| 1083 server_network_stats_map->rbegin(); | 1107 server_network_stats_map->rbegin(); |
| 1084 map_it != server_network_stats_map->rend(); ++map_it) { | 1108 map_it != server_network_stats_map->rend(); ++map_it) { |
| 1085 const HostPortPair& server = map_it->first; | 1109 const url::SchemeHostPort server = map_it->first; |
| 1086 ServerPrefMap::iterator it = server_pref_map.Get(server); | 1110 ServerPrefMap::iterator it = server_pref_map.Get(server); |
| 1087 if (it == server_pref_map.end()) { | 1111 if (it == server_pref_map.end()) { |
| 1088 ServerPref server_pref; | 1112 ServerPref server_pref; |
| 1089 server_pref.server_network_stats = &map_it->second; | 1113 server_pref.server_network_stats = &map_it->second; |
| 1090 server_pref_map.Put(server, server_pref); | 1114 server_pref_map.Put(server, server_pref); |
| 1091 } else { | 1115 } else { |
| 1092 it->second.server_network_stats = &map_it->second; | 1116 it->second.server_network_stats = &map_it->second; |
| 1093 } | 1117 } |
| 1094 } | 1118 } |
| 1095 | 1119 |
| 1096 // Persist properties to the prefs in the MRU order. | 1120 // Persist properties to the prefs in the MRU order. |
| 1097 base::DictionaryValue http_server_properties_dict; | 1121 base::DictionaryValue http_server_properties_dict; |
| 1098 base::ListValue* servers_list = new base::ListValue; | 1122 base::ListValue* servers_list = new base::ListValue; |
| 1099 for (ServerPrefMap::const_reverse_iterator map_it = server_pref_map.rbegin(); | 1123 for (ServerPrefMap::const_reverse_iterator map_it = server_pref_map.rbegin(); |
| 1100 map_it != server_pref_map.rend(); ++map_it) { | 1124 map_it != server_pref_map.rend(); ++map_it) { |
| 1101 const HostPortPair& server = map_it->first; | 1125 const url::SchemeHostPort server = map_it->first; |
| 1102 const ServerPref& server_pref = map_it->second; | 1126 const ServerPref& server_pref = map_it->second; |
| 1103 | 1127 |
| 1104 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 1128 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 1105 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 1129 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 1106 | 1130 |
| 1107 // Save supports_spdy. | 1131 // Save supports_spdy. |
| 1108 if (server_pref.supports_spdy) | 1132 if (server_pref.supports_spdy) |
| 1109 server_pref_dict->SetBoolean(kSupportsSpdyKey, server_pref.supports_spdy); | 1133 server_pref_dict->SetBoolean(kSupportsSpdyKey, server_pref.supports_spdy); |
| 1110 SaveSpdySettingsToServerPrefs(server_pref.settings_map, server_pref_dict); | 1134 SaveSpdySettingsToServerPrefs(server_pref.settings_map, server_pref_dict); |
| 1111 SaveAlternativeServiceToServerPrefs( | 1135 SaveAlternativeServiceToServerPrefs( |
| 1112 server_pref.alternative_service_info_vector, server_pref_dict); | 1136 server_pref.alternative_service_info_vector, server_pref_dict); |
| 1113 SaveNetworkStatsToServerPrefs(server_pref.server_network_stats, | 1137 SaveNetworkStatsToServerPrefs(server_pref.server_network_stats, |
| 1114 server_pref_dict); | 1138 server_pref_dict); |
| 1115 | 1139 |
| 1116 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict); | 1140 servers_dict->SetWithoutPathExpansion(server.Serialize(), server_pref_dict); |
| 1117 bool value = servers_list->AppendIfNotPresent(servers_dict); | 1141 bool value = servers_list->AppendIfNotPresent(servers_dict); |
| 1118 DCHECK(value); // Should never happen. | 1142 DCHECK(value); // Should never happen. |
| 1119 } | 1143 } |
| 1120 | 1144 |
| 1121 http_server_properties_dict.SetWithoutPathExpansion(kServersKey, | 1145 http_server_properties_dict.SetWithoutPathExpansion(kServersKey, |
| 1122 servers_list); | 1146 servers_list); |
| 1123 SetVersion(&http_server_properties_dict, kVersionNumber); | 1147 SetVersion(&http_server_properties_dict, kVersionNumber); |
| 1124 | 1148 |
| 1125 SaveSupportsQuicToPrefs(last_quic_address, &http_server_properties_dict); | 1149 SaveSupportsQuicToPrefs(last_quic_address, &http_server_properties_dict); |
| 1126 | 1150 |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1239 quic_servers_dict); | 1263 quic_servers_dict); |
| 1240 } | 1264 } |
| 1241 | 1265 |
| 1242 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { | 1266 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { |
| 1243 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 1267 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
| 1244 if (!setting_prefs_) | 1268 if (!setting_prefs_) |
| 1245 ScheduleUpdateCacheOnPrefThread(); | 1269 ScheduleUpdateCacheOnPrefThread(); |
| 1246 } | 1270 } |
| 1247 | 1271 |
| 1248 } // namespace net | 1272 } // namespace net |
| OLD | NEW |