Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(127)

Unified Diff: net/base/network_change_notifier.cc

Issue 2369673004: Wire NQE Prefs to Profile (Closed)
Patch Set: Added functionality for reading and writing multiple network IDs, Rebased, Addressed Ryan's comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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");

Powered by Google App Engine
This is Rietveld 408576698