[Android] Implement 3-way sensor fallback for Device Orientation.
[chromium-blink-merge.git] / net / http / http_server_properties.cc
blob08059c27466b69f3ed30e716db8f931ae7c6abe3
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
3 // found in the LICENSE file.
5 #include "net/http/http_server_properties.h"
7 #include "base/logging.h"
8 #include "base/metrics/histogram_macros.h"
9 #include "base/strings/stringprintf.h"
10 #include "net/socket/ssl_client_socket.h"
11 #include "net/ssl/ssl_config.h"
13 namespace net {
15 const char kAlternateProtocolHeader[] = "Alternate-Protocol";
16 const char kAlternativeServiceHeader[] = "Alt-Svc";
18 namespace {
20 // The order of these strings much match the order of the enum definition
21 // for AlternateProtocol.
22 const char* const kAlternateProtocolStrings[] = {
23 "npn-spdy/2",
24 "npn-spdy/3",
25 "npn-spdy/3.1",
26 "npn-h2-14", // HTTP/2 draft-14. Called SPDY4 internally.
27 "npn-h2",
28 "quic"};
30 static_assert(arraysize(kAlternateProtocolStrings) ==
31 NUM_VALID_ALTERNATE_PROTOCOLS,
32 "kAlternateProtocolStrings has incorrect size");
34 } // namespace
36 void HistogramAlternateProtocolUsage(AlternateProtocolUsage usage) {
37 UMA_HISTOGRAM_ENUMERATION("Net.AlternateProtocolUsage", usage,
38 ALTERNATE_PROTOCOL_USAGE_MAX);
41 void HistogramBrokenAlternateProtocolLocation(
42 BrokenAlternateProtocolLocation location){
43 UMA_HISTOGRAM_ENUMERATION("Net.AlternateProtocolBrokenLocation", location,
44 BROKEN_ALTERNATE_PROTOCOL_LOCATION_MAX);
47 bool IsAlternateProtocolValid(AlternateProtocol protocol) {
48 return protocol >= ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION &&
49 protocol <= ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION;
52 const char* AlternateProtocolToString(AlternateProtocol protocol) {
53 switch (protocol) {
54 case DEPRECATED_NPN_SPDY_2:
55 case NPN_SPDY_3:
56 case NPN_SPDY_3_1:
57 case NPN_HTTP_2_14:
58 case NPN_HTTP_2:
59 case QUIC:
60 DCHECK(IsAlternateProtocolValid(protocol));
61 return kAlternateProtocolStrings[
62 protocol - ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION];
63 case UNINITIALIZED_ALTERNATE_PROTOCOL:
64 return "Uninitialized";
66 NOTREACHED();
67 return "";
70 AlternateProtocol AlternateProtocolFromString(const std::string& str) {
71 for (int i = ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION;
72 i <= ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION; ++i) {
73 AlternateProtocol protocol = static_cast<AlternateProtocol>(i);
74 if (str == AlternateProtocolToString(protocol))
75 return protocol;
77 return UNINITIALIZED_ALTERNATE_PROTOCOL;
80 AlternateProtocol AlternateProtocolFromNextProto(NextProto next_proto) {
81 switch (next_proto) {
82 case kProtoDeprecatedSPDY2:
83 return DEPRECATED_NPN_SPDY_2;
84 case kProtoSPDY3:
85 return NPN_SPDY_3;
86 case kProtoSPDY31:
87 return NPN_SPDY_3_1;
88 case kProtoHTTP2_14:
89 return NPN_HTTP_2_14;
90 case kProtoHTTP2:
91 return NPN_HTTP_2;
92 case kProtoQUIC1SPDY3:
93 return QUIC;
95 case kProtoUnknown:
96 case kProtoHTTP11:
97 break;
100 NOTREACHED() << "Invalid NextProto: " << next_proto;
101 return UNINITIALIZED_ALTERNATE_PROTOCOL;
104 std::string AlternativeService::ToString() const {
105 return base::StringPrintf("%s %s:%d", AlternateProtocolToString(protocol),
106 host.c_str(), port);
109 std::string AlternativeServiceInfo::ToString() const {
110 return base::StringPrintf("%s, p=%f", alternative_service.ToString().c_str(),
111 probability);
114 // static
115 void HttpServerProperties::ForceHTTP11(SSLConfig* ssl_config) {
116 ssl_config->next_protos.clear();
117 ssl_config->next_protos.push_back(kProtoHTTP11);
120 } // namespace net