Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Unified Diff: net/base/network_change_notifier_win.h

Issue 2893943002: [NetworkChangeNotifier] Run Windows connection type computation on other thread (Closed)
Patch Set: Nit Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/base/network_change_notifier_win.h
diff --git a/net/base/network_change_notifier_win.h b/net/base/network_change_notifier_win.h
index 94bab7f8d100213744e72863ebb4a2b0aa6b51b8..61023240d2750bd1afde0847699cbb642d5aa020 100644
--- a/net/base/network_change_notifier_win.h
+++ b/net/base/network_change_notifier_win.h
@@ -9,8 +9,10 @@
#include <memory>
+#include "base/callback.h"
#include "base/compiler_specific.h"
#include "base/macros.h"
+#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/threading/non_thread_safe.h"
#include "base/timer/timer.h"
@@ -18,6 +20,10 @@
#include "net/base/net_export.h"
#include "net/base/network_change_notifier.h"
+namespace base {
+class SingleThreadTaskRunner;
+} // namespace base
+
namespace net {
// NetworkChangeNotifierWin inherits from NonThreadSafe, as all its internal
@@ -50,6 +56,7 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierWin
private:
class DnsConfigServiceThread;
friend class NetworkChangeNotifierWinTest;
+ friend class TestNetworkChangeNotifierWin;
// NetworkChangeNotifier methods:
ConnectionType GetCurrentConnectionType() const override;
@@ -58,19 +65,16 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierWin
// Must only be called on the thread |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;
-
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.
- void NotifyObservers();
+ void NotifyObservers(ConnectionType connection_type);
// Forwards connection type notifications to parent class.
void NotifyParentOfConnectionTypeChange();
+ void NotifyParentOfConnectionTypeChangeImpl(ConnectionType connection_type);
// Tries to start listening for a single subsequent address change. Returns
// false on failure. The caller is responsible for updating |is_watching_|.
@@ -98,6 +102,7 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierWin
// Thread on which we can run DnsConfigService.
std::unique_ptr<DnsConfigServiceThread> dns_config_service_thread_;
+ scoped_refptr<base::SingleThreadTaskRunner> dns_task_runner_;
pauljensen 2017/05/22 18:01:51 Hmm, can we avoid dns_task_runner_ and calculate_c
jkarlin 2017/05/23 11:44:38 We could get rid of dns_task_runner_ that way I su
pauljensen 2017/05/23 14:55:50 Why would DnsConfigServiceThread need to be ref co
jkarlin 2017/05/23 15:11:06 Ah, you're right. All tasks on the dns thread will
mutable base::Lock last_computed_connection_type_lock_;
ConnectionType last_computed_connection_type_;
@@ -108,6 +113,9 @@ class NET_EXPORT_PRIVATE NetworkChangeNotifierWin
// Number of times polled to check if still offline.
int offline_polls_;
+ // The callback run to calculate connection type.
+ base::Callback<ConnectionType()> calculate_connection_type_;
+
// Used for calling WatchForAddressChange again on failure.
base::WeakPtrFactory<NetworkChangeNotifierWin> weak_factory_;

Powered by Google App Engine
This is Rietveld 408576698