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

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

Issue 701163002: Introduce AlternateProtocolInfo.is_broken. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Nit. Created 6 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.h" 8 #include "base/metrics/histogram.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 10
11 namespace net { 11 namespace net {
12 12
13 const char kAlternateProtocolHeader[] = "Alternate-Protocol"; 13 const char kAlternateProtocolHeader[] = "Alternate-Protocol";
14 14
15 namespace { 15 namespace {
16 16
17 // The order of these strings much match the order of the enum definition 17 // The order of these strings much match the order of the enum definition
18 // for AlternateProtocol. 18 // for AlternateProtocol.
19 const char* const kAlternateProtocolStrings[] = { 19 const char* const kAlternateProtocolStrings[] = {
20 "npn-spdy/2", 20 "npn-spdy/2",
21 "npn-spdy/3", 21 "npn-spdy/3",
22 "npn-spdy/3.1", 22 "npn-spdy/3.1",
23 "npn-h2-14", // HTTP/2 draft 14. Called SPDY4 internally. 23 "npn-h2-14", // HTTP/2 draft 14. Called SPDY4 internally.
24 "quic" 24 "quic"
25 }; 25 };
26 const char kBrokenAlternateProtocol[] = "Broken";
27 26
28 COMPILE_ASSERT( 27 COMPILE_ASSERT(
29 arraysize(kAlternateProtocolStrings) == NUM_VALID_ALTERNATE_PROTOCOLS, 28 arraysize(kAlternateProtocolStrings) == NUM_VALID_ALTERNATE_PROTOCOLS,
30 kAlternateProtocolStringsSize_kNumValidAlternateProtocols_not_equal); 29 kAlternateProtocolStringsSize_kNumValidAlternateProtocols_not_equal);
31 30
32 } // namespace 31 } // namespace
33 32
34 void HistogramAlternateProtocolUsage(AlternateProtocolUsage usage) { 33 void HistogramAlternateProtocolUsage(AlternateProtocolUsage usage) {
35 UMA_HISTOGRAM_ENUMERATION("Net.AlternateProtocolUsage", usage, 34 UMA_HISTOGRAM_ENUMERATION("Net.AlternateProtocolUsage", usage,
36 ALTERNATE_PROTOCOL_USAGE_MAX); 35 ALTERNATE_PROTOCOL_USAGE_MAX);
(...skipping 13 matching lines...) Expand all
50 const char* AlternateProtocolToString(AlternateProtocol protocol) { 49 const char* AlternateProtocolToString(AlternateProtocol protocol) {
51 switch (protocol) { 50 switch (protocol) {
52 case DEPRECATED_NPN_SPDY_2: 51 case DEPRECATED_NPN_SPDY_2:
53 case NPN_SPDY_3: 52 case NPN_SPDY_3:
54 case NPN_SPDY_3_1: 53 case NPN_SPDY_3_1:
55 case NPN_SPDY_4: 54 case NPN_SPDY_4:
56 case QUIC: 55 case QUIC:
57 DCHECK(IsAlternateProtocolValid(protocol)); 56 DCHECK(IsAlternateProtocolValid(protocol));
58 return kAlternateProtocolStrings[ 57 return kAlternateProtocolStrings[
59 protocol - ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION]; 58 protocol - ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION];
60 case ALTERNATE_PROTOCOL_BROKEN:
61 return kBrokenAlternateProtocol;
62 case UNINITIALIZED_ALTERNATE_PROTOCOL: 59 case UNINITIALIZED_ALTERNATE_PROTOCOL:
63 return "Uninitialized"; 60 return "Uninitialized";
64 } 61 }
65 NOTREACHED(); 62 NOTREACHED();
66 return ""; 63 return "";
67 } 64 }
68 65
69 AlternateProtocol AlternateProtocolFromString(const std::string& str) { 66 AlternateProtocol AlternateProtocolFromString(const std::string& str) {
70 for (int i = ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION; 67 for (int i = ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION;
71 i <= ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION; ++i) { 68 i <= ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION; ++i) {
72 AlternateProtocol protocol = static_cast<AlternateProtocol>(i); 69 AlternateProtocol protocol = static_cast<AlternateProtocol>(i);
73 if (str == AlternateProtocolToString(protocol)) 70 if (str == AlternateProtocolToString(protocol))
74 return protocol; 71 return protocol;
75 } 72 }
76 if (str == kBrokenAlternateProtocol)
77 return ALTERNATE_PROTOCOL_BROKEN;
78 return UNINITIALIZED_ALTERNATE_PROTOCOL; 73 return UNINITIALIZED_ALTERNATE_PROTOCOL;
79 } 74 }
80 75
81 AlternateProtocol AlternateProtocolFromNextProto(NextProto next_proto) { 76 AlternateProtocol AlternateProtocolFromNextProto(NextProto next_proto) {
82 switch (next_proto) { 77 switch (next_proto) {
83 case kProtoDeprecatedSPDY2: 78 case kProtoDeprecatedSPDY2:
84 return DEPRECATED_NPN_SPDY_2; 79 return DEPRECATED_NPN_SPDY_2;
85 case kProtoSPDY3: 80 case kProtoSPDY3:
86 return NPN_SPDY_3; 81 return NPN_SPDY_3;
87 case kProtoSPDY31: 82 case kProtoSPDY31:
88 return NPN_SPDY_3_1; 83 return NPN_SPDY_3_1;
89 case kProtoSPDY4: 84 case kProtoSPDY4:
90 return NPN_SPDY_4; 85 return NPN_SPDY_4;
91 case kProtoQUIC1SPDY3: 86 case kProtoQUIC1SPDY3:
92 return QUIC; 87 return QUIC;
93 88
94 case kProtoUnknown: 89 case kProtoUnknown:
95 case kProtoHTTP11: 90 case kProtoHTTP11:
96 break; 91 break;
97 } 92 }
98 93
99 NOTREACHED() << "Invalid NextProto: " << next_proto; 94 NOTREACHED() << "Invalid NextProto: " << next_proto;
100 return UNINITIALIZED_ALTERNATE_PROTOCOL; 95 return UNINITIALIZED_ALTERNATE_PROTOCOL;
101 } 96 }
102 97
103 std::string AlternateProtocolInfo::ToString() const { 98 std::string AlternateProtocolInfo::ToString() const {
104 return base::StringPrintf("%d:%s p=%f", port, 99 return base::StringPrintf("%d:%s p=%f%s", port,
105 AlternateProtocolToString(protocol), 100 AlternateProtocolToString(protocol),
106 probability); 101 probability,
102 is_broken ? " (broken)" : "");
107 } 103 }
108 104
109 } // namespace net 105 } // 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