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

Unified Diff: net/http/http_server_properties.cc

Issue 2129973002: Serialize NPN_HTTP_2 as "h2" instead of "npn-h2". (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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.cc
diff --git a/net/http/http_server_properties.cc b/net/http/http_server_properties.cc
index cea3032f0d108b9246a5c43f477958d9ba8e8a61..98cf6c88eb3775c02cd5fe6141336570dffd4645 100644
--- a/net/http/http_server_properties.cc
+++ b/net/http/http_server_properties.cc
@@ -14,21 +14,6 @@ namespace net {
const char kAlternativeServiceHeader[] = "Alt-Svc";
-namespace {
-
-// The order of these strings much match the order of the enum definition
-// for AlternateProtocol.
-const char* const kAlternateProtocolStrings[] = {
- "npn-spdy/3.1",
- "npn-h2",
- "quic"};
-
-static_assert(arraysize(kAlternateProtocolStrings) ==
- NUM_VALID_ALTERNATE_PROTOCOLS,
- "kAlternateProtocolStrings has incorrect size");
-
-} // namespace
-
void HistogramAlternateProtocolUsage(AlternateProtocolUsage usage) {
UMA_HISTOGRAM_ENUMERATION("Net.AlternateProtocolUsage", usage,
ALTERNATE_PROTOCOL_USAGE_MAX);
@@ -47,12 +32,12 @@ bool IsAlternateProtocolValid(AlternateProtocol protocol) {
const char* AlternateProtocolToString(AlternateProtocol protocol) {
switch (protocol) {
- case NPN_SPDY_3_1:
- case NPN_HTTP_2:
case QUIC:
- DCHECK(IsAlternateProtocolValid(protocol));
- return kAlternateProtocolStrings[
- protocol - ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION];
+ return "quic";
+ case NPN_HTTP_2:
+ return "h2";
+ case NPN_SPDY_3_1:
+ return "npn-spdy/3.1";
case UNINITIALIZED_ALTERNATE_PROTOCOL:
return "Uninitialized";
}
@@ -61,12 +46,17 @@ const char* AlternateProtocolToString(AlternateProtocol protocol) {
}
AlternateProtocol AlternateProtocolFromString(const std::string& str) {
- for (int i = ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION;
- i <= ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION; ++i) {
- AlternateProtocol protocol = static_cast<AlternateProtocol>(i);
- if (str == AlternateProtocolToString(protocol))
- return protocol;
- }
+ if (str == "quic")
+ return QUIC;
+ if (str == "h2")
+ return NPN_HTTP_2;
+ // "npn-h2" is accepted here so that persisted settings with the old string
+ // can be loaded from disk. TODO(bnc): Remove around 2016 December.
+ if (str == "npn-h2")
+ return NPN_HTTP_2;
+ if (str == "npn-spdy/3.1")
+ return NPN_SPDY_3_1;
+
return UNINITIALIZED_ALTERNATE_PROTOCOL;
}

Powered by Google App Engine
This is Rietveld 408576698