Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(494)

Side by Side Diff: net/base/network_change_notifier.h

Issue 1306653003: Add connection type to NCN::MaxBandwidthChanged (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove extra space in comment Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // GetMaxBanwidthAndConnectionType for what to expect for the values of
193 // strength changes. 193 // |max_bandwidth_mbps|.
194 // TODO(jkarlin): This is currently only implemented for Android. Implement 194 virtual void OnMaxBandwidthChanged(double max_bandwidth_mbps,
195 // on every platform. 195 ConnectionType type) = 0;
196 virtual void OnMaxBandwidthChanged(double max_bandwidth_mbps) = 0;
197 196
198 protected: 197 protected:
199 MaxBandwidthObserver() {} 198 MaxBandwidthObserver() {}
200 virtual ~MaxBandwidthObserver() {} 199 virtual ~MaxBandwidthObserver() {}
201 200
202 private: 201 private:
203 DISALLOW_COPY_AND_ASSIGN(MaxBandwidthObserver); 202 DISALLOW_COPY_AND_ASSIGN(MaxBandwidthObserver);
204 }; 203 };
205 204
206 virtual ~NetworkChangeNotifier(); 205 virtual ~NetworkChangeNotifier();
(...skipping 20 matching lines...) Expand all
227 // user won't be able to connect to remote sites. However, another return 226 // 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; 227 // 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 228 // even if some link is up, it is uncertain whether a particular connection
230 // attempt to a particular remote site will be successful. 229 // attempt to a particular remote site will be successful.
231 // The returned value only describes the connection currently used by the 230 // 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 231 // 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 232 // example, if the device is connected using Wifi to a 3G gateway to access
234 // the internet, the connection type is CONNECTION_WIFI. 233 // the internet, the connection type is CONNECTION_WIFI.
235 static ConnectionType GetConnectionType(); 234 static ConnectionType GetConnectionType();
236 235
237 // Returns a theoretical upper limit on download bandwidth, potentially based 236 // Sets |max_bandwidth_mbps| to a theoretical upper limit on download
238 // on underlying connection type, signal strength, or some other signal. The 237 // bandwidth, potentially based on underlying connection type, signal
239 // default mapping of connection type to maximum bandwidth is provided in the 238 // strength, or some other signal. If the network subtype is unknown then
240 // NetInfo spec: http://w3c.github.io/netinfo/. Host-specific application 239 // |max_bandwidth_mbps| is set to +Infinity and if there is no network
241 // permissions may be required, please see host-specific declaration for more 240 // connection then it is set to 0.0. The circumstances in which a more
242 // information. 241 // specific value is given are: when an Android device is connected to a
243 static double GetMaxBandwidth(); 242 // cellular or WiFi network, and when a ChromeOS device is connected to a
243 // cellular network. See the NetInfo spec for the mapping of
244 // specific subtypes to bandwidth values: http://w3c.github.io/netinfo/.
245 // |connection_type| is set to the current active default network's connection
246 // type.
247 static void GetMaxBandwidthAndConnectionType(double* max_bandwidth_mbps,
248 ConnectionType* connection_type);
244 249
245 // Retrieve the last read DnsConfig. This could be expensive if the system has 250 // Retrieve the last read DnsConfig. This could be expensive if the system has
246 // a large HOSTS file. 251 // a large HOSTS file.
247 static void GetDnsConfig(DnsConfig* config); 252 static void GetDnsConfig(DnsConfig* config);
248 253
249 #if defined(OS_LINUX) 254 #if defined(OS_LINUX)
250 // Returns the AddressTrackerLinux if present. 255 // Returns the AddressTrackerLinux if present.
251 static const internal::AddressTrackerLinux* GetAddressTracker(); 256 static const internal::AddressTrackerLinux* GetAddressTracker();
252 #endif 257 #endif
253 258
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 static void RemoveDNSObserver(DNSObserver* observer); 307 static void RemoveDNSObserver(DNSObserver* observer);
303 static void RemoveNetworkChangeObserver(NetworkChangeObserver* observer); 308 static void RemoveNetworkChangeObserver(NetworkChangeObserver* observer);
304 static void RemoveMaxBandwidthObserver(MaxBandwidthObserver* observer); 309 static void RemoveMaxBandwidthObserver(MaxBandwidthObserver* observer);
305 310
306 // Allow unit tests to trigger notifications. 311 // Allow unit tests to trigger notifications.
307 static void NotifyObserversOfIPAddressChangeForTests(); 312 static void NotifyObserversOfIPAddressChangeForTests();
308 static void NotifyObserversOfConnectionTypeChangeForTests( 313 static void NotifyObserversOfConnectionTypeChangeForTests(
309 ConnectionType type); 314 ConnectionType type);
310 static void NotifyObserversOfNetworkChangeForTests(ConnectionType type); 315 static void NotifyObserversOfNetworkChangeForTests(ConnectionType type);
311 static void NotifyObserversOfInitialDNSConfigReadForTests(); 316 static void NotifyObserversOfInitialDNSConfigReadForTests();
317 static void NotifyObserversOfMaxBandwidthChangeForTests(
318 double max_bandwidth_mbps,
319 ConnectionType type);
312 320
313 // Enable or disable notifications from the host. After setting to true, be 321 // Enable or disable notifications from the host. After setting to true, be
314 // sure to pump the RunLoop until idle to finish any preexisting 322 // sure to pump the RunLoop until idle to finish any preexisting
315 // notifications. To use this, it must must be called before a 323 // notifications. To use this, it must must be called before a
316 // NetworkChangeNotifier is created. 324 // NetworkChangeNotifier is created.
317 static void SetTestNotificationsOnly(bool test_only); 325 static void SetTestNotificationsOnly(bool test_only);
318 326
319 // Return a string equivalent to |type|. 327 // Return a string equivalent to |type|.
320 static const char* ConnectionTypeToString(ConnectionType type); 328 static const char* ConnectionTypeToString(ConnectionType type);
321 329
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 #if defined(OS_LINUX) 393 #if defined(OS_LINUX)
386 // Returns the AddressTrackerLinux if present. 394 // Returns the AddressTrackerLinux if present.
387 // TODO(szym): Retrieve AddressMap from NetworkState. http://crbug.com/144212 395 // TODO(szym): Retrieve AddressMap from NetworkState. http://crbug.com/144212
388 virtual const internal::AddressTrackerLinux* 396 virtual const internal::AddressTrackerLinux*
389 GetAddressTrackerInternal() const; 397 GetAddressTrackerInternal() const;
390 #endif 398 #endif
391 399
392 // See the description of NetworkChangeNotifier::GetMaxBandwidth(). 400 // See the description of NetworkChangeNotifier::GetMaxBandwidth().
393 // Implementations must be thread-safe. Implementations must also be 401 // Implementations must be thread-safe. Implementations must also be
394 // cheap as it is called often. 402 // cheap as it is called often.
395 virtual double GetCurrentMaxBandwidth() const; 403 virtual void GetCurrentMaxBandwidthAndConnectionType(
404 double* max_bandwidth_mbps,
405 ConnectionType* connection_type) const;
396 406
397 // Returns a theoretical upper limit on download bandwidth given a connection 407 // Returns a theoretical upper limit on download bandwidth given a connection
398 // subtype. The mapping of connection type to maximum bandwidth is provided in 408 // subtype. The mapping of connection type to maximum bandwidth is provided in
399 // the NetInfo spec: http://w3c.github.io/netinfo/. 409 // the NetInfo spec: http://w3c.github.io/netinfo/.
400 static double GetMaxBandwidthForConnectionSubtype(ConnectionSubtype subtype); 410 static double GetMaxBandwidthForConnectionSubtype(ConnectionSubtype subtype);
401 411
402 // Broadcasts a notification to all registered observers. Note that this 412 // Broadcasts a notification to all registered observers. Note that this
403 // happens asynchronously, even for observers on the current thread, even in 413 // happens asynchronously, even for observers on the current thread, even in
404 // tests. 414 // tests.
405 static void NotifyObserversOfIPAddressChange(); 415 static void NotifyObserversOfIPAddressChange();
406 static void NotifyObserversOfConnectionTypeChange(); 416 static void NotifyObserversOfConnectionTypeChange();
407 static void NotifyObserversOfDNSChange(); 417 static void NotifyObserversOfDNSChange();
408 static void NotifyObserversOfInitialDNSConfigRead(); 418 static void NotifyObserversOfInitialDNSConfigRead();
409 static void NotifyObserversOfNetworkChange(ConnectionType type); 419 static void NotifyObserversOfNetworkChange(ConnectionType type);
410 static void NotifyObserversOfMaxBandwidthChange(double max_bandwidth_mbps); 420 static void NotifyObserversOfMaxBandwidthChange(double max_bandwidth_mbps,
421 ConnectionType type);
411 422
412 // Stores |config| in NetworkState and notifies OnDNSChanged observers. 423 // Stores |config| in NetworkState and notifies OnDNSChanged observers.
413 static void SetDnsConfig(const DnsConfig& config); 424 static void SetDnsConfig(const DnsConfig& config);
414 // Stores |config| in NetworkState and notifies OnInitialDNSConfigRead 425 // Stores |config| in NetworkState and notifies OnInitialDNSConfigRead
415 // observers. 426 // observers.
416 static void SetInitialDnsConfig(const DnsConfig& config); 427 static void SetInitialDnsConfig(const DnsConfig& config);
417 428
418 private: 429 private:
419 friend class HostResolverImplDnsTest; 430 friend class HostResolverImplDnsTest;
420 friend class NetworkChangeNotifierAndroidTest; 431 friend class NetworkChangeNotifierAndroidTest;
421 friend class NetworkChangeNotifierLinuxTest; 432 friend class NetworkChangeNotifierLinuxTest;
422 friend class NetworkChangeNotifierWinTest; 433 friend class NetworkChangeNotifierWinTest;
423 434
424 class NetworkState; 435 class NetworkState;
425 class NetworkChangeCalculator; 436 class NetworkChangeCalculator;
426 437
427 void NotifyObserversOfIPAddressChangeImpl(); 438 void NotifyObserversOfIPAddressChangeImpl();
428 void NotifyObserversOfConnectionTypeChangeImpl(ConnectionType type); 439 void NotifyObserversOfConnectionTypeChangeImpl(ConnectionType type);
429 void NotifyObserversOfDNSChangeImpl(); 440 void NotifyObserversOfDNSChangeImpl();
430 void NotifyObserversOfInitialDNSConfigReadImpl(); 441 void NotifyObserversOfInitialDNSConfigReadImpl();
431 void NotifyObserversOfNetworkChangeImpl(ConnectionType type); 442 void NotifyObserversOfNetworkChangeImpl(ConnectionType type);
432 void NotifyObserversOfMaxBandwidthChangeImpl(double max_bandwidth_mbps); 443 void NotifyObserversOfMaxBandwidthChangeImpl(double max_bandwidth_mbps,
444 ConnectionType type);
433 445
434 const scoped_refptr<base::ObserverListThreadSafe<IPAddressObserver>> 446 const scoped_refptr<base::ObserverListThreadSafe<IPAddressObserver>>
435 ip_address_observer_list_; 447 ip_address_observer_list_;
436 const scoped_refptr<base::ObserverListThreadSafe<ConnectionTypeObserver>> 448 const scoped_refptr<base::ObserverListThreadSafe<ConnectionTypeObserver>>
437 connection_type_observer_list_; 449 connection_type_observer_list_;
438 const scoped_refptr<base::ObserverListThreadSafe<DNSObserver>> 450 const scoped_refptr<base::ObserverListThreadSafe<DNSObserver>>
439 resolver_state_observer_list_; 451 resolver_state_observer_list_;
440 const scoped_refptr<base::ObserverListThreadSafe<NetworkChangeObserver>> 452 const scoped_refptr<base::ObserverListThreadSafe<NetworkChangeObserver>>
441 network_change_observer_list_; 453 network_change_observer_list_;
442 const scoped_refptr<base::ObserverListThreadSafe<MaxBandwidthObserver>> 454 const scoped_refptr<base::ObserverListThreadSafe<MaxBandwidthObserver>>
(...skipping 10 matching lines...) Expand all
453 465
454 // Set true to disable non-test notifications (to prevent flakes in tests). 466 // Set true to disable non-test notifications (to prevent flakes in tests).
455 static bool test_notifications_only_; 467 static bool test_notifications_only_;
456 468
457 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier); 469 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier);
458 }; 470 };
459 471
460 } // namespace net 472 } // namespace net
461 473
462 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ 474 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_H_
OLDNEW
« no previous file with comments | « net/android/network_change_notifier_delegate_android.cc ('k') | net/base/network_change_notifier.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698