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_H_ | 5 #ifndef NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ |
6 #define NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ | 6 #define NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ |
7 | 7 |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/observer_list_threadsafe.h" | 9 #include "base/observer_list_threadsafe.h" |
10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
11 #include "net/base/net_export.h" | 11 #include "net/base/net_export.h" |
12 | 12 |
13 namespace net { | 13 namespace net { |
14 | 14 |
15 class NetworkChangeNotifierFactory; | 15 class NetworkChangeNotifierFactory; |
16 | 16 |
17 namespace internal { | 17 namespace internal { |
18 class DnsConfigWatcher; | 18 class DnsConfigWatcher; |
| 19 |
| 20 #if defined(OS_LINUX) |
| 21 class AddressTrackerLinux; |
| 22 #endif |
19 } | 23 } |
20 | 24 |
21 // NetworkChangeNotifier monitors the system for network changes, and notifies | 25 // NetworkChangeNotifier monitors the system for network changes, and notifies |
22 // registered observers of those events. Observers may register on any thread, | 26 // registered observers of those events. Observers may register on any thread, |
23 // and will be called back on the thread from which they registered. | 27 // and will be called back on the thread from which they registered. |
24 // NetworkChangeNotifiers are threadsafe, though they must be created and | 28 // NetworkChangeNotifiers are threadsafe, though they must be created and |
25 // destroyed on the same thread. | 29 // destroyed on the same thread. |
26 class NET_EXPORT NetworkChangeNotifier { | 30 class NET_EXPORT NetworkChangeNotifier { |
27 public: | 31 public: |
28 // Flags which are ORed together to form |detail| in OnDNSChanged. | 32 // Flags which are ORed together to form |detail| in OnDNSChanged. |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 static NetworkChangeNotifier* Create(); | 121 static NetworkChangeNotifier* Create(); |
118 | 122 |
119 // Returns the connection type. | 123 // Returns the connection type. |
120 // A return value of |CONNECTION_NONE| is a pretty strong indicator that the | 124 // A return value of |CONNECTION_NONE| is a pretty strong indicator that the |
121 // user won't be able to connect to remote sites. However, another return | 125 // user won't be able to connect to remote sites. However, another return |
122 // value doesn't imply that the user will be able to connect to remote sites; | 126 // value doesn't imply that the user will be able to connect to remote sites; |
123 // even if some link is up, it is uncertain whether a particular connection | 127 // even if some link is up, it is uncertain whether a particular connection |
124 // attempt to a particular remote site will be successful. | 128 // attempt to a particular remote site will be successful. |
125 static ConnectionType GetConnectionType(); | 129 static ConnectionType GetConnectionType(); |
126 | 130 |
| 131 #if defined(OS_LINUX) |
| 132 // Returns the AddressTrackerLinux if present. |
| 133 static const internal::AddressTrackerLinux* GetAddressTracker(); |
| 134 #endif |
| 135 |
127 // Convenience method to determine if the user is offline. | 136 // Convenience method to determine if the user is offline. |
128 // Returns true if there is currently no internet connection. | 137 // Returns true if there is currently no internet connection. |
129 // | 138 // |
130 // A return value of |true| is a pretty strong indicator that the user | 139 // A return value of |true| is a pretty strong indicator that the user |
131 // won't be able to connect to remote sites. However, a return value of | 140 // won't be able to connect to remote sites. However, a return value of |
132 // |false| is inconclusive; even if some link is up, it is uncertain | 141 // |false| is inconclusive; even if some link is up, it is uncertain |
133 // whether a particular connection attempt to a particular remote site | 142 // whether a particular connection attempt to a particular remote site |
134 // will be successfully. | 143 // will be successfully. |
135 static bool IsOffline() { | 144 static bool IsOffline() { |
136 return GetConnectionType() == CONNECTION_NONE; | 145 return GetConnectionType() == CONNECTION_NONE; |
(...skipping 29 matching lines...) Expand all Loading... |
166 // Allow unit tests to trigger notifications. | 175 // Allow unit tests to trigger notifications. |
167 static void NotifyObserversOfIPAddressChangeForTests() { | 176 static void NotifyObserversOfIPAddressChangeForTests() { |
168 NotifyObserversOfIPAddressChange(); | 177 NotifyObserversOfIPAddressChange(); |
169 } | 178 } |
170 | 179 |
171 protected: | 180 protected: |
172 friend class internal::DnsConfigWatcher; | 181 friend class internal::DnsConfigWatcher; |
173 | 182 |
174 NetworkChangeNotifier(); | 183 NetworkChangeNotifier(); |
175 | 184 |
| 185 #if defined(OS_LINUX) |
| 186 // Returns the AddressTrackerLinux if present. |
| 187 virtual const internal::AddressTrackerLinux* |
| 188 GetAddressTrackerInternal() const; |
| 189 #endif |
| 190 |
176 // Broadcasts a notification to all registered observers. Note that this | 191 // Broadcasts a notification to all registered observers. Note that this |
177 // happens asynchronously, even for observers on the current thread, even in | 192 // happens asynchronously, even for observers on the current thread, even in |
178 // tests. | 193 // tests. |
179 static void NotifyObserversOfIPAddressChange(); | 194 static void NotifyObserversOfIPAddressChange(); |
180 static void NotifyObserversOfConnectionTypeChange(); | 195 static void NotifyObserversOfConnectionTypeChange(); |
181 static void NotifyObserversOfDNSChange(unsigned detail); | 196 static void NotifyObserversOfDNSChange(unsigned detail); |
182 | 197 |
183 private: | 198 private: |
184 friend class NetworkChangeNotifierLinuxTest; | 199 friend class NetworkChangeNotifierLinuxTest; |
185 friend class NetworkChangeNotifierWinTest; | 200 friend class NetworkChangeNotifierWinTest; |
(...skipping 28 matching lines...) Expand all Loading... |
214 // http://crbug.com/116139 | 229 // http://crbug.com/116139 |
215 base::Lock watching_dns_lock_; | 230 base::Lock watching_dns_lock_; |
216 bool watching_dns_; | 231 bool watching_dns_; |
217 | 232 |
218 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier); | 233 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier); |
219 }; | 234 }; |
220 | 235 |
221 } // namespace net | 236 } // namespace net |
222 | 237 |
223 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ | 238 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ |
OLD | NEW |