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

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

Issue 2406763003: Add Network Quality observer to NQE (Closed)
Patch Set: ps Created 4 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
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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 EffectiveConnectionType type) = 0; 77 EffectiveConnectionType type) = 0;
78 78
79 protected: 79 protected:
80 EffectiveConnectionTypeObserver() {} 80 EffectiveConnectionTypeObserver() {}
81 virtual ~EffectiveConnectionTypeObserver() {} 81 virtual ~EffectiveConnectionTypeObserver() {}
82 82
83 private: 83 private:
84 DISALLOW_COPY_AND_ASSIGN(EffectiveConnectionTypeObserver); 84 DISALLOW_COPY_AND_ASSIGN(EffectiveConnectionTypeObserver);
85 }; 85 };
86 86
87 // Observes changes in the network quality.
88 class NET_EXPORT NetworkQualityObserver {
89 public:
90 // Notifies the observer of a change in the network quality (estimated HTTP
91 // RTT, estimated transport RTT and estimated downstream throughput).
92 // NetworkQualityEstimator computes the network quality once in
93 // every interval of duration
94 // |effective_connection_type_recomputation_interval_|. Additionally, when
95 // there is a change in the connection type of the device, then the
96 // network quality is immediately recomputed. The observer must
97 // register and unregister itself on the IO thread. All the observers would
98 // be notified on the IO thread.
RyanSturm 2016/10/11 01:46:26 nit: I feel like this comment could be reformatted
tbansal1 2016/10/11 17:46:12 Done.
99 //
100 // If the computed network quality is different from the previously notified
RyanSturm 2016/10/11 01:46:26 nit: Can you say something like "If any of the thr
tbansal1 2016/10/11 17:46:12 Done.
101 // network quality, then all the registered observers are notified of the
102 // new network quality. |http_rtt|, |transport_rtt| and
103 // |downstream_throughput_kbps| are the current estimates of the HTTP RTT,
104 // transport RTT and downstream throughput (in kilobits per second),
105 // respectively. If an estimate of the HTTP or transport RTT is unavailable,
106 // it will be set to nqe::internal::InvalidRTT(). If the throughput is
107 // unavailable, it will be set to nqe::internal::kInvalidThroughput.
108 virtual void OnNetworkQualityChanged(
109 base::TimeDelta http_rtt,
110 base::TimeDelta transport_rtt,
111 int32_t downstream_throughput_kbps) = 0;
112
113 protected:
114 NetworkQualityObserver() {}
115 virtual ~NetworkQualityObserver() {}
116
117 private:
118 DISALLOW_COPY_AND_ASSIGN(NetworkQualityObserver);
119 };
120
87 // Observes measurements of round trip time. 121 // Observes measurements of round trip time.
88 class NET_EXPORT_PRIVATE RTTObserver { 122 class NET_EXPORT_PRIVATE RTTObserver {
89 public: 123 public:
90 // Will be called when a new RTT observation is available. The round trip 124 // Will be called when a new RTT observation is available. The round trip
91 // time is specified in milliseconds. The time when the observation was 125 // time is specified in milliseconds. The time when the observation was
92 // taken and the source of the observation are provided. 126 // taken and the source of the observation are provided.
93 virtual void OnRTTObservation(int32_t rtt_ms, 127 virtual void OnRTTObservation(int32_t rtt_ms,
94 const base::TimeTicks& timestamp, 128 const base::TimeTicks& timestamp,
95 NetworkQualityObservationSource source) = 0; 129 NetworkQualityObservationSource source) = 0;
96 130
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 // Adds |observer| to the list of effective connection type observers. Must be 212 // Adds |observer| to the list of effective connection type observers. Must be
179 // called on the IO thread. 213 // called on the IO thread.
180 void AddEffectiveConnectionTypeObserver( 214 void AddEffectiveConnectionTypeObserver(
181 EffectiveConnectionTypeObserver* observer); 215 EffectiveConnectionTypeObserver* observer);
182 216
183 // Removes |observer| from the list of effective connection type observers. 217 // Removes |observer| from the list of effective connection type observers.
184 // Must be called on the IO thread. 218 // Must be called on the IO thread.
185 void RemoveEffectiveConnectionTypeObserver( 219 void RemoveEffectiveConnectionTypeObserver(
186 EffectiveConnectionTypeObserver* observer); 220 EffectiveConnectionTypeObserver* observer);
187 221
222 // Adds |observer| to the list of network quality observers. Must be
223 // called on the IO thread.
224 void AddNetworkQualityObserver(NetworkQualityObserver* observer);
225
226 // Removes |observer| from the list of network quality observers.
227 // Must be called on the IO thread.
228 void RemoveNetworkQualityObserver(NetworkQualityObserver* observer);
229
188 // Notifies NetworkQualityEstimator that the response header of |request| has 230 // Notifies NetworkQualityEstimator that the response header of |request| has
189 // been received. 231 // been received.
190 void NotifyHeadersReceived(const URLRequest& request); 232 void NotifyHeadersReceived(const URLRequest& request);
191 233
192 // Notifies NetworkQualityEstimator that the headers of |request| are about to 234 // Notifies NetworkQualityEstimator that the headers of |request| are about to
193 // be sent. 235 // be sent.
194 void NotifyStartTransaction(const URLRequest& request); 236 void NotifyStartTransaction(const URLRequest& request);
195 237
196 // Notifies NetworkQualityEstimator that the response body of |request| has 238 // Notifies NetworkQualityEstimator that the response body of |request| has
197 // been received. 239 // been received.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 // prediction should be recorded. Virtualized for testing. 343 // prediction should be recorded. Virtualized for testing.
302 virtual const std::vector<base::TimeDelta>& GetAccuracyRecordingIntervals() 344 virtual const std::vector<base::TimeDelta>& GetAccuracyRecordingIntervals()
303 const; 345 const;
304 346
305 // Overrides the tick clock used by |this| for testing. 347 // Overrides the tick clock used by |this| for testing.
306 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock); 348 void SetTickClockForTesting(std::unique_ptr<base::TickClock> tick_clock);
307 349
308 // Returns a random double in the range [0.0, 1.0). Virtualized for testing. 350 // Returns a random double in the range [0.0, 1.0). Virtualized for testing.
309 virtual double RandDouble() const; 351 virtual double RandDouble() const;
310 352
353 // Returns the effective type of the current connection based on only the
354 // observations received after |start_time|. May use HTTP RTT, transport RTT
355 // and downstream throughput to compute the effective connection type based on
356 // |http_rtt_metric|, |transport_rtt_metric| and
RyanSturm 2016/10/11 01:46:26 Are the "|*_metric|" variables relevant to this me
tbansal1 2016/10/11 17:46:12 Done.
357 // |downstream_throughput_kbps_metric|, respectively. |http_rtt|,
358 // |transport_rtt| and |downstream_throughput_kbps| must be non-null.
359 // |http_rtt|, |transport_rtt| and |downstream_throughput_kbps| are
360 // set to the expected HTTP RTT, transport RTT and downstream throughput (in
361 // kilobits per second) based on observations taken since |start_time|.
362 // Virtualized for testing.
363 virtual EffectiveConnectionType
364 GetRecentEffectiveConnectionTypeAndNetworkQuality(
365 const base::TimeTicks& start_time,
366 base::TimeDelta* http_rtt,
367 base::TimeDelta* transport_rtt,
368 int32_t* downstream_throughput_kbps) const;
369
311 private: 370 private:
312 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, 371 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest,
313 AdaptiveRecomputationEffectiveConnectionType); 372 AdaptiveRecomputationEffectiveConnectionType);
314 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations); 373 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, StoreObservations);
315 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation); 374 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, TestAddObservation);
316 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams); 375 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ObtainOperatingParams);
317 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, 376 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest,
318 ObtainAlgorithmToUseFromParams); 377 ObtainAlgorithmToUseFromParams);
319 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam); 378 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, HalfLifeParam);
320 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles); 379 FRIEND_TEST_ALL_PREFIXES(NetworkQualityEstimatorTest, ComputedPercentiles);
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 520
462 // Obtains the current cellular signal strength value and updates 521 // Obtains the current cellular signal strength value and updates
463 // |min_signal_strength_since_connection_change_| and 522 // |min_signal_strength_since_connection_change_| and
464 // |max_signal_strength_since_connection_change_|. 523 // |max_signal_strength_since_connection_change_|.
465 void UpdateSignalStrength(); 524 void UpdateSignalStrength();
466 525
467 // Returns the effective type of the current connection based on only the 526 // Returns the effective type of the current connection based on only the
468 // samples observed after |start_time|. May use HTTP RTT, transport RTT and 527 // samples observed after |start_time|. May use HTTP RTT, transport RTT and
469 // downstream throughput to compute the effective connection type based on 528 // downstream throughput to compute the effective connection type based on
470 // |http_rtt_metric|, |transport_rtt_metric| and 529 // |http_rtt_metric|, |transport_rtt_metric| and
471 // |downstream_throughput_kbps_metric|, respectively. 530 // |downstream_throughput_kbps_metric|, respectively. |http_rtt|,
531 // |transport_rtt| and |downstream_throughput_kbps| must be non-null.
532 // |http_rtt|, |transport_rtt| and |downstream_throughput_kbps| are
533 // set to the expected HTTP RTT, transport RTT and downstream throughput (in
534 // kilobits per second) based on observations taken since |start_time|.
472 EffectiveConnectionType GetRecentEffectiveConnectionTypeUsingMetrics( 535 EffectiveConnectionType GetRecentEffectiveConnectionTypeUsingMetrics(
473 const base::TimeTicks& start_time, 536 const base::TimeTicks& start_time,
474 MetricUsage http_rtt_metric, 537 MetricUsage http_rtt_metric,
475 MetricUsage transport_rtt_metric, 538 MetricUsage transport_rtt_metric,
476 MetricUsage downstream_throughput_kbps_metric) const; 539 MetricUsage downstream_throughput_kbps_metric,
540 base::TimeDelta* http_rtt,
541 base::TimeDelta* transport_rtt,
542 int32_t* downstream_throughput_kbps) const;
477 543
478 // Values of external estimate provider status. This enum must remain 544 // Values of external estimate provider status. This enum must remain
479 // synchronized with the enum of the same name in 545 // synchronized with the enum of the same name in
480 // metrics/histograms/histograms.xml. 546 // metrics/histograms/histograms.xml.
481 enum NQEExternalEstimateProviderStatus { 547 enum NQEExternalEstimateProviderStatus {
482 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE, 548 EXTERNAL_ESTIMATE_PROVIDER_STATUS_NOT_AVAILABLE,
483 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE, 549 EXTERNAL_ESTIMATE_PROVIDER_STATUS_AVAILABLE,
484 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED, 550 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERIED,
485 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL, 551 EXTERNAL_ESTIMATE_PROVIDER_STATUS_QUERY_SUCCESSFUL,
486 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK, 552 EXTERNAL_ESTIMATE_PROVIDER_STATUS_CALLBACK,
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
583 EffectiveConnectionType effective_connection_type_at_last_main_frame_; 649 EffectiveConnectionType effective_connection_type_at_last_main_frame_;
584 650
585 // Estimated network quality obtained from external estimate provider when the 651 // Estimated network quality obtained from external estimate provider when the
586 // external estimate provider was last queried. 652 // external estimate provider was last queried.
587 nqe::internal::NetworkQuality external_estimate_provider_quality_; 653 nqe::internal::NetworkQuality external_estimate_provider_quality_;
588 654
589 // ExternalEstimateProvider that provides network quality using operating 655 // ExternalEstimateProvider that provides network quality using operating
590 // system APIs. May be NULL. 656 // system APIs. May be NULL.
591 const std::unique_ptr<ExternalEstimateProvider> external_estimate_provider_; 657 const std::unique_ptr<ExternalEstimateProvider> external_estimate_provider_;
592 658
593 // Observer list for changes in effective connection type. 659 // Observer list for changes in the effective connection type.
RyanSturm 2016/10/11 01:46:26 nit: I don't think adding "the" here improves this
tbansal1 2016/10/11 17:46:12 Done.
594 base::ObserverList<EffectiveConnectionTypeObserver> 660 base::ObserverList<EffectiveConnectionTypeObserver>
595 effective_connection_type_observer_list_; 661 effective_connection_type_observer_list_;
596 662
663 // Observer list for changes in the network quality.
664 base::ObserverList<NetworkQualityObserver> network_quality_observer_list_;
665
597 // Observer lists for round trip times and throughput measurements. 666 // Observer lists for round trip times and throughput measurements.
598 base::ObserverList<RTTObserver> rtt_observer_list_; 667 base::ObserverList<RTTObserver> rtt_observer_list_;
599 base::ObserverList<ThroughputObserver> throughput_observer_list_; 668 base::ObserverList<ThroughputObserver> throughput_observer_list_;
600 669
601 std::unique_ptr<SocketPerformanceWatcherFactory> watcher_factory_; 670 std::unique_ptr<SocketPerformanceWatcherFactory> watcher_factory_;
602 671
603 // Takes throughput measurements, and passes them back to |this| through the 672 // Takes throughput measurements, and passes them back to |this| through the
604 // provided callback. |this| stores the throughput observations in 673 // provided callback. |this| stores the throughput observations in
605 // |downstream_throughput_kbps_observations_|, which are later used for 674 // |downstream_throughput_kbps_observations_|, which are later used for
606 // estimating the throughput. 675 // estimating the throughput.
607 std::unique_ptr<nqe::internal::ThroughputAnalyzer> throughput_analyzer_; 676 std::unique_ptr<nqe::internal::ThroughputAnalyzer> throughput_analyzer_;
608 677
609 // Minimum duration between two consecutive computations of effective 678 // Minimum duration between two consecutive computations of effective
610 // connection type. Set to non-zero value as a performance optimization. 679 // connection type. Set to non-zero value as a performance optimization.
611 const base::TimeDelta effective_connection_type_recomputation_interval_; 680 const base::TimeDelta effective_connection_type_recomputation_interval_;
612 681
613 // Time when the effective connection type was last computed. 682 // Time when the effective connection type was last computed.
614 base::TimeTicks last_effective_connection_type_computation_; 683 base::TimeTicks last_effective_connection_type_computation_;
615 684
616 // Number of RTT and bandwidth samples available when effective connection 685 // Number of RTT and bandwidth samples available when effective connection
617 // type was last recomputed. 686 // type was last recomputed.
618 size_t rtt_observations_size_at_last_ect_computation_; 687 size_t rtt_observations_size_at_last_ect_computation_;
619 size_t throughput_observations_size_at_last_ect_computation_; 688 size_t throughput_observations_size_at_last_ect_computation_;
620 689
690 // Current estimates of the HTTP RTT, transport RTT and downstream throughput
691 // (in kilobits per second).
692 base::TimeDelta http_rtt_;
693 base::TimeDelta transport_rtt_;
694 int32_t downstream_throughput_kbps_;
695
621 // Current effective connection type. It is updated on connection change 696 // Current effective connection type. It is updated on connection change
622 // events. It is also updated every time there is network traffic (provided 697 // events. It is also updated every time there is network traffic (provided
623 // the last computation was more than 698 // the last computation was more than
624 // |effective_connection_type_recomputation_interval_| ago). 699 // |effective_connection_type_recomputation_interval_| ago).
625 EffectiveConnectionType effective_connection_type_; 700 EffectiveConnectionType effective_connection_type_;
626 701
627 // Minimum and Maximum signal strength (in dbM) observed since last connection 702 // Minimum and Maximum signal strength (in dbM) observed since last connection
628 // change. Updated on connection change and main frame requests. 703 // change. Updated on connection change and main frame requests.
629 int32_t min_signal_strength_since_connection_change_; 704 int32_t min_signal_strength_since_connection_change_;
630 int32_t max_signal_strength_since_connection_change_; 705 int32_t max_signal_strength_since_connection_change_;
(...skipping 17 matching lines...) Expand all
648 base::ThreadChecker thread_checker_; 723 base::ThreadChecker thread_checker_;
649 724
650 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; 725 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_;
651 726
652 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); 727 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator);
653 }; 728 };
654 729
655 } // namespace net 730 } // namespace net
656 731
657 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ 732 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_
OLDNEW
« no previous file with comments | « no previous file | net/nqe/network_quality_estimator.cc » ('j') | net/nqe/network_quality_estimator.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698