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

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

Issue 1878143005: SHP 4: Change AlternativeServiceMap to use SchemeHostPort as the key. No change to Pref data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@SHP_3
Patch Set: fix a comment Created 4 years, 8 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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 ScheduleUpdatePrefsOnNetworkThread(HTTP_11_REQUIRED); 182 ScheduleUpdatePrefsOnNetworkThread(HTTP_11_REQUIRED);
183 } 183 }
184 184
185 void HttpServerPropertiesManager::MaybeForceHTTP11(const HostPortPair& server, 185 void HttpServerPropertiesManager::MaybeForceHTTP11(const HostPortPair& server,
186 SSLConfig* ssl_config) { 186 SSLConfig* ssl_config) {
187 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 187 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
188 http_server_properties_impl_->MaybeForceHTTP11(server, ssl_config); 188 http_server_properties_impl_->MaybeForceHTTP11(server, ssl_config);
189 } 189 }
190 190
191 AlternativeServiceVector HttpServerPropertiesManager::GetAlternativeServices( 191 AlternativeServiceVector HttpServerPropertiesManager::GetAlternativeServices(
192 const HostPortPair& origin) { 192 const url::SchemeHostPort& origin) {
193 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 193 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
194 return http_server_properties_impl_->GetAlternativeServices(origin); 194 return http_server_properties_impl_->GetAlternativeServices(origin);
195 } 195 }
196 196
197 bool HttpServerPropertiesManager::SetAlternativeService( 197 bool HttpServerPropertiesManager::SetAlternativeService(
198 const HostPortPair& origin, 198 const url::SchemeHostPort& origin,
199 const AlternativeService& alternative_service, 199 const AlternativeService& alternative_service,
200 base::Time expiration) { 200 base::Time expiration) {
201 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 201 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
202 const bool changed = http_server_properties_impl_->SetAlternativeService( 202 const bool changed = http_server_properties_impl_->SetAlternativeService(
203 origin, alternative_service, expiration); 203 origin, alternative_service, expiration);
204 if (changed) { 204 if (changed) {
205 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES); 205 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES);
206 } 206 }
207 return changed; 207 return changed;
208 } 208 }
209 209
210 bool HttpServerPropertiesManager::SetAlternativeServices( 210 bool HttpServerPropertiesManager::SetAlternativeServices(
211 const HostPortPair& origin, 211 const url::SchemeHostPort& origin,
212 const AlternativeServiceInfoVector& alternative_service_info_vector) { 212 const AlternativeServiceInfoVector& alternative_service_info_vector) {
213 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 213 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
214 const bool changed = http_server_properties_impl_->SetAlternativeServices( 214 const bool changed = http_server_properties_impl_->SetAlternativeServices(
215 origin, alternative_service_info_vector); 215 origin, alternative_service_info_vector);
216 if (changed) { 216 if (changed) {
217 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES); 217 ScheduleUpdatePrefsOnNetworkThread(SET_ALTERNATIVE_SERVICES);
218 } 218 }
219 return changed; 219 return changed;
220 } 220 }
221 221
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 http_server_properties_impl_->ConfirmAlternativeService(alternative_service); 257 http_server_properties_impl_->ConfirmAlternativeService(alternative_service);
258 bool new_value = http_server_properties_impl_->IsAlternativeServiceBroken( 258 bool new_value = http_server_properties_impl_->IsAlternativeServiceBroken(
259 alternative_service); 259 alternative_service);
260 // For persisting, we only care about the value returned by 260 // For persisting, we only care about the value returned by
261 // IsAlternativeServiceBroken. If that value changes, then call persist. 261 // IsAlternativeServiceBroken. If that value changes, then call persist.
262 if (old_value != new_value) 262 if (old_value != new_value)
263 ScheduleUpdatePrefsOnNetworkThread(CONFIRM_ALTERNATIVE_SERVICE); 263 ScheduleUpdatePrefsOnNetworkThread(CONFIRM_ALTERNATIVE_SERVICE);
264 } 264 }
265 265
266 void HttpServerPropertiesManager::ClearAlternativeServices( 266 void HttpServerPropertiesManager::ClearAlternativeServices(
267 const HostPortPair& origin) { 267 const url::SchemeHostPort& origin) {
268 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 268 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
269 const AlternativeServiceMap& map = 269 const AlternativeServiceMap& map =
270 http_server_properties_impl_->alternative_service_map(); 270 http_server_properties_impl_->alternative_service_map();
271 size_t old_size = map.size(); 271 size_t old_size = map.size();
272 http_server_properties_impl_->ClearAlternativeServices(origin); 272 http_server_properties_impl_->ClearAlternativeServices(origin);
273 size_t new_size = map.size(); 273 size_t new_size = map.size();
274 // Persist only if we have deleted an entry. 274 // Persist only if we have deleted an entry.
275 if (old_size != new_size) 275 if (old_size != new_size)
276 ScheduleUpdatePrefsOnNetworkThread(CLEAR_ALTERNATIVE_SERVICE); 276 ScheduleUpdatePrefsOnNetworkThread(CLEAR_ALTERNATIVE_SERVICE);
277 } 277 }
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 ServerList* spdy_servers, 547 ServerList* spdy_servers,
548 SpdySettingsMap* spdy_settings_map, 548 SpdySettingsMap* spdy_settings_map,
549 AlternativeServiceMap* alternative_service_map, 549 AlternativeServiceMap* alternative_service_map,
550 ServerNetworkStatsMap* network_stats_map) { 550 ServerNetworkStatsMap* network_stats_map) {
551 for (base::DictionaryValue::Iterator it(servers_dict); !it.IsAtEnd(); 551 for (base::DictionaryValue::Iterator it(servers_dict); !it.IsAtEnd();
552 it.Advance()) { 552 it.Advance()) {
553 // TODO(zhongyi): get server's scheme/host/port when servers_dict migrates 553 // TODO(zhongyi): get server's scheme/host/port when servers_dict migrates
554 // to SchemeHostPort. 554 // to SchemeHostPort.
555 // Get server's host/pair. 555 // Get server's host/pair.
556 const std::string& server_str = it.key(); 556 const std::string& server_str = it.key();
557 HostPortPair server = HostPortPair::FromString(server_str);
558 // TODO(zhongyi): fill in the scheme field when servers_dict has scheme. 557 // TODO(zhongyi): fill in the scheme field when servers_dict has scheme.
559 std::string spdy_server_url = "https://" + server_str; 558 std::string spdy_server_url = "https://" + server_str;
560 url::SchemeHostPort spdy_server((GURL(spdy_server_url))); 559 url::SchemeHostPort spdy_server((GURL(spdy_server_url)));
561 if (server.host().empty()) { 560 if (spdy_server.host().empty()) {
562 DVLOG(1) << "Malformed http_server_properties for server: " << server_str; 561 DVLOG(1) << "Malformed http_server_properties for server: " << server_str;
563 return false; 562 return false;
564 } 563 }
565 564
566 const base::DictionaryValue* server_pref_dict = nullptr; 565 const base::DictionaryValue* server_pref_dict = nullptr;
567 if (!it.value().GetAsDictionary(&server_pref_dict)) { 566 if (!it.value().GetAsDictionary(&server_pref_dict)) {
568 DVLOG(1) << "Malformed http_server_properties server: " << server_str; 567 DVLOG(1) << "Malformed http_server_properties server: " << server_str;
569 return false; 568 return false;
570 } 569 }
571 570
572 // Get if server supports Spdy. 571 // Get if server supports Spdy.
573 bool supports_spdy = false; 572 bool supports_spdy = false;
574 if ((server_pref_dict->GetBoolean(kSupportsSpdyKey, &supports_spdy)) && 573 if ((server_pref_dict->GetBoolean(kSupportsSpdyKey, &supports_spdy)) &&
575 supports_spdy) { 574 supports_spdy) {
576 spdy_servers->push_back(spdy_server.Serialize()); 575 spdy_servers->push_back(spdy_server.Serialize());
577 } 576 }
578 577
579 AddToSpdySettingsMap(spdy_server, *server_pref_dict, spdy_settings_map); 578 AddToSpdySettingsMap(spdy_server, *server_pref_dict, spdy_settings_map);
580 if (!AddToAlternativeServiceMap(server, *server_pref_dict, 579 if (!AddToAlternativeServiceMap(spdy_server, *server_pref_dict,
581 alternative_service_map) || 580 alternative_service_map) ||
582 !AddToNetworkStatsMap(spdy_server, *server_pref_dict, 581 !AddToNetworkStatsMap(spdy_server, *server_pref_dict,
583 network_stats_map)) { 582 network_stats_map)) {
584 return false; 583 return false;
585 } 584 }
586 } 585 }
587 return true; 586 return true;
588 } 587 }
589 588
590 void HttpServerPropertiesManager::AddToSpdySettingsMap( 589 void HttpServerPropertiesManager::AddToSpdySettingsMap(
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 base::Time::FromInternalValue(expiration_int64); 682 base::Time::FromInternalValue(expiration_int64);
684 return true; 683 return true;
685 } 684 }
686 685
687 DVLOG(1) << "Malformed alternative service expiration for server: " 686 DVLOG(1) << "Malformed alternative service expiration for server: "
688 << server_str; 687 << server_str;
689 return false; 688 return false;
690 } 689 }
691 690
692 bool HttpServerPropertiesManager::AddToAlternativeServiceMap( 691 bool HttpServerPropertiesManager::AddToAlternativeServiceMap(
693 const HostPortPair& server, 692 const url::SchemeHostPort& server,
694 const base::DictionaryValue& server_pref_dict, 693 const base::DictionaryValue& server_pref_dict,
695 AlternativeServiceMap* alternative_service_map) { 694 AlternativeServiceMap* alternative_service_map) {
696 DCHECK(alternative_service_map->Peek(server) == 695 DCHECK(alternative_service_map->Peek(server) ==
697 alternative_service_map->end()); 696 alternative_service_map->end());
698 const base::ListValue* alternative_service_list; 697 const base::ListValue* alternative_service_list;
699 if (!server_pref_dict.GetListWithoutPathExpansion( 698 if (!server_pref_dict.GetListWithoutPathExpansion(
700 kAlternativeServiceKey, &alternative_service_list)) { 699 kAlternativeServiceKey, &alternative_service_list)) {
701 return true; 700 return true;
702 } 701 }
703 702
704 AlternativeServiceInfoVector alternative_service_info_vector; 703 AlternativeServiceInfoVector alternative_service_info_vector;
705 for (const base::Value* alternative_service_list_item : 704 for (const base::Value* alternative_service_list_item :
706 *alternative_service_list) { 705 *alternative_service_list) {
707 const base::DictionaryValue* alternative_service_dict; 706 const base::DictionaryValue* alternative_service_dict;
708 if (!alternative_service_list_item->GetAsDictionary( 707 if (!alternative_service_list_item->GetAsDictionary(
709 &alternative_service_dict)) 708 &alternative_service_dict))
710 return false; 709 return false;
711 AlternativeServiceInfo alternative_service_info; 710 AlternativeServiceInfo alternative_service_info;
712 if (!ParseAlternativeServiceDict(*alternative_service_dict, 711 if (!ParseAlternativeServiceDict(*alternative_service_dict,
713 server.ToString(), 712 server.Serialize(),
714 &alternative_service_info)) { 713 &alternative_service_info)) {
715 return false; 714 return false;
716 } 715 }
717 if (base::Time::Now() < alternative_service_info.expiration) { 716 if (base::Time::Now() < alternative_service_info.expiration) {
718 alternative_service_info_vector.push_back(alternative_service_info); 717 alternative_service_info_vector.push_back(alternative_service_info);
719 } 718 }
720 } 719 }
721 720
722 if (alternative_service_info_vector.empty()) { 721 if (alternative_service_info_vector.empty()) {
723 return false; 722 return false;
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
920 const AlternativeServiceMap& map = 919 const AlternativeServiceMap& map =
921 http_server_properties_impl_->alternative_service_map(); 920 http_server_properties_impl_->alternative_service_map();
922 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers.Memory", 921 UMA_HISTOGRAM_COUNTS("Net.CountOfAlternateProtocolServers.Memory",
923 map.size()); 922 map.size());
924 count = 0; 923 count = 0;
925 typedef std::map<std::string, bool> CanonicalHostPersistedMap; 924 typedef std::map<std::string, bool> CanonicalHostPersistedMap;
926 CanonicalHostPersistedMap persisted_map; 925 CanonicalHostPersistedMap persisted_map;
927 // Maintain MRU order. 926 // Maintain MRU order.
928 for (AlternativeServiceMap::const_reverse_iterator it = map.rbegin(); 927 for (AlternativeServiceMap::const_reverse_iterator it = map.rbegin();
929 it != map.rend() && count < kMaxAlternateProtocolHostsToPersist; ++it) { 928 it != map.rend() && count < kMaxAlternateProtocolHostsToPersist; ++it) {
930 const HostPortPair& server = it->first; 929 const url::SchemeHostPort& server = it->first;
931 AlternativeServiceInfoVector notbroken_alternative_service_info_vector; 930 AlternativeServiceInfoVector notbroken_alternative_service_info_vector;
932 for (const AlternativeServiceInfo& alternative_service_info : it->second) { 931 for (const AlternativeServiceInfo& alternative_service_info : it->second) {
933 // Do not persist expired entries. 932 // Do not persist expired entries.
934 if (alternative_service_info.expiration < base::Time::Now()) { 933 if (alternative_service_info.expiration < base::Time::Now()) {
935 continue; 934 continue;
936 } 935 }
937 AlternativeService alternative_service( 936 AlternativeService alternative_service(
938 alternative_service_info.alternative_service); 937 alternative_service_info.alternative_service);
939 if (!IsAlternateProtocolValid(alternative_service.protocol)) { 938 if (!IsAlternateProtocolValid(alternative_service.protocol)) {
940 continue; 939 continue;
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 server_pref_map.Put(server, server_pref); 1071 server_pref_map.Put(server, server_pref);
1073 } else { 1072 } else {
1074 it->second.settings_map = &map_it->second; 1073 it->second.settings_map = &map_it->second;
1075 } 1074 }
1076 } 1075 }
1077 1076
1078 // Add alternative services to server_pref_map in the MRU order. 1077 // Add alternative services to server_pref_map in the MRU order.
1079 for (AlternativeServiceMap::const_reverse_iterator map_it = 1078 for (AlternativeServiceMap::const_reverse_iterator map_it =
1080 alternative_service_map->rbegin(); 1079 alternative_service_map->rbegin();
1081 map_it != alternative_service_map->rend(); ++map_it) { 1080 map_it != alternative_service_map->rend(); ++map_it) {
1082 const HostPortPair& server = map_it->first; 1081 // TODO(zhongyi): migrate to SHP once server_pref_map is migrated.
1082 const HostPortPair server(map_it->first.host(), map_it->first.port());
1083 ServerPrefMap::iterator it = server_pref_map.Get(server); 1083 ServerPrefMap::iterator it = server_pref_map.Get(server);
1084 if (it == server_pref_map.end()) { 1084 if (it == server_pref_map.end()) {
1085 ServerPref server_pref; 1085 ServerPref server_pref;
1086 server_pref.alternative_service_info_vector = &map_it->second; 1086 server_pref.alternative_service_info_vector = &map_it->second;
1087 server_pref_map.Put(server, server_pref); 1087 server_pref_map.Put(server, server_pref);
1088 } else { 1088 } else {
1089 it->second.alternative_service_info_vector = &map_it->second; 1089 it->second.alternative_service_info_vector = &map_it->second;
1090 } 1090 }
1091 } 1091 }
1092 1092
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 quic_servers_dict); 1252 quic_servers_dict);
1253 } 1253 }
1254 1254
1255 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { 1255 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() {
1256 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); 1256 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread());
1257 if (!setting_prefs_) 1257 if (!setting_prefs_)
1258 ScheduleUpdateCacheOnPrefThread(); 1258 ScheduleUpdateCacheOnPrefThread();
1259 } 1259 }
1260 1260
1261 } // namespace net 1261 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698