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.h" | 8 #include "base/metrics/histogram.h" |
9 #include "base/prefs/pref_service.h" | 9 #include "base/prefs/pref_service.h" |
10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
(...skipping 29 matching lines...) Expand all Loading... |
40 | 40 |
41 // Persist 200 MRU AlternateProtocolHostPortPairs. | 41 // Persist 200 MRU AlternateProtocolHostPortPairs. |
42 const int kMaxAlternateProtocolHostsToPersist = 200; | 42 const int kMaxAlternateProtocolHostsToPersist = 200; |
43 | 43 |
44 // Persist 200 MRU SpdySettingsHostPortPairs. | 44 // Persist 200 MRU SpdySettingsHostPortPairs. |
45 const int kMaxSpdySettingsHostsToPersist = 200; | 45 const int kMaxSpdySettingsHostsToPersist = 200; |
46 | 46 |
47 // Persist 300 MRU SupportsSpdyServerHostPortPairs. | 47 // Persist 300 MRU SupportsSpdyServerHostPortPairs. |
48 const int kMaxSupportsSpdyServerHostsToPersist = 300; | 48 const int kMaxSupportsSpdyServerHostsToPersist = 300; |
49 | 49 |
| 50 // Persist 200 ServerNetworkStats. |
| 51 const int kMaxServerNetworkStatsHostsToPersist = 200; |
| 52 |
50 } // namespace | 53 } // namespace |
51 | 54 |
52 //////////////////////////////////////////////////////////////////////////////// | 55 //////////////////////////////////////////////////////////////////////////////// |
53 // HttpServerPropertiesManager | 56 // HttpServerPropertiesManager |
54 | 57 |
55 HttpServerPropertiesManager::HttpServerPropertiesManager( | 58 HttpServerPropertiesManager::HttpServerPropertiesManager( |
56 PrefService* pref_service, | 59 PrefService* pref_service, |
57 const char* pref_path, | 60 const char* pref_path, |
58 scoped_refptr<base::SequencedTaskRunner> network_task_runner) | 61 scoped_refptr<base::SequencedTaskRunner> network_task_runner) |
59 : pref_task_runner_(base::ThreadTaskRunnerHandle::Get()), | 62 : pref_task_runner_(base::ThreadTaskRunnerHandle::Get()), |
(...skipping 16 matching lines...) Expand all Loading... |
76 | 79 |
77 HttpServerPropertiesManager::~HttpServerPropertiesManager() { | 80 HttpServerPropertiesManager::~HttpServerPropertiesManager() { |
78 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 81 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
79 network_weak_ptr_factory_.reset(); | 82 network_weak_ptr_factory_.reset(); |
80 } | 83 } |
81 | 84 |
82 void HttpServerPropertiesManager::InitializeOnNetworkThread() { | 85 void HttpServerPropertiesManager::InitializeOnNetworkThread() { |
83 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 86 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
84 network_weak_ptr_factory_.reset( | 87 network_weak_ptr_factory_.reset( |
85 new base::WeakPtrFactory<HttpServerPropertiesManager>(this)); | 88 new base::WeakPtrFactory<HttpServerPropertiesManager>(this)); |
86 http_server_properties_impl_.reset(new net::HttpServerPropertiesImpl()); | 89 http_server_properties_impl_.reset(new HttpServerPropertiesImpl()); |
87 | 90 |
88 network_prefs_update_timer_.reset( | 91 network_prefs_update_timer_.reset( |
89 new base::OneShotTimer<HttpServerPropertiesManager>); | 92 new base::OneShotTimer<HttpServerPropertiesManager>); |
90 | 93 |
91 pref_task_runner_->PostTask( | 94 pref_task_runner_->PostTask( |
92 FROM_HERE, | 95 FROM_HERE, |
93 base::Bind(&HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread, | 96 base::Bind(&HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread, |
94 pref_weak_ptr_)); | 97 pref_weak_ptr_)); |
95 } | 98 } |
96 | 99 |
(...skipping 10 matching lines...) Expand all Loading... |
107 base::DictionaryValue* http_server_properties_dict, | 110 base::DictionaryValue* http_server_properties_dict, |
108 int version_number) { | 111 int version_number) { |
109 if (version_number < 0) | 112 if (version_number < 0) |
110 version_number = kVersionNumber; | 113 version_number = kVersionNumber; |
111 DCHECK_LE(version_number, kVersionNumber); | 114 DCHECK_LE(version_number, kVersionNumber); |
112 if (version_number <= kVersionNumber) | 115 if (version_number <= kVersionNumber) |
113 http_server_properties_dict->SetInteger("version", version_number); | 116 http_server_properties_dict->SetInteger("version", version_number); |
114 } | 117 } |
115 | 118 |
116 // This is required for conformance with the HttpServerProperties interface. | 119 // This is required for conformance with the HttpServerProperties interface. |
117 base::WeakPtr<net::HttpServerProperties> | 120 base::WeakPtr<HttpServerProperties> HttpServerPropertiesManager::GetWeakPtr() { |
118 HttpServerPropertiesManager::GetWeakPtr() { | |
119 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 121 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
120 return network_weak_ptr_factory_->GetWeakPtr(); | 122 return network_weak_ptr_factory_->GetWeakPtr(); |
121 } | 123 } |
122 | 124 |
123 void HttpServerPropertiesManager::Clear() { | 125 void HttpServerPropertiesManager::Clear() { |
124 Clear(base::Closure()); | 126 Clear(base::Closure()); |
125 } | 127 } |
126 | 128 |
127 void HttpServerPropertiesManager::Clear(const base::Closure& completion) { | 129 void HttpServerPropertiesManager::Clear(const base::Closure& completion) { |
128 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 130 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
129 | 131 |
130 http_server_properties_impl_->Clear(); | 132 http_server_properties_impl_->Clear(); |
131 UpdatePrefsFromCacheOnNetworkThread(completion); | 133 UpdatePrefsFromCacheOnNetworkThread(completion); |
132 } | 134 } |
133 | 135 |
134 bool HttpServerPropertiesManager::SupportsSpdy( | 136 bool HttpServerPropertiesManager::SupportsSpdy(const HostPortPair& server) { |
135 const net::HostPortPair& server) { | |
136 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 137 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
137 return http_server_properties_impl_->SupportsSpdy(server); | 138 return http_server_properties_impl_->SupportsSpdy(server); |
138 } | 139 } |
139 | 140 |
140 void HttpServerPropertiesManager::SetSupportsSpdy( | 141 void HttpServerPropertiesManager::SetSupportsSpdy(const HostPortPair& server, |
141 const net::HostPortPair& server, | 142 bool support_spdy) { |
142 bool support_spdy) { | |
143 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 143 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
144 | 144 |
145 http_server_properties_impl_->SetSupportsSpdy(server, support_spdy); | 145 http_server_properties_impl_->SetSupportsSpdy(server, support_spdy); |
146 ScheduleUpdatePrefsOnNetworkThread(); | 146 ScheduleUpdatePrefsOnNetworkThread(); |
147 } | 147 } |
148 | 148 |
149 bool HttpServerPropertiesManager::HasAlternateProtocol( | 149 bool HttpServerPropertiesManager::HasAlternateProtocol( |
150 const net::HostPortPair& server) { | 150 const HostPortPair& server) { |
151 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 151 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
152 return http_server_properties_impl_->HasAlternateProtocol(server); | 152 return http_server_properties_impl_->HasAlternateProtocol(server); |
153 } | 153 } |
154 | 154 |
155 net::AlternateProtocolInfo | 155 AlternateProtocolInfo HttpServerPropertiesManager::GetAlternateProtocol( |
156 HttpServerPropertiesManager::GetAlternateProtocol( | 156 const HostPortPair& server) { |
157 const net::HostPortPair& server) { | |
158 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 157 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
159 return http_server_properties_impl_->GetAlternateProtocol(server); | 158 return http_server_properties_impl_->GetAlternateProtocol(server); |
160 } | 159 } |
161 | 160 |
162 void HttpServerPropertiesManager::SetAlternateProtocol( | 161 void HttpServerPropertiesManager::SetAlternateProtocol( |
163 const net::HostPortPair& server, | 162 const HostPortPair& server, |
164 uint16 alternate_port, | 163 uint16 alternate_port, |
165 AlternateProtocol alternate_protocol, | 164 AlternateProtocol alternate_protocol, |
166 double alternate_probability) { | 165 double alternate_probability) { |
167 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 166 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
168 http_server_properties_impl_->SetAlternateProtocol( | 167 http_server_properties_impl_->SetAlternateProtocol( |
169 server, alternate_port, alternate_protocol, alternate_probability); | 168 server, alternate_port, alternate_protocol, alternate_probability); |
170 ScheduleUpdatePrefsOnNetworkThread(); | 169 ScheduleUpdatePrefsOnNetworkThread(); |
171 } | 170 } |
172 | 171 |
173 void HttpServerPropertiesManager::SetBrokenAlternateProtocol( | 172 void HttpServerPropertiesManager::SetBrokenAlternateProtocol( |
174 const net::HostPortPair& server) { | 173 const HostPortPair& server) { |
175 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 174 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
176 http_server_properties_impl_->SetBrokenAlternateProtocol(server); | 175 http_server_properties_impl_->SetBrokenAlternateProtocol(server); |
177 ScheduleUpdatePrefsOnNetworkThread(); | 176 ScheduleUpdatePrefsOnNetworkThread(); |
178 } | 177 } |
179 | 178 |
180 bool HttpServerPropertiesManager::WasAlternateProtocolRecentlyBroken( | 179 bool HttpServerPropertiesManager::WasAlternateProtocolRecentlyBroken( |
181 const net::HostPortPair& server) { | 180 const HostPortPair& server) { |
182 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 181 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
183 return http_server_properties_impl_->WasAlternateProtocolRecentlyBroken( | 182 return http_server_properties_impl_->WasAlternateProtocolRecentlyBroken( |
184 server); | 183 server); |
185 } | 184 } |
186 | 185 |
187 void HttpServerPropertiesManager::ConfirmAlternateProtocol( | 186 void HttpServerPropertiesManager::ConfirmAlternateProtocol( |
188 const net::HostPortPair& server) { | 187 const HostPortPair& server) { |
189 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 188 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
190 http_server_properties_impl_->ConfirmAlternateProtocol(server); | 189 http_server_properties_impl_->ConfirmAlternateProtocol(server); |
191 ScheduleUpdatePrefsOnNetworkThread(); | 190 ScheduleUpdatePrefsOnNetworkThread(); |
192 } | 191 } |
193 | 192 |
194 void HttpServerPropertiesManager::ClearAlternateProtocol( | 193 void HttpServerPropertiesManager::ClearAlternateProtocol( |
195 const net::HostPortPair& server) { | 194 const HostPortPair& server) { |
196 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 195 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
197 http_server_properties_impl_->ClearAlternateProtocol(server); | 196 http_server_properties_impl_->ClearAlternateProtocol(server); |
198 ScheduleUpdatePrefsOnNetworkThread(); | 197 ScheduleUpdatePrefsOnNetworkThread(); |
199 } | 198 } |
200 | 199 |
201 const net::AlternateProtocolMap& | 200 const AlternateProtocolMap& |
202 HttpServerPropertiesManager::alternate_protocol_map() const { | 201 HttpServerPropertiesManager::alternate_protocol_map() const { |
203 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 202 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
204 return http_server_properties_impl_->alternate_protocol_map(); | 203 return http_server_properties_impl_->alternate_protocol_map(); |
205 } | 204 } |
206 | 205 |
207 void HttpServerPropertiesManager::SetAlternateProtocolProbabilityThreshold( | 206 void HttpServerPropertiesManager::SetAlternateProtocolProbabilityThreshold( |
208 double threshold) { | 207 double threshold) { |
209 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 208 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
210 http_server_properties_impl_->SetAlternateProtocolProbabilityThreshold( | 209 http_server_properties_impl_->SetAlternateProtocolProbabilityThreshold( |
211 threshold); | 210 threshold); |
(...skipping 30 matching lines...) Expand all Loading... |
242 http_server_properties_impl_->ClearAllSpdySettings(); | 241 http_server_properties_impl_->ClearAllSpdySettings(); |
243 ScheduleUpdatePrefsOnNetworkThread(); | 242 ScheduleUpdatePrefsOnNetworkThread(); |
244 } | 243 } |
245 | 244 |
246 const SpdySettingsMap& HttpServerPropertiesManager::spdy_settings_map() | 245 const SpdySettingsMap& HttpServerPropertiesManager::spdy_settings_map() |
247 const { | 246 const { |
248 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 247 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
249 return http_server_properties_impl_->spdy_settings_map(); | 248 return http_server_properties_impl_->spdy_settings_map(); |
250 } | 249 } |
251 | 250 |
252 net::SupportsQuic | 251 SupportsQuic HttpServerPropertiesManager::GetSupportsQuic( |
253 HttpServerPropertiesManager::GetSupportsQuic( | 252 const HostPortPair& host_port_pair) const { |
254 const net::HostPortPair& host_port_pair) const { | |
255 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 253 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
256 return http_server_properties_impl_->GetSupportsQuic(host_port_pair); | 254 return http_server_properties_impl_->GetSupportsQuic(host_port_pair); |
257 } | 255 } |
258 | 256 |
259 void HttpServerPropertiesManager::SetSupportsQuic( | 257 void HttpServerPropertiesManager::SetSupportsQuic( |
260 const net::HostPortPair& host_port_pair, | 258 const HostPortPair& host_port_pair, |
261 bool used_quic, | 259 bool used_quic, |
262 const std::string& address) { | 260 const std::string& address) { |
263 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 261 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
264 http_server_properties_impl_->SetSupportsQuic( | 262 http_server_properties_impl_->SetSupportsQuic( |
265 host_port_pair, used_quic, address); | 263 host_port_pair, used_quic, address); |
266 ScheduleUpdatePrefsOnNetworkThread(); | 264 ScheduleUpdatePrefsOnNetworkThread(); |
267 } | 265 } |
268 | 266 |
269 const SupportsQuicMap& HttpServerPropertiesManager::supports_quic_map() | 267 const SupportsQuicMap& HttpServerPropertiesManager::supports_quic_map() |
270 const { | 268 const { |
271 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 269 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
272 return http_server_properties_impl_->supports_quic_map(); | 270 return http_server_properties_impl_->supports_quic_map(); |
273 } | 271 } |
274 | 272 |
275 void HttpServerPropertiesManager::SetServerNetworkStats( | 273 void HttpServerPropertiesManager::SetServerNetworkStats( |
276 const net::HostPortPair& host_port_pair, | 274 const HostPortPair& host_port_pair, |
277 NetworkStats stats) { | 275 ServerNetworkStats stats) { |
278 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 276 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
279 http_server_properties_impl_->SetServerNetworkStats(host_port_pair, stats); | 277 http_server_properties_impl_->SetServerNetworkStats(host_port_pair, stats); |
| 278 ScheduleUpdatePrefsOnNetworkThread(); |
280 } | 279 } |
281 | 280 |
282 const HttpServerPropertiesManager::NetworkStats* | 281 const ServerNetworkStats* HttpServerPropertiesManager::GetServerNetworkStats( |
283 HttpServerPropertiesManager::GetServerNetworkStats( | 282 const HostPortPair& host_port_pair) { |
284 const net::HostPortPair& host_port_pair) const { | |
285 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 283 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
286 return http_server_properties_impl_->GetServerNetworkStats(host_port_pair); | 284 return http_server_properties_impl_->GetServerNetworkStats(host_port_pair); |
287 } | 285 } |
288 | 286 |
| 287 const ServerNetworkStatsMap& |
| 288 HttpServerPropertiesManager::server_network_stats_map() const { |
| 289 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 290 return http_server_properties_impl_->server_network_stats_map(); |
| 291 } |
| 292 |
289 // | 293 // |
290 // Update the HttpServerPropertiesImpl's cache with data from preferences. | 294 // Update the HttpServerPropertiesImpl's cache with data from preferences. |
291 // | 295 // |
292 void HttpServerPropertiesManager::ScheduleUpdateCacheOnPrefThread() { | 296 void HttpServerPropertiesManager::ScheduleUpdateCacheOnPrefThread() { |
293 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 297 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
294 // Cancel pending updates, if any. | 298 // Cancel pending updates, if any. |
295 pref_cache_update_timer_->Stop(); | 299 pref_cache_update_timer_->Stop(); |
296 StartCacheUpdateTimerOnPrefThread( | 300 StartCacheUpdateTimerOnPrefThread( |
297 base::TimeDelta::FromMilliseconds(kUpdateCacheDelayMs)); | 301 base::TimeDelta::FromMilliseconds(kUpdateCacheDelayMs)); |
298 } | 302 } |
(...skipping 30 matching lines...) Expand all Loading... |
329 // http_server_properties_dict["servers"][server]. | 333 // http_server_properties_dict["servers"][server]. |
330 const base::DictionaryValue* servers_dict = NULL; | 334 const base::DictionaryValue* servers_dict = NULL; |
331 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion( | 335 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion( |
332 "servers", &servers_dict)) { | 336 "servers", &servers_dict)) { |
333 DVLOG(1) << "Malformed http_server_properties for servers."; | 337 DVLOG(1) << "Malformed http_server_properties for servers."; |
334 return; | 338 return; |
335 } | 339 } |
336 | 340 |
337 // String is host/port pair of spdy server. | 341 // String is host/port pair of spdy server. |
338 scoped_ptr<StringVector> spdy_servers(new StringVector); | 342 scoped_ptr<StringVector> spdy_servers(new StringVector); |
339 scoped_ptr<net::SpdySettingsMap> spdy_settings_map( | 343 scoped_ptr<SpdySettingsMap> spdy_settings_map( |
340 new net::SpdySettingsMap(kMaxSpdySettingsHostsToPersist)); | 344 new SpdySettingsMap(kMaxSpdySettingsHostsToPersist)); |
341 scoped_ptr<net::AlternateProtocolMap> alternate_protocol_map( | 345 scoped_ptr<AlternateProtocolMap> alternate_protocol_map( |
342 new net::AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist)); | 346 new AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist)); |
343 scoped_ptr<net::SupportsQuicMap> supports_quic_map( | 347 scoped_ptr<SupportsQuicMap> supports_quic_map(new SupportsQuicMap()); |
344 new net::SupportsQuicMap()); | 348 scoped_ptr<ServerNetworkStatsMap> server_network_stats_map( |
| 349 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist)); |
345 | 350 |
346 int count = 0; | |
347 for (base::DictionaryValue::Iterator it(*servers_dict); !it.IsAtEnd(); | 351 for (base::DictionaryValue::Iterator it(*servers_dict); !it.IsAtEnd(); |
348 it.Advance()) { | 352 it.Advance()) { |
349 // Get server's host/pair. | 353 // Get server's host/pair. |
350 const std::string& server_str = it.key(); | 354 const std::string& server_str = it.key(); |
351 net::HostPortPair server = net::HostPortPair::FromString(server_str); | 355 HostPortPair server = HostPortPair::FromString(server_str); |
352 if (server.host().empty()) { | 356 if (server.host().empty()) { |
353 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; | 357 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; |
354 detected_corrupted_prefs = true; | 358 detected_corrupted_prefs = true; |
355 continue; | 359 continue; |
356 } | 360 } |
357 | 361 |
358 const base::DictionaryValue* server_pref_dict = NULL; | 362 const base::DictionaryValue* server_pref_dict = NULL; |
359 if (!it.value().GetAsDictionary(&server_pref_dict)) { | 363 if (!it.value().GetAsDictionary(&server_pref_dict)) { |
360 DVLOG(1) << "Malformed http_server_properties server: " << server_str; | 364 DVLOG(1) << "Malformed http_server_properties server: " << server_str; |
361 detected_corrupted_prefs = true; | 365 detected_corrupted_prefs = true; |
362 continue; | 366 continue; |
363 } | 367 } |
364 | 368 |
365 // Get if server supports Spdy. | 369 // Get if server supports Spdy. |
366 bool supports_spdy = false; | 370 bool supports_spdy = false; |
367 if ((server_pref_dict->GetBoolean("supports_spdy", &supports_spdy)) && | 371 if ((server_pref_dict->GetBoolean("supports_spdy", &supports_spdy)) && |
368 supports_spdy) { | 372 supports_spdy) { |
369 spdy_servers->push_back(server_str); | 373 spdy_servers->push_back(server_str); |
370 } | 374 } |
371 | 375 |
372 // Get SpdySettings. | 376 // Get SpdySettings. |
373 DCHECK(spdy_settings_map->Peek(server) == spdy_settings_map->end()); | 377 DCHECK(spdy_settings_map->Peek(server) == spdy_settings_map->end()); |
374 const base::DictionaryValue* spdy_settings_dict = NULL; | 378 const base::DictionaryValue* spdy_settings_dict = NULL; |
375 if (server_pref_dict->GetDictionaryWithoutPathExpansion( | 379 if (server_pref_dict->GetDictionaryWithoutPathExpansion( |
376 "settings", &spdy_settings_dict)) { | 380 "settings", &spdy_settings_dict)) { |
377 net::SettingsMap settings_map; | 381 SettingsMap settings_map; |
378 for (base::DictionaryValue::Iterator dict_it(*spdy_settings_dict); | 382 for (base::DictionaryValue::Iterator dict_it(*spdy_settings_dict); |
379 !dict_it.IsAtEnd(); | 383 !dict_it.IsAtEnd(); |
380 dict_it.Advance()) { | 384 dict_it.Advance()) { |
381 const std::string& id_str = dict_it.key(); | 385 const std::string& id_str = dict_it.key(); |
382 int id = 0; | 386 int id = 0; |
383 if (!base::StringToInt(id_str, &id)) { | 387 if (!base::StringToInt(id_str, &id)) { |
384 DVLOG(1) << "Malformed id in SpdySettings for server: " << server_str; | 388 DVLOG(1) << "Malformed id in SpdySettings for server: " << server_str; |
385 NOTREACHED(); | 389 NOTREACHED(); |
386 continue; | 390 continue; |
387 } | 391 } |
388 int value = 0; | 392 int value = 0; |
389 if (!dict_it.value().GetAsInteger(&value)) { | 393 if (!dict_it.value().GetAsInteger(&value)) { |
390 DVLOG(1) << "Malformed value in SpdySettings for server: " | 394 DVLOG(1) << "Malformed value in SpdySettings for server: " |
391 << server_str; | 395 << server_str; |
392 NOTREACHED(); | 396 NOTREACHED(); |
393 continue; | 397 continue; |
394 } | 398 } |
395 net::SettingsFlagsAndValue flags_and_value(net::SETTINGS_FLAG_PERSISTED, | 399 SettingsFlagsAndValue flags_and_value(SETTINGS_FLAG_PERSISTED, value); |
396 value); | 400 settings_map[static_cast<SpdySettingsIds>(id)] = flags_and_value; |
397 settings_map[static_cast<net::SpdySettingsIds>(id)] = flags_and_value; | |
398 } | 401 } |
399 spdy_settings_map->Put(server, settings_map); | 402 spdy_settings_map->Put(server, settings_map); |
400 } | 403 } |
401 | 404 |
402 // Get alternate_protocol server. | 405 // Get alternate_protocol server. |
403 DCHECK(alternate_protocol_map->Peek(server) == | 406 DCHECK(alternate_protocol_map->Peek(server) == |
404 alternate_protocol_map->end()); | 407 alternate_protocol_map->end()); |
405 const base::DictionaryValue* port_alternate_protocol_dict = NULL; | 408 const base::DictionaryValue* port_alternate_protocol_dict = NULL; |
406 if (!server_pref_dict->GetDictionaryWithoutPathExpansion( | 409 if (server_pref_dict->GetDictionaryWithoutPathExpansion( |
407 "alternate_protocol", &port_alternate_protocol_dict)) { | 410 "alternate_protocol", &port_alternate_protocol_dict)) { |
408 continue; | |
409 } | |
410 | |
411 if (count >= kMaxAlternateProtocolHostsToPersist) | |
412 continue; | |
413 do { | |
414 int port = 0; | 411 int port = 0; |
415 if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion( | 412 if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion( |
416 "port", &port) || | 413 "port", &port) || |
417 !IsPortValid(port)) { | 414 !IsPortValid(port)) { |
418 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; | 415 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; |
419 detected_corrupted_prefs = true; | 416 detected_corrupted_prefs = true; |
420 continue; | 417 continue; |
421 } | 418 } |
422 std::string protocol_str; | 419 std::string protocol_str; |
423 if (!port_alternate_protocol_dict->GetStringWithoutPathExpansion( | 420 if (!port_alternate_protocol_dict->GetStringWithoutPathExpansion( |
424 "protocol_str", &protocol_str)) { | 421 "protocol_str", &protocol_str)) { |
425 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; | 422 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; |
426 detected_corrupted_prefs = true; | 423 detected_corrupted_prefs = true; |
427 continue; | 424 continue; |
428 } | 425 } |
429 net::AlternateProtocol protocol = | 426 AlternateProtocol protocol = AlternateProtocolFromString(protocol_str); |
430 net::AlternateProtocolFromString(protocol_str); | 427 if (!IsAlternateProtocolValid(protocol)) { |
431 if (!net::IsAlternateProtocolValid(protocol)) { | |
432 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; | 428 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; |
433 detected_corrupted_prefs = true; | 429 detected_corrupted_prefs = true; |
434 continue; | 430 continue; |
435 } | 431 } |
436 | 432 |
437 double probability = 1; | 433 double probability = 1; |
438 if (port_alternate_protocol_dict->HasKey("probability") && | 434 if (port_alternate_protocol_dict->HasKey("probability") && |
439 !port_alternate_protocol_dict->GetDoubleWithoutPathExpansion( | 435 !port_alternate_protocol_dict->GetDoubleWithoutPathExpansion( |
440 "probability", &probability)) { | 436 "probability", &probability)) { |
441 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; | 437 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str; |
442 detected_corrupted_prefs = true; | 438 detected_corrupted_prefs = true; |
443 continue; | 439 continue; |
444 } | 440 } |
445 | 441 |
446 net::AlternateProtocolInfo port_alternate_protocol( | 442 AlternateProtocolInfo port_alternate_protocol(static_cast<uint16>(port), |
447 static_cast<uint16>(port), protocol, probability); | 443 protocol, probability); |
448 alternate_protocol_map->Put(server, port_alternate_protocol); | 444 alternate_protocol_map->Put(server, port_alternate_protocol); |
449 ++count; | 445 } |
450 } while (false); | |
451 | 446 |
452 // Get SupportsQuic. | 447 // Get SupportsQuic. |
453 DCHECK(supports_quic_map->find(server) == supports_quic_map->end()); | 448 DCHECK(supports_quic_map->find(server) == supports_quic_map->end()); |
454 const base::DictionaryValue* supports_quic_dict = NULL; | 449 const base::DictionaryValue* supports_quic_dict = NULL; |
455 if (!server_pref_dict->GetDictionaryWithoutPathExpansion( | 450 if (server_pref_dict->GetDictionaryWithoutPathExpansion( |
456 "supports_quic", &supports_quic_dict)) { | 451 "supports_quic", &supports_quic_dict)) { |
457 continue; | |
458 } | |
459 do { | |
460 bool used_quic = 0; | 452 bool used_quic = 0; |
461 if (!supports_quic_dict->GetBooleanWithoutPathExpansion( | 453 if (!supports_quic_dict->GetBooleanWithoutPathExpansion( |
462 "used_quic", &used_quic)) { | 454 "used_quic", &used_quic)) { |
463 DVLOG(1) << "Malformed SupportsQuic server: " << server_str; | 455 DVLOG(1) << "Malformed SupportsQuic server: " << server_str; |
464 detected_corrupted_prefs = true; | 456 detected_corrupted_prefs = true; |
465 continue; | 457 continue; |
466 } | 458 } |
467 std::string address; | 459 std::string address; |
468 if (!supports_quic_dict->GetStringWithoutPathExpansion( | 460 if (!supports_quic_dict->GetStringWithoutPathExpansion( |
469 "address", &address)) { | 461 "address", &address)) { |
470 DVLOG(1) << "Malformed SupportsQuic server: " << server_str; | 462 DVLOG(1) << "Malformed SupportsQuic server: " << server_str; |
471 detected_corrupted_prefs = true; | 463 detected_corrupted_prefs = true; |
472 continue; | 464 continue; |
473 } | 465 } |
474 net::SupportsQuic supports_quic(used_quic, address); | 466 SupportsQuic supports_quic(used_quic, address); |
475 supports_quic_map->insert(std::make_pair(server, supports_quic)); | 467 supports_quic_map->insert(std::make_pair(server, supports_quic)); |
476 } while (false); | 468 } |
| 469 |
| 470 // Get ServerNetworkStats. |
| 471 DCHECK(server_network_stats_map->Peek(server) == |
| 472 server_network_stats_map->end()); |
| 473 const base::DictionaryValue* server_network_stats_dict = NULL; |
| 474 if (server_pref_dict->GetDictionaryWithoutPathExpansion( |
| 475 "network_stats", &server_network_stats_dict)) { |
| 476 int srtt; |
| 477 if (!server_network_stats_dict->GetIntegerWithoutPathExpansion("srtt", |
| 478 &srtt)) { |
| 479 DVLOG(1) << "Malformed ServerNetworkStats for server: " << server_str; |
| 480 detected_corrupted_prefs = true; |
| 481 continue; |
| 482 } |
| 483 ServerNetworkStats server_network_stats; |
| 484 server_network_stats.srtt = base::TimeDelta::FromInternalValue(srtt); |
| 485 // TODO(rtenneti): When QUIC starts using bandwidth_estimate, then persist |
| 486 // bandwidth_estimate. |
| 487 server_network_stats_map->Put(server, server_network_stats); |
| 488 } |
477 } | 489 } |
478 | 490 |
479 network_task_runner_->PostTask( | 491 network_task_runner_->PostTask( |
480 FROM_HERE, | 492 FROM_HERE, |
481 base::Bind( | 493 base::Bind( |
482 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread, | 494 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread, |
483 base::Unretained(this), | 495 base::Unretained(this), base::Owned(spdy_servers.release()), |
484 base::Owned(spdy_servers.release()), | |
485 base::Owned(spdy_settings_map.release()), | 496 base::Owned(spdy_settings_map.release()), |
486 base::Owned(alternate_protocol_map.release()), | 497 base::Owned(alternate_protocol_map.release()), |
487 base::Owned(supports_quic_map.release()), | 498 base::Owned(supports_quic_map.release()), |
| 499 base::Owned(server_network_stats_map.release()), |
488 detected_corrupted_prefs)); | 500 detected_corrupted_prefs)); |
489 } | 501 } |
490 | 502 |
491 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread( | 503 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread( |
492 StringVector* spdy_servers, | 504 StringVector* spdy_servers, |
493 net::SpdySettingsMap* spdy_settings_map, | 505 SpdySettingsMap* spdy_settings_map, |
494 net::AlternateProtocolMap* alternate_protocol_map, | 506 AlternateProtocolMap* alternate_protocol_map, |
495 net::SupportsQuicMap* supports_quic_map, | 507 SupportsQuicMap* supports_quic_map, |
| 508 ServerNetworkStatsMap* server_network_stats_map, |
496 bool detected_corrupted_prefs) { | 509 bool detected_corrupted_prefs) { |
497 // Preferences have the master data because admins might have pushed new | 510 // Preferences have the master data because admins might have pushed new |
498 // preferences. Update the cached data with new data from preferences. | 511 // preferences. Update the cached data with new data from preferences. |
499 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 512 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
500 | 513 |
501 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size()); | 514 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size()); |
502 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); | 515 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); |
503 | 516 |
504 // Update the cached data and use the new spdy_settings from preferences. | 517 // Update the cached data and use the new spdy_settings from preferences. |
505 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size()); | 518 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size()); |
506 http_server_properties_impl_->InitializeSpdySettingsServers( | 519 http_server_properties_impl_->InitializeSpdySettingsServers( |
507 spdy_settings_map); | 520 spdy_settings_map); |
508 | 521 |
509 // Update the cached data and use the new Alternate-Protocol server list from | 522 // Update the cached data and use the new Alternate-Protocol server list from |
510 // preferences. | 523 // preferences. |
511 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers", | 524 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers", |
512 alternate_protocol_map->size()); | 525 alternate_protocol_map->size()); |
513 http_server_properties_impl_->InitializeAlternateProtocolServers( | 526 http_server_properties_impl_->InitializeAlternateProtocolServers( |
514 alternate_protocol_map); | 527 alternate_protocol_map); |
515 | 528 |
516 http_server_properties_impl_->InitializeSupportsQuic(supports_quic_map); | 529 http_server_properties_impl_->InitializeSupportsQuic(supports_quic_map); |
517 | 530 |
| 531 http_server_properties_impl_->InitializeServerNetworkStats( |
| 532 server_network_stats_map); |
| 533 |
518 // Update the prefs with what we have read (delete all corrupted prefs). | 534 // Update the prefs with what we have read (delete all corrupted prefs). |
519 if (detected_corrupted_prefs) | 535 if (detected_corrupted_prefs) |
520 ScheduleUpdatePrefsOnNetworkThread(); | 536 ScheduleUpdatePrefsOnNetworkThread(); |
521 } | 537 } |
522 | 538 |
523 // | 539 // |
524 // Update Preferences with data from the cached data. | 540 // Update Preferences with data from the cached data. |
525 // | 541 // |
526 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnNetworkThread() { | 542 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnNetworkThread() { |
527 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 543 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
(...skipping 20 matching lines...) Expand all Loading... |
548 } | 564 } |
549 | 565 |
550 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread( | 566 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread( |
551 const base::Closure& completion) { | 567 const base::Closure& completion) { |
552 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 568 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
553 | 569 |
554 base::ListValue* spdy_server_list = new base::ListValue; | 570 base::ListValue* spdy_server_list = new base::ListValue; |
555 http_server_properties_impl_->GetSpdyServerList( | 571 http_server_properties_impl_->GetSpdyServerList( |
556 spdy_server_list, kMaxSupportsSpdyServerHostsToPersist); | 572 spdy_server_list, kMaxSupportsSpdyServerHostsToPersist); |
557 | 573 |
558 net::SpdySettingsMap* spdy_settings_map = | 574 SpdySettingsMap* spdy_settings_map = |
559 new net::SpdySettingsMap(kMaxSpdySettingsHostsToPersist); | 575 new SpdySettingsMap(kMaxSpdySettingsHostsToPersist); |
560 const net::SpdySettingsMap& main_map = | 576 const SpdySettingsMap& main_map = |
561 http_server_properties_impl_->spdy_settings_map(); | 577 http_server_properties_impl_->spdy_settings_map(); |
562 int count = 0; | 578 int count = 0; |
563 for (net::SpdySettingsMap::const_iterator it = main_map.begin(); | 579 for (SpdySettingsMap::const_iterator it = main_map.begin(); |
564 it != main_map.end() && count < kMaxSpdySettingsHostsToPersist; | 580 it != main_map.end() && count < kMaxSpdySettingsHostsToPersist; |
565 ++it, ++count) { | 581 ++it, ++count) { |
566 spdy_settings_map->Put(it->first, it->second); | 582 spdy_settings_map->Put(it->first, it->second); |
567 } | 583 } |
568 | 584 |
569 net::AlternateProtocolMap* alternate_protocol_map = | 585 AlternateProtocolMap* alternate_protocol_map = |
570 new net::AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist); | 586 new AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist); |
571 const net::AlternateProtocolMap& map = | 587 const AlternateProtocolMap& map = |
572 http_server_properties_impl_->alternate_protocol_map(); | 588 http_server_properties_impl_->alternate_protocol_map(); |
573 count = 0; | 589 count = 0; |
574 typedef std::map<std::string, bool> CanonicalHostPersistedMap; | 590 typedef std::map<std::string, bool> CanonicalHostPersistedMap; |
575 CanonicalHostPersistedMap persisted_map; | 591 CanonicalHostPersistedMap persisted_map; |
576 for (net::AlternateProtocolMap::const_iterator it = map.begin(); | 592 for (AlternateProtocolMap::const_iterator it = map.begin(); |
577 it != map.end() && count < kMaxAlternateProtocolHostsToPersist; | 593 it != map.end() && count < kMaxAlternateProtocolHostsToPersist; ++it) { |
578 ++it) { | 594 const HostPortPair& server = it->first; |
579 const net::HostPortPair& server = it->first; | |
580 std::string canonical_suffix = | 595 std::string canonical_suffix = |
581 http_server_properties_impl_->GetCanonicalSuffix(server); | 596 http_server_properties_impl_->GetCanonicalSuffix(server); |
582 if (!canonical_suffix.empty()) { | 597 if (!canonical_suffix.empty()) { |
583 if (persisted_map.find(canonical_suffix) != persisted_map.end()) | 598 if (persisted_map.find(canonical_suffix) != persisted_map.end()) |
584 continue; | 599 continue; |
585 persisted_map[canonical_suffix] = true; | 600 persisted_map[canonical_suffix] = true; |
586 } | 601 } |
587 alternate_protocol_map->Put(server, it->second); | 602 alternate_protocol_map->Put(server, it->second); |
588 ++count; | 603 ++count; |
589 } | 604 } |
590 | 605 |
591 net::SupportsQuicMap* supports_quic_map = new net::SupportsQuicMap(); | 606 SupportsQuicMap* supports_quic_map = new SupportsQuicMap(); |
592 const net::SupportsQuicMap& main_supports_quic_map = | 607 const SupportsQuicMap& main_supports_quic_map = |
593 http_server_properties_impl_->supports_quic_map(); | 608 http_server_properties_impl_->supports_quic_map(); |
594 for (net::SupportsQuicMap::const_iterator it = main_supports_quic_map.begin(); | 609 for (SupportsQuicMap::const_iterator it = main_supports_quic_map.begin(); |
595 it != main_supports_quic_map.end(); ++it) { | 610 it != main_supports_quic_map.end(); ++it) { |
596 supports_quic_map->insert(std::make_pair(it->first, it->second)); | 611 supports_quic_map->insert(std::make_pair(it->first, it->second)); |
597 } | 612 } |
598 | 613 |
| 614 ServerNetworkStatsMap* server_network_stats_map = |
| 615 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist); |
| 616 const ServerNetworkStatsMap& main_server_network_stats_map = |
| 617 http_server_properties_impl_->server_network_stats_map(); |
| 618 for (ServerNetworkStatsMap::const_iterator it = |
| 619 main_server_network_stats_map.begin(); |
| 620 it != main_server_network_stats_map.end(); ++it) { |
| 621 server_network_stats_map->Put(it->first, it->second); |
| 622 } |
| 623 |
599 // Update the preferences on the pref thread. | 624 // Update the preferences on the pref thread. |
600 pref_task_runner_->PostTask( | 625 pref_task_runner_->PostTask( |
601 FROM_HERE, | 626 FROM_HERE, |
602 base::Bind(&HttpServerPropertiesManager::UpdatePrefsOnPrefThread, | 627 base::Bind( |
603 pref_weak_ptr_, | 628 &HttpServerPropertiesManager::UpdatePrefsOnPrefThread, pref_weak_ptr_, |
604 base::Owned(spdy_server_list), | 629 base::Owned(spdy_server_list), base::Owned(spdy_settings_map), |
605 base::Owned(spdy_settings_map), | 630 base::Owned(alternate_protocol_map), base::Owned(supports_quic_map), |
606 base::Owned(alternate_protocol_map), | 631 base::Owned(server_network_stats_map), completion)); |
607 base::Owned(supports_quic_map), | |
608 completion)); | |
609 } | 632 } |
610 | 633 |
611 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, | 634 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, |
612 // AlternateProtocolInfo and SupportsQuic preferences for a server. This is used | 635 // AlternateProtocolInfo and SupportsQuic preferences for a server. This is used |
613 // only in UpdatePrefsOnPrefThread. | 636 // only in UpdatePrefsOnPrefThread. |
614 struct ServerPref { | 637 struct ServerPref { |
615 ServerPref() : supports_spdy(false), | 638 ServerPref() |
616 settings_map(NULL), | 639 : supports_spdy(false), |
617 alternate_protocol(NULL), | 640 settings_map(NULL), |
618 supports_quic(NULL) {} | 641 alternate_protocol(NULL), |
| 642 supports_quic(NULL), |
| 643 server_network_stats(NULL) {} |
619 ServerPref(bool supports_spdy, | 644 ServerPref(bool supports_spdy, |
620 const net::SettingsMap* settings_map, | 645 const SettingsMap* settings_map, |
621 const net::AlternateProtocolInfo* alternate_protocol, | 646 const AlternateProtocolInfo* alternate_protocol, |
622 const net::SupportsQuic* supports_quic) | 647 const SupportsQuic* supports_quic, |
| 648 const ServerNetworkStats* server_network_stats) |
623 : supports_spdy(supports_spdy), | 649 : supports_spdy(supports_spdy), |
624 settings_map(settings_map), | 650 settings_map(settings_map), |
625 alternate_protocol(alternate_protocol), | 651 alternate_protocol(alternate_protocol), |
626 supports_quic(supports_quic) {} | 652 supports_quic(supports_quic), |
| 653 server_network_stats(server_network_stats) {} |
627 bool supports_spdy; | 654 bool supports_spdy; |
628 const net::SettingsMap* settings_map; | 655 const SettingsMap* settings_map; |
629 const net::AlternateProtocolInfo* alternate_protocol; | 656 const AlternateProtocolInfo* alternate_protocol; |
630 const net::SupportsQuic* supports_quic; | 657 const SupportsQuic* supports_quic; |
| 658 const ServerNetworkStats* server_network_stats; |
631 }; | 659 }; |
632 | 660 |
633 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( | 661 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( |
634 base::ListValue* spdy_server_list, | 662 base::ListValue* spdy_server_list, |
635 net::SpdySettingsMap* spdy_settings_map, | 663 SpdySettingsMap* spdy_settings_map, |
636 net::AlternateProtocolMap* alternate_protocol_map, | 664 AlternateProtocolMap* alternate_protocol_map, |
637 net::SupportsQuicMap* supports_quic_map, | 665 SupportsQuicMap* supports_quic_map, |
| 666 ServerNetworkStatsMap* server_network_stats_map, |
638 const base::Closure& completion) { | 667 const base::Closure& completion) { |
639 typedef std::map<net::HostPortPair, ServerPref> ServerPrefMap; | 668 typedef std::map<HostPortPair, ServerPref> ServerPrefMap; |
640 ServerPrefMap server_pref_map; | 669 ServerPrefMap server_pref_map; |
641 | 670 |
642 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 671 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
643 | 672 |
644 // Add servers that support spdy to server_pref_map. | 673 // Add servers that support spdy to server_pref_map. |
645 std::string s; | 674 std::string s; |
646 for (base::ListValue::const_iterator list_it = spdy_server_list->begin(); | 675 for (base::ListValue::const_iterator list_it = spdy_server_list->begin(); |
647 list_it != spdy_server_list->end(); | 676 list_it != spdy_server_list->end(); |
648 ++list_it) { | 677 ++list_it) { |
649 if ((*list_it)->GetAsString(&s)) { | 678 if ((*list_it)->GetAsString(&s)) { |
650 net::HostPortPair server = net::HostPortPair::FromString(s); | 679 HostPortPair server = HostPortPair::FromString(s); |
651 | 680 |
652 ServerPrefMap::iterator it = server_pref_map.find(server); | 681 ServerPrefMap::iterator it = server_pref_map.find(server); |
653 if (it == server_pref_map.end()) { | 682 if (it == server_pref_map.end()) { |
654 ServerPref server_pref(true, NULL, NULL, NULL); | 683 ServerPref server_pref(true, NULL, NULL, NULL, NULL); |
655 server_pref_map[server] = server_pref; | 684 server_pref_map[server] = server_pref; |
656 } else { | 685 } else { |
657 it->second.supports_spdy = true; | 686 it->second.supports_spdy = true; |
658 } | 687 } |
659 } | 688 } |
660 } | 689 } |
661 | 690 |
662 // Add servers that have SpdySettings to server_pref_map. | 691 // Add servers that have SpdySettings to server_pref_map. |
663 for (net::SpdySettingsMap::iterator map_it = spdy_settings_map->begin(); | 692 for (SpdySettingsMap::iterator map_it = spdy_settings_map->begin(); |
664 map_it != spdy_settings_map->end(); | 693 map_it != spdy_settings_map->end(); ++map_it) { |
665 ++map_it) { | 694 const HostPortPair& server = map_it->first; |
666 const net::HostPortPair& server = map_it->first; | |
667 | 695 |
668 ServerPrefMap::iterator it = server_pref_map.find(server); | 696 ServerPrefMap::iterator it = server_pref_map.find(server); |
669 if (it == server_pref_map.end()) { | 697 if (it == server_pref_map.end()) { |
670 ServerPref server_pref(false, &map_it->second, NULL, NULL); | 698 ServerPref server_pref(false, &map_it->second, NULL, NULL, NULL); |
671 server_pref_map[server] = server_pref; | 699 server_pref_map[server] = server_pref; |
672 } else { | 700 } else { |
673 it->second.settings_map = &map_it->second; | 701 it->second.settings_map = &map_it->second; |
674 } | 702 } |
675 } | 703 } |
676 | 704 |
677 // Add AlternateProtocol servers to server_pref_map. | 705 // Add AlternateProtocol servers to server_pref_map. |
678 for (net::AlternateProtocolMap::const_iterator map_it = | 706 for (AlternateProtocolMap::const_iterator map_it = |
679 alternate_protocol_map->begin(); | 707 alternate_protocol_map->begin(); |
680 map_it != alternate_protocol_map->end(); | 708 map_it != alternate_protocol_map->end(); ++map_it) { |
681 ++map_it) { | 709 const HostPortPair& server = map_it->first; |
682 const net::HostPortPair& server = map_it->first; | 710 const AlternateProtocolInfo& port_alternate_protocol = map_it->second; |
683 const net::AlternateProtocolInfo& port_alternate_protocol = | 711 if (!IsAlternateProtocolValid(port_alternate_protocol.protocol)) { |
684 map_it->second; | |
685 if (!net::IsAlternateProtocolValid(port_alternate_protocol.protocol)) { | |
686 continue; | 712 continue; |
687 } | 713 } |
688 | 714 |
689 ServerPrefMap::iterator it = server_pref_map.find(server); | 715 ServerPrefMap::iterator it = server_pref_map.find(server); |
690 if (it == server_pref_map.end()) { | 716 if (it == server_pref_map.end()) { |
691 ServerPref server_pref(false, NULL, &map_it->second, NULL); | 717 ServerPref server_pref(false, NULL, &map_it->second, NULL, NULL); |
692 server_pref_map[server] = server_pref; | 718 server_pref_map[server] = server_pref; |
693 } else { | 719 } else { |
694 it->second.alternate_protocol = &map_it->second; | 720 it->second.alternate_protocol = &map_it->second; |
695 } | 721 } |
696 } | 722 } |
697 | 723 |
698 // Add SupportsQuic servers to server_pref_map. | 724 // Add SupportsQuic servers to server_pref_map. |
699 for (net::SupportsQuicMap::const_iterator map_it = supports_quic_map->begin(); | 725 for (SupportsQuicMap::const_iterator map_it = supports_quic_map->begin(); |
700 map_it != supports_quic_map->end(); ++map_it) { | 726 map_it != supports_quic_map->end(); ++map_it) { |
701 const net::HostPortPair& server = map_it->first; | 727 const HostPortPair& server = map_it->first; |
702 | 728 |
703 ServerPrefMap::iterator it = server_pref_map.find(server); | 729 ServerPrefMap::iterator it = server_pref_map.find(server); |
704 if (it == server_pref_map.end()) { | 730 if (it == server_pref_map.end()) { |
705 ServerPref server_pref(false, NULL, NULL, &map_it->second); | 731 ServerPref server_pref(false, NULL, NULL, &map_it->second, NULL); |
706 server_pref_map[server] = server_pref; | 732 server_pref_map[server] = server_pref; |
707 } else { | 733 } else { |
708 it->second.supports_quic = &map_it->second; | 734 it->second.supports_quic = &map_it->second; |
709 } | 735 } |
710 } | 736 } |
711 | 737 |
| 738 // Add ServerNetworkStats servers to server_pref_map. |
| 739 for (ServerNetworkStatsMap::const_iterator map_it = |
| 740 server_network_stats_map->begin(); |
| 741 map_it != server_network_stats_map->end(); ++map_it) { |
| 742 const HostPortPair& server = map_it->first; |
| 743 |
| 744 ServerPrefMap::iterator it = server_pref_map.find(server); |
| 745 if (it == server_pref_map.end()) { |
| 746 ServerPref server_pref(false, NULL, NULL, NULL, &map_it->second); |
| 747 server_pref_map[server] = server_pref; |
| 748 } else { |
| 749 it->second.server_network_stats = &map_it->second; |
| 750 } |
| 751 } |
| 752 |
712 // Persist properties to the |path_|. | 753 // Persist properties to the |path_|. |
713 base::DictionaryValue http_server_properties_dict; | 754 base::DictionaryValue http_server_properties_dict; |
714 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 755 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
715 for (ServerPrefMap::const_iterator map_it = server_pref_map.begin(); | 756 for (ServerPrefMap::const_iterator map_it = server_pref_map.begin(); |
716 map_it != server_pref_map.end(); | 757 map_it != server_pref_map.end(); |
717 ++map_it) { | 758 ++map_it) { |
718 const net::HostPortPair& server = map_it->first; | 759 const HostPortPair& server = map_it->first; |
719 const ServerPref& server_pref = map_it->second; | 760 const ServerPref& server_pref = map_it->second; |
720 | 761 |
721 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 762 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
722 | 763 |
723 // Save supports_spdy. | 764 // Save supports_spdy. |
724 if (server_pref.supports_spdy) | 765 if (server_pref.supports_spdy) |
725 server_pref_dict->SetBoolean("supports_spdy", server_pref.supports_spdy); | 766 server_pref_dict->SetBoolean("supports_spdy", server_pref.supports_spdy); |
726 | 767 |
727 // Save SPDY settings. | 768 // Save SPDY settings. |
728 if (server_pref.settings_map) { | 769 if (server_pref.settings_map) { |
729 base::DictionaryValue* spdy_settings_dict = new base::DictionaryValue; | 770 base::DictionaryValue* spdy_settings_dict = new base::DictionaryValue; |
730 for (net::SettingsMap::const_iterator it = | 771 for (SettingsMap::const_iterator it = server_pref.settings_map->begin(); |
731 server_pref.settings_map->begin(); | 772 it != server_pref.settings_map->end(); ++it) { |
732 it != server_pref.settings_map->end(); | 773 SpdySettingsIds id = it->first; |
733 ++it) { | |
734 net::SpdySettingsIds id = it->first; | |
735 uint32 value = it->second.second; | 774 uint32 value = it->second.second; |
736 std::string key = base::StringPrintf("%u", id); | 775 std::string key = base::StringPrintf("%u", id); |
737 spdy_settings_dict->SetInteger(key, value); | 776 spdy_settings_dict->SetInteger(key, value); |
738 } | 777 } |
739 server_pref_dict->SetWithoutPathExpansion("settings", spdy_settings_dict); | 778 server_pref_dict->SetWithoutPathExpansion("settings", spdy_settings_dict); |
740 } | 779 } |
741 | 780 |
742 // Save alternate_protocol. | 781 // Save alternate_protocol. |
743 const net::AlternateProtocolInfo* port_alternate_protocol = | 782 const AlternateProtocolInfo* port_alternate_protocol = |
744 server_pref.alternate_protocol; | 783 server_pref.alternate_protocol; |
745 if (port_alternate_protocol && !port_alternate_protocol->is_broken) { | 784 if (port_alternate_protocol && !port_alternate_protocol->is_broken) { |
746 base::DictionaryValue* port_alternate_protocol_dict = | 785 base::DictionaryValue* port_alternate_protocol_dict = |
747 new base::DictionaryValue; | 786 new base::DictionaryValue; |
748 port_alternate_protocol_dict->SetInteger("port", | 787 port_alternate_protocol_dict->SetInteger("port", |
749 port_alternate_protocol->port); | 788 port_alternate_protocol->port); |
750 const char* protocol_str = | 789 const char* protocol_str = |
751 net::AlternateProtocolToString(port_alternate_protocol->protocol); | 790 AlternateProtocolToString(port_alternate_protocol->protocol); |
752 port_alternate_protocol_dict->SetString("protocol_str", protocol_str); | 791 port_alternate_protocol_dict->SetString("protocol_str", protocol_str); |
753 port_alternate_protocol_dict->SetDouble( | 792 port_alternate_protocol_dict->SetDouble( |
754 "probability", port_alternate_protocol->probability); | 793 "probability", port_alternate_protocol->probability); |
755 server_pref_dict->SetWithoutPathExpansion( | 794 server_pref_dict->SetWithoutPathExpansion( |
756 "alternate_protocol", port_alternate_protocol_dict); | 795 "alternate_protocol", port_alternate_protocol_dict); |
757 } | 796 } |
758 | 797 |
759 // Save supports_quic. | 798 // Save supports_quic. |
760 if (server_pref.supports_quic) { | 799 if (server_pref.supports_quic) { |
761 base::DictionaryValue* supports_quic_dict = new base::DictionaryValue; | 800 base::DictionaryValue* supports_quic_dict = new base::DictionaryValue; |
762 const net::SupportsQuic* supports_quic = server_pref.supports_quic; | 801 const SupportsQuic* supports_quic = server_pref.supports_quic; |
763 supports_quic_dict->SetBoolean("used_quic", supports_quic->used_quic); | 802 supports_quic_dict->SetBoolean("used_quic", supports_quic->used_quic); |
764 supports_quic_dict->SetString("address", supports_quic->address); | 803 supports_quic_dict->SetString("address", supports_quic->address); |
765 server_pref_dict->SetWithoutPathExpansion( | 804 server_pref_dict->SetWithoutPathExpansion( |
766 "supports_quic", supports_quic_dict); | 805 "supports_quic", supports_quic_dict); |
767 } | 806 } |
768 | 807 |
| 808 // Save ServerNetworkStats. |
| 809 if (server_pref.server_network_stats) { |
| 810 base::DictionaryValue* server_network_stats_dict = |
| 811 new base::DictionaryValue; |
| 812 const ServerNetworkStats* server_network_stats = |
| 813 server_pref.server_network_stats; |
| 814 // Becasue JSON doesn't support int64, persist int64 as a string. |
| 815 server_network_stats_dict->SetInteger( |
| 816 "srtt", |
| 817 static_cast<int>(server_network_stats->srtt.ToInternalValue())); |
| 818 // TODO(rtenneti): When QUIC starts using bandwidth_estimate, then persist |
| 819 // bandwidth_estimate. |
| 820 server_pref_dict->SetWithoutPathExpansion("network_stats", |
| 821 server_network_stats_dict); |
| 822 } |
| 823 |
769 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict); | 824 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict); |
770 } | 825 } |
771 | 826 |
772 http_server_properties_dict.SetWithoutPathExpansion("servers", servers_dict); | 827 http_server_properties_dict.SetWithoutPathExpansion("servers", servers_dict); |
773 SetVersion(&http_server_properties_dict, kVersionNumber); | 828 SetVersion(&http_server_properties_dict, kVersionNumber); |
774 setting_prefs_ = true; | 829 setting_prefs_ = true; |
775 pref_service_->Set(path_, http_server_properties_dict); | 830 pref_service_->Set(path_, http_server_properties_dict); |
776 setting_prefs_ = false; | 831 setting_prefs_ = false; |
777 | 832 |
778 // Note that |completion| will be fired after we have written everything to | 833 // Note that |completion| will be fired after we have written everything to |
779 // the Preferences, but likely before these changes are serialized to disk. | 834 // the Preferences, but likely before these changes are serialized to disk. |
780 // This is not a problem though, as JSONPrefStore guarantees that this will | 835 // This is not a problem though, as JSONPrefStore guarantees that this will |
781 // happen, pretty soon, and even in the case we shut down immediately. | 836 // happen, pretty soon, and even in the case we shut down immediately. |
782 if (!completion.is_null()) | 837 if (!completion.is_null()) |
783 completion.Run(); | 838 completion.Run(); |
784 } | 839 } |
785 | 840 |
786 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { | 841 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { |
787 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 842 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
788 if (!setting_prefs_) | 843 if (!setting_prefs_) |
789 ScheduleUpdateCacheOnPrefThread(); | 844 ScheduleUpdateCacheOnPrefThread(); |
790 } | 845 } |
791 | 846 |
792 } // namespace net | 847 } // namespace net |
OLD | NEW |