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

Side by Side 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 unified diff | Download patch
OLDNEW
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/base/network_change_notifier.h" 5 #include "net/base/network_change_notifier.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <unordered_set> 8 #include <unordered_set>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 20 matching lines...) Expand all
31 #elif defined(OS_LINUX) && !defined(OS_CHROMEOS) 31 #elif defined(OS_LINUX) && !defined(OS_CHROMEOS)
32 #include "net/base/network_change_notifier_linux.h" 32 #include "net/base/network_change_notifier_linux.h"
33 #elif defined(OS_MACOSX) 33 #elif defined(OS_MACOSX)
34 #include "net/base/network_change_notifier_mac.h" 34 #include "net/base/network_change_notifier_mac.h"
35 #endif 35 #endif
36 36
37 namespace net { 37 namespace net {
38 38
39 namespace { 39 namespace {
40 40
41 static const char* const kConnectionTypeNames[] = {
42 "CONNECTION_UNKNOWN", "CONNECTION_ETHERNET", "CONNECTION_WIFI",
43 "CONNECTION_2G", "CONNECTION_3G", "CONNECTION_4G",
44 "CONNECTION_NONE", "CONNECTION_BLUETOOTH"};
45
41 // The actual singleton notifier. The class contract forbids usage of the API 46 // The actual singleton notifier. The class contract forbids usage of the API
42 // in ways that would require us to place locks around access to this object. 47 // in ways that would require us to place locks around access to this object.
43 // (The prohibition on global non-POD objects makes it tricky to do such a thing 48 // (The prohibition on global non-POD objects makes it tricky to do such a thing
44 // anyway.) 49 // anyway.)
45 NetworkChangeNotifier* g_network_change_notifier = NULL; 50 NetworkChangeNotifier* g_network_change_notifier = NULL;
46 51
47 // Class factory singleton. 52 // Class factory singleton.
48 NetworkChangeNotifierFactory* g_network_change_notifier_factory = NULL; 53 NetworkChangeNotifierFactory* g_network_change_notifier_factory = NULL;
49 54
50 class MockNetworkChangeNotifier : public NetworkChangeNotifier { 55 class MockNetworkChangeNotifier : public NetworkChangeNotifier {
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 679
675 // static 680 // static
676 void NetworkChangeNotifier::GetDnsConfig(DnsConfig* config) { 681 void NetworkChangeNotifier::GetDnsConfig(DnsConfig* config) {
677 if (!g_network_change_notifier) { 682 if (!g_network_change_notifier) {
678 *config = DnsConfig(); 683 *config = DnsConfig();
679 } else { 684 } else {
680 g_network_change_notifier->network_state_->GetDnsConfig(config); 685 g_network_change_notifier->network_state_->GetDnsConfig(config);
681 } 686 }
682 } 687 }
683 688
689 // static
690 NetworkChangeNotifier::ConnectionType
691 NetworkChangeNotifier::StringToConnectionType(
692 const std::string& connection_type) {
693 static_assert(arraysize(kConnectionTypeNames) ==
694 NetworkChangeNotifier::CONNECTION_LAST + 1,
695 "ConnectionType name count should match");
696 const auto it = std::find(
697 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.
698 kConnectionTypeNames + arraysize(kConnectionTypeNames), connection_type);
699 return it != kConnectionTypeNames + arraysize(kConnectionTypeNames)
700 ? 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
701 it - kConnectionTypeNames)
702 : NetworkChangeNotifier::CONNECTION_UNKNOWN;
703 }
704
684 // static 705 // static
685 const char* NetworkChangeNotifier::ConnectionTypeToString( 706 const char* NetworkChangeNotifier::ConnectionTypeToString(
686 ConnectionType type) { 707 ConnectionType type) {
687 static const char* const kConnectionTypeNames[] = {
688 "CONNECTION_UNKNOWN",
689 "CONNECTION_ETHERNET",
690 "CONNECTION_WIFI",
691 "CONNECTION_2G",
692 "CONNECTION_3G",
693 "CONNECTION_4G",
694 "CONNECTION_NONE",
695 "CONNECTION_BLUETOOTH"
696 };
697 static_assert(arraysize(kConnectionTypeNames) == 708 static_assert(arraysize(kConnectionTypeNames) ==
698 NetworkChangeNotifier::CONNECTION_LAST + 1, 709 NetworkChangeNotifier::CONNECTION_LAST + 1,
699 "ConnectionType name count should match"); 710 "ConnectionType name count should match");
700 if (type < CONNECTION_UNKNOWN || type > CONNECTION_LAST) { 711 if (type < CONNECTION_UNKNOWN || type > CONNECTION_LAST) {
701 NOTREACHED(); 712 NOTREACHED();
702 return "CONNECTION_INVALID"; 713 return "CONNECTION_INVALID";
703 } 714 }
704 return kConnectionTypeNames[type]; 715 return kConnectionTypeNames[type];
705 } 716 }
706 717
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after
1169 1180
1170 NetworkChangeNotifier::DisableForTest::~DisableForTest() { 1181 NetworkChangeNotifier::DisableForTest::~DisableForTest() {
1171 DCHECK(!g_network_change_notifier); 1182 DCHECK(!g_network_change_notifier);
1172 g_network_change_notifier = network_change_notifier_; 1183 g_network_change_notifier = network_change_notifier_;
1173 } 1184 }
1174 1185
1175 void NetworkChangeNotifier::DNSObserver::OnInitialDNSConfigRead() { 1186 void NetworkChangeNotifier::DNSObserver::OnInitialDNSConfigRead() {
1176 } 1187 }
1177 1188
1178 } // namespace net 1189 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698