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

Unified Diff: net/base/network_change_notifier_mac.cc

Issue 9147026: API for connection type (Ethernet/WIFI/WWAN ...) in NetworkChangeNotifier. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 11 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_mac.cc
diff --git a/net/base/network_change_notifier_mac.cc b/net/base/network_change_notifier_mac.cc
index 69024c778f6099d6e46b2af2dac65ebe639eff90..b603f0619821c0dd097982ebc4711e5b4286e892 100644
--- a/net/base/network_change_notifier_mac.cc
+++ b/net/base/network_change_notifier_mac.cc
@@ -8,15 +8,17 @@
namespace net {
-static bool CalculateReachability(SCNetworkConnectionFlags flags) {
+static NetworkChangeNotifier::ConnectionState
+CalculateReachability(SCNetworkConnectionFlags flags) {
bool reachable = flags & kSCNetworkFlagsReachable;
bool connection_required = flags & kSCNetworkFlagsConnectionRequired;
- return reachable && !connection_required;
+ return (reachable && !connection_required) ?
+ NetworkChangeNotifier::ETHERNET : NetworkChangeNotifier::NONE;
}
NetworkChangeNotifierMac::NetworkChangeNotifierMac()
- : online_state_(UNINITIALIZED),
- initial_state_cv_(&online_state_lock_),
+ : connection_state_(UNKNOWN),
+ initial_state_cv_(&connection_state_lock_),
forwarder_(this) {
// Must be initialized after the rest of this object, as it may call back into
// SetInitialState().
@@ -37,13 +39,14 @@ NetworkChangeNotifierMac::~NetworkChangeNotifierMac() {
}
}
-bool NetworkChangeNotifierMac::IsCurrentlyOffline() const {
- base::AutoLock lock(online_state_lock_);
+NetworkChangeNotifier::ConnectionState
+NetworkChangeNotifierMac::GetCurrentConnectionState() const {
+ base::AutoLock lock(connection_state_lock_);
// Make sure the initial state is set before returning.
- while (online_state_ == UNINITIALIZED) {
+ while (connection_state_ == UNKNOWN) {
droger_google 2012/01/10 11:48:26 Here, the Mac implementation uses UNKNOWN with a U
initial_state_cv_.Wait();
}
- return online_state_ == OFFLINE;
+ return connection_state_;
}
void NetworkChangeNotifierMac::SetInitialState() {
@@ -62,14 +65,14 @@ void NetworkChangeNotifierMac::SetInitialState() {
kCFAllocatorDefault, reinterpret_cast<struct sockaddr*>(&addr)));
SCNetworkConnectionFlags flags;
- bool reachable = true;
+ ConnectionState reachable = ETHERNET;
if (SCNetworkReachabilityGetFlags(reachability_, &flags))
reachable = CalculateReachability(flags);
else
LOG(ERROR) << "Could not get initial network state, assuming online.";
{
- base::AutoLock lock(online_state_lock_);
- online_state_ = reachable ? ONLINE : OFFLINE;
+ base::AutoLock lock(connection_state_lock_);
+ connection_state_ = reachable;
initial_state_cv_.Signal();
}
}
@@ -151,15 +154,15 @@ void NetworkChangeNotifierMac::ReachabilityCallback(
DCHECK_EQ(notifier_mac->run_loop_.get(), CFRunLoopGetCurrent());
- OnlineState new_state = CalculateReachability(flags) ? ONLINE : OFFLINE;
- OnlineState old_state;
+ ConnectionState new_state = CalculateReachability(flags) ? ETHERNET : NONE;
+ ConnectionState old_state;
{
- base::AutoLock lock(notifier_mac->online_state_lock_);
- old_state = notifier_mac->online_state_;
- notifier_mac->online_state_ = new_state;
+ base::AutoLock lock(notifier_mac->connection_state_lock_);
+ old_state = notifier_mac->connection_state_;
+ notifier_mac->connection_state_ = new_state;
}
if (old_state != new_state)
- NotifyObserversOfOnlineStateChange();
+ NotifyObserversOfConnectionStateChange();
}
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698