Chromium Code Reviews| 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 <vector> | |
| 9 | |
| 8 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| 11 #include "base/gtest_prod_util.h" | |
| 9 #include "base/observer_list_threadsafe.h" | 12 #include "base/observer_list_threadsafe.h" |
| 10 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 11 #include "net/base/net_export.h" | 14 #include "net/base/net_export.h" |
|
pauljensen
2014/06/20 05:58:53
Sadly I cannot include net_util.h here because it
| |
| 12 | 15 |
| 13 class GURL; | 16 class GURL; |
| 14 | 17 |
| 15 namespace net { | 18 namespace net { |
| 16 | 19 |
| 17 struct DnsConfig; | 20 struct DnsConfig; |
| 18 class HistogramWatcher; | 21 class HistogramWatcher; |
| 19 class NetworkChangeNotifierFactory; | 22 class NetworkChangeNotifierFactory; |
| 23 struct NetworkInterface; | |
| 24 typedef std::vector<NetworkInterface> NetworkInterfaceList; | |
|
pauljensen
2014/06/20 05:58:53
This is sadly necessary because net_util.h include
mmenke
2014/06/20 15:18:57
Ugly, but fine for now. I'd argue it may make sen
| |
| 20 class URLRequest; | 25 class URLRequest; |
| 21 | 26 |
| 22 #if defined(OS_LINUX) | 27 #if defined(OS_LINUX) |
| 23 namespace internal { | 28 namespace internal { |
| 24 class AddressTrackerLinux; | 29 class AddressTrackerLinux; |
| 25 } | 30 } |
| 26 #endif | 31 #endif |
| 27 | 32 |
| 28 // NetworkChangeNotifier monitors the system for network changes, and notifies | 33 // NetworkChangeNotifier monitors the system for network changes, and notifies |
| 29 // registered observers of those events. Observers may register on any thread, | 34 // registered observers of those events. Observers may register on any thread, |
| (...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 // happens asynchronously, even for observers on the current thread, even in | 298 // happens asynchronously, even for observers on the current thread, even in |
| 294 // tests. | 299 // tests. |
| 295 static void NotifyObserversOfIPAddressChange(); | 300 static void NotifyObserversOfIPAddressChange(); |
| 296 static void NotifyObserversOfConnectionTypeChange(); | 301 static void NotifyObserversOfConnectionTypeChange(); |
| 297 static void NotifyObserversOfDNSChange(); | 302 static void NotifyObserversOfDNSChange(); |
| 298 static void NotifyObserversOfNetworkChange(ConnectionType type); | 303 static void NotifyObserversOfNetworkChange(ConnectionType type); |
| 299 | 304 |
| 300 // Stores |config| in NetworkState and notifies observers. | 305 // Stores |config| in NetworkState and notifies observers. |
| 301 static void SetDnsConfig(const DnsConfig& config); | 306 static void SetDnsConfig(const DnsConfig& config); |
| 302 | 307 |
| 308 // Infer connection type from |GetNetworkList|. If all network interfaces have | |
| 309 // the same type, return it, otherwise return CONNECTION_UNKNOWN. | |
| 310 static ConnectionType ConnectionTypeFromInterfaces(); | |
| 311 | |
| 303 private: | 312 private: |
| 304 friend class HostResolverImplDnsTest; | 313 friend class HostResolverImplDnsTest; |
| 305 friend class NetworkChangeNotifierAndroidTest; | 314 friend class NetworkChangeNotifierAndroidTest; |
| 306 friend class NetworkChangeNotifierLinuxTest; | 315 friend class NetworkChangeNotifierLinuxTest; |
| 307 friend class NetworkChangeNotifierWinTest; | 316 friend class NetworkChangeNotifierWinTest; |
| 317 FRIEND_TEST_ALL_PREFIXES(NetworkChangeNotifierTest, | |
| 318 InterfacesToConnectionType); | |
| 308 | 319 |
| 309 class NetworkState; | 320 class NetworkState; |
| 310 class NetworkChangeCalculator; | 321 class NetworkChangeCalculator; |
| 311 | 322 |
| 323 // Infer connection type from |list|. If all network interfaces have | |
| 324 // the same type, return it, otherwise return CONNECTION_UNKNOWN. | |
| 325 static ConnectionType ConnectionTypeFromInterfaceList( | |
| 326 const NetworkInterfaceList& interfaces); | |
| 327 | |
| 312 const scoped_refptr<ObserverListThreadSafe<IPAddressObserver> > | 328 const scoped_refptr<ObserverListThreadSafe<IPAddressObserver> > |
| 313 ip_address_observer_list_; | 329 ip_address_observer_list_; |
| 314 const scoped_refptr<ObserverListThreadSafe<ConnectionTypeObserver> > | 330 const scoped_refptr<ObserverListThreadSafe<ConnectionTypeObserver> > |
| 315 connection_type_observer_list_; | 331 connection_type_observer_list_; |
| 316 const scoped_refptr<ObserverListThreadSafe<DNSObserver> > | 332 const scoped_refptr<ObserverListThreadSafe<DNSObserver> > |
| 317 resolver_state_observer_list_; | 333 resolver_state_observer_list_; |
| 318 const scoped_refptr<ObserverListThreadSafe<NetworkChangeObserver> > | 334 const scoped_refptr<ObserverListThreadSafe<NetworkChangeObserver> > |
| 319 network_change_observer_list_; | 335 network_change_observer_list_; |
| 320 | 336 |
| 321 // The current network state. Hosts DnsConfig, exposed via GetDnsConfig. | 337 // The current network state. Hosts DnsConfig, exposed via GetDnsConfig. |
| 322 scoped_ptr<NetworkState> network_state_; | 338 scoped_ptr<NetworkState> network_state_; |
| 323 | 339 |
| 324 // A little-piggy-back observer that simply logs UMA histogram data. | 340 // A little-piggy-back observer that simply logs UMA histogram data. |
| 325 scoped_ptr<HistogramWatcher> histogram_watcher_; | 341 scoped_ptr<HistogramWatcher> histogram_watcher_; |
| 326 | 342 |
| 327 // Computes NetworkChange signal from IPAddress and ConnectionType signals. | 343 // Computes NetworkChange signal from IPAddress and ConnectionType signals. |
| 328 scoped_ptr<NetworkChangeCalculator> network_change_calculator_; | 344 scoped_ptr<NetworkChangeCalculator> network_change_calculator_; |
| 329 | 345 |
| 330 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier); | 346 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier); |
| 331 }; | 347 }; |
| 332 | 348 |
| 333 } // namespace net | 349 } // namespace net |
| 334 | 350 |
| 335 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ | 351 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ |
| OLD | NEW |