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> | 8 #include <vector> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
179 protected: | 179 protected: |
180 NetworkChangeObserver() {} | 180 NetworkChangeObserver() {} |
181 virtual ~NetworkChangeObserver() {} | 181 virtual ~NetworkChangeObserver() {} |
182 | 182 |
183 private: | 183 private: |
184 DISALLOW_COPY_AND_ASSIGN(NetworkChangeObserver); | 184 DISALLOW_COPY_AND_ASSIGN(NetworkChangeObserver); |
185 }; | 185 }; |
186 | 186 |
187 class NET_EXPORT MaxBandwidthObserver { | 187 class NET_EXPORT MaxBandwidthObserver { |
188 public: | 188 public: |
189 // Will be called when a change occurs to the network's maximum bandwidth as | 189 // Called when a change occurs to the network's maximum bandwidth as |
190 // defined in http://w3c.github.io/netinfo/. Generally this will only be | 190 // defined in http://w3c.github.io/netinfo/. Also called on type change, |
191 // called on bandwidth changing network connection/disconnection events. | 191 // even if the maximum bandwidth doesn't change. See the documentation of |
192 // Some platforms may call it more frequently, such as when WiFi signal | 192 // GetMaxBanwidth for what to expect for the values of |max_bandwidth_mbps|. |
193 // strength changes. | 193 virtual void OnMaxBandwidthChanged(ConnectionType type, |
194 // TODO(jkarlin): This is currently only implemented for Android. Implement | 194 double max_bandwidth_mbps) = 0; |
195 // on every platform. | |
196 virtual void OnMaxBandwidthChanged(double max_bandwidth_mbps) = 0; | |
197 | 195 |
198 protected: | 196 protected: |
199 MaxBandwidthObserver() {} | 197 MaxBandwidthObserver() {} |
200 virtual ~MaxBandwidthObserver() {} | 198 virtual ~MaxBandwidthObserver() {} |
201 | 199 |
202 private: | 200 private: |
203 DISALLOW_COPY_AND_ASSIGN(MaxBandwidthObserver); | 201 DISALLOW_COPY_AND_ASSIGN(MaxBandwidthObserver); |
204 }; | 202 }; |
205 | 203 |
206 virtual ~NetworkChangeNotifier(); | 204 virtual ~NetworkChangeNotifier(); |
(...skipping 21 matching lines...) Expand all Loading... | |
228 // value doesn't imply that the user will be able to connect to remote sites; | 226 // value doesn't imply that the user will be able to connect to remote sites; |
229 // even if some link is up, it is uncertain whether a particular connection | 227 // even if some link is up, it is uncertain whether a particular connection |
230 // attempt to a particular remote site will be successful. | 228 // attempt to a particular remote site will be successful. |
231 // The returned value only describes the connection currently used by the | 229 // The returned value only describes the connection currently used by the |
232 // device, and does not take into account other machines on the network. For | 230 // device, and does not take into account other machines on the network. For |
233 // example, if the device is connected using Wifi to a 3G gateway to access | 231 // example, if the device is connected using Wifi to a 3G gateway to access |
234 // the internet, the connection type is CONNECTION_WIFI. | 232 // the internet, the connection type is CONNECTION_WIFI. |
235 static ConnectionType GetConnectionType(); | 233 static ConnectionType GetConnectionType(); |
236 | 234 |
237 // Returns a theoretical upper limit on download bandwidth, potentially based | 235 // Returns a theoretical upper limit on download bandwidth, potentially based |
238 // on underlying connection type, signal strength, or some other signal. The | 236 // on underlying connection type, signal strength, or some other signal. |
239 // default mapping of connection type to maximum bandwidth is provided in the | 237 // Specifically, it returns +Infinity if there is a connection and 0.0 |
240 // NetInfo spec: http://w3c.github.io/netinfo/. Host-specific application | 238 // otherwise. The circumstances in which a more specific value is given are: |
241 // permissions may be required, please see host-specific declaration for more | 239 // Android cellular types, Android wifi types, and ChromeOS cellular types. |
242 // information. | 240 // See the NetInfo spec for the mapping of specific subtypes to bandwidth |
243 static double GetMaxBandwidth(); | 241 // values: http://w3c.github.io/netinfo/. |
242 // If |connection_type| is not nullptr then it is set to the | |
243 // current ConnectionType. | |
244 static double GetMaxBandwidthAndConnectionType( | |
245 ConnectionType* connection_type); | |
pauljensen
2015/09/11 18:59:02
Are you going to change this API to take pointers
jkarlin
2015/09/11 19:04:26
Ah, I took our convo. to mean that you were fine w
pauljensen
2015/09/11 19:18:59
Oh, no, I was trying to say I wanted it to be:
voi
jkarlin
2015/09/11 20:07:24
Done.
| |
244 | 246 |
245 // Retrieve the last read DnsConfig. This could be expensive if the system has | 247 // Retrieve the last read DnsConfig. This could be expensive if the system has |
246 // a large HOSTS file. | 248 // a large HOSTS file. |
247 static void GetDnsConfig(DnsConfig* config); | 249 static void GetDnsConfig(DnsConfig* config); |
248 | 250 |
249 #if defined(OS_LINUX) | 251 #if defined(OS_LINUX) |
250 // Returns the AddressTrackerLinux if present. | 252 // Returns the AddressTrackerLinux if present. |
251 static const internal::AddressTrackerLinux* GetAddressTracker(); | 253 static const internal::AddressTrackerLinux* GetAddressTracker(); |
252 #endif | 254 #endif |
253 | 255 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 static void RemoveDNSObserver(DNSObserver* observer); | 304 static void RemoveDNSObserver(DNSObserver* observer); |
303 static void RemoveNetworkChangeObserver(NetworkChangeObserver* observer); | 305 static void RemoveNetworkChangeObserver(NetworkChangeObserver* observer); |
304 static void RemoveMaxBandwidthObserver(MaxBandwidthObserver* observer); | 306 static void RemoveMaxBandwidthObserver(MaxBandwidthObserver* observer); |
305 | 307 |
306 // Allow unit tests to trigger notifications. | 308 // Allow unit tests to trigger notifications. |
307 static void NotifyObserversOfIPAddressChangeForTests(); | 309 static void NotifyObserversOfIPAddressChangeForTests(); |
308 static void NotifyObserversOfConnectionTypeChangeForTests( | 310 static void NotifyObserversOfConnectionTypeChangeForTests( |
309 ConnectionType type); | 311 ConnectionType type); |
310 static void NotifyObserversOfNetworkChangeForTests(ConnectionType type); | 312 static void NotifyObserversOfNetworkChangeForTests(ConnectionType type); |
311 static void NotifyObserversOfInitialDNSConfigReadForTests(); | 313 static void NotifyObserversOfInitialDNSConfigReadForTests(); |
314 static void NotifyObserversOfMaxBandwidthChangeForTests(ConnectionType type, | |
315 double max_bandwidth); | |
312 | 316 |
313 // Enable or disable notifications from the host. After setting to true, be | 317 // Enable or disable notifications from the host. After setting to true, be |
314 // sure to pump the RunLoop until idle to finish any preexisting | 318 // sure to pump the RunLoop until idle to finish any preexisting |
315 // notifications. To use this, it must must be called before a | 319 // notifications. To use this, it must must be called before a |
316 // NetworkChangeNotifier is created. | 320 // NetworkChangeNotifier is created. |
317 static void SetTestNotificationsOnly(bool test_only); | 321 static void SetTestNotificationsOnly(bool test_only); |
318 | 322 |
319 // Return a string equivalent to |type|. | 323 // Return a string equivalent to |type|. |
320 static const char* ConnectionTypeToString(ConnectionType type); | 324 static const char* ConnectionTypeToString(ConnectionType type); |
321 | 325 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 #if defined(OS_LINUX) | 389 #if defined(OS_LINUX) |
386 // Returns the AddressTrackerLinux if present. | 390 // Returns the AddressTrackerLinux if present. |
387 // TODO(szym): Retrieve AddressMap from NetworkState. http://crbug.com/144212 | 391 // TODO(szym): Retrieve AddressMap from NetworkState. http://crbug.com/144212 |
388 virtual const internal::AddressTrackerLinux* | 392 virtual const internal::AddressTrackerLinux* |
389 GetAddressTrackerInternal() const; | 393 GetAddressTrackerInternal() const; |
390 #endif | 394 #endif |
391 | 395 |
392 // See the description of NetworkChangeNotifier::GetMaxBandwidth(). | 396 // See the description of NetworkChangeNotifier::GetMaxBandwidth(). |
393 // Implementations must be thread-safe. Implementations must also be | 397 // Implementations must be thread-safe. Implementations must also be |
394 // cheap as it is called often. | 398 // cheap as it is called often. |
395 virtual double GetCurrentMaxBandwidth() const; | 399 virtual double GetCurrentMaxBandwidthAndConnectionType( |
400 ConnectionType* connection_type) const; | |
pauljensen
2015/09/11 18:59:02
ditto
jkarlin
2015/09/11 20:07:23
Done.
| |
396 | 401 |
397 // Returns a theoretical upper limit on download bandwidth given a connection | 402 // Returns a theoretical upper limit on download bandwidth given a connection |
398 // subtype. The mapping of connection type to maximum bandwidth is provided in | 403 // subtype. The mapping of connection type to maximum bandwidth is provided in |
399 // the NetInfo spec: http://w3c.github.io/netinfo/. | 404 // the NetInfo spec: http://w3c.github.io/netinfo/. |
400 static double GetMaxBandwidthForConnectionSubtype(ConnectionSubtype subtype); | 405 static double GetMaxBandwidthForConnectionSubtype(ConnectionSubtype subtype); |
401 | 406 |
402 // Broadcasts a notification to all registered observers. Note that this | 407 // Broadcasts a notification to all registered observers. Note that this |
403 // happens asynchronously, even for observers on the current thread, even in | 408 // happens asynchronously, even for observers on the current thread, even in |
404 // tests. | 409 // tests. |
405 static void NotifyObserversOfIPAddressChange(); | 410 static void NotifyObserversOfIPAddressChange(); |
406 static void NotifyObserversOfConnectionTypeChange(); | 411 static void NotifyObserversOfConnectionTypeChange(); |
407 static void NotifyObserversOfDNSChange(); | 412 static void NotifyObserversOfDNSChange(); |
408 static void NotifyObserversOfInitialDNSConfigRead(); | 413 static void NotifyObserversOfInitialDNSConfigRead(); |
409 static void NotifyObserversOfNetworkChange(ConnectionType type); | 414 static void NotifyObserversOfNetworkChange(ConnectionType type); |
410 static void NotifyObserversOfMaxBandwidthChange(double max_bandwidth_mbps); | 415 static void NotifyObserversOfMaxBandwidthChange(ConnectionType type, |
416 double max_bandwidth_mbps); | |
411 | 417 |
412 // Stores |config| in NetworkState and notifies OnDNSChanged observers. | 418 // Stores |config| in NetworkState and notifies OnDNSChanged observers. |
413 static void SetDnsConfig(const DnsConfig& config); | 419 static void SetDnsConfig(const DnsConfig& config); |
414 // Stores |config| in NetworkState and notifies OnInitialDNSConfigRead | 420 // Stores |config| in NetworkState and notifies OnInitialDNSConfigRead |
415 // observers. | 421 // observers. |
416 static void SetInitialDnsConfig(const DnsConfig& config); | 422 static void SetInitialDnsConfig(const DnsConfig& config); |
417 | 423 |
418 private: | 424 private: |
419 friend class HostResolverImplDnsTest; | 425 friend class HostResolverImplDnsTest; |
420 friend class NetworkChangeNotifierAndroidTest; | 426 friend class NetworkChangeNotifierAndroidTest; |
421 friend class NetworkChangeNotifierLinuxTest; | 427 friend class NetworkChangeNotifierLinuxTest; |
422 friend class NetworkChangeNotifierWinTest; | 428 friend class NetworkChangeNotifierWinTest; |
423 | 429 |
424 class NetworkState; | 430 class NetworkState; |
425 class NetworkChangeCalculator; | 431 class NetworkChangeCalculator; |
426 | 432 |
427 void NotifyObserversOfIPAddressChangeImpl(); | 433 void NotifyObserversOfIPAddressChangeImpl(); |
428 void NotifyObserversOfConnectionTypeChangeImpl(ConnectionType type); | 434 void NotifyObserversOfConnectionTypeChangeImpl(ConnectionType type); |
429 void NotifyObserversOfDNSChangeImpl(); | 435 void NotifyObserversOfDNSChangeImpl(); |
430 void NotifyObserversOfInitialDNSConfigReadImpl(); | 436 void NotifyObserversOfInitialDNSConfigReadImpl(); |
431 void NotifyObserversOfNetworkChangeImpl(ConnectionType type); | 437 void NotifyObserversOfNetworkChangeImpl(ConnectionType type); |
432 void NotifyObserversOfMaxBandwidthChangeImpl(double max_bandwidth_mbps); | 438 void NotifyObserversOfMaxBandwidthChangeImpl(ConnectionType type, |
439 double max_bandwidth_mbps); | |
433 | 440 |
434 const scoped_refptr<base::ObserverListThreadSafe<IPAddressObserver>> | 441 const scoped_refptr<base::ObserverListThreadSafe<IPAddressObserver>> |
435 ip_address_observer_list_; | 442 ip_address_observer_list_; |
436 const scoped_refptr<base::ObserverListThreadSafe<ConnectionTypeObserver>> | 443 const scoped_refptr<base::ObserverListThreadSafe<ConnectionTypeObserver>> |
437 connection_type_observer_list_; | 444 connection_type_observer_list_; |
438 const scoped_refptr<base::ObserverListThreadSafe<DNSObserver>> | 445 const scoped_refptr<base::ObserverListThreadSafe<DNSObserver>> |
439 resolver_state_observer_list_; | 446 resolver_state_observer_list_; |
440 const scoped_refptr<base::ObserverListThreadSafe<NetworkChangeObserver>> | 447 const scoped_refptr<base::ObserverListThreadSafe<NetworkChangeObserver>> |
441 network_change_observer_list_; | 448 network_change_observer_list_; |
442 const scoped_refptr<base::ObserverListThreadSafe<MaxBandwidthObserver>> | 449 const scoped_refptr<base::ObserverListThreadSafe<MaxBandwidthObserver>> |
(...skipping 10 matching lines...) Expand all Loading... | |
453 | 460 |
454 // Set true to disable non-test notifications (to prevent flakes in tests). | 461 // Set true to disable non-test notifications (to prevent flakes in tests). |
455 static bool test_notifications_only_; | 462 static bool test_notifications_only_; |
456 | 463 |
457 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier); | 464 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier); |
458 }; | 465 }; |
459 | 466 |
460 } // namespace net | 467 } // namespace net |
461 | 468 |
462 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ | 469 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ |
OLD | NEW |