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

Unified Diff: net/http/http_server_properties_impl.cc

Issue 665083009: ABANDONED Handle multiple AlternateProtocols for each HostPortPair. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Custom entries for broken_alternate_protocol_list_ and map_. 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_impl.h ('k') | net/http/http_server_properties_impl_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_impl.cc
diff --git a/net/http/http_server_properties_impl.cc b/net/http/http_server_properties_impl.cc
index d048e98871acba04071ccae2c0c81d51d494bc26..003a4fe77baf7dc4a2a99b7bb0bd3ca2b6f315aa 100644
--- a/net/http/http_server_properties_impl.cc
+++ b/net/http/http_server_properties_impl.cc
@@ -50,13 +50,25 @@ void HttpServerPropertiesImpl::InitializeSpdyServers(
void HttpServerPropertiesImpl::InitializeAlternateProtocolServers(
AlternateProtocolMap* alternate_protocol_map) {
- // Keep all the broken ones since those don't get persisted.
- for (AlternateProtocolMap::iterator it = alternate_protocol_map_.begin();
- it != alternate_protocol_map_.end();) {
- AlternateProtocolMap::iterator old_it = it;
- ++it;
- if (!old_it->second.is_broken) {
- alternate_protocol_map_.Erase(old_it);
+ for (AlternateProtocolMap::iterator alternate_protocols =
+ alternate_protocol_map_.begin();
+ alternate_protocols != alternate_protocol_map_.end();) {
+ // TODO(bnc): Factor out code shared with ClearNonBrokenAlternateProtocols
+ // into separate method.
+ // Keep all the broken ones since those don't get persisted.
+ for (AlternateProtocols::iterator it = alternate_protocols->second.begin();
+ it != alternate_protocols->second.end();) {
+ if (!it->is_broken) {
+ it = alternate_protocols->second.erase(it);
+ } else {
+ ++it;
+ }
+ }
+ if (alternate_protocols->second.size() == 0) {
+ RemoveCanonicalHost(alternate_protocols->first);
+ alternate_protocols = alternate_protocol_map_.Erase(alternate_protocols);
+ } else {
+ ++alternate_protocols;
}
}
@@ -225,12 +237,8 @@ void HttpServerPropertiesImpl::MaybeForceHTTP11(const HostPortPair& server,
bool HttpServerPropertiesImpl::HasAlternateProtocol(
const HostPortPair& server) {
- if (g_forced_alternate_protocol)
- return true;
- AlternateProtocolMap::const_iterator it =
- GetAlternateProtocolIterator(server);
- return it != alternate_protocol_map_.end() &&
- it->second.probability >= alternate_protocol_probability_threshold_;
+ return GetAlternateProtocol(server).protocol !=
+ UNINITIALIZED_ALTERNATE_PROTOCOL;
}
std::string HttpServerPropertiesImpl::GetCanonicalSuffix(
@@ -246,51 +254,68 @@ std::string HttpServerPropertiesImpl::GetCanonicalSuffix(
return std::string();
}
-AlternateProtocolInfo
-HttpServerPropertiesImpl::GetAlternateProtocol(
+AlternateProtocolInfo HttpServerPropertiesImpl::GetAlternateProtocol(
const HostPortPair& server) {
- DCHECK(HasAlternateProtocol(server));
-
- AlternateProtocolMap::const_iterator it =
+ AlternateProtocolMap::const_iterator alternate_protocols =
GetAlternateProtocolIterator(server);
- if (it != alternate_protocol_map_.end())
- return it->second;
+ if (alternate_protocols != alternate_protocol_map_.end()) {
+ for (const AlternateProtocolInfo& alternate_protocol :
+ alternate_protocols->second) {
+ if (!alternate_protocol.is_broken &&
+ alternate_protocol.probability >=
+ alternate_protocol_probability_threshold_) {
+ return alternate_protocol;
+ }
+ }
+ }
- // We must be forcing an alternate.
- DCHECK(g_forced_alternate_protocol);
- return *g_forced_alternate_protocol;
+ if (g_forced_alternate_protocol)
+ return *g_forced_alternate_protocol;
+
+ AlternateProtocolInfo uninitialized_alternate_protocol;
+ return uninitialized_alternate_protocol;
}
-void HttpServerPropertiesImpl::SetAlternateProtocol(
+void HttpServerPropertiesImpl::AddAlternateProtocol(
const HostPortPair& server,
uint16 alternate_port,
AlternateProtocol alternate_protocol,
double alternate_probability) {
-
+ if (!IsAlternateProtocolValid(alternate_protocol))
+ return;
AlternateProtocolInfo alternate(alternate_port,
alternate_protocol,
alternate_probability);
- 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.";
- return;
+ AlternateProtocolMap::const_iterator map_it =
+ alternate_protocol_map_.Get(server);
+ if (map_it != alternate_protocol_map_.end()) {
+ AlternateProtocols existing_alternates = map_it->second;
+ AlternateProtocols::iterator it;
+ for (it = existing_alternates.begin(); it != existing_alternates.end();
+ ++it) {
+ if (it->EqualsModuloProbability(alternate)) {
+ break;
+ }
}
- if (!existing_alternate.Equals(alternate)) {
- LOG(WARNING) << "Changing the alternate protocol for: "
- << server.ToString()
- << " from [Port: " << existing_alternate.port
- << ", Protocol: " << existing_alternate.protocol
- << ", Probability: " << existing_alternate.probability
- << "] to [Port: " << alternate_port
- << ", Protocol: " << alternate_protocol
- << ", Probability: " << alternate_probability
- << "].";
+ if (it != existing_alternates.end()) {
+ if (it->is_broken) {
+ DVLOG(1) << "Ignore alternate protocol since it's known to be broken.";
+ return;
+ }
+ if (it->probability != alternate_probability) {
+ LOG(WARNING) << "Changing the probability of alternate protocol for: "
+ << server.ToString() << " Port: " << it->port
+ << ", Protocol: " << it->protocol
+ << ", Probability from: " << it->probability
+ << " to: " << alternate_probability << ".";
+ it->probability = alternate_probability;
+ }
+ } else {
+ existing_alternates.push_back(alternate);
}
+
+ alternate_protocol_map_.Put(server, existing_alternates);
} else {
if (alternate_probability >= alternate_protocol_probability_threshold_) {
// TODO(rch): Consider the case where multiple requests are started
@@ -298,10 +323,10 @@ void HttpServerPropertiesImpl::SetAlternateProtocol(
// would reach this code, whereas all of them should should have.
HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING);
}
+ alternate_protocol_map_.Put(server,
+ AlternateProtocols(/*size=*/1, alternate));
}
- alternate_protocol_map_.Put(server, alternate);
-
// If this host ends with a canonical suffix, then set it as the
// canonical host.
for (size_t i = 0; i < canonical_suffixes_.size(); ++i) {
@@ -315,47 +340,61 @@ void HttpServerPropertiesImpl::SetAlternateProtocol(
}
void HttpServerPropertiesImpl::SetBrokenAlternateProtocol(
- const HostPortPair& server) {
- AlternateProtocolMap::iterator it = alternate_protocol_map_.Get(server);
- if (it == alternate_protocol_map_.end()) {
- if (!HasAlternateProtocol(server)) {
- LOG(DFATAL) << "Trying to mark unknown alternate protocol broken.";
- return;
+ const HostPortPair& server,
+ const AlternateProtocolInfo& broken_alternate_protocol) {
+ if (!IsAlternateProtocolValid(broken_alternate_protocol.protocol))
+ return;
+ AddAlternateProtocol(server, broken_alternate_protocol.port,
+ broken_alternate_protocol.protocol,
+ broken_alternate_protocol.probability);
+ AlternateProtocolMap::iterator alternate_protocols =
+ alternate_protocol_map_.Get(server);
+ DCHECK(alternate_protocols != alternate_protocol_map_.end());
+ AlternateProtocols::iterator it;
+ for (it = alternate_protocols->second.begin();
+ it != alternate_protocols->second.end(); ++it) {
+ if (it->Equals(broken_alternate_protocol)) {
+ it->is_broken = true;
+ break;
}
- // This server's alternate protocol information is coming from a canonical
- // server. Add an entry in the map for this server explicitly so that
- // it can be marked as broken.
- it = alternate_protocol_map_.Put(server, GetAlternateProtocol(server));
}
- it->second.is_broken = true;
- int count = ++broken_alternate_protocol_map_[server];
+ DCHECK(it != alternate_protocols->second.end());
+
+ const BrokenAlternateProtocolEntry entry(server,
+ broken_alternate_protocol.port,
+ broken_alternate_protocol.protocol);
+ int count = ++broken_alternate_protocol_map_[entry];
base::TimeDelta delay =
base::TimeDelta::FromSeconds(kBrokenAlternateProtocolDelaySecs);
- BrokenAlternateProtocolEntry entry;
- entry.server = server;
- entry.when = base::TimeTicks::Now() + delay * (1 << (count - 1));
- broken_alternate_protocol_list_.push_back(entry);
+ base::TimeTicks when = base::TimeTicks::Now() + delay * (1 << (count - 1));
+ broken_alternate_protocol_list_.push_back(
+ BrokenAlternateProtocolEntryWithTime(entry, when));
// Do not leave this host as canonical so that we don't infer the other
// hosts are also broken without testing them first.
RemoveCanonicalHost(server);
// If this is the only entry in the list, schedule an expiration task.
- // Otherwse it will be rescheduled automatically when the pending
- // task runs.
+ // Otherwise it will be rescheduled automatically when the pending task runs.
if (broken_alternate_protocol_list_.size() == 1) {
ScheduleBrokenAlternateProtocolMappingsExpiration();
}
}
bool HttpServerPropertiesImpl::WasAlternateProtocolRecentlyBroken(
- const HostPortPair& server) {
- return ContainsKey(broken_alternate_protocol_map_, server);
+ const HostPortPair& server,
+ const AlternateProtocolInfo& alternate_protocol) {
+ const BrokenAlternateProtocolEntry entry(server, alternate_protocol.port,
+ alternate_protocol.protocol);
+ return ContainsKey(broken_alternate_protocol_map_, entry);
}
void HttpServerPropertiesImpl::ConfirmAlternateProtocol(
- const HostPortPair& server) {
- broken_alternate_protocol_map_.erase(server);
+ const HostPortPair& server,
+ const AlternateProtocolInfo& alternate_protocol) {
+ const BrokenAlternateProtocolEntry entry(server, alternate_protocol.port,
+ alternate_protocol.protocol);
+ broken_alternate_protocol_map_.erase(entry);
}
void HttpServerPropertiesImpl::ClearAlternateProtocol(
@@ -367,6 +406,48 @@ void HttpServerPropertiesImpl::ClearAlternateProtocol(
RemoveCanonicalHost(server);
}
+void HttpServerPropertiesImpl::ClearNonBrokenAlternateProtocols(
+ const HostPortPair& server) {
+ AlternateProtocolMap::iterator alternate_protocols =
+ alternate_protocol_map_.Peek(server);
+ if (alternate_protocols == alternate_protocol_map_.end()) {
+ return;
+ }
+ for (AlternateProtocols::iterator it = alternate_protocols->second.begin();
+ it != alternate_protocols->second.end();) {
+ if (!it->is_broken) {
+ it = alternate_protocols->second.erase(it);
+ } else {
+ ++it;
+ }
+ }
+ if (alternate_protocols->second.size() == 0) {
+ alternate_protocol_map_.Erase(alternate_protocols);
+ RemoveCanonicalHost(server);
+ }
+}
+
+void HttpServerPropertiesImpl::RemoveAlternateProtocol(
+ const HostPortPair& server,
+ const AlternateProtocolInfo& alternate_protocol) {
+ AlternateProtocolMap::iterator alternate_protocols =
+ alternate_protocol_map_.Peek(server);
+ if (alternate_protocols == alternate_protocol_map_.end()) {
+ return;
+ }
+ for (AlternateProtocols::iterator it = alternate_protocols->second.begin();
+ it != alternate_protocols->second.end(); ++it) {
+ if (it->EqualsModuloProbability(alternate_protocol)) {
+ alternate_protocols->second.erase(it);
+ break;
+ }
+ }
+ if (alternate_protocols->second.size() == 0) {
+ alternate_protocol_map_.Erase(alternate_protocols);
+ RemoveCanonicalHost(server);
+ }
+}
+
const AlternateProtocolMap&
HttpServerPropertiesImpl::alternate_protocol_map() const {
return alternate_protocol_map_;
@@ -509,13 +590,17 @@ void HttpServerPropertiesImpl::RemoveCanonicalHost(
void HttpServerPropertiesImpl::ExpireBrokenAlternateProtocolMappings() {
base::TimeTicks now = base::TimeTicks::Now();
while (!broken_alternate_protocol_list_.empty()) {
- BrokenAlternateProtocolEntry entry =
+ BrokenAlternateProtocolEntryWithTime entry_with_time =
broken_alternate_protocol_list_.front();
- if (now < entry.when) {
+ if (now < entry_with_time.when) {
break;
}
- ClearAlternateProtocol(entry.server);
+ const BrokenAlternateProtocolEntry& entry =
+ entry_with_time.broken_alternate_protocol_entry;
+ const AlternateProtocolInfo alternate_protocol(entry.port, entry.protocol,
+ 1.0);
+ RemoveAlternateProtocol(entry.server, alternate_protocol);
broken_alternate_protocol_list_.pop_front();
}
ScheduleBrokenAlternateProtocolMappingsExpiration();
« no previous file with comments | « net/http/http_server_properties_impl.h ('k') | net/http/http_server_properties_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698