| 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/stringprintf.h" | 8 #include "base/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 const char* const kAlternateProtocolStrings[] = { | 13 const char* const kAlternateProtocolStrings[] = { |
| 14 "npn-spdy/1", | 14 "npn-spdy/1", |
| 15 "npn-spdy/2", | 15 "npn-spdy/2", |
| 16 "npn-spdy/3", | 16 "npn-spdy/3", |
| 17 }; | 17 }; |
| 18 const char kBrokenAlternateProtocol[] = "Broken"; |
| 18 | 19 |
| 19 static const char* AlternateProtocolToString(AlternateProtocol protocol) { | 20 const char* AlternateProtocolToString(AlternateProtocol protocol) { |
| 20 switch (protocol) { | 21 switch (protocol) { |
| 21 case NPN_SPDY_1: | 22 case NPN_SPDY_1: |
| 22 case NPN_SPDY_2: | 23 case NPN_SPDY_2: |
| 23 case NPN_SPDY_3: | 24 case NPN_SPDY_3: |
| 24 return kAlternateProtocolStrings[protocol]; | 25 return kAlternateProtocolStrings[protocol]; |
| 25 case ALTERNATE_PROTOCOL_BROKEN: | 26 case ALTERNATE_PROTOCOL_BROKEN: |
| 26 return "Broken"; | 27 return kBrokenAlternateProtocol; |
| 27 case UNINITIALIZED_ALTERNATE_PROTOCOL: | 28 case UNINITIALIZED_ALTERNATE_PROTOCOL: |
| 28 return "Uninitialized"; | 29 return "Uninitialized"; |
| 29 default: | 30 default: |
| 30 NOTREACHED(); | 31 NOTREACHED(); |
| 31 return ""; | 32 return ""; |
| 32 } | 33 } |
| 33 } | 34 } |
| 34 | 35 |
| 36 AlternateProtocol AlternateProtocolFromString(const std::string& protocol) { |
| 37 for (int i = NPN_SPDY_1; i < NUM_ALTERNATE_PROTOCOLS; ++i) |
| 38 if (protocol == kAlternateProtocolStrings[i]) |
| 39 return static_cast<AlternateProtocol>(i); |
| 40 if (protocol == kBrokenAlternateProtocol) |
| 41 return ALTERNATE_PROTOCOL_BROKEN; |
| 42 return UNINITIALIZED_ALTERNATE_PROTOCOL; |
| 43 } |
| 44 |
| 45 |
| 35 std::string PortAlternateProtocolPair::ToString() const { | 46 std::string PortAlternateProtocolPair::ToString() const { |
| 36 return base::StringPrintf("%d:%s", port, | 47 return base::StringPrintf("%d:%s", port, |
| 37 AlternateProtocolToString(protocol)); | 48 AlternateProtocolToString(protocol)); |
| 38 } | 49 } |
| 39 | 50 |
| 40 } // namespace net | 51 } // namespace net |
| OLD | NEW |