OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_BASE_NETWORK_CHANGE_NOTIFIER_WIN_H_ | 5 #ifndef NET_BASE_NETWORK_CHANGE_NOTIFIER_WIN_H_ |
6 #define NET_BASE_NETWORK_CHANGE_NOTIFIER_WIN_H_ | 6 #define NET_BASE_NETWORK_CHANGE_NOTIFIER_WIN_H_ |
7 | 7 |
8 #include <windows.h> | 8 #include <windows.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 | 11 |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/compiler_specific.h" | 13 #include "base/compiler_specific.h" |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/threading/non_thread_safe.h" | 16 #include "base/threading/thread_checker.h" |
17 #include "base/timer/timer.h" | 17 #include "base/timer/timer.h" |
18 #include "base/win/object_watcher.h" | 18 #include "base/win/object_watcher.h" |
19 #include "net/base/net_export.h" | 19 #include "net/base/net_export.h" |
20 #include "net/base/network_change_notifier.h" | 20 #include "net/base/network_change_notifier.h" |
21 | 21 |
22 namespace net { | 22 namespace net { |
23 | 23 |
24 // NetworkChangeNotifierWin inherits from NonThreadSafe, as all its internal | 24 // NetworkChangeNotifierWin uses a ThreadChecker, as all its internal |
25 // notification code must be called on the thread it is created and destroyed | 25 // notification code must be called on the thread it is created and destroyed |
26 // on. All the NetworkChangeNotifier methods it implements are threadsafe. | 26 // on. All the NetworkChangeNotifier methods it implements are threadsafe. |
27 class NET_EXPORT_PRIVATE NetworkChangeNotifierWin | 27 class NET_EXPORT_PRIVATE NetworkChangeNotifierWin |
28 : public NetworkChangeNotifier, | 28 : public NetworkChangeNotifier, |
29 public base::win::ObjectWatcher::Delegate, | 29 public base::win::ObjectWatcher::Delegate { |
30 NON_EXPORTED_BASE(public base::NonThreadSafe) { | |
31 public: | 30 public: |
32 NetworkChangeNotifierWin(); | 31 NetworkChangeNotifierWin(); |
33 | 32 |
34 // Begins listening for a single subsequent address change. If it fails to | 33 // Begins listening for a single subsequent address change. If it fails to |
35 // start watching, it retries on a timer. Must be called only once, on the | 34 // start watching, it retries on a timer. Must be called only once, on the |
36 // thread |this| was created on. This cannot be called in the constructor, as | 35 // thread |this| was created on. This cannot be called in the constructor, as |
37 // WatchForAddressChangeInternal is mocked out in unit tests. | 36 // WatchForAddressChangeInternal is mocked out in unit tests. |
38 // TODO(mmenke): Consider making this function a part of the | 37 // TODO(mmenke): Consider making this function a part of the |
39 // NetworkChangeNotifier interface, so other subclasses can be | 38 // NetworkChangeNotifier interface, so other subclasses can be |
40 // unit tested in similar fashion, as needed. | 39 // unit tested in similar fashion, as needed. |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 | 107 |
109 mutable base::Lock last_computed_connection_type_lock_; | 108 mutable base::Lock last_computed_connection_type_lock_; |
110 ConnectionType last_computed_connection_type_; | 109 ConnectionType last_computed_connection_type_; |
111 | 110 |
112 // Result of IsOffline() when NotifyObserversOfConnectionTypeChange() | 111 // Result of IsOffline() when NotifyObserversOfConnectionTypeChange() |
113 // was last called. | 112 // was last called. |
114 bool last_announced_offline_; | 113 bool last_announced_offline_; |
115 // Number of times polled to check if still offline. | 114 // Number of times polled to check if still offline. |
116 int offline_polls_; | 115 int offline_polls_; |
117 | 116 |
| 117 THREAD_CHECKER(thread_checker_); |
| 118 |
118 // Used for calling WatchForAddressChange again on failure. | 119 // Used for calling WatchForAddressChange again on failure. |
119 base::WeakPtrFactory<NetworkChangeNotifierWin> weak_factory_; | 120 base::WeakPtrFactory<NetworkChangeNotifierWin> weak_factory_; |
120 | 121 |
121 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierWin); | 122 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifierWin); |
122 }; | 123 }; |
123 | 124 |
124 } // namespace net | 125 } // namespace net |
125 | 126 |
126 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_WIN_H_ | 127 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_WIN_H_ |
OLD | NEW |