Commit 54e76ef7 authored by bnc's avatar bnc Committed by Commit bot

Refactor alternate protocol dictionary parsing.

This CL breaks out into its own function the parsing of a DictionaryValue to
AlternateProtocolInfo.  This is only called once now, but as soon as we start
storing multiple entries per server, we'll need to call it multiple times.  See
https://codereview.chromium.org/665083009/#ps460001.

BUG=392575

Review URL: https://codereview.chromium.org/897313002

Cr-Commit-Position: refs/heads/master@{#314890}
parent 4a1e13b1
......@@ -450,46 +450,59 @@ void HttpServerPropertiesManager::AddToSpdySettingsMap(
spdy_settings_map->Put(server, settings_map);
}
AlternateProtocolInfo HttpServerPropertiesManager::ParseAlternateProtocolDict(
const base::DictionaryValue& alternate_protocol_dict,
const std::string& server_str) {
AlternateProtocolInfo alternate_protocol;
int port = 0;
if (!alternate_protocol_dict.GetInteger(kPortKey, &port) ||
!IsPortValid(port)) {
DVLOG(1) << "Malformed AltSvc port for server: " << server_str;
return alternate_protocol;
}
alternate_protocol.port = static_cast<uint16>(port);
double probability = 1.0;
if (alternate_protocol_dict.HasKey(kProbabilityKey) &&
!alternate_protocol_dict.GetDoubleWithoutPathExpansion(kProbabilityKey,
&probability)) {
DVLOG(1) << "Malformed AltSvc probability for server: " << server_str;
return alternate_protocol;
}
alternate_protocol.probability = probability;
std::string protocol_str;
if (!alternate_protocol_dict.GetStringWithoutPathExpansion(kProtocolKey,
&protocol_str)) {
DVLOG(1) << "Malformed AltSvc protocol string for server: " << server_str;
return alternate_protocol;
}
AlternateProtocol protocol = AlternateProtocolFromString(protocol_str);
if (!IsAlternateProtocolValid(protocol)) {
DVLOG(1) << "Invalid AltSvc protocol string for server: " << server_str;
return alternate_protocol;
}
alternate_protocol.protocol = protocol;
return alternate_protocol;
}
bool HttpServerPropertiesManager::AddToAlternateProtocolMap(
const HostPortPair& server,
const base::DictionaryValue& server_pref_dict,
AlternateProtocolMap* alternate_protocol_map) {
// Get alternate_protocol server.
DCHECK(alternate_protocol_map->Peek(server) == alternate_protocol_map->end());
const base::DictionaryValue* port_alternate_protocol_dict = NULL;
const base::DictionaryValue* alternate_protocol_dict = NULL;
if (!server_pref_dict.GetDictionaryWithoutPathExpansion(
kAlternateProtocolKey, &port_alternate_protocol_dict)) {
kAlternateProtocolKey, &alternate_protocol_dict)) {
return true;
}
int port = 0;
if (!port_alternate_protocol_dict->GetIntegerWithoutPathExpansion(kPortKey,
&port) ||
!IsPortValid(port)) {
DVLOG(1) << "Malformed Alternate-Protocol server: " << server.ToString();
AlternateProtocolInfo alternate_protocol =
ParseAlternateProtocolDict(*alternate_protocol_dict, server.ToString());
if (alternate_protocol.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL)
return false;
}
std::string protocol_str;
if (!port_alternate_protocol_dict->GetStringWithoutPathExpansion(
kProtocolKey, &protocol_str)) {
DVLOG(1) << "Malformed Alternate-Protocol server: " << server.ToString();
return false;
}
AlternateProtocol protocol = AlternateProtocolFromString(protocol_str);
if (!IsAlternateProtocolValid(protocol)) {
DVLOG(1) << "Malformed Alternate-Protocol server: " << server.ToString();
return false;
}
double probability = 1;
if (port_alternate_protocol_dict->HasKey(kProbabilityKey) &&
!port_alternate_protocol_dict->GetDoubleWithoutPathExpansion(
kProbabilityKey, &probability)) {
DVLOG(1) << "Malformed Alternate-Protocol server: " << server.ToString();
return false;
}
AlternateProtocolInfo port_alternate_protocol(static_cast<uint16>(port),
protocol, probability);
alternate_protocol_map->Put(server, port_alternate_protocol);
alternate_protocol_map->Put(server, alternate_protocol);
return true;
}
......
......@@ -182,6 +182,9 @@ class NET_EXPORT HttpServerPropertiesManager : public HttpServerProperties {
void AddToSpdySettingsMap(const HostPortPair& server,
const base::DictionaryValue& server_dict,
SpdySettingsMap* spdy_settings_map);
AlternateProtocolInfo ParseAlternateProtocolDict(
const base::DictionaryValue& alternate_protocol_dict,
const std::string& server_str);
bool AddToAlternateProtocolMap(const HostPortPair& server,
const base::DictionaryValue& server_dict,
AlternateProtocolMap* alternate_protocol_map);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment