| OLD | NEW |
| 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", "npn-spdy/3", "npn-spdy/3.1", |
| 21 "npn-spdy/3", | 21 "npn-h2-11", // HTTP/2 draft 11. Called SPDY4 internally. |
| 22 "npn-spdy/3.1", | 22 "quic"}; |
| 23 "npn-h2-11", // HTTP/2 draft 11. Called SPDY4 internally. | |
| 24 "quic" | |
| 25 }; | |
| 26 const char kBrokenAlternateProtocol[] = "Broken"; | 23 const char kBrokenAlternateProtocol[] = "Broken"; |
| 27 | 24 |
| 28 COMPILE_ASSERT( | 25 COMPILE_ASSERT( |
| 29 arraysize(kAlternateProtocolStrings) == NUM_VALID_ALTERNATE_PROTOCOLS, | 26 arraysize(kAlternateProtocolStrings) == NUM_VALID_ALTERNATE_PROTOCOLS, |
| 30 kAlternateProtocolStringsSize_kNumValidAlternateProtocols_not_equal); | 27 kAlternateProtocolStringsSize_kNumValidAlternateProtocols_not_equal); |
| 31 | 28 |
| 32 } // namespace | 29 } // namespace |
| 33 | 30 |
| 34 void HistogramAlternateProtocolUsage(AlternateProtocolUsage usage) { | 31 void HistogramAlternateProtocolUsage(AlternateProtocolUsage usage) { |
| 35 UMA_HISTOGRAM_ENUMERATION("Net.AlternateProtocolUsage", usage, | 32 UMA_HISTOGRAM_ENUMERATION( |
| 36 ALTERNATE_PROTOCOL_USAGE_MAX); | 33 "Net.AlternateProtocolUsage", usage, ALTERNATE_PROTOCOL_USAGE_MAX); |
| 37 } | 34 } |
| 38 | 35 |
| 39 void HistogramBrokenAlternateProtocolLocation( | 36 void HistogramBrokenAlternateProtocolLocation( |
| 40 BrokenAlternateProtocolLocation location){ | 37 BrokenAlternateProtocolLocation location) { |
| 41 UMA_HISTOGRAM_ENUMERATION("Net.AlternateProtocolBrokenLocation", location, | 38 UMA_HISTOGRAM_ENUMERATION("Net.AlternateProtocolBrokenLocation", |
| 39 location, |
| 42 BROKEN_ALTERNATE_PROTOCOL_LOCATION_MAX); | 40 BROKEN_ALTERNATE_PROTOCOL_LOCATION_MAX); |
| 43 } | 41 } |
| 44 | 42 |
| 45 bool IsAlternateProtocolValid(AlternateProtocol protocol) { | 43 bool IsAlternateProtocolValid(AlternateProtocol protocol) { |
| 46 return protocol >= ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION && | 44 return protocol >= ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION && |
| 47 protocol <= ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION; | 45 protocol <= ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION; |
| 48 } | 46 } |
| 49 | 47 |
| 50 const char* AlternateProtocolToString(AlternateProtocol protocol) { | 48 const char* AlternateProtocolToString(AlternateProtocol protocol) { |
| 51 switch (protocol) { | 49 switch (protocol) { |
| 52 case DEPRECATED_NPN_SPDY_2: | 50 case DEPRECATED_NPN_SPDY_2: |
| 53 case NPN_SPDY_3: | 51 case NPN_SPDY_3: |
| 54 case NPN_SPDY_3_1: | 52 case NPN_SPDY_3_1: |
| 55 case NPN_SPDY_4: | 53 case NPN_SPDY_4: |
| 56 case QUIC: | 54 case QUIC: |
| 57 DCHECK(IsAlternateProtocolValid(protocol)); | 55 DCHECK(IsAlternateProtocolValid(protocol)); |
| 58 return kAlternateProtocolStrings[ | 56 return kAlternateProtocolStrings |
| 59 protocol - ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION]; | 57 [protocol - ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION]; |
| 60 case ALTERNATE_PROTOCOL_BROKEN: | 58 case ALTERNATE_PROTOCOL_BROKEN: |
| 61 return kBrokenAlternateProtocol; | 59 return kBrokenAlternateProtocol; |
| 62 case UNINITIALIZED_ALTERNATE_PROTOCOL: | 60 case UNINITIALIZED_ALTERNATE_PROTOCOL: |
| 63 return "Uninitialized"; | 61 return "Uninitialized"; |
| 64 } | 62 } |
| 65 NOTREACHED(); | 63 NOTREACHED(); |
| 66 return ""; | 64 return ""; |
| 67 } | 65 } |
| 68 | 66 |
| 69 AlternateProtocol AlternateProtocolFromString(const std::string& str) { | 67 AlternateProtocol AlternateProtocolFromString(const std::string& str) { |
| 70 for (int i = ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION; | 68 for (int i = ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION; |
| 71 i <= ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION; ++i) { | 69 i <= ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION; |
| 70 ++i) { |
| 72 AlternateProtocol protocol = static_cast<AlternateProtocol>(i); | 71 AlternateProtocol protocol = static_cast<AlternateProtocol>(i); |
| 73 if (str == AlternateProtocolToString(protocol)) | 72 if (str == AlternateProtocolToString(protocol)) |
| 74 return protocol; | 73 return protocol; |
| 75 } | 74 } |
| 76 if (str == kBrokenAlternateProtocol) | 75 if (str == kBrokenAlternateProtocol) |
| 77 return ALTERNATE_PROTOCOL_BROKEN; | 76 return ALTERNATE_PROTOCOL_BROKEN; |
| 78 return UNINITIALIZED_ALTERNATE_PROTOCOL; | 77 return UNINITIALIZED_ALTERNATE_PROTOCOL; |
| 79 } | 78 } |
| 80 | 79 |
| 81 AlternateProtocol AlternateProtocolFromNextProto(NextProto next_proto) { | 80 AlternateProtocol AlternateProtocolFromNextProto(NextProto next_proto) { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 94 case kProtoUnknown: | 93 case kProtoUnknown: |
| 95 case kProtoHTTP11: | 94 case kProtoHTTP11: |
| 96 break; | 95 break; |
| 97 } | 96 } |
| 98 | 97 |
| 99 NOTREACHED() << "Invalid NextProto: " << next_proto; | 98 NOTREACHED() << "Invalid NextProto: " << next_proto; |
| 100 return UNINITIALIZED_ALTERNATE_PROTOCOL; | 99 return UNINITIALIZED_ALTERNATE_PROTOCOL; |
| 101 } | 100 } |
| 102 | 101 |
| 103 std::string PortAlternateProtocolPair::ToString() const { | 102 std::string PortAlternateProtocolPair::ToString() const { |
| 104 return base::StringPrintf("%d:%s", port, | 103 return base::StringPrintf("%d:%s", port, AlternateProtocolToString(protocol)); |
| 105 AlternateProtocolToString(protocol)); | |
| 106 } | 104 } |
| 107 | 105 |
| 108 } // namespace net | 106 } // namespace net |
| OLD | NEW |