Index: net/base/network_change_notifier.cc |
diff --git a/net/base/network_change_notifier.cc b/net/base/network_change_notifier.cc |
index 0cfaaa38d259db9be27343bf487aaf3b88d1a6a0..34baa47bd02a58741a479451cd6caccea7f09595 100644 |
--- a/net/base/network_change_notifier.cc |
+++ b/net/base/network_change_notifier.cc |
@@ -38,6 +38,11 @@ namespace net { |
namespace { |
+static const char* const kConnectionTypeNames[] = { |
+ "CONNECTION_UNKNOWN", "CONNECTION_ETHERNET", "CONNECTION_WIFI", |
+ "CONNECTION_2G", "CONNECTION_3G", "CONNECTION_4G", |
+ "CONNECTION_NONE", "CONNECTION_BLUETOOTH"}; |
+ |
// The actual singleton notifier. The class contract forbids usage of the API |
// in ways that would require us to place locks around access to this object. |
// (The prohibition on global non-POD objects makes it tricky to do such a thing |
@@ -681,19 +686,25 @@ void NetworkChangeNotifier::GetDnsConfig(DnsConfig* config) { |
} |
} |
+// static |
+NetworkChangeNotifier::ConnectionType |
+NetworkChangeNotifier::StringToConnectionType( |
+ const std::string& connection_type) { |
+ static_assert(arraysize(kConnectionTypeNames) == |
+ NetworkChangeNotifier::CONNECTION_LAST + 1, |
+ "ConnectionType name count should match"); |
+ const auto it = std::find( |
+ kConnectionTypeNames, |
RyanSturm
2016/10/12 21:33:34
Can this be more C++11-ish and have std::find(std:
tbansal1
2016/10/12 22:04:01
Obsolete.
|
+ kConnectionTypeNames + arraysize(kConnectionTypeNames), connection_type); |
+ return it != kConnectionTypeNames + arraysize(kConnectionTypeNames) |
+ ? static_cast<NetworkChangeNotifier::ConnectionType>( |
RyanSturm
2016/10/12 21:33:34
I'm not convinced this static_cast is a good way t
tbansal1
2016/10/12 22:04:01
From https://cs.chromium.org/chromium/src/net/base
|
+ it - kConnectionTypeNames) |
+ : NetworkChangeNotifier::CONNECTION_UNKNOWN; |
+} |
+ |
// static |
const char* NetworkChangeNotifier::ConnectionTypeToString( |
ConnectionType type) { |
- static const char* const kConnectionTypeNames[] = { |
- "CONNECTION_UNKNOWN", |
- "CONNECTION_ETHERNET", |
- "CONNECTION_WIFI", |
- "CONNECTION_2G", |
- "CONNECTION_3G", |
- "CONNECTION_4G", |
- "CONNECTION_NONE", |
- "CONNECTION_BLUETOOTH" |
- }; |
static_assert(arraysize(kConnectionTypeNames) == |
NetworkChangeNotifier::CONNECTION_LAST + 1, |
"ConnectionType name count should match"); |