Chromium Code Reviews| Index: components/cronet/android/java/src/org/chromium/net/impl/CronetUrlRequestContext.java |
| diff --git a/components/cronet/android/java/src/org/chromium/net/impl/CronetUrlRequestContext.java b/components/cronet/android/java/src/org/chromium/net/impl/CronetUrlRequestContext.java |
| index 819347d57a1cad185362e7e0315d0afc3d09fe71..66a07f83f2f33dcdb7158ee20476291a46a53b8f 100644 |
| --- a/components/cronet/android/java/src/org/chromium/net/impl/CronetUrlRequestContext.java |
| +++ b/components/cronet/android/java/src/org/chromium/net/impl/CronetUrlRequestContext.java |
| @@ -24,6 +24,7 @@ import org.chromium.net.EffectiveConnectionType; |
| import org.chromium.net.NetworkQualityRttListener; |
| import org.chromium.net.NetworkQualityThroughputListener; |
| import org.chromium.net.RequestFinishedInfo; |
| +import org.chromium.net.RttThroughputValues; |
| import org.chromium.net.UrlRequest; |
| import org.chromium.net.urlconnection.CronetHttpURLConnection; |
| import org.chromium.net.urlconnection.CronetURLStreamHandlerFactory; |
| @@ -94,6 +95,27 @@ public class CronetUrlRequestContext extends CronetEngine { |
| @GuardedBy("mNetworkQualityLock") |
| private int mEffectiveConnectionType = EffectiveConnectionType.TYPE_UNKNOWN; |
| + /** |
| + * Current estimate of the HTTP RTT (in milliseconds) computed by the |
| + * network quality estimator. |
| + */ |
| + @GuardedBy("mNetworkQualityLock") |
| + private int mHttpRttMs = RttThroughputValues.INVALID_RTT_THROUGHPUT_VALUE; |
| + |
| + /** |
| + * Current estimate of the transport RTT (in milliseconds) computed by the |
| + * network quality estimator. |
| + */ |
| + @GuardedBy("mNetworkQualityLock") |
| + private int mTransportRttMs = RttThroughputValues.INVALID_RTT_THROUGHPUT_VALUE; |
| + |
| + /** |
| + * Current estimate of the downstream throughput (in kilobits per second) |
| + * computed by the network quality estimator. |
| + */ |
| + @GuardedBy("mNetworkQualityLock") |
| + private int mDownstreamThroughputKbps = RttThroughputValues.INVALID_RTT_THROUGHPUT_VALUE; |
| + |
| @GuardedBy("mNetworkQualityLock") |
| private final ObserverList<NetworkQualityRttListener> mRttListenerList = |
| new ObserverList<NetworkQualityRttListener>(); |
| @@ -334,6 +356,45 @@ public class CronetUrlRequestContext extends CronetEngine { |
| } |
| } |
| + @Override |
| + public int getHttpRttMsec() { |
| + if (!mNetworkQualityEstimatorEnabled) { |
| + throw new IllegalStateException("Network quality estimator must be enabled"); |
| + } |
| + synchronized (mNetworkQualityLock) { |
| + synchronized (mLock) { |
|
RyanSturm
2016/10/14 21:21:32
I'm not happy with the locking order pattern in th
tbansal1
2016/10/14 21:50:29
This pattern was introduced in https://codereview.
RyanSturm
2016/10/14 22:19:12
Any chance you want to try to fix it in this CL? T
tbansal1
2016/10/14 22:44:43
If we do want to fix it, I would prefer to do it i
RyanSturm
2016/10/14 22:55:38
If getEffectiveConnectionTypeChanged gets blocked
tbansal1
2016/10/14 23:31:49
Yeah, I need to check with clm@ why it was done th
|
| + checkHaveAdapter(); |
| + } |
| + return mHttpRttMs; |
| + } |
| + } |
| + |
| + @Override |
| + public int getTransportRttMsec() { |
| + if (!mNetworkQualityEstimatorEnabled) { |
| + throw new IllegalStateException("Network quality estimator must be enabled"); |
| + } |
| + synchronized (mNetworkQualityLock) { |
| + synchronized (mLock) { |
| + checkHaveAdapter(); |
| + } |
| + return mTransportRttMs; |
| + } |
| + } |
| + |
| + @Override |
| + public int getDownstreamThroughputKbps() { |
| + if (!mNetworkQualityEstimatorEnabled) { |
| + throw new IllegalStateException("Network quality estimator must be enabled"); |
| + } |
| + synchronized (mNetworkQualityLock) { |
| + synchronized (mLock) { |
| + checkHaveAdapter(); |
| + } |
| + return mDownstreamThroughputKbps; |
| + } |
| + } |
| + |
| @VisibleForTesting |
| @Override |
| public void configureNetworkQualityEstimatorForTesting( |
| @@ -527,6 +588,17 @@ public class CronetUrlRequestContext extends CronetEngine { |
| @SuppressWarnings("unused") |
| @CalledByNative |
| + private void onRTTOrThroughputEstimatesComputed( |
| + final int httpRttMs, final int transportRttMs, final int downstreamThroughputKbps) { |
| + synchronized (mNetworkQualityLock) { |
| + mHttpRttMs = httpRttMs; |
| + mTransportRttMs = transportRttMs; |
| + mDownstreamThroughputKbps = downstreamThroughputKbps; |
| + } |
| + } |
| + |
| + @SuppressWarnings("unused") |
| + @CalledByNative |
| private void onRttObservation(final int rttMs, final long whenMs, final int source) { |
| synchronized (mNetworkQualityLock) { |
| for (final NetworkQualityRttListener listener : mRttListenerList) { |