Commit 44387769 authored by bnc's avatar bnc Committed by Commit bot

Introduce AlternativeService in BrokenAlternateProtol{List,Map}.

Introduce struct AlternativeService and use it in
BrokenAlternateProtol{List,Map} instead of BrokenAlternateProtocolEntry.  This
is the first step towards making an alternative service broken not with respect
to an origin, but by itself.

BUG=392576

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

Cr-Commit-Position: refs/heads/master@{#319680}
parent 9bae2008
......@@ -86,6 +86,32 @@ NET_EXPORT AlternateProtocol AlternateProtocolFromString(
NET_EXPORT_PRIVATE AlternateProtocol AlternateProtocolFromNextProto(
NextProto next_proto);
struct NET_EXPORT AlternativeService {
AlternativeService()
: protocol(UNINITIALIZED_ALTERNATE_PROTOCOL), host(), port(0) {}
AlternativeService(AlternateProtocol protocol,
const std::string& host,
uint16 port)
: protocol(protocol), host(host), port(port) {}
AlternativeService(const AlternativeService& alternative_service) = default;
AlternativeService& operator=(const AlternativeService& alternative_service) =
default;
bool operator<(const AlternativeService& other) const {
if (protocol != other.protocol)
return protocol < other.protocol;
if (host != other.host)
return host < other.host;
return port < other.port;
}
AlternateProtocol protocol;
std::string host;
uint16 port;
};
struct NET_EXPORT AlternateProtocolInfo {
AlternateProtocolInfo()
: port(0),
......
......@@ -318,14 +318,14 @@ void HttpServerPropertiesImpl::SetBrokenAlternateProtocol(
it = alternate_protocol_map_.Put(server, alternate);
}
it->second.is_broken = true;
const BrokenAlternateProtocolEntry entry(server, alternate.port,
alternate.protocol);
int count = ++broken_alternate_protocol_map_[entry];
const AlternativeService alternative_service(alternate.protocol,
server.host(), alternate.port);
int count = ++broken_alternate_protocol_map_[alternative_service];
base::TimeDelta delay =
base::TimeDelta::FromSeconds(kBrokenAlternateProtocolDelaySecs);
base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << (count - 1));
broken_alternate_protocol_list_.push_back(
BrokenAlternateProtocolEntryWithTime(entry, when));
BrokenAlternateProtocolEntryWithTime(alternative_service, when));
// Do not leave this host as canonical so that we don't infer the other
// hosts are also broken without testing them first.
......@@ -343,9 +343,9 @@ bool HttpServerPropertiesImpl::WasAlternateProtocolRecentlyBroken(
const AlternateProtocolInfo alternate_protocol = GetAlternateProtocol(server);
if (alternate_protocol.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL)
return false;
const BrokenAlternateProtocolEntry entry(server, alternate_protocol.port,
alternate_protocol.protocol);
return ContainsKey(broken_alternate_protocol_map_, entry);
const AlternativeService alternative_service(
alternate_protocol.protocol, server.host(), alternate_protocol.port);
return ContainsKey(broken_alternate_protocol_map_, alternative_service);
}
void HttpServerPropertiesImpl::ConfirmAlternateProtocol(
......@@ -353,9 +353,9 @@ void HttpServerPropertiesImpl::ConfirmAlternateProtocol(
const AlternateProtocolInfo alternate_protocol = GetAlternateProtocol(server);
if (alternate_protocol.protocol == UNINITIALIZED_ALTERNATE_PROTOCOL)
return;
const BrokenAlternateProtocolEntry entry(server, alternate_protocol.port,
alternate_protocol.protocol);
broken_alternate_protocol_map_.erase(entry);
const AlternativeService alternative_service(
alternate_protocol.protocol, server.host(), alternate_protocol.port);
broken_alternate_protocol_map_.erase(alternative_service);
}
void HttpServerPropertiesImpl::ClearAlternateProtocol(
......@@ -511,9 +511,10 @@ void HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings() {
break;
}
const BrokenAlternateProtocolEntry& entry =
entry_with_time.broken_alternate_protocol_entry;
ClearAlternateProtocol(entry.server);
const AlternativeService& alternative_service =
entry_with_time.alternative_service;
ClearAlternateProtocol(
HostPortPair(alternative_service.host, alternative_service.port));
broken_alternate_protocol_list_.pop_front();
}
ScheduleBrokenAlternateProtocolMappingsExpiration();
......
......@@ -117,37 +117,14 @@ class NET_EXPORT HttpServerPropertiesImpl
typedef std::vector<std::string> CanonicalSufficList;
typedef std::set<HostPortPair> Http11ServerHostPortSet;
// Server, port, and AlternateProtocol: an entity that can be broken. (Once
// we use AlternativeService, the same AltSvc can be broken for one server but
// not for another depending on what certificate it can offer.)
struct BrokenAlternateProtocolEntry {
BrokenAlternateProtocolEntry(const BrokenAlternateProtocolEntry&) = default;
BrokenAlternateProtocolEntry(const HostPortPair& server,
uint16 port,
AlternateProtocol protocol)
: server(server), port(port), protocol(protocol) {}
bool operator<(const BrokenAlternateProtocolEntry& other) const {
if (!server.Equals(other.server))
return server < other.server;
if (port != other.port)
return port < other.port;
return protocol < other.protocol;
}
HostPortPair server;
uint16 port;
AlternateProtocol protocol;
};
// BrokenAlternateProtocolEntry with expiration time.
// Broken alternative service with expiration time.
struct BrokenAlternateProtocolEntryWithTime {
BrokenAlternateProtocolEntryWithTime(
const BrokenAlternateProtocolEntry& broken_alternate_protocol_entry,
const AlternativeService& alternative_service,
base::TimeTicks when)
: broken_alternate_protocol_entry(broken_alternate_protocol_entry),
when(when) {}
: alternative_service(alternative_service), when(when) {}
BrokenAlternateProtocolEntry broken_alternate_protocol_entry;
AlternativeService alternative_service;
base::TimeTicks when;
};
// Deque of BrokenAlternateProtocolEntryWithTime items, ordered by expiration
......@@ -156,8 +133,7 @@ class NET_EXPORT HttpServerPropertiesImpl
BrokenAlternateProtocolList;
// Map from (server, alternate protocol and port) to the number of
// times that alternate protocol has been marked broken for that server.
typedef std::map<BrokenAlternateProtocolEntry, int>
BrokenAlternateProtocolMap;
typedef std::map<AlternativeService, int> BrokenAlternateProtocolMap;
// Return the iterator for |server|, or for its canonical host, or end.
AlternateProtocolMap::const_iterator GetAlternateProtocolIterator(
......
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