| Index: components/cronet/android/test/javatests/src/org/chromium/net/TestNetworkQualityRttListener.java
|
| diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/TestNetworkQualityRttListener.java b/components/cronet/android/test/javatests/src/org/chromium/net/TestNetworkQualityRttListener.java
|
| index afeec1f4f53651b45986b50ca842f4fbe79115b2..c2a937ea25d14092651545b9e006c1c4575051d6 100644
|
| --- a/components/cronet/android/test/javatests/src/org/chromium/net/TestNetworkQualityRttListener.java
|
| +++ b/components/cronet/android/test/javatests/src/org/chromium/net/TestNetworkQualityRttListener.java
|
| @@ -6,6 +6,7 @@ package org.chromium.net;
|
|
|
| import static junit.framework.Assert.assertEquals;
|
|
|
| +import android.os.ConditionVariable;
|
| import android.util.SparseIntArray;
|
|
|
| import java.util.concurrent.Executor;
|
| @@ -13,6 +14,10 @@ import java.util.concurrent.Executor;
|
| class TestNetworkQualityRttListener extends NetworkQualityRttListener {
|
| // Lock to ensure that observation counts can be updated and read by different threads.
|
| private final Object mLock = new Object();
|
| +
|
| + // Signals when the first RTT observation at the URL request layer is received.
|
| + private final ConditionVariable mWaitForUrlRequestRtt = new ConditionVariable();
|
| +
|
| private int mRttObservationCount;
|
|
|
| // Holds the RTT observations counts indexed by source.
|
| @@ -20,6 +25,11 @@ class TestNetworkQualityRttListener extends NetworkQualityRttListener {
|
|
|
| private Thread mExecutorThread;
|
|
|
| + /*
|
| + * Constructs a NetworkQualityRttListener that can listen to the RTT observations at various
|
| + * layers of the network stack.
|
| + * @param executor The executor on which the observations are reported.
|
| + */
|
| TestNetworkQualityRttListener(Executor executor) {
|
| super(executor);
|
| }
|
| @@ -27,6 +37,11 @@ class TestNetworkQualityRttListener extends NetworkQualityRttListener {
|
| @Override
|
| public void onRttObservation(int rttMs, long when, int source) {
|
| synchronized (mLock) {
|
| + if (source == 0) {
|
| + // Source 0 indicates that the RTT was observed at the URL request layer.
|
| + mWaitForUrlRequestRtt.open();
|
| + }
|
| +
|
| mRttObservationCount++;
|
| mRttObservationCountBySource.put(source, mRttObservationCountBySource.get(source) + 1);
|
|
|
| @@ -38,6 +53,13 @@ class TestNetworkQualityRttListener extends NetworkQualityRttListener {
|
| }
|
| }
|
|
|
| + /*
|
| + * Blocks until the first RTT observation at the URL request layer is received.
|
| + */
|
| + public void waitUntilFirstUrlRequestRTTReceived() {
|
| + mWaitForUrlRequestRtt.block();
|
| + }
|
| +
|
| public int rttObservationCount() {
|
| synchronized (mLock) {
|
| return mRttObservationCount;
|
|
|