| 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/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 UMA_HISTOGRAM_MEDIUM_TIMES( | 101 UMA_HISTOGRAM_MEDIUM_TIMES( |
| 102 "NCN.ConnectionTypeChangeToIPAddressChange", | 102 "NCN.ConnectionTypeChangeToIPAddressChange", |
| 103 last_ip_address_change_ - last_connection_change_); | 103 last_ip_address_change_ - last_connection_change_); |
| 104 } | 104 } |
| 105 | 105 |
| 106 // NetworkChangeNotifier::ConnectionTypeObserver implementation. | 106 // NetworkChangeNotifier::ConnectionTypeObserver implementation. |
| 107 void OnConnectionTypeChanged( | 107 void OnConnectionTypeChanged( |
| 108 NetworkChangeNotifier::ConnectionType type) override { | 108 NetworkChangeNotifier::ConnectionType type) override { |
| 109 DCHECK(thread_checker_.CalledOnValidThread()); | 109 DCHECK(thread_checker_.CalledOnValidThread()); |
| 110 base::TimeTicks now = base::TimeTicks::Now(); | 110 base::TimeTicks now = base::TimeTicks::Now(); |
| 111 int32 kilobytes_read = bytes_read_since_last_connection_change_ / 1000; | 111 int32_t kilobytes_read = bytes_read_since_last_connection_change_ / 1000; |
| 112 base::TimeDelta state_duration = SinceLast(&last_connection_change_); | 112 base::TimeDelta state_duration = SinceLast(&last_connection_change_); |
| 113 if (bytes_read_since_last_connection_change_) { | 113 if (bytes_read_since_last_connection_change_) { |
| 114 switch (last_connection_type_) { | 114 switch (last_connection_type_) { |
| 115 case NetworkChangeNotifier::CONNECTION_UNKNOWN: | 115 case NetworkChangeNotifier::CONNECTION_UNKNOWN: |
| 116 UMA_HISTOGRAM_TIMES("NCN.CM.FirstReadOnUnknown", | 116 UMA_HISTOGRAM_TIMES("NCN.CM.FirstReadOnUnknown", |
| 117 first_byte_after_connection_change_); | 117 first_byte_after_connection_change_); |
| 118 UMA_HISTOGRAM_TIMES("NCN.CM.FastestRTTOnUnknown", | 118 UMA_HISTOGRAM_TIMES("NCN.CM.FastestRTTOnUnknown", |
| 119 fastest_RTT_since_last_connection_change_); | 119 fastest_RTT_since_last_connection_change_); |
| 120 break; | 120 break; |
| 121 case NetworkChangeNotifier::CONNECTION_ETHERNET: | 121 case NetworkChangeNotifier::CONNECTION_ETHERNET: |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 299 fastest_RTT_since_last_connection_change_ = request_duration; | 299 fastest_RTT_since_last_connection_change_ = request_duration; |
| 300 } | 300 } |
| 301 bytes_read_since_last_connection_change_ += bytes_read; | 301 bytes_read_since_last_connection_change_ += bytes_read; |
| 302 if (request_duration < fastest_RTT_since_last_connection_change_) | 302 if (request_duration < fastest_RTT_since_last_connection_change_) |
| 303 fastest_RTT_since_last_connection_change_ = request_duration; | 303 fastest_RTT_since_last_connection_change_ = request_duration; |
| 304 // Ignore tiny transfers which will not produce accurate rates. | 304 // Ignore tiny transfers which will not produce accurate rates. |
| 305 // Ignore zero duration transfers which might cause divide by zero. | 305 // Ignore zero duration transfers which might cause divide by zero. |
| 306 if (bytes_read > 10000 && | 306 if (bytes_read > 10000 && |
| 307 request_duration > base::TimeDelta::FromMilliseconds(1) && | 307 request_duration > base::TimeDelta::FromMilliseconds(1) && |
| 308 request.creation_time() > last_connection_change_) { | 308 request.creation_time() > last_connection_change_) { |
| 309 int32 kbps = static_cast<int32>( | 309 int32_t kbps = static_cast<int32_t>(bytes_read * 8 / |
| 310 bytes_read * 8 / request_duration.InMilliseconds()); | 310 request_duration.InMilliseconds()); |
| 311 if (kbps > peak_kbps_since_last_connection_change_) | 311 if (kbps > peak_kbps_since_last_connection_change_) |
| 312 peak_kbps_since_last_connection_change_ = kbps; | 312 peak_kbps_since_last_connection_change_ = kbps; |
| 313 } | 313 } |
| 314 | 314 |
| 315 if (last_connection_type_ != NetworkChangeNotifier::CONNECTION_NONE) | 315 if (last_connection_type_ != NetworkChangeNotifier::CONNECTION_NONE) |
| 316 return; | 316 return; |
| 317 | 317 |
| 318 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.OfflineDataRecv", | 318 UMA_HISTOGRAM_MEDIUM_TIMES("NCN.OfflineDataRecv", |
| 319 now - last_connection_change_); | 319 now - last_connection_change_); |
| 320 offline_packets_received_++; | 320 offline_packets_received_++; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 // state. | 354 // state. |
| 355 base::TimeDelta polling_interval_; | 355 base::TimeDelta polling_interval_; |
| 356 // |last_connection_type_| is the last value passed to | 356 // |last_connection_type_| is the last value passed to |
| 357 // |OnConnectionTypeChanged|. | 357 // |OnConnectionTypeChanged|. |
| 358 NetworkChangeNotifier::ConnectionType last_connection_type_; | 358 NetworkChangeNotifier::ConnectionType last_connection_type_; |
| 359 // |last_polled_connection_type_| is last result from calling | 359 // |last_polled_connection_type_| is last result from calling |
| 360 // |NetworkChangeNotifier::GetConnectionType| in |NotifyDataReceived|. | 360 // |NetworkChangeNotifier::GetConnectionType| in |NotifyDataReceived|. |
| 361 NetworkChangeNotifier::ConnectionType last_polled_connection_type_; | 361 NetworkChangeNotifier::ConnectionType last_polled_connection_type_; |
| 362 // Count of how many times NotifyDataReceived() has been called while the | 362 // Count of how many times NotifyDataReceived() has been called while the |
| 363 // NetworkChangeNotifier thought network connection was offline. | 363 // NetworkChangeNotifier thought network connection was offline. |
| 364 int32 offline_packets_received_; | 364 int32_t offline_packets_received_; |
| 365 // Number of bytes of network data received since last connectivity change. | 365 // Number of bytes of network data received since last connectivity change. |
| 366 int32 bytes_read_since_last_connection_change_; | 366 int32_t bytes_read_since_last_connection_change_; |
| 367 // Fastest round-trip-time (RTT) since last connectivity change. RTT measured | 367 // Fastest round-trip-time (RTT) since last connectivity change. RTT measured |
| 368 // from URLRequest creation until first byte received. | 368 // from URLRequest creation until first byte received. |
| 369 base::TimeDelta fastest_RTT_since_last_connection_change_; | 369 base::TimeDelta fastest_RTT_since_last_connection_change_; |
| 370 // Time between connectivity change and first network data byte received. | 370 // Time between connectivity change and first network data byte received. |
| 371 base::TimeDelta first_byte_after_connection_change_; | 371 base::TimeDelta first_byte_after_connection_change_; |
| 372 // Rough measurement of peak KB/s witnessed since last connectivity change. | 372 // Rough measurement of peak KB/s witnessed since last connectivity change. |
| 373 // The accuracy is decreased by ignoring these factors: | 373 // The accuracy is decreased by ignoring these factors: |
| 374 // 1) Multiple URLRequests can occur concurrently. | 374 // 1) Multiple URLRequests can occur concurrently. |
| 375 // 2) NotifyDataReceived() may be called repeatedly for one URLRequest. | 375 // 2) NotifyDataReceived() may be called repeatedly for one URLRequest. |
| 376 // 3) The transfer time includes at least one RTT while no bytes are read. | 376 // 3) The transfer time includes at least one RTT while no bytes are read. |
| 377 // Erring on the conservative side is hopefully offset by taking the maximum. | 377 // Erring on the conservative side is hopefully offset by taking the maximum. |
| 378 int32 peak_kbps_since_last_connection_change_; | 378 int32_t peak_kbps_since_last_connection_change_; |
| 379 | 379 |
| 380 base::ThreadChecker thread_checker_; | 380 base::ThreadChecker thread_checker_; |
| 381 | 381 |
| 382 DISALLOW_COPY_AND_ASSIGN(HistogramWatcher); | 382 DISALLOW_COPY_AND_ASSIGN(HistogramWatcher); |
| 383 }; | 383 }; |
| 384 | 384 |
| 385 // NetworkState is thread safe. | 385 // NetworkState is thread safe. |
| 386 class NetworkChangeNotifier::NetworkState { | 386 class NetworkChangeNotifier::NetworkState { |
| 387 public: | 387 public: |
| 388 NetworkState() {} | 388 NetworkState() {} |
| (...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1026 | 1026 |
| 1027 NetworkChangeNotifier::DisableForTest::~DisableForTest() { | 1027 NetworkChangeNotifier::DisableForTest::~DisableForTest() { |
| 1028 DCHECK(!g_network_change_notifier); | 1028 DCHECK(!g_network_change_notifier); |
| 1029 g_network_change_notifier = network_change_notifier_; | 1029 g_network_change_notifier = network_change_notifier_; |
| 1030 } | 1030 } |
| 1031 | 1031 |
| 1032 void NetworkChangeNotifier::DNSObserver::OnInitialDNSConfigRead() { | 1032 void NetworkChangeNotifier::DNSObserver::OnInitialDNSConfigRead() { |
| 1033 } | 1033 } |
| 1034 | 1034 |
| 1035 } // namespace net | 1035 } // namespace net |
| OLD | NEW |