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

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: Fixed a typo 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
« no previous file with comments | « net/base/network_change_notifier_mac.h ('k') | net/base/network_change_notifier_win.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 0265ef1707814ba7596e1e0dbcfd4f23630aff77..85e95a240971a49c28584409c92977f273afc7c2 100644
--- a/net/base/network_change_notifier_mac.cc
+++ b/net/base/network_change_notifier_mac.cc
@@ -46,12 +46,13 @@ class NetworkChangeNotifierMac::DnsWatcherThread : public base::Thread {
};
NetworkChangeNotifierMac::NetworkChangeNotifierMac()
- : online_state_(UNINITIALIZED),
- initial_state_cv_(&online_state_lock_),
+ : connection_type_(CONNECTION_UNKNOWN),
+ connection_type_initialized_(false),
+ initial_connection_type_cv_(&connection_type_lock_),
forwarder_(this),
dns_watcher_thread_(new DnsWatcherThread()) {
// Must be initialized after the rest of this object, as it may call back into
- // SetInitialState().
+ // SetInitialConnectionType().
config_watcher_.reset(new NetworkConfigWatcherMac(&forwarder_));
dns_watcher_thread_->StartWithOptions(
base::Thread::Options(MessageLoop::TYPE_IO, 0));
@@ -71,16 +72,17 @@ NetworkChangeNotifierMac::~NetworkChangeNotifierMac() {
}
}
-bool NetworkChangeNotifierMac::IsCurrentlyOffline() const {
- base::AutoLock lock(online_state_lock_);
- // Make sure the initial state is set before returning.
- while (online_state_ == UNINITIALIZED) {
- initial_state_cv_.Wait();
+NetworkChangeNotifier::ConnectionType
+NetworkChangeNotifierMac::GetCurrentConnectionType() const {
+ base::AutoLock lock(connection_type_lock_);
+ // Make sure the initial connection type is set before returning.
+ while (!connection_type_initialized_) {
+ initial_connection_type_cv_.Wait();
}
- return online_state_ == OFFLINE;
+ return connection_type_;
}
-void NetworkChangeNotifierMac::SetInitialState() {
+void NetworkChangeNotifierMac::SetInitialConnectionType() {
// Called on notifier thread.
// Try to reach 0.0.0.0. This is the approach taken by Firefox:
@@ -100,11 +102,14 @@ void NetworkChangeNotifierMac::SetInitialState() {
if (SCNetworkReachabilityGetFlags(reachability_, &flags))
reachable = CalculateReachability(flags);
else
- LOG(ERROR) << "Could not get initial network state, assuming online.";
+ LOG(ERROR) << "Could not get initial network connection type,"
+ << "assuming online.";
{
- base::AutoLock lock(online_state_lock_);
- online_state_ = reachable ? ONLINE : OFFLINE;
- initial_state_cv_.Signal();
+ 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_connection_type_cv_.Signal();
}
}
@@ -187,15 +192,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
« no previous file with comments | « net/base/network_change_notifier_mac.h ('k') | net/base/network_change_notifier_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698