| 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 #include "net/base/network_change_notifier.h" | 5 #include "net/base/network_change_notifier.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/synchronization/lock.h" | 10 #include "base/synchronization/lock.h" |
| (...skipping 27 matching lines...) Expand all Loading... |
| 38 // in ways that would require us to place locks around access to this object. | 38 // in ways that would require us to place locks around access to this object. |
| 39 // (The prohibition on global non-POD objects makes it tricky to do such a thing | 39 // (The prohibition on global non-POD objects makes it tricky to do such a thing |
| 40 // anyway.) | 40 // anyway.) |
| 41 NetworkChangeNotifier* g_network_change_notifier = NULL; | 41 NetworkChangeNotifier* g_network_change_notifier = NULL; |
| 42 | 42 |
| 43 // Class factory singleton. | 43 // Class factory singleton. |
| 44 NetworkChangeNotifierFactory* g_network_change_notifier_factory = NULL; | 44 NetworkChangeNotifierFactory* g_network_change_notifier_factory = NULL; |
| 45 | 45 |
| 46 class MockNetworkChangeNotifier : public NetworkChangeNotifier { | 46 class MockNetworkChangeNotifier : public NetworkChangeNotifier { |
| 47 public: | 47 public: |
| 48 virtual ConnectionType GetCurrentConnectionType() const OVERRIDE { | 48 virtual ConnectionType GetCurrentConnectionType() const override { |
| 49 return CONNECTION_UNKNOWN; | 49 return CONNECTION_UNKNOWN; |
| 50 } | 50 } |
| 51 }; | 51 }; |
| 52 | 52 |
| 53 } // namespace | 53 } // namespace |
| 54 | 54 |
| 55 // The main observer class that records UMAs for network events. | 55 // The main observer class that records UMAs for network events. |
| 56 class HistogramWatcher | 56 class HistogramWatcher |
| 57 : public NetworkChangeNotifier::ConnectionTypeObserver, | 57 : public NetworkChangeNotifier::ConnectionTypeObserver, |
| 58 public NetworkChangeNotifier::IPAddressObserver, | 58 public NetworkChangeNotifier::IPAddressObserver, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 86 virtual ~HistogramWatcher() { | 86 virtual ~HistogramWatcher() { |
| 87 DCHECK(thread_checker_.CalledOnValidThread()); | 87 DCHECK(thread_checker_.CalledOnValidThread()); |
| 88 DCHECK(g_network_change_notifier); | 88 DCHECK(g_network_change_notifier); |
| 89 NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | 89 NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
| 90 NetworkChangeNotifier::RemoveIPAddressObserver(this); | 90 NetworkChangeNotifier::RemoveIPAddressObserver(this); |
| 91 NetworkChangeNotifier::RemoveDNSObserver(this); | 91 NetworkChangeNotifier::RemoveDNSObserver(this); |
| 92 NetworkChangeNotifier::RemoveNetworkChangeObserver(this); | 92 NetworkChangeNotifier::RemoveNetworkChangeObserver(this); |
| 93 } | 93 } |
| 94 | 94 |
| 95 // NetworkChangeNotifier::IPAddressObserver implementation. | 95 // NetworkChangeNotifier::IPAddressObserver implementation. |
| 96 virtual void OnIPAddressChanged() OVERRIDE { | 96 virtual void OnIPAddressChanged() override { |
| 97 DCHECK(thread_checker_.CalledOnValidThread()); | 97 DCHECK(thread_checker_.CalledOnValidThread()); |
| 98 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.IPAddressChange", | 98 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.IPAddressChange", |
| 99 SinceLast(&last_ip_address_change_)); | 99 SinceLast(&last_ip_address_change_)); |
| 100 UMA_HISTOGRAM_MEDIUM_TIMES( | 100 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 101 "NCN.ConnectionTypeChangeToIPAddressChange", | 101 "NCN.ConnectionTypeChangeToIPAddressChange", |
| 102 last_ip_address_change_ - last_connection_change_); | 102 last_ip_address_change_ - last_connection_change_); |
| 103 } | 103 } |
| 104 | 104 |
| 105 // NetworkChangeNotifier::ConnectionTypeObserver implementation. | 105 // NetworkChangeNotifier::ConnectionTypeObserver implementation. |
| 106 virtual void OnConnectionTypeChanged( | 106 virtual void OnConnectionTypeChanged( |
| 107 NetworkChangeNotifier::ConnectionType type) OVERRIDE { | 107 NetworkChangeNotifier::ConnectionType type) override { |
| 108 DCHECK(thread_checker_.CalledOnValidThread()); | 108 DCHECK(thread_checker_.CalledOnValidThread()); |
| 109 base::TimeTicks now = base::TimeTicks::Now(); | 109 base::TimeTicks now = base::TimeTicks::Now(); |
| 110 int32 kilobytes_read = bytes_read_since_last_connection_change_ / 1000; | 110 int32 kilobytes_read = bytes_read_since_last_connection_change_ / 1000; |
| 111 base::TimeDelta state_duration = SinceLast(&last_connection_change_); | 111 base::TimeDelta state_duration = SinceLast(&last_connection_change_); |
| 112 if (bytes_read_since_last_connection_change_) { | 112 if (bytes_read_since_last_connection_change_) { |
| 113 switch (last_connection_type_) { | 113 switch (last_connection_type_) { |
| 114 case NetworkChangeNotifier::CONNECTION_UNKNOWN: | 114 case NetworkChangeNotifier::CONNECTION_UNKNOWN: |
| 115 UMA_HISTOGRAM_TIMES("NCN.CM.FirstReadOnUnknown", | 115 UMA_HISTOGRAM_TIMES("NCN.CM.FirstReadOnUnknown", |
| 116 first_byte_after_connection_change_); | 116 first_byte_after_connection_change_); |
| 117 UMA_HISTOGRAM_TIMES("NCN.CM.FastestRTTOnUnknown", | 117 UMA_HISTOGRAM_TIMES("NCN.CM.FastestRTTOnUnknown", |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 now - last_ip_address_change_); | 257 now - last_ip_address_change_); |
| 258 | 258 |
| 259 offline_packets_received_ = 0; | 259 offline_packets_received_ = 0; |
| 260 bytes_read_since_last_connection_change_ = 0; | 260 bytes_read_since_last_connection_change_ = 0; |
| 261 peak_kbps_since_last_connection_change_ = 0; | 261 peak_kbps_since_last_connection_change_ = 0; |
| 262 last_connection_type_ = type; | 262 last_connection_type_ = type; |
| 263 polling_interval_ = base::TimeDelta::FromSeconds(1); | 263 polling_interval_ = base::TimeDelta::FromSeconds(1); |
| 264 } | 264 } |
| 265 | 265 |
| 266 // NetworkChangeNotifier::DNSObserver implementation. | 266 // NetworkChangeNotifier::DNSObserver implementation. |
| 267 virtual void OnDNSChanged() OVERRIDE { | 267 virtual void OnDNSChanged() override { |
| 268 DCHECK(thread_checker_.CalledOnValidThread()); | 268 DCHECK(thread_checker_.CalledOnValidThread()); |
| 269 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.DNSConfigChange", | 269 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.DNSConfigChange", |
| 270 SinceLast(&last_dns_change_)); | 270 SinceLast(&last_dns_change_)); |
| 271 } | 271 } |
| 272 | 272 |
| 273 // NetworkChangeNotifier::NetworkChangeObserver implementation. | 273 // NetworkChangeNotifier::NetworkChangeObserver implementation. |
| 274 virtual void OnNetworkChanged( | 274 virtual void OnNetworkChanged( |
| 275 NetworkChangeNotifier::ConnectionType type) OVERRIDE { | 275 NetworkChangeNotifier::ConnectionType type) override { |
| 276 DCHECK(thread_checker_.CalledOnValidThread()); | 276 DCHECK(thread_checker_.CalledOnValidThread()); |
| 277 if (type != NetworkChangeNotifier::CONNECTION_NONE) { | 277 if (type != NetworkChangeNotifier::CONNECTION_NONE) { |
| 278 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.NetworkOnlineChange", | 278 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.NetworkOnlineChange", |
| 279 SinceLast(&last_network_change_)); | 279 SinceLast(&last_network_change_)); |
| 280 } else { | 280 } else { |
| 281 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.NetworkOfflineChange", | 281 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.NetworkOfflineChange", |
| 282 SinceLast(&last_network_change_)); | 282 SinceLast(&last_network_change_)); |
| 283 } | 283 } |
| 284 } | 284 } |
| 285 | 285 |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 } | 425 } |
| 426 | 426 |
| 427 virtual ~NetworkChangeCalculator() { | 427 virtual ~NetworkChangeCalculator() { |
| 428 DCHECK(thread_checker_.CalledOnValidThread()); | 428 DCHECK(thread_checker_.CalledOnValidThread()); |
| 429 DCHECK(g_network_change_notifier); | 429 DCHECK(g_network_change_notifier); |
| 430 RemoveConnectionTypeObserver(this); | 430 RemoveConnectionTypeObserver(this); |
| 431 RemoveIPAddressObserver(this); | 431 RemoveIPAddressObserver(this); |
| 432 } | 432 } |
| 433 | 433 |
| 434 // NetworkChangeNotifier::IPAddressObserver implementation. | 434 // NetworkChangeNotifier::IPAddressObserver implementation. |
| 435 virtual void OnIPAddressChanged() OVERRIDE { | 435 virtual void OnIPAddressChanged() override { |
| 436 DCHECK(thread_checker_.CalledOnValidThread()); | 436 DCHECK(thread_checker_.CalledOnValidThread()); |
| 437 base::TimeDelta delay = last_announced_connection_type_ == CONNECTION_NONE | 437 base::TimeDelta delay = last_announced_connection_type_ == CONNECTION_NONE |
| 438 ? params_.ip_address_offline_delay_ : params_.ip_address_online_delay_; | 438 ? params_.ip_address_offline_delay_ : params_.ip_address_online_delay_; |
| 439 // Cancels any previous timer. | 439 // Cancels any previous timer. |
| 440 timer_.Start(FROM_HERE, delay, this, &NetworkChangeCalculator::Notify); | 440 timer_.Start(FROM_HERE, delay, this, &NetworkChangeCalculator::Notify); |
| 441 } | 441 } |
| 442 | 442 |
| 443 // NetworkChangeNotifier::ConnectionTypeObserver implementation. | 443 // NetworkChangeNotifier::ConnectionTypeObserver implementation. |
| 444 virtual void OnConnectionTypeChanged(ConnectionType type) OVERRIDE { | 444 virtual void OnConnectionTypeChanged(ConnectionType type) override { |
| 445 DCHECK(thread_checker_.CalledOnValidThread()); | 445 DCHECK(thread_checker_.CalledOnValidThread()); |
| 446 pending_connection_type_ = type; | 446 pending_connection_type_ = type; |
| 447 base::TimeDelta delay = last_announced_connection_type_ == CONNECTION_NONE | 447 base::TimeDelta delay = last_announced_connection_type_ == CONNECTION_NONE |
| 448 ? params_.connection_type_offline_delay_ | 448 ? params_.connection_type_offline_delay_ |
| 449 : params_.connection_type_online_delay_; | 449 : params_.connection_type_online_delay_; |
| 450 // Cancels any previous timer. | 450 // Cancels any previous timer. |
| 451 timer_.Start(FROM_HERE, delay, this, &NetworkChangeCalculator::Notify); | 451 timer_.Start(FROM_HERE, delay, this, &NetworkChangeCalculator::Notify); |
| 452 } | 452 } |
| 453 | 453 |
| 454 private: | 454 private: |
| (...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 851 DCHECK(g_network_change_notifier); | 851 DCHECK(g_network_change_notifier); |
| 852 g_network_change_notifier = NULL; | 852 g_network_change_notifier = NULL; |
| 853 } | 853 } |
| 854 | 854 |
| 855 NetworkChangeNotifier::DisableForTest::~DisableForTest() { | 855 NetworkChangeNotifier::DisableForTest::~DisableForTest() { |
| 856 DCHECK(!g_network_change_notifier); | 856 DCHECK(!g_network_change_notifier); |
| 857 g_network_change_notifier = network_change_notifier_; | 857 g_network_change_notifier = network_change_notifier_; |
| 858 } | 858 } |
| 859 | 859 |
| 860 } // namespace net | 860 } // namespace net |
| OLD | NEW |