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

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

Issue 1216703002: Implement multiple alternative services per origin. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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_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
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 void HttpServerPropertiesManager::AddAlternativeService(
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 http_server_properties_impl_->AddAlternativeService(
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 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICE);
208 // If |alternative_probability| was above the threashold now it is below or
209 // vice versa, then a different alternative_service will be returned from the
210 // old and if so, then persist.
211 if (old_alternative_service != new_alternative_service)
212 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICE);
Ryan Hamilton 2015/06/29 21:15:52 You seem to have removed the conditional here of n
Bence 2015/06/30 19:16:14 I think SetAlternativeServices is a good idea. It
Ryan Hamilton 2015/07/06 17:48:09 I'm not sure that I understand. If the output of G
Bence 2015/07/07 09:55:55 There might be situations when the output of GetAl
213 } 207 }
214 208
215 void HttpServerPropertiesManager::MarkAlternativeServiceBroken( 209 void HttpServerPropertiesManager::MarkAlternativeServiceBroken(
216 const AlternativeService& alternative_service) { 210 const AlternativeService& alternative_service) {
217 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 211 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
218 http_server_properties_impl_->MarkAlternativeServiceBroken( 212 http_server_properties_impl_->MarkAlternativeServiceBroken(
219 alternative_service); 213 alternative_service);
220 ScheduleUpdatePrefsOnNetworkThread(MARK_ALTERNATIVE_SERVICE_BROKEN); 214 ScheduleUpdatePrefsOnNetworkThread(MARK_ALTERNATIVE_SERVICE_BROKEN);
221 } 215 }
222 216
(...skipping 26 matching lines...) Expand all
249 alternative_service); 243 alternative_service);
250 http_server_properties_impl_->ConfirmAlternativeService(alternative_service); 244 http_server_properties_impl_->ConfirmAlternativeService(alternative_service);
251 bool new_value = http_server_properties_impl_->IsAlternativeServiceBroken( 245 bool new_value = http_server_properties_impl_->IsAlternativeServiceBroken(
252 alternative_service); 246 alternative_service);
253 // For persisting, we only care about the value returned by 247 // For persisting, we only care about the value returned by
254 // IsAlternativeServiceBroken. If that value changes, then call persist. 248 // IsAlternativeServiceBroken. If that value changes, then call persist.
255 if (old_value != new_value) 249 if (old_value != new_value)
256 ScheduleUpdatePrefsOnNetworkThread(CONFIRM_ALTERNATIVE_SERVICE); 250 ScheduleUpdatePrefsOnNetworkThread(CONFIRM_ALTERNATIVE_SERVICE);
257 } 251 }
258 252
259 void HttpServerPropertiesManager::ClearAlternativeService( 253 void HttpServerPropertiesManager::ClearAlternativeServices(
260 const HostPortPair& origin) { 254 const HostPortPair& origin) {
261 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 255 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
262 const AlternativeServiceMap& map = 256 const AlternativeServiceMap& map =
263 http_server_properties_impl_->alternative_service_map(); 257 http_server_properties_impl_->alternative_service_map();
264 size_t old_size = map.size(); 258 size_t old_size = map.size();
265 http_server_properties_impl_->ClearAlternativeService(origin); 259 http_server_properties_impl_->ClearAlternativeServices(origin);
266 size_t new_size = map.size(); 260 size_t new_size = map.size();
267 // Persist only if we have deleted an entry. 261 // Persist only if we have deleted an entry.
268 if (old_size != new_size) 262 if (old_size != new_size)
269 ScheduleUpdatePrefsOnNetworkThread(CLEAR_ALTERNATIVE_SERVICE); 263 ScheduleUpdatePrefsOnNetworkThread(CLEAR_ALTERNATIVE_SERVICE);
270 } 264 }
271 265
272 const AlternativeServiceMap& 266 const AlternativeServiceMap&
273 HttpServerPropertiesManager::alternative_service_map() const { 267 HttpServerPropertiesManager::alternative_service_map() const {
274 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 268 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
275 return http_server_properties_impl_->alternative_service_map(); 269 return http_server_properties_impl_->alternative_service_map();
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
566 560
567 bool HttpServerPropertiesManager::AddToAlternativeServiceMap( 561 bool HttpServerPropertiesManager::AddToAlternativeServiceMap(
568 const HostPortPair& server, 562 const HostPortPair& server,
569 const base::DictionaryValue& server_pref_dict, 563 const base::DictionaryValue& server_pref_dict,
570 AlternativeServiceMap* alternative_service_map) { 564 AlternativeServiceMap* alternative_service_map) {
571 DCHECK(alternative_service_map->Peek(server) == 565 DCHECK(alternative_service_map->Peek(server) ==
572 alternative_service_map->end()); 566 alternative_service_map->end());
573 // Get alternative_services... 567 // Get alternative_services...
574 const base::ListValue* alternative_service_list; 568 const base::ListValue* alternative_service_list;
575 const base::DictionaryValue* alternative_service_dict; 569 const base::DictionaryValue* alternative_service_dict;
576 AlternativeServiceInfo alternative_service_info; 570 AlternativeServiceInfoVector alternative_service_info_vector;
577 if (server_pref_dict.GetListWithoutPathExpansion(kAlternativeServiceKey, 571 if (server_pref_dict.GetListWithoutPathExpansion(kAlternativeServiceKey,
578 &alternative_service_list)) { 572 &alternative_service_list)) {
579 if (alternative_service_list->empty()) { 573 for (const base::Value* alternative_service_list_item :
580 return false; 574 *alternative_service_list) {
575 if (!alternative_service_list_item->GetAsDictionary(
576 &alternative_service_dict))
577 return false;
578 AlternativeServiceInfo alternative_service_info =
579 ParseAlternativeServiceDict(*alternative_service_dict,
580 server.ToString());
581 if (alternative_service_info.alternative_service.protocol ==
582 UNINITIALIZED_ALTERNATE_PROTOCOL) {
583 return false;
584 }
585 alternative_service_info_vector.push_back(alternative_service_info);
581 } 586 }
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 { 587 } else {
592 // ...or alternate_protocol. 588 // ...or alternate_protocol.
593 // TODO(bnc): Remove this in M46, we do not need preference migration for 589 // TODO(bnc): Remove this in M46, we do not need preference migration for
594 // long. 590 // long.
595 if (!server_pref_dict.GetDictionaryWithoutPathExpansion( 591 if (!server_pref_dict.GetDictionaryWithoutPathExpansion(
596 kAlternateProtocolKey, &alternative_service_dict)) { 592 kAlternateProtocolKey, &alternative_service_dict)) {
597 return true; 593 return true;
598 } 594 }
599 alternative_service_info = ParseAlternativeServiceDict( 595 AlternativeServiceInfo alternative_service_info =
600 *alternative_service_dict, server.ToString()); 596 ParseAlternativeServiceDict(*alternative_service_dict,
597 server.ToString());
598 if (alternative_service_info.alternative_service.protocol ==
599 UNINITIALIZED_ALTERNATE_PROTOCOL) {
600 return false;
601 }
602 alternative_service_info_vector.push_back(alternative_service_info);
601 } 603 }
602 604
603 if (alternative_service_info.alternative_service.protocol == 605 if (alternative_service_info_vector.empty()) {
604 UNINITIALIZED_ALTERNATE_PROTOCOL) {
605 return false; 606 return false;
606 } 607 }
607 alternative_service_map->Put(server, alternative_service_info); 608
609 alternative_service_map->Put(server, alternative_service_info_vector);
608 return true; 610 return true;
609 } 611 }
610 612
611 bool HttpServerPropertiesManager::ReadSupportsQuic( 613 bool HttpServerPropertiesManager::ReadSupportsQuic(
612 const base::DictionaryValue& http_server_properties_dict, 614 const base::DictionaryValue& http_server_properties_dict,
613 IPAddressNumber* last_quic_address) { 615 IPAddressNumber* last_quic_address) {
614 const base::DictionaryValue* supports_quic_dict = NULL; 616 const base::DictionaryValue* supports_quic_dict = NULL;
615 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion( 617 if (!http_server_properties_dict.GetDictionaryWithoutPathExpansion(
616 kSupportsQuicKey, &supports_quic_dict)) { 618 kSupportsQuicKey, &supports_quic_dict)) {
617 return true; 619 return true;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 674 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
673 675
674 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size()); 676 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size());
675 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true); 677 http_server_properties_impl_->InitializeSpdyServers(spdy_servers, true);
676 678
677 // Update the cached data and use the new spdy_settings from preferences. 679 // Update the cached data and use the new spdy_settings from preferences.
678 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size()); 680 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdySettings", spdy_settings_map->size());
679 http_server_properties_impl_->InitializeSpdySettingsServers( 681 http_server_properties_impl_->InitializeSpdySettingsServers(
680 spdy_settings_map); 682 spdy_settings_map);
681 683
682 // Update the cached data and use the new Alternate-Protocol server list from 684 // Update the cached data and use the new alternative service list from
683 // preferences. 685 // preferences.
684 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers", 686 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers",
685 alternative_service_map->size()); 687 alternative_service_map->size());
686 http_server_properties_impl_->InitializeAlternativeServiceServers( 688 http_server_properties_impl_->InitializeAlternativeServiceServers(
687 alternative_service_map); 689 alternative_service_map);
688 690
689 http_server_properties_impl_->InitializeSupportsQuic(last_quic_address); 691 http_server_properties_impl_->InitializeSupportsQuic(last_quic_address);
690 692
691 http_server_properties_impl_->InitializeServerNetworkStats( 693 http_server_properties_impl_->InitializeServerNetworkStats(
692 server_network_stats_map); 694 server_network_stats_map);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
748 750
749 AlternativeServiceMap* alternative_service_map = 751 AlternativeServiceMap* alternative_service_map =
750 new AlternativeServiceMap(kMaxAlternateProtocolHostsToPersist); 752 new AlternativeServiceMap(kMaxAlternateProtocolHostsToPersist);
751 const AlternativeServiceMap& map = 753 const AlternativeServiceMap& map =
752 http_server_properties_impl_->alternative_service_map(); 754 http_server_properties_impl_->alternative_service_map();
753 count = 0; 755 count = 0;
754 typedef std::map<std::string, bool> CanonicalHostPersistedMap; 756 typedef std::map<std::string, bool> CanonicalHostPersistedMap;
755 CanonicalHostPersistedMap persisted_map; 757 CanonicalHostPersistedMap persisted_map;
756 for (AlternativeServiceMap::const_iterator it = map.begin(); 758 for (AlternativeServiceMap::const_iterator it = map.begin();
757 it != map.end() && count < kMaxAlternateProtocolHostsToPersist; ++it) { 759 it != map.end() && count < kMaxAlternateProtocolHostsToPersist; ++it) {
758 const AlternativeServiceInfo& alternative_service_info = it->second; 760 const HostPortPair& server = it->first;
759 if (!IsAlternateProtocolValid( 761 AlternativeServiceInfoVector notbroken_alternative_service_info_vector;
760 alternative_service_info.alternative_service.protocol)) { 762 for (const AlternativeServiceInfo& alternative_service_info : it->second) {
763 if (!IsAlternateProtocolValid(
764 alternative_service_info.alternative_service.protocol)) {
765 continue;
766 }
767 AlternativeService alternative_service(
768 alternative_service_info.alternative_service);
769 if (alternative_service.host.empty()) {
770 alternative_service.host = server.host();
771 }
772 if (IsAlternativeServiceBroken(alternative_service)) {
773 continue;
774 }
775 notbroken_alternative_service_info_vector.push_back(
776 alternative_service_info);
777 }
778 if (notbroken_alternative_service_info_vector.empty()) {
761 continue; 779 continue;
762 } 780 }
763 const HostPortPair& server = it->first; 781 alternative_service_map->Put(server,
764 AlternativeService alternative_service( 782 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 = 783 std::string canonical_suffix =
773 http_server_properties_impl_->GetCanonicalSuffix(server.host()); 784 http_server_properties_impl_->GetCanonicalSuffix(server.host());
774 if (!canonical_suffix.empty()) { 785 if (!canonical_suffix.empty()) {
775 if (persisted_map.find(canonical_suffix) != persisted_map.end()) 786 if (persisted_map.find(canonical_suffix) != persisted_map.end())
776 continue; 787 continue;
777 persisted_map[canonical_suffix] = true; 788 persisted_map[canonical_suffix] = true;
778 } 789 }
779 alternative_service_map->Put(server, alternative_service_info);
780 ++count; 790 ++count;
781 } 791 }
782 792
783 ServerNetworkStatsMap* server_network_stats_map = 793 ServerNetworkStatsMap* server_network_stats_map =
784 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist); 794 new ServerNetworkStatsMap(kMaxServerNetworkStatsHostsToPersist);
785 const ServerNetworkStatsMap& main_server_network_stats_map = 795 const ServerNetworkStatsMap& main_server_network_stats_map =
786 http_server_properties_impl_->server_network_stats_map(); 796 http_server_properties_impl_->server_network_stats_map();
787 for (ServerNetworkStatsMap::const_iterator it = 797 for (ServerNetworkStatsMap::const_iterator it =
788 main_server_network_stats_map.begin(); 798 main_server_network_stats_map.begin();
789 it != main_server_network_stats_map.end(); ++it) { 799 it != main_server_network_stats_map.end(); ++it) {
790 server_network_stats_map->Put(it->first, it->second); 800 server_network_stats_map->Put(it->first, it->second);
791 } 801 }
792 802
793 IPAddressNumber* last_quic_addr = new IPAddressNumber; 803 IPAddressNumber* last_quic_addr = new IPAddressNumber;
794 http_server_properties_impl_->GetSupportsQuic(last_quic_addr); 804 http_server_properties_impl_->GetSupportsQuic(last_quic_addr);
795 // Update the preferences on the pref thread. 805 // Update the preferences on the pref thread.
796 pref_task_runner_->PostTask( 806 pref_task_runner_->PostTask(
797 FROM_HERE, 807 FROM_HERE,
798 base::Bind( 808 base::Bind(
799 &HttpServerPropertiesManager::UpdatePrefsOnPrefThread, pref_weak_ptr_, 809 &HttpServerPropertiesManager::UpdatePrefsOnPrefThread, pref_weak_ptr_,
800 base::Owned(spdy_server_list), base::Owned(spdy_settings_map), 810 base::Owned(spdy_server_list), base::Owned(spdy_settings_map),
801 base::Owned(alternative_service_map), base::Owned(last_quic_addr), 811 base::Owned(alternative_service_map), base::Owned(last_quic_addr),
802 base::Owned(server_network_stats_map), completion)); 812 base::Owned(server_network_stats_map), completion));
803 } 813 }
804 814
805 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, 815 // A local or temporary data structure to hold |supports_spdy|, SpdySettings,
806 // AlternativeServiceInfo and SupportsQuic preferences for a server. This is 816 // AlternativeServiceInfoVector, and SupportsQuic preferences for a server. This
807 // used only in UpdatePrefsOnPrefThread. 817 // is used only in UpdatePrefsOnPrefThread.
808 struct ServerPref { 818 struct ServerPref {
809 ServerPref() 819 ServerPref()
810 : supports_spdy(false), 820 : supports_spdy(false),
811 settings_map(NULL), 821 settings_map(NULL),
812 alternative_service(NULL), 822 alternative_service_info_vector(NULL),
813 supports_quic(NULL), 823 supports_quic(NULL),
814 server_network_stats(NULL) {} 824 server_network_stats(NULL) {}
815 ServerPref(bool supports_spdy, 825 ServerPref(
816 const SettingsMap* settings_map, 826 bool supports_spdy,
817 const AlternativeServiceInfo* alternative_service, 827 const SettingsMap* settings_map,
818 const SupportsQuic* supports_quic, 828 const AlternativeServiceInfoVector* alternative_service_info_vector,
819 const ServerNetworkStats* server_network_stats) 829 const SupportsQuic* supports_quic,
830 const ServerNetworkStats* server_network_stats)
820 : supports_spdy(supports_spdy), 831 : supports_spdy(supports_spdy),
821 settings_map(settings_map), 832 settings_map(settings_map),
822 alternative_service(alternative_service), 833 alternative_service_info_vector(alternative_service_info_vector),
823 supports_quic(supports_quic), 834 supports_quic(supports_quic),
824 server_network_stats(server_network_stats) {} 835 server_network_stats(server_network_stats) {}
825 bool supports_spdy; 836 bool supports_spdy;
826 const SettingsMap* settings_map; 837 const SettingsMap* settings_map;
827 const AlternativeServiceInfo* alternative_service; 838 const AlternativeServiceInfoVector* alternative_service_info_vector;
828 const SupportsQuic* supports_quic; 839 const SupportsQuic* supports_quic;
829 const ServerNetworkStats* server_network_stats; 840 const ServerNetworkStats* server_network_stats;
830 }; 841 };
831 842
832 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( 843 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread(
833 base::ListValue* spdy_server_list, 844 base::ListValue* spdy_server_list,
834 SpdySettingsMap* spdy_settings_map, 845 SpdySettingsMap* spdy_settings_map,
835 AlternativeServiceMap* alternative_service_map, 846 AlternativeServiceMap* alternative_service_map,
836 IPAddressNumber* last_quic_address, 847 IPAddressNumber* last_quic_address,
837 ServerNetworkStatsMap* server_network_stats_map, 848 ServerNetworkStatsMap* server_network_stats_map,
(...skipping 14 matching lines...) Expand all
852 } 863 }
853 } 864 }
854 865
855 // Add servers that have SpdySettings to server_pref_map. 866 // Add servers that have SpdySettings to server_pref_map.
856 for (SpdySettingsMap::iterator map_it = spdy_settings_map->begin(); 867 for (SpdySettingsMap::iterator map_it = spdy_settings_map->begin();
857 map_it != spdy_settings_map->end(); ++map_it) { 868 map_it != spdy_settings_map->end(); ++map_it) {
858 const HostPortPair& server = map_it->first; 869 const HostPortPair& server = map_it->first;
859 server_pref_map[server].settings_map = &map_it->second; 870 server_pref_map[server].settings_map = &map_it->second;
860 } 871 }
861 872
862 // Add AlternateProtocol servers to server_pref_map. 873 // Add alternative services to server_pref_map.
863 for (AlternativeServiceMap::const_iterator map_it = 874 for (AlternativeServiceMap::const_iterator map_it =
864 alternative_service_map->begin(); 875 alternative_service_map->begin();
865 map_it != alternative_service_map->end(); ++map_it) { 876 map_it != alternative_service_map->end(); ++map_it) {
866 server_pref_map[map_it->first].alternative_service = &map_it->second; 877 server_pref_map[map_it->first].alternative_service_info_vector =
878 &map_it->second;
867 } 879 }
868 880
869 // Add ServerNetworkStats servers to server_pref_map. 881 // Add ServerNetworkStats servers to server_pref_map.
870 for (ServerNetworkStatsMap::const_iterator map_it = 882 for (ServerNetworkStatsMap::const_iterator map_it =
871 server_network_stats_map->begin(); 883 server_network_stats_map->begin();
872 map_it != server_network_stats_map->end(); ++map_it) { 884 map_it != server_network_stats_map->end(); ++map_it) {
873 const HostPortPair& server = map_it->first; 885 const HostPortPair& server = map_it->first;
874 server_pref_map[server].server_network_stats = &map_it->second; 886 server_pref_map[server].server_network_stats = &map_it->second;
875 } 887 }
876 888
877 // Persist properties to the |path_|. 889 // Persist properties to the |path_|.
878 base::DictionaryValue http_server_properties_dict; 890 base::DictionaryValue http_server_properties_dict;
879 base::DictionaryValue* servers_dict = new base::DictionaryValue; 891 base::DictionaryValue* servers_dict = new base::DictionaryValue;
880 for (ServerPrefMap::const_iterator map_it = server_pref_map.begin(); 892 for (ServerPrefMap::const_iterator map_it = server_pref_map.begin();
881 map_it != server_pref_map.end(); 893 map_it != server_pref_map.end();
882 ++map_it) { 894 ++map_it) {
883 const HostPortPair& server = map_it->first; 895 const HostPortPair& server = map_it->first;
884 const ServerPref& server_pref = map_it->second; 896 const ServerPref& server_pref = map_it->second;
885 897
886 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 898 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
887 899
888 // Save supports_spdy. 900 // Save supports_spdy.
889 if (server_pref.supports_spdy) 901 if (server_pref.supports_spdy)
890 server_pref_dict->SetBoolean(kSupportsSpdyKey, server_pref.supports_spdy); 902 server_pref_dict->SetBoolean(kSupportsSpdyKey, server_pref.supports_spdy);
891 SaveSpdySettingsToServerPrefs(server_pref.settings_map, server_pref_dict); 903 SaveSpdySettingsToServerPrefs(server_pref.settings_map, server_pref_dict);
892 SaveAlternativeServiceToServerPrefs(server_pref.alternative_service, 904 SaveAlternativeServiceToServerPrefs(
893 server_pref_dict); 905 server_pref.alternative_service_info_vector, server_pref_dict);
894 SaveNetworkStatsToServerPrefs(server_pref.server_network_stats, 906 SaveNetworkStatsToServerPrefs(server_pref.server_network_stats,
895 server_pref_dict); 907 server_pref_dict);
896 908
897 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict); 909 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict);
898 } 910 }
899 911
900 http_server_properties_dict.SetWithoutPathExpansion(kServersKey, 912 http_server_properties_dict.SetWithoutPathExpansion(kServersKey,
901 servers_dict); 913 servers_dict);
902 SetVersion(&http_server_properties_dict, kVersionNumber); 914 SetVersion(&http_server_properties_dict, kVersionNumber);
903 915
(...skipping 22 matching lines...) Expand all
926 it != settings_map->end(); ++it) { 938 it != settings_map->end(); ++it) {
927 SpdySettingsIds id = it->first; 939 SpdySettingsIds id = it->first;
928 uint32 value = it->second.second; 940 uint32 value = it->second.second;
929 std::string key = base::StringPrintf("%u", id); 941 std::string key = base::StringPrintf("%u", id);
930 spdy_settings_dict->SetInteger(key, value); 942 spdy_settings_dict->SetInteger(key, value);
931 } 943 }
932 server_pref_dict->SetWithoutPathExpansion(kSettingsKey, spdy_settings_dict); 944 server_pref_dict->SetWithoutPathExpansion(kSettingsKey, spdy_settings_dict);
933 } 945 }
934 946
935 void HttpServerPropertiesManager::SaveAlternativeServiceToServerPrefs( 947 void HttpServerPropertiesManager::SaveAlternativeServiceToServerPrefs(
936 const AlternativeServiceInfo* alternative_service_info, 948 const AlternativeServiceInfoVector* alternative_service_info_vector,
937 base::DictionaryValue* server_pref_dict) { 949 base::DictionaryValue* server_pref_dict) {
938 if (!alternative_service_info) 950 if (!alternative_service_info_vector ||
951 alternative_service_info_vector->empty()) {
939 return; 952 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 } 953 }
951 alternative_service_info_dict->SetInteger(kPortKey, alternative_service.port); 954 scoped_ptr<base::ListValue> alternative_service_list(new base::ListValue);
952 alternative_service_info_dict->SetDouble( 955 for (const AlternativeServiceInfo& alternative_service_info :
953 kProbabilityKey, alternative_service_info->probability); 956 *alternative_service_info_vector) {
954 957 const AlternativeService alternative_service =
955 // Create a single element list here. 958 alternative_service_info.alternative_service;
956 // TODO(bnc): Once we store multiple AlternativeServiceInfo per server, save 959 DCHECK(IsAlternateProtocolValid(alternative_service.protocol));
957 // all of them. 960 base::DictionaryValue* alternative_service_dict = new base::DictionaryValue;
958 base::ListValue* alternative_service_list = new base::ListValue(); 961 alternative_service_dict->SetInteger(kPortKey, alternative_service.port);
959 alternative_service_list->Append(alternative_service_info_dict); 962 if (!alternative_service.host.empty()) {
963 alternative_service_dict->SetString(kHostKey, alternative_service.host);
964 }
965 alternative_service_dict->SetString(
966 kProtocolKey, AlternateProtocolToString(alternative_service.protocol));
967 alternative_service_dict->SetDouble(kProbabilityKey,
968 alternative_service_info.probability);
969 alternative_service_list->Append(alternative_service_dict);
970 }
971 if (alternative_service_list->GetSize() == 0)
972 return;
960 server_pref_dict->SetWithoutPathExpansion(kAlternativeServiceKey, 973 server_pref_dict->SetWithoutPathExpansion(kAlternativeServiceKey,
961 alternative_service_list); 974 alternative_service_list.release());
962 } 975 }
963 976
964 void HttpServerPropertiesManager::SaveSupportsQuicToPrefs( 977 void HttpServerPropertiesManager::SaveSupportsQuicToPrefs(
965 const IPAddressNumber* last_quic_address, 978 const IPAddressNumber* last_quic_address,
966 base::DictionaryValue* http_server_properties_dict) { 979 base::DictionaryValue* http_server_properties_dict) {
967 if (!last_quic_address || last_quic_address->empty()) 980 if (!last_quic_address || last_quic_address->empty())
968 return; 981 return;
969 982
970 base::DictionaryValue* supports_quic_dict = new base::DictionaryValue; 983 base::DictionaryValue* supports_quic_dict = new base::DictionaryValue;
971 supports_quic_dict->SetBoolean(kUsedQuicKey, true); 984 supports_quic_dict->SetBoolean(kUsedQuicKey, true);
(...skipping 19 matching lines...) Expand all
991 server_network_stats_dict); 1004 server_network_stats_dict);
992 } 1005 }
993 1006
994 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { 1007 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() {
995 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); 1008 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread());
996 if (!setting_prefs_) 1009 if (!setting_prefs_)
997 ScheduleUpdateCacheOnPrefThread(); 1010 ScheduleUpdateCacheOnPrefThread();
998 } 1011 }
999 1012
1000 } // namespace net 1013 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698