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

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

Issue 816543004: Update from https://crrev.com/308996 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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
« no previous file with comments | « net/base/net_log_event_type_list.h ('k') | net/base/network_change_notifier.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/observer_list_threadsafe.h" 9 #include "base/observer_list_threadsafe.h"
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 virtual void OnNetworkChanged(ConnectionType type) = 0; 167 virtual void OnNetworkChanged(ConnectionType type) = 0;
168 168
169 protected: 169 protected:
170 NetworkChangeObserver() {} 170 NetworkChangeObserver() {}
171 virtual ~NetworkChangeObserver() {} 171 virtual ~NetworkChangeObserver() {}
172 172
173 private: 173 private:
174 DISALLOW_COPY_AND_ASSIGN(NetworkChangeObserver); 174 DISALLOW_COPY_AND_ASSIGN(NetworkChangeObserver);
175 }; 175 };
176 176
177 class NET_EXPORT MaxBandwidthObserver {
178 public:
179 // Will be called when a change occurs to the network's maximum bandwidth as
180 // defined in http://w3c.github.io/netinfo/. Generally this will only be
181 // called on bandwidth changing network connection/disconnection events.
182 // Some platforms may call it more frequently, such as when WiFi signal
183 // strength changes.
184 // TODO(jkarlin): This is currently only implemented for Android. Implement
185 // on every platform.
186 virtual void OnMaxBandwidthChanged(double max_bandwidth_mbps) = 0;
187
188 protected:
189 MaxBandwidthObserver() {}
190 virtual ~MaxBandwidthObserver() {}
191
192 private:
193 DISALLOW_COPY_AND_ASSIGN(MaxBandwidthObserver);
194 };
195
177 virtual ~NetworkChangeNotifier(); 196 virtual ~NetworkChangeNotifier();
178 197
179 // See the description of NetworkChangeNotifier::GetConnectionType(). 198 // See the description of NetworkChangeNotifier::GetConnectionType().
180 // Implementations must be thread-safe. Implementations must also be 199 // Implementations must be thread-safe. Implementations must also be
181 // cheap as it is called often. 200 // cheap as it is called often.
182 virtual ConnectionType GetCurrentConnectionType() const = 0; 201 virtual ConnectionType GetCurrentConnectionType() const = 0;
183 202
184 // Replaces the default class factory instance of NetworkChangeNotifier class. 203 // Replaces the default class factory instance of NetworkChangeNotifier class.
185 // The method will take over the ownership of |factory| object. 204 // The method will take over the ownership of |factory| object.
186 static void SetFactory(NetworkChangeNotifierFactory* factory); 205 static void SetFactory(NetworkChangeNotifierFactory* factory);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 264
246 // Registers |observer| to receive notifications of network changes. The 265 // Registers |observer| to receive notifications of network changes. The
247 // thread on which this is called is the thread on which |observer| will be 266 // thread on which this is called is the thread on which |observer| will be
248 // called back with notifications. This is safe to call if Create() has not 267 // called back with notifications. This is safe to call if Create() has not
249 // been called (as long as it doesn't race the Create() call on another 268 // been called (as long as it doesn't race the Create() call on another
250 // thread), in which case it will simply do nothing. 269 // thread), in which case it will simply do nothing.
251 static void AddIPAddressObserver(IPAddressObserver* observer); 270 static void AddIPAddressObserver(IPAddressObserver* observer);
252 static void AddConnectionTypeObserver(ConnectionTypeObserver* observer); 271 static void AddConnectionTypeObserver(ConnectionTypeObserver* observer);
253 static void AddDNSObserver(DNSObserver* observer); 272 static void AddDNSObserver(DNSObserver* observer);
254 static void AddNetworkChangeObserver(NetworkChangeObserver* observer); 273 static void AddNetworkChangeObserver(NetworkChangeObserver* observer);
274 static void AddMaxBandwidthObserver(MaxBandwidthObserver* observer);
255 275
256 // Unregisters |observer| from receiving notifications. This must be called 276 // Unregisters |observer| from receiving notifications. This must be called
257 // on the same thread on which AddObserver() was called. Like AddObserver(), 277 // on the same thread on which AddObserver() was called. Like AddObserver(),
258 // this is safe to call if Create() has not been called (as long as it doesn't 278 // this is safe to call if Create() has not been called (as long as it doesn't
259 // race the Create() call on another thread), in which case it will simply do 279 // race the Create() call on another thread), in which case it will simply do
260 // nothing. Technically, it's also safe to call after the notifier object has 280 // nothing. Technically, it's also safe to call after the notifier object has
261 // been destroyed, if the call doesn't race the notifier's destruction, but 281 // been destroyed, if the call doesn't race the notifier's destruction, but
262 // there's no reason to use the API in this risky way, so don't do it. 282 // there's no reason to use the API in this risky way, so don't do it.
263 static void RemoveIPAddressObserver(IPAddressObserver* observer); 283 static void RemoveIPAddressObserver(IPAddressObserver* observer);
264 static void RemoveConnectionTypeObserver(ConnectionTypeObserver* observer); 284 static void RemoveConnectionTypeObserver(ConnectionTypeObserver* observer);
265 static void RemoveDNSObserver(DNSObserver* observer); 285 static void RemoveDNSObserver(DNSObserver* observer);
266 static void RemoveNetworkChangeObserver(NetworkChangeObserver* observer); 286 static void RemoveNetworkChangeObserver(NetworkChangeObserver* observer);
287 static void RemoveMaxBandwidthObserver(MaxBandwidthObserver* observer);
267 288
268 // Allow unit tests to trigger notifications. 289 // Allow unit tests to trigger notifications.
269 static void NotifyObserversOfIPAddressChangeForTests(); 290 static void NotifyObserversOfIPAddressChangeForTests();
270 static void NotifyObserversOfConnectionTypeChangeForTests( 291 static void NotifyObserversOfConnectionTypeChangeForTests(
271 ConnectionType type); 292 ConnectionType type);
272 static void NotifyObserversOfNetworkChangeForTests(ConnectionType type); 293 static void NotifyObserversOfNetworkChangeForTests(ConnectionType type);
273 294
274 // Enable or disable notifications from the host. After setting to true, be 295 // Enable or disable notifications from the host. After setting to true, be
275 // sure to pump the RunLoop until idle to finish any preexisting 296 // sure to pump the RunLoop until idle to finish any preexisting
276 // notifications. 297 // notifications.
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 // the NetInfo spec: http://w3c.github.io/netinfo/. 380 // the NetInfo spec: http://w3c.github.io/netinfo/.
360 static double GetMaxBandwidthForConnectionSubtype(ConnectionSubtype subtype); 381 static double GetMaxBandwidthForConnectionSubtype(ConnectionSubtype subtype);
361 382
362 // Broadcasts a notification to all registered observers. Note that this 383 // Broadcasts a notification to all registered observers. Note that this
363 // happens asynchronously, even for observers on the current thread, even in 384 // happens asynchronously, even for observers on the current thread, even in
364 // tests. 385 // tests.
365 static void NotifyObserversOfIPAddressChange(); 386 static void NotifyObserversOfIPAddressChange();
366 static void NotifyObserversOfConnectionTypeChange(); 387 static void NotifyObserversOfConnectionTypeChange();
367 static void NotifyObserversOfDNSChange(); 388 static void NotifyObserversOfDNSChange();
368 static void NotifyObserversOfNetworkChange(ConnectionType type); 389 static void NotifyObserversOfNetworkChange(ConnectionType type);
390 static void NotifyObserversOfMaxBandwidthChange(double max_bandwidth_mbps);
369 391
370 // Stores |config| in NetworkState and notifies observers. 392 // Stores |config| in NetworkState and notifies observers.
371 static void SetDnsConfig(const DnsConfig& config); 393 static void SetDnsConfig(const DnsConfig& config);
372 394
373 private: 395 private:
374 friend class HostResolverImplDnsTest; 396 friend class HostResolverImplDnsTest;
375 friend class NetworkChangeNotifierAndroidTest; 397 friend class NetworkChangeNotifierAndroidTest;
376 friend class NetworkChangeNotifierLinuxTest; 398 friend class NetworkChangeNotifierLinuxTest;
377 friend class NetworkChangeNotifierWinTest; 399 friend class NetworkChangeNotifierWinTest;
378 400
379 class NetworkState; 401 class NetworkState;
380 class NetworkChangeCalculator; 402 class NetworkChangeCalculator;
381 403
382 void NotifyObserversOfIPAddressChangeImpl(); 404 void NotifyObserversOfIPAddressChangeImpl();
383 void NotifyObserversOfConnectionTypeChangeImpl(ConnectionType type); 405 void NotifyObserversOfConnectionTypeChangeImpl(ConnectionType type);
384 void NotifyObserversOfDNSChangeImpl(); 406 void NotifyObserversOfDNSChangeImpl();
385 void NotifyObserversOfNetworkChangeImpl(ConnectionType type); 407 void NotifyObserversOfNetworkChangeImpl(ConnectionType type);
408 void NotifyObserversOfMaxBandwidthChangeImpl(double max_bandwidth_mbps);
386 409
387 const scoped_refptr<ObserverListThreadSafe<IPAddressObserver> > 410 const scoped_refptr<ObserverListThreadSafe<IPAddressObserver>>
388 ip_address_observer_list_; 411 ip_address_observer_list_;
389 const scoped_refptr<ObserverListThreadSafe<ConnectionTypeObserver> > 412 const scoped_refptr<ObserverListThreadSafe<ConnectionTypeObserver>>
390 connection_type_observer_list_; 413 connection_type_observer_list_;
391 const scoped_refptr<ObserverListThreadSafe<DNSObserver> > 414 const scoped_refptr<ObserverListThreadSafe<DNSObserver>>
392 resolver_state_observer_list_; 415 resolver_state_observer_list_;
393 const scoped_refptr<ObserverListThreadSafe<NetworkChangeObserver> > 416 const scoped_refptr<ObserverListThreadSafe<NetworkChangeObserver>>
394 network_change_observer_list_; 417 network_change_observer_list_;
418 const scoped_refptr<ObserverListThreadSafe<MaxBandwidthObserver>>
419 max_bandwidth_observer_list_;
395 420
396 // The current network state. Hosts DnsConfig, exposed via GetDnsConfig. 421 // The current network state. Hosts DnsConfig, exposed via GetDnsConfig.
397 scoped_ptr<NetworkState> network_state_; 422 scoped_ptr<NetworkState> network_state_;
398 423
399 // A little-piggy-back observer that simply logs UMA histogram data. 424 // A little-piggy-back observer that simply logs UMA histogram data.
400 scoped_ptr<HistogramWatcher> histogram_watcher_; 425 scoped_ptr<HistogramWatcher> histogram_watcher_;
401 426
402 // Computes NetworkChange signal from IPAddress and ConnectionType signals. 427 // Computes NetworkChange signal from IPAddress and ConnectionType signals.
403 scoped_ptr<NetworkChangeCalculator> network_change_calculator_; 428 scoped_ptr<NetworkChangeCalculator> network_change_calculator_;
404 429
405 // Set true to disable non-test notifications (to prevent flakes in tests). 430 // Set true to disable non-test notifications (to prevent flakes in tests).
406 bool test_notifications_only_; 431 bool test_notifications_only_;
407 432
408 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier); 433 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier);
409 }; 434 };
410 435
411 } // namespace net 436 } // namespace net
412 437
413 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ 438 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_H_
OLDNEW
« no previous file with comments | « net/base/net_log_event_type_list.h ('k') | net/base/network_change_notifier.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698