| 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 103d0e1eaa36dad0eb2ab29c6f257bf2ec653ccd..e80603d7b314ec57cb315ac9bed94b7edf65c78f 100644
|
| --- a/net/http/http_server_properties_impl.cc
|
| +++ b/net/http/http_server_properties_impl.cc
|
| @@ -49,14 +49,23 @@ void HttpServerPropertiesImpl::InitializeSpdyServers(
|
|
|
| void HttpServerPropertiesImpl::InitializeAlternateProtocolServers(
|
| AlternateProtocolMap* alternate_protocol_map) {
|
| - // Keep all the ALTERNATE_PROTOCOL_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.protocol != ALTERNATE_PROTOCOL_BROKEN) {
|
| - alternate_protocol_map_.Erase(old_it);
|
| + for (AlternateProtocolMap::iterator alternate_protocols =
|
| + alternate_protocol_map_.begin();
|
| + alternate_protocols != alternate_protocol_map_.end();) {
|
| + // Keep all the ALTERNATE_PROTOCOL_BROKEN ones since those don't get
|
| + // persisted.
|
| + for (AlternateProtocols::iterator it = alternate_protocols->second.begin();
|
| + it != alternate_protocols->second.end();) {
|
| + if (it->protocol != ALTERNATE_PROTOCOL_BROKEN) {
|
| + it = alternate_protocols->second.erase(it);
|
| + } else {
|
| + ++it;
|
| + }
|
| + }
|
| + if (alternate_protocols->second.size() == 0) {
|
| + alternate_protocols = alternate_protocol_map_.Erase(alternate_protocols);
|
| + } else {
|
| + ++alternate_protocols;
|
| }
|
| }
|
|
|
| @@ -138,21 +147,20 @@ std::string HttpServerPropertiesImpl::GetFlattenedSpdyServer(
|
| return spdy_server;
|
| }
|
|
|
| -static const AlternateProtocolInfo* g_forced_alternate_protocol = NULL;
|
| +static AlternateProtocols* g_forced_alternate_protocol =
|
| + new AlternateProtocols();
|
|
|
| // static
|
| void HttpServerPropertiesImpl::ForceAlternateProtocol(
|
| const AlternateProtocolInfo& info) {
|
| + DisableForcedAlternateProtocol();
|
| // Note: we're going to leak this.
|
| - if (g_forced_alternate_protocol)
|
| - delete g_forced_alternate_protocol;
|
| - g_forced_alternate_protocol = new AlternateProtocolInfo(info);
|
| + g_forced_alternate_protocol->push_back(info);
|
| }
|
|
|
| // static
|
| void HttpServerPropertiesImpl::DisableForcedAlternateProtocol() {
|
| - delete g_forced_alternate_protocol;
|
| - g_forced_alternate_protocol = NULL;
|
| + g_forced_alternate_protocol->clear();
|
| }
|
|
|
| base::WeakPtr<HttpServerProperties> HttpServerPropertiesImpl::GetWeakPtr() {
|
| @@ -202,12 +210,20 @@ void HttpServerPropertiesImpl::SetSupportsSpdy(
|
|
|
| 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() &&
|
| - it->second.probability >= alternate_protocol_probability_threshold_) {
|
| + if (!g_forced_alternate_protocol->empty())
|
| return true;
|
| + AlternateProtocolMap::const_iterator alternate_protocols =
|
| + alternate_protocol_map_.Get(server);
|
| + if (alternate_protocols != alternate_protocol_map_.end()) {
|
| + for (AlternateProtocols::const_iterator alternate_protocol =
|
| + alternate_protocols->second.begin();
|
| + alternate_protocol != alternate_protocols->second.end();
|
| + alternate_protocol++) {
|
| + if (alternate_protocol->probability >=
|
| + alternate_protocol_probability_threshold_) {
|
| + return true;
|
| + }
|
| + }
|
| }
|
|
|
| return GetCanonicalHost(server) != canonical_host_to_origin_map_.end();
|
| @@ -226,8 +242,7 @@ std::string HttpServerPropertiesImpl::GetCanonicalSuffix(
|
| return std::string();
|
| }
|
|
|
| -AlternateProtocolInfo
|
| -HttpServerPropertiesImpl::GetAlternateProtocol(
|
| +const AlternateProtocols& HttpServerPropertiesImpl::GetAlternateProtocols(
|
| const HostPortPair& server) {
|
| DCHECK(HasAlternateProtocol(server));
|
|
|
| @@ -242,11 +257,11 @@ HttpServerPropertiesImpl::GetAlternateProtocol(
|
| return alternate_protocol_map_.Get(canonical_host->second)->second;
|
|
|
| // We must be forcing an alternate.
|
| - DCHECK(g_forced_alternate_protocol);
|
| + DCHECK(!g_forced_alternate_protocol->empty());
|
| return *g_forced_alternate_protocol;
|
| }
|
|
|
| -void HttpServerPropertiesImpl::SetAlternateProtocol(
|
| +void HttpServerPropertiesImpl::AddAlternateProtocol(
|
| const HostPortPair& server,
|
| uint16 alternate_port,
|
| AlternateProtocol alternate_protocol,
|
| @@ -259,27 +274,39 @@ void HttpServerPropertiesImpl::SetAlternateProtocol(
|
| AlternateProtocolInfo alternate(alternate_port,
|
| alternate_protocol,
|
| alternate_probability);
|
| - if (HasAlternateProtocol(server)) {
|
| - const AlternateProtocolInfo existing_alternate =
|
| - GetAlternateProtocol(server);
|
| -
|
| - if (existing_alternate.protocol == ALTERNATE_PROTOCOL_BROKEN) {
|
| - DVLOG(1) << "Ignore alternate protocol since it's known to be broken.";
|
| - return;
|
| + // Do not call HasAlternateProtocol(), because we don't care about
|
| + // |g_forced_alternate_protocol|, or whether the alternate protocol
|
| + // probability is higher than the threshold.
|
| + AlternateProtocolMap::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->EqualsModuloProbabilityAndProtocol(alternate)) {
|
| + break;
|
| + }
|
| }
|
|
|
| - if (alternate_protocol != ALTERNATE_PROTOCOL_BROKEN &&
|
| - !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->protocol == ALTERNATE_PROTOCOL_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
|
| @@ -287,10 +314,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) {
|
| @@ -304,16 +331,26 @@ void HttpServerPropertiesImpl::SetAlternateProtocol(
|
| }
|
|
|
| void HttpServerPropertiesImpl::SetBrokenAlternateProtocol(
|
| - const HostPortPair& server) {
|
| - AlternateProtocolMap::iterator it = alternate_protocol_map_.Get(server);
|
| - if (it != alternate_protocol_map_.end()) {
|
| - it->second.protocol = ALTERNATE_PROTOCOL_BROKEN;
|
| - } else {
|
| - AlternateProtocolInfo alternate(server.port(),
|
| - ALTERNATE_PROTOCOL_BROKEN,
|
| - 1);
|
| - alternate_protocol_map_.Put(server, alternate);
|
| + const HostPortPair& server,
|
| + const AlternateProtocolInfo& broken_alternate_protocol) {
|
| + 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->protocol = ALTERNATE_PROTOCOL_BROKEN;
|
| + break;
|
| + }
|
| }
|
| + DCHECK(it != alternate_protocols->second.end());
|
| +
|
| int count = ++broken_alternate_protocol_map_[server];
|
| base::TimeDelta delay =
|
| base::TimeDelta::FromSeconds(kBrokenAlternateProtocolDelaySecs);
|
| @@ -322,37 +359,62 @@ void HttpServerPropertiesImpl::SetBrokenAlternateProtocol(
|
| entry.when = base::TimeTicks::Now() + delay * (1 << (count - 1));
|
| broken_alternate_protocol_list_.push_back(entry);
|
|
|
| - // Do not leave this host as canonical so that we don't infer the other
|
| - // hosts are also broken without testing them first.
|
| + // 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) {
|
| + const HostPortPair& server,
|
| + const AlternateProtocolInfo& alternate_protocol) {
|
| return ContainsKey(broken_alternate_protocol_map_, server);
|
| }
|
|
|
| void HttpServerPropertiesImpl::ConfirmAlternateProtocol(
|
| - const HostPortPair& server) {
|
| + const HostPortPair& server,
|
| + const AlternateProtocolInfo& alternate_protocol) {
|
| broken_alternate_protocol_map_.erase(server);
|
| }
|
|
|
| void HttpServerPropertiesImpl::ClearAlternateProtocol(
|
| const HostPortPair& server) {
|
| AlternateProtocolMap::iterator it = alternate_protocol_map_.Peek(server);
|
| - if (it != alternate_protocol_map_.end())
|
| + if (it != alternate_protocol_map_.end()) {
|
| alternate_protocol_map_.Erase(it);
|
| + }
|
|
|
| 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();) {
|
| + if (it->Equals(alternate_protocol)) {
|
| + it = alternate_protocols->second.erase(it);
|
| + break;
|
| + } else {
|
| + ++it;
|
| + }
|
| + }
|
| + 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_;
|
|
|