Index: net/base/network_change_notifier.h |
diff --git a/net/base/network_change_notifier.h b/net/base/network_change_notifier.h |
index 84e399ee6c28162d53fc49695e1c51109b09a5a8..1884c8eb061d690eafe1a55a8f7bbad165cf029f 100644 |
--- a/net/base/network_change_notifier.h |
+++ b/net/base/network_change_notifier.h |
@@ -86,6 +86,43 @@ class NET_EXPORT NetworkChangeNotifier { |
DISALLOW_COPY_AND_ASSIGN(DNSObserver); |
}; |
+ class NET_EXPORT NetworkChangeObserver { |
+ public: |
+ // OnNetworkChanged will be called when a change occurs to the host |
+ // computer's hardware or software that affects the route network packets |
+ // take to any network server. Some examples: |
+ // 1. A network connection becoming available or going away. For example |
+ // plugging or unplugging an Ethernet cable, WiFi or cellular modem |
+ // connecting or disconnecting from a network, or a VPN tunnel being |
+ // established or taken down. |
+ // 2. An active network connection's IP address changes. |
+ // 3. A change to the local IP routing tables. |
+ // The signal shall only be produced when the change is complete. For |
+ // example if a new network connection has become available, only give the |
+ // signal once we think the O/S has finished establishing the connection |
+ // (i.e. DHCP is done) to the point where the new connection is usable. |
+ // The signal shall not be produced spuriously as it will be triggering some |
+ // expensive operations, like socket pools closing all connections and |
+ // sockets and then re-establishing them. |
+ // |type| indicates the type of the active primary network connection after |
+ // the change. Observers performing "constructive" activities like trying |
+ // to establish a connection to a server should only do so when |
+ // |type != CONNECTION_NONE|. Observers performing "destructive" activities |
+ // like resetting already established server connections should only do so |
+ // when |type == CONNECTION_NONE|. OnNetworkChanged will be called with |
+ // CONNECTION_NONE immediately prior to being called with an online state; |
+ // this is done to make sure that destructive actions take place prior to |
+ // constructive actions. |
+ virtual void OnNetworkChanged(ConnectionType type) = 0; |
+ |
+ protected: |
+ NetworkChangeObserver() {} |
+ virtual ~NetworkChangeObserver() {} |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(NetworkChangeObserver); |
+ }; |
+ |
virtual ~NetworkChangeNotifier(); |
// See the description of NetworkChangeNotifier::GetConnectionType(). |
@@ -155,6 +192,7 @@ class NET_EXPORT NetworkChangeNotifier { |
static void AddIPAddressObserver(IPAddressObserver* observer); |
static void AddConnectionTypeObserver(ConnectionTypeObserver* observer); |
static void AddDNSObserver(DNSObserver* observer); |
+ static void AddNetworkChangeObserver(NetworkChangeObserver* observer); |
// Unregisters |observer| from receiving notifications. This must be called |
// on the same thread on which AddObserver() was called. Like AddObserver(), |
@@ -166,6 +204,7 @@ class NET_EXPORT NetworkChangeNotifier { |
static void RemoveIPAddressObserver(IPAddressObserver* observer); |
static void RemoveConnectionTypeObserver(ConnectionTypeObserver* observer); |
static void RemoveDNSObserver(DNSObserver* observer); |
+ static void RemoveNetworkChangeObserver(NetworkChangeObserver* observer); |
// Allow unit tests to trigger notifications. |
static void NotifyObserversOfIPAddressChangeForTests() { |
@@ -185,7 +224,14 @@ class NET_EXPORT NetworkChangeNotifier { |
static void InitHistogramWatcher(); |
protected: |
- NetworkChangeNotifier(); |
+ // Delay arguments control how many milliseconds to delay notifications |
+ // so as to combine duplicates. They should be tuned for the particular |
+ // child class implementation. See NetworkChangeCalculator() for more |
+ // details. |
+ NetworkChangeNotifier(uint32 ip_address_offline_delay_ms, |
+ uint32 ip_address_online_delay_ms, |
+ uint32 connection_type_offline_delay_ms, |
+ uint32 connection_type_online_delay_ms); |
szym
2012/11/25 07:37:37
They should be TimeDelta.
I suggest using four in
|
#if defined(OS_LINUX) |
// Returns the AddressTrackerLinux if present. |
@@ -200,6 +246,7 @@ class NET_EXPORT NetworkChangeNotifier { |
static void NotifyObserversOfIPAddressChange(); |
static void NotifyObserversOfConnectionTypeChange(); |
static void NotifyObserversOfDNSChange(); |
+ static void NotifyObserversOfNetworkChange(ConnectionType type); |
// Stores |config| in NetworkState and notifies observers. |
static void SetDnsConfig(const DnsConfig& config); |
@@ -211,6 +258,7 @@ class NET_EXPORT NetworkChangeNotifier { |
friend class NetworkChangeNotifierWinTest; |
class NetworkState; |
+ class NetworkChangeCalculator; |
// Allows a second NetworkChangeNotifier to be created for unit testing, so |
// the test suite can create a MockNetworkChangeNotifier, but platform |
@@ -235,6 +283,8 @@ class NET_EXPORT NetworkChangeNotifier { |
connection_type_observer_list_; |
const scoped_refptr<ObserverListThreadSafe<DNSObserver> > |
resolver_state_observer_list_; |
+ const scoped_refptr<ObserverListThreadSafe<NetworkChangeObserver> > |
+ network_change_observer_list_; |
// The current network state. Hosts DnsConfig, exposed via GetDnsConfig. |
scoped_ptr<NetworkState> network_state_; |
@@ -242,6 +292,9 @@ class NET_EXPORT NetworkChangeNotifier { |
// A little-piggy-back observer that simply logs UMA histogram data. |
scoped_ptr<HistogramWatcher> histogram_watcher_; |
+ // Computes NetworkChange signal from IPAddress and ConnectionType signals. |
+ scoped_ptr<NetworkChangeCalculator> network_change_calculator_; |
+ |
DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier); |
}; |