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

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

Issue 2949513005: Update param types of HttpServerPropertiesImpl setters and getters. Fix MRU order when loading (Closed)
Patch Set: Fixed minor typos Created 3 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 <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 501 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 if (!AddToQuicServerInfoMap(http_server_properties_dict, 512 if (!AddToQuicServerInfoMap(http_server_properties_dict,
513 quic_server_info_map.get())) { 513 quic_server_info_map.get())) {
514 detected_corrupted_prefs = true; 514 detected_corrupted_prefs = true;
515 } 515 }
516 516
517 network_task_runner_->PostTask( 517 network_task_runner_->PostTask(
518 FROM_HERE, 518 FROM_HERE,
519 base::Bind( 519 base::Bind(
520 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkSequence, 520 &HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkSequence,
521 base::Unretained(this), base::Owned(spdy_servers.release()), 521 base::Unretained(this), base::Owned(spdy_servers.release()),
522 base::Owned(alternative_service_map.release()), base::Owned(addr), 522 base::Passed(&alternative_service_map), base::Owned(addr),
523 base::Owned(server_network_stats_map.release()), 523 base::Passed(&server_network_stats_map),
524 base::Owned(quic_server_info_map.release()), 524 base::Passed(&quic_server_info_map), detected_corrupted_prefs));
525 detected_corrupted_prefs));
526 } 525 }
527 526
528 bool HttpServerPropertiesManager::AddServersData( 527 bool HttpServerPropertiesManager::AddServersData(
529 const base::DictionaryValue& servers_dict, 528 const base::DictionaryValue& servers_dict,
530 ServerList* spdy_servers, 529 ServerList* spdy_servers,
531 AlternativeServiceMap* alternative_service_map, 530 AlternativeServiceMap* alternative_service_map,
532 ServerNetworkStatsMap* network_stats_map, 531 ServerNetworkStatsMap* network_stats_map,
533 int version) { 532 int version) {
534 for (base::DictionaryValue::Iterator it(servers_dict); !it.IsAtEnd(); 533 for (base::DictionaryValue::Iterator it(servers_dict); !it.IsAtEnd();
535 it.Advance()) { 534 it.Advance()) {
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 << quic_server_id_str; 767 << quic_server_id_str;
769 detected_corrupted_prefs = true; 768 detected_corrupted_prefs = true;
770 continue; 769 continue;
771 } 770 }
772 quic_server_info_map->Put(quic_server_id, quic_server_info); 771 quic_server_info_map->Put(quic_server_id, quic_server_info);
773 } 772 }
774 return !detected_corrupted_prefs; 773 return !detected_corrupted_prefs;
775 } 774 }
776 775
777 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkSequence( 776 void HttpServerPropertiesManager::UpdateCacheFromPrefsOnNetworkSequence(
778 ServerList* spdy_servers, 777 const ServerList* spdy_servers,
779 AlternativeServiceMap* alternative_service_map, 778 std::unique_ptr<AlternativeServiceMap> alternative_service_map,
780 IPAddress* last_quic_address, 779 const IPAddress* last_quic_address,
781 ServerNetworkStatsMap* server_network_stats_map, 780 std::unique_ptr<ServerNetworkStatsMap> server_network_stats_map,
782 QuicServerInfoMap* quic_server_info_map, 781 std::unique_ptr<QuicServerInfoMap> quic_server_info_map,
783 bool detected_corrupted_prefs) { 782 bool detected_corrupted_prefs) {
784 // Preferences have the master data because admins might have pushed new 783 // Preferences have the master data because admins might have pushed new
785 // preferences. Update the cached data with new data from preferences. 784 // preferences. Update the cached data with new data from preferences.
786 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); 785 DCHECK(network_task_runner_->RunsTasksInCurrentSequence());
787 786
788 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size()); 787 UMA_HISTOGRAM_COUNTS("Net.CountOfSpdyServers", spdy_servers->size());
789 http_server_properties_impl_->SetSpdyServers(spdy_servers, true); 788 http_server_properties_impl_->SetSpdyServers(spdy_servers, true);
790 789
791 // Update the cached data and use the new alternative service list from 790 // Update the cached data and use the new alternative service list from
792 // preferences. 791 // preferences.
793 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers", 792 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers",
794 alternative_service_map->size()); 793 alternative_service_map->size());
795 http_server_properties_impl_->SetAlternativeServiceServers( 794 http_server_properties_impl_->SetAlternativeServiceServers(
796 alternative_service_map); 795 std::move(alternative_service_map));
797 796
798 http_server_properties_impl_->SetSupportsQuic(last_quic_address); 797 http_server_properties_impl_->SetSupportsQuic(last_quic_address);
799 798
800 http_server_properties_impl_->SetServerNetworkStats(server_network_stats_map); 799 http_server_properties_impl_->SetServerNetworkStats(
800 std::move(server_network_stats_map));
801 801
802 UMA_HISTOGRAM_COUNTS_1000("Net.CountOfQuicServerInfos", 802 UMA_HISTOGRAM_COUNTS_1000("Net.CountOfQuicServerInfos",
803 quic_server_info_map->size()); 803 quic_server_info_map->size());
804 804
805 http_server_properties_impl_->SetQuicServerInfoMap(quic_server_info_map); 805 http_server_properties_impl_->SetQuicServerInfoMap(
806 std::move(quic_server_info_map));
806 807
807 // Update the prefs with what we have read (delete all corrupted prefs). 808 // Update the prefs with what we have read (delete all corrupted prefs).
808 if (detected_corrupted_prefs) 809 if (detected_corrupted_prefs)
809 ScheduleUpdatePrefsOnNetworkSequence(DETECTED_CORRUPTED_PREFS); 810 ScheduleUpdatePrefsOnNetworkSequence(DETECTED_CORRUPTED_PREFS);
810 } 811 }
811 812
812 // 813 //
813 // Update Preferences with data from the cached data. 814 // Update Preferences with data from the cached data.
814 // 815 //
815 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnNetworkSequence( 816 void HttpServerPropertiesManager::ScheduleUpdatePrefsOnNetworkSequence(
(...skipping 15 matching lines...) Expand all
831 // This is required so we can set this as the callback for a timer. 832 // This is required so we can set this as the callback for a timer.
832 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkSequence() { 833 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkSequence() {
833 UpdatePrefsFromCacheOnNetworkSequence(base::Closure()); 834 UpdatePrefsFromCacheOnNetworkSequence(base::Closure());
834 } 835 }
835 836
836 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkSequence( 837 void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkSequence(
837 const base::Closure& completion) { 838 const base::Closure& completion) {
838 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); 839 DCHECK(network_task_runner_->RunsTasksInCurrentSequence());
839 840
840 // It is in MRU order. 841 // It is in MRU order.
841 base::ListValue* spdy_server_list = new base::ListValue; 842 std::unique_ptr<ServerList> spdy_servers = base::MakeUnique<ServerList>();
842 http_server_properties_impl_->GetSpdyServerList( 843 http_server_properties_impl_->GetSpdyServers(
843 spdy_server_list, kMaxSupportsSpdyServerHostsToPersist); 844 spdy_servers.get(), kMaxSupportsSpdyServerHostsToPersist);
Ryan Hamilton 2017/06/20 18:25:56 it's a bit odd that GetSpdyServers takes a vector<
wangyix1 2017/06/21 18:45:33 Done.
844 845
845 AlternativeServiceMap* alternative_service_map = 846 AlternativeServiceMap* alternative_service_map =
846 new AlternativeServiceMap(kMaxAlternateProtocolHostsToPersist); 847 new AlternativeServiceMap(kMaxAlternateProtocolHostsToPersist);
847 const AlternativeServiceMap& map = 848 const AlternativeServiceMap& map =
848 http_server_properties_impl_->alternative_service_map(); 849 http_server_properties_impl_->alternative_service_map();
849 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers.Memory", 850 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers.Memory",
850 map.size()); 851 map.size());
851 int count = 0; 852 int count = 0;
852 typedef std::map<std::string, bool> CanonicalHostPersistedMap; 853 typedef std::map<std::string, bool> CanonicalHostPersistedMap;
853 CanonicalHostPersistedMap persisted_map; 854 CanonicalHostPersistedMap persisted_map;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
915 } 916 }
916 } 917 }
917 918
918 IPAddress* last_quic_addr = new IPAddress; 919 IPAddress* last_quic_addr = new IPAddress;
919 http_server_properties_impl_->GetSupportsQuic(last_quic_addr); 920 http_server_properties_impl_->GetSupportsQuic(last_quic_addr);
920 // Update the preferences on the pref thread. 921 // Update the preferences on the pref thread.
921 pref_task_runner_->PostTask( 922 pref_task_runner_->PostTask(
922 FROM_HERE, 923 FROM_HERE,
923 base::Bind( 924 base::Bind(
924 &HttpServerPropertiesManager::UpdatePrefsOnPrefThread, pref_weak_ptr_, 925 &HttpServerPropertiesManager::UpdatePrefsOnPrefThread, pref_weak_ptr_,
925 base::Owned(spdy_server_list), base::Owned(alternative_service_map), 926 base::Passed(&spdy_servers), base::Owned(alternative_service_map),
926 base::Owned(last_quic_addr), base::Owned(server_network_stats_map), 927 base::Owned(last_quic_addr), base::Owned(server_network_stats_map),
927 base::Owned(quic_server_info_map), completion)); 928 base::Owned(quic_server_info_map), completion));
928 } 929 }
929 930
930 // A local or temporary data structure to hold |supports_spdy|, SpdySettings, 931 // A local or temporary data structure to hold |supports_spdy|, SpdySettings,
931 // AlternativeServiceInfoVector, and SupportsQuic preferences for a server. This 932 // AlternativeServiceInfoVector, and SupportsQuic preferences for a server. This
932 // is used only in UpdatePrefsOnPrefThread. 933 // is used only in UpdatePrefsOnPrefThread.
933 struct ServerPref { 934 struct ServerPref {
934 ServerPref() 935 ServerPref()
935 : supports_spdy(false), 936 : supports_spdy(false),
(...skipping 14 matching lines...) Expand all
950 server_network_stats(server_network_stats) {} 951 server_network_stats(server_network_stats) {}
951 bool supports_spdy; 952 bool supports_spdy;
952 const SettingsMap* settings_map; 953 const SettingsMap* settings_map;
953 const AlternativeServiceInfoVector* alternative_service_info_vector; 954 const AlternativeServiceInfoVector* alternative_service_info_vector;
954 const SupportsQuic* supports_quic; 955 const SupportsQuic* supports_quic;
955 const ServerNetworkStats* server_network_stats; 956 const ServerNetworkStats* server_network_stats;
956 }; 957 };
957 958
958 // All maps and lists are in MRU order. 959 // All maps and lists are in MRU order.
959 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread( 960 void HttpServerPropertiesManager::UpdatePrefsOnPrefThread(
960 base::ListValue* spdy_server_list, 961 std::unique_ptr<ServerList> spdy_servers,
961 AlternativeServiceMap* alternative_service_map, 962 AlternativeServiceMap* alternative_service_map,
962 IPAddress* last_quic_address, 963 IPAddress* last_quic_address,
963 ServerNetworkStatsMap* server_network_stats_map, 964 ServerNetworkStatsMap* server_network_stats_map,
964 QuicServerInfoMap* quic_server_info_map, 965 QuicServerInfoMap* quic_server_info_map,
965 const base::Closure& completion) { 966 const base::Closure& completion) {
966 typedef base::MRUCache<url::SchemeHostPort, ServerPref> ServerPrefMap; 967 typedef base::MRUCache<url::SchemeHostPort, ServerPref> ServerPrefMap;
967 ServerPrefMap server_pref_map(ServerPrefMap::NO_AUTO_EVICT); 968 ServerPrefMap server_pref_map(ServerPrefMap::NO_AUTO_EVICT);
968 969
969 DCHECK(pref_task_runner_->RunsTasksInCurrentSequence()); 970 DCHECK(pref_task_runner_->RunsTasksInCurrentSequence());
970 971
971 // Add servers that support spdy to server_pref_map in the MRU order. 972 // Add servers that support spdy to server_pref_map in the MRU order.
972 for (size_t index = spdy_server_list->GetSize(); index > 0; --index) { 973 for (size_t i = spdy_servers->size(); i > 0; --i) {
973 std::string server_str; 974 url::SchemeHostPort server((GURL(spdy_servers->at(i - 1))));
974 if (spdy_server_list->GetString(index - 1, &server_str)) { 975 ServerPrefMap::iterator it = server_pref_map.Get(server);
975 url::SchemeHostPort server((GURL(server_str))); 976 if (it == server_pref_map.end()) {
976 ServerPrefMap::iterator it = server_pref_map.Get(server); 977 ServerPref server_pref;
977 if (it == server_pref_map.end()) { 978 server_pref.supports_spdy = true;
978 ServerPref server_pref; 979 server_pref_map.Put(server, server_pref);
979 server_pref.supports_spdy = true; 980 } else {
980 server_pref_map.Put(server, server_pref); 981 it->second.supports_spdy = true;
981 } else {
982 it->second.supports_spdy = true;
983 }
984 } 982 }
985 } 983 }
986 984
987 // Add alternative services to server_pref_map in the MRU order. 985 // Add alternative services to server_pref_map in the MRU order.
988 for (AlternativeServiceMap::const_reverse_iterator map_it = 986 for (AlternativeServiceMap::const_reverse_iterator map_it =
989 alternative_service_map->rbegin(); 987 alternative_service_map->rbegin();
990 map_it != alternative_service_map->rend(); ++map_it) { 988 map_it != alternative_service_map->rend(); ++map_it) {
991 const url::SchemeHostPort server = map_it->first; 989 const url::SchemeHostPort server = map_it->first;
992 ServerPrefMap::iterator it = server_pref_map.Get(server); 990 ServerPrefMap::iterator it = server_pref_map.Get(server);
993 if (it == server_pref_map.end()) { 991 if (it == server_pref_map.end()) {
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1149 if (!setting_prefs_) 1147 if (!setting_prefs_)
1150 ScheduleUpdateCacheOnPrefThread(); 1148 ScheduleUpdateCacheOnPrefThread();
1151 } 1149 }
1152 1150
1153 void HttpServerPropertiesManager::SetInitialized() { 1151 void HttpServerPropertiesManager::SetInitialized() {
1154 DCHECK(network_task_runner_->RunsTasksInCurrentSequence()); 1152 DCHECK(network_task_runner_->RunsTasksInCurrentSequence());
1155 is_initialized_ = true; 1153 is_initialized_ = true;
1156 } 1154 }
1157 1155
1158 } // namespace net 1156 } // namespace net
OLDNEW
« net/http/http_server_properties_manager.h ('K') | « net/http/http_server_properties_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698