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

Unified Diff: net/http/http_server_properties_manager.cc

Issue 665083009: ABANDONED Handle multiple AlternateProtocols for each HostPortPair. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Work on pref load/save and on Job. Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/http/http_server_properties_manager.h ('k') | net/http/http_server_properties_manager_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/http/http_server_properties_manager.cc
diff --git a/net/http/http_server_properties_manager.cc b/net/http/http_server_properties_manager.cc
index 873c8ca700faae8a9b1b39de9e47877d9000828b..6973e0b31780b98732c2785ea60e096628da20a5 100644
--- a/net/http/http_server_properties_manager.cc
+++ b/net/http/http_server_properties_manager.cc
@@ -146,14 +146,13 @@ void HttpServerPropertiesManager::SetSupportsSpdy(const HostPortPair& server,
ScheduleUpdatePrefsOnNetworkThread();
}
-bool HttpServerPropertiesManager::RequiresHTTP11(
- const net::HostPortPair& server) {
+bool HttpServerPropertiesManager::RequiresHTTP11(const HostPortPair& server) {
DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
return http_server_properties_impl_->RequiresHTTP11(server);
}
void HttpServerPropertiesManager::SetHTTP11Required(
- const net::HostPortPair& server) {
+ const HostPortPair& server) {
DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
http_server_properties_impl_->SetHTTP11Required(server);
@@ -172,41 +171,46 @@ bool HttpServerPropertiesManager::HasAlternateProtocol(
return http_server_properties_impl_->HasAlternateProtocol(server);
}
-AlternateProtocolInfo HttpServerPropertiesManager::GetAlternateProtocol(
+const AlternateProtocols& HttpServerPropertiesManager::GetAlternateProtocols(
const HostPortPair& server) {
DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
- return http_server_properties_impl_->GetAlternateProtocol(server);
+ return http_server_properties_impl_->GetAlternateProtocols(server);
}
-void HttpServerPropertiesManager::SetAlternateProtocol(
+void HttpServerPropertiesManager::AddAlternateProtocol(
const HostPortPair& server,
uint16 alternate_port,
AlternateProtocol alternate_protocol,
double alternate_probability) {
DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
- http_server_properties_impl_->SetAlternateProtocol(
+ http_server_properties_impl_->AddAlternateProtocol(
server, alternate_port, alternate_protocol, alternate_probability);
ScheduleUpdatePrefsOnNetworkThread();
}
void HttpServerPropertiesManager::SetBrokenAlternateProtocol(
- const HostPortPair& server) {
+ const HostPortPair& server,
+ const AlternateProtocolInfo& broken_alternate_protocol) {
DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
- http_server_properties_impl_->SetBrokenAlternateProtocol(server);
+ http_server_properties_impl_->SetBrokenAlternateProtocol(
+ server, broken_alternate_protocol);
ScheduleUpdatePrefsOnNetworkThread();
}
bool HttpServerPropertiesManager::WasAlternateProtocolRecentlyBroken(
- const HostPortPair& server) {
+ const HostPortPair& server,
+ const AlternateProtocolInfo& alternate_protocol) {
DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
return http_server_properties_impl_->WasAlternateProtocolRecentlyBroken(
- server);
+ server, alternate_protocol);
}
void HttpServerPropertiesManager::ConfirmAlternateProtocol(
- const HostPortPair& server) {
+ const HostPortPair& server,
+ const AlternateProtocolInfo& alternate_protocol) {
DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
- http_server_properties_impl_->ConfirmAlternateProtocol(server);
+ http_server_properties_impl_->ConfirmAlternateProtocol(server,
+ alternate_protocol);
ScheduleUpdatePrefsOnNetworkThread();
}
@@ -217,6 +221,22 @@ void HttpServerPropertiesManager::ClearAlternateProtocol(
ScheduleUpdatePrefsOnNetworkThread();
}
+void HttpServerPropertiesManager::ClearNonBrokenAlternateProtocols(
+ const HostPortPair& server) {
+ DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
+ http_server_properties_impl_->ClearNonBrokenAlternateProtocols(server);
+ ScheduleUpdatePrefsOnNetworkThread();
+}
+
+void HttpServerPropertiesManager::RemoveAlternateProtocol(
+ const HostPortPair& server,
+ const AlternateProtocolInfo& alternate_protocol) {
+ DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
+ http_server_properties_impl_->RemoveAlternateProtocol(server,
+ alternate_protocol);
+ ScheduleUpdatePrefsOnNetworkThread();
+}
+
const AlternateProtocolMap&
HttpServerPropertiesManager::alternate_protocol_map() const {
DCHECK(network_task_runner_->RunsTasksOnCurrentThread());
@@ -422,46 +442,102 @@ void HttpServerPropertiesManager::UpdateCacheFromPrefsOnPrefThread() {
spdy_settings_map->Put(server, settings_map);
}
- // Get alternate_protocol server.
+ // Get alternative_services...
DCHECK(alternate_protocol_map->Peek(server) ==
alternate_protocol_map->end());
- const base::DictionaryValue* port_alternate_protocol_dict = NULL;
- if (server_pref_dict->GetDictionaryWithoutPathExpansion(
- "alternate_protocol", &port_alternate_protocol_dict)) {
- int port = 0;
- if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion(
- "port", &port) ||
- !IsPortValid(port)) {
- DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str;
- detected_corrupted_prefs = true;
- continue;
- }
- std::string protocol_str;
- if (!port_alternate_protocol_dict->GetStringWithoutPathExpansion(
- "protocol_str", &protocol_str)) {
- DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str;
- detected_corrupted_prefs = true;
- continue;
- }
- AlternateProtocol protocol = AlternateProtocolFromString(protocol_str);
- if (!IsAlternateProtocolValid(protocol)) {
- DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str;
- detected_corrupted_prefs = true;
- continue;
- }
+ const base::ListValue* alternate_protocol_list = NULL;
+ if (server_pref_dict->GetListWithoutPathExpansion(
+ "alternative_services", &alternate_protocol_list) &&
+ !alternate_protocol_list->empty()) {
+ AlternateProtocols alternate_protocols;
+ for (const auto& alternate_protocol_list_item :
+ *alternate_protocol_list) {
+ base::DictionaryValue* alternate_protocol_dict;
+ if (!alternate_protocol_list_item->GetAsDictionary(
+ &alternate_protocol_dict))
+ continue;
+ AlternateProtocolInfo alternate_protocol;
- double probability = 1;
- if (port_alternate_protocol_dict->HasKey("probability") &&
- !port_alternate_protocol_dict->GetDoubleWithoutPathExpansion(
- "probability", &probability)) {
- DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str;
- detected_corrupted_prefs = true;
- continue;
+ int port = 0;
+ if (!alternate_protocol_dict->GetInteger("port", &port) ||
+ !IsPortValid(port)) {
+ DVLOG(1) << "Malformed AltSvc port for server: " << server_str;
+ detected_corrupted_prefs = true;
+ continue;
+ }
+ alternate_protocol.port = static_cast<uint16>(port);
+
+ std::string protocol_str;
+ if (!alternate_protocol_dict->GetStringWithoutPathExpansion(
+ "protocol_str", &protocol_str)) {
+ DVLOG(1) << "Malformed AltSvc protocol string for server: "
+ << server_str;
+ detected_corrupted_prefs = true;
+ continue;
+ }
+ AlternateProtocol protocol = AlternateProtocolFromString(protocol_str);
+ if (!IsAlternateProtocolValid(protocol)) {
+ DVLOG(1) << "Invalid AltSvc protocol string for server: "
+ << server_str;
+ detected_corrupted_prefs = true;
+ continue;
+ }
+ alternate_protocol.protocol = AlternateProtocolFromString(protocol_str);
+
+ double probability = 1;
+ if (alternate_protocol_dict->HasKey("probability") &&
+ !alternate_protocol_dict->GetDoubleWithoutPathExpansion(
+ "probability", &probability)) {
+ DVLOG(1) << "Malformed AltSvc probability for server: " << server_str;
+ detected_corrupted_prefs = true;
+ continue;
+ }
+ alternate_protocol.probability = probability;
+
+ alternate_protocols.push_back(alternate_protocol);
}
+ alternate_protocol_map->Put(server, alternate_protocols);
+ } else {
+ // ...or alternate_protocol.
Bence 2015/01/30 21:24:50 Do we need to be able to load old settings, or can
Ryan Hamilton 2015/01/30 21:50:19 We definitely want to support old settings. It loo
Bence 2015/02/06 19:59:40 Done.
+ const base::DictionaryValue* port_alternate_protocol_dict = NULL;
+ if (server_pref_dict->GetDictionaryWithoutPathExpansion(
+ "alternate_protocol", &port_alternate_protocol_dict)) {
+ int port = 0;
+ if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion(
+ "port", &port) ||
+ !IsPortValid(port)) {
+ DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str;
+ detected_corrupted_prefs = true;
+ continue;
+ }
+ std::string protocol_str;
+ if (!port_alternate_protocol_dict->GetStringWithoutPathExpansion(
+ "protocol_str", &protocol_str)) {
+ DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str;
+ detected_corrupted_prefs = true;
+ continue;
+ }
+ AlternateProtocol protocol = AlternateProtocolFromString(protocol_str);
+ if (!IsAlternateProtocolValid(protocol)) {
+ DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str;
+ detected_corrupted_prefs = true;
+ continue;
+ }
+
+ double probability = 1;
+ if (port_alternate_protocol_dict->HasKey("probability") &&
+ !port_alternate_protocol_dict->GetDoubleWithoutPathExpansion(
+ "probability", &probability)) {
+ DVLOG(1) << "Malformed Alternate-Protocol server: " << server_str;
+ detected_corrupted_prefs = true;
+ continue;
+ }
- AlternateProtocolInfo port_alternate_protocol(static_cast<uint16>(port),
- protocol, probability);
- alternate_protocol_map->Put(server, port_alternate_protocol);
+ AlternateProtocolInfo port_alternate_protocol(static_cast<uint16>(port),
+ protocol, probability);
+ alternate_protocol_map->Put(
+ server, AlternateProtocols(/*size=*/1, port_alternate_protocol));
+ }
}
// Get SupportsQuic.
@@ -652,28 +728,28 @@ void HttpServerPropertiesManager::UpdatePrefsFromCacheOnNetworkThread(
}
// A local or temporary data structure to hold |supports_spdy|, SpdySettings,
-// AlternateProtocolInfo and SupportsQuic preferences for a server. This is used
+// AlternateProtocols and SupportsQuic preferences for a server. This is used
// only in UpdatePrefsOnPrefThread.
struct ServerPref {
ServerPref()
: supports_spdy(false),
settings_map(NULL),
- alternate_protocol(NULL),
+ alternate_protocols(NULL),
supports_quic(NULL),
server_network_stats(NULL) {}
ServerPref(bool supports_spdy,
const SettingsMap* settings_map,
- const AlternateProtocolInfo* alternate_protocol,
+ const AlternateProtocols* alternate_protocols,
const SupportsQuic* supports_quic,
const ServerNetworkStats* server_network_stats)
: supports_spdy(supports_spdy),
settings_map(settings_map),
- alternate_protocol(alternate_protocol),
+ alternate_protocols(alternate_protocols),
supports_quic(supports_quic),
server_network_stats(server_network_stats) {}
bool supports_spdy;
const SettingsMap* settings_map;
- const AlternateProtocolInfo* alternate_protocol;
+ const AlternateProtocols* alternate_protocols;
const SupportsQuic* supports_quic;
const ServerNetworkStats* server_network_stats;
};
@@ -727,17 +803,12 @@ void HttpServerPropertiesManager::UpdatePrefsOnPrefThread(
alternate_protocol_map->begin();
map_it != alternate_protocol_map->end(); ++map_it) {
const HostPortPair& server = map_it->first;
- const AlternateProtocolInfo& port_alternate_protocol = map_it->second;
- if (!IsAlternateProtocolValid(port_alternate_protocol.protocol)) {
- continue;
- }
-
ServerPrefMap::iterator it = server_pref_map.find(server);
if (it == server_pref_map.end()) {
ServerPref server_pref(false, NULL, &map_it->second, NULL, NULL);
server_pref_map[server] = server_pref;
} else {
- it->second.alternate_protocol = &map_it->second;
+ it->second.alternate_protocols = &map_it->second;
}
}
@@ -798,21 +869,27 @@ void HttpServerPropertiesManager::UpdatePrefsOnPrefThread(
server_pref_dict->SetWithoutPathExpansion("settings", spdy_settings_dict);
}
- // Save alternate_protocol.
- const AlternateProtocolInfo* port_alternate_protocol =
- server_pref.alternate_protocol;
- if (port_alternate_protocol && !port_alternate_protocol->is_broken) {
- base::DictionaryValue* port_alternate_protocol_dict =
- new base::DictionaryValue;
- port_alternate_protocol_dict->SetInteger("port",
- port_alternate_protocol->port);
- const char* protocol_str =
- AlternateProtocolToString(port_alternate_protocol->protocol);
- port_alternate_protocol_dict->SetString("protocol_str", protocol_str);
- port_alternate_protocol_dict->SetDouble(
- "probability", port_alternate_protocol->probability);
- server_pref_dict->SetWithoutPathExpansion(
- "alternate_protocol", port_alternate_protocol_dict);
+ // Save alternative_services.
+ if (server_pref.alternate_protocols &&
+ server_pref.alternate_protocols->size() > 0) {
+ base::ListValue* alternate_protocols_list = new base::ListValue;
+ for (AlternateProtocols::const_iterator alternate_protocol =
+ server_pref.alternate_protocols->begin();
+ alternate_protocol != server_pref.alternate_protocols->end();
+ ++alternate_protocol) {
+ base::DictionaryValue* alternate_protocol_dict =
+ new base::DictionaryValue;
+ alternate_protocol_dict->SetInteger("port", alternate_protocol->port);
+ alternate_protocol_dict->SetString("host", server.host());
+ alternate_protocol_dict->SetString(
+ "protocol_str",
+ AlternateProtocolToString(alternate_protocol->protocol));
+ alternate_protocol_dict->SetDouble("probability",
+ alternate_protocol->probability);
+ alternate_protocols_list->Append(alternate_protocol_dict);
+ }
+ server_pref_dict->SetWithoutPathExpansion("alternative_services",
+ alternate_protocols_list);
}
// Save supports_quic.
« no previous file with comments | « net/http/http_server_properties_manager.h ('k') | net/http/http_server_properties_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698