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

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

Issue 1824903002: Change the AlternativeServiceMap with SchemeOriginPair key. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add unittests Created 4 years, 9 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/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 139 }
140 140
141 void HttpServerPropertiesManager::Clear(const base::Closure& completion) { 141 void HttpServerPropertiesManager::Clear(const base::Closure& completion) {
142 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 142 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
143 143
144 http_server_properties_impl_->Clear(); 144 http_server_properties_impl_->Clear();
145 UpdatePrefsFromCacheOnNetworkThread(completion); 145 UpdatePrefsFromCacheOnNetworkThread(completion);
146 } 146 }
147 147
148 bool HttpServerPropertiesManager::SupportsRequestPriority( 148 bool HttpServerPropertiesManager::SupportsRequestPriority(
149 const HostPortPair& server) { 149 const SchemeOriginPair& server) {
150 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 150 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
151 return http_server_properties_impl_->SupportsRequestPriority(server); 151 return http_server_properties_impl_->SupportsRequestPriority(server);
152 } 152 }
153 153
154 bool HttpServerPropertiesManager::GetSupportsSpdy(const HostPortPair& server) { 154 bool HttpServerPropertiesManager::GetSupportsSpdy(const HostPortPair& server) {
155 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 155 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
156 return http_server_properties_impl_->GetSupportsSpdy(server); 156 return http_server_properties_impl_->GetSupportsSpdy(server);
157 } 157 }
158 158
159 void HttpServerPropertiesManager::SetSupportsSpdy(const HostPortPair& server, 159 void HttpServerPropertiesManager::SetSupportsSpdy(const HostPortPair& server,
(...skipping 20 matching lines...) Expand all
180 ScheduleUpdatePrefsOnNetworkThread(HTTP_11_REQUIRED); 180 ScheduleUpdatePrefsOnNetworkThread(HTTP_11_REQUIRED);
181 } 181 }
182 182
183 void HttpServerPropertiesManager::MaybeForceHTTP11(const HostPortPair& server, 183 void HttpServerPropertiesManager::MaybeForceHTTP11(const HostPortPair& server,
184 SSLConfig* ssl_config) { 184 SSLConfig* ssl_config) {
185 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 185 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
186 http_server_properties_impl_->MaybeForceHTTP11(server, ssl_config); 186 http_server_properties_impl_->MaybeForceHTTP11(server, ssl_config);
187 } 187 }
188 188
189 AlternativeServiceVector HttpServerPropertiesManager::GetAlternativeServices( 189 AlternativeServiceVector HttpServerPropertiesManager::GetAlternativeServices(
190 const HostPortPair& origin) { 190 const SchemeOriginPair& origin) {
191 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 191 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
192 return http_server_properties_impl_->GetAlternativeServices(origin); 192 return http_server_properties_impl_->GetAlternativeServices(origin);
193 } 193 }
194 194
195 bool HttpServerPropertiesManager::SetAlternativeService( 195 bool HttpServerPropertiesManager::SetAlternativeService(
196 const HostPortPair& origin, 196 const SchemeOriginPair& origin,
197 const AlternativeService& alternative_service, 197 const AlternativeService& alternative_service,
198 double alternative_probability, 198 double alternative_probability,
199 base::Time expiration) { 199 base::Time expiration) {
200 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 200 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
201 const bool changed = http_server_properties_impl_->SetAlternativeService( 201 const bool changed = http_server_properties_impl_->SetAlternativeService(
202 origin, alternative_service, alternative_probability, expiration); 202 origin, alternative_service, alternative_probability, expiration);
203 if (changed) { 203 if (changed) {
204 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES); 204 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES);
205 } 205 }
206 return changed; 206 return changed;
207 } 207 }
208 208
209 bool HttpServerPropertiesManager::SetAlternativeServices( 209 bool HttpServerPropertiesManager::SetAlternativeServices(
210 const HostPortPair& origin, 210 const SchemeOriginPair& origin,
211 const AlternativeServiceInfoVector& alternative_service_info_vector) { 211 const AlternativeServiceInfoVector& alternative_service_info_vector) {
212 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 212 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
213 const bool changed = http_server_properties_impl_->SetAlternativeServices( 213 const bool changed = http_server_properties_impl_->SetAlternativeServices(
214 origin, alternative_service_info_vector); 214 origin, alternative_service_info_vector);
215 if (changed) { 215 if (changed) {
216 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES); 216 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES);
217 } 217 }
218 return changed; 218 return changed;
219 } 219 }
220 220
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 http_server_properties_impl_->ConfirmAlternativeService(alternative_service); 256 http_server_properties_impl_->ConfirmAlternativeService(alternative_service);
257 bool new_value = http_server_properties_impl_->IsAlternativeServiceBroken( 257 bool new_value = http_server_properties_impl_->IsAlternativeServiceBroken(
258 alternative_service); 258 alternative_service);
259 // For persisting, we only care about the value returned by 259 // For persisting, we only care about the value returned by
260 // IsAlternativeServiceBroken. If that value changes, then call persist. 260 // IsAlternativeServiceBroken. If that value changes, then call persist.
261 if (old_value != new_value) 261 if (old_value != new_value)
262 ScheduleUpdatePrefsOnNetworkThread(CONFIRM_ALTERNATIVE_SERVICE); 262 ScheduleUpdatePrefsOnNetworkThread(CONFIRM_ALTERNATIVE_SERVICE);
263 } 263 }
264 264
265 void HttpServerPropertiesManager::ClearAlternativeServices( 265 void HttpServerPropertiesManager::ClearAlternativeServices(
266 const HostPortPair& origin) { 266 const SchemeOriginPair& origin) {
267 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 267 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
268 const AlternativeServiceMap& map = 268 const AlternativeServiceMap& map =
269 http_server_properties_impl_->alternative_service_map(); 269 http_server_properties_impl_->alternative_service_map();
270 size_t old_size = map.size(); 270 size_t old_size = map.size();
271 http_server_properties_impl_->ClearAlternativeServices(origin); 271 http_server_properties_impl_->ClearAlternativeServices(origin);
272 size_t new_size = map.size(); 272 size_t new_size = map.size();
273 // Persist only if we have deleted an entry. 273 // Persist only if we have deleted an entry.
274 if (old_size != new_size) 274 if (old_size != new_size)
275 ScheduleUpdatePrefsOnNetworkThread(CLEAR_ALTERNATIVE_SERVICE); 275 ScheduleUpdatePrefsOnNetworkThread(CLEAR_ALTERNATIVE_SERVICE);
276 } 276 }
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
552 const base::DictionaryValue& servers_dict, 552 const base::DictionaryValue& servers_dict,
553 ServerList* spdy_servers, 553 ServerList* spdy_servers,
554 SpdySettingsMap* spdy_settings_map, 554 SpdySettingsMap* spdy_settings_map,
555 AlternativeServiceMap* alternative_service_map, 555 AlternativeServiceMap* alternative_service_map,
556 ServerNetworkStatsMap* network_stats_map) { 556 ServerNetworkStatsMap* network_stats_map) {
557 for (base::DictionaryValue::Iterator it(servers_dict); !it.IsAtEnd(); 557 for (base::DictionaryValue::Iterator it(servers_dict); !it.IsAtEnd();
558 it.Advance()) { 558 it.Advance()) {
559 // Get server's host/pair. 559 // Get server's host/pair.
560 const std::string& server_str = it.key(); 560 const std::string& server_str = it.key();
561 HostPortPair server = HostPortPair::FromString(server_str); 561 HostPortPair server = HostPortPair::FromString(server_str);
562 // TODO(zhongyi): figure out which scheme is using.
563 SchemeOriginPair scheme_origin_pair("https", server);
Zhongyi Shi 2016/03/22 20:49:08 I'm not sure, whether setting the scheme to be "ht
Ryan Hamilton 2016/03/24 22:23:14 I recommend chatting with Raman about this. He's t
Zhongyi Shi 2016/04/04 18:58:36 After chatting with Raman and a deep digging in th
562 if (server.host().empty()) { 564 if (server.host().empty()) {
563 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; 565 DVLOG(1) << "Malformed http_server_properties for server: " << server_str;
564 return false; 566 return false;
565 } 567 }
566 568
567 const base::DictionaryValue* server_pref_dict = nullptr; 569 const base::DictionaryValue* server_pref_dict = nullptr;
568 if (!it.value().GetAsDictionary(&server_pref_dict)) { 570 if (!it.value().GetAsDictionary(&server_pref_dict)) {
569 DVLOG(1) << "Malformed http_server_properties server: " << server_str; 571 DVLOG(1) << "Malformed http_server_properties server: " << server_str;
570 return false; 572 return false;
571 } 573 }
572 574
573 // Get if server supports Spdy. 575 // Get if server supports Spdy.
574 bool supports_spdy = false; 576 bool supports_spdy = false;
575 if ((server_pref_dict->GetBoolean(kSupportsSpdyKey, &supports_spdy)) && 577 if ((server_pref_dict->GetBoolean(kSupportsSpdyKey, &supports_spdy)) &&
576 supports_spdy) { 578 supports_spdy) {
577 spdy_servers->push_back(server_str); 579 spdy_servers->push_back(server_str);
578 } 580 }
579 581
580 AddToSpdySettingsMap(server, *server_pref_dict, spdy_settings_map); 582 AddToSpdySettingsMap(server, *server_pref_dict, spdy_settings_map);
581 if (!AddToAlternativeServiceMap(server, *server_pref_dict, 583 if (!AddToAlternativeServiceMap(scheme_origin_pair, *server_pref_dict,
582 alternative_service_map) || 584 alternative_service_map) ||
583 !AddToNetworkStatsMap(server, *server_pref_dict, network_stats_map)) { 585 !AddToNetworkStatsMap(server, *server_pref_dict, network_stats_map)) {
584 return false; 586 return false;
585 } 587 }
586 } 588 }
587 return true; 589 return true;
588 } 590 }
589 591
590 void HttpServerPropertiesManager::AddToSpdySettingsMap( 592 void HttpServerPropertiesManager::AddToSpdySettingsMap(
591 const HostPortPair& server, 593 const HostPortPair& server,
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 base::Time::FromInternalValue(expiration_int64); 695 base::Time::FromInternalValue(expiration_int64);
694 return true; 696 return true;
695 } 697 }
696 698
697 DVLOG(1) << "Malformed alternative service expiration for server: " 699 DVLOG(1) << "Malformed alternative service expiration for server: "
698 << server_str; 700 << server_str;
699 return false; 701 return false;
700 } 702 }
701 703
702 bool HttpServerPropertiesManager::AddToAlternativeServiceMap( 704 bool HttpServerPropertiesManager::AddToAlternativeServiceMap(
703 const HostPortPair& server, 705 const SchemeOriginPair& server,
704 const base::DictionaryValue& server_pref_dict, 706 const base::DictionaryValue& server_pref_dict,
705 AlternativeServiceMap* alternative_service_map) { 707 AlternativeServiceMap* alternative_service_map) {
706 DCHECK(alternative_service_map->Peek(server) == 708 DCHECK(alternative_service_map->Peek(server) ==
707 alternative_service_map->end()); 709 alternative_service_map->end());
708 const base::ListValue* alternative_service_list; 710 const base::ListValue* alternative_service_list;
709 if (!server_pref_dict.GetListWithoutPathExpansion( 711 if (!server_pref_dict.GetListWithoutPathExpansion(
710 kAlternativeServiceKey, &alternative_service_list)) { 712 kAlternativeServiceKey, &alternative_service_list)) {
711 return true; 713 return true;
712 } 714 }
713 715
714 AlternativeServiceInfoVector alternative_service_info_vector; 716 AlternativeServiceInfoVector alternative_service_info_vector;
715 for (const base::Value* alternative_service_list_item : 717 for (const base::Value* alternative_service_list_item :
716 *alternative_service_list) { 718 *alternative_service_list) {
717 const base::DictionaryValue* alternative_service_dict; 719 const base::DictionaryValue* alternative_service_dict;
718 if (!alternative_service_list_item->GetAsDictionary( 720 if (!alternative_service_list_item->GetAsDictionary(
719 &alternative_service_dict)) 721 &alternative_service_dict))
720 return false; 722 return false;
721 AlternativeServiceInfo alternative_service_info; 723 AlternativeServiceInfo alternative_service_info;
722 if (!ParseAlternativeServiceDict(*alternative_service_dict, 724 if (!ParseAlternativeServiceDict(*alternative_service_dict,
723 server.ToString(), 725 server.host_port_pair().ToString(),
724 &alternative_service_info)) { 726 &alternative_service_info)) {
725 return false; 727 return false;
726 } 728 }
727 if (base::Time::Now() < alternative_service_info.expiration) { 729 if (base::Time::Now() < alternative_service_info.expiration) {
728 alternative_service_info_vector.push_back(alternative_service_info); 730 alternative_service_info_vector.push_back(alternative_service_info);
729 } 731 }
730 } 732 }
731 733
732 if (alternative_service_info_vector.empty()) { 734 if (alternative_service_info_vector.empty()) {
733 return false; 735 return false;
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 const AlternativeServiceMap& map = 932 const AlternativeServiceMap& map =
931 http_server_properties_impl_->alternative_service_map(); 933 http_server_properties_impl_->alternative_service_map();
932 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers.Memory", 934 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers.Memory",
933 map.size()); 935 map.size());
934 count = 0; 936 count = 0;
935 typedef std::map<std::string, bool> CanonicalHostPersistedMap; 937 typedef std::map<std::string, bool> CanonicalHostPersistedMap;
936 CanonicalHostPersistedMap persisted_map; 938 CanonicalHostPersistedMap persisted_map;
937 // Maintain MRU order. 939 // Maintain MRU order.
938 for (AlternativeServiceMap::const_reverse_iterator it = map.rbegin(); 940 for (AlternativeServiceMap::const_reverse_iterator it = map.rbegin();
939 it != map.rend() && count < kMaxAlternateProtocolHostsToPersist; ++it) { 941 it != map.rend() && count < kMaxAlternateProtocolHostsToPersist; ++it) {
940 const HostPortPair& server = it->first; 942 const SchemeOriginPair& server = it->first;
941 AlternativeServiceInfoVector notbroken_alternative_service_info_vector; 943 AlternativeServiceInfoVector notbroken_alternative_service_info_vector;
942 for (const AlternativeServiceInfo& alternative_service_info : it->second) { 944 for (const AlternativeServiceInfo& alternative_service_info : it->second) {
943 // Do not persist expired entries. 945 // Do not persist expired entries.
944 if (alternative_service_info.expiration < base::Time::Now()) { 946 if (alternative_service_info.expiration < base::Time::Now()) {
945 continue; 947 continue;
946 } 948 }
947 AlternativeService alternative_service( 949 AlternativeService alternative_service(
948 alternative_service_info.alternative_service); 950 alternative_service_info.alternative_service);
949 if (!IsAlternateProtocolValid(alternative_service.protocol)) { 951 if (!IsAlternateProtocolValid(alternative_service.protocol)) {
950 continue; 952 continue;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 server_pref_map.Put(server, server_pref); 1082 server_pref_map.Put(server, server_pref);
1081 } else { 1083 } else {
1082 it->second.settings_map = &map_it->second; 1084 it->second.settings_map = &map_it->second;
1083 } 1085 }
1084 } 1086 }
1085 1087
1086 // Add alternative services to server_pref_map in the MRU order. 1088 // Add alternative services to server_pref_map in the MRU order.
1087 for (AlternativeServiceMap::const_reverse_iterator map_it = 1089 for (AlternativeServiceMap::const_reverse_iterator map_it =
1088 alternative_service_map->rbegin(); 1090 alternative_service_map->rbegin();
1089 map_it != alternative_service_map->rend(); ++map_it) { 1091 map_it != alternative_service_map->rend(); ++map_it) {
1090 const HostPortPair& server = map_it->first; 1092 const HostPortPair& server = map_it->first.host_port_pair();
1091 ServerPrefMap::iterator it = server_pref_map.Get(server); 1093 ServerPrefMap::iterator it = server_pref_map.Get(server);
1092 if (it == server_pref_map.end()) { 1094 if (it == server_pref_map.end()) {
1093 ServerPref server_pref; 1095 ServerPref server_pref;
1094 server_pref.alternative_service_info_vector = &map_it->second; 1096 server_pref.alternative_service_info_vector = &map_it->second;
1095 server_pref_map.Put(server, server_pref); 1097 server_pref_map.Put(server, server_pref);
1096 } else { 1098 } else {
1097 it->second.alternative_service_info_vector = &map_it->second; 1099 it->second.alternative_service_info_vector = &map_it->second;
1098 } 1100 }
1099 } 1101 }
1100 1102
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1260 quic_servers_dict); 1262 quic_servers_dict);
1261 } 1263 }
1262 1264
1263 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { 1265 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() {
1264 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); 1266 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread());
1265 if (!setting_prefs_) 1267 if (!setting_prefs_)
1266 ScheduleUpdateCacheOnPrefThread(); 1268 ScheduleUpdateCacheOnPrefThread();
1267 } 1269 }
1268 1270
1269 } // namespace net 1271 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698