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

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

Issue 25956002: [SPDY] Remove references to obsolete SPDY versions SPDY/1 and SPDY/2.1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test Created 7 years, 2 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/http/http_server_properties.h ('k') | net/http/http_server_properties_impl_unittest.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/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 9
10 namespace net { 10 namespace net {
11 11
12 const char kAlternateProtocolHeader[] = "Alternate-Protocol"; 12 const char kAlternateProtocolHeader[] = "Alternate-Protocol";
13 13
14 namespace { 14 namespace {
15 15
16 // The order of these strings much match the order of the enum definition 16 // The order of these strings much match the order of the enum definition
17 // for AlternateProtocol. 17 // for AlternateProtocol.
18 const char* const kAlternateProtocolStrings[] = { 18 const char* const kAlternateProtocolStrings[] = {
19 "npn-spdy/1",
20 "npn-spdy/2", 19 "npn-spdy/2",
21 "npn-spdy/3", 20 "npn-spdy/3",
22 "npn-spdy/3.1", 21 "npn-spdy/3.1",
23 "npn-spdy/4a2", 22 "npn-spdy/4a2",
24 "npn-HTTP-draft-04/2.0", 23 "npn-HTTP-draft-04/2.0",
25 "quic" 24 "quic"
26 }; 25 };
27 const char kBrokenAlternateProtocol[] = "Broken"; 26 const char kBrokenAlternateProtocol[] = "Broken";
28 27
29 COMPILE_ASSERT(arraysize(kAlternateProtocolStrings) == NUM_ALTERNATE_PROTOCOLS, 28 COMPILE_ASSERT(
30 kAlternateProtocolStringsSize_NUM_ALTERNATE_PROTOCOLS_nut_equal); 29 arraysize(kAlternateProtocolStrings) == NUM_VALID_ALTERNATE_PROTOCOLS,
30 kAlternateProtocolStringsSize_kNumValidAlternateProtocols_not_equal);
31 31
32 } // namespace 32 } // namespace
33 33
34 bool IsAlternateProtocolValid(AlternateProtocol protocol) {
35 return protocol >= ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION &&
36 protocol <= ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION;
37 }
38
34 const char* AlternateProtocolToString(AlternateProtocol protocol) { 39 const char* AlternateProtocolToString(AlternateProtocol protocol) {
35 switch (protocol) { 40 switch (protocol) {
36 case NPN_SPDY_1:
37 case NPN_SPDY_2: 41 case NPN_SPDY_2:
38 case NPN_SPDY_3: 42 case NPN_SPDY_3:
39 case NPN_SPDY_3_1: 43 case NPN_SPDY_3_1:
40 case NPN_SPDY_4A2: 44 case NPN_SPDY_4A2:
41 case NPN_HTTP2_DRAFT_04: 45 case NPN_HTTP2_DRAFT_04:
42 case QUIC: 46 case QUIC:
43 DCHECK_LT(static_cast<size_t>(protocol), 47 DCHECK(IsAlternateProtocolValid(protocol));
44 arraysize(kAlternateProtocolStrings)); 48 return kAlternateProtocolStrings[
45 return kAlternateProtocolStrings[protocol]; 49 protocol - ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION];
46 case NUM_ALTERNATE_PROTOCOLS:
47 break;
48 case ALTERNATE_PROTOCOL_BROKEN: 50 case ALTERNATE_PROTOCOL_BROKEN:
49 return kBrokenAlternateProtocol; 51 return kBrokenAlternateProtocol;
50 case UNINITIALIZED_ALTERNATE_PROTOCOL: 52 case UNINITIALIZED_ALTERNATE_PROTOCOL:
51 return "Uninitialized"; 53 return "Uninitialized";
52 } 54 }
53 NOTREACHED(); 55 NOTREACHED();
54 return ""; 56 return "";
55 } 57 }
56 58
57 AlternateProtocol AlternateProtocolFromString(const std::string& protocol) { 59 AlternateProtocol AlternateProtocolFromString(const std::string& str) {
58 for (int i = NPN_SPDY_1; i < NUM_ALTERNATE_PROTOCOLS; ++i) 60 for (int i = ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION;
59 if (protocol == kAlternateProtocolStrings[i]) 61 i <= ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION; ++i) {
60 return static_cast<AlternateProtocol>(i); 62 AlternateProtocol protocol = static_cast<AlternateProtocol>(i);
61 if (protocol == kBrokenAlternateProtocol) 63 if (str == AlternateProtocolToString(protocol))
64 return protocol;
65 }
66 if (str == kBrokenAlternateProtocol)
62 return ALTERNATE_PROTOCOL_BROKEN; 67 return ALTERNATE_PROTOCOL_BROKEN;
63 return UNINITIALIZED_ALTERNATE_PROTOCOL; 68 return UNINITIALIZED_ALTERNATE_PROTOCOL;
64 } 69 }
65 70
66 AlternateProtocol AlternateProtocolFromNextProto(NextProto next_proto) { 71 AlternateProtocol AlternateProtocolFromNextProto(NextProto next_proto) {
67 switch (next_proto) { 72 switch (next_proto) {
68 case kProtoSPDY2: 73 case kProtoSPDY2:
69 return NPN_SPDY_2; 74 return NPN_SPDY_2;
70 case kProtoSPDY3: 75 case kProtoSPDY3:
71 return NPN_SPDY_3; 76 return NPN_SPDY_3;
72 case kProtoSPDY31: 77 case kProtoSPDY31:
73 return NPN_SPDY_3_1; 78 return NPN_SPDY_3_1;
74 case kProtoSPDY4a2: 79 case kProtoSPDY4a2:
75 return NPN_SPDY_4A2; 80 return NPN_SPDY_4A2;
76 case kProtoHTTP2Draft04: 81 case kProtoHTTP2Draft04:
77 return NPN_HTTP2_DRAFT_04; 82 return NPN_HTTP2_DRAFT_04;
78 case kProtoQUIC1SPDY3: 83 case kProtoQUIC1SPDY3:
79 return QUIC; 84 return QUIC;
80 85
81 case kProtoUnknown: 86 case kProtoUnknown:
82 case kProtoHTTP11: 87 case kProtoHTTP11:
83 case kProtoSPDY1:
84 case kProtoSPDY21:
85 break; 88 break;
86 } 89 }
87 90
88 NOTREACHED() << "Invalid NextProto: " << next_proto; 91 NOTREACHED() << "Invalid NextProto: " << next_proto;
89 return UNINITIALIZED_ALTERNATE_PROTOCOL; 92 return UNINITIALIZED_ALTERNATE_PROTOCOL;
90 } 93 }
91 94
92 std::string PortAlternateProtocolPair::ToString() const { 95 std::string PortAlternateProtocolPair::ToString() const {
93 return base::StringPrintf("%d:%s", port, 96 return base::StringPrintf("%d:%s", port,
94 AlternateProtocolToString(protocol)); 97 AlternateProtocolToString(protocol));
95 } 98 }
96 99
97 } // namespace net 100 } // namespace net
OLDNEW
« no previous file with comments | « net/http/http_server_properties.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