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

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

Issue 995013004: Add IsAlternativeServiceBroken(), remove is_broken. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: More nits. Created 5 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
« no previous file with comments | « net/http/http_server_properties_manager.h ('k') | net/http/http_stream_factory_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.h" 8 #include "base/metrics/histogram.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 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 ScheduleUpdatePrefsOnNetworkThread(); 197 ScheduleUpdatePrefsOnNetworkThread();
198 } 198 }
199 199
200 void HttpServerPropertiesManager::SetBrokenAlternateProtocol( 200 void HttpServerPropertiesManager::SetBrokenAlternateProtocol(
201 const HostPortPair& server) { 201 const HostPortPair& server) {
202 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 202 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
203 http_server_properties_impl_->SetBrokenAlternateProtocol(server); 203 http_server_properties_impl_->SetBrokenAlternateProtocol(server);
204 ScheduleUpdatePrefsOnNetworkThread(); 204 ScheduleUpdatePrefsOnNetworkThread();
205 } 205 }
206 206
207 bool HttpServerPropertiesManager::IsAlternativeServiceBroken(
208 const AlternativeService& alternative_service) {
209 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
210 return http_server_properties_impl_->IsAlternativeServiceBroken(
211 alternative_service);
212 }
213
207 bool HttpServerPropertiesManager::WasAlternateProtocolRecentlyBroken( 214 bool HttpServerPropertiesManager::WasAlternateProtocolRecentlyBroken(
208 const HostPortPair& server) { 215 const HostPortPair& server) {
209 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 216 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
210 return http_server_properties_impl_->WasAlternateProtocolRecentlyBroken( 217 return http_server_properties_impl_->WasAlternateProtocolRecentlyBroken(
211 server); 218 server);
212 } 219 }
213 220
214 void HttpServerPropertiesManager::ConfirmAlternateProtocol( 221 void HttpServerPropertiesManager::ConfirmAlternateProtocol(
215 const HostPortPair& server) { 222 const HostPortPair& server) {
216 DCHECK(network_task_runner_->RunsTasksOnCurrentThread()); 223 DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 spdy_settings_map->Put(server, settings_map); 457 spdy_settings_map->Put(server, settings_map);
451 } 458 }
452 459
453 AlternateProtocolInfo HttpServerPropertiesManager::ParseAlternateProtocolDict( 460 AlternateProtocolInfo HttpServerPropertiesManager::ParseAlternateProtocolDict(
454 const base::DictionaryValue& alternate_protocol_dict, 461 const base::DictionaryValue& alternate_protocol_dict,
455 const std::string& server_str) { 462 const std::string& server_str) {
456 AlternateProtocolInfo alternate_protocol; 463 AlternateProtocolInfo alternate_protocol;
457 int port = 0; 464 int port = 0;
458 if (!alternate_protocol_dict.GetInteger(kPortKey, &port) || 465 if (!alternate_protocol_dict.GetInteger(kPortKey, &port) ||
459 !IsPortValid(port)) { 466 !IsPortValid(port)) {
460 DVLOG(1) << "Malformed AltSvc port for server: " << server_str; 467 DVLOG(1) << "Malformed alternative service port for server: " << server_str;
461 return alternate_protocol; 468 return alternate_protocol;
462 } 469 }
463 alternate_protocol.port = static_cast<uint16>(port); 470 alternate_protocol.port = static_cast<uint16>(port);
464 471
465 double probability = 1.0; 472 double probability = 1.0;
466 if (alternate_protocol_dict.HasKey(kProbabilityKey) && 473 if (alternate_protocol_dict.HasKey(kProbabilityKey) &&
467 !alternate_protocol_dict.GetDoubleWithoutPathExpansion(kProbabilityKey, 474 !alternate_protocol_dict.GetDoubleWithoutPathExpansion(kProbabilityKey,
468 &probability)) { 475 &probability)) {
469 DVLOG(1) << "Malformed AltSvc probability for server: " << server_str; 476 DVLOG(1) << "Malformed alternative service probability for server: "
477 << server_str;
470 return alternate_protocol; 478 return alternate_protocol;
471 } 479 }
472 alternate_protocol.probability = probability; 480 alternate_protocol.probability = probability;
473 481
474 std::string protocol_str; 482 std::string protocol_str;
475 if (!alternate_protocol_dict.GetStringWithoutPathExpansion(kProtocolKey, 483 if (!alternate_protocol_dict.GetStringWithoutPathExpansion(kProtocolKey,
476 &protocol_str)) { 484 &protocol_str)) {
477 DVLOG(1) << "Malformed AltSvc protocol string for server: " << server_str; 485 DVLOG(1) << "Malformed alternative service protocol string for server: "
486 << server_str;
478 return alternate_protocol; 487 return alternate_protocol;
479 } 488 }
480 AlternateProtocol protocol = AlternateProtocolFromString(protocol_str); 489 AlternateProtocol protocol = AlternateProtocolFromString(protocol_str);
481 if (!IsAlternateProtocolValid(protocol)) { 490 if (!IsAlternateProtocolValid(protocol)) {
482 DVLOG(1) << "Invalid AltSvc protocol string for server: " << server_str; 491 DVLOG(1) << "Invalid alternative service protocol string for server: "
492 << server_str;
483 return alternate_protocol; 493 return alternate_protocol;
484 } 494 }
485 alternate_protocol.protocol = protocol; 495 alternate_protocol.protocol = protocol;
486 496
487 return alternate_protocol; 497 return alternate_protocol;
488 } 498 }
489 499
490 bool HttpServerPropertiesManager::AddToAlternateProtocolMap( 500 bool HttpServerPropertiesManager::AddToAlternateProtocolMap(
491 const HostPortPair& server, 501 const HostPortPair& server,
492 const base::DictionaryValue& server_pref_dict, 502 const base::DictionaryValue& server_pref_dict,
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
768 ++map_it) { 778 ++map_it) {
769 const HostPortPair& server = map_it->first; 779 const HostPortPair& server = map_it->first;
770 const ServerPref& server_pref = map_it->second; 780 const ServerPref& server_pref = map_it->second;
771 781
772 base::DictionaryValue* server_pref_dict = new base::DictionaryValue; 782 base::DictionaryValue* server_pref_dict = new base::DictionaryValue;
773 783
774 // Save supports_spdy. 784 // Save supports_spdy.
775 if (server_pref.supports_spdy) 785 if (server_pref.supports_spdy)
776 server_pref_dict->SetBoolean(kSupportsSpdyKey, server_pref.supports_spdy); 786 server_pref_dict->SetBoolean(kSupportsSpdyKey, server_pref.supports_spdy);
777 SaveSpdySettingsToServerPrefs(server_pref.settings_map, server_pref_dict); 787 SaveSpdySettingsToServerPrefs(server_pref.settings_map, server_pref_dict);
778 SaveAlternateProtocolToServerPrefs(server_pref.alternate_protocol, 788 SaveAlternateProtocolToServerPrefs(server, server_pref.alternate_protocol,
779 server_pref_dict); 789 server_pref_dict);
780 SaveNetworkStatsToServerPrefs(server_pref.server_network_stats, 790 SaveNetworkStatsToServerPrefs(server_pref.server_network_stats,
781 server_pref_dict); 791 server_pref_dict);
782 792
783 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict); 793 servers_dict->SetWithoutPathExpansion(server.ToString(), server_pref_dict);
784 } 794 }
785 795
786 http_server_properties_dict.SetWithoutPathExpansion(kServersKey, 796 http_server_properties_dict.SetWithoutPathExpansion(kServersKey,
787 servers_dict); 797 servers_dict);
788 SetVersion(&http_server_properties_dict, kVersionNumber); 798 SetVersion(&http_server_properties_dict, kVersionNumber);
(...skipping 23 matching lines...) Expand all
812 it != settings_map->end(); ++it) { 822 it != settings_map->end(); ++it) {
813 SpdySettingsIds id = it->first; 823 SpdySettingsIds id = it->first;
814 uint32 value = it->second.second; 824 uint32 value = it->second.second;
815 std::string key = base::StringPrintf("%u", id); 825 std::string key = base::StringPrintf("%u", id);
816 spdy_settings_dict->SetInteger(key, value); 826 spdy_settings_dict->SetInteger(key, value);
817 } 827 }
818 server_pref_dict->SetWithoutPathExpansion(kSettingsKey, spdy_settings_dict); 828 server_pref_dict->SetWithoutPathExpansion(kSettingsKey, spdy_settings_dict);
819 } 829 }
820 830
821 void HttpServerPropertiesManager::SaveAlternateProtocolToServerPrefs( 831 void HttpServerPropertiesManager::SaveAlternateProtocolToServerPrefs(
832 const HostPortPair& origin,
822 const AlternateProtocolInfo* port_alternate_protocol, 833 const AlternateProtocolInfo* port_alternate_protocol,
823 base::DictionaryValue* server_pref_dict) { 834 base::DictionaryValue* server_pref_dict) {
824 if (!port_alternate_protocol || port_alternate_protocol->is_broken) 835 if (!port_alternate_protocol)
836 return;
837
838 const AlternativeService alternative_service(
839 port_alternate_protocol->protocol, origin.host(),
840 port_alternate_protocol->port);
841 if (IsAlternativeServiceBroken(alternative_service))
Ryan Hamilton 2015/03/10 23:11:52 I'm sorry for not noticing this initally, but I th
Bence 2015/03/11 02:47:44 Good catch. Done.
825 return; 842 return;
826 843
827 base::DictionaryValue* port_alternate_protocol_dict = 844 base::DictionaryValue* port_alternate_protocol_dict =
828 new base::DictionaryValue; 845 new base::DictionaryValue;
829 port_alternate_protocol_dict->SetInteger(kPortKey, 846 port_alternate_protocol_dict->SetInteger(kPortKey,
830 port_alternate_protocol->port); 847 port_alternate_protocol->port);
831 const char* protocol_str = 848 const char* protocol_str =
832 AlternateProtocolToString(port_alternate_protocol->protocol); 849 AlternateProtocolToString(port_alternate_protocol->protocol);
833 port_alternate_protocol_dict->SetString(kProtocolKey, protocol_str); 850 port_alternate_protocol_dict->SetString(kProtocolKey, protocol_str);
834 port_alternate_protocol_dict->SetDouble(kProbabilityKey, 851 port_alternate_protocol_dict->SetDouble(kProbabilityKey,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 server_network_stats_dict); 884 server_network_stats_dict);
868 } 885 }
869 886
870 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { 887 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() {
871 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); 888 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread());
872 if (!setting_prefs_) 889 if (!setting_prefs_)
873 ScheduleUpdateCacheOnPrefThread(); 890 ScheduleUpdateCacheOnPrefThread();
874 } 891 }
875 892
876 } // namespace net 893 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties_manager.h ('k') | net/http/http_stream_factory_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698