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.h

Issue 2007713002: Expose NQE::OnEffectiveConnectionTypeChanged API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 4 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
« no previous file with comments | « no previous file | net/nqe/network_quality_estimator.cc » ('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 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 #ifndef NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ 5 #ifndef NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_
6 #define NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ 6 #define NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <map> 10 #include <map>
(...skipping 14 matching lines...) Expand all
25 #include "net/nqe/cached_network_quality.h" 25 #include "net/nqe/cached_network_quality.h"
26 #include "net/nqe/external_estimate_provider.h" 26 #include "net/nqe/external_estimate_provider.h"
27 #include "net/nqe/network_quality.h" 27 #include "net/nqe/network_quality.h"
28 #include "net/nqe/network_quality_observation.h" 28 #include "net/nqe/network_quality_observation.h"
29 #include "net/nqe/network_quality_observation_source.h" 29 #include "net/nqe/network_quality_observation_source.h"
30 #include "net/nqe/observation_buffer.h" 30 #include "net/nqe/observation_buffer.h"
31 #include "net/socket/socket_performance_watcher_factory.h" 31 #include "net/socket/socket_performance_watcher_factory.h"
32 32
33 namespace base { 33 namespace base {
34 class SingleThreadTaskRunner; 34 class SingleThreadTaskRunner;
35 class TickClock;
35 } // namespace base 36 } // namespace base
36 37
37 namespace net { 38 namespace net {
38 39
39 namespace nqe { 40 namespace nqe {
40 namespace internal { 41 namespace internal {
41 class ThroughputAnalyzer; 42 class ThroughputAnalyzer;
42 } 43 }
43 } 44 }
44 45
(...skipping 24 matching lines...) Expand all
69 EFFECTIVE_CONNECTION_TYPE_UNKNOWN = 0, 70 EFFECTIVE_CONNECTION_TYPE_UNKNOWN = 0,
70 EFFECTIVE_CONNECTION_TYPE_OFFLINE, 71 EFFECTIVE_CONNECTION_TYPE_OFFLINE,
71 EFFECTIVE_CONNECTION_TYPE_SLOW_2G, 72 EFFECTIVE_CONNECTION_TYPE_SLOW_2G,
72 EFFECTIVE_CONNECTION_TYPE_2G, 73 EFFECTIVE_CONNECTION_TYPE_2G,
73 EFFECTIVE_CONNECTION_TYPE_3G, 74 EFFECTIVE_CONNECTION_TYPE_3G,
74 EFFECTIVE_CONNECTION_TYPE_4G, 75 EFFECTIVE_CONNECTION_TYPE_4G,
75 EFFECTIVE_CONNECTION_TYPE_BROADBAND, 76 EFFECTIVE_CONNECTION_TYPE_BROADBAND,
76 EFFECTIVE_CONNECTION_TYPE_LAST, 77 EFFECTIVE_CONNECTION_TYPE_LAST,
77 }; 78 };
78 79
80 // Observes changes in effective connection type.
81 class NET_EXPORT_PRIVATE EffectiveConnectionTypeObserver {
82 public:
83 // Notifies the observer of a change in the effective connection type.
84 // NetworkQualityEstimator computes the effective connection type once in
85 // every interval of duration
86 // |effective_connection_type_recomputation_interval_|. Additionally, when
87 // there is a change in the connection type of the device, then the
88 // effective connection type is immediately recomputed. The observer must
89 // register and unregister itself on the IO thread. All the observers would
90 // be notified on the IO thread.
91 //
92 // If the computed effective connection type is different from the
93 // previously notified effective connection type, then all the registered
94 // observers are notified of the new effective connection type.
95 virtual void OnEffectiveConnectionTypeChanged(
96 EffectiveConnectionType type) = 0;
97
98 protected:
99 EffectiveConnectionTypeObserver() {}
100 virtual ~EffectiveConnectionTypeObserver() {}
101
102 private:
103 DISALLOW_COPY_AND_ASSIGN(EffectiveConnectionTypeObserver);
104 };
105
79 // Observes measurements of round trip time. 106 // Observes measurements of round trip time.
80 class NET_EXPORT_PRIVATE RTTObserver { 107 class NET_EXPORT_PRIVATE RTTObserver {
81 public: 108 public:
82 // Will be called when a new RTT observation is available. The round trip 109 // Will be called when a new RTT observation is available. The round trip
83 // time is specified in milliseconds. The time when the observation was 110 // time is specified in milliseconds. The time when the observation was
84 // taken and the source of the observation are provided. 111 // taken and the source of the observation are provided.
85 virtual void OnRTTObservation(int32_t rtt_ms, 112 virtual void OnRTTObservation(int32_t rtt_ms,
86 const base::TimeTicks& timestamp, 113 const base::TimeTicks& timestamp,
87 NetworkQualityObservationSource source) = 0; 114 NetworkQualityObservationSource source) = 0;
88 115
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 const std::map<std::string, std::string>& variation_params, 164 const std::map<std::string, std::string>& variation_params,
138 bool use_local_host_requests_for_tests, 165 bool use_local_host_requests_for_tests,
139 bool use_smaller_responses_for_tests); 166 bool use_smaller_responses_for_tests);
140 167
141 ~NetworkQualityEstimator() override; 168 ~NetworkQualityEstimator() override;
142 169
143 // Returns the effective type of the current connection. Virtualized for 170 // Returns the effective type of the current connection. Virtualized for
144 // testing. 171 // testing.
145 virtual EffectiveConnectionType GetEffectiveConnectionType() const; 172 virtual EffectiveConnectionType GetEffectiveConnectionType() const;
146 173
174 // Adds |observer| to the list of effective connection type observers. Must be
175 // called on the IO thread.
176 void AddEffectiveConnectionTypeObserver(
177 EffectiveConnectionTypeObserver* observer);
178
179 // Removes |observer| from the list of effective connection type observers.
180 // Must be called on the IO thread.
181 void RemoveEffectiveConnectionTypeObserver(
182 EffectiveConnectionTypeObserver* observer);
183
147 // Returns true if the RTT is available and sets |rtt| to the RTT estimated at 184 // Returns true if the RTT is available and sets |rtt| to the RTT estimated at
148 // the HTTP layer. Virtualized for testing. |rtt| should not be null. The RTT 185 // the HTTP layer. Virtualized for testing. |rtt| should not be null. The RTT
149 // at the HTTP layer measures the time from when the request was sent (this 186 // at the HTTP layer measures the time from when the request was sent (this
150 // happens after the connection is established) to the time when the response 187 // happens after the connection is established) to the time when the response
151 // headers were received. 188 // headers were received.
152 virtual bool GetHttpRTTEstimate(base::TimeDelta* rtt) const 189 virtual bool GetHttpRTTEstimate(base::TimeDelta* rtt) const
153 WARN_UNUSED_RESULT; 190 WARN_UNUSED_RESULT;
154 191
155 // Returns true if the RTT is available and sets |rtt| to the RTT estimated at 192 // Returns true if the RTT is available and sets |rtt| to the RTT estimated at
156 // the transport layer. |rtt| should not be null. 193 // the transport layer. |rtt| should not be null.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 303
267 // ExternalEstimateProvider::UpdatedEstimateObserver implementation. 304 // ExternalEstimateProvider::UpdatedEstimateObserver implementation.
268 void OnUpdatedEstimateAvailable(const base::TimeDelta& rtt, 305 void OnUpdatedEstimateAvailable(const base::TimeDelta& rtt,
269 int32_t downstream_throughput_kbps, 306 int32_t downstream_throughput_kbps,
270 int32_t upstream_throughput_kbps) override; 307 int32_t upstream_throughput_kbps) override;
271 308
272 // Return a string equivalent to |type|. 309 // Return a string equivalent to |type|.
273 const char* GetNameForEffectiveConnectionType( 310 const char* GetNameForEffectiveConnectionType(
274 EffectiveConnectionType type) const; 311 EffectiveConnectionType type) const;
275 312
313 // Overrides the tick clock used by |this| for testing.
314 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock);
315
276 private: 316 private:
277 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); 317 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations);
278 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); 318 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation);
279 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); 319 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams);
280 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); 320 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam);
281 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles); 321 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles);
282 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestCaching); 322 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestCaching);
283 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, 323 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest,
284 TestLRUCacheMaximumSize); 324 TestLRUCacheMaximumSize);
285 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestGetMetricsSince); 325 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestGetMetricsSince);
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 425
386 void NotifyObserversOfThroughput(const ThroughputObservation& observation); 426 void NotifyObserversOfThroughput(const ThroughputObservation& observation);
387 427
388 // Records the UMA related to the RTT at the HTTP layer. 428 // Records the UMA related to the RTT at the HTTP layer.
389 void RecordHttpRTTUMA(int32_t estimated_value_msec, 429 void RecordHttpRTTUMA(int32_t estimated_value_msec,
390 int32_t actual_value_msec) const; 430 int32_t actual_value_msec) const;
391 431
392 // Returns true only if the |request| can be used for RTT estimation. 432 // Returns true only if the |request| can be used for RTT estimation.
393 bool RequestProvidesRTTObservation(const URLRequest& request) const; 433 bool RequestProvidesRTTObservation(const URLRequest& request) const;
394 434
435 // Recomputes effective connection type, if it was computed more than the
436 // specified duration ago, or if there has been a connection change recently.
437 void MaybeRecomputeEffectiveConnectionType();
438
439 // Notify observers of a change in effective connection type.
440 void NotifyObserversOfEffectiveConnectionTypeChanged();
441
395 // Values of external estimate provider status. This enum must remain 442 // Values of external estimate provider status. This enum must remain
396 // synchronized with the enum of the same name in 443 // synchronized with the enum of the same name in
397 // metrics/histograms/histograms.xml. 444 // metrics/histograms/histograms.xml.
398 enum NQEExternalEstimateProviderStatus { 445 enum NQEExternalEstimateProviderStatus {
399 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE, 446 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE,
400 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE, 447 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE,
401 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED, 448 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED,
402 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL, 449 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL,
403 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK, 450 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK,
404 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE, 451 EXTERNAL_ESTIMATE_PROVIDER_STATUS_RTT_AVAILABLE,
(...skipping 10 matching lines...) Expand all
415 const bool use_localhost_requests_; 462 const bool use_localhost_requests_;
416 463
417 // Determines if the responses smaller than |kMinTransferSizeInBytes| 464 // Determines if the responses smaller than |kMinTransferSizeInBytes|
418 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the 465 // or shorter than |kMinTransferSizeInBytes| can be used in estimating the
419 // network quality. Set to true only for tests. 466 // network quality. Set to true only for tests.
420 const bool use_small_responses_; 467 const bool use_small_responses_;
421 468
422 // The factor by which the weight of an observation reduces every second. 469 // The factor by which the weight of an observation reduces every second.
423 const double weight_multiplier_per_second_; 470 const double weight_multiplier_per_second_;
424 471
472 // Tick clock used by the network quality estimator.
473 std::unique_ptr<base::TickClock> tick_clock_;
474
475 // Minimum duration between two consecutive computations of effective
476 // connection type. Set to non-zero value as a performance optimization.
477 const base::TimeDelta effective_connection_type_recomputation_interval_;
478
479 // Time when the effective connection type was last computed.
480 base::TimeTicks last_effective_connection_type_computation_;
481
425 // Time when last connection change was observed. 482 // Time when last connection change was observed.
426 base::TimeTicks last_connection_change_; 483 base::TimeTicks last_connection_change_;
427 484
428 // ID of the current network. 485 // ID of the current network.
429 NetworkID current_network_id_; 486 NetworkID current_network_id_;
430 487
431 // Peak network quality (fastest round-trip-time (RTT) and highest 488 // Peak network quality (fastest round-trip-time (RTT) and highest
432 // downstream throughput) measured since last connectivity change. RTT is 489 // downstream throughput) measured since last connectivity change. RTT is
433 // measured from time the request is sent until the first byte received. 490 // measured from time the request is sent until the first byte received.
434 // The accuracy is decreased by ignoring these factors: 491 // The accuracy is decreased by ignoring these factors:
(...skipping 24 matching lines...) Expand all
459 nqe::internal::NetworkQuality 516 nqe::internal::NetworkQuality
460 connection_thresholds_[EFFECTIVE_CONNECTION_TYPE_LAST]; 517 connection_thresholds_[EFFECTIVE_CONNECTION_TYPE_LAST];
461 518
462 // Estimated network quality. Updated on mainframe requests. 519 // Estimated network quality. Updated on mainframe requests.
463 nqe::internal::NetworkQuality estimated_median_network_quality_; 520 nqe::internal::NetworkQuality estimated_median_network_quality_;
464 521
465 // ExternalEstimateProvider that provides network quality using operating 522 // ExternalEstimateProvider that provides network quality using operating
466 // system APIs. May be NULL. 523 // system APIs. May be NULL.
467 const std::unique_ptr<ExternalEstimateProvider> external_estimate_provider_; 524 const std::unique_ptr<ExternalEstimateProvider> external_estimate_provider_;
468 525
526 // Observer list for changes in effective connection type.
527 base::ObserverList<EffectiveConnectionTypeObserver>
528 effective_connection_type_observer_list_;
529
469 // Observer lists for round trip times and throughput measurements. 530 // Observer lists for round trip times and throughput measurements.
470 base::ObserverList<RTTObserver> rtt_observer_list_; 531 base::ObserverList<RTTObserver> rtt_observer_list_;
471 base::ObserverList<ThroughputObserver> throughput_observer_list_; 532 base::ObserverList<ThroughputObserver> throughput_observer_list_;
472 533
473 std::unique_ptr<SocketPerformanceWatcherFactory> watcher_factory_; 534 std::unique_ptr<SocketPerformanceWatcherFactory> watcher_factory_;
474 535
475 // Takes throughput measurements, and passes them back to |this| through the 536 // Takes throughput measurements, and passes them back to |this| through the
476 // provided callback. |this| stores the throughput observations in 537 // provided callback. |this| stores the throughput observations in
477 // |downstream_throughput_kbps_observations_|, which are later used for 538 // |downstream_throughput_kbps_observations_|, which are later used for
478 // estimating the throughput. 539 // estimating the throughput.
479 std::unique_ptr<nqe::internal::ThroughputAnalyzer> throughput_analyzer_; 540 std::unique_ptr<nqe::internal::ThroughputAnalyzer> throughput_analyzer_;
480 541
542 // Current effective connection type. It is updated on connection change
543 // events. It is also updated every time there is network traffic (provided
544 // the last computation was more than
545 // |effective_connection_type_recomputation_interval_| ago).
546 EffectiveConnectionType effective_connection_type_;
547
481 base::ThreadChecker thread_checker_; 548 base::ThreadChecker thread_checker_;
482 549
483 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; 550 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_;
484 551
485 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); 552 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator);
486 }; 553 };
487 554
488 } // namespace net 555 } // namespace net
489 556
490 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ 557 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_
OLDNEW
« no previous file with comments | « no previous file | net/nqe/network_quality_estimator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698