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

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

Issue 667923003: Standardize usage of virtual/override/final in net/ (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 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
« no previous file with comments | « net/base/net_util_icu.cc ('k') | net/base/network_change_notifier_mac.h » ('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 #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
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 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 17 matching lines...) Expand all
76 // only called from the network thread. 76 // only called from the network thread.
77 void Init() { 77 void Init() {
78 DCHECK(thread_checker_.CalledOnValidThread()); 78 DCHECK(thread_checker_.CalledOnValidThread());
79 DCHECK(g_network_change_notifier); 79 DCHECK(g_network_change_notifier);
80 NetworkChangeNotifier::AddConnectionTypeObserver(this); 80 NetworkChangeNotifier::AddConnectionTypeObserver(this);
81 NetworkChangeNotifier::AddIPAddressObserver(this); 81 NetworkChangeNotifier::AddIPAddressObserver(this);
82 NetworkChangeNotifier::AddDNSObserver(this); 82 NetworkChangeNotifier::AddDNSObserver(this);
83 NetworkChangeNotifier::AddNetworkChangeObserver(this); 83 NetworkChangeNotifier::AddNetworkChangeObserver(this);
84 } 84 }
85 85
86 virtual ~HistogramWatcher() { 86 ~HistogramWatcher() override {
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 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 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_);
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 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 void OnNetworkChanged(NetworkChangeNotifier::ConnectionType type) override {
275 NetworkChangeNotifier::ConnectionType type) override {
276 DCHECK(thread_checker_.CalledOnValidThread()); 275 DCHECK(thread_checker_.CalledOnValidThread());
277 if (type != NetworkChangeNotifier::CONNECTION_NONE) { 276 if (type != NetworkChangeNotifier::CONNECTION_NONE) {
278 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.NetworkOnlineChange", 277 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.NetworkOnlineChange",
279 SinceLast(&last_network_change_)); 278 SinceLast(&last_network_change_));
280 } else { 279 } else {
281 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.NetworkOfflineChange", 280 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.NetworkOfflineChange",
282 SinceLast(&last_network_change_)); 281 SinceLast(&last_network_change_));
283 } 282 }
284 } 283 }
285 284
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
417 last_announced_connection_type_(CONNECTION_NONE), 416 last_announced_connection_type_(CONNECTION_NONE),
418 pending_connection_type_(CONNECTION_NONE) {} 417 pending_connection_type_(CONNECTION_NONE) {}
419 418
420 void Init() { 419 void Init() {
421 DCHECK(thread_checker_.CalledOnValidThread()); 420 DCHECK(thread_checker_.CalledOnValidThread());
422 DCHECK(g_network_change_notifier); 421 DCHECK(g_network_change_notifier);
423 AddConnectionTypeObserver(this); 422 AddConnectionTypeObserver(this);
424 AddIPAddressObserver(this); 423 AddIPAddressObserver(this);
425 } 424 }
426 425
427 virtual ~NetworkChangeCalculator() { 426 ~NetworkChangeCalculator() override {
428 DCHECK(thread_checker_.CalledOnValidThread()); 427 DCHECK(thread_checker_.CalledOnValidThread());
429 DCHECK(g_network_change_notifier); 428 DCHECK(g_network_change_notifier);
430 RemoveConnectionTypeObserver(this); 429 RemoveConnectionTypeObserver(this);
431 RemoveIPAddressObserver(this); 430 RemoveIPAddressObserver(this);
432 } 431 }
433 432
434 // NetworkChangeNotifier::IPAddressObserver implementation. 433 // NetworkChangeNotifier::IPAddressObserver implementation.
435 virtual void OnIPAddressChanged() override { 434 void OnIPAddressChanged() override {
436 DCHECK(thread_checker_.CalledOnValidThread()); 435 DCHECK(thread_checker_.CalledOnValidThread());
437 base::TimeDelta delay = last_announced_connection_type_ == CONNECTION_NONE 436 base::TimeDelta delay = last_announced_connection_type_ == CONNECTION_NONE
438 ? params_.ip_address_offline_delay_ : params_.ip_address_online_delay_; 437 ? params_.ip_address_offline_delay_ : params_.ip_address_online_delay_;
439 // Cancels any previous timer. 438 // Cancels any previous timer.
440 timer_.Start(FROM_HERE, delay, this, &NetworkChangeCalculator::Notify); 439 timer_.Start(FROM_HERE, delay, this, &NetworkChangeCalculator::Notify);
441 } 440 }
442 441
443 // NetworkChangeNotifier::ConnectionTypeObserver implementation. 442 // NetworkChangeNotifier::ConnectionTypeObserver implementation.
444 virtual void OnConnectionTypeChanged(ConnectionType type) override { 443 void OnConnectionTypeChanged(ConnectionType type) override {
445 DCHECK(thread_checker_.CalledOnValidThread()); 444 DCHECK(thread_checker_.CalledOnValidThread());
446 pending_connection_type_ = type; 445 pending_connection_type_ = type;
447 base::TimeDelta delay = last_announced_connection_type_ == CONNECTION_NONE 446 base::TimeDelta delay = last_announced_connection_type_ == CONNECTION_NONE
448 ? params_.connection_type_offline_delay_ 447 ? params_.connection_type_offline_delay_
449 : params_.connection_type_online_delay_; 448 : params_.connection_type_online_delay_;
450 // Cancels any previous timer. 449 // Cancels any previous timer.
451 timer_.Start(FROM_HERE, delay, this, &NetworkChangeCalculator::Notify); 450 timer_.Start(FROM_HERE, delay, this, &NetworkChangeCalculator::Notify);
452 } 451 }
453 452
454 private: 453 private:
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 DCHECK(g_network_change_notifier); 850 DCHECK(g_network_change_notifier);
852 g_network_change_notifier = NULL; 851 g_network_change_notifier = NULL;
853 } 852 }
854 853
855 NetworkChangeNotifier::DisableForTest::~DisableForTest() { 854 NetworkChangeNotifier::DisableForTest::~DisableForTest() {
856 DCHECK(!g_network_change_notifier); 855 DCHECK(!g_network_change_notifier);
857 g_network_change_notifier = network_change_notifier_; 856 g_network_change_notifier = network_change_notifier_;
858 } 857 }
859 858
860 } // namespace net 859 } // namespace net
OLDNEW
« no previous file with comments | « net/base/net_util_icu.cc ('k') | net/base/network_change_notifier_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698