diff options
author | adamk@chromium.org <adamk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-08 20:43:25 +0000 |
---|---|---|
committer | adamk@chromium.org <adamk@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-08 20:43:25 +0000 |
commit | d72b8a85957fc568c31e0a3df4c2566cf1e502f9 (patch) | |
tree | 686ca2d7b93056ca6e931929ee550c3d51e77605 /net | |
parent | 9f3fba5755542d0f9ac5f39540e771713dd666bb (diff) | |
download | chromium_src-d72b8a85957fc568c31e0a3df4c2566cf1e502f9.zip chromium_src-d72b8a85957fc568c31e0a3df4c2566cf1e502f9.tar.gz chromium_src-d72b8a85957fc568c31e0a3df4c2566cf1e502f9.tar.bz2 |
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
Diffstat (limited to 'net')
-rw-r--r-- | net/base/network_change_notifier_mac.cc | 7 | ||||
-rw-r--r-- | net/base/network_change_notifier_mac.h | 2 |
2 files changed, 8 insertions, 1 deletions
diff --git a/net/base/network_change_notifier_mac.cc b/net/base/network_change_notifier_mac.cc index cde4d6e..b8e25ed 100644 --- a/net/base/network_change_notifier_mac.cc +++ b/net/base/network_change_notifier_mac.cc @@ -10,6 +10,7 @@ #include <SystemConfiguration/SCSchemaDefinitions.h> #include "base/mac/scoped_cftyperef.h" +#include "base/synchronization/lock.h" namespace net { @@ -27,6 +28,7 @@ NetworkChangeNotifierMac::~NetworkChangeNotifierMac() { } bool NetworkChangeNotifierMac::IsCurrentlyOffline() const { + base::AutoLock lock(network_reachable_lock_); return !network_reachable_; } @@ -120,7 +122,10 @@ void NetworkChangeNotifierMac::ReachabilityCallback( bool reachable = flags & kSCNetworkFlagsReachable; bool connection_required = flags & kSCNetworkFlagsConnectionRequired; 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_) NotifyObserversOfOnlineStateChange(); } diff --git a/net/base/network_change_notifier_mac.h b/net/base/network_change_notifier_mac.h index d0f49d6..e01e244 100644 --- a/net/base/network_change_notifier_mac.h +++ b/net/base/network_change_notifier_mac.h @@ -11,6 +11,7 @@ #include "base/basictypes.h" #include "base/mac/scoped_cftyperef.h" +#include "base/synchronization/lock.h" #include "net/base/network_change_notifier.h" #include "net/base/network_config_watcher_mac.h" @@ -58,6 +59,7 @@ class NetworkChangeNotifierMac: public NetworkChangeNotifier { base::mac::ScopedCFTypeRef<CFRunLoopRef> run_loop_; base::mac::ScopedCFTypeRef<SCNetworkReachabilityRef> reachability_; bool network_reachable_; + mutable base::Lock network_reachable_lock_; DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierMac); }; |