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

Modify SetAlternateProtocol logging behavior.

Modify SetAlternateProtocol() behavior with respect to logging and histograms, by
ignoring alternate protocol being shadowed by |g_forced_alternate_protocol| or
being inactive due to too high probability threshold.

Also clean up HasAlternateProtocol() and GetAlternateProtocol().

BUG=392575

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

Cr-Commit-Position: refs/heads/master@{#313197}
parent 9be085c3
......@@ -227,17 +227,10 @@ bool HttpServerPropertiesImpl::HasAlternateProtocol(
const HostPortPair& server) {
if (g_forced_alternate_protocol)
return true;
AlternateProtocolMap::const_iterator it = alternate_protocol_map_.Get(server);
if (it != alternate_protocol_map_.end())
return it->second.probability >= alternate_protocol_probability_threshold_;
auto canonical = GetCanonicalHost(server);
if (canonical == canonical_host_to_origin_map_.end() ||
canonical->second.Equals(server)) {
return false;
}
return HasAlternateProtocol(canonical->second);
AlternateProtocolMap::const_iterator it =
GetAlternateProtocolIterator(server);
return it != alternate_protocol_map_.end() &&
it->second.probability >= alternate_protocol_probability_threshold_;
}
std::string HttpServerPropertiesImpl::GetCanonicalSuffix(
......@@ -258,16 +251,11 @@ HttpServerPropertiesImpl::GetAlternateProtocol(
const HostPortPair& server) {
DCHECK(HasAlternateProtocol(server));
// First check the map.
AlternateProtocolMap::iterator it = alternate_protocol_map_.Get(server);
AlternateProtocolMap::const_iterator it =
GetAlternateProtocolIterator(server);
if (it != alternate_protocol_map_.end())
return it->second;
// Next check the canonical host.
CanonicalHostMap::const_iterator canonical_host = GetCanonicalHost(server);
if (canonical_host != canonical_host_to_origin_map_.end())
return alternate_protocol_map_.Get(canonical_host->second)->second;
// We must be forcing an alternate.
DCHECK(g_forced_alternate_protocol);
return *g_forced_alternate_protocol;
......@@ -282,9 +270,10 @@ void HttpServerPropertiesImpl::SetAlternateProtocol(
AlternateProtocolInfo alternate(alternate_port,
alternate_protocol,
alternate_probability);
if (HasAlternateProtocol(server)) {
const AlternateProtocolInfo existing_alternate =
GetAlternateProtocol(server);
AlternateProtocolMap::const_iterator it =
GetAlternateProtocolIterator(server);
if (it != alternate_protocol_map_.end()) {
const AlternateProtocolInfo existing_alternate = it->second;
if (existing_alternate.is_broken) {
DVLOG(1) << "Ignore alternate protocol since it's known to be broken.";
......@@ -478,6 +467,20 @@ void HttpServerPropertiesImpl::SetAlternateProtocolProbabilityThreshold(
alternate_protocol_probability_threshold_ = threshold;
}
AlternateProtocolMap::const_iterator
HttpServerPropertiesImpl::GetAlternateProtocolIterator(
const HostPortPair& server) {
AlternateProtocolMap::const_iterator it = alternate_protocol_map_.Get(server);
if (it != alternate_protocol_map_.end())
return it;
CanonicalHostMap::const_iterator canonical = GetCanonicalHost(server);
if (canonical != canonical_host_to_origin_map_.end())
return alternate_protocol_map_.Get(canonical->second);
return alternate_protocol_map_.end();
}
HttpServerPropertiesImpl::CanonicalHostMap::const_iterator
HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const {
for (size_t i = 0; i < canonical_suffixes_.size(); ++i) {
......
......@@ -182,6 +182,10 @@ class NET_EXPORT HttpServerPropertiesImpl
// been marked broken.
typedef std::map<HostPortPair, int> BrokenAlternateProtocolMap;
// Return the iterator for |server|, or for its canonical host, or end.
AlternateProtocolMap::const_iterator GetAlternateProtocolIterator(
const HostPortPair& server);
// Return the canonical host for |server|, or end if none exists.
CanonicalHostMap::const_iterator GetCanonicalHost(HostPortPair server) const;
......
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