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

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: Review comments Created 8 years, 7 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 ca314a199f9f6343b105a034bde290f5c55d3e72..270b552d17ad49dca4d50bb4b174d58f85c414c9 100644
--- a/net/base/network_change_notifier_mac.cc
+++ b/net/base/network_change_notifier_mac.cc
@@ -15,8 +15,9 @@ static bool CalculateReachability(SCNetworkConnectionFlags flags) {
}
NetworkChangeNotifierMac::NetworkChangeNotifierMac()
- : online_state_(UNINITIALIZED),
- initial_state_cv_(&online_state_lock_),
+ : connection_type_(CONNECTION_UNKNOWN),
+ connection_type_initialized_(false),
+ initial_state_cv_(&connection_type_lock_),
forwarder_(this) {
// Must be initialized after the rest of this object, as it may call back into
// SetInitialState().
@@ -37,13 +38,14 @@ NetworkChangeNotifierMac::~NetworkChangeNotifierMac() {
}
}
-bool NetworkChangeNotifierMac::IsCurrentlyOffline() const {
- base::AutoLock lock(online_state_lock_);
+NetworkChangeNotifier::ConnectionType
+NetworkChangeNotifierMac::GetCurrentConnectionType() const {
+ base::AutoLock lock(connection_type_lock_);
// Make sure the initial state is set before returning.
- while (online_state_ == UNINITIALIZED) {
+ while (!connection_type_initialized_) {
initial_state_cv_.Wait();
}
- return online_state_ == OFFLINE;
+ return connection_type_;
}
void NetworkChangeNotifierMac::SetInitialState() {
@@ -68,8 +70,10 @@ void NetworkChangeNotifierMac::SetInitialState() {
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_type_lock_);
+ // TODO(droger): Get something more detailed than CONNECTION_UNKNOWN.
+ connection_type_ = reachable ? CONNECTION_UNKNOWN : CONNECTION_NONE;
+ connection_type_initialized_ = true;
initial_state_cv_.Signal();
}
}
@@ -153,15 +157,17 @@ void NetworkChangeNotifierMac::ReachabilityCallback(
DCHECK_EQ(notifier_mac->run_loop_.get(), CFRunLoopGetCurrent());
- OnlineState new_state = CalculateReachability(flags) ? ONLINE : OFFLINE;
- OnlineState old_state;
+ // TODO(droger): Get something more detailed than CONNECTION_UNKNOWN.
+ ConnectionType new_type = CalculateReachability(flags) ? CONNECTION_UNKNOWN
+ : CONNECTION_NONE;
+ ConnectionType old_type;
{
- 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_type_lock_);
+ old_type = notifier_mac->connection_type_;
+ notifier_mac->connection_type_ = new_type;
}
- if (old_state != new_state)
- NotifyObserversOfOnlineStateChange();
+ if (old_type != new_type)
+ NotifyObserversOfConnectionTypeChange();
}
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698