Chromium Code Reviews| 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/2.1", | 16 "npn-spdy/2.1", |
| 17 "npn-spdy/3", | 17 "npn-spdy/3", |
| 18 }; | 18 }; |
| 19 const char kBrokenAlternateProtocol[] = "Broken"; | |
| 19 | 20 |
| 20 static const char* AlternateProtocolToString(AlternateProtocol protocol) { | 21 const char* AlternateProtocolToString(AlternateProtocol protocol) { |
| 21 switch (protocol) { | 22 switch (protocol) { |
| 22 case NPN_SPDY_1: | 23 case NPN_SPDY_1: |
| 23 case NPN_SPDY_2: | 24 case NPN_SPDY_2: |
| 24 case NPN_SPDY_21: | 25 case NPN_SPDY_21: |
| 25 case NPN_SPDY_3: | 26 case NPN_SPDY_3: |
| 26 return kAlternateProtocolStrings[protocol]; | 27 return kAlternateProtocolStrings[protocol]; |
| 27 case ALTERNATE_PROTOCOL_BROKEN: | 28 case ALTERNATE_PROTOCOL_BROKEN: |
| 28 return "Broken"; | 29 return kBrokenAlternateProtocol; |
| 29 case UNINITIALIZED_ALTERNATE_PROTOCOL: | 30 case UNINITIALIZED_ALTERNATE_PROTOCOL: |
| 30 return "Uninitialized"; | 31 return "Uninitialized"; |
| 31 default: | 32 default: |
| 32 NOTREACHED(); | 33 NOTREACHED(); |
| 33 return ""; | 34 return ""; |
| 34 } | 35 } |
| 35 } | 36 } |
| 36 | 37 |
| 38 AlternateProtocol AlternateProtocolFromString(const std::string& protocol) { | |
| 39 for (int i = NPN_SPDY_1; i < NPN_SPDY_3; i++) | |
|
ramant (doing other things)
2012/04/07 00:41:22
nit: i++ -> ++i
Should we support "npn-spdy/3"?
| |
| 40 if (protocol == kAlternateProtocolStrings[i]) | |
| 41 return static_cast<AlternateProtocol>(i); | |
| 42 if (protocol == kBrokenAlternateProtocol) | |
| 43 return ALTERNATE_PROTOCOL_BROKEN; | |
| 44 return UNINITIALIZED_ALTERNATE_PROTOCOL; | |
| 45 } | |
| 46 | |
| 47 | |
| 37 std::string PortAlternateProtocolPair::ToString() const { | 48 std::string PortAlternateProtocolPair::ToString() const { |
| 38 return base::StringPrintf("%d:%s", port, | 49 return base::StringPrintf("%d:%s", port, |
| 39 AlternateProtocolToString(protocol)); | 50 AlternateProtocolToString(protocol)); |
| 40 } | 51 } |
| 41 | 52 |
| 42 } // namespace net | 53 } // namespace net |
| OLD | NEW |