Commit d72b8a85 authored by adamk@chromium.org's avatar adamk@chromium.org

NetworkChangeNotifierMac: lock access to network_reachable_ as it may be read

on different threads than the one on which it's written.

R=eroman@chromium.org


Review URL: http://codereview.chromium.org/7135005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@88389 0039d316-1c4b-4281-b951-d872f2087c98
parent 9f3fba57
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <SystemConfiguration/SCSchemaDefinitions.h> #include <SystemConfiguration/SCSchemaDefinitions.h>
#include "base/mac/scoped_cftyperef.h" #include "base/mac/scoped_cftyperef.h"
#include "base/synchronization/lock.h"
namespace net { namespace net {
...@@ -27,6 +28,7 @@ NetworkChangeNotifierMac::~NetworkChangeNotifierMac() { ...@@ -27,6 +28,7 @@ NetworkChangeNotifierMac::~NetworkChangeNotifierMac() {
} }
bool NetworkChangeNotifierMac::IsCurrentlyOffline() const { bool NetworkChangeNotifierMac::IsCurrentlyOffline() const {
base::AutoLock lock(network_reachable_lock_);
return !network_reachable_; return !network_reachable_;
} }
...@@ -120,7 +122,10 @@ void NetworkChangeNotifierMac::ReachabilityCallback( ...@@ -120,7 +122,10 @@ void NetworkChangeNotifierMac::ReachabilityCallback(
bool reachable = flags & kSCNetworkFlagsReachable; bool reachable = flags & kSCNetworkFlagsReachable;
bool connection_required = flags & kSCNetworkFlagsConnectionRequired; bool connection_required = flags & kSCNetworkFlagsConnectionRequired;
bool old_reachability = notifier_mac->network_reachable_; bool old_reachability = notifier_mac->network_reachable_;
notifier_mac->network_reachable_ = reachable && !connection_required; {
base::AutoLock lock(notifier_mac->network_reachable_lock_);
notifier_mac->network_reachable_ = reachable && !connection_required;
}
if (old_reachability != notifier_mac->network_reachable_) if (old_reachability != notifier_mac->network_reachable_)
NotifyObserversOfOnlineStateChange(); NotifyObserversOfOnlineStateChange();
} }
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/mac/scoped_cftyperef.h" #include "base/mac/scoped_cftyperef.h"
#include "base/synchronization/lock.h"
#include "net/base/network_change_notifier.h" #include "net/base/network_change_notifier.h"
#include "net/base/network_config_watcher_mac.h" #include "net/base/network_config_watcher_mac.h"
...@@ -58,6 +59,7 @@ class NetworkChangeNotifierMac: public NetworkChangeNotifier { ...@@ -58,6 +59,7 @@ class NetworkChangeNotifierMac: public NetworkChangeNotifier {
base::mac::ScopedCFTypeRef<CFRunLoopRef> run_loop_; base::mac::ScopedCFTypeRef<CFRunLoopRef> run_loop_;
base::mac::ScopedCFTypeRef<SCNetworkReachabilityRef> reachability_; base::mac::ScopedCFTypeRef<SCNetworkReachabilityRef> reachability_;
bool network_reachable_; bool network_reachable_;
mutable base::Lock network_reachable_lock_;
DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierMac); DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierMac);
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment