diff options
Diffstat (limited to 'chromium/net/base/network_change_notifier_win.h')
-rw-r--r-- | chromium/net/base/network_change_notifier_win.h | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/chromium/net/base/network_change_notifier_win.h b/chromium/net/base/network_change_notifier_win.h index beef6bad9f7..e7a00b9cd71 100644 --- a/chromium/net/base/network_change_notifier_win.h +++ b/chromium/net/base/network_change_notifier_win.h @@ -12,17 +12,25 @@ #include "base/callback.h" #include "base/compiler_specific.h" #include "base/macros.h" +#include "base/memory/scoped_refptr.h" #include "base/memory/weak_ptr.h" -#include "base/threading/thread_checker.h" +#include "base/sequence_checker.h" #include "base/timer/timer.h" #include "base/win/object_watcher.h" #include "net/base/net_export.h" #include "net/base/network_change_notifier.h" +namespace base { +class SequencedTaskRunner; +struct OnTaskRunnerDeleter; +} // namespace base + namespace net { -// NetworkChangeNotifierWin uses a ThreadChecker, as all its internal -// notification code must be called on the thread it is created and destroyed +class DnsConfigService; + +// NetworkChangeNotifierWin uses a SequenceChecker, as all its internal +// notification code must be called on the sequence it is created and destroyed // on. All the NetworkChangeNotifier methods it implements are threadsafe. class NET_EXPORT_PRIVATE NetworkChangeNotifierWin : public NetworkChangeNotifier, @@ -32,8 +40,8 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierWin // Begins listening for a single subsequent address change. If it fails to // start watching, it retries on a timer. Must be called only once, on the - // thread |this| was created on. This cannot be called in the constructor, as - // WatchForAddressChangeInternal is mocked out in unit tests. + // sequence |this| was created on. This cannot be called in the constructor, + // as WatchForAddressChangeInternal is mocked out in unit tests. // TODO(mmenke): Consider making this function a part of the // NetworkChangeNotifier interface, so other subclasses can be // unit tested in similar fashion, as needed. @@ -48,30 +56,29 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierWin int sequential_failures() { return sequential_failures_; } private: - class DnsConfigServiceThread; friend class NetworkChangeNotifierWinTest; // NetworkChangeNotifier methods: ConnectionType GetCurrentConnectionType() const override; // ObjectWatcher::Delegate methods: - // Must only be called on the thread |this| was created on. + // Must only be called on the sequence |this| was created on. void OnObjectSignaled(HANDLE object) override; // Does the actual work to determine the current connection type. // It is not thread safe, see crbug.com/324913. virtual ConnectionType RecomputeCurrentConnectionType() const; - // Calls RecomputeCurrentConnectionTypeImpl on the DNS thread and runs - // |reply_callback| with the type on the calling thread. - virtual void RecomputeCurrentConnectionTypeOnDnsThread( - base::Callback<void(ConnectionType)> reply_callback) const; + // Calls RecomputeCurrentConnectionTypeImpl on the DNS sequence and runs + // |reply_callback| with the type on the calling sequence. + virtual void RecomputeCurrentConnectionTypeOnDnsSequence( + base::OnceCallback<void(ConnectionType)> reply_callback) const; void SetCurrentConnectionType(ConnectionType connection_type); // Notifies IP address change observers of a change immediately, and notifies // network state change observers on a delay. Must only be called on the - // thread |this| was created on. + // sequence |this| was created on. void NotifyObservers(ConnectionType connection_type); // Forwards connection type notifications to parent class. @@ -80,14 +87,14 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierWin // Tries to start listening for a single subsequent address change. Returns // false on failure. The caller is responsible for updating |is_watching_|. - // Virtual for unit tests. Must only be called on the thread |this| was + // Virtual for unit tests. Must only be called on the sequence |this| was // created on. virtual bool WatchForAddressChangeInternal(); static NetworkChangeCalculatorParams NetworkChangeCalculatorParamsWin(); - // All member variables may only be accessed on the thread |this| was created - // on. + // All member variables may only be accessed on the sequence |this| was + // created on. // False when not currently watching for network change events. This only // happens on initialization and when WatchForAddressChangeInternal fails and @@ -102,8 +109,11 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierWin // Number of times WatchForAddressChange has failed in a row. int sequential_failures_; - // Thread on which we can run DnsConfigService. - std::unique_ptr<DnsConfigServiceThread> dns_config_service_thread_; + // |dns_config_service_| will live on this runner. + scoped_refptr<base::SequencedTaskRunner> dns_config_service_runner_; + // DnsConfigService that lives on |dns_config_service_runner_|. + std::unique_ptr<DnsConfigService, base::OnTaskRunnerDeleter> + dns_config_service_; mutable base::Lock last_computed_connection_type_lock_; ConnectionType last_computed_connection_type_; @@ -114,7 +124,10 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierWin // Number of times polled to check if still offline. int offline_polls_; - THREAD_CHECKER(thread_checker_); + // Keeps track of whether DnsConfigService::WatchConfig() has been called. + bool posted_watch_config_ = false; + + SEQUENCE_CHECKER(sequence_checker_); // Used for calling WatchForAddressChange again on failure. base::WeakPtrFactory<NetworkChangeNotifierWin> weak_factory_; |