Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: net/http/http_server_properties_manager.cc

Issue 903273002: Update from https://crrev.com/315085 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
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. 50 // Persist 200 ServerNetworkStats.
51 const int kMaxServerNetworkStatsHostsToPersist = 200; 51 const int kMaxServerNetworkStatsHostsToPersist = 200;
52 52
53 const char kVersionKey[] = "version";
54 const char kServersKey[] = "servers";
55 const char kSupportsSpdyKey[] = "supports_spdy";
56 const char kSettingsKey[] = "settings";
57 const char kSupportsQuicKey[] = "supports_quic";
58 const char kUsedQuicKey[] = "used_quic";
59 const char kAddressKey[] = "address";
60 const char kAlternateProtocolKey[] = "alternate_protocol";
61 const char kPortKey[] = "port";
62 const char kProtocolKey[] = "protocol_str";
63 const char kProbabilityKey[] = "probability";
64 const char kNetworkStatsKey[] = "network_stats";
65 const char kSrttKey[] = "srtt";
66
53 } // namespace 67 } // namespace
54 68
55 //////////////////////////////////////////////////////////////////////////////// 69 ////////////////////////////////////////////////////////////////////////////////
56 // HttpServerPropertiesManager 70 // HttpServerPropertiesManager
57 71
58 HttpServerPropertiesManager::HttpServerPropertiesManager( 72 HttpServerPropertiesManager::HttpServerPropertiesManager(
59 PrefService* pref_service, 73 PrefService* pref_service,
60 const char* pref_path, 74 const char* pref_path,
61 scoped_refptr<base::SequencedTaskRunner> network_task_runner) 75 scoped_refptr<base::SequencedTaskRunner> network_task_runner)
62 : pref_task_runner_(base::ThreadTaskRunnerHandle::Get()), 76 : pref_task_runner_(base::ThreadTaskRunnerHandle::Get()),
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 } 120 }
107 121
108 // static 122 // static
109 void HttpServerPropertiesManager::SetVersion( 123 void HttpServerPropertiesManager::SetVersion(
110 base::DictionaryValue* http_server_properties_dict, 124 base::DictionaryValue* http_server_properties_dict,
111 int version_number) { 125 int version_number) {
112 if (version_number < 0) 126 if (version_number < 0)
113 version_number = kVersionNumber; 127 version_number = kVersionNumber;
114 DCHECK_LE(version_number, kVersionNumber); 128 DCHECK_LE(version_number, kVersionNumber);
115 if (version_number <= kVersionNumber) 129 if (version_number <= kVersionNumber)
116 http_server_properties_dict->SetInteger("version", version_number); 130 http_server_properties_dict->SetInteger(kVersionKey, version_number);
117 } 131 }
118 132
119 // This is required for conformance with the HttpServerProperties interface. 133 // This is required for conformance with the HttpServerProperties interface.
120 base::WeakPtr<HttpServerProperties> HttpServerPropertiesManager::GetWeakPtr() { 134 base::WeakPtr<HttpServerProperties> HttpServerPropertiesManager::GetWeakPtr() {
121 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 135 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
122 return network_weak_ptr_factory_->GetWeakPtr(); 136 return network_weak_ptr_factory_->GetWeakPtr();
123 } 137 }
124 138
125 void HttpServerPropertiesManager::Clear() { 139 void HttpServerPropertiesManager::Clear() {
126 Clear(base::Closure()); 140 Clear(base::Closure());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
159 http_server_properties_impl_->SetHTTP11Required(server); 173 http_server_properties_impl_->SetHTTP11Required(server);
160 ScheduleUpdatePrefsOnNetworkThread(); 174 ScheduleUpdatePrefsOnNetworkThread();
161 } 175 }
162 176
163 void HttpServerPropertiesManager::MaybeForceHTTP11(const HostPortPair& server, 177 void HttpServerPropertiesManager::MaybeForceHTTP11(const HostPortPair& server,
164 SSLConfig* ssl_config) { 178 SSLConfig* ssl_config) {
165 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 179 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
166 http_server_properties_impl_->MaybeForceHTTP11(server, ssl_config); 180 http_server_properties_impl_->MaybeForceHTTP11(server, ssl_config);
167 } 181 }
168 182
169 bool HttpServerPropertiesManager::HasAlternateProtocol(
170 const HostPortPair& server) {
171 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
172 return http_server_properties_impl_->HasAlternateProtocol(server);
173 }
174
175 AlternateProtocolInfo HttpServerPropertiesManager::GetAlternateProtocol( 183 AlternateProtocolInfo HttpServerPropertiesManager::GetAlternateProtocol(
176 const HostPortPair& server) { 184 const HostPortPair& server) {
177 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 185 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
178 return http_server_properties_impl_->GetAlternateProtocol(server); 186 return http_server_properties_impl_->GetAlternateProtocol(server);
179 } 187 }
180 188
181 void HttpServerPropertiesManager::SetAlternateProtocol( 189 void HttpServerPropertiesManager::SetAlternateProtocol(
182 const HostPortPair& server, 190 const HostPortPair& server,
183 uint16 alternate_port, 191 uint16 alternate_port,
184 AlternateProtocol alternate_protocol, 192 AlternateProtocol alternate_protocol,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 http_server_properties_impl_->ClearAllSpdySettings(); 269 http_server_properties_impl_->ClearAllSpdySettings();
262 ScheduleUpdatePrefsOnNetworkThread(); 270 ScheduleUpdatePrefsOnNetworkThread();
263 } 271 }
264 272
265 const SpdySettingsMap& HttpServerPropertiesManager::spdy_settings_map() 273 const SpdySettingsMap& HttpServerPropertiesManager::spdy_settings_map()
266 const { 274 const {
267 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 275 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
268 return http_server_properties_impl_->spdy_settings_map(); 276 return http_server_properties_impl_->spdy_settings_map();
269 } 277 }
270 278
271 SupportsQuic HttpServerPropertiesManager::GetSupportsQuic( 279 bool HttpServerPropertiesManager::GetSupportsQuic(
272 const HostPortPair& host_port_pair) const { 280 IPAddressNumber* last_address) const {
273 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 281 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
274 return http_server_properties_impl_->GetSupportsQuic(host_port_pair); 282 return http_server_properties_impl_->GetSupportsQuic(last_address);
275 } 283 }
276 284
277 void HttpServerPropertiesManager::SetSupportsQuic( 285 void HttpServerPropertiesManager::SetSupportsQuic(
278 const HostPortPair& host_port_pair,
279 bool used_quic, 286 bool used_quic,
280 const std::string& address) { 287 const IPAddressNumber& address) {
281 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 288 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
282 http_server_properties_impl_->SetSupportsQuic( 289 http_server_properties_impl_->SetSupportsQuic(used_quic, address);
283 host_port_pair, used_quic, address);
284 ScheduleUpdatePrefsOnNetworkThread(); 290 ScheduleUpdatePrefsOnNetworkThread();
285 } 291 }
286 292
287 const SupportsQuicMap& HttpServerPropertiesManager::supports_quic_map()
288 const {
289 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
290 return http_server_properties_impl_->supports_quic_map();
291 }
292
293 void HttpServerPropertiesManager::SetServerNetworkStats( 293 void HttpServerPropertiesManager::SetServerNetworkStats(
294 const HostPortPair& host_port_pair, 294 const HostPortPair& host_port_pair,
295 ServerNetworkStats stats) { 295 ServerNetworkStats stats) {
296 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 296 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
297 http_server_properties_impl_->SetServerNetworkStats(host_port_pair, stats); 297 http_server_properties_impl_->SetServerNetworkStats(host_port_pair, stats);
298 ScheduleUpdatePrefsOnNetworkThread(); 298 ScheduleUpdatePrefsOnNetworkThread();
299 } 299 }
300 300
301 const ServerNetworkStats* HttpServerPropertiesManager::GetServerNetworkStats( 301 const ServerNetworkStats* HttpServerPropertiesManager::GetServerNetworkStats(
302 const HostPortPair& host_port_pair) { 302 const HostPortPair& host_port_pair) {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); 336 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread());
337 337
338 if (!pref_service_->HasPrefPath(path_)) 338 if (!pref_service_->HasPrefPath(path_))
339 return; 339 return;
340 340
341 bool detected_corrupted_prefs = false; 341 bool detected_corrupted_prefs = false;
342 const base::DictionaryValue& http_server_properties_dict = 342 const base::DictionaryValue& http_server_properties_dict =
343 *pref_service_->GetDictionary(path_); 343 *pref_service_->GetDictionary(path_);
344 344
345 int version = kMissingVersion; 345 int version = kMissingVersion;
346 if (!http_server_properties_dict.GetIntegerWithoutPathExpansion("version", 346 if (!http_server_properties_dict.GetIntegerWithoutPathExpansion(kVersionKey,
347 &version)) { 347 &version)) {
348 DVLOG(1) << "Missing version. Clearing all properties."; 348 DVLOG(1) << "Missing version. Clearing all properties.";
349 return; 349 return;
350 } 350 }
351 351
352 // The properties for a given server is in 352 // The properties for a given server is in
353 // http_server_properties_dict["servers"][server]. 353 // http_server_properties_dict["servers"][server].
354 const base::DictionaryValue* servers_dict = NULL; 354 const base::DictionaryValue* servers_dict = NULL;
355 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion( 355 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion(
356 "servers", &servers_dict)) { 356 kServersKey, &servers_dict)) {
357 DVLOG(1) << "Malformed http_server_properties for servers."; 357 DVLOG(1) << "Malformed http_server_properties for servers.";
358 return; 358 return;
359 } 359 }
360 360
361 IPAddressNumber* addr = new IPAddressNumber;
362 ReadSupportsQuic(http_server_properties_dict, addr);
363
361 // String is host/port pair of spdy server. 364 // String is host/port pair of spdy server.
362 scoped_ptr<StringVector> spdy_servers(new StringVector); 365 scoped_ptr<StringVector> spdy_servers(new StringVector);
363 scoped_ptr<SpdySettingsMap> spdy_settings_map( 366 scoped_ptr<SpdySettingsMap> spdy_settings_map(
364 new SpdySettingsMap(kMaxSpdySettingsHostsToPersist)); 367 new SpdySettingsMap(kMaxSpdySettingsHostsToPersist));
365 scoped_ptr<AlternateProtocolMap> alternate_protocol_map( 368 scoped_ptr<AlternateProtocolMap> alternate_protocol_map(
366 new AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist)); 369 new AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist));
367 scoped_ptr<SupportsQuicMap> supports_quic_map(new SupportsQuicMap());
368 scoped_ptr<ServerNetworkStatsMap> server_network_stats_map( 370 scoped_ptr<ServerNetworkStatsMap> server_network_stats_map(
369 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist)); 371 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist));
370 372
371 for (base::DictionaryValue::Iterator it(*servers_dict); !it.IsAtEnd(); 373 for (base::DictionaryValue::Iterator it(*servers_dict); !it.IsAtEnd();
372 it.Advance()) { 374 it.Advance()) {
373 // Get server's host/pair. 375 // Get server's host/pair.
374 const std::string& server_str = it.key(); 376 const std::string& server_str = it.key();
375 HostPortPair server = HostPortPair::FromString(server_str); 377 HostPortPair server = HostPortPair::FromString(server_str);
376 if (server.host().empty()) { 378 if (server.host().empty()) {
377 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; 379 DVLOG(1) << "Malformed http_server_properties for server: " << server_str;
378 detected_corrupted_prefs = true; 380 detected_corrupted_prefs = true;
379 continue; 381 continue;
380 } 382 }
381 383
382 const base::DictionaryValue* server_pref_dict = NULL; 384 const base::DictionaryValue* server_pref_dict = NULL;
383 if (!it.value().GetAsDictionary(&server_pref_dict)) { 385 if (!it.value().GetAsDictionary(&server_pref_dict)) {
384 DVLOG(1) << "Malformed http_server_properties server: " << server_str; 386 DVLOG(1) << "Malformed http_server_properties server: " << server_str;
385 detected_corrupted_prefs = true; 387 detected_corrupted_prefs = true;
386 continue; 388 continue;
387 } 389 }
388 390
389 // Get if server supports Spdy. 391 // Get if server supports Spdy.
390 bool supports_spdy = false; 392 bool supports_spdy = false;
391 if ((server_pref_dict->GetBoolean("supports_spdy", &supports_spdy)) && 393 if ((server_pref_dict->GetBoolean(kSupportsSpdyKey, &supports_spdy)) &&
392 supports_spdy) { 394 supports_spdy) {
393 spdy_servers->push_back(server_str); 395 spdy_servers->push_back(server_str);
394 } 396 }
395 397
396 // Get SpdySettings. 398 AddToSpdySettingsMap(server, *server_pref_dict, spdy_settings_map.get());
397 DCHECK(spdy_settings_map->Peek(server) == spdy_settings_map->end()); 399 if (!AddToAlternateProtocolMap(server, *server_pref_dict,
398 const base::DictionaryValue* spdy_settings_dict = NULL; 400 alternate_protocol_map.get()) ||
399 if (server_pref_dict->GetDictionaryWithoutPathExpansion( 401 !AddToNetworkStatsMap(server, *server_pref_dict,
400 "settings", &spdy_settings_dict)) { 402 server_network_stats_map.get())) {
401 SettingsMap settings_map; 403 detected_corrupted_prefs = true;
402 for (base::DictionaryValue::Iterator dict_it(*spdy_settings_dict);
403 !dict_it.IsAtEnd();
404 dict_it.Advance()) {
405 const std::string& id_str = dict_it.key();
406 int id = 0;
407 if (!base::StringToInt(id_str, &id)) {
408 DVLOG(1) << "Malformed id in SpdySettings for server: " << server_str;
409 NOTREACHED();
410 continue;
411 }
412 int value = 0;
413 if (!dict_it.value().GetAsInteger(&value)) {
414 DVLOG(1) << "Malformed value in SpdySettings for server: "
415 << server_str;
416 NOTREACHED();
417 continue;
418 }
419 SettingsFlagsAndValue flags_and_value(SETTINGS_FLAG_PERSISTED, value);
420 settings_map[static_cast<SpdySettingsIds>(id)] = flags_and_value;
421 }
422 spdy_settings_map->Put(server, settings_map);
423 }
424
425 // Get alternate_protocol server.
426 DCHECK(alternate_protocol_map->Peek(server) ==
427 alternate_protocol_map->end());
428 const base::DictionaryValue* port_alternate_protocol_dict = NULL;
429 if (server_pref_dict->GetDictionaryWithoutPathExpansion(
430 "alternate_protocol", &port_alternate_protocol_dict)) {
431 int port = 0;
432 if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion(
433 "port", &port) ||
434 !IsPortValid(port)) {
435 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str;
436 detected_corrupted_prefs = true;
437 continue;
438 }
439 std::string protocol_str;
440 if (!port_alternate_protocol_dict->GetStringWithoutPathExpansion(
441 "protocol_str", &protocol_str)) {
442 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str;
443 detected_corrupted_prefs = true;
444 continue;
445 }
446 AlternateProtocol protocol = AlternateProtocolFromString(protocol_str);
447 if (!IsAlternateProtocolValid(protocol)) {
448 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str;
449 detected_corrupted_prefs = true;
450 continue;
451 }
452
453 double probability = 1;
454 if (port_alternate_protocol_dict->HasKey("probability") &&
455 !port_alternate_protocol_dict->GetDoubleWithoutPathExpansion(
456 "probability", &probability)) {
457 DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str;
458 detected_corrupted_prefs = true;
459 continue;
460 }
461
462 AlternateProtocolInfo port_alternate_protocol(static_cast<uint16>(port),
463 protocol, probability);
464 alternate_protocol_map->Put(server, port_alternate_protocol);
465 }
466
467 // Get SupportsQuic.
468 DCHECK(supports_quic_map->find(server) == supports_quic_map->end());
469 const base::DictionaryValue* supports_quic_dict = NULL;
470 if (server_pref_dict->GetDictionaryWithoutPathExpansion(
471 "supports_quic", &supports_quic_dict)) {
472 bool used_quic = 0;
473 if (!supports_quic_dict->GetBooleanWithoutPathExpansion(
474 "used_quic", &used_quic)) {
475 DVLOG(1) << "Malformed SupportsQuic server: " << server_str;
476 detected_corrupted_prefs = true;
477 continue;
478 }
479 std::string address;
480 if (!supports_quic_dict->GetStringWithoutPathExpansion(
481 "address", &address)) {
482 DVLOG(1) << "Malformed SupportsQuic server: " << server_str;
483 detected_corrupted_prefs = true;
484 continue;
485 }
486 SupportsQuic supports_quic(used_quic, address);
487 supports_quic_map->insert(std::make_pair(server, supports_quic));
488 }
489
490 // Get ServerNetworkStats.
491 DCHECK(server_network_stats_map->Peek(server) ==
492 server_network_stats_map->end());
493 const base::DictionaryValue* server_network_stats_dict = NULL;
494 if (server_pref_dict->GetDictionaryWithoutPathExpansion(
495 "network_stats", &server_network_stats_dict)) {
496 int srtt;
497 if (!server_network_stats_dict->GetIntegerWithoutPathExpansion("srtt",
498 &srtt)) {
499 DVLOG(1) << "Malformed ServerNetworkStats for server: " << server_str;
500 detected_corrupted_prefs = true;
501 continue;
502 }
503 ServerNetworkStats server_network_stats;
504 server_network_stats.srtt = base::TimeDelta::FromInternalValue(srtt);
505 // TODO(rtenneti): When QUIC starts using bandwidth_estimate, then persist
506 // bandwidth_estimate.
507 server_network_stats_map->Put(server, server_network_stats);
508 } 404 }
509 } 405 }
510 406
511 network_task_runner_->PostTask( 407 network_task_runner_->PostTask(
512 FROM_HERE, 408 FROM_HERE,
513 base::Bind( 409 base::Bind(
514 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread, 410 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread,
515 base::Unretained(this), base::Owned(spdy_servers.release()), 411 base::Unretained(this), base::Owned(spdy_servers.release()),
516 base::Owned(spdy_settings_map.release()), 412 base::Owned(spdy_settings_map.release()),
517 base::Owned(alternate_protocol_map.release()), 413 base::Owned(alternate_protocol_map.release()), base::Owned(addr),
518 base::Owned(supports_quic_map.release()),
519 base::Owned(server_network_stats_map.release()), 414 base::Owned(server_network_stats_map.release()),
520 detected_corrupted_prefs)); 415 detected_corrupted_prefs));
521 } 416 }
522 417
418 void HttpServerPropertiesManager::AddToSpdySettingsMap(
419 const HostPortPair& server,
420 const base::DictionaryValue& server_pref_dict,
421 SpdySettingsMap* spdy_settings_map) {
422 // Get SpdySettings.
423 DCHECK(spdy_settings_map->Peek(server) == spdy_settings_map->end());
424 const base::DictionaryValue* spdy_settings_dict = NULL;
425 if (!server_pref_dict.GetDictionaryWithoutPathExpansion(
426 kSettingsKey, &spdy_settings_dict)) {
427 return;
428 }
429 SettingsMap settings_map;
430 for (base::DictionaryValue::Iterator dict_it(*spdy_settings_dict);
431 !dict_it.IsAtEnd(); dict_it.Advance()) {
432 const std::string& id_str = dict_it.key();
433 int id = 0;
434 if (!base::StringToInt(id_str, &id)) {
435 DVLOG(1) << "Malformed id in SpdySettings for server: "
436 << server.ToString();
437 NOTREACHED();
438 continue;
439 }
440 int value = 0;
441 if (!dict_it.value().GetAsInteger(&value)) {
442 DVLOG(1) << "Malformed value in SpdySettings for server: "
443 << server.ToString();
444 NOTREACHED();
445 continue;
446 }
447 SettingsFlagsAndValue flags_and_value(SETTINGS_FLAG_PERSISTED, value);
448 settings_map[static_cast<SpdySettingsIds>(id)] = flags_and_value;
449 }
450 spdy_settings_map->Put(server, settings_map);
451 }
452
453 AlternateProtocolInfo HttpServerPropertiesManager::ParseAlternateProtocolDict(
454 const base::DictionaryValue& alternate_protocol_dict,
455 const std::string& server_str) {
456 AlternateProtocolInfo alternate_protocol;
457 int port = 0;
458 if (!alternate_protocol_dict.GetInteger(kPortKey, &port) ||
459 !IsPortValid(port)) {
460 DVLOG(1) << "Malformed AltSvc port for server: " << server_str;
461 return alternate_protocol;
462 }
463 alternate_protocol.port = static_cast<uint16>(port);
464
465 double probability = 1.0;
466 if (alternate_protocol_dict.HasKey(kProbabilityKey) &&
467 !alternate_protocol_dict.GetDoubleWithoutPathExpansion(kProbabilityKey,
468 &probability)) {
469 DVLOG(1) << "Malformed AltSvc probability for server: " << server_str;
470 return alternate_protocol;
471 }
472 alternate_protocol.probability = probability;
473
474 std::string protocol_str;
475 if (!alternate_protocol_dict.GetStringWithoutPathExpansion(kProtocolKey,
476 &protocol_str)) {
477 DVLOG(1) << "Malformed AltSvc protocol string for server: " << server_str;
478 return alternate_protocol;
479 }
480 AlternateProtocol protocol = AlternateProtocolFromString(protocol_str);
481 if (!IsAlternateProtocolValid(protocol)) {
482 DVLOG(1) << "Invalid AltSvc protocol string for server: " << server_str;
483 return alternate_protocol;
484 }
485 alternate_protocol.protocol = protocol;
486
487 return alternate_protocol;
488 }
489
490 bool HttpServerPropertiesManager::AddToAlternateProtocolMap(
491 const HostPortPair& server,
492 const base::DictionaryValue& server_pref_dict,
493 AlternateProtocolMap* alternate_protocol_map) {
494 // Get alternate_protocol server.
495 DCHECK(alternate_protocol_map->Peek(server) == alternate_protocol_map->end());
496 const base::DictionaryValue* alternate_protocol_dict = NULL;
497 if (!server_pref_dict.GetDictionaryWithoutPathExpansion(
498 kAlternateProtocolKey, &alternate_protocol_dict)) {
499 return true;
500 }
501 AlternateProtocolInfo alternate_protocol =
502 ParseAlternateProtocolDict(*alternate_protocol_dict, server.ToString());
503 if (alternate_protocol.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL)
504 return false;
505 alternate_protocol_map->Put(server, alternate_protocol);
506 return true;
507 }
508
509 bool HttpServerPropertiesManager::ReadSupportsQuic(
510 const base::DictionaryValue& http_server_properties_dict,
511 IPAddressNumber* last_quic_address) {
512 const base::DictionaryValue* supports_quic_dict = NULL;
513 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion(
514 kSupportsQuicKey, &supports_quic_dict)) {
515 return true;
516 }
517 bool used_quic = false;
518 if (!supports_quic_dict->GetBooleanWithoutPathExpansion(kUsedQuicKey,
519 &used_quic)) {
520 DVLOG(1) << "Malformed SupportsQuic";
521 return false;
522 }
523 if (!used_quic)
524 return false;
525
526 std::string address;
527 if (!supports_quic_dict->GetStringWithoutPathExpansion(kAddressKey,
528 &address) ||
529 !ParseIPLiteralToNumber(address, last_quic_address)) {
530 DVLOG(1) << "Malformed SupportsQuic";
531 return false;
532 }
533 return true;
534 }
535
536 bool HttpServerPropertiesManager::AddToNetworkStatsMap(
537 const HostPortPair& server,
538 const base::DictionaryValue& server_pref_dict,
539 ServerNetworkStatsMap* network_stats_map) {
540 DCHECK(network_stats_map->Peek(server) == network_stats_map->end());
541 const base::DictionaryValue* server_network_stats_dict = NULL;
542 if (!server_pref_dict.GetDictionaryWithoutPathExpansion(
543 kNetworkStatsKey, &server_network_stats_dict)) {
544 return true;
545 }
546 int srtt;
547 if (!server_network_stats_dict->GetIntegerWithoutPathExpansion(kSrttKey,
548 &srtt)) {
549 DVLOG(1) << "Malformed ServerNetworkStats for server: "
550 << server.ToString();
551 return false;
552 }
553 ServerNetworkStats server_network_stats;
554 server_network_stats.srtt = base::TimeDelta::FromInternalValue(srtt);
555 // TODO(rtenneti): When QUIC starts using bandwidth_estimate, then persist
556 // bandwidth_estimate.
557 network_stats_map->Put(server, server_network_stats);
558 return true;
559 }
560
523 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread( 561 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread(
524 StringVector* spdy_servers, 562 StringVector* spdy_servers,
525 SpdySettingsMap* spdy_settings_map, 563 SpdySettingsMap* spdy_settings_map,
526 AlternateProtocolMap* alternate_protocol_map, 564 AlternateProtocolMap* alternate_protocol_map,
527 SupportsQuicMap* supports_quic_map, 565 IPAddressNumber* last_quic_address,
528 ServerNetworkStatsMap* server_network_stats_map, 566 ServerNetworkStatsMap* server_network_stats_map,
529 bool detected_corrupted_prefs) { 567 bool detected_corrupted_prefs) {
530 // Preferences have the master data because admins might have pushed new 568 // Preferences have the master data because admins might have pushed new
531 // preferences. Update the cached data with new data from preferences. 569 // preferences. Update the cached data with new data from preferences.
532 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 570 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
533 571
534 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size()); 572 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size());
535 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); 573 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true);
536 574
537 // Update the cached data and use the new spdy_settings from preferences. 575 // Update the cached data and use the new spdy_settings from preferences.
538 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size()); 576 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size());
539 http_server_properties_impl_->InitializeSpdySettingsServers( 577 http_server_properties_impl_->InitializeSpdySettingsServers(
540 spdy_settings_map); 578 spdy_settings_map);
541 579
542 // Update the cached data and use the new Alternate-Protocol server list from 580 // Update the cached data and use the new Alternate-Protocol server list from
543 // preferences. 581 // preferences.
544 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers", 582 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers",
545 alternate_protocol_map->size()); 583 alternate_protocol_map->size());
546 http_server_properties_impl_->InitializeAlternateProtocolServers( 584 http_server_properties_impl_->InitializeAlternateProtocolServers(
547 alternate_protocol_map); 585 alternate_protocol_map);
548 586
549 http_server_properties_impl_->InitializeSupportsQuic(supports_quic_map); 587 http_server_properties_impl_->InitializeSupportsQuic(last_quic_address);
550 588
551 http_server_properties_impl_->InitializeServerNetworkStats( 589 http_server_properties_impl_->InitializeServerNetworkStats(
552 server_network_stats_map); 590 server_network_stats_map);
553 591
554 // Update the prefs with what we have read (delete all corrupted prefs). 592 // Update the prefs with what we have read (delete all corrupted prefs).
555 if (detected_corrupted_prefs) 593 if (detected_corrupted_prefs)
556 ScheduleUpdatePrefsOnNetworkThread(); 594 ScheduleUpdatePrefsOnNetworkThread();
557 } 595 }
558 596
559 // 597 //
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 http_server_properties_impl_->GetCanonicalSuffix(server.host()); 654 http_server_properties_impl_->GetCanonicalSuffix(server.host());
617 if (!canonical_suffix.empty()) { 655 if (!canonical_suffix.empty()) {
618 if (persisted_map.find(canonical_suffix) != persisted_map.end()) 656 if (persisted_map.find(canonical_suffix) != persisted_map.end())
619 continue; 657 continue;
620 persisted_map[canonical_suffix] = true; 658 persisted_map[canonical_suffix] = true;
621 } 659 }
622 alternate_protocol_map->Put(server, it->second); 660 alternate_protocol_map->Put(server, it->second);
623 ++count; 661 ++count;
624 } 662 }
625 663
626 SupportsQuicMap* supports_quic_map = new SupportsQuicMap();
627 const SupportsQuicMap& main_supports_quic_map =
628 http_server_properties_impl_->supports_quic_map();
629 for (SupportsQuicMap::const_iterator it = main_supports_quic_map.begin();
630 it != main_supports_quic_map.end(); ++it) {
631 supports_quic_map->insert(std::make_pair(it->first, it->second));
632 }
633
634 ServerNetworkStatsMap* server_network_stats_map = 664 ServerNetworkStatsMap* server_network_stats_map =
635 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist); 665 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist);
636 const ServerNetworkStatsMap& main_server_network_stats_map = 666 const ServerNetworkStatsMap& main_server_network_stats_map =
637 http_server_properties_impl_->server_network_stats_map(); 667 http_server_properties_impl_->server_network_stats_map();
638 for (ServerNetworkStatsMap::const_iterator it = 668 for (ServerNetworkStatsMap::const_iterator it =
639 main_server_network_stats_map.begin(); 669 main_server_network_stats_map.begin();
640 it != main_server_network_stats_map.end(); ++it) { 670 it != main_server_network_stats_map.end(); ++it) {
641 server_network_stats_map->Put(it->first, it->second); 671 server_network_stats_map->Put(it->first, it->second);
642 } 672 }
643 673
674 IPAddressNumber* last_quic_addr = new IPAddressNumber;
675 http_server_properties_impl_->GetSupportsQuic(last_quic_addr);
644 // Update the preferences on the pref thread. 676 // Update the preferences on the pref thread.
645 pref_task_runner_->PostTask( 677 pref_task_runner_->PostTask(
646 FROM_HERE, 678 FROM_HERE,
647 base::Bind( 679 base::Bind(
648 &HttpServerPropertiesManager::UpdatePrefsOnPrefThread, pref_weak_ptr_, 680 &HttpServerPropertiesManager::UpdatePrefsOnPrefThread, pref_weak_ptr_,
649 base::Owned(spdy_server_list), base::Owned(spdy_settings_map), 681 base::Owned(spdy_server_list), base::Owned(spdy_settings_map),
650 base::Owned(alternate_protocol_map), base::Owned(supports_quic_map), 682 base::Owned(alternate_protocol_map), base::Owned(last_quic_addr),
651 base::Owned(server_network_stats_map), completion)); 683 base::Owned(server_network_stats_map), completion));
652 } 684 }
653 685
654 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, 686 // A local or temporary data structure to hold |supports_spdy|, SpdySettings,
655 // AlternateProtocolInfo and SupportsQuic preferences for a server. This is used 687 // AlternateProtocolInfo and SupportsQuic preferences for a server. This is used
656 // only in UpdatePrefsOnPrefThread. 688 // only in UpdatePrefsOnPrefThread.
657 struct ServerPref { 689 struct ServerPref {
658 ServerPref() 690 ServerPref()
659 : supports_spdy(false), 691 : supports_spdy(false),
660 settings_map(NULL), 692 settings_map(NULL),
(...skipping 14 matching lines...) Expand all
675 const SettingsMap* settings_map; 707 const SettingsMap* settings_map;
676 const AlternateProtocolInfo* alternate_protocol; 708 const AlternateProtocolInfo* alternate_protocol;
677 const SupportsQuic* supports_quic; 709 const SupportsQuic* supports_quic;
678 const ServerNetworkStats* server_network_stats; 710 const ServerNetworkStats* server_network_stats;
679 }; 711 };
680 712
681 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( 713 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread(
682 base::ListValue* spdy_server_list, 714 base::ListValue* spdy_server_list,
683 SpdySettingsMap* spdy_settings_map, 715 SpdySettingsMap* spdy_settings_map,
684 AlternateProtocolMap* alternate_protocol_map, 716 AlternateProtocolMap* alternate_protocol_map,
685 SupportsQuicMap* supports_quic_map, 717 IPAddressNumber* last_quic_address,
686 ServerNetworkStatsMap* server_network_stats_map, 718 ServerNetworkStatsMap* server_network_stats_map,
687 const base::Closure& completion) { 719 const base::Closure& completion) {
688 typedef std::map<HostPortPair, ServerPref> ServerPrefMap; 720 typedef std::map<HostPortPair, ServerPref> ServerPrefMap;
689 ServerPrefMap server_pref_map; 721 ServerPrefMap server_pref_map;
690 722
691 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); 723 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread());
692 724
693 // Add servers that support spdy to server_pref_map. 725 // Add servers that support spdy to server_pref_map.
694 std::string s; 726 std::string s;
695 for (base::ListValue::const_iterator list_it = spdy_server_list->begin(); 727 for (base::ListValue::const_iterator list_it = spdy_server_list->begin();
696 list_it != spdy_server_list->end(); 728 list_it != spdy_server_list->end();
697 ++list_it) { 729 ++list_it) {
698 if ((*list_it)->GetAsString(&s)) { 730 if ((*list_it)->GetAsString(&s)) {
699 HostPortPair server = HostPortPair::FromString(s); 731 HostPortPair server = HostPortPair::FromString(s);
700 732 server_pref_map[server].supports_spdy = true;
701 ServerPrefMap::iterator it = server_pref_map.find(server);
702 if (it == server_pref_map.end()) {
703 ServerPref server_pref(true, NULL, NULL, NULL, NULL);
704 server_pref_map[server] = server_pref;
705 } else {
706 it->second.supports_spdy = true;
707 }
708 } 733 }
709 } 734 }
710 735
711 // Add servers that have SpdySettings to server_pref_map. 736 // Add servers that have SpdySettings to server_pref_map.
712 for (SpdySettingsMap::iterator map_it = spdy_settings_map->begin(); 737 for (SpdySettingsMap::iterator map_it = spdy_settings_map->begin();
713 map_it != spdy_settings_map->end(); ++map_it) { 738 map_it != spdy_settings_map->end(); ++map_it) {
714 const HostPortPair& server = map_it->first; 739 const HostPortPair& server = map_it->first;
715 740 server_pref_map[server].settings_map = &map_it->second;
716 ServerPrefMap::iterator it = server_pref_map.find(server);
717 if (it == server_pref_map.end()) {
718 ServerPref server_pref(false, &map_it->second, NULL, NULL, NULL);
719 server_pref_map[server] = server_pref;
720 } else {
721 it->second.settings_map = &map_it->second;
722 }
723 } 741 }
724 742
725 // Add AlternateProtocol servers to server_pref_map. 743 // Add AlternateProtocol servers to server_pref_map.
726 for (AlternateProtocolMap::const_iterator map_it = 744 for (AlternateProtocolMap::const_iterator map_it =
727 alternate_protocol_map->begin(); 745 alternate_protocol_map->begin();
728 map_it != alternate_protocol_map->end(); ++map_it) { 746 map_it != alternate_protocol_map->end(); ++map_it) {
729 const HostPortPair& server = map_it->first; 747 const HostPortPair& server = map_it->first;
730 const AlternateProtocolInfo& port_alternate_protocol = map_it->second; 748 const AlternateProtocolInfo& port_alternate_protocol = map_it->second;
731 if (!IsAlternateProtocolValid(port_alternate_protocol.protocol)) { 749 if (!IsAlternateProtocolValid(port_alternate_protocol.protocol)) {
732 continue; 750 continue;
733 } 751 }
734 752 server_pref_map[server].alternate_protocol = &map_it->second;
735 ServerPrefMap::iterator it = server_pref_map.find(server);
736 if (it == server_pref_map.end()) {
737 ServerPref server_pref(false, NULL, &map_it->second, NULL, NULL);
738 server_pref_map[server] = server_pref;
739 } else {
740 it->second.alternate_protocol = &map_it->second;
741 }
742 }
743
744 // Add SupportsQuic servers to server_pref_map.
745 for (SupportsQuicMap::const_iterator map_it = supports_quic_map->begin();
746 map_it != supports_quic_map->end(); ++map_it) {
747 const HostPortPair& server = map_it->first;
748
749 ServerPrefMap::iterator it = server_pref_map.find(server);
750 if (it == server_pref_map.end()) {
751 ServerPref server_pref(false, NULL, NULL, &map_it->second, NULL);
752 server_pref_map[server] = server_pref;
753 } else {
754 it->second.supports_quic = &map_it->second;
755 }
756 } 753 }
757 754
758 // Add ServerNetworkStats servers to server_pref_map. 755 // Add ServerNetworkStats servers to server_pref_map.
759 for (ServerNetworkStatsMap::const_iterator map_it = 756 for (ServerNetworkStatsMap::const_iterator map_it =
760 server_network_stats_map->begin(); 757 server_network_stats_map->begin();
761 map_it != server_network_stats_map->end(); ++map_it) { 758 map_it != server_network_stats_map->end(); ++map_it) {
762 const HostPortPair& server = map_it->first; 759 const HostPortPair& server = map_it->first;
763 760 server_pref_map[server].server_network_stats = &map_it->second;
764 ServerPrefMap::iterator it = server_pref_map.find(server);
765 if (it == server_pref_map.end()) {
766 ServerPref server_pref(false, NULL, NULL, NULL, &map_it->second);
767 server_pref_map[server] = server_pref;
768 } else {
769 it->second.server_network_stats = &map_it->second;
770 }
771 } 761 }
772 762
773 // Persist properties to the |path_|. 763 // Persist properties to the |path_|.
774 base::DictionaryValue http_server_properties_dict; 764 base::DictionaryValue http_server_properties_dict;
775 base::DictionaryValue* servers_dict = new base::DictionaryValue; 765 base::DictionaryValue* servers_dict = new base::DictionaryValue;
776 for (ServerPrefMap::const_iterator map_it = server_pref_map.begin(); 766 for (ServerPrefMap::const_iterator map_it = server_pref_map.begin();
777 map_it != server_pref_map.end(); 767 map_it != server_pref_map.end();
778 ++map_it) { 768 ++map_it) {
779 const HostPortPair& server = map_it->first; 769 const HostPortPair& server = map_it->first;
780 const ServerPref& server_pref = map_it->second; 770 const ServerPref& server_pref = map_it->second;
781 771
782 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 772 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
783 773
784 // Save supports_spdy. 774 // Save supports_spdy.
785 if (server_pref.supports_spdy) 775 if (server_pref.supports_spdy)
786 server_pref_dict->SetBoolean("supports_spdy", server_pref.supports_spdy); 776 server_pref_dict->SetBoolean(kSupportsSpdyKey, server_pref.supports_spdy);
787 777 SaveSpdySettingsToServerPrefs(server_pref.settings_map, server_pref_dict);
788 // Save SPDY settings. 778 SaveAlternateProtocolToServerPrefs(server_pref.alternate_protocol,
789 if (server_pref.settings_map) { 779 server_pref_dict);
790 base::DictionaryValue* spdy_settings_dict = new base::DictionaryValue; 780 SaveNetworkStatsToServerPrefs(server_pref.server_network_stats,
791 for (SettingsMap::const_iterator it = server_pref.settings_map->begin(); 781 server_pref_dict);
792 it != server_pref.settings_map->end(); ++it) {
793 SpdySettingsIds id = it->first;
794 uint32 value = it->second.second;
795 std::string key = base::StringPrintf("%u", id);
796 spdy_settings_dict->SetInteger(key, value);
797 }
798 server_pref_dict->SetWithoutPathExpansion("settings", spdy_settings_dict);
799 }
800
801 // Save alternate_protocol.
802 const AlternateProtocolInfo* port_alternate_protocol =
803 server_pref.alternate_protocol;
804 if (port_alternate_protocol && !port_alternate_protocol->is_broken) {
805 base::DictionaryValue* port_alternate_protocol_dict =
806 new base::DictionaryValue;
807 port_alternate_protocol_dict->SetInteger("port",
808 port_alternate_protocol->port);
809 const char* protocol_str =
810 AlternateProtocolToString(port_alternate_protocol->protocol);
811 port_alternate_protocol_dict->SetString("protocol_str", protocol_str);
812 port_alternate_protocol_dict->SetDouble(
813 "probability", port_alternate_protocol->probability);
814 server_pref_dict->SetWithoutPathExpansion(
815 "alternate_protocol", port_alternate_protocol_dict);
816 }
817
818 // Save supports_quic.
819 if (server_pref.supports_quic) {
820 base::DictionaryValue* supports_quic_dict = new base::DictionaryValue;
821 const SupportsQuic* supports_quic = server_pref.supports_quic;
822 supports_quic_dict->SetBoolean("used_quic", supports_quic->used_quic);
823 supports_quic_dict->SetString("address", supports_quic->address);
824 server_pref_dict->SetWithoutPathExpansion(
825 "supports_quic", supports_quic_dict);
826 }
827
828 // Save ServerNetworkStats.
829 if (server_pref.server_network_stats) {
830 base::DictionaryValue* server_network_stats_dict =
831 new base::DictionaryValue;
832 const ServerNetworkStats* server_network_stats =
833 server_pref.server_network_stats;
834 // Becasue JSON doesn't support int64, persist int64 as a string.
835 server_network_stats_dict->SetInteger(
836 "srtt",
837 static_cast<int>(server_network_stats->srtt.ToInternalValue()));
838 // TODO(rtenneti): When QUIC starts using bandwidth_estimate, then persist
839 // bandwidth_estimate.
840 server_pref_dict->SetWithoutPathExpansion("network_stats",
841 server_network_stats_dict);
842 }
843 782
844 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict); 783 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict);
845 } 784 }
846 785
847 http_server_properties_dict.SetWithoutPathExpansion("servers", servers_dict); 786 http_server_properties_dict.SetWithoutPathExpansion(kServersKey,
787 servers_dict);
848 SetVersion(&http_server_properties_dict, kVersionNumber); 788 SetVersion(&http_server_properties_dict, kVersionNumber);
789
790 SaveSupportsQuicToPrefs(last_quic_address, &http_server_properties_dict);
791
849 setting_prefs_ = true; 792 setting_prefs_ = true;
850 pref_service_->Set(path_, http_server_properties_dict); 793 pref_service_->Set(path_, http_server_properties_dict);
851 setting_prefs_ = false; 794 setting_prefs_ = false;
852 795
853 // Note that |completion| will be fired after we have written everything to 796 // Note that |completion| will be fired after we have written everything to
854 // the Preferences, but likely before these changes are serialized to disk. 797 // the Preferences, but likely before these changes are serialized to disk.
855 // This is not a problem though, as JSONPrefStore guarantees that this will 798 // This is not a problem though, as JSONPrefStore guarantees that this will
856 // happen, pretty soon, and even in the case we shut down immediately. 799 // happen, pretty soon, and even in the case we shut down immediately.
857 if (!completion.is_null()) 800 if (!completion.is_null())
858 completion.Run(); 801 completion.Run();
859 } 802 }
860 803
804 void HttpServerPropertiesManager::SaveSpdySettingsToServerPrefs(
805 const SettingsMap* settings_map,
806 base::DictionaryValue* server_pref_dict) {
807 if (!settings_map) {
808 return;
809 }
810 base::DictionaryValue* spdy_settings_dict = new base::DictionaryValue;
811 for (SettingsMap::const_iterator it = settings_map->begin();
812 it != settings_map->end(); ++it) {
813 SpdySettingsIds id = it->first;
814 uint32 value = it->second.second;
815 std::string key = base::StringPrintf("%u", id);
816 spdy_settings_dict->SetInteger(key, value);
817 }
818 server_pref_dict->SetWithoutPathExpansion(kSettingsKey, spdy_settings_dict);
819 }
820
821 void HttpServerPropertiesManager::SaveAlternateProtocolToServerPrefs(
822 const AlternateProtocolInfo* port_alternate_protocol,
823 base::DictionaryValue* server_pref_dict) {
824 if (!port_alternate_protocol || port_alternate_protocol->is_broken)
825 return;
826
827 base::DictionaryValue* port_alternate_protocol_dict =
828 new base::DictionaryValue;
829 port_alternate_protocol_dict->SetInteger(kPortKey,
830 port_alternate_protocol->port);
831 const char* protocol_str =
832 AlternateProtocolToString(port_alternate_protocol->protocol);
833 port_alternate_protocol_dict->SetString(kProtocolKey, protocol_str);
834 port_alternate_protocol_dict->SetDouble(kProbabilityKey,
835 port_alternate_protocol->probability);
836 server_pref_dict->SetWithoutPathExpansion(kAlternateProtocolKey,
837 port_alternate_protocol_dict);
838 }
839
840 void HttpServerPropertiesManager::SaveSupportsQuicToPrefs(
841 const IPAddressNumber* last_quic_address,
842 base::DictionaryValue* http_server_properties_dict) {
843 if (!last_quic_address || last_quic_address->empty())
844 return;
845
846 base::DictionaryValue* supports_quic_dict = new base::DictionaryValue;
847 supports_quic_dict->SetBoolean(kUsedQuicKey, true);
848 supports_quic_dict->SetString(kAddressKey,
849 IPAddressToString(*last_quic_address));
850 http_server_properties_dict->SetWithoutPathExpansion(kSupportsQuicKey,
851 supports_quic_dict);
852 }
853
854 void HttpServerPropertiesManager::SaveNetworkStatsToServerPrefs(
855 const ServerNetworkStats* server_network_stats,
856 base::DictionaryValue* server_pref_dict) {
857 if (!server_network_stats)
858 return;
859
860 base::DictionaryValue* server_network_stats_dict = new base::DictionaryValue;
861 // Becasue JSON doesn't support int64, persist int64 as a string.
862 server_network_stats_dict->SetInteger(
863 kSrttKey, static_cast<int>(server_network_stats->srtt.ToInternalValue()));
864 // TODO(rtenneti): When QUIC starts using bandwidth_estimate, then persist
865 // bandwidth_estimate.
866 server_pref_dict->SetWithoutPathExpansion(kNetworkStatsKey,
867 server_network_stats_dict);
868 }
869
861 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { 870 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() {
862 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); 871 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread());
863 if (!setting_prefs_) 872 if (!setting_prefs_)
864 ScheduleUpdateCacheOnPrefThread(); 873 ScheduleUpdateCacheOnPrefThread();
865 } 874 }
866 875
867 } // namespace net 876 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties_manager.h ('k') | net/http/http_server_properties_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698