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

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

Issue 2103323007: Exposing NQE on the Browser UI thread (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: typo Created 4 years, 5 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 class URLRequest; 45 class URLRequest;
46 46
47 // NetworkQualityEstimator provides network quality estimates (quality of the 47 // NetworkQualityEstimator provides network quality estimates (quality of the
48 // full paths to all origins that have been connected to). 48 // full paths to all origins that have been connected to).
49 // The estimates are based on the observed organic traffic. 49 // The estimates are based on the observed organic traffic.
50 // A NetworkQualityEstimator instance is attached to URLRequestContexts and 50 // A NetworkQualityEstimator instance is attached to URLRequestContexts and
51 // observes the traffic of URLRequests spawned from the URLRequestContexts. 51 // observes the traffic of URLRequests spawned from the URLRequestContexts.
52 // A single instance of NQE can be attached to multiple URLRequestContexts, 52 // A single instance of NQE can be attached to multiple URLRequestContexts,
53 // thereby increasing the single NQE instance's accuracy by providing more 53 // thereby increasing the single NQE instance's accuracy by providing more
54 // observed traffic characteristics. 54 // observed traffic characteristics.
55 class NET_EXPORT_PRIVATE NetworkQualityEstimator 55 class NET_EXPORT NetworkQualityEstimator
56 : public NetworkChangeNotifier::ConnectionTypeObserver, 56 : public NetworkChangeNotifier::ConnectionTypeObserver,
57 public ExternalEstimateProvider::UpdatedEstimateDelegate { 57 public ExternalEstimateProvider::UpdatedEstimateDelegate {
58 public: 58 public:
59 // EffectiveConnectionType is the connection type whose typical performance is 59 // EffectiveConnectionType is the connection type whose typical performance is
60 // most similar to the measured performance of the network in use. In many 60 // most similar to the measured performance of the network in use. In many
61 // cases, the "effective" connection type and the actual type of connection in 61 // cases, the "effective" connection type and the actual type of connection in
62 // use are the same, but often a network connection performs significantly 62 // use are the same, but often a network connection performs significantly
63 // different, usually worse, from its expected capabilities. 63 // different, usually worse, from its expected capabilities.
64 // EffectiveConnectionType of a network is independent of if the current 64 // EffectiveConnectionType of a network is independent of if the current
65 // connection is metered or not. For example, an unmetered slow connection may 65 // connection is metered or not. For example, an unmetered slow connection may
66 // have EFFECTIVE_CONNECTION_TYPE_SLOW_2G as its effective connection type. 66 // have EFFECTIVE_CONNECTION_TYPE_SLOW_2G as its effective connection type.
67 enum EffectiveConnectionType { 67 enum EffectiveConnectionType {
68 // The connection types should be in increasing order of quality. 68 // The connection types should be in increasing order of quality.
69 EFFECTIVE_CONNECTION_TYPE_UNKNOWN = 0, 69 EFFECTIVE_CONNECTION_TYPE_UNKNOWN = 0,
70 EFFECTIVE_CONNECTION_TYPE_OFFLINE, 70 EFFECTIVE_CONNECTION_TYPE_OFFLINE,
71 EFFECTIVE_CONNECTION_TYPE_SLOW_2G, 71 EFFECTIVE_CONNECTION_TYPE_SLOW_2G,
72 EFFECTIVE_CONNECTION_TYPE_2G, 72 EFFECTIVE_CONNECTION_TYPE_2G,
73 EFFECTIVE_CONNECTION_TYPE_3G, 73 EFFECTIVE_CONNECTION_TYPE_3G,
74 EFFECTIVE_CONNECTION_TYPE_4G, 74 EFFECTIVE_CONNECTION_TYPE_4G,
75 EFFECTIVE_CONNECTION_TYPE_BROADBAND, 75 EFFECTIVE_CONNECTION_TYPE_BROADBAND,
76 EFFECTIVE_CONNECTION_TYPE_LAST, 76 EFFECTIVE_CONNECTION_TYPE_LAST,
77 }; 77 };
78 78
79 // Observes changes in effective connection type. 79 // Observes changes in effective connection type.
80 class NET_EXPORT_PRIVATE EffectiveConnectionTypeObserver { 80 class NET_EXPORT EffectiveConnectionTypeObserver {
81 public: 81 public:
82 // Notifies the observer of a change in the effective connection type. 82 // Notifies the observer of a change in the effective connection type.
83 // NetworkQualityEstimator computes the effective connection type once in 83 // NetworkQualityEstimator computes the effective connection type once in
84 // every interval of duration 84 // every interval of duration
85 // |effective_connection_type_recomputation_interval_|. Additionally, when 85 // |effective_connection_type_recomputation_interval_|. Additionally, when
86 // there is a change in the connection type of the device, then the 86 // there is a change in the connection type of the device, then the
87 // effective connection type is immediately recomputed. The observer must 87 // effective connection type is immediately recomputed. The observer must
88 // register and unregister itself on the IO thread. All the observers would 88 // register and unregister itself on the IO thread. All the observers would
89 // be notified on the IO thread. 89 // be notified on the IO thread.
90 // 90 //
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 // |use_localhost_requests| should only be true when testing against local 230 // |use_localhost_requests| should only be true when testing against local
231 // HTTP server and allows the requests to local host to be used for network 231 // HTTP server and allows the requests to local host to be used for network
232 // quality estimation. 232 // quality estimation.
233 void SetUseLocalHostRequestsForTesting(bool use_localhost_requests); 233 void SetUseLocalHostRequestsForTesting(bool use_localhost_requests);
234 234
235 // |use_smaller_responses_for_tests| should only be true when testing. 235 // |use_smaller_responses_for_tests| should only be true when testing.
236 // Allows the responses smaller than |kMinTransferSizeInBits| to be used for 236 // Allows the responses smaller than |kMinTransferSizeInBits| to be used for
237 // network quality estimation. 237 // network quality estimation.
238 void SetUseSmallResponsesForTesting(bool use_small_responses); 238 void SetUseSmallResponsesForTesting(bool use_small_responses);
239 239
240 // Prevents updates to EffectiveConnectionTypeObservers aside from calls to
241 // ReportEffectiveConnectionTypeForTesting.
242 void StopReportingEffectiveConnectionTypeForTesting(
243 bool stop_reporting_effective_connection_type);
tbansal1 2016/07/19 23:05:22 I would suggest not including any param in the fun
RyanSturm 2016/07/19 23:31:03 Done.
244
245 // Reports |effective_connection_type| to all
246 // EffectiveConnectionTypeObservers.
247 void ReportEffectiveConnectionTypeForTesting(
248 EffectiveConnectionType effective_connection_type);
249
240 protected: 250 protected:
241 // NetworkID is used to uniquely identify a network. 251 // NetworkID is used to uniquely identify a network.
242 // For the purpose of network quality estimation and caching, a network is 252 // For the purpose of network quality estimation and caching, a network is
243 // uniquely identified by a combination of |type| and 253 // uniquely identified by a combination of |type| and
244 // |id|. This approach is unable to distinguish networks with 254 // |id|. This approach is unable to distinguish networks with
245 // same name (e.g., different Wi-Fi networks with same SSID). 255 // same name (e.g., different Wi-Fi networks with same SSID).
246 // This is a protected member to expose it to tests. 256 // This is a protected member to expose it to tests.
247 struct NET_EXPORT_PRIVATE NetworkID { 257 struct NET_EXPORT_PRIVATE NetworkID {
248 NetworkID(NetworkChangeNotifier::ConnectionType type, const std::string& id) 258 NetworkID(NetworkChangeNotifier::ConnectionType type, const std::string& id)
249 : type(type), id(id) {} 259 : type(type), id(id) {}
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
635 // events. It is also updated every time there is network traffic (provided 645 // events. It is also updated every time there is network traffic (provided
636 // the last computation was more than 646 // the last computation was more than
637 // |effective_connection_type_recomputation_interval_| ago). 647 // |effective_connection_type_recomputation_interval_| ago).
638 EffectiveConnectionType effective_connection_type_; 648 EffectiveConnectionType effective_connection_type_;
639 649
640 // Minimum and Maximum signal strength (in dbM) observed since last connection 650 // Minimum and Maximum signal strength (in dbM) observed since last connection
641 // change. Updated on connection change and main frame requests. 651 // change. Updated on connection change and main frame requests.
642 int32_t min_signal_strength_since_connection_change_; 652 int32_t min_signal_strength_since_connection_change_;
643 int32_t max_signal_strength_since_connection_change_; 653 int32_t max_signal_strength_since_connection_change_;
644 654
655 // When true, no updates to EffectiveConnectionTypeObservers will occur aside
656 // from calls to ReportEffectiveConnectionTypeForTesting.
tbansal1 2016/07/19 23:05:22 s/to/from/
RyanSturm 2016/07/19 23:31:03 Done.
657 bool stop_reporting_effective_connection_type_;
658
645 base::ThreadChecker thread_checker_; 659 base::ThreadChecker thread_checker_;
646 660
647 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_; 661 base::WeakPtrFactory<NetworkQualityEstimator> weak_ptr_factory_;
648 662
649 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator); 663 DISALLOW_COPY_AND_ASSIGN(NetworkQualityEstimator);
650 }; 664 };
651 665
652 } // namespace net 666 } // namespace net
653 667
654 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_ 668 #endif // NET_NQE_NETWORK_QUALITY_ESTIMATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698