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

Side by Side Diff: net/http/http_server_properties.cc

Issue 2496953002: Revert of Unify enum NextProto and enum AlternateProtocol. (Closed)
Patch Set: Created 4 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « net/http/http_server_properties.h ('k') | net/http/http_server_properties_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/http/http_server_properties.h" 5 #include "net/http/http_server_properties.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/metrics/histogram_macros.h" 8 #include "base/metrics/histogram_macros.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "net/socket/ssl_client_socket.h" 10 #include "net/socket/ssl_client_socket.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 ALTERNATE_PROTOCOL_USAGE_MAX); 56 ALTERNATE_PROTOCOL_USAGE_MAX);
57 } 57 }
58 } 58 }
59 59
60 void HistogramBrokenAlternateProtocolLocation( 60 void HistogramBrokenAlternateProtocolLocation(
61 BrokenAlternateProtocolLocation location){ 61 BrokenAlternateProtocolLocation location){
62 UMA_HISTOGRAM_ENUMERATION("Net.AlternateProtocolBrokenLocation", location, 62 UMA_HISTOGRAM_ENUMERATION("Net.AlternateProtocolBrokenLocation", location,
63 BROKEN_ALTERNATE_PROTOCOL_LOCATION_MAX); 63 BROKEN_ALTERNATE_PROTOCOL_LOCATION_MAX);
64 } 64 }
65 65
66 bool IsAlternateProtocolValid(NextProto protocol) { 66 bool IsAlternateProtocolValid(AlternateProtocol protocol) {
67 switch (protocol) { 67 switch (protocol) {
68 case kProtoUnknown: 68 case NPN_HTTP_2:
69 return true;
70 case QUIC:
71 return true;
72 case UNINITIALIZED_ALTERNATE_PROTOCOL:
69 return false; 73 return false;
70 case kProtoHTTP11:
71 return false;
72 case kProtoHTTP2:
73 return true;
74 case kProtoQUIC:
75 return true;
76 } 74 }
77 NOTREACHED(); 75 NOTREACHED();
78 return false; 76 return false;
79 } 77 }
80 78
79 const char* AlternateProtocolToString(AlternateProtocol protocol) {
80 switch (protocol) {
81 case QUIC:
82 return "quic";
83 case NPN_HTTP_2:
84 return "h2";
85 case UNINITIALIZED_ALTERNATE_PROTOCOL:
86 return "Uninitialized";
87 }
88 NOTREACHED();
89 return "";
90 }
91
92 AlternateProtocol AlternateProtocolFromString(const std::string& str) {
93 if (str == "quic")
94 return QUIC;
95 if (str == "h2")
96 return NPN_HTTP_2;
97 // "npn-h2" and "npn-spdy/3.1" are accepted here so that persisted settings
98 // with the old string can be loaded from disk. TODO(bnc): Remove around
99 // 2016 December.
100 if (str == "npn-h2")
101 return NPN_HTTP_2;
102 if (str == "npn-spdy/3.1")
103 return NPN_HTTP_2;
104
105 return UNINITIALIZED_ALTERNATE_PROTOCOL;
106 }
107
108 AlternateProtocol AlternateProtocolFromNextProto(NextProto next_proto) {
109 switch (next_proto) {
110 case kProtoHTTP2:
111 return NPN_HTTP_2;
112 case kProtoQUIC:
113 return QUIC;
114
115 case kProtoUnknown:
116 case kProtoHTTP11:
117 break;
118 }
119
120 NOTREACHED() << "Invalid NextProto: " << next_proto;
121 return UNINITIALIZED_ALTERNATE_PROTOCOL;
122 }
123
81 std::string AlternativeService::ToString() const { 124 std::string AlternativeService::ToString() const {
82 return base::StringPrintf("%s %s:%d", NextProtoToString(protocol), 125 return base::StringPrintf("%s %s:%d", AlternateProtocolToString(protocol),
83 host.c_str(), port); 126 host.c_str(), port);
84 } 127 }
85 128
86 std::string AlternativeServiceInfo::ToString() const { 129 std::string AlternativeServiceInfo::ToString() const {
87 base::Time::Exploded exploded; 130 base::Time::Exploded exploded;
88 expiration.LocalExplode(&exploded); 131 expiration.LocalExplode(&exploded);
89 return base::StringPrintf( 132 return base::StringPrintf(
90 "%s, expires %04d-%02d-%02d %02d:%02d:%02d", 133 "%s, expires %04d-%02d-%02d %02d:%02d:%02d",
91 alternative_service.ToString().c_str(), exploded.year, exploded.month, 134 alternative_service.ToString().c_str(), exploded.year, exploded.month,
92 exploded.day_of_month, exploded.hour, exploded.minute, exploded.second); 135 exploded.day_of_month, exploded.hour, exploded.minute, exploded.second);
93 } 136 }
94 137
95 // static 138 // static
96 void HttpServerProperties::ForceHTTP11(SSLConfig* ssl_config) { 139 void HttpServerProperties::ForceHTTP11(SSLConfig* ssl_config) {
97 ssl_config->alpn_protos.clear(); 140 ssl_config->alpn_protos.clear();
98 ssl_config->alpn_protos.push_back(kProtoHTTP11); 141 ssl_config->alpn_protos.push_back(kProtoHTTP11);
99 } 142 }
100 143
101 } // namespace net 144 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties.h ('k') | net/http/http_server_properties_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698