| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 virtual void OnNetworkMadeDefault(NetworkHandle network) = 0; | 240 virtual void OnNetworkMadeDefault(NetworkHandle network) = 0; |
| 241 | 241 |
| 242 protected: | 242 protected: |
| 243 NetworkObserver() {} | 243 NetworkObserver() {} |
| 244 virtual ~NetworkObserver() {} | 244 virtual ~NetworkObserver() {} |
| 245 | 245 |
| 246 private: | 246 private: |
| 247 DISALLOW_COPY_AND_ASSIGN(NetworkObserver); | 247 DISALLOW_COPY_AND_ASSIGN(NetworkObserver); |
| 248 }; | 248 }; |
| 249 | 249 |
| 250 // An interface that when implemented and added via AddMetricsObserver(), |
| 251 // provides notifications when metrics are cut. The callback is called |
| 252 // asynchronously on observer's thread. |
| 253 class NET_EXPORT MetricsObserver { |
| 254 public: |
| 255 virtual void OnMetricsFinalize() = 0; |
| 256 |
| 257 protected: |
| 258 MetricsObserver() {} |
| 259 virtual ~MetricsObserver() {} |
| 260 |
| 261 private: |
| 262 DISALLOW_COPY_AND_ASSIGN(MetricsObserver); |
| 263 }; |
| 264 |
| 250 // An invalid NetworkHandle. | 265 // An invalid NetworkHandle. |
| 251 static const NetworkHandle kInvalidNetworkHandle; | 266 static const NetworkHandle kInvalidNetworkHandle; |
| 252 | 267 |
| 253 virtual ~NetworkChangeNotifier(); | 268 virtual ~NetworkChangeNotifier(); |
| 254 | 269 |
| 255 // Replaces the default class factory instance of NetworkChangeNotifier class. | 270 // Replaces the default class factory instance of NetworkChangeNotifier class. |
| 256 // The method will take over the ownership of |factory| object. | 271 // The method will take over the ownership of |factory| object. |
| 257 static void SetFactory(NetworkChangeNotifierFactory* factory); | 272 static void SetFactory(NetworkChangeNotifierFactory* factory); |
| 258 | 273 |
| 259 // Creates the process-wide, platform-specific NetworkChangeNotifier. The | 274 // Creates the process-wide, platform-specific NetworkChangeNotifier. The |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 // Registers |observer| to receive notifications of network changes. The | 387 // Registers |observer| to receive notifications of network changes. The |
| 373 // thread on which this is called is the thread on which |observer| will be | 388 // thread on which this is called is the thread on which |observer| will be |
| 374 // called back with notifications. This is safe to call if Create() has not | 389 // called back with notifications. This is safe to call if Create() has not |
| 375 // been called (as long as it doesn't race the Create() call on another | 390 // been called (as long as it doesn't race the Create() call on another |
| 376 // thread), in which case it will simply do nothing. | 391 // thread), in which case it will simply do nothing. |
| 377 static void AddIPAddressObserver(IPAddressObserver* observer); | 392 static void AddIPAddressObserver(IPAddressObserver* observer); |
| 378 static void AddConnectionTypeObserver(ConnectionTypeObserver* observer); | 393 static void AddConnectionTypeObserver(ConnectionTypeObserver* observer); |
| 379 static void AddDNSObserver(DNSObserver* observer); | 394 static void AddDNSObserver(DNSObserver* observer); |
| 380 static void AddNetworkChangeObserver(NetworkChangeObserver* observer); | 395 static void AddNetworkChangeObserver(NetworkChangeObserver* observer); |
| 381 static void AddMaxBandwidthObserver(MaxBandwidthObserver* observer); | 396 static void AddMaxBandwidthObserver(MaxBandwidthObserver* observer); |
| 397 static void AddMetricsObserver(MetricsObserver* observer); |
| 382 static void AddNetworkObserver(NetworkObserver* observer); | 398 static void AddNetworkObserver(NetworkObserver* observer); |
| 383 | 399 |
| 384 // Unregisters |observer| from receiving notifications. This must be called | 400 // Unregisters |observer| from receiving notifications. This must be called |
| 385 // on the same thread on which AddObserver() was called. Like AddObserver(), | 401 // on the same thread on which AddObserver() was called. Like AddObserver(), |
| 386 // this is safe to call if Create() has not been called (as long as it doesn't | 402 // this is safe to call if Create() has not been called (as long as it doesn't |
| 387 // race the Create() call on another thread), in which case it will simply do | 403 // race the Create() call on another thread), in which case it will simply do |
| 388 // nothing. Technically, it's also safe to call after the notifier object has | 404 // nothing. Technically, it's also safe to call after the notifier object has |
| 389 // been destroyed, if the call doesn't race the notifier's destruction, but | 405 // been destroyed, if the call doesn't race the notifier's destruction, but |
| 390 // there's no reason to use the API in this risky way, so don't do it. | 406 // there's no reason to use the API in this risky way, so don't do it. |
| 391 static void RemoveIPAddressObserver(IPAddressObserver* observer); | 407 static void RemoveIPAddressObserver(IPAddressObserver* observer); |
| (...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 510 double* max_bandwidth_mbps, | 526 double* max_bandwidth_mbps, |
| 511 ConnectionType* connection_type) const; | 527 ConnectionType* connection_type) const; |
| 512 virtual bool AreNetworkHandlesCurrentlySupported() const; | 528 virtual bool AreNetworkHandlesCurrentlySupported() const; |
| 513 virtual void GetCurrentConnectedNetworks(NetworkList* network_list) const; | 529 virtual void GetCurrentConnectedNetworks(NetworkList* network_list) const; |
| 514 virtual ConnectionType GetCurrentNetworkConnectionType( | 530 virtual ConnectionType GetCurrentNetworkConnectionType( |
| 515 NetworkHandle network) const; | 531 NetworkHandle network) const; |
| 516 virtual NetworkHandle GetCurrentDefaultNetwork() const; | 532 virtual NetworkHandle GetCurrentDefaultNetwork() const; |
| 517 | 533 |
| 518 // Hook that allows derived implementations to log histograms at the time a | 534 // Hook that allows derived implementations to log histograms at the time a |
| 519 // new histogram record is being finalized. | 535 // new histogram record is being finalized. |
| 520 virtual void OnFinalizingMetricsLogRecord() {} | 536 virtual void OnFinalizingMetricsLogRecord(); |
| 521 | 537 |
| 522 // Broadcasts a notification to all registered observers. Note that this | 538 // Broadcasts a notification to all registered observers. Note that this |
| 523 // happens asynchronously, even for observers on the current thread, even in | 539 // happens asynchronously, even for observers on the current thread, even in |
| 524 // tests. | 540 // tests. |
| 525 static void NotifyObserversOfIPAddressChange(); | 541 static void NotifyObserversOfIPAddressChange(); |
| 526 static void NotifyObserversOfConnectionTypeChange(); | 542 static void NotifyObserversOfConnectionTypeChange(); |
| 527 static void NotifyObserversOfDNSChange(); | 543 static void NotifyObserversOfDNSChange(); |
| 528 static void NotifyObserversOfInitialDNSConfigRead(); | 544 static void NotifyObserversOfInitialDNSConfigRead(); |
| 529 static void NotifyObserversOfNetworkChange(ConnectionType type); | 545 static void NotifyObserversOfNetworkChange(ConnectionType type); |
| 530 static void NotifyObserversOfMaxBandwidthChange(double max_bandwidth_mbps, | 546 static void NotifyObserversOfMaxBandwidthChange(double max_bandwidth_mbps, |
| (...skipping 16 matching lines...) Expand all Loading... |
| 547 class NetworkState; | 563 class NetworkState; |
| 548 class NetworkChangeCalculator; | 564 class NetworkChangeCalculator; |
| 549 | 565 |
| 550 void NotifyObserversOfIPAddressChangeImpl(); | 566 void NotifyObserversOfIPAddressChangeImpl(); |
| 551 void NotifyObserversOfConnectionTypeChangeImpl(ConnectionType type); | 567 void NotifyObserversOfConnectionTypeChangeImpl(ConnectionType type); |
| 552 void NotifyObserversOfDNSChangeImpl(); | 568 void NotifyObserversOfDNSChangeImpl(); |
| 553 void NotifyObserversOfInitialDNSConfigReadImpl(); | 569 void NotifyObserversOfInitialDNSConfigReadImpl(); |
| 554 void NotifyObserversOfNetworkChangeImpl(ConnectionType type); | 570 void NotifyObserversOfNetworkChangeImpl(ConnectionType type); |
| 555 void NotifyObserversOfMaxBandwidthChangeImpl(double max_bandwidth_mbps, | 571 void NotifyObserversOfMaxBandwidthChangeImpl(double max_bandwidth_mbps, |
| 556 ConnectionType type); | 572 ConnectionType type); |
| 573 void NotifyObserversOfMetricsOnFinalize(); |
| 574 |
| 557 void NotifyObserversOfSpecificNetworkChangeImpl(NetworkChangeType type, | 575 void NotifyObserversOfSpecificNetworkChangeImpl(NetworkChangeType type, |
| 558 NetworkHandle network); | 576 NetworkHandle network); |
| 559 | 577 |
| 560 const scoped_refptr<base::ObserverListThreadSafe<IPAddressObserver>> | 578 const scoped_refptr<base::ObserverListThreadSafe<IPAddressObserver>> |
| 561 ip_address_observer_list_; | 579 ip_address_observer_list_; |
| 562 const scoped_refptr<base::ObserverListThreadSafe<ConnectionTypeObserver>> | 580 const scoped_refptr<base::ObserverListThreadSafe<ConnectionTypeObserver>> |
| 563 connection_type_observer_list_; | 581 connection_type_observer_list_; |
| 564 const scoped_refptr<base::ObserverListThreadSafe<DNSObserver>> | 582 const scoped_refptr<base::ObserverListThreadSafe<DNSObserver>> |
| 565 resolver_state_observer_list_; | 583 resolver_state_observer_list_; |
| 566 const scoped_refptr<base::ObserverListThreadSafe<NetworkChangeObserver>> | 584 const scoped_refptr<base::ObserverListThreadSafe<NetworkChangeObserver>> |
| 567 network_change_observer_list_; | 585 network_change_observer_list_; |
| 568 const scoped_refptr<base::ObserverListThreadSafe<MaxBandwidthObserver>> | 586 const scoped_refptr<base::ObserverListThreadSafe<MaxBandwidthObserver>> |
| 569 max_bandwidth_observer_list_; | 587 max_bandwidth_observer_list_; |
| 570 const scoped_refptr<base::ObserverListThreadSafe<NetworkObserver>> | 588 const scoped_refptr<base::ObserverListThreadSafe<NetworkObserver>> |
| 571 network_observer_list_; | 589 network_observer_list_; |
| 590 const scoped_refptr<base::ObserverListThreadSafe<MetricsObserver>> |
| 591 metrics_observer_list_; |
| 572 | 592 |
| 573 // The current network state. Hosts DnsConfig, exposed via GetDnsConfig. | 593 // The current network state. Hosts DnsConfig, exposed via GetDnsConfig. |
| 574 std::unique_ptr<NetworkState> network_state_; | 594 std::unique_ptr<NetworkState> network_state_; |
| 575 | 595 |
| 576 // A little-piggy-back observer that simply logs UMA histogram data. | 596 // A little-piggy-back observer that simply logs UMA histogram data. |
| 577 std::unique_ptr<HistogramWatcher> histogram_watcher_; | 597 std::unique_ptr<HistogramWatcher> histogram_watcher_; |
| 578 | 598 |
| 579 // Computes NetworkChange signal from IPAddress and ConnectionType signals. | 599 // Computes NetworkChange signal from IPAddress and ConnectionType signals. |
| 580 std::unique_ptr<NetworkChangeCalculator> network_change_calculator_; | 600 std::unique_ptr<NetworkChangeCalculator> network_change_calculator_; |
| 581 | 601 |
| 582 // Set true to disable non-test notifications (to prevent flakes in tests). | 602 // Set true to disable non-test notifications (to prevent flakes in tests). |
| 583 static bool test_notifications_only_; | 603 static bool test_notifications_only_; |
| 584 | 604 |
| 585 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier); | 605 DISALLOW_COPY_AND_ASSIGN(NetworkChangeNotifier); |
| 586 }; | 606 }; |
| 587 | 607 |
| 588 } // namespace net | 608 } // namespace net |
| 589 | 609 |
| 590 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ | 610 #endif // NET_BASE_NETWORK_CHANGE_NOTIFIER_H_ |
| OLD | NEW |