Chromium Code Reviews| 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 |