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

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: Comments 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 // 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
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
240 // NetInfo spec: http://w3c.github.io/netinfo/. Host-specific application 238 // 0.0 otherwise. The circumstances in which a more specific value is given
241 // permissions may be required, please see host-specific declaration for more 239 // are: Android cellular types, Android wifi types, and ChromeOS cellular
242 // information. 240 // types). See the NetInfo spec for the mapping of specific subtypes to
pneubeck (no reviews) 2015/09/11 07:48:20 s/)//
jkarlin 2015/09/11 18:56:11 Done.
241 // bandwidth values: http://w3c.github.io/netinfo/.
243 static double GetMaxBandwidth(); 242 static double GetMaxBandwidth();
244 243
245 // Retrieve the last read DnsConfig. This could be expensive if the system has 244 // Retrieve the last read DnsConfig. This could be expensive if the system has
246 // a large HOSTS file. 245 // a large HOSTS file.
247 static void GetDnsConfig(DnsConfig* config); 246 static void GetDnsConfig(DnsConfig* config);
248 247
249 #if defined(OS_LINUX) 248 #if defined(OS_LINUX)
250 // Returns the AddressTrackerLinux if present. 249 // Returns the AddressTrackerLinux if present.
251 static const internal::AddressTrackerLinux* GetAddressTracker(); 250 static const internal::AddressTrackerLinux* GetAddressTracker();
252 #endif 251 #endif
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 static void RemoveDNSObserver(DNSObserver* observer); 301 static void RemoveDNSObserver(DNSObserver* observer);
303 static void RemoveNetworkChangeObserver(NetworkChangeObserver* observer); 302 static void RemoveNetworkChangeObserver(NetworkChangeObserver* observer);
304 static void RemoveMaxBandwidthObserver(MaxBandwidthObserver* observer); 303 static void RemoveMaxBandwidthObserver(MaxBandwidthObserver* observer);
305 304
306 // Allow unit tests to trigger notifications. 305 // Allow unit tests to trigger notifications.
307 static void NotifyObserversOfIPAddressChangeForTests(); 306 static void NotifyObserversOfIPAddressChangeForTests();
308 static void NotifyObserversOfConnectionTypeChangeForTests( 307 static void NotifyObserversOfConnectionTypeChangeForTests(
309 ConnectionType type); 308 ConnectionType type);
310 static void NotifyObserversOfNetworkChangeForTests(ConnectionType type); 309 static void NotifyObserversOfNetworkChangeForTests(ConnectionType type);
311 static void NotifyObserversOfInitialDNSConfigReadForTests(); 310 static void NotifyObserversOfInitialDNSConfigReadForTests();
311 static void NotifyObserversOfMaxBandwidthChangeForTests(ConnectionType type,
312 double max_bandwidth);
312 313
313 // Enable or disable notifications from the host. After setting to true, be 314 // Enable or disable notifications from the host. After setting to true, be
314 // sure to pump the RunLoop until idle to finish any preexisting 315 // sure to pump the RunLoop until idle to finish any preexisting
315 // notifications. To use this, it must must be called before a 316 // notifications. To use this, it must must be called before a
316 // NetworkChangeNotifier is created. 317 // NetworkChangeNotifier is created.
317 static void SetTestNotificationsOnly(bool test_only); 318 static void SetTestNotificationsOnly(bool test_only);
318 319
319 // Return a string equivalent to |type|. 320 // Return a string equivalent to |type|.
320 static const char* ConnectionTypeToString(ConnectionType type); 321 static const char* ConnectionTypeToString(ConnectionType type);
321 322
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 static double GetMaxBandwidthForConnectionSubtype(ConnectionSubtype subtype); 401 static double GetMaxBandwidthForConnectionSubtype(ConnectionSubtype subtype);
401 402
402 // Broadcasts a notification to all registered observers. Note that this 403 // Broadcasts a notification to all registered observers. Note that this
403 // happens asynchronously, even for observers on the current thread, even in 404 // happens asynchronously, even for observers on the current thread, even in
404 // tests. 405 // tests.
405 static void NotifyObserversOfIPAddressChange(); 406 static void NotifyObserversOfIPAddressChange();
406 static void NotifyObserversOfConnectionTypeChange(); 407 static void NotifyObserversOfConnectionTypeChange();
407 static void NotifyObserversOfDNSChange(); 408 static void NotifyObserversOfDNSChange();
408 static void NotifyObserversOfInitialDNSConfigRead(); 409 static void NotifyObserversOfInitialDNSConfigRead();
409 static void NotifyObserversOfNetworkChange(ConnectionType type); 410 static void NotifyObserversOfNetworkChange(ConnectionType type);
410 static void NotifyObserversOfMaxBandwidthChange(double max_bandwidth_mbps); 411 static void NotifyObserversOfMaxBandwidthChange(ConnectionType type,
412 double max_bandwidth_mbps);
411 413
412 // Stores |config| in NetworkState and notifies OnDNSChanged observers. 414 // Stores |config| in NetworkState and notifies OnDNSChanged observers.
413 static void SetDnsConfig(const DnsConfig& config); 415 static void SetDnsConfig(const DnsConfig& config);
414 // Stores |config| in NetworkState and notifies OnInitialDNSConfigRead 416 // Stores |config| in NetworkState and notifies OnInitialDNSConfigRead
415 // observers. 417 // observers.
416 static void SetInitialDnsConfig(const DnsConfig& config); 418 static void SetInitialDnsConfig(const DnsConfig& config);
417 419
418 private: 420 private:
419 friend class HostResolverImplDnsTest; 421 friend class HostResolverImplDnsTest;
420 friend class NetworkChangeNotifierAndroidTest; 422 friend class NetworkChangeNotifierAndroidTest;
421 friend class NetworkChangeNotifierLinuxTest; 423 friend class NetworkChangeNotifierLinuxTest;
422 friend class NetworkChangeNotifierWinTest; 424 friend class NetworkChangeNotifierWinTest;
423 425
424 class NetworkState; 426 class NetworkState;
425 class NetworkChangeCalculator; 427 class NetworkChangeCalculator;
426 428
427 void NotifyObserversOfIPAddressChangeImpl(); 429 void NotifyObserversOfIPAddressChangeImpl();
428 void NotifyObserversOfConnectionTypeChangeImpl(ConnectionType type); 430 void NotifyObserversOfConnectionTypeChangeImpl(ConnectionType type);
429 void NotifyObserversOfDNSChangeImpl(); 431 void NotifyObserversOfDNSChangeImpl();
430 void NotifyObserversOfInitialDNSConfigReadImpl(); 432 void NotifyObserversOfInitialDNSConfigReadImpl();
431 void NotifyObserversOfNetworkChangeImpl(ConnectionType type); 433 void NotifyObserversOfNetworkChangeImpl(ConnectionType type);
432 void NotifyObserversOfMaxBandwidthChangeImpl(double max_bandwidth_mbps); 434 void NotifyObserversOfMaxBandwidthChangeImpl(ConnectionType type,
435 double max_bandwidth_mbps);
433 436
434 const scoped_refptr<base::ObserverListThreadSafe<IPAddressObserver>> 437 const scoped_refptr<base::ObserverListThreadSafe<IPAddressObserver>>
435 ip_address_observer_list_; 438 ip_address_observer_list_;
436 const scoped_refptr<base::ObserverListThreadSafe<ConnectionTypeObserver>> 439 const scoped_refptr<base::ObserverListThreadSafe<ConnectionTypeObserver>>
437 connection_type_observer_list_; 440 connection_type_observer_list_;
438 const scoped_refptr<base::ObserverListThreadSafe<DNSObserver>> 441 const scoped_refptr<base::ObserverListThreadSafe<DNSObserver>>
439 resolver_state_observer_list_; 442 resolver_state_observer_list_;
440 const scoped_refptr<base::ObserverListThreadSafe<NetworkChangeObserver>> 443 const scoped_refptr<base::ObserverListThreadSafe<NetworkChangeObserver>>
441 network_change_observer_list_; 444 network_change_observer_list_;
442 const scoped_refptr<base::ObserverListThreadSafe<MaxBandwidthObserver>> 445 const scoped_refptr<base::ObserverListThreadSafe<MaxBandwidthObserver>>
(...skipping 10 matching lines...) Expand all
453 456
454 // Set true to disable non-test notifications (to prevent flakes in tests). 457 // Set true to disable non-test notifications (to prevent flakes in tests).
455 static bool test_notifications_only_; 458 static bool test_notifications_only_;
456 459
457 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier); 460 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier);
458 }; 461 };
459 462
460 } // namespace net 463 } // namespace net
461 464
462 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ 465 #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