| 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 #include "net/socket/ssl_client_socket.h" | 10 #include "net/socket/ssl_client_socket.h" |
| 11 #include "net/ssl/ssl_config.h" | 11 #include "net/ssl/ssl_config.h" |
| 12 | 12 |
| 13 namespace net { | 13 namespace net { |
| 14 | 14 |
| 15 const char kAlternateProtocolHeader[] = "Alternate-Protocol"; | 15 const char kAlternateProtocolHeader[] = "Alternate-Protocol"; |
| 16 | 16 |
| 17 namespace { | 17 namespace { |
| 18 | 18 |
| 19 // The order of these strings much match the order of the enum definition | 19 // The order of these strings much match the order of the enum definition |
| 20 // for AlternateProtocol. | 20 // for AlternateProtocol. |
| 21 const char* const kAlternateProtocolStrings[] = { | 21 const char* const kAlternateProtocolStrings[] = { |
| 22 "npn-spdy/2", | 22 "npn-spdy/2", |
| 23 "npn-spdy/3", | 23 "npn-spdy/3", |
| 24 "npn-spdy/3.1", | 24 "npn-spdy/3.1", |
| 25 "npn-h2-14", // HTTP/2 draft-14. Called SPDY4 internally. | 25 "npn-h2-14", // HTTP/2 draft-14. Called SPDY4 internally. |
| 26 "npn-h2-15", // HTTP/2 draft-15. Called SPDY4 internally. | 26 "npn-h2-15", // HTTP/2 draft-15. Called SPDY4 internally. |
| 27 "quic" | 27 "npn-h2", |
| 28 }; | 28 "quic"}; |
| 29 | 29 |
| 30 static_assert(arraysize(kAlternateProtocolStrings) == | 30 static_assert(arraysize(kAlternateProtocolStrings) == |
| 31 NUM_VALID_ALTERNATE_PROTOCOLS, | 31 NUM_VALID_ALTERNATE_PROTOCOLS, |
| 32 "kAlternateProtocolStrings has incorrect size"); | 32 "kAlternateProtocolStrings has incorrect size"); |
| 33 | 33 |
| 34 } // namespace | 34 } // namespace |
| 35 | 35 |
| 36 void HistogramAlternateProtocolUsage(AlternateProtocolUsage usage) { | 36 void HistogramAlternateProtocolUsage(AlternateProtocolUsage usage) { |
| 37 UMA_HISTOGRAM_ENUMERATION("Net.AlternateProtocolUsage", usage, | 37 UMA_HISTOGRAM_ENUMERATION("Net.AlternateProtocolUsage", usage, |
| 38 ALTERNATE_PROTOCOL_USAGE_MAX); | 38 ALTERNATE_PROTOCOL_USAGE_MAX); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 49 protocol <= ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION; | 49 protocol <= ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION; |
| 50 } | 50 } |
| 51 | 51 |
| 52 const char* AlternateProtocolToString(AlternateProtocol protocol) { | 52 const char* AlternateProtocolToString(AlternateProtocol protocol) { |
| 53 switch (protocol) { | 53 switch (protocol) { |
| 54 case DEPRECATED_NPN_SPDY_2: | 54 case DEPRECATED_NPN_SPDY_2: |
| 55 case NPN_SPDY_3: | 55 case NPN_SPDY_3: |
| 56 case NPN_SPDY_3_1: | 56 case NPN_SPDY_3_1: |
| 57 case NPN_SPDY_4_14: | 57 case NPN_SPDY_4_14: |
| 58 case NPN_SPDY_4_15: | 58 case NPN_SPDY_4_15: |
| 59 case NPN_SPDY_4: |
| 59 case QUIC: | 60 case QUIC: |
| 60 DCHECK(IsAlternateProtocolValid(protocol)); | 61 DCHECK(IsAlternateProtocolValid(protocol)); |
| 61 return kAlternateProtocolStrings[ | 62 return kAlternateProtocolStrings[ |
| 62 protocol - ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION]; | 63 protocol - ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION]; |
| 63 case UNINITIALIZED_ALTERNATE_PROTOCOL: | 64 case UNINITIALIZED_ALTERNATE_PROTOCOL: |
| 64 return "Uninitialized"; | 65 return "Uninitialized"; |
| 65 } | 66 } |
| 66 NOTREACHED(); | 67 NOTREACHED(); |
| 67 return ""; | 68 return ""; |
| 68 } | 69 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 82 case kProtoDeprecatedSPDY2: | 83 case kProtoDeprecatedSPDY2: |
| 83 return DEPRECATED_NPN_SPDY_2; | 84 return DEPRECATED_NPN_SPDY_2; |
| 84 case kProtoSPDY3: | 85 case kProtoSPDY3: |
| 85 return NPN_SPDY_3; | 86 return NPN_SPDY_3; |
| 86 case kProtoSPDY31: | 87 case kProtoSPDY31: |
| 87 return NPN_SPDY_3_1; | 88 return NPN_SPDY_3_1; |
| 88 case kProtoSPDY4_14: | 89 case kProtoSPDY4_14: |
| 89 return NPN_SPDY_4_14; | 90 return NPN_SPDY_4_14; |
| 90 case kProtoSPDY4_15: | 91 case kProtoSPDY4_15: |
| 91 return NPN_SPDY_4_15; | 92 return NPN_SPDY_4_15; |
| 93 case kProtoSPDY4: |
| 94 return NPN_SPDY_4; |
| 92 case kProtoQUIC1SPDY3: | 95 case kProtoQUIC1SPDY3: |
| 93 return QUIC; | 96 return QUIC; |
| 94 | 97 |
| 95 case kProtoUnknown: | 98 case kProtoUnknown: |
| 96 case kProtoHTTP11: | 99 case kProtoHTTP11: |
| 97 break; | 100 break; |
| 98 } | 101 } |
| 99 | 102 |
| 100 NOTREACHED() << "Invalid NextProto: " << next_proto; | 103 NOTREACHED() << "Invalid NextProto: " << next_proto; |
| 101 return UNINITIALIZED_ALTERNATE_PROTOCOL; | 104 return UNINITIALIZED_ALTERNATE_PROTOCOL; |
| 102 } | 105 } |
| 103 | 106 |
| 104 std::string AlternateProtocolInfo::ToString() const { | 107 std::string AlternateProtocolInfo::ToString() const { |
| 105 return base::StringPrintf("%d:%s p=%f%s", port, | 108 return base::StringPrintf("%d:%s p=%f%s", port, |
| 106 AlternateProtocolToString(protocol), | 109 AlternateProtocolToString(protocol), |
| 107 probability, | 110 probability, |
| 108 is_broken ? " (broken)" : ""); | 111 is_broken ? " (broken)" : ""); |
| 109 } | 112 } |
| 110 | 113 |
| 111 // static | 114 // static |
| 112 void HttpServerProperties::ForceHTTP11(SSLConfig* ssl_config) { | 115 void HttpServerProperties::ForceHTTP11(SSLConfig* ssl_config) { |
| 113 ssl_config->next_protos.clear(); | 116 ssl_config->next_protos.clear(); |
| 114 ssl_config->next_protos.push_back(kProtoHTTP11); | 117 ssl_config->next_protos.push_back(kProtoHTTP11); |
| 115 } | 118 } |
| 116 | 119 |
| 117 } // namespace net | 120 } // namespace net |
| OLD | NEW |