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

Side by Side Diff: net/nqe/network_quality_estimator.cc

Issue 2763853002: Use Android callback API to obtain cellular signal strength (Closed)
Patch Set: pauljensen comments Created 3 years, 6 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/nqe/network_quality_estimator.h" 5 #include "net/nqe/network_quality_estimator.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <limits> 9 #include <limits>
10 #include <utility> 10 #include <utility>
(...skipping 23 matching lines...) Expand all
34 #include "net/http/http_response_headers.h" 34 #include "net/http/http_response_headers.h"
35 #include "net/http/http_response_info.h" 35 #include "net/http/http_response_info.h"
36 #include "net/http/http_status_code.h" 36 #include "net/http/http_status_code.h"
37 #include "net/nqe/socket_watcher_factory.h" 37 #include "net/nqe/socket_watcher_factory.h"
38 #include "net/nqe/throughput_analyzer.h" 38 #include "net/nqe/throughput_analyzer.h"
39 #include "net/url_request/url_request.h" 39 #include "net/url_request/url_request.h"
40 #include "net/url_request/url_request_status.h" 40 #include "net/url_request/url_request_status.h"
41 #include "url/gurl.h" 41 #include "url/gurl.h"
42 42
43 #if defined(OS_ANDROID) 43 #if defined(OS_ANDROID)
44 #include "net/android/cellular_signal_strength.h"
45 #include "net/android/network_library.h" 44 #include "net/android/network_library.h"
46 #endif // OS_ANDROID 45 #endif // OS_ANDROID
47 46
48 namespace net { 47 namespace net {
49 48
50 namespace { 49 namespace {
51 50
52 // Returns the histogram that should be used to record the given statistic. 51 // Returns the histogram that should be used to record the given statistic.
53 // |max_limit| is the maximum value that can be stored in the histogram. 52 // |max_limit| is the maximum value that can be stored in the histogram.
54 base::HistogramBase* GetHistogram(const std::string& statistic_name, 53 base::HistogramBase* GetHistogram(const std::string& statistic_name,
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 : algorithm_name_to_enum_ 260 : algorithm_name_to_enum_
262 .find(params_.GetEffectiveConnectionTypeAlgorithm()) 261 .find(params_.GetEffectiveConnectionTypeAlgorithm())
263 ->second), 262 ->second),
264 tick_clock_(new base::DefaultTickClock()), 263 tick_clock_(new base::DefaultTickClock()),
265 last_connection_change_(tick_clock_->NowTicks()), 264 last_connection_change_(tick_clock_->NowTicks()),
266 current_network_id_(nqe::internal::NetworkID( 265 current_network_id_(nqe::internal::NetworkID(
267 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN, 266 NetworkChangeNotifier::ConnectionType::CONNECTION_UNKNOWN,
268 std::string())), 267 std::string())),
269 downstream_throughput_kbps_observations_( 268 downstream_throughput_kbps_observations_(
270 params_.weight_multiplier_per_second(), 269 params_.weight_multiplier_per_second(),
271 params_.weight_multiplier_per_dbm()), 270 params_.weight_multiplier_per_signal_strength_level()),
272 rtt_observations_(params_.weight_multiplier_per_second(), 271 rtt_observations_(params_.weight_multiplier_per_second(),
273 params_.weight_multiplier_per_dbm()), 272 params_.weight_multiplier_per_signal_strength_level()),
274 effective_connection_type_at_last_main_frame_( 273 effective_connection_type_at_last_main_frame_(
275 EFFECTIVE_CONNECTION_TYPE_UNKNOWN), 274 EFFECTIVE_CONNECTION_TYPE_UNKNOWN),
276 external_estimate_provider_(std::move(external_estimates_provider)), 275 external_estimate_provider_(std::move(external_estimates_provider)),
277 effective_connection_type_recomputation_interval_( 276 effective_connection_type_recomputation_interval_(
278 base::TimeDelta::FromSeconds(10)), 277 base::TimeDelta::FromSeconds(10)),
279 rtt_observations_size_at_last_ect_computation_(0), 278 rtt_observations_size_at_last_ect_computation_(0),
280 throughput_observations_size_at_last_ect_computation_(0), 279 throughput_observations_size_at_last_ect_computation_(0),
281 effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN), 280 effective_connection_type_(EFFECTIVE_CONNECTION_TYPE_UNKNOWN),
282 signal_strength_dbm_(INT32_MIN),
283 min_signal_strength_since_connection_change_(INT32_MAX),
284 max_signal_strength_since_connection_change_(INT32_MIN),
285 event_creator_(net_log), 281 event_creator_(net_log),
286 disallowed_observation_sources_for_http_( 282 disallowed_observation_sources_for_http_(
287 {NETWORK_QUALITY_OBSERVATION_SOURCE_TCP, 283 {NETWORK_QUALITY_OBSERVATION_SOURCE_TCP,
288 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC, 284 NETWORK_QUALITY_OBSERVATION_SOURCE_QUIC,
289 NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT_CACHED_ESTIMATE, 285 NETWORK_QUALITY_OBSERVATION_SOURCE_TRANSPORT_CACHED_ESTIMATE,
290 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_TRANSPORT_FROM_PLATFORM}), 286 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_TRANSPORT_FROM_PLATFORM}),
291 disallowed_observation_sources_for_transport_( 287 disallowed_observation_sources_for_transport_(
292 {NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP, 288 {NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP,
293 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE, 289 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE,
294 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE, 290 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_CACHED_ESTIMATE,
295 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM}), 291 NETWORK_QUALITY_OBSERVATION_SOURCE_DEFAULT_HTTP_FROM_PLATFORM}),
296 weak_ptr_factory_(this) { 292 weak_ptr_factory_(this) {
297 // None of the algorithms can have an empty name. 293 // None of the algorithms can have an empty name.
298 DCHECK(algorithm_name_to_enum_.end() == 294 DCHECK(algorithm_name_to_enum_.end() ==
299 algorithm_name_to_enum_.find(std::string())); 295 algorithm_name_to_enum_.find(std::string()));
300 296
301 DCHECK_EQ(algorithm_name_to_enum_.size(), 297 DCHECK_EQ(algorithm_name_to_enum_.size(),
302 static_cast<size_t>(EffectiveConnectionTypeAlgorithm:: 298 static_cast<size_t>(EffectiveConnectionTypeAlgorithm::
303 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST)); 299 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST));
304 DCHECK_NE(EffectiveConnectionTypeAlgorithm:: 300 DCHECK_NE(EffectiveConnectionTypeAlgorithm::
305 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST, 301 EFFECTIVE_CONNECTION_TYPE_ALGORITHM_LAST,
306 effective_connection_type_algorithm_); 302 effective_connection_type_algorithm_);
307 303
308 network_quality_store_.reset(new nqe::internal::NetworkQualityStore()); 304 network_quality_store_.reset(new nqe::internal::NetworkQualityStore());
305
306 #if defined(OS_ANDROID)
307 if (params_.weight_multiplier_per_signal_strength_level() < 1.0)
308 cellular_signal_strength_.reset(new android::CellularSignalStrength());
309 #endif // OS_ANDROID
310
309 NetworkChangeNotifier::AddConnectionTypeObserver(this); 311 NetworkChangeNotifier::AddConnectionTypeObserver(this);
310 if (external_estimate_provider_) { 312 if (external_estimate_provider_) {
311 RecordExternalEstimateProviderMetrics( 313 RecordExternalEstimateProviderMetrics(
312 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE); 314 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE);
313 external_estimate_provider_->SetUpdatedEstimateDelegate(this); 315 external_estimate_provider_->SetUpdatedEstimateDelegate(this);
314 } else { 316 } else {
315 RecordExternalEstimateProviderMetrics( 317 RecordExternalEstimateProviderMetrics(
316 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE); 318 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE);
317 } 319 }
318 current_network_id_ = GetCurrentNetworkID(); 320 current_network_id_ = GetCurrentNetworkID();
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 base::TimeDelta observed_http_rtt = 466 base::TimeDelta observed_http_rtt =
465 load_timing_info.receive_headers_end - load_timing_info.send_start; 467 load_timing_info.receive_headers_end - load_timing_info.send_start;
466 DCHECK_GE(observed_http_rtt, base::TimeDelta()); 468 DCHECK_GE(observed_http_rtt, base::TimeDelta());
467 if (observed_http_rtt < peak_network_quality_.http_rtt() || 469 if (observed_http_rtt < peak_network_quality_.http_rtt() ||
468 peak_network_quality_.http_rtt() == nqe::internal::InvalidRTT()) { 470 peak_network_quality_.http_rtt() == nqe::internal::InvalidRTT()) {
469 peak_network_quality_ = nqe::internal::NetworkQuality( 471 peak_network_quality_ = nqe::internal::NetworkQuality(
470 observed_http_rtt, peak_network_quality_.transport_rtt(), 472 observed_http_rtt, peak_network_quality_.transport_rtt(),
471 peak_network_quality_.downstream_throughput_kbps()); 473 peak_network_quality_.downstream_throughput_kbps());
472 } 474 }
473 475
474 RttObservation http_rtt_observation( 476 RttObservation http_rtt_observation(observed_http_rtt,
475 observed_http_rtt, tick_clock_->NowTicks(), signal_strength_dbm_, 477 tick_clock_->NowTicks(), signal_strength_,
476 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP); 478 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP);
477 rtt_observations_.AddObservation(http_rtt_observation); 479 rtt_observations_.AddObservation(http_rtt_observation);
478 NotifyObserversOfRTT(http_rtt_observation); 480 NotifyObserversOfRTT(http_rtt_observation);
479 } 481 }
480 482
481 void NetworkQualityEstimator::RecordAccuracyAfterMainFrame( 483 void NetworkQualityEstimator::RecordAccuracyAfterMainFrame(
482 base::TimeDelta measuring_duration) const { 484 base::TimeDelta measuring_duration) const {
483 DCHECK(thread_checker_.CalledOnValidThread()); 485 DCHECK(thread_checker_.CalledOnValidThread());
484 DCHECK_EQ(0, measuring_duration.InMilliseconds() % 1000); 486 DCHECK_EQ(0, measuring_duration.InMilliseconds() % 1000);
485 DCHECK(ContainsValue(GetAccuracyRecordingIntervals(), measuring_duration)); 487 DCHECK(ContainsValue(GetAccuracyRecordingIntervals(), measuring_duration));
486 488
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
826 last_effective_connection_type_computation_, 828 last_effective_connection_type_computation_,
827 network_quality_, effective_connection_type_)); 829 network_quality_, effective_connection_type_));
828 830
829 // Clear the local state. 831 // Clear the local state.
830 last_connection_change_ = tick_clock_->NowTicks(); 832 last_connection_change_ = tick_clock_->NowTicks();
831 peak_network_quality_ = nqe::internal::NetworkQuality(); 833 peak_network_quality_ = nqe::internal::NetworkQuality();
832 downstream_throughput_kbps_observations_.Clear(); 834 downstream_throughput_kbps_observations_.Clear();
833 rtt_observations_.Clear(); 835 rtt_observations_.Clear();
834 836
835 #if defined(OS_ANDROID) 837 #if defined(OS_ANDROID)
836 if (params_.weight_multiplier_per_dbm() < 1.0 && 838 if (cellular_signal_strength_ &&
837 NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type)) { 839 NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type)) {
838 UMA_HISTOGRAM_BOOLEAN( 840 bool signal_strength_available =
839 "NQE.CellularSignalStrengthAvailable", 841 min_signal_strength_since_connection_change_ &&
840 min_signal_strength_since_connection_change_ != INT32_MAX && 842 max_signal_strength_since_connection_change_;
841 max_signal_strength_since_connection_change_ != INT32_MIN); 843 UMA_HISTOGRAM_BOOLEAN("NQE.CellularSignalStrength.LevelAvailable",
844 signal_strength_available);
842 845
843 if (min_signal_strength_since_connection_change_ != INT32_MAX && 846 if (signal_strength_available) {
844 max_signal_strength_since_connection_change_ != INT32_MIN) {
845 UMA_HISTOGRAM_COUNTS_100( 847 UMA_HISTOGRAM_COUNTS_100(
846 "NQE.CellularSignalStrengthDifference", 848 "NQE.CellularSignalStrength.LevelDifference",
847 max_signal_strength_since_connection_change_ - 849 max_signal_strength_since_connection_change_.value() -
848 min_signal_strength_since_connection_change_); 850 min_signal_strength_since_connection_change_.value());
849 } 851 }
850 } 852 }
851 #endif // OS_ANDROID 853 #endif // OS_ANDROID
852 signal_strength_dbm_ = INT32_MIN; 854 signal_strength_.reset();
853 min_signal_strength_since_connection_change_ = INT32_MAX; 855 min_signal_strength_since_connection_change_.reset();
854 max_signal_strength_since_connection_change_ = INT32_MIN; 856 max_signal_strength_since_connection_change_.reset();
855 network_quality_ = nqe::internal::NetworkQuality(); 857 network_quality_ = nqe::internal::NetworkQuality();
856 effective_connection_type_ = EFFECTIVE_CONNECTION_TYPE_UNKNOWN; 858 effective_connection_type_ = EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
857 effective_connection_type_at_last_main_frame_ = 859 effective_connection_type_at_last_main_frame_ =
858 EFFECTIVE_CONNECTION_TYPE_UNKNOWN; 860 EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
859 rtt_observations_size_at_last_ect_computation_ = 0; 861 rtt_observations_size_at_last_ect_computation_ = 0;
860 throughput_observations_size_at_last_ect_computation_ = 0; 862 throughput_observations_size_at_last_ect_computation_ = 0;
861 863
862 // Update the local state as part of preparation for the new connection. 864 // Update the local state as part of preparation for the new connection.
863 current_network_id_ = GetCurrentNetworkID(); 865 current_network_id_ = GetCurrentNetworkID();
864 RecordNetworkIDAvailability(); 866 RecordNetworkIDAvailability();
(...skipping 22 matching lines...) Expand all
887 current_network_id_.type != NetworkChangeNotifier::CONNECTION_UNKNOWN && 889 current_network_id_.type != NetworkChangeNotifier::CONNECTION_UNKNOWN &&
888 current_network_id_.type != NetworkChangeNotifier::CONNECTION_ETHERNET && 890 current_network_id_.type != NetworkChangeNotifier::CONNECTION_ETHERNET &&
889 current_network_id_.type != NetworkChangeNotifier::CONNECTION_BLUETOOTH) { 891 current_network_id_.type != NetworkChangeNotifier::CONNECTION_BLUETOOTH) {
890 RecordExternalEstimateProviderMetrics( 892 RecordExternalEstimateProviderMetrics(
891 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED); 893 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED);
892 external_estimate_provider_->Update(); 894 external_estimate_provider_->Update();
893 } 895 }
894 } 896 }
895 897
896 void NetworkQualityEstimator::UpdateSignalStrength() { 898 void NetworkQualityEstimator::UpdateSignalStrength() {
899 DCHECK(thread_checker_.CalledOnValidThread());
900
901 signal_strength_.reset();
897 #if defined(OS_ANDROID) 902 #if defined(OS_ANDROID)
898 if (params_.weight_multiplier_per_dbm() >= 1.0 || 903 if (!cellular_signal_strength_)
899 !NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type) || 904 return;
900 !android::cellular_signal_strength::GetSignalStrengthDbm( 905 if (!NetworkChangeNotifier::IsConnectionCellular(current_network_id_.type))
901 &signal_strength_dbm_)) { 906 return;
902 signal_strength_dbm_ = INT32_MIN; 907
903 } 908 signal_strength_ = cellular_signal_strength_->GetSignalStrengthLevel();
904 min_signal_strength_since_connection_change_ = std::min( 909
905 min_signal_strength_since_connection_change_, signal_strength_dbm_); 910 if (!signal_strength_)
906 max_signal_strength_since_connection_change_ = std::max( 911 return;
907 max_signal_strength_since_connection_change_, signal_strength_dbm_); 912
913 min_signal_strength_since_connection_change_ =
914 std::min(min_signal_strength_since_connection_change_.value_or(INT32_MAX),
915 signal_strength_.value());
916 max_signal_strength_since_connection_change_ =
917 std::max(max_signal_strength_since_connection_change_.value_or(INT32_MIN),
918 signal_strength_.value());
908 #endif // OS_ANDROID 919 #endif // OS_ANDROID
909 } 920 }
910 921
911 void NetworkQualityEstimator::RecordMetricsOnConnectionTypeChanged() const { 922 void NetworkQualityEstimator::RecordMetricsOnConnectionTypeChanged() const {
912 DCHECK(thread_checker_.CalledOnValidThread()); 923 DCHECK(thread_checker_.CalledOnValidThread());
913 if (peak_network_quality_.http_rtt() != nqe::internal::InvalidRTT()) { 924 if (peak_network_quality_.http_rtt() != nqe::internal::InvalidRTT()) {
914 base::HistogramBase* rtt_histogram = 925 base::HistogramBase* rtt_histogram =
915 GetHistogram("FastestRTT.", current_network_id_.type, 10 * 1000); 926 GetHistogram("FastestRTT.", current_network_id_.type, 10 * 1000);
916 rtt_histogram->Add(peak_network_quality_.http_rtt().InMilliseconds()); 927 rtt_histogram->Add(peak_network_quality_.http_rtt().InMilliseconds());
917 } 928 }
(...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 const base::Optional<Statistic>& statistic, 1377 const base::Optional<Statistic>& statistic,
1367 int percentile) const { 1378 int percentile) const {
1368 DCHECK(thread_checker_.CalledOnValidThread()); 1379 DCHECK(thread_checker_.CalledOnValidThread());
1369 1380
1370 // RTT observations are sorted by duration from shortest to longest, thus 1381 // RTT observations are sorted by duration from shortest to longest, thus
1371 // a higher percentile RTT will have a longer RTT than a lower percentile. 1382 // a higher percentile RTT will have a longer RTT than a lower percentile.
1372 base::TimeDelta rtt = nqe::internal::InvalidRTT(); 1383 base::TimeDelta rtt = nqe::internal::InvalidRTT();
1373 1384
1374 if (!statistic) { 1385 if (!statistic) {
1375 // Use default statistic algorithm. 1386 // Use default statistic algorithm.
1376 if (!rtt_observations_.GetPercentile(start_time, signal_strength_dbm_, &rtt, 1387 if (!rtt_observations_.GetPercentile(start_time, signal_strength_, &rtt,
1377 percentile, 1388 percentile,
1378 disallowed_observation_sources)) { 1389 disallowed_observation_sources)) {
1379 return nqe::internal::InvalidRTT(); 1390 return nqe::internal::InvalidRTT();
1380 } 1391 }
1381 return rtt; 1392 return rtt;
1382 } 1393 }
1383 1394
1384 switch (statistic.value()) { 1395 switch (statistic.value()) {
1385 case STATISTIC_LAST: 1396 case STATISTIC_LAST:
1386 NOTREACHED(); 1397 NOTREACHED();
1387 return nqe::internal::InvalidRTT(); 1398 return nqe::internal::InvalidRTT();
1388 case STATISTIC_WEIGHTED_AVERAGE: 1399 case STATISTIC_WEIGHTED_AVERAGE:
1389 if (!rtt_observations_.GetWeightedAverage( 1400 if (!rtt_observations_.GetWeightedAverage(start_time, signal_strength_,
1390 start_time, signal_strength_dbm_, disallowed_observation_sources, 1401 disallowed_observation_sources,
1391 &rtt)) { 1402 &rtt)) {
1392 return nqe::internal::InvalidRTT(); 1403 return nqe::internal::InvalidRTT();
1393 } 1404 }
1394 return rtt; 1405 return rtt;
1395 case STATISTIC_UNWEIGHTED_AVERAGE: 1406 case STATISTIC_UNWEIGHTED_AVERAGE:
1396 if (!rtt_observations_.GetUnweightedAverage( 1407 if (!rtt_observations_.GetUnweightedAverage(
1397 start_time, signal_strength_dbm_, disallowed_observation_sources, 1408 start_time, signal_strength_, disallowed_observation_sources,
1398 &rtt)) { 1409 &rtt)) {
1399 return nqe::internal::InvalidRTT(); 1410 return nqe::internal::InvalidRTT();
1400 } 1411 }
1401 return rtt; 1412 return rtt;
1402 } 1413 }
1403 NOTREACHED(); 1414 NOTREACHED();
1404 return nqe::internal::InvalidRTT(); 1415 return nqe::internal::InvalidRTT();
1405 } 1416 }
1406 1417
1407 int32_t NetworkQualityEstimator::GetDownlinkThroughputKbpsEstimateInternal( 1418 int32_t NetworkQualityEstimator::GetDownlinkThroughputKbpsEstimateInternal(
1408 const base::TimeTicks& start_time, 1419 const base::TimeTicks& start_time,
1409 int percentile) const { 1420 int percentile) const {
1410 DCHECK(thread_checker_.CalledOnValidThread()); 1421 DCHECK(thread_checker_.CalledOnValidThread());
1411 1422
1412 // Throughput observations are sorted by kbps from slowest to fastest, 1423 // Throughput observations are sorted by kbps from slowest to fastest,
1413 // thus a higher percentile throughput will be faster than a lower one. 1424 // thus a higher percentile throughput will be faster than a lower one.
1414 int32_t kbps = nqe::internal::kInvalidThroughput; 1425 int32_t kbps = nqe::internal::kInvalidThroughput;
1415 if (!downstream_throughput_kbps_observations_.GetPercentile( 1426 if (!downstream_throughput_kbps_observations_.GetPercentile(
1416 start_time, signal_strength_dbm_, &kbps, 100 - percentile, 1427 start_time, signal_strength_, &kbps, 100 - percentile,
1417 std::vector<NetworkQualityObservationSource>())) { 1428 std::vector<NetworkQualityObservationSource>())) {
1418 return nqe::internal::kInvalidThroughput; 1429 return nqe::internal::kInvalidThroughput;
1419 } 1430 }
1420 return kbps; 1431 return kbps;
1421 } 1432 }
1422 1433
1423 nqe::internal::NetworkID NetworkQualityEstimator::GetCurrentNetworkID() const { 1434 nqe::internal::NetworkID NetworkQualityEstimator::GetCurrentNetworkID() const {
1424 DCHECK(thread_checker_.CalledOnValidThread()); 1435 DCHECK(thread_checker_.CalledOnValidThread());
1425 1436
1426 // TODO(tbansal): crbug.com/498068 Add NetworkQualityEstimatorAndroid class 1437 // TODO(tbansal): crbug.com/498068 Add NetworkQualityEstimatorAndroid class
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
1529 RecordExternalEstimateProviderMetrics( 1540 RecordExternalEstimateProviderMetrics(
1530 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK); 1541 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK);
1531 1542
1532 external_estimate_provider_quality_ = nqe::internal::NetworkQuality(); 1543 external_estimate_provider_quality_ = nqe::internal::NetworkQuality();
1533 1544
1534 if (rtt > base::TimeDelta()) { 1545 if (rtt > base::TimeDelta()) {
1535 RecordExternalEstimateProviderMetrics( 1546 RecordExternalEstimateProviderMetrics(
1536 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE); 1547 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE);
1537 UMA_HISTOGRAM_TIMES("NQE.ExternalEstimateProvider.RTT", rtt); 1548 UMA_HISTOGRAM_TIMES("NQE.ExternalEstimateProvider.RTT", rtt);
1538 RttObservation rtt_observation( 1549 RttObservation rtt_observation(
1539 rtt, tick_clock_->NowTicks(), signal_strength_dbm_, 1550 rtt, tick_clock_->NowTicks(), signal_strength_,
1540 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE); 1551 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE);
1541 rtt_observations_.AddObservation(rtt_observation); 1552 rtt_observations_.AddObservation(rtt_observation);
1542 external_estimate_provider_quality_.set_http_rtt(rtt); 1553 external_estimate_provider_quality_.set_http_rtt(rtt);
1543 NotifyObserversOfRTT(rtt_observation); 1554 NotifyObserversOfRTT(rtt_observation);
1544 } 1555 }
1545 1556
1546 if (downstream_throughput_kbps > 0) { 1557 if (downstream_throughput_kbps > 0) {
1547 RecordExternalEstimateProviderMetrics( 1558 RecordExternalEstimateProviderMetrics(
1548 EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE); 1559 EXTERNAL_ESTIMATE_PROVIDER_STATUS_DOWNLINK_BANDWIDTH_AVAILABLE);
1549 UMA_HISTOGRAM_COUNTS("NQE.ExternalEstimateProvider.DownlinkBandwidth", 1560 UMA_HISTOGRAM_COUNTS("NQE.ExternalEstimateProvider.DownlinkBandwidth",
1550 downstream_throughput_kbps); 1561 downstream_throughput_kbps);
1551 ThroughputObservation throughput_observation( 1562 ThroughputObservation throughput_observation(
1552 downstream_throughput_kbps, tick_clock_->NowTicks(), 1563 downstream_throughput_kbps, tick_clock_->NowTicks(), signal_strength_,
1553 signal_strength_dbm_,
1554 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE); 1564 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP_EXTERNAL_ESTIMATE);
1555 downstream_throughput_kbps_observations_.AddObservation( 1565 downstream_throughput_kbps_observations_.AddObservation(
1556 throughput_observation); 1566 throughput_observation);
1557 external_estimate_provider_quality_.set_downstream_throughput_kbps( 1567 external_estimate_provider_quality_.set_downstream_throughput_kbps(
1558 downstream_throughput_kbps); 1568 downstream_throughput_kbps);
1559 NotifyObserversOfThroughput(throughput_observation); 1569 NotifyObserversOfThroughput(throughput_observation);
1560 } 1570 }
1561 } 1571 }
1562 1572
1563 void NetworkQualityEstimator::SetTickClockForTesting( 1573 void NetworkQualityEstimator::SetTickClockForTesting(
1564 std::unique_ptr<base::TickClock> tick_clock) { 1574 std::unique_ptr<base::TickClock> tick_clock) {
1565 DCHECK(thread_checker_.CalledOnValidThread()); 1575 DCHECK(thread_checker_.CalledOnValidThread());
1566 tick_clock_ = std::move(tick_clock); 1576 tick_clock_ = std::move(tick_clock);
1567 } 1577 }
1568 1578
1569 double NetworkQualityEstimator::RandDouble() const { 1579 double NetworkQualityEstimator::RandDouble() const {
1570 return base::RandDouble(); 1580 return base::RandDouble();
1571 } 1581 }
1572 1582
1573 void NetworkQualityEstimator::OnUpdatedRTTAvailable( 1583 void NetworkQualityEstimator::OnUpdatedRTTAvailable(
1574 SocketPerformanceWatcherFactory::Protocol protocol, 1584 SocketPerformanceWatcherFactory::Protocol protocol,
1575 const base::TimeDelta& rtt) { 1585 const base::TimeDelta& rtt) {
1576 DCHECK(thread_checker_.CalledOnValidThread()); 1586 DCHECK(thread_checker_.CalledOnValidThread());
1577 DCHECK_NE(nqe::internal::InvalidRTT(), rtt); 1587 DCHECK_NE(nqe::internal::InvalidRTT(), rtt);
1578 1588
1579 RttObservation observation(rtt, tick_clock_->NowTicks(), signal_strength_dbm_, 1589 RttObservation observation(rtt, tick_clock_->NowTicks(), signal_strength_,
1580 ProtocolSourceToObservationSource(protocol)); 1590 ProtocolSourceToObservationSource(protocol));
1581 NotifyObserversOfRTT(observation); 1591 NotifyObserversOfRTT(observation);
1582 rtt_observations_.AddObservation(observation); 1592 rtt_observations_.AddObservation(observation);
1583 } 1593 }
1584 1594
1585 void NetworkQualityEstimator::NotifyObserversOfRTT( 1595 void NetworkQualityEstimator::NotifyObserversOfRTT(
1586 const RttObservation& observation) { 1596 const RttObservation& observation) {
1587 DCHECK(thread_checker_.CalledOnValidThread()); 1597 DCHECK(thread_checker_.CalledOnValidThread());
1588 DCHECK_NE(nqe::internal::InvalidRTT(), observation.value); 1598 DCHECK_NE(nqe::internal::InvalidRTT(), observation.value);
1589 DCHECK_GT(NETWORK_QUALITY_OBSERVATION_SOURCE_MAX, observation.source); 1599 DCHECK_GT(NETWORK_QUALITY_OBSERVATION_SOURCE_MAX, observation.source);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1628 DCHECK_NE(nqe::internal::kInvalidThroughput, downstream_kbps); 1638 DCHECK_NE(nqe::internal::kInvalidThroughput, downstream_kbps);
1629 1639
1630 if (downstream_kbps > peak_network_quality_.downstream_throughput_kbps() || 1640 if (downstream_kbps > peak_network_quality_.downstream_throughput_kbps() ||
1631 peak_network_quality_.downstream_throughput_kbps() == 1641 peak_network_quality_.downstream_throughput_kbps() ==
1632 nqe::internal::kInvalidThroughput) { 1642 nqe::internal::kInvalidThroughput) {
1633 peak_network_quality_ = nqe::internal::NetworkQuality( 1643 peak_network_quality_ = nqe::internal::NetworkQuality(
1634 peak_network_quality_.http_rtt(), peak_network_quality_.transport_rtt(), 1644 peak_network_quality_.http_rtt(), peak_network_quality_.transport_rtt(),
1635 downstream_kbps); 1645 downstream_kbps);
1636 } 1646 }
1637 ThroughputObservation throughput_observation( 1647 ThroughputObservation throughput_observation(
1638 downstream_kbps, tick_clock_->NowTicks(), signal_strength_dbm_, 1648 downstream_kbps, tick_clock_->NowTicks(), signal_strength_,
1639 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP); 1649 NETWORK_QUALITY_OBSERVATION_SOURCE_HTTP);
1640 downstream_throughput_kbps_observations_.AddObservation( 1650 downstream_throughput_kbps_observations_.AddObservation(
1641 throughput_observation); 1651 throughput_observation);
1642 NotifyObserversOfThroughput(throughput_observation); 1652 NotifyObserversOfThroughput(throughput_observation);
1643 } 1653 }
1644 1654
1645 void NetworkQualityEstimator::MaybeComputeEffectiveConnectionType() { 1655 void NetworkQualityEstimator::MaybeComputeEffectiveConnectionType() {
1646 DCHECK(thread_checker_.CalledOnValidThread()); 1656 DCHECK(thread_checker_.CalledOnValidThread());
1647 1657
1648 const base::TimeTicks now = tick_clock_->NowTicks(); 1658 const base::TimeTicks now = tick_clock_->NowTicks();
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
1845 return "UnweightedAverage"; 1855 return "UnweightedAverage";
1846 case STATISTIC_LAST: 1856 case STATISTIC_LAST:
1847 NOTREACHED(); 1857 NOTREACHED();
1848 return ""; 1858 return "";
1849 } 1859 }
1850 NOTREACHED(); 1860 NOTREACHED();
1851 return ""; 1861 return "";
1852 } 1862 }
1853 1863
1854 } // namespace net 1864 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698