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|. |
pauljensen
2015/09/15 18:17:40
GetMaxBandwidth->GetMaxBandwidthAndConnectionType
jkarlin
2015/09/16 12:12:22
Done.
| |
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 20 matching lines...) Expand all Loading... | |
227 // user won't be able to connect to remote sites. However, another return | 225 // user won't be able to connect to remote sites. However, another return |
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 // Sets |max_bandwidth_mbps| to a theoretical upper limit on download |
238 // on underlying connection type, signal strength, or some other signal. The | 236 // bandwidth, potentially based on underlying connection type, signal |
239 // default mapping of connection type to maximum bandwidth is provided in the | 237 // strength, or some other signal. Specifically, it returns +Infinity if there |
240 // NetInfo spec: http://w3c.github.io/netinfo/. Host-specific application | 238 // is a connection and 0.0 otherwise. The circumstances in which a more |
pauljensen
2015/09/15 18:17:40
Um I think it does more than "Specifically, it ret
jkarlin
2015/09/16 12:12:22
Done.
| |
241 // permissions may be required, please see host-specific declaration for more | 239 // specific value is given are: Android cellular types, Android wifi types, |
pauljensen
2015/09/15 18:17:40
can we reword the "types" here to something like "
pauljensen
2015/09/15 18:17:40
wifi->WiFi
jkarlin
2015/09/16 12:12:22
Done.
jkarlin
2015/09/16 12:12:22
Done.
| |
242 // information. | 240 // and ChromeOS cellular types. See the NetInfo spec for the mapping of |
243 static double GetMaxBandwidth(); | 241 // specific subtypes to bandwidth values: http://w3c.github.io/netinfo/. |
242 // |connection_type| is set to the current ConnectionType. | |
pauljensen
2015/09/15 18:17:40
ConnectionType->active default network's connectio
jkarlin
2015/09/16 12:12:22
Done.
| |
243 static void GetMaxBandwidthAndConnectionType(double* max_bandwidth_mbps, | |
244 ConnectionType* connection_type); | |
244 | 245 |
245 // Retrieve the last read DnsConfig. This could be expensive if the system has | 246 // Retrieve the last read DnsConfig. This could be expensive if the system has |
246 // a large HOSTS file. | 247 // a large HOSTS file. |
247 static void GetDnsConfig(DnsConfig* config); | 248 static void GetDnsConfig(DnsConfig* config); |
248 | 249 |
249 #if defined(OS_LINUX) | 250 #if defined(OS_LINUX) |
250 // Returns the AddressTrackerLinux if present. | 251 // Returns the AddressTrackerLinux if present. |
251 static const internal::AddressTrackerLinux* GetAddressTracker(); | 252 static const internal::AddressTrackerLinux* GetAddressTracker(); |
252 #endif | 253 #endif |
253 | 254 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 static void RemoveDNSObserver(DNSObserver* observer); | 303 static void RemoveDNSObserver(DNSObserver* observer); |
303 static void RemoveNetworkChangeObserver(NetworkChangeObserver* observer); | 304 static void RemoveNetworkChangeObserver(NetworkChangeObserver* observer); |
304 static void RemoveMaxBandwidthObserver(MaxBandwidthObserver* observer); | 305 static void RemoveMaxBandwidthObserver(MaxBandwidthObserver* observer); |
305 | 306 |
306 // Allow unit tests to trigger notifications. | 307 // Allow unit tests to trigger notifications. |
307 static void NotifyObserversOfIPAddressChangeForTests(); | 308 static void NotifyObserversOfIPAddressChangeForTests(); |
308 static void NotifyObserversOfConnectionTypeChangeForTests( | 309 static void NotifyObserversOfConnectionTypeChangeForTests( |
309 ConnectionType type); | 310 ConnectionType type); |
310 static void NotifyObserversOfNetworkChangeForTests(ConnectionType type); | 311 static void NotifyObserversOfNetworkChangeForTests(ConnectionType type); |
311 static void NotifyObserversOfInitialDNSConfigReadForTests(); | 312 static void NotifyObserversOfInitialDNSConfigReadForTests(); |
313 static void NotifyObserversOfMaxBandwidthChangeForTests(ConnectionType type, | |
314 double max_bandwidth); | |
312 | 315 |
313 // Enable or disable notifications from the host. After setting to true, be | 316 // Enable or disable notifications from the host. After setting to true, be |
314 // sure to pump the RunLoop until idle to finish any preexisting | 317 // sure to pump the RunLoop until idle to finish any preexisting |
315 // notifications. To use this, it must must be called before a | 318 // notifications. To use this, it must must be called before a |
316 // NetworkChangeNotifier is created. | 319 // NetworkChangeNotifier is created. |
317 static void SetTestNotificationsOnly(bool test_only); | 320 static void SetTestNotificationsOnly(bool test_only); |
318 | 321 |
319 // Return a string equivalent to |type|. | 322 // Return a string equivalent to |type|. |
320 static const char* ConnectionTypeToString(ConnectionType type); | 323 static const char* ConnectionTypeToString(ConnectionType type); |
321 | 324 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
385 #if defined(OS_LINUX) | 388 #if defined(OS_LINUX) |
386 // Returns the AddressTrackerLinux if present. | 389 // Returns the AddressTrackerLinux if present. |
387 // TODO(szym): Retrieve AddressMap from NetworkState. http://crbug.com/144212 | 390 // TODO(szym): Retrieve AddressMap from NetworkState. http://crbug.com/144212 |
388 virtual const internal::AddressTrackerLinux* | 391 virtual const internal::AddressTrackerLinux* |
389 GetAddressTrackerInternal() const; | 392 GetAddressTrackerInternal() const; |
390 #endif | 393 #endif |
391 | 394 |
392 // See the description of NetworkChangeNotifier::GetMaxBandwidth(). | 395 // See the description of NetworkChangeNotifier::GetMaxBandwidth(). |
393 // Implementations must be thread-safe. Implementations must also be | 396 // Implementations must be thread-safe. Implementations must also be |
394 // cheap as it is called often. | 397 // cheap as it is called often. |
395 virtual double GetCurrentMaxBandwidth() const; | 398 virtual void GetCurrentMaxBandwidthAndConnectionType( |
399 double* max_bandwidth_mbps, | |
400 ConnectionType* connection_type) const; | |
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 |