Remove a race around NetworkChangeNotifier::test_notifications_only_
There is a possible race in which
NetworkChangeNotifier::test_notifications_only_ might be read on one
thread while being written on another. This CL fixes that by making
the variable static and only allowing writes to it before the
NetworkChangeNotifier is created (before other things might try to
read it).
BUG=454652
Review URL: https://codereview.chromium.org/1255263002
Cr-Commit-Position: refs/heads/master@{#341354}
diff --git a/net/base/network_change_notifier.h b/net/base/network_change_notifier.h
index df6792f..abced48 100644
--- a/net/base/network_change_notifier.h
+++ b/net/base/network_change_notifier.h
@@ -312,7 +312,8 @@
// Enable or disable notifications from the host. After setting to true, be
// sure to pump the RunLoop until idle to finish any preexisting
- // notifications.
+ // notifications. To use this, it must must be called before a
+ // NetworkChangeNotifier is created.
static void SetTestNotificationsOnly(bool test_only);
// Return a string equivalent to |type|.
@@ -451,7 +452,7 @@
scoped_ptr<NetworkChangeCalculator> network_change_calculator_;
// Set true to disable non-test notifications (to prevent flakes in tests).
- bool test_notifications_only_;
+ static bool test_notifications_only_;
DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier);
};