| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_THROUGHPUT_ANALYZER_H_ | 5 #ifndef NET_NQE_THROUGHPUT_ANALYZER_H_ |
| 6 #define NET_NQE_THROUGHPUT_ANALYZER_H_ | 6 #define NET_NQE_THROUGHPUT_ANALYZER_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| 11 #include "base/containers/hash_tables.h" | 11 #include "base/containers/hash_tables.h" |
| 12 #include "base/macros.h" | 12 #include "base/macros.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/threading/thread_checker.h" | 14 #include "base/threading/thread_checker.h" |
| 15 #include "base/time/time.h" | 15 #include "base/time/time.h" |
| 16 #include "net/base/net_export.h" | 16 #include "net/base/net_export.h" |
| 17 #include "net/log/net_log_with_source.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 typedef base::Callback<void(int32_t)> ThroughputObservationCallback; | 20 typedef base::Callback<void(int32_t)> ThroughputObservationCallback; |
| 20 } | 21 } |
| 21 | 22 |
| 22 namespace base { | 23 namespace base { |
| 23 class SingleThreadTaskRunner; | 24 class SingleThreadTaskRunner; |
| 24 } | 25 } |
| 25 | 26 |
| 26 namespace net { | 27 namespace net { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 53 // should only be true when testing, and allows the responses smaller than | 54 // should only be true when testing, and allows the responses smaller than |
| 54 // |kMinTransferSizeInBits| or shorter than | 55 // |kMinTransferSizeInBits| or shorter than |
| 55 // |kMinRequestDurationMicroseconds| to be used for network quality | 56 // |kMinRequestDurationMicroseconds| to be used for network quality |
| 56 // estimation. | 57 // estimation. |
| 57 // Virtualized for testing. | 58 // Virtualized for testing. |
| 58 ThroughputAnalyzer( | 59 ThroughputAnalyzer( |
| 59 const NetworkQualityEstimatorParams* params, | 60 const NetworkQualityEstimatorParams* params, |
| 60 scoped_refptr<base::SingleThreadTaskRunner> task_runner, | 61 scoped_refptr<base::SingleThreadTaskRunner> task_runner, |
| 61 ThroughputObservationCallback throughput_observation_callback, | 62 ThroughputObservationCallback throughput_observation_callback, |
| 62 bool use_local_host_requests_for_tests, | 63 bool use_local_host_requests_for_tests, |
| 63 bool use_smaller_responses_for_tests); | 64 bool use_smaller_responses_for_tests, |
| 65 const NetLogWithSource& net_log); |
| 64 virtual ~ThroughputAnalyzer(); | 66 virtual ~ThroughputAnalyzer(); |
| 65 | 67 |
| 66 // Notifies |this| that the headers of |request| are about to be sent. | 68 // Notifies |this| that the headers of |request| are about to be sent. |
| 67 void NotifyStartTransaction(const URLRequest& request); | 69 void NotifyStartTransaction(const URLRequest& request); |
| 68 | 70 |
| 69 // Notifies |this| that |request| has completed. | 71 // Notifies |this| that |request| has completed. |
| 70 void NotifyRequestCompleted(const URLRequest& request); | 72 void NotifyRequestCompleted(const URLRequest& request); |
| 71 | 73 |
| 72 // Notifies |this| of a change in connection type. | 74 // Notifies |this| of a change in connection type. |
| 73 void OnConnectionTypeChanged(); | 75 void OnConnectionTypeChanged(); |
| 74 | 76 |
| 75 // |use_localhost_requests| should only be true when testing against local | 77 // |use_localhost_requests| should only be true when testing against local |
| 76 // HTTP server and allows the requests to local host to be used for network | 78 // HTTP server and allows the requests to local host to be used for network |
| 77 // quality estimation. | 79 // quality estimation. |
| 78 void SetUseLocalHostRequestsForTesting(bool use_localhost_requests); | 80 void SetUseLocalHostRequestsForTesting(bool use_localhost_requests); |
| 79 | 81 |
| 80 // |use_smaller_responses_for_tests| should only be true when testing, and | 82 // |use_smaller_responses_for_tests| should only be true when testing, and |
| 81 // allows the responses smaller than |kMinTransferSizeInBits| or shorter than | 83 // allows the responses smaller than |kMinTransferSizeInBits| or shorter than |
| 82 // |kMinRequestDurationMicroseconds| to be used for network quality | 84 // |kMinRequestDurationMicroseconds| to be used for network quality |
| 83 // estimation. | 85 // estimation. |
| 84 void SetUseSmallResponsesForTesting(bool use_small_responses); | 86 void SetUseSmallResponsesForTesting(bool use_small_responses); |
| 85 | 87 |
| 88 // Returns true if throughput is currently tracked by a throughput |
| 89 // observation window. |
| 90 bool IsCurrentlyTrackingThroughput() const; |
| 91 |
| 86 protected: | 92 protected: |
| 87 // Exposed for testing. | 93 // Exposed for testing. |
| 88 bool disable_throughput_measurements() const { | 94 bool disable_throughput_measurements() const { |
| 89 return disable_throughput_measurements_; | 95 return disable_throughput_measurements_; |
| 90 } | 96 } |
| 91 | 97 |
| 92 // Returns the number of bits received by Chromium so far. The count may not | 98 // Returns the number of bits received by Chromium so far. The count may not |
| 93 // start from zero, so the caller should only look at difference from a prior | 99 // start from zero, so the caller should only look at difference from a prior |
| 94 // call. The count is obtained by polling TrafficStats on Android, and | 100 // call. The count is obtained by polling TrafficStats on Android, and |
| 95 // net::NetworkActivityMonitor on all other platforms. Virtualized for | 101 // net::NetworkActivityMonitor on all other platforms. Virtualized for |
| (...skipping 19 matching lines...) Expand all Loading... |
| 115 // (i) All active requests are non-local; | 121 // (i) All active requests are non-local; |
| 116 // (ii) There is at least one active, non-local request; and, | 122 // (ii) There is at least one active, non-local request; and, |
| 117 // (iii) The throughput observation window is not already tracking | 123 // (iii) The throughput observation window is not already tracking |
| 118 // throughput. The window is started by setting the |start_| and | 124 // throughput. The window is started by setting the |start_| and |
| 119 // |bits_received_|. | 125 // |bits_received_|. |
| 120 void MaybeStartThroughputObservationWindow(); | 126 void MaybeStartThroughputObservationWindow(); |
| 121 | 127 |
| 122 // EndThroughputObservationWindow ends the throughput observation window. | 128 // EndThroughputObservationWindow ends the throughput observation window. |
| 123 void EndThroughputObservationWindow(); | 129 void EndThroughputObservationWindow(); |
| 124 | 130 |
| 125 // Returns true if throughput is currently tracked by a throughput | |
| 126 // observation window. | |
| 127 bool IsCurrentlyTrackingThroughput() const; | |
| 128 | |
| 129 // Returns true if the |request| degrades the accuracy of the throughput | 131 // Returns true if the |request| degrades the accuracy of the throughput |
| 130 // observation window. A local request or a request that spans a connection | 132 // observation window. A local request or a request that spans a connection |
| 131 // change degrades the accuracy of the throughput computation. | 133 // change degrades the accuracy of the throughput computation. |
| 132 bool DegradesAccuracy(const URLRequest& request) const; | 134 bool DegradesAccuracy(const URLRequest& request) const; |
| 133 | 135 |
| 134 // Bounds |accuracy_degrading_requests_| and |requests_| to ensure their sizes | 136 // Bounds |accuracy_degrading_requests_| and |requests_| to ensure their sizes |
| 135 // do not exceed their capacities. | 137 // do not exceed their capacities. |
| 136 void BoundRequestsSize(); | 138 void BoundRequestsSize(); |
| 137 | 139 |
| 138 const NetworkQualityEstimatorParams* params_; | 140 const NetworkQualityEstimatorParams* params_; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 171 // network quality. Set to true only for tests. | 173 // network quality. Set to true only for tests. |
| 172 bool use_localhost_requests_for_tests_; | 174 bool use_localhost_requests_for_tests_; |
| 173 | 175 |
| 174 // Determines if the responses smaller than |kMinTransferSizeInBits| | 176 // Determines if the responses smaller than |kMinTransferSizeInBits| |
| 175 // or shorter than |kMinTransferSizeInBits| can be used in estimating the | 177 // or shorter than |kMinTransferSizeInBits| can be used in estimating the |
| 176 // network quality. Set to true only for tests. | 178 // network quality. Set to true only for tests. |
| 177 bool use_small_responses_for_tests_; | 179 bool use_small_responses_for_tests_; |
| 178 | 180 |
| 179 base::ThreadChecker thread_checker_; | 181 base::ThreadChecker thread_checker_; |
| 180 | 182 |
| 183 NetLogWithSource net_log_; |
| 184 |
| 181 DISALLOW_COPY_AND_ASSIGN(ThroughputAnalyzer); | 185 DISALLOW_COPY_AND_ASSIGN(ThroughputAnalyzer); |
| 182 }; | 186 }; |
| 183 | 187 |
| 184 } // namespace internal | 188 } // namespace internal |
| 185 | 189 |
| 186 } // namespace nqe | 190 } // namespace nqe |
| 187 | 191 |
| 188 } // namespace net | 192 } // namespace net |
| 189 | 193 |
| 190 #endif // NET_NQE_THROUGHPUT_ANALYZER_H_ | 194 #endif // NET_NQE_THROUGHPUT_ANALYZER_H_ |
| OLD | NEW |