| Index: components/cronet/android/test/javatests/src/org/chromium/net/TestNetworkQualityThroughputListener.java
|
| diff --git a/components/cronet/android/test/javatests/src/org/chromium/net/TestNetworkQualityThroughputListener.java b/components/cronet/android/test/javatests/src/org/chromium/net/TestNetworkQualityThroughputListener.java
|
| index c4574a50f537fef4ac8026912a7173340a22aa69..5f64ac62356f6271352e3148770da0a25bacf7a6 100644
|
| --- a/components/cronet/android/test/javatests/src/org/chromium/net/TestNetworkQualityThroughputListener.java
|
| +++ b/components/cronet/android/test/javatests/src/org/chromium/net/TestNetworkQualityThroughputListener.java
|
| @@ -13,21 +13,25 @@ import java.util.concurrent.Executor;
|
| class TestNetworkQualityThroughputListener extends NetworkQualityThroughputListener {
|
| // Lock to ensure that observation counts can be updated and read by different threads.
|
| private final Object mLock = new Object();
|
| - private final ConditionVariable mWaitForThroughput;
|
| +
|
| + // Signals when the first throughput observation is received.
|
| + private final ConditionVariable mWaitForThroughput = new ConditionVariable();
|
| +
|
| private int mThroughputObservationCount;
|
| private Thread mExecutorThread;
|
|
|
| - TestNetworkQualityThroughputListener(Executor executor, ConditionVariable waitForThroughput) {
|
| + /*
|
| + * Constructs a NetworkQualityThroughputListener that can listen to the throughput observations.
|
| + * @param executor The executor on which the observations are reported.
|
| + */
|
| + TestNetworkQualityThroughputListener(Executor executor) {
|
| super(executor);
|
| - mWaitForThroughput = waitForThroughput;
|
| }
|
|
|
| @Override
|
| public void onThroughputObservation(int throughputKbps, long when, int source) {
|
| synchronized (mLock) {
|
| - if (mWaitForThroughput != null) {
|
| - mWaitForThroughput.open();
|
| - }
|
| + mWaitForThroughput.open();
|
| mThroughputObservationCount++;
|
| if (mExecutorThread == null) {
|
| mExecutorThread = Thread.currentThread();
|
| @@ -37,6 +41,13 @@ class TestNetworkQualityThroughputListener extends NetworkQualityThroughputListe
|
| }
|
| }
|
|
|
| + /*
|
| + * Blocks until the first throughput observation is received.
|
| + */
|
| + public void waitUntilFirstThroughputObservationReceived() {
|
| + mWaitForThroughput.block();
|
| + }
|
| +
|
| public int throughputObservationCount() {
|
| synchronized (mLock) {
|
| return mThroughputObservationCount;
|
|
|