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

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

Issue 892203004: Make HttpServerProperties::GetSupportsQuic not host-specific. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase 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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
269 http_server_properties_impl_->ClearAllSpdySettings(); 269 http_server_properties_impl_->ClearAllSpdySettings();
270 ScheduleUpdatePrefsOnNetworkThread(); 270 ScheduleUpdatePrefsOnNetworkThread();
271 } 271 }
272 272
273 const SpdySettingsMap& HttpServerPropertiesManager::spdy_settings_map() 273 const SpdySettingsMap& HttpServerPropertiesManager::spdy_settings_map()
274 const { 274 const {
275 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 275 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
276 return http_server_properties_impl_->spdy_settings_map(); 276 return http_server_properties_impl_->spdy_settings_map();
277 } 277 }
278 278
279 SupportsQuic HttpServerPropertiesManager::GetSupportsQuic( 279 bool HttpServerPropertiesManager::GetSupportsQuic(
280 const HostPortPair& host_port_pair) const { 280 IPAddressNumber* last_address) const {
281 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 281 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
282 return http_server_properties_impl_->GetSupportsQuic(host_port_pair); 282 return http_server_properties_impl_->GetSupportsQuic(last_address);
283 } 283 }
284 284
285 void HttpServerPropertiesManager::SetSupportsQuic( 285 void HttpServerPropertiesManager::SetSupportsQuic(
286 const HostPortPair& host_port_pair,
287 bool used_quic, 286 bool used_quic,
288 const std::string& address) { 287 const IPAddressNumber& address) {
289 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 288 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
290 http_server_properties_impl_->SetSupportsQuic( 289 http_server_properties_impl_->SetSupportsQuic(used_quic, address);
291 host_port_pair, used_quic, address);
292 ScheduleUpdatePrefsOnNetworkThread(); 290 ScheduleUpdatePrefsOnNetworkThread();
293 } 291 }
294 292
295 const SupportsQuicMap& HttpServerPropertiesManager::supports_quic_map()
296 const {
297 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
298 return http_server_properties_impl_->supports_quic_map();
299 }
300
301 void HttpServerPropertiesManager::SetServerNetworkStats( 293 void HttpServerPropertiesManager::SetServerNetworkStats(
302 const HostPortPair& host_port_pair, 294 const HostPortPair& host_port_pair,
303 ServerNetworkStats stats) { 295 ServerNetworkStats stats) {
304 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 296 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
305 http_server_properties_impl_->SetServerNetworkStats(host_port_pair, stats); 297 http_server_properties_impl_->SetServerNetworkStats(host_port_pair, stats);
306 ScheduleUpdatePrefsOnNetworkThread(); 298 ScheduleUpdatePrefsOnNetworkThread();
307 } 299 }
308 300
309 const ServerNetworkStats* HttpServerPropertiesManager::GetServerNetworkStats( 301 const ServerNetworkStats* HttpServerPropertiesManager::GetServerNetworkStats(
310 const HostPortPair& host_port_pair) { 302 const HostPortPair& host_port_pair) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 351
360 // The properties for a given server is in 352 // The properties for a given server is in
361 // http_server_properties_dict["servers"][server]. 353 // http_server_properties_dict["servers"][server].
362 const base::DictionaryValue* servers_dict = NULL; 354 const base::DictionaryValue* servers_dict = NULL;
363 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion( 355 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion(
364 kServersKey, &servers_dict)) { 356 kServersKey, &servers_dict)) {
365 DVLOG(1) << "Malformed http_server_properties for servers."; 357 DVLOG(1) << "Malformed http_server_properties for servers.";
366 return; 358 return;
367 } 359 }
368 360
361 IPAddressNumber* addr = new IPAddressNumber;
362 ReadSupportsQuic(http_server_properties_dict, addr);
363
369 // String is host/port pair of spdy server. 364 // String is host/port pair of spdy server.
370 scoped_ptr<StringVector> spdy_servers(new StringVector); 365 scoped_ptr<StringVector> spdy_servers(new StringVector);
371 scoped_ptr<SpdySettingsMap> spdy_settings_map( 366 scoped_ptr<SpdySettingsMap> spdy_settings_map(
372 new SpdySettingsMap(kMaxSpdySettingsHostsToPersist)); 367 new SpdySettingsMap(kMaxSpdySettingsHostsToPersist));
373 scoped_ptr<AlternateProtocolMap> alternate_protocol_map( 368 scoped_ptr<AlternateProtocolMap> alternate_protocol_map(
374 new AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist)); 369 new AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist));
375 scoped_ptr<SupportsQuicMap> supports_quic_map(new SupportsQuicMap());
376 scoped_ptr<ServerNetworkStatsMap> server_network_stats_map( 370 scoped_ptr<ServerNetworkStatsMap> server_network_stats_map(
377 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist)); 371 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist));
378 372
379 for (base::DictionaryValue::Iterator it(*servers_dict); !it.IsAtEnd(); 373 for (base::DictionaryValue::Iterator it(*servers_dict); !it.IsAtEnd();
380 it.Advance()) { 374 it.Advance()) {
381 // Get server's host/pair. 375 // Get server's host/pair.
382 const std::string& server_str = it.key(); 376 const std::string& server_str = it.key();
383 HostPortPair server = HostPortPair::FromString(server_str); 377 HostPortPair server = HostPortPair::FromString(server_str);
384 if (server.host().empty()) { 378 if (server.host().empty()) {
385 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; 379 DVLOG(1) << "Malformed http_server_properties for server: " << server_str;
(...skipping 11 matching lines...) Expand all
397 // Get if server supports Spdy. 391 // Get if server supports Spdy.
398 bool supports_spdy = false; 392 bool supports_spdy = false;
399 if ((server_pref_dict->GetBoolean(kSupportsSpdyKey, &supports_spdy)) && 393 if ((server_pref_dict->GetBoolean(kSupportsSpdyKey, &supports_spdy)) &&
400 supports_spdy) { 394 supports_spdy) {
401 spdy_servers->push_back(server_str); 395 spdy_servers->push_back(server_str);
402 } 396 }
403 397
404 AddToSpdySettingsMap(server, *server_pref_dict, spdy_settings_map.get()); 398 AddToSpdySettingsMap(server, *server_pref_dict, spdy_settings_map.get());
405 if (!AddToAlternateProtocolMap(server, *server_pref_dict, 399 if (!AddToAlternateProtocolMap(server, *server_pref_dict,
406 alternate_protocol_map.get()) || 400 alternate_protocol_map.get()) ||
407 !AddToSupportsQuicMap(server, *server_pref_dict,
408 supports_quic_map.get()) ||
409 !AddToNetworkStatsMap(server, *server_pref_dict, 401 !AddToNetworkStatsMap(server, *server_pref_dict,
410 server_network_stats_map.get())) { 402 server_network_stats_map.get())) {
411 detected_corrupted_prefs = true; 403 detected_corrupted_prefs = true;
412 } 404 }
413 } 405 }
414 406
415 network_task_runner_->PostTask( 407 network_task_runner_->PostTask(
416 FROM_HERE, 408 FROM_HERE,
417 base::Bind( 409 base::Bind(
418 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread, 410 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread,
419 base::Unretained(this), base::Owned(spdy_servers.release()), 411 base::Unretained(this), base::Owned(spdy_servers.release()),
420 base::Owned(spdy_settings_map.release()), 412 base::Owned(spdy_settings_map.release()),
421 base::Owned(alternate_protocol_map.release()), 413 base::Owned(alternate_protocol_map.release()), base::Owned(addr),
422 base::Owned(supports_quic_map.release()),
423 base::Owned(server_network_stats_map.release()), 414 base::Owned(server_network_stats_map.release()),
424 detected_corrupted_prefs)); 415 detected_corrupted_prefs));
425 } 416 }
426 417
427 void HttpServerPropertiesManager::AddToSpdySettingsMap( 418 void HttpServerPropertiesManager::AddToSpdySettingsMap(
428 const HostPortPair& server, 419 const HostPortPair& server,
429 const base::DictionaryValue& server_pref_dict, 420 const base::DictionaryValue& server_pref_dict,
430 SpdySettingsMap* spdy_settings_map) { 421 SpdySettingsMap* spdy_settings_map) {
431 // Get SpdySettings. 422 // Get SpdySettings.
432 DCHECK(spdy_settings_map->Peek(server) == spdy_settings_map->end()); 423 DCHECK(spdy_settings_map->Peek(server) == spdy_settings_map->end());
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 DVLOG(1) << "Malformed Alternate-Protocol server: " << server.ToString(); 486 DVLOG(1) << "Malformed Alternate-Protocol server: " << server.ToString();
496 return false; 487 return false;
497 } 488 }
498 489
499 AlternateProtocolInfo port_alternate_protocol(static_cast<uint16>(port), 490 AlternateProtocolInfo port_alternate_protocol(static_cast<uint16>(port),
500 protocol, probability); 491 protocol, probability);
501 alternate_protocol_map->Put(server, port_alternate_protocol); 492 alternate_protocol_map->Put(server, port_alternate_protocol);
502 return true; 493 return true;
503 } 494 }
504 495
505 bool HttpServerPropertiesManager::AddToSupportsQuicMap( 496 bool HttpServerPropertiesManager::ReadSupportsQuic(
506 const HostPortPair& server, 497 const base::DictionaryValue& http_server_properties_dict,
507 const base::DictionaryValue& server_pref_dict, 498 IPAddressNumber* last_quic_address) {
508 SupportsQuicMap* supports_quic_map) {
509 DCHECK(supports_quic_map->find(server) == supports_quic_map->end());
510 const base::DictionaryValue* supports_quic_dict = NULL; 499 const base::DictionaryValue* supports_quic_dict = NULL;
511 if (!server_pref_dict.GetDictionaryWithoutPathExpansion( 500 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion(
512 kSupportsQuicKey, &supports_quic_dict)) { 501 kSupportsQuicKey, &supports_quic_dict)) {
513 return true; 502 return true;
514 } 503 }
515 bool used_quic = 0; 504 bool used_quic = false;
516 if (!supports_quic_dict->GetBooleanWithoutPathExpansion(kUsedQuicKey, 505 if (!supports_quic_dict->GetBooleanWithoutPathExpansion(kUsedQuicKey,
517 &used_quic)) { 506 &used_quic)) {
518 DVLOG(1) << "Malformed SupportsQuic server: " << server.ToString(); 507 DVLOG(1) << "Malformed SupportsQuic";
519 return false; 508 return false;
520 } 509 }
510 if (!used_quic)
511 return false;
512
521 std::string address; 513 std::string address;
522 if (!supports_quic_dict->GetStringWithoutPathExpansion(kAddressKey, 514 if (!supports_quic_dict->GetStringWithoutPathExpansion(kAddressKey,
523 &address)) { 515 &address) ||
524 DVLOG(1) << "Malformed SupportsQuic server: " << server.ToString(); 516 !ParseIPLiteralToNumber(address, last_quic_address)) {
517 DVLOG(1) << "Malformed SupportsQuic";
525 return false; 518 return false;
526 } 519 }
527 SupportsQuic supports_quic(used_quic, address);
528 supports_quic_map->insert(std::make_pair(server, supports_quic));
529 return true; 520 return true;
530 } 521 }
531 522
532 bool HttpServerPropertiesManager::AddToNetworkStatsMap( 523 bool HttpServerPropertiesManager::AddToNetworkStatsMap(
533 const HostPortPair& server, 524 const HostPortPair& server,
534 const base::DictionaryValue& server_pref_dict, 525 const base::DictionaryValue& server_pref_dict,
535 ServerNetworkStatsMap* network_stats_map) { 526 ServerNetworkStatsMap* network_stats_map) {
536 DCHECK(network_stats_map->Peek(server) == network_stats_map->end()); 527 DCHECK(network_stats_map->Peek(server) == network_stats_map->end());
537 const base::DictionaryValue* server_network_stats_dict = NULL; 528 const base::DictionaryValue* server_network_stats_dict = NULL;
538 if (!server_pref_dict.GetDictionaryWithoutPathExpansion( 529 if (!server_pref_dict.GetDictionaryWithoutPathExpansion(
(...skipping 12 matching lines...) Expand all
551 // TODO(rtenneti): When QUIC starts using bandwidth_estimate, then persist 542 // TODO(rtenneti): When QUIC starts using bandwidth_estimate, then persist
552 // bandwidth_estimate. 543 // bandwidth_estimate.
553 network_stats_map->Put(server, server_network_stats); 544 network_stats_map->Put(server, server_network_stats);
554 return true; 545 return true;
555 } 546 }
556 547
557 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread( 548 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread(
558 StringVector* spdy_servers, 549 StringVector* spdy_servers,
559 SpdySettingsMap* spdy_settings_map, 550 SpdySettingsMap* spdy_settings_map,
560 AlternateProtocolMap* alternate_protocol_map, 551 AlternateProtocolMap* alternate_protocol_map,
561 SupportsQuicMap* supports_quic_map, 552 IPAddressNumber* last_quic_address,
562 ServerNetworkStatsMap* server_network_stats_map, 553 ServerNetworkStatsMap* server_network_stats_map,
563 bool detected_corrupted_prefs) { 554 bool detected_corrupted_prefs) {
564 // Preferences have the master data because admins might have pushed new 555 // Preferences have the master data because admins might have pushed new
565 // preferences. Update the cached data with new data from preferences. 556 // preferences. Update the cached data with new data from preferences.
566 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 557 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
567 558
568 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size()); 559 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size());
569 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); 560 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true);
570 561
571 // Update the cached data and use the new spdy_settings from preferences. 562 // Update the cached data and use the new spdy_settings from preferences.
572 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size()); 563 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size());
573 http_server_properties_impl_->InitializeSpdySettingsServers( 564 http_server_properties_impl_->InitializeSpdySettingsServers(
574 spdy_settings_map); 565 spdy_settings_map);
575 566
576 // Update the cached data and use the new Alternate-Protocol server list from 567 // Update the cached data and use the new Alternate-Protocol server list from
577 // preferences. 568 // preferences.
578 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers", 569 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers",
579 alternate_protocol_map->size()); 570 alternate_protocol_map->size());
580 http_server_properties_impl_->InitializeAlternateProtocolServers( 571 http_server_properties_impl_->InitializeAlternateProtocolServers(
581 alternate_protocol_map); 572 alternate_protocol_map);
582 573
583 http_server_properties_impl_->InitializeSupportsQuic(supports_quic_map); 574 http_server_properties_impl_->InitializeSupportsQuic(last_quic_address);
584 575
585 http_server_properties_impl_->InitializeServerNetworkStats( 576 http_server_properties_impl_->InitializeServerNetworkStats(
586 server_network_stats_map); 577 server_network_stats_map);
587 578
588 // Update the prefs with what we have read (delete all corrupted prefs). 579 // Update the prefs with what we have read (delete all corrupted prefs).
589 if (detected_corrupted_prefs) 580 if (detected_corrupted_prefs)
590 ScheduleUpdatePrefsOnNetworkThread(); 581 ScheduleUpdatePrefsOnNetworkThread();
591 } 582 }
592 583
593 // 584 //
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
650 http_server_properties_impl_->GetCanonicalSuffix(server.host()); 641 http_server_properties_impl_->GetCanonicalSuffix(server.host());
651 if (!canonical_suffix.empty()) { 642 if (!canonical_suffix.empty()) {
652 if (persisted_map.find(canonical_suffix) != persisted_map.end()) 643 if (persisted_map.find(canonical_suffix) != persisted_map.end())
653 continue; 644 continue;
654 persisted_map[canonical_suffix] = true; 645 persisted_map[canonical_suffix] = true;
655 } 646 }
656 alternate_protocol_map->Put(server, it->second); 647 alternate_protocol_map->Put(server, it->second);
657 ++count; 648 ++count;
658 } 649 }
659 650
660 SupportsQuicMap* supports_quic_map = new SupportsQuicMap();
661 const SupportsQuicMap& main_supports_quic_map =
662 http_server_properties_impl_->supports_quic_map();
663 for (SupportsQuicMap::const_iterator it = main_supports_quic_map.begin();
664 it != main_supports_quic_map.end(); ++it) {
665 supports_quic_map->insert(std::make_pair(it->first, it->second));
666 }
667
668 ServerNetworkStatsMap* server_network_stats_map = 651 ServerNetworkStatsMap* server_network_stats_map =
669 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist); 652 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist);
670 const ServerNetworkStatsMap& main_server_network_stats_map = 653 const ServerNetworkStatsMap& main_server_network_stats_map =
671 http_server_properties_impl_->server_network_stats_map(); 654 http_server_properties_impl_->server_network_stats_map();
672 for (ServerNetworkStatsMap::const_iterator it = 655 for (ServerNetworkStatsMap::const_iterator it =
673 main_server_network_stats_map.begin(); 656 main_server_network_stats_map.begin();
674 it != main_server_network_stats_map.end(); ++it) { 657 it != main_server_network_stats_map.end(); ++it) {
675 server_network_stats_map->Put(it->first, it->second); 658 server_network_stats_map->Put(it->first, it->second);
676 } 659 }
677 660
661 IPAddressNumber* last_quic_addr = new IPAddressNumber;
662 http_server_properties_impl_->GetSupportsQuic(last_quic_addr);
678 // Update the preferences on the pref thread. 663 // Update the preferences on the pref thread.
679 pref_task_runner_->PostTask( 664 pref_task_runner_->PostTask(
680 FROM_HERE, 665 FROM_HERE,
681 base::Bind( 666 base::Bind(
682 &HttpServerPropertiesManager::UpdatePrefsOnPrefThread, pref_weak_ptr_, 667 &HttpServerPropertiesManager::UpdatePrefsOnPrefThread, pref_weak_ptr_,
683 base::Owned(spdy_server_list), base::Owned(spdy_settings_map), 668 base::Owned(spdy_server_list), base::Owned(spdy_settings_map),
684 base::Owned(alternate_protocol_map), base::Owned(supports_quic_map), 669 base::Owned(alternate_protocol_map), base::Owned(last_quic_addr),
685 base::Owned(server_network_stats_map), completion)); 670 base::Owned(server_network_stats_map), completion));
686 } 671 }
687 672
688 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, 673 // A local or temporary data structure to hold |supports_spdy|, SpdySettings,
689 // AlternateProtocolInfo and SupportsQuic preferences for a server. This is used 674 // AlternateProtocolInfo and SupportsQuic preferences for a server. This is used
690 // only in UpdatePrefsOnPrefThread. 675 // only in UpdatePrefsOnPrefThread.
691 struct ServerPref { 676 struct ServerPref {
692 ServerPref() 677 ServerPref()
693 : supports_spdy(false), 678 : supports_spdy(false),
694 settings_map(NULL), 679 settings_map(NULL),
(...skipping 14 matching lines...) Expand all
709 const SettingsMap* settings_map; 694 const SettingsMap* settings_map;
710 const AlternateProtocolInfo* alternate_protocol; 695 const AlternateProtocolInfo* alternate_protocol;
711 const SupportsQuic* supports_quic; 696 const SupportsQuic* supports_quic;
712 const ServerNetworkStats* server_network_stats; 697 const ServerNetworkStats* server_network_stats;
713 }; 698 };
714 699
715 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( 700 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread(
716 base::ListValue* spdy_server_list, 701 base::ListValue* spdy_server_list,
717 SpdySettingsMap* spdy_settings_map, 702 SpdySettingsMap* spdy_settings_map,
718 AlternateProtocolMap* alternate_protocol_map, 703 AlternateProtocolMap* alternate_protocol_map,
719 SupportsQuicMap* supports_quic_map, 704 IPAddressNumber* last_quic_address,
720 ServerNetworkStatsMap* server_network_stats_map, 705 ServerNetworkStatsMap* server_network_stats_map,
721 const base::Closure& completion) { 706 const base::Closure& completion) {
722 typedef std::map<HostPortPair, ServerPref> ServerPrefMap; 707 typedef std::map<HostPortPair, ServerPref> ServerPrefMap;
723 ServerPrefMap server_pref_map; 708 ServerPrefMap server_pref_map;
724 709
725 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); 710 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread());
726 711
727 // Add servers that support spdy to server_pref_map. 712 // Add servers that support spdy to server_pref_map.
728 std::string s; 713 std::string s;
729 for (base::ListValue::const_iterator list_it = spdy_server_list->begin(); 714 for (base::ListValue::const_iterator list_it = spdy_server_list->begin();
(...skipping 17 matching lines...) Expand all
747 alternate_protocol_map->begin(); 732 alternate_protocol_map->begin();
748 map_it != alternate_protocol_map->end(); ++map_it) { 733 map_it != alternate_protocol_map->end(); ++map_it) {
749 const HostPortPair& server = map_it->first; 734 const HostPortPair& server = map_it->first;
750 const AlternateProtocolInfo& port_alternate_protocol = map_it->second; 735 const AlternateProtocolInfo& port_alternate_protocol = map_it->second;
751 if (!IsAlternateProtocolValid(port_alternate_protocol.protocol)) { 736 if (!IsAlternateProtocolValid(port_alternate_protocol.protocol)) {
752 continue; 737 continue;
753 } 738 }
754 server_pref_map[server].alternate_protocol = &map_it->second; 739 server_pref_map[server].alternate_protocol = &map_it->second;
755 } 740 }
756 741
757 // Add SupportsQuic servers to server_pref_map.
758 for (SupportsQuicMap::const_iterator map_it = supports_quic_map->begin();
759 map_it != supports_quic_map->end(); ++map_it) {
760 const HostPortPair& server = map_it->first;
761 server_pref_map[server].supports_quic = &map_it->second;
762 }
763
764 // Add ServerNetworkStats servers to server_pref_map. 742 // Add ServerNetworkStats servers to server_pref_map.
765 for (ServerNetworkStatsMap::const_iterator map_it = 743 for (ServerNetworkStatsMap::const_iterator map_it =
766 server_network_stats_map->begin(); 744 server_network_stats_map->begin();
767 map_it != server_network_stats_map->end(); ++map_it) { 745 map_it != server_network_stats_map->end(); ++map_it) {
768 const HostPortPair& server = map_it->first; 746 const HostPortPair& server = map_it->first;
769 server_pref_map[server].server_network_stats = &map_it->second; 747 server_pref_map[server].server_network_stats = &map_it->second;
770 } 748 }
771 749
772 // Persist properties to the |path_|. 750 // Persist properties to the |path_|.
773 base::DictionaryValue http_server_properties_dict; 751 base::DictionaryValue http_server_properties_dict;
774 base::DictionaryValue* servers_dict = new base::DictionaryValue; 752 base::DictionaryValue* servers_dict = new base::DictionaryValue;
775 for (ServerPrefMap::const_iterator map_it = server_pref_map.begin(); 753 for (ServerPrefMap::const_iterator map_it = server_pref_map.begin();
776 map_it != server_pref_map.end(); 754 map_it != server_pref_map.end();
777 ++map_it) { 755 ++map_it) {
778 const HostPortPair& server = map_it->first; 756 const HostPortPair& server = map_it->first;
779 const ServerPref& server_pref = map_it->second; 757 const ServerPref& server_pref = map_it->second;
780 758
781 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 759 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
782 760
783 // Save supports_spdy. 761 // Save supports_spdy.
784 if (server_pref.supports_spdy) 762 if (server_pref.supports_spdy)
785 server_pref_dict->SetBoolean(kSupportsSpdyKey, server_pref.supports_spdy); 763 server_pref_dict->SetBoolean(kSupportsSpdyKey, server_pref.supports_spdy);
786 SaveSpdySettingsToServerPrefs(server_pref.settings_map, server_pref_dict); 764 SaveSpdySettingsToServerPrefs(server_pref.settings_map, server_pref_dict);
787 SaveAlternateProtocolToServerPrefs(server_pref.alternate_protocol, 765 SaveAlternateProtocolToServerPrefs(server_pref.alternate_protocol,
788 server_pref_dict); 766 server_pref_dict);
789 SaveSupportsQuicToServerPrefs(server_pref.supports_quic, server_pref_dict);
790 SaveNetworkStatsToServerPrefs(server_pref.server_network_stats, 767 SaveNetworkStatsToServerPrefs(server_pref.server_network_stats,
791 server_pref_dict); 768 server_pref_dict);
792 769
793 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict); 770 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict);
794 } 771 }
795 772
796 http_server_properties_dict.SetWithoutPathExpansion(kServersKey, 773 http_server_properties_dict.SetWithoutPathExpansion(kServersKey,
797 servers_dict); 774 servers_dict);
798 SetVersion(&http_server_properties_dict, kVersionNumber); 775 SetVersion(&http_server_properties_dict, kVersionNumber);
776
777 SaveSupportsQuicToPrefs(last_quic_address, &http_server_properties_dict);
778
799 setting_prefs_ = true; 779 setting_prefs_ = true;
800 pref_service_->Set(path_, http_server_properties_dict); 780 pref_service_->Set(path_, http_server_properties_dict);
801 setting_prefs_ = false; 781 setting_prefs_ = false;
802 782
803 // Note that |completion| will be fired after we have written everything to 783 // Note that |completion| will be fired after we have written everything to
804 // the Preferences, but likely before these changes are serialized to disk. 784 // the Preferences, but likely before these changes are serialized to disk.
805 // This is not a problem though, as JSONPrefStore guarantees that this will 785 // This is not a problem though, as JSONPrefStore guarantees that this will
806 // happen, pretty soon, and even in the case we shut down immediately. 786 // happen, pretty soon, and even in the case we shut down immediately.
807 if (!completion.is_null()) 787 if (!completion.is_null())
808 completion.Run(); 788 completion.Run();
(...skipping 28 matching lines...) Expand all
837 port_alternate_protocol->port); 817 port_alternate_protocol->port);
838 const char* protocol_str = 818 const char* protocol_str =
839 AlternateProtocolToString(port_alternate_protocol->protocol); 819 AlternateProtocolToString(port_alternate_protocol->protocol);
840 port_alternate_protocol_dict->SetString(kProtocolKey, protocol_str); 820 port_alternate_protocol_dict->SetString(kProtocolKey, protocol_str);
841 port_alternate_protocol_dict->SetDouble(kProbabilityKey, 821 port_alternate_protocol_dict->SetDouble(kProbabilityKey,
842 port_alternate_protocol->probability); 822 port_alternate_protocol->probability);
843 server_pref_dict->SetWithoutPathExpansion(kAlternateProtocolKey, 823 server_pref_dict->SetWithoutPathExpansion(kAlternateProtocolKey,
844 port_alternate_protocol_dict); 824 port_alternate_protocol_dict);
845 } 825 }
846 826
847 void HttpServerPropertiesManager::SaveSupportsQuicToServerPrefs( 827 void HttpServerPropertiesManager::SaveSupportsQuicToPrefs(
848 const SupportsQuic* supports_quic, 828 const IPAddressNumber* last_quic_address,
849 base::DictionaryValue* server_pref_dict) { 829 base::DictionaryValue* http_server_properties_dict) {
850 // Save supports_quic. 830 if (!last_quic_address || last_quic_address->empty())
851 if (!supports_quic)
852 return; 831 return;
853 832
854 base::DictionaryValue* supports_quic_dict = new base::DictionaryValue; 833 base::DictionaryValue* supports_quic_dict = new base::DictionaryValue;
855 supports_quic_dict->SetBoolean(kUsedQuicKey, supports_quic->used_quic); 834 supports_quic_dict->SetBoolean(kUsedQuicKey, true);
856 supports_quic_dict->SetString(kAddressKey, supports_quic->address); 835 supports_quic_dict->SetString(kAddressKey,
857 server_pref_dict->SetWithoutPathExpansion(kSupportsQuicKey, 836 IPAddressToString(*last_quic_address));
858 supports_quic_dict); 837 http_server_properties_dict->SetWithoutPathExpansion(kSupportsQuicKey,
838 supports_quic_dict);
859 } 839 }
860 840
861 void HttpServerPropertiesManager::SaveNetworkStatsToServerPrefs( 841 void HttpServerPropertiesManager::SaveNetworkStatsToServerPrefs(
862 const ServerNetworkStats* server_network_stats, 842 const ServerNetworkStats* server_network_stats,
863 base::DictionaryValue* server_pref_dict) { 843 base::DictionaryValue* server_pref_dict) {
864 if (!server_network_stats) 844 if (!server_network_stats)
865 return; 845 return;
866 846
867 base::DictionaryValue* server_network_stats_dict = new base::DictionaryValue; 847 base::DictionaryValue* server_network_stats_dict = new base::DictionaryValue;
868 // Becasue JSON doesn't support int64, persist int64 as a string. 848 // Becasue JSON doesn't support int64, persist int64 as a string.
869 server_network_stats_dict->SetInteger( 849 server_network_stats_dict->SetInteger(
870 kSrttKey, static_cast<int>(server_network_stats->srtt.ToInternalValue())); 850 kSrttKey, static_cast<int>(server_network_stats->srtt.ToInternalValue()));
871 // TODO(rtenneti): When QUIC starts using bandwidth_estimate, then persist 851 // TODO(rtenneti): When QUIC starts using bandwidth_estimate, then persist
872 // bandwidth_estimate. 852 // bandwidth_estimate.
873 server_pref_dict->SetWithoutPathExpansion(kNetworkStatsKey, 853 server_pref_dict->SetWithoutPathExpansion(kNetworkStatsKey,
874 server_network_stats_dict); 854 server_network_stats_dict);
875 } 855 }
876 856
877 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { 857 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() {
878 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); 858 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread());
879 if (!setting_prefs_) 859 if (!setting_prefs_)
880 ScheduleUpdateCacheOnPrefThread(); 860 ScheduleUpdateCacheOnPrefThread();
881 } 861 }
882 862
883 } // namespace net 863 } // 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