| 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/rand_util.h" | 10 #include "base/rand_util.h" |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 http_server_properties_impl_->ClearAllSpdySettings(); | 257 http_server_properties_impl_->ClearAllSpdySettings(); |
| 258 ScheduleUpdatePrefsOnNetworkThread(); | 258 ScheduleUpdatePrefsOnNetworkThread(); |
| 259 } | 259 } |
| 260 | 260 |
| 261 const SpdySettingsMap& HttpServerPropertiesManager::spdy_settings_map() | 261 const SpdySettingsMap& HttpServerPropertiesManager::spdy_settings_map() |
| 262 const { | 262 const { |
| 263 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 263 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 264 return http_server_properties_impl_->spdy_settings_map(); | 264 return http_server_properties_impl_->spdy_settings_map(); |
| 265 } | 265 } |
| 266 | 266 |
| 267 net::SupportsQuic |
| 268 HttpServerPropertiesManager::GetSupportsQuic( |
| 269 const net::HostPortPair& host_port_pair) const { |
| 270 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 271 return http_server_properties_impl_->GetSupportsQuic(host_port_pair); |
| 272 } |
| 273 |
| 274 void HttpServerPropertiesManager::SetSupportsQuic( |
| 275 const net::HostPortPair& host_port_pair, |
| 276 bool used_quic, |
| 277 const std::string& address) { |
| 278 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 279 http_server_properties_impl_->SetSupportsQuic( |
| 280 host_port_pair, used_quic, address); |
| 281 ScheduleUpdatePrefsOnNetworkThread(); |
| 282 } |
| 283 |
| 284 const SupportsQuicMap& HttpServerPropertiesManager::supports_quic_map() |
| 285 const { |
| 286 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 287 return http_server_properties_impl_->supports_quic_map(); |
| 288 } |
| 289 |
| 267 void HttpServerPropertiesManager::SetServerNetworkStats( | 290 void HttpServerPropertiesManager::SetServerNetworkStats( |
| 268 const net::HostPortPair& host_port_pair, | 291 const net::HostPortPair& host_port_pair, |
| 269 NetworkStats stats) { | 292 NetworkStats stats) { |
| 270 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 293 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 271 http_server_properties_impl_->SetServerNetworkStats(host_port_pair, stats); | 294 http_server_properties_impl_->SetServerNetworkStats(host_port_pair, stats); |
| 272 } | 295 } |
| 273 | 296 |
| 274 const HttpServerPropertiesManager::NetworkStats* | 297 const HttpServerPropertiesManager::NetworkStats* |
| 275 HttpServerPropertiesManager::GetServerNetworkStats( | 298 HttpServerPropertiesManager::GetServerNetworkStats( |
| 276 const net::HostPortPair& host_port_pair) const { | 299 const net::HostPortPair& host_port_pair) const { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 DVLOG(1) << "Malformed http_server_properties for servers."; | 348 DVLOG(1) << "Malformed http_server_properties for servers."; |
| 326 return; | 349 return; |
| 327 } | 350 } |
| 328 | 351 |
| 329 // String is host/port pair of spdy server. | 352 // String is host/port pair of spdy server. |
| 330 scoped_ptr<StringVector> spdy_servers(new StringVector); | 353 scoped_ptr<StringVector> spdy_servers(new StringVector); |
| 331 scoped_ptr<net::SpdySettingsMap> spdy_settings_map( | 354 scoped_ptr<net::SpdySettingsMap> spdy_settings_map( |
| 332 new net::SpdySettingsMap(kMaxSpdySettingsHostsToPersist)); | 355 new net::SpdySettingsMap(kMaxSpdySettingsHostsToPersist)); |
| 333 scoped_ptr<net::AlternateProtocolMap> alternate_protocol_map( | 356 scoped_ptr<net::AlternateProtocolMap> alternate_protocol_map( |
| 334 new net::AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist)); | 357 new net::AlternateProtocolMap(kMaxAlternateProtocolHostsToPersist)); |
| 358 scoped_ptr<net::SupportsQuicMap> supports_quic_map( |
| 359 new net::SupportsQuicMap()); |
| 335 // TODO(rtenneti): Delete the following code after the experiment. | 360 // TODO(rtenneti): Delete the following code after the experiment. |
| 336 int alternate_protocols_to_load = k200AlternateProtocolHostsToLoad; | 361 int alternate_protocols_to_load = k200AlternateProtocolHostsToLoad; |
| 337 net::AlternateProtocolExperiment alternate_protocol_experiment = | 362 net::AlternateProtocolExperiment alternate_protocol_experiment = |
| 338 net::ALTERNATE_PROTOCOL_NOT_PART_OF_EXPERIMENT; | 363 net::ALTERNATE_PROTOCOL_NOT_PART_OF_EXPERIMENT; |
| 339 if (version == kVersionNumber) { | 364 if (version == kVersionNumber) { |
| 340 if (base::RandInt(0, 99) == 0) { | 365 if (base::RandInt(0, 99) == 0) { |
| 341 alternate_protocol_experiment = | 366 alternate_protocol_experiment = |
| 342 net::ALTERNATE_PROTOCOL_TRUNCATED_200_SERVERS; | 367 net::ALTERNATE_PROTOCOL_TRUNCATED_200_SERVERS; |
| 343 } else { | 368 } else { |
| 344 alternate_protocols_to_load = k1000AlternateProtocolHostsToLoad; | 369 alternate_protocols_to_load = k1000AlternateProtocolHostsToLoad; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 detected_corrupted_prefs = true; | 473 detected_corrupted_prefs = true; |
| 449 continue; | 474 continue; |
| 450 } | 475 } |
| 451 | 476 |
| 452 net::AlternateProtocolInfo port_alternate_protocol(port, | 477 net::AlternateProtocolInfo port_alternate_protocol(port, |
| 453 protocol, | 478 protocol, |
| 454 probability); | 479 probability); |
| 455 alternate_protocol_map->Put(server, port_alternate_protocol); | 480 alternate_protocol_map->Put(server, port_alternate_protocol); |
| 456 ++count; | 481 ++count; |
| 457 } while (false); | 482 } while (false); |
| 483 |
| 484 // Get SupportsQuic. |
| 485 DCHECK(supports_quic_map->find(server) == supports_quic_map->end()); |
| 486 const base::DictionaryValue* supports_quic_dict = NULL; |
| 487 if (!server_pref_dict->GetDictionaryWithoutPathExpansion( |
| 488 "supports_quic", &supports_quic_dict)) { |
| 489 continue; |
| 490 } |
| 491 do { |
| 492 bool used_quic = 0; |
| 493 if (!supports_quic_dict->GetBooleanWithoutPathExpansion( |
| 494 "used_quic", &used_quic)) { |
| 495 DVLOG(1) << "Malformed SupportsQuic server: " << server_str; |
| 496 detected_corrupted_prefs = true; |
| 497 continue; |
| 498 } |
| 499 std::string address; |
| 500 if (!supports_quic_dict->GetStringWithoutPathExpansion( |
| 501 "address", &address)) { |
| 502 DVLOG(1) << "Malformed SupportsQuic server: " << server_str; |
| 503 detected_corrupted_prefs = true; |
| 504 continue; |
| 505 } |
| 506 net::SupportsQuic supports_quic(used_quic, address); |
| 507 supports_quic_map->insert(std::make_pair(server, supports_quic)); |
| 508 } while (false); |
| 458 } | 509 } |
| 459 | 510 |
| 460 network_task_runner_->PostTask( | 511 network_task_runner_->PostTask( |
| 461 FROM_HERE, | 512 FROM_HERE, |
| 462 base::Bind( | 513 base::Bind( |
| 463 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread, | 514 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread, |
| 464 base::Unretained(this), | 515 base::Unretained(this), |
| 465 base::Owned(spdy_servers.release()), | 516 base::Owned(spdy_servers.release()), |
| 466 base::Owned(spdy_settings_map.release()), | 517 base::Owned(spdy_settings_map.release()), |
| 467 base::Owned(alternate_protocol_map.release()), | 518 base::Owned(alternate_protocol_map.release()), |
| 468 alternate_protocol_experiment, | 519 alternate_protocol_experiment, |
| 520 base::Owned(supports_quic_map.release()), |
| 469 detected_corrupted_prefs)); | 521 detected_corrupted_prefs)); |
| 470 } | 522 } |
| 471 | 523 |
| 472 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread( | 524 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkThread( |
| 473 StringVector* spdy_servers, | 525 StringVector* spdy_servers, |
| 474 net::SpdySettingsMap* spdy_settings_map, | 526 net::SpdySettingsMap* spdy_settings_map, |
| 475 net::AlternateProtocolMap* alternate_protocol_map, | 527 net::AlternateProtocolMap* alternate_protocol_map, |
| 476 net::AlternateProtocolExperiment alternate_protocol_experiment, | 528 net::AlternateProtocolExperiment alternate_protocol_experiment, |
| 529 net::SupportsQuicMap* supports_quic_map, |
| 477 bool detected_corrupted_prefs) { | 530 bool detected_corrupted_prefs) { |
| 478 // Preferences have the master data because admins might have pushed new | 531 // Preferences have the master data because admins might have pushed new |
| 479 // preferences. Update the cached data with new data from preferences. | 532 // preferences. Update the cached data with new data from preferences. |
| 480 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 533 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 481 | 534 |
| 482 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size()); | 535 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size()); |
| 483 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); | 536 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); |
| 484 | 537 |
| 485 // Update the cached data and use the new spdy_settings from preferences. | 538 // Update the cached data and use the new spdy_settings from preferences. |
| 486 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size()); | 539 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size()); |
| 487 http_server_properties_impl_->InitializeSpdySettingsServers( | 540 http_server_properties_impl_->InitializeSpdySettingsServers( |
| 488 spdy_settings_map); | 541 spdy_settings_map); |
| 489 | 542 |
| 490 // Update the cached data and use the new Alternate-Protocol server list from | 543 // Update the cached data and use the new Alternate-Protocol server list from |
| 491 // preferences. | 544 // preferences. |
| 492 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers", | 545 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers", |
| 493 alternate_protocol_map->size()); | 546 alternate_protocol_map->size()); |
| 494 http_server_properties_impl_->InitializeAlternateProtocolServers( | 547 http_server_properties_impl_->InitializeAlternateProtocolServers( |
| 495 alternate_protocol_map); | 548 alternate_protocol_map); |
| 496 http_server_properties_impl_->SetAlternateProtocolExperiment( | 549 http_server_properties_impl_->SetAlternateProtocolExperiment( |
| 497 alternate_protocol_experiment); | 550 alternate_protocol_experiment); |
| 498 | 551 |
| 552 http_server_properties_impl_->InitializeSupportsQuic(supports_quic_map); |
| 553 |
| 499 // Update the prefs with what we have read (delete all corrupted prefs). | 554 // Update the prefs with what we have read (delete all corrupted prefs). |
| 500 if (detected_corrupted_prefs) | 555 if (detected_corrupted_prefs) |
| 501 ScheduleUpdatePrefsOnNetworkThread(); | 556 ScheduleUpdatePrefsOnNetworkThread(); |
| 502 } | 557 } |
| 503 | 558 |
| 504 // | 559 // |
| 505 // Update Preferences with data from the cached data. | 560 // Update Preferences with data from the cached data. |
| 506 // | 561 // |
| 507 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnNetworkThread() { | 562 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnNetworkThread() { |
| 508 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 563 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 http_server_properties_impl_->GetCanonicalSuffix(server); | 617 http_server_properties_impl_->GetCanonicalSuffix(server); |
| 563 if (!canonical_suffix.empty()) { | 618 if (!canonical_suffix.empty()) { |
| 564 if (persisted_map.find(canonical_suffix) != persisted_map.end()) | 619 if (persisted_map.find(canonical_suffix) != persisted_map.end()) |
| 565 continue; | 620 continue; |
| 566 persisted_map[canonical_suffix] = true; | 621 persisted_map[canonical_suffix] = true; |
| 567 } | 622 } |
| 568 alternate_protocol_map->Put(server, it->second); | 623 alternate_protocol_map->Put(server, it->second); |
| 569 ++count; | 624 ++count; |
| 570 } | 625 } |
| 571 | 626 |
| 627 net::SupportsQuicMap* supports_quic_map = new net::SupportsQuicMap(); |
| 628 const net::SupportsQuicMap& main_supports_quic_map = |
| 629 http_server_properties_impl_->supports_quic_map(); |
| 630 for (net::SupportsQuicMap::const_iterator it = main_supports_quic_map.begin(); |
| 631 it != main_supports_quic_map.end(); ++it) { |
| 632 supports_quic_map->insert(std::make_pair(it->first, it->second)); |
| 633 } |
| 634 |
| 572 // Update the preferences on the pref thread. | 635 // Update the preferences on the pref thread. |
| 573 pref_task_runner_->PostTask( | 636 pref_task_runner_->PostTask( |
| 574 FROM_HERE, | 637 FROM_HERE, |
| 575 base::Bind(&HttpServerPropertiesManager::UpdatePrefsOnPrefThread, | 638 base::Bind(&HttpServerPropertiesManager::UpdatePrefsOnPrefThread, |
| 576 pref_weak_ptr_, | 639 pref_weak_ptr_, |
| 577 base::Owned(spdy_server_list), | 640 base::Owned(spdy_server_list), |
| 578 base::Owned(spdy_settings_map), | 641 base::Owned(spdy_settings_map), |
| 579 base::Owned(alternate_protocol_map), | 642 base::Owned(alternate_protocol_map), |
| 643 base::Owned(supports_quic_map), |
| 580 completion)); | 644 completion)); |
| 581 } | 645 } |
| 582 | 646 |
| 583 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, | 647 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, |
| 584 // and AlternateProtocolInfo preferences for a server. This is used only in | 648 // AlternateProtocolInfo and SupportsQuic preferences for a server. This is used |
| 585 // UpdatePrefsOnPrefThread. | 649 // only in UpdatePrefsOnPrefThread. |
| 586 struct ServerPref { | 650 struct ServerPref { |
| 587 ServerPref() | 651 ServerPref() : supports_spdy(false), |
| 588 : supports_spdy(false), settings_map(NULL), alternate_protocol(NULL) {} | 652 settings_map(NULL), |
| 653 alternate_protocol(NULL), |
| 654 supports_quic(NULL) {} |
| 589 ServerPref(bool supports_spdy, | 655 ServerPref(bool supports_spdy, |
| 590 const net::SettingsMap* settings_map, | 656 const net::SettingsMap* settings_map, |
| 591 const net::AlternateProtocolInfo* alternate_protocol) | 657 const net::AlternateProtocolInfo* alternate_protocol, |
| 658 const net::SupportsQuic* supports_quic) |
| 592 : supports_spdy(supports_spdy), | 659 : supports_spdy(supports_spdy), |
| 593 settings_map(settings_map), | 660 settings_map(settings_map), |
| 594 alternate_protocol(alternate_protocol) {} | 661 alternate_protocol(alternate_protocol), |
| 662 supports_quic(supports_quic) {} |
| 595 bool supports_spdy; | 663 bool supports_spdy; |
| 596 const net::SettingsMap* settings_map; | 664 const net::SettingsMap* settings_map; |
| 597 const net::AlternateProtocolInfo* alternate_protocol; | 665 const net::AlternateProtocolInfo* alternate_protocol; |
| 666 const net::SupportsQuic* supports_quic; |
| 598 }; | 667 }; |
| 599 | 668 |
| 600 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( | 669 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( |
| 601 base::ListValue* spdy_server_list, | 670 base::ListValue* spdy_server_list, |
| 602 net::SpdySettingsMap* spdy_settings_map, | 671 net::SpdySettingsMap* spdy_settings_map, |
| 603 net::AlternateProtocolMap* alternate_protocol_map, | 672 net::AlternateProtocolMap* alternate_protocol_map, |
| 673 net::SupportsQuicMap* supports_quic_map, |
| 604 const base::Closure& completion) { | 674 const base::Closure& completion) { |
| 605 typedef std::map<net::HostPortPair, ServerPref> ServerPrefMap; | 675 typedef std::map<net::HostPortPair, ServerPref> ServerPrefMap; |
| 606 ServerPrefMap server_pref_map; | 676 ServerPrefMap server_pref_map; |
| 607 | 677 |
| 608 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 678 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
| 609 | 679 |
| 610 // Add servers that support spdy to server_pref_map. | 680 // Add servers that support spdy to server_pref_map. |
| 611 std::string s; | 681 std::string s; |
| 612 for (base::ListValue::const_iterator list_it = spdy_server_list->begin(); | 682 for (base::ListValue::const_iterator list_it = spdy_server_list->begin(); |
| 613 list_it != spdy_server_list->end(); | 683 list_it != spdy_server_list->end(); |
| 614 ++list_it) { | 684 ++list_it) { |
| 615 if ((*list_it)->GetAsString(&s)) { | 685 if ((*list_it)->GetAsString(&s)) { |
| 616 net::HostPortPair server = net::HostPortPair::FromString(s); | 686 net::HostPortPair server = net::HostPortPair::FromString(s); |
| 617 | 687 |
| 618 ServerPrefMap::iterator it = server_pref_map.find(server); | 688 ServerPrefMap::iterator it = server_pref_map.find(server); |
| 619 if (it == server_pref_map.end()) { | 689 if (it == server_pref_map.end()) { |
| 620 ServerPref server_pref(true, NULL, NULL); | 690 ServerPref server_pref(true, NULL, NULL, NULL); |
| 621 server_pref_map[server] = server_pref; | 691 server_pref_map[server] = server_pref; |
| 622 } else { | 692 } else { |
| 623 it->second.supports_spdy = true; | 693 it->second.supports_spdy = true; |
| 624 } | 694 } |
| 625 } | 695 } |
| 626 } | 696 } |
| 627 | 697 |
| 628 // Add servers that have SpdySettings to server_pref_map. | 698 // Add servers that have SpdySettings to server_pref_map. |
| 629 for (net::SpdySettingsMap::iterator map_it = spdy_settings_map->begin(); | 699 for (net::SpdySettingsMap::iterator map_it = spdy_settings_map->begin(); |
| 630 map_it != spdy_settings_map->end(); | 700 map_it != spdy_settings_map->end(); |
| 631 ++map_it) { | 701 ++map_it) { |
| 632 const net::HostPortPair& server = map_it->first; | 702 const net::HostPortPair& server = map_it->first; |
| 633 | 703 |
| 634 ServerPrefMap::iterator it = server_pref_map.find(server); | 704 ServerPrefMap::iterator it = server_pref_map.find(server); |
| 635 if (it == server_pref_map.end()) { | 705 if (it == server_pref_map.end()) { |
| 636 ServerPref server_pref(false, &map_it->second, NULL); | 706 ServerPref server_pref(false, &map_it->second, NULL, NULL); |
| 637 server_pref_map[server] = server_pref; | 707 server_pref_map[server] = server_pref; |
| 638 } else { | 708 } else { |
| 639 it->second.settings_map = &map_it->second; | 709 it->second.settings_map = &map_it->second; |
| 640 } | 710 } |
| 641 } | 711 } |
| 642 | 712 |
| 643 // Add AlternateProtocol servers to server_pref_map. | 713 // Add AlternateProtocol servers to server_pref_map. |
| 644 for (net::AlternateProtocolMap::const_iterator map_it = | 714 for (net::AlternateProtocolMap::const_iterator map_it = |
| 645 alternate_protocol_map->begin(); | 715 alternate_protocol_map->begin(); |
| 646 map_it != alternate_protocol_map->end(); | 716 map_it != alternate_protocol_map->end(); |
| 647 ++map_it) { | 717 ++map_it) { |
| 648 const net::HostPortPair& server = map_it->first; | 718 const net::HostPortPair& server = map_it->first; |
| 649 const net::AlternateProtocolInfo& port_alternate_protocol = | 719 const net::AlternateProtocolInfo& port_alternate_protocol = |
| 650 map_it->second; | 720 map_it->second; |
| 651 if (!net::IsAlternateProtocolValid(port_alternate_protocol.protocol)) { | 721 if (!net::IsAlternateProtocolValid(port_alternate_protocol.protocol)) { |
| 652 continue; | 722 continue; |
| 653 } | 723 } |
| 654 | 724 |
| 655 ServerPrefMap::iterator it = server_pref_map.find(server); | 725 ServerPrefMap::iterator it = server_pref_map.find(server); |
| 656 if (it == server_pref_map.end()) { | 726 if (it == server_pref_map.end()) { |
| 657 ServerPref server_pref(false, NULL, &map_it->second); | 727 ServerPref server_pref(false, NULL, &map_it->second, NULL); |
| 658 server_pref_map[server] = server_pref; | 728 server_pref_map[server] = server_pref; |
| 659 } else { | 729 } else { |
| 660 it->second.alternate_protocol = &map_it->second; | 730 it->second.alternate_protocol = &map_it->second; |
| 661 } | 731 } |
| 662 } | 732 } |
| 663 | 733 |
| 734 // Add SupportsQuic servers to server_pref_map. |
| 735 for (net::SupportsQuicMap::const_iterator map_it = supports_quic_map->begin(); |
| 736 map_it != supports_quic_map->end(); ++map_it) { |
| 737 const net::HostPortPair& server = map_it->first; |
| 738 |
| 739 ServerPrefMap::iterator it = server_pref_map.find(server); |
| 740 if (it == server_pref_map.end()) { |
| 741 ServerPref server_pref(false, NULL, NULL, &map_it->second); |
| 742 server_pref_map[server] = server_pref; |
| 743 } else { |
| 744 it->second.supports_quic = &map_it->second; |
| 745 } |
| 746 } |
| 747 |
| 664 // Persist properties to the |path_|. | 748 // Persist properties to the |path_|. |
| 665 base::DictionaryValue http_server_properties_dict; | 749 base::DictionaryValue http_server_properties_dict; |
| 666 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 750 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 667 for (ServerPrefMap::const_iterator map_it = server_pref_map.begin(); | 751 for (ServerPrefMap::const_iterator map_it = server_pref_map.begin(); |
| 668 map_it != server_pref_map.end(); | 752 map_it != server_pref_map.end(); |
| 669 ++map_it) { | 753 ++map_it) { |
| 670 const net::HostPortPair& server = map_it->first; | 754 const net::HostPortPair& server = map_it->first; |
| 671 const ServerPref& server_pref = map_it->second; | 755 const ServerPref& server_pref = map_it->second; |
| 672 | 756 |
| 673 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 757 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 701 port_alternate_protocol->port); | 785 port_alternate_protocol->port); |
| 702 const char* protocol_str = | 786 const char* protocol_str = |
| 703 net::AlternateProtocolToString(port_alternate_protocol->protocol); | 787 net::AlternateProtocolToString(port_alternate_protocol->protocol); |
| 704 port_alternate_protocol_dict->SetString("protocol_str", protocol_str); | 788 port_alternate_protocol_dict->SetString("protocol_str", protocol_str); |
| 705 port_alternate_protocol_dict->SetDouble( | 789 port_alternate_protocol_dict->SetDouble( |
| 706 "probability", port_alternate_protocol->probability); | 790 "probability", port_alternate_protocol->probability); |
| 707 server_pref_dict->SetWithoutPathExpansion( | 791 server_pref_dict->SetWithoutPathExpansion( |
| 708 "alternate_protocol", port_alternate_protocol_dict); | 792 "alternate_protocol", port_alternate_protocol_dict); |
| 709 } | 793 } |
| 710 | 794 |
| 795 // Save supports_quic. |
| 796 if (server_pref.supports_quic) { |
| 797 base::DictionaryValue* supports_quic_dict = new base::DictionaryValue; |
| 798 const net::SupportsQuic* supports_quic = server_pref.supports_quic; |
| 799 supports_quic_dict->SetBoolean("used_quic", supports_quic->used_quic); |
| 800 supports_quic_dict->SetString("address", supports_quic->address); |
| 801 server_pref_dict->SetWithoutPathExpansion( |
| 802 "supports_quic", supports_quic_dict); |
| 803 } |
| 804 |
| 711 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict); | 805 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict); |
| 712 } | 806 } |
| 713 | 807 |
| 714 http_server_properties_dict.SetWithoutPathExpansion("servers", servers_dict); | 808 http_server_properties_dict.SetWithoutPathExpansion("servers", servers_dict); |
| 715 SetVersion(&http_server_properties_dict, kVersionNumber); | 809 SetVersion(&http_server_properties_dict, kVersionNumber); |
| 716 setting_prefs_ = true; | 810 setting_prefs_ = true; |
| 717 pref_service_->Set(path_, http_server_properties_dict); | 811 pref_service_->Set(path_, http_server_properties_dict); |
| 718 setting_prefs_ = false; | 812 setting_prefs_ = false; |
| 719 | 813 |
| 720 // Note that |completion| will be fired after we have written everything to | 814 // Note that |completion| will be fired after we have written everything to |
| 721 // the Preferences, but likely before these changes are serialized to disk. | 815 // the Preferences, but likely before these changes are serialized to disk. |
| 722 // This is not a problem though, as JSONPrefStore guarantees that this will | 816 // This is not a problem though, as JSONPrefStore guarantees that this will |
| 723 // happen, pretty soon, and even in the case we shut down immediately. | 817 // happen, pretty soon, and even in the case we shut down immediately. |
| 724 if (!completion.is_null()) | 818 if (!completion.is_null()) |
| 725 completion.Run(); | 819 completion.Run(); |
| 726 } | 820 } |
| 727 | 821 |
| 728 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { | 822 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { |
| 729 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 823 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
| 730 if (!setting_prefs_) | 824 if (!setting_prefs_) |
| 731 ScheduleUpdateCacheOnPrefThread(); | 825 ScheduleUpdateCacheOnPrefThread(); |
| 732 } | 826 } |
| 733 | 827 |
| 734 } // namespace net | 828 } // namespace net |
| OLD | NEW |