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

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: 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
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_pref.alternate_protocol,
Ryan Hamilton 2015/03/10 21:05:46 Can you check IsBroken here to resolve your TODO b
Bence 2015/03/10 21:46:13 I'd rather not, because it does not belong here, b
Ryan Hamilton 2015/03/10 22:15:26 The only reason I suggest it is that as currently
Bence 2015/03/10 22:54:41 Good call. I think with this change the behavior
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 25 matching lines...) Expand all
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(
822 const AlternateProtocolInfo* port_alternate_protocol, 832 const AlternateProtocolInfo* port_alternate_protocol,
823 base::DictionaryValue* server_pref_dict) { 833 base::DictionaryValue* server_pref_dict) {
824 if (!port_alternate_protocol || port_alternate_protocol->is_broken) 834 // TODO(bnc): Do not save alternative service if broken.
835 if (!port_alternate_protocol)
825 return; 836 return;
826 837
827 base::DictionaryValue* port_alternate_protocol_dict = 838 base::DictionaryValue* port_alternate_protocol_dict =
828 new base::DictionaryValue; 839 new base::DictionaryValue;
829 port_alternate_protocol_dict->SetInteger(kPortKey, 840 port_alternate_protocol_dict->SetInteger(kPortKey,
830 port_alternate_protocol->port); 841 port_alternate_protocol->port);
831 const char* protocol_str = 842 const char* protocol_str =
832 AlternateProtocolToString(port_alternate_protocol->protocol); 843 AlternateProtocolToString(port_alternate_protocol->protocol);
833 port_alternate_protocol_dict->SetString(kProtocolKey, protocol_str); 844 port_alternate_protocol_dict->SetString(kProtocolKey, protocol_str);
834 port_alternate_protocol_dict->SetDouble(kProbabilityKey, 845 port_alternate_protocol_dict->SetDouble(kProbabilityKey,
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
867 server_network_stats_dict); 878 server_network_stats_dict);
868 } 879 }
869 880
870 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() { 881 void HttpServerPropertiesManager::OnHttpServerPropertiesChanged() {
871 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread()); 882 DCHECK(pref_task_runner_->RunsTasksOnCurrentThread());
872 if (!setting_prefs_) 883 if (!setting_prefs_)
873 ScheduleUpdateCacheOnPrefThread(); 884 ScheduleUpdateCacheOnPrefThread();
874 } 885 }
875 886
876 } // namespace net 887 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698