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

Unified Diff: net/http/http_server_properties_impl.cc

Issue 1878143005: SHP 4: Change AlternativeServiceMap to use SchemeHostPort as the key. No change to Pref data. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@SHP_3
Patch Set: fix a comment Created 4 years, 8 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
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 b2c2c572e7f7d307fc92c2b87bfae32c6755c3ca..52a6e80a6609d8f9ebd991c8f9a9fca4d50e07fa 100644
--- a/net/http/http_server_properties_impl.cc
+++ b/net/http/http_server_properties_impl.cc
@@ -105,29 +105,29 @@ void HttpServerPropertiesImpl::InitializeAlternativeServiceServers(
}
}
- // Attempt to find canonical servers.
- uint16_t canonical_ports[] = {80, 443};
+ // Attempt to find canonical servers. Canonical suffix only apply to HTTPS.
Ryan Hamilton 2016/04/18 17:18:40 Does this represent a behavior change? If so, is t
Zhongyi Shi 2016/04/18 19:26:37 According to our discussion (https://codereview.ch
+ uint16_t canonical_ports = 443;
Ryan Hamilton 2016/04/18 17:18:40 Since this is a single port, you could say _port i
Zhongyi Shi 2016/04/18 19:26:37 Done.
for (size_t i = 0; i < canonical_suffixes_.size(); ++i) {
std::string canonical_suffix = canonical_suffixes_[i];
- for (size_t j = 0; j < arraysize(canonical_ports); ++j) {
- HostPortPair canonical_host(canonical_suffix, canonical_ports[j]);
- // If we already have a valid canonical server, we're done.
- if (ContainsKey(canonical_host_to_origin_map_, canonical_host) &&
- (alternative_service_map_.Peek(
- canonical_host_to_origin_map_[canonical_host]) !=
- alternative_service_map_.end())) {
- continue;
- }
- // Now attempt to find a server which matches this origin and set it as
- // canonical.
- for (AlternativeServiceMap::const_iterator it =
- alternative_service_map_.begin();
- it != alternative_service_map_.end(); ++it) {
- if (base::EndsWith(it->first.host(), canonical_suffixes_[i],
- base::CompareCase::INSENSITIVE_ASCII)) {
- canonical_host_to_origin_map_[canonical_host] = it->first;
- break;
- }
+ url::SchemeHostPort canonical_host("https", canonical_suffix,
Ryan Hamilton 2016/04/18 17:18:40 nit s/_host/_server/?
Zhongyi Shi 2016/04/18 19:26:37 Done.
+ canonical_ports);
+ // If we already have a valid canonical server, we're done.
+ if (ContainsKey(canonical_host_to_origin_map_, canonical_host) &&
+ (alternative_service_map_.Peek(
+ canonical_host_to_origin_map_[canonical_host]) !=
+ alternative_service_map_.end())) {
+ continue;
+ }
+ // Now attempt to find a server which matches this origin and set it as
+ // canonical.
+ for (AlternativeServiceMap::const_iterator it =
+ alternative_service_map_.begin();
+ it != alternative_service_map_.end(); ++it) {
+ if (base::EndsWith(it->first.host(), canonical_suffixes_[i],
+ base::CompareCase::INSENSITIVE_ASCII) &&
+ it->first.scheme() == "https") {
Ryan Hamilton 2016/04/18 17:18:40 nit: instead of checking https here, you can use c
Zhongyi Shi 2016/04/18 19:26:37 Done.
+ canonical_host_to_origin_map_[canonical_host] = it->first;
+ break;
}
}
}
@@ -236,7 +236,6 @@ void HttpServerPropertiesImpl::Clear() {
bool HttpServerPropertiesImpl::SupportsRequestPriority(
const url::SchemeHostPort& server) {
- HostPortPair host_port_pair(server.host(), server.port());
DCHECK(CalledOnValidThread());
if (server.host().empty())
return false;
@@ -244,7 +243,7 @@ bool HttpServerPropertiesImpl::SupportsRequestPriority(
if (GetSupportsSpdy(server))
return true;
const AlternativeServiceVector alternative_service_vector =
- GetAlternativeServices(host_port_pair);
+ GetAlternativeServices(server);
for (const AlternativeService& alternative_service :
alternative_service_vector) {
if (alternative_service.protocol == QUIC) {
@@ -322,7 +321,8 @@ std::string HttpServerPropertiesImpl::GetCanonicalSuffix(
}
AlternativeServiceVector HttpServerPropertiesImpl::GetAlternativeServices(
- const HostPortPair& origin) {
+ const url::SchemeHostPort& origin) {
+ HostPortPair host_port_pair(origin.host(), origin.port());
Ryan Hamilton 2016/04/18 17:18:40 nit: move this down to where it's used.
Zhongyi Shi 2016/04/18 19:26:37 Done.
// Copy valid alternative services into |valid_alternative_services|.
AlternativeServiceVector valid_alternative_services;
const base::Time now = base::Time::Now();
@@ -341,7 +341,7 @@ AlternativeServiceVector HttpServerPropertiesImpl::GetAlternativeServices(
// If the alternative service is equivalent to the origin (same host, same
// port, and both TCP), then there is already a Job for it, so do not
Ryan Hamilton 2016/04/18 17:18:40 nit: Can you change the comment to remove the ment
Zhongyi Shi 2016/04/18 19:26:37 Done.
// return it here.
- if (origin.Equals(alternative_service.host_port_pair()) &&
+ if (host_port_pair.Equals(alternative_service.host_port_pair()) &&
NPN_SPDY_MINIMUM_VERSION <= alternative_service.protocol &&
alternative_service.protocol <= NPN_SPDY_MAXIMUM_VERSION) {
++it;
@@ -392,7 +392,7 @@ AlternativeServiceVector HttpServerPropertiesImpl::GetAlternativeServices(
}
bool HttpServerPropertiesImpl::SetAlternativeService(
- const HostPortPair& origin,
+ const url::SchemeHostPort& origin,
const AlternativeService& alternative_service,
base::Time expiration) {
return SetAlternativeServices(
@@ -402,7 +402,7 @@ bool HttpServerPropertiesImpl::SetAlternativeService(
}
bool HttpServerPropertiesImpl::SetAlternativeServices(
- const HostPortPair& origin,
+ const url::SchemeHostPort& origin,
const AlternativeServiceInfoVector& alternative_service_info_vector) {
AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin);
@@ -440,9 +440,12 @@ bool HttpServerPropertiesImpl::SetAlternativeServices(
// canonical host.
for (size_t i = 0; i < canonical_suffixes_.size(); ++i) {
std::string canonical_suffix = canonical_suffixes_[i];
- if (base::EndsWith(origin.host(), canonical_suffixes_[i],
+ // canonical suffixes only apply to HTTPS.
+ if (origin.scheme() == "https" &&
+ base::EndsWith(origin.host(), canonical_suffixes_[i],
base::CompareCase::INSENSITIVE_ASCII)) {
- HostPortPair canonical_host(canonical_suffix, origin.port());
+ url::SchemeHostPort canonical_host("https", canonical_suffix,
+ origin.port());
canonical_host_to_origin_map_[canonical_host] = origin;
break;
}
@@ -507,7 +510,7 @@ void HttpServerPropertiesImpl::ConfirmAlternativeService(
}
void HttpServerPropertiesImpl::ClearAlternativeServices(
- const HostPortPair& origin) {
+ const url::SchemeHostPort& origin) {
RemoveCanonicalHost(origin);
AlternativeServiceMap::iterator it = alternative_service_map_.Peek(origin);
@@ -528,7 +531,7 @@ HttpServerPropertiesImpl::GetAlternativeServiceInfoAsValue()
scoped_ptr<base::ListValue> dict_list(new base::ListValue);
for (const auto& alternative_service_map_item : alternative_service_map_) {
scoped_ptr<base::ListValue> alternative_service_list(new base::ListValue);
- const HostPortPair& host_port_pair = alternative_service_map_item.first;
+ const url::SchemeHostPort& server = alternative_service_map_item.first;
for (const AlternativeServiceInfo& alternative_service_info :
alternative_service_map_item.second) {
std::string alternative_service_string(
@@ -536,7 +539,7 @@ HttpServerPropertiesImpl::GetAlternativeServiceInfoAsValue()
AlternativeService alternative_service(
alternative_service_info.alternative_service);
if (alternative_service.host.empty()) {
- alternative_service.host = host_port_pair.host();
+ alternative_service.host = server.host();
}
if (IsAlternativeServiceBroken(alternative_service)) {
alternative_service_string.append(" (broken)");
@@ -547,7 +550,7 @@ HttpServerPropertiesImpl::GetAlternativeServiceInfoAsValue()
if (alternative_service_list->empty())
continue;
scoped_ptr<base::DictionaryValue> dict(new base::DictionaryValue());
- dict->SetString("host_port_pair", host_port_pair.ToString());
+ dict->SetString("server", server.Serialize());
dict->Set("alternative_service",
scoped_ptr<base::Value>(std::move(alternative_service_list)));
dict_list->Append(std::move(dict));
@@ -685,7 +688,7 @@ void HttpServerPropertiesImpl::SetMaxServerConfigsStoredInProperties(
AlternativeServiceMap::const_iterator
HttpServerPropertiesImpl::GetAlternateProtocolIterator(
- const HostPortPair& server) {
+ const url::SchemeHostPort& server) {
AlternativeServiceMap::const_iterator it =
alternative_service_map_.Get(server);
if (it != alternative_service_map_.end())
@@ -696,8 +699,8 @@ HttpServerPropertiesImpl::GetAlternateProtocolIterator(
return alternative_service_map_.end();
}
- const HostPortPair canonical_host_port = canonical->second;
- it = alternative_service_map_.Get(canonical_host_port);
+ const url::SchemeHostPort canonical_server = canonical->second;
+ it = alternative_service_map_.Get(canonical_server);
if (it == alternative_service_map_.end()) {
return alternative_service_map_.end();
}
@@ -706,24 +709,29 @@ HttpServerPropertiesImpl::GetAlternateProtocolIterator(
AlternativeService alternative_service(
alternative_service_info.alternative_service);
if (alternative_service.host.empty()) {
- alternative_service.host = canonical_host_port.host();
+ alternative_service.host = canonical_server.host();
}
if (!IsAlternativeServiceBroken(alternative_service)) {
return it;
}
}
- RemoveCanonicalHost(canonical_host_port);
+ RemoveCanonicalHost(canonical_server);
return alternative_service_map_.end();
}
HttpServerPropertiesImpl::CanonicalHostMap::const_iterator
-HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const {
+HttpServerPropertiesImpl::GetCanonicalHost(
+ const url::SchemeHostPort& server) const {
+ if (server.scheme() != "https")
+ return canonical_host_to_origin_map_.end();
+
for (size_t i = 0; i < canonical_suffixes_.size(); ++i) {
std::string canonical_suffix = canonical_suffixes_[i];
if (base::EndsWith(server.host(), canonical_suffixes_[i],
base::CompareCase::INSENSITIVE_ASCII)) {
- HostPortPair canonical_host(canonical_suffix, server.port());
+ url::SchemeHostPort canonical_host("https", canonical_suffix,
+ server.port());
return canonical_host_to_origin_map_.find(canonical_host);
}
}
@@ -732,7 +740,7 @@ HttpServerPropertiesImpl::GetCanonicalHost(HostPortPair server) const {
}
void HttpServerPropertiesImpl::RemoveCanonicalHost(
- const HostPortPair& server) {
+ const url::SchemeHostPort& server) {
CanonicalHostMap::const_iterator canonical = GetCanonicalHost(server);
if (canonical == canonical_host_to_origin_map_.end())
return;

Powered by Google App Engine
This is Rietveld 408576698