| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "net/http/http_server_properties_manager.h" | 5 #include "net/http/http_server_properties_manager.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/metrics/histogram_macros.h" | 8 #include "base/metrics/histogram_macros.h" |
| 9 #include "base/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 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 183 http_server_properties_impl_->SetHTTP11Required(server); | 183 http_server_properties_impl_->SetHTTP11Required(server); |
| 184 ScheduleUpdatePrefsOnNetworkThread(HTTP_11_REQUIRED); | 184 ScheduleUpdatePrefsOnNetworkThread(HTTP_11_REQUIRED); |
| 185 } | 185 } |
| 186 | 186 |
| 187 void HttpServerPropertiesManager::MaybeForceHTTP11(const HostPortPair& server, | 187 void HttpServerPropertiesManager::MaybeForceHTTP11(const HostPortPair& server, |
| 188 SSLConfig* ssl_config) { | 188 SSLConfig* ssl_config) { |
| 189 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 189 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 190 http_server_properties_impl_->MaybeForceHTTP11(server, ssl_config); | 190 http_server_properties_impl_->MaybeForceHTTP11(server, ssl_config); |
| 191 } | 191 } |
| 192 | 192 |
| 193 AlternativeService HttpServerPropertiesManager::GetAlternativeService( | 193 AlternativeServiceVector HttpServerPropertiesManager::GetAlternativeServices( |
| 194 const HostPortPair& origin) { | 194 const HostPortPair& origin) { |
| 195 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 195 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 196 return http_server_properties_impl_->GetAlternativeService(origin); | 196 return http_server_properties_impl_->GetAlternativeServices(origin); |
| 197 } | 197 } |
| 198 | 198 |
| 199 void HttpServerPropertiesManager::SetAlternativeService( | 199 bool HttpServerPropertiesManager::SetAlternativeService( |
| 200 const HostPortPair& origin, | 200 const HostPortPair& origin, |
| 201 const AlternativeService& alternative_service, | 201 const AlternativeService& alternative_service, |
| 202 double alternative_probability) { | 202 double alternative_probability) { |
| 203 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 203 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 204 AlternativeService old_alternative_service = GetAlternativeService(origin); | 204 const bool changed = http_server_properties_impl_->SetAlternativeService( |
| 205 http_server_properties_impl_->SetAlternativeService( | |
| 206 origin, alternative_service, alternative_probability); | 205 origin, alternative_service, alternative_probability); |
| 207 AlternativeService new_alternative_service = GetAlternativeService(origin); | 206 if (changed) { |
| 208 // If |alternative_probability| was above the threashold now it is below or | 207 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES); |
| 209 // vice versa, then a different alternative_service will be returned from the | 208 } |
| 210 // old and if so, then persist. | 209 return changed; |
| 211 if (old_alternative_service != new_alternative_service) | 210 } |
| 212 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICE); | 211 |
| 212 bool HttpServerPropertiesManager::SetAlternativeServices( |
| 213 const HostPortPair& origin, |
| 214 const AlternativeServiceInfoVector& alternative_service_info_vector) { |
| 215 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 216 const bool changed = http_server_properties_impl_->SetAlternativeServices( |
| 217 origin, alternative_service_info_vector); |
| 218 if (changed) { |
| 219 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES); |
| 220 } |
| 221 return changed; |
| 213 } | 222 } |
| 214 | 223 |
| 215 void HttpServerPropertiesManager::MarkAlternativeServiceBroken( | 224 void HttpServerPropertiesManager::MarkAlternativeServiceBroken( |
| 216 const AlternativeService& alternative_service) { | 225 const AlternativeService& alternative_service) { |
| 217 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 226 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 218 http_server_properties_impl_->MarkAlternativeServiceBroken( | 227 http_server_properties_impl_->MarkAlternativeServiceBroken( |
| 219 alternative_service); | 228 alternative_service); |
| 220 ScheduleUpdatePrefsOnNetworkThread(MARK_ALTERNATIVE_SERVICE_BROKEN); | 229 ScheduleUpdatePrefsOnNetworkThread(MARK_ALTERNATIVE_SERVICE_BROKEN); |
| 221 } | 230 } |
| 222 | 231 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 249 alternative_service); | 258 alternative_service); |
| 250 http_server_properties_impl_->ConfirmAlternativeService(alternative_service); | 259 http_server_properties_impl_->ConfirmAlternativeService(alternative_service); |
| 251 bool new_value = http_server_properties_impl_->IsAlternativeServiceBroken( | 260 bool new_value = http_server_properties_impl_->IsAlternativeServiceBroken( |
| 252 alternative_service); | 261 alternative_service); |
| 253 // For persisting, we only care about the value returned by | 262 // For persisting, we only care about the value returned by |
| 254 // IsAlternativeServiceBroken. If that value changes, then call persist. | 263 // IsAlternativeServiceBroken. If that value changes, then call persist. |
| 255 if (old_value != new_value) | 264 if (old_value != new_value) |
| 256 ScheduleUpdatePrefsOnNetworkThread(CONFIRM_ALTERNATIVE_SERVICE); | 265 ScheduleUpdatePrefsOnNetworkThread(CONFIRM_ALTERNATIVE_SERVICE); |
| 257 } | 266 } |
| 258 | 267 |
| 259 void HttpServerPropertiesManager::ClearAlternativeService( | 268 void HttpServerPropertiesManager::ClearAlternativeServices( |
| 260 const HostPortPair& origin) { | 269 const HostPortPair& origin) { |
| 261 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 270 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 262 const AlternativeServiceMap& map = | 271 const AlternativeServiceMap& map = |
| 263 http_server_properties_impl_->alternative_service_map(); | 272 http_server_properties_impl_->alternative_service_map(); |
| 264 size_t old_size = map.size(); | 273 size_t old_size = map.size(); |
| 265 http_server_properties_impl_->ClearAlternativeService(origin); | 274 http_server_properties_impl_->ClearAlternativeServices(origin); |
| 266 size_t new_size = map.size(); | 275 size_t new_size = map.size(); |
| 267 // Persist only if we have deleted an entry. | 276 // Persist only if we have deleted an entry. |
| 268 if (old_size != new_size) | 277 if (old_size != new_size) |
| 269 ScheduleUpdatePrefsOnNetworkThread(CLEAR_ALTERNATIVE_SERVICE); | 278 ScheduleUpdatePrefsOnNetworkThread(CLEAR_ALTERNATIVE_SERVICE); |
| 270 } | 279 } |
| 271 | 280 |
| 272 const AlternativeServiceMap& | 281 const AlternativeServiceMap& |
| 273 HttpServerPropertiesManager::alternative_service_map() const { | 282 HttpServerPropertiesManager::alternative_service_map() const { |
| 274 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 283 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 275 return http_server_properties_impl_->alternative_service_map(); | 284 return http_server_properties_impl_->alternative_service_map(); |
| (...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 566 | 575 |
| 567 bool HttpServerPropertiesManager::AddToAlternativeServiceMap( | 576 bool HttpServerPropertiesManager::AddToAlternativeServiceMap( |
| 568 const HostPortPair& server, | 577 const HostPortPair& server, |
| 569 const base::DictionaryValue& server_pref_dict, | 578 const base::DictionaryValue& server_pref_dict, |
| 570 AlternativeServiceMap* alternative_service_map) { | 579 AlternativeServiceMap* alternative_service_map) { |
| 571 DCHECK(alternative_service_map->Peek(server) == | 580 DCHECK(alternative_service_map->Peek(server) == |
| 572 alternative_service_map->end()); | 581 alternative_service_map->end()); |
| 573 // Get alternative_services... | 582 // Get alternative_services... |
| 574 const base::ListValue* alternative_service_list; | 583 const base::ListValue* alternative_service_list; |
| 575 const base::DictionaryValue* alternative_service_dict; | 584 const base::DictionaryValue* alternative_service_dict; |
| 576 AlternativeServiceInfo alternative_service_info; | 585 AlternativeServiceInfoVector alternative_service_info_vector; |
| 577 if (server_pref_dict.GetListWithoutPathExpansion(kAlternativeServiceKey, | 586 if (server_pref_dict.GetListWithoutPathExpansion(kAlternativeServiceKey, |
| 578 &alternative_service_list)) { | 587 &alternative_service_list)) { |
| 579 if (alternative_service_list->empty()) { | 588 for (const base::Value* alternative_service_list_item : |
| 580 return false; | 589 *alternative_service_list) { |
| 590 if (!alternative_service_list_item->GetAsDictionary( |
| 591 &alternative_service_dict)) |
| 592 return false; |
| 593 AlternativeServiceInfo alternative_service_info = |
| 594 ParseAlternativeServiceDict(*alternative_service_dict, |
| 595 server.ToString()); |
| 596 if (alternative_service_info.alternative_service.protocol == |
| 597 UNINITIALIZED_ALTERNATE_PROTOCOL) { |
| 598 return false; |
| 599 } |
| 600 alternative_service_info_vector.push_back(alternative_service_info); |
| 581 } | 601 } |
| 582 // Get first element of the list. | |
| 583 // TODO(bnc): Once we store multiple AlternativeServiceInfo per server, read | |
| 584 // all of them. | |
| 585 if (!alternative_service_list->GetDictionary(0, | |
| 586 &alternative_service_dict)) { | |
| 587 return false; | |
| 588 } | |
| 589 alternative_service_info = ParseAlternativeServiceDict( | |
| 590 *alternative_service_dict, server.ToString()); | |
| 591 } else { | 602 } else { |
| 592 // ...or alternate_protocol. | 603 // ...or alternate_protocol. |
| 593 // TODO(bnc): Remove this in M46, we do not need preference migration for | 604 // TODO(bnc): Remove this in M46, we do not need preference migration for |
| 594 // long. | 605 // long. |
| 595 if (!server_pref_dict.GetDictionaryWithoutPathExpansion( | 606 if (!server_pref_dict.GetDictionaryWithoutPathExpansion( |
| 596 kAlternateProtocolKey, &alternative_service_dict)) { | 607 kAlternateProtocolKey, &alternative_service_dict)) { |
| 597 return true; | 608 return true; |
| 598 } | 609 } |
| 599 alternative_service_info = ParseAlternativeServiceDict( | 610 AlternativeServiceInfo alternative_service_info = |
| 600 *alternative_service_dict, server.ToString()); | 611 ParseAlternativeServiceDict(*alternative_service_dict, |
| 612 server.ToString()); |
| 613 if (alternative_service_info.alternative_service.protocol == |
| 614 UNINITIALIZED_ALTERNATE_PROTOCOL) { |
| 615 return false; |
| 616 } |
| 617 alternative_service_info_vector.push_back(alternative_service_info); |
| 601 } | 618 } |
| 602 | 619 |
| 603 if (alternative_service_info.alternative_service.protocol == | 620 if (alternative_service_info_vector.empty()) { |
| 604 UNINITIALIZED_ALTERNATE_PROTOCOL) { | |
| 605 return false; | 621 return false; |
| 606 } | 622 } |
| 607 alternative_service_map->Put(server, alternative_service_info); | 623 |
| 624 alternative_service_map->Put(server, alternative_service_info_vector); |
| 608 return true; | 625 return true; |
| 609 } | 626 } |
| 610 | 627 |
| 611 bool HttpServerPropertiesManager::ReadSupportsQuic( | 628 bool HttpServerPropertiesManager::ReadSupportsQuic( |
| 612 const base::DictionaryValue& http_server_properties_dict, | 629 const base::DictionaryValue& http_server_properties_dict, |
| 613 IPAddressNumber* last_quic_address) { | 630 IPAddressNumber* last_quic_address) { |
| 614 const base::DictionaryValue* supports_quic_dict = NULL; | 631 const base::DictionaryValue* supports_quic_dict = NULL; |
| 615 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion( | 632 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion( |
| 616 kSupportsQuicKey, &supports_quic_dict)) { | 633 kSupportsQuicKey, &supports_quic_dict)) { |
| 617 return true; | 634 return true; |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); | 689 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); |
| 673 | 690 |
| 674 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size()); | 691 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size()); |
| 675 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); | 692 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); |
| 676 | 693 |
| 677 // Update the cached data and use the new spdy_settings from preferences. | 694 // Update the cached data and use the new spdy_settings from preferences. |
| 678 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size()); | 695 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size()); |
| 679 http_server_properties_impl_->InitializeSpdySettingsServers( | 696 http_server_properties_impl_->InitializeSpdySettingsServers( |
| 680 spdy_settings_map); | 697 spdy_settings_map); |
| 681 | 698 |
| 682 // Update the cached data and use the new Alternate-Protocol server list from | 699 // Update the cached data and use the new alternative service list from |
| 683 // preferences. | 700 // preferences. |
| 684 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers", | 701 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers", |
| 685 alternative_service_map->size()); | 702 alternative_service_map->size()); |
| 686 http_server_properties_impl_->InitializeAlternativeServiceServers( | 703 http_server_properties_impl_->InitializeAlternativeServiceServers( |
| 687 alternative_service_map); | 704 alternative_service_map); |
| 688 | 705 |
| 689 http_server_properties_impl_->InitializeSupportsQuic(last_quic_address); | 706 http_server_properties_impl_->InitializeSupportsQuic(last_quic_address); |
| 690 | 707 |
| 691 http_server_properties_impl_->InitializeServerNetworkStats( | 708 http_server_properties_impl_->InitializeServerNetworkStats( |
| 692 server_network_stats_map); | 709 server_network_stats_map); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 748 | 765 |
| 749 AlternativeServiceMap* alternative_service_map = | 766 AlternativeServiceMap* alternative_service_map = |
| 750 new AlternativeServiceMap(kMaxAlternateProtocolHostsToPersist); | 767 new AlternativeServiceMap(kMaxAlternateProtocolHostsToPersist); |
| 751 const AlternativeServiceMap& map = | 768 const AlternativeServiceMap& map = |
| 752 http_server_properties_impl_->alternative_service_map(); | 769 http_server_properties_impl_->alternative_service_map(); |
| 753 count = 0; | 770 count = 0; |
| 754 typedef std::map<std::string, bool> CanonicalHostPersistedMap; | 771 typedef std::map<std::string, bool> CanonicalHostPersistedMap; |
| 755 CanonicalHostPersistedMap persisted_map; | 772 CanonicalHostPersistedMap persisted_map; |
| 756 for (AlternativeServiceMap::const_iterator it = map.begin(); | 773 for (AlternativeServiceMap::const_iterator it = map.begin(); |
| 757 it != map.end() && count < kMaxAlternateProtocolHostsToPersist; ++it) { | 774 it != map.end() && count < kMaxAlternateProtocolHostsToPersist; ++it) { |
| 758 const AlternativeServiceInfo& alternative_service_info = it->second; | 775 const HostPortPair& server = it->first; |
| 759 if (!IsAlternateProtocolValid( | 776 AlternativeServiceInfoVector notbroken_alternative_service_info_vector; |
| 760 alternative_service_info.alternative_service.protocol)) { | 777 for (const AlternativeServiceInfo& alternative_service_info : it->second) { |
| 778 if (!IsAlternateProtocolValid( |
| 779 alternative_service_info.alternative_service.protocol)) { |
| 780 continue; |
| 781 } |
| 782 AlternativeService alternative_service( |
| 783 alternative_service_info.alternative_service); |
| 784 if (alternative_service.host.empty()) { |
| 785 alternative_service.host = server.host(); |
| 786 } |
| 787 if (IsAlternativeServiceBroken(alternative_service)) { |
| 788 continue; |
| 789 } |
| 790 notbroken_alternative_service_info_vector.push_back( |
| 791 alternative_service_info); |
| 792 } |
| 793 if (notbroken_alternative_service_info_vector.empty()) { |
| 761 continue; | 794 continue; |
| 762 } | 795 } |
| 763 const HostPortPair& server = it->first; | 796 alternative_service_map->Put(server, |
| 764 AlternativeService alternative_service( | 797 notbroken_alternative_service_info_vector); |
| 765 alternative_service_info.alternative_service); | |
| 766 if (alternative_service.host.empty()) { | |
| 767 alternative_service.host = server.host(); | |
| 768 } | |
| 769 if (IsAlternativeServiceBroken(alternative_service)) { | |
| 770 continue; | |
| 771 } | |
| 772 std::string canonical_suffix = | 798 std::string canonical_suffix = |
| 773 http_server_properties_impl_->GetCanonicalSuffix(server.host()); | 799 http_server_properties_impl_->GetCanonicalSuffix(server.host()); |
| 774 if (!canonical_suffix.empty()) { | 800 if (!canonical_suffix.empty()) { |
| 775 if (persisted_map.find(canonical_suffix) != persisted_map.end()) | 801 if (persisted_map.find(canonical_suffix) != persisted_map.end()) |
| 776 continue; | 802 continue; |
| 777 persisted_map[canonical_suffix] = true; | 803 persisted_map[canonical_suffix] = true; |
| 778 } | 804 } |
| 779 alternative_service_map->Put(server, alternative_service_info); | |
| 780 ++count; | 805 ++count; |
| 781 } | 806 } |
| 782 | 807 |
| 783 ServerNetworkStatsMap* server_network_stats_map = | 808 ServerNetworkStatsMap* server_network_stats_map = |
| 784 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist); | 809 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist); |
| 785 const ServerNetworkStatsMap& main_server_network_stats_map = | 810 const ServerNetworkStatsMap& main_server_network_stats_map = |
| 786 http_server_properties_impl_->server_network_stats_map(); | 811 http_server_properties_impl_->server_network_stats_map(); |
| 787 for (ServerNetworkStatsMap::const_iterator it = | 812 for (ServerNetworkStatsMap::const_iterator it = |
| 788 main_server_network_stats_map.begin(); | 813 main_server_network_stats_map.begin(); |
| 789 it != main_server_network_stats_map.end(); ++it) { | 814 it != main_server_network_stats_map.end(); ++it) { |
| 790 server_network_stats_map->Put(it->first, it->second); | 815 server_network_stats_map->Put(it->first, it->second); |
| 791 } | 816 } |
| 792 | 817 |
| 793 IPAddressNumber* last_quic_addr = new IPAddressNumber; | 818 IPAddressNumber* last_quic_addr = new IPAddressNumber; |
| 794 http_server_properties_impl_->GetSupportsQuic(last_quic_addr); | 819 http_server_properties_impl_->GetSupportsQuic(last_quic_addr); |
| 795 // Update the preferences on the pref thread. | 820 // Update the preferences on the pref thread. |
| 796 pref_task_runner_->PostTask( | 821 pref_task_runner_->PostTask( |
| 797 FROM_HERE, | 822 FROM_HERE, |
| 798 base::Bind( | 823 base::Bind( |
| 799 &HttpServerPropertiesManager::UpdatePrefsOnPrefThread, pref_weak_ptr_, | 824 &HttpServerPropertiesManager::UpdatePrefsOnPrefThread, pref_weak_ptr_, |
| 800 base::Owned(spdy_server_list), base::Owned(spdy_settings_map), | 825 base::Owned(spdy_server_list), base::Owned(spdy_settings_map), |
| 801 base::Owned(alternative_service_map), base::Owned(last_quic_addr), | 826 base::Owned(alternative_service_map), base::Owned(last_quic_addr), |
| 802 base::Owned(server_network_stats_map), completion)); | 827 base::Owned(server_network_stats_map), completion)); |
| 803 } | 828 } |
| 804 | 829 |
| 805 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, | 830 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, |
| 806 // AlternativeServiceInfo and SupportsQuic preferences for a server. This is | 831 // AlternativeServiceInfoVector, and SupportsQuic preferences for a server. This |
| 807 // used only in UpdatePrefsOnPrefThread. | 832 // is used only in UpdatePrefsOnPrefThread. |
| 808 struct ServerPref { | 833 struct ServerPref { |
| 809 ServerPref() | 834 ServerPref() |
| 810 : supports_spdy(false), | 835 : supports_spdy(false), |
| 811 settings_map(NULL), | 836 settings_map(NULL), |
| 812 alternative_service(NULL), | 837 alternative_service_info_vector(NULL), |
| 813 supports_quic(NULL), | 838 supports_quic(NULL), |
| 814 server_network_stats(NULL) {} | 839 server_network_stats(NULL) {} |
| 815 ServerPref(bool supports_spdy, | 840 ServerPref( |
| 816 const SettingsMap* settings_map, | 841 bool supports_spdy, |
| 817 const AlternativeServiceInfo* alternative_service, | 842 const SettingsMap* settings_map, |
| 818 const SupportsQuic* supports_quic, | 843 const AlternativeServiceInfoVector* alternative_service_info_vector, |
| 819 const ServerNetworkStats* server_network_stats) | 844 const SupportsQuic* supports_quic, |
| 845 const ServerNetworkStats* server_network_stats) |
| 820 : supports_spdy(supports_spdy), | 846 : supports_spdy(supports_spdy), |
| 821 settings_map(settings_map), | 847 settings_map(settings_map), |
| 822 alternative_service(alternative_service), | 848 alternative_service_info_vector(alternative_service_info_vector), |
| 823 supports_quic(supports_quic), | 849 supports_quic(supports_quic), |
| 824 server_network_stats(server_network_stats) {} | 850 server_network_stats(server_network_stats) {} |
| 825 bool supports_spdy; | 851 bool supports_spdy; |
| 826 const SettingsMap* settings_map; | 852 const SettingsMap* settings_map; |
| 827 const AlternativeServiceInfo* alternative_service; | 853 const AlternativeServiceInfoVector* alternative_service_info_vector; |
| 828 const SupportsQuic* supports_quic; | 854 const SupportsQuic* supports_quic; |
| 829 const ServerNetworkStats* server_network_stats; | 855 const ServerNetworkStats* server_network_stats; |
| 830 }; | 856 }; |
| 831 | 857 |
| 832 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( | 858 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( |
| 833 base::ListValue* spdy_server_list, | 859 base::ListValue* spdy_server_list, |
| 834 SpdySettingsMap* spdy_settings_map, | 860 SpdySettingsMap* spdy_settings_map, |
| 835 AlternativeServiceMap* alternative_service_map, | 861 AlternativeServiceMap* alternative_service_map, |
| 836 IPAddressNumber* last_quic_address, | 862 IPAddressNumber* last_quic_address, |
| 837 ServerNetworkStatsMap* server_network_stats_map, | 863 ServerNetworkStatsMap* server_network_stats_map, |
| (...skipping 14 matching lines...) Expand all Loading... |
| 852 } | 878 } |
| 853 } | 879 } |
| 854 | 880 |
| 855 // Add servers that have SpdySettings to server_pref_map. | 881 // Add servers that have SpdySettings to server_pref_map. |
| 856 for (SpdySettingsMap::iterator map_it = spdy_settings_map->begin(); | 882 for (SpdySettingsMap::iterator map_it = spdy_settings_map->begin(); |
| 857 map_it != spdy_settings_map->end(); ++map_it) { | 883 map_it != spdy_settings_map->end(); ++map_it) { |
| 858 const HostPortPair& server = map_it->first; | 884 const HostPortPair& server = map_it->first; |
| 859 server_pref_map[server].settings_map = &map_it->second; | 885 server_pref_map[server].settings_map = &map_it->second; |
| 860 } | 886 } |
| 861 | 887 |
| 862 // Add AlternateProtocol servers to server_pref_map. | 888 // Add alternative services to server_pref_map. |
| 863 for (AlternativeServiceMap::const_iterator map_it = | 889 for (AlternativeServiceMap::const_iterator map_it = |
| 864 alternative_service_map->begin(); | 890 alternative_service_map->begin(); |
| 865 map_it != alternative_service_map->end(); ++map_it) { | 891 map_it != alternative_service_map->end(); ++map_it) { |
| 866 server_pref_map[map_it->first].alternative_service = &map_it->second; | 892 server_pref_map[map_it->first].alternative_service_info_vector = |
| 893 &map_it->second; |
| 867 } | 894 } |
| 868 | 895 |
| 869 // Add ServerNetworkStats servers to server_pref_map. | 896 // Add ServerNetworkStats servers to server_pref_map. |
| 870 for (ServerNetworkStatsMap::const_iterator map_it = | 897 for (ServerNetworkStatsMap::const_iterator map_it = |
| 871 server_network_stats_map->begin(); | 898 server_network_stats_map->begin(); |
| 872 map_it != server_network_stats_map->end(); ++map_it) { | 899 map_it != server_network_stats_map->end(); ++map_it) { |
| 873 const HostPortPair& server = map_it->first; | 900 const HostPortPair& server = map_it->first; |
| 874 server_pref_map[server].server_network_stats = &map_it->second; | 901 server_pref_map[server].server_network_stats = &map_it->second; |
| 875 } | 902 } |
| 876 | 903 |
| 877 // Persist properties to the |path_|. | 904 // Persist properties to the |path_|. |
| 878 base::DictionaryValue http_server_properties_dict; | 905 base::DictionaryValue http_server_properties_dict; |
| 879 base::DictionaryValue* servers_dict = new base::DictionaryValue; | 906 base::DictionaryValue* servers_dict = new base::DictionaryValue; |
| 880 for (ServerPrefMap::const_iterator map_it = server_pref_map.begin(); | 907 for (ServerPrefMap::const_iterator map_it = server_pref_map.begin(); |
| 881 map_it != server_pref_map.end(); | 908 map_it != server_pref_map.end(); |
| 882 ++map_it) { | 909 ++map_it) { |
| 883 const HostPortPair& server = map_it->first; | 910 const HostPortPair& server = map_it->first; |
| 884 const ServerPref& server_pref = map_it->second; | 911 const ServerPref& server_pref = map_it->second; |
| 885 | 912 |
| 886 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; | 913 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; |
| 887 | 914 |
| 888 // Save supports_spdy. | 915 // Save supports_spdy. |
| 889 if (server_pref.supports_spdy) | 916 if (server_pref.supports_spdy) |
| 890 server_pref_dict->SetBoolean(kSupportsSpdyKey, server_pref.supports_spdy); | 917 server_pref_dict->SetBoolean(kSupportsSpdyKey, server_pref.supports_spdy); |
| 891 SaveSpdySettingsToServerPrefs(server_pref.settings_map, server_pref_dict); | 918 SaveSpdySettingsToServerPrefs(server_pref.settings_map, server_pref_dict); |
| 892 SaveAlternativeServiceToServerPrefs(server_pref.alternative_service, | 919 SaveAlternativeServiceToServerPrefs( |
| 893 server_pref_dict); | 920 server_pref.alternative_service_info_vector, server_pref_dict); |
| 894 SaveNetworkStatsToServerPrefs(server_pref.server_network_stats, | 921 SaveNetworkStatsToServerPrefs(server_pref.server_network_stats, |
| 895 server_pref_dict); | 922 server_pref_dict); |
| 896 | 923 |
| 897 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict); | 924 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict); |
| 898 } | 925 } |
| 899 | 926 |
| 900 http_server_properties_dict.SetWithoutPathExpansion(kServersKey, | 927 http_server_properties_dict.SetWithoutPathExpansion(kServersKey, |
| 901 servers_dict); | 928 servers_dict); |
| 902 SetVersion(&http_server_properties_dict, kVersionNumber); | 929 SetVersion(&http_server_properties_dict, kVersionNumber); |
| 903 | 930 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 926 it != settings_map->end(); ++it) { | 953 it != settings_map->end(); ++it) { |
| 927 SpdySettingsIds id = it->first; | 954 SpdySettingsIds id = it->first; |
| 928 uint32 value = it->second.second; | 955 uint32 value = it->second.second; |
| 929 std::string key = base::StringPrintf("%u", id); | 956 std::string key = base::StringPrintf("%u", id); |
| 930 spdy_settings_dict->SetInteger(key, value); | 957 spdy_settings_dict->SetInteger(key, value); |
| 931 } | 958 } |
| 932 server_pref_dict->SetWithoutPathExpansion(kSettingsKey, spdy_settings_dict); | 959 server_pref_dict->SetWithoutPathExpansion(kSettingsKey, spdy_settings_dict); |
| 933 } | 960 } |
| 934 | 961 |
| 935 void HttpServerPropertiesManager::SaveAlternativeServiceToServerPrefs( | 962 void HttpServerPropertiesManager::SaveAlternativeServiceToServerPrefs( |
| 936 const AlternativeServiceInfo* alternative_service_info, | 963 const AlternativeServiceInfoVector* alternative_service_info_vector, |
| 937 base::DictionaryValue* server_pref_dict) { | 964 base::DictionaryValue* server_pref_dict) { |
| 938 if (!alternative_service_info) | 965 if (!alternative_service_info_vector || |
| 966 alternative_service_info_vector->empty()) { |
| 939 return; | 967 return; |
| 940 | |
| 941 const AlternativeService& alternative_service = | |
| 942 alternative_service_info->alternative_service; | |
| 943 base::DictionaryValue* alternative_service_info_dict = | |
| 944 new base::DictionaryValue; | |
| 945 alternative_service_info_dict->SetString( | |
| 946 kProtocolKey, AlternateProtocolToString(alternative_service.protocol)); | |
| 947 if (!alternative_service.host.empty()) { | |
| 948 alternative_service_info_dict->SetString(kHostKey, | |
| 949 alternative_service.host); | |
| 950 } | 968 } |
| 951 alternative_service_info_dict->SetInteger(kPortKey, alternative_service.port); | 969 scoped_ptr<base::ListValue> alternative_service_list(new base::ListValue); |
| 952 alternative_service_info_dict->SetDouble( | 970 for (const AlternativeServiceInfo& alternative_service_info : |
| 953 kProbabilityKey, alternative_service_info->probability); | 971 *alternative_service_info_vector) { |
| 954 | 972 const AlternativeService alternative_service = |
| 955 // Create a single element list here. | 973 alternative_service_info.alternative_service; |
| 956 // TODO(bnc): Once we store multiple AlternativeServiceInfo per server, save | 974 DCHECK(IsAlternateProtocolValid(alternative_service.protocol)); |
| 957 // all of them. | 975 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue; |
| 958 base::ListValue* alternative_service_list = new base::ListValue(); | 976 alternative_service_dict->SetInteger(kPortKey, alternative_service.port); |
| 959 alternative_service_list->Append(alternative_service_info_dict); | 977 if (!alternative_service.host.empty()) { |
| 978 alternative_service_dict->SetString(kHostKey, alternative_service.host); |
| 979 } |
| 980 alternative_service_dict->SetString( |
| 981 kProtocolKey, AlternateProtocolToString(alternative_service.protocol)); |
| 982 alternative_service_dict->SetDouble(kProbabilityKey, |
| 983 alternative_service_info.probability); |
| 984 alternative_service_list->Append(alternative_service_dict); |
| 985 } |
| 986 if (alternative_service_list->GetSize() == 0) |
| 987 return; |
| 960 server_pref_dict->SetWithoutPathExpansion(kAlternativeServiceKey, | 988 server_pref_dict->SetWithoutPathExpansion(kAlternativeServiceKey, |
| 961 alternative_service_list); | 989 alternative_service_list.release()); |
| 962 } | 990 } |
| 963 | 991 |
| 964 void HttpServerPropertiesManager::SaveSupportsQuicToPrefs( | 992 void HttpServerPropertiesManager::SaveSupportsQuicToPrefs( |
| 965 const IPAddressNumber* last_quic_address, | 993 const IPAddressNumber* last_quic_address, |
| 966 base::DictionaryValue* http_server_properties_dict) { | 994 base::DictionaryValue* http_server_properties_dict) { |
| 967 if (!last_quic_address || last_quic_address->empty()) | 995 if (!last_quic_address || last_quic_address->empty()) |
| 968 return; | 996 return; |
| 969 | 997 |
| 970 base::DictionaryValue* supports_quic_dict = new base::DictionaryValue; | 998 base::DictionaryValue* supports_quic_dict = new base::DictionaryValue; |
| 971 supports_quic_dict->SetBoolean(kUsedQuicKey, true); | 999 supports_quic_dict->SetBoolean(kUsedQuicKey, true); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 991 server_network_stats_dict); | 1019 server_network_stats_dict); |
| 992 } | 1020 } |
| 993 | 1021 |
| 994 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { | 1022 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { |
| 995 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); | 1023 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); |
| 996 if (!setting_prefs_) | 1024 if (!setting_prefs_) |
| 997 ScheduleUpdateCacheOnPrefThread(); | 1025 ScheduleUpdateCacheOnPrefThread(); |
| 998 } | 1026 } |
| 999 | 1027 |
| 1000 } // namespace net | 1028 } // namespace net |
| OLD | NEW |