Index: components/cronet/android/api/src/org/chromium/net/CronetEngine.java |
diff --git a/components/cronet/android/api/src/org/chromium/net/CronetEngine.java b/components/cronet/android/api/src/org/chromium/net/CronetEngine.java |
index f30991ac3c7ae2223aaaeabfa683902ab575467f..b1d672798e35b3e5f652161e09270c82971001f7 100644 |
--- a/components/cronet/android/api/src/org/chromium/net/CronetEngine.java |
+++ b/components/cronet/android/api/src/org/chromium/net/CronetEngine.java |
@@ -119,6 +119,7 @@ public abstract class CronetEngine { |
private long mHttpCacheMaxSize; |
private String mExperimentalOptions; |
private long mMockCertVerifier; |
+ private boolean mNetworkQualityEstimatorEnabled; |
/** |
* Default config enables SPDY, disables QUIC, SDCH and HTTP cache. |
@@ -132,6 +133,7 @@ public abstract class CronetEngine { |
enableHTTP2(true); |
enableSDCH(false); |
enableHttpCache(HTTP_CACHE_DISABLED, 0); |
+ enableNetworkQualityEstimator(false); |
} |
/** |
@@ -601,6 +603,41 @@ public abstract class CronetEngine { |
} |
/** |
+ * Enables the network quality estimator, which collects and reports |
+ * measurements of round trip time (RTT) and downstream throughput at |
+ * various layers of the network stack. After enabling the estimator, |
+ * listeners of RTT and throughput can be added with |
+ * {@link #addRttListener} and {@link #addThroughputListener} and |
+ * removed with {@link #removeRttListener} and |
+ * {@link #removeThroughputListener}. The estimator uses memory and CPU |
+ * only when enabled. |
+ * @param value {@code true} to enable network quality estimator, |
+ * {@code false} to disable. |
+ * @hide as it's a prototype. |
+ * @return the builder to facilitate chaining. |
+ */ |
+ public Builder enableNetworkQualityEstimator(boolean value) { |
+ if (!value) { |
mef
2016/06/20 16:50:27
I think for Builder it is ok to be able to turn it
tbansal1
2016/06/20 20:06:57
Done.
|
+ return this; |
+ } |
+ |
+ if (mNetworkQualityEstimatorEnabled) { |
+ throw new IllegalStateException("Network quality estimator is already initialized"); |
+ } |
+ mNetworkQualityEstimatorEnabled = true; |
+ return this; |
+ } |
+ |
+ /** |
+ * @return true if the network quality estimator has been enabled for |
+ * this builder. |
+ * @hide as it's a prototype. |
+ */ |
+ boolean networkQualityEstimatorEnabled() { |
+ return mNetworkQualityEstimatorEnabled; |
+ } |
+ |
+ /** |
* Returns {@link Context} for builder. |
* |
* @return {@link Context} for builder. |
@@ -790,6 +827,18 @@ public abstract class CronetEngine { |
public abstract byte[] getGlobalMetricsDeltas(); |
/** |
+ * Sets the executor which will be used to notify RequestFinished |
+ * listeners, and to notify network quality RTT listeners |
+ * that do not provide an executor. |
+ * TODO(tbansal): http://crbug.com/618034 Remove this API. In short term, |
+ * once all Cronet embedders supply a valid executor with |
+ * NetworkQualityRTTListener, update the above comment to reflect that |
+ * {@link executor} is only used to notify RequestFinishedListeners. |
+ * @hide as it's a prototype. |
+ */ |
+ public abstract void setRequestFinishedListenerExecutor(Executor executor); |
+ |
+ /** |
* Enables the network quality estimator, which collects and reports |
* measurements of round trip time (RTT) and downstream throughput at |
* various layers of the network stack. After enabling the estimator, |
@@ -800,22 +849,22 @@ public abstract class CronetEngine { |
* only when enabled. |
* @param executor an executor that will be used to notified all |
* added RTT and throughput listeners. |
+ * TODO(tbansal): http://crbug.com/618034 Remove this API. |
* @hide as it's a prototype. |
*/ |
public abstract void enableNetworkQualityEstimator(Executor executor); |
/** |
- * Enables the network quality estimator for testing. This must be called |
- * before round trip time and throughput listeners are added. Set both |
- * boolean parameters to false for default behavior. |
+ * Configures the network quality estimator for testing. This must be called |
+ * before round trip time and throughput listeners are added, and after the |
+ * network quality estimator has been enabled. |
* @param useLocalHostRequests include requests to localhost in estimates. |
- * @param useSmallerResponses include small responses in throughput estimates. |
- * @param executor an {@link java.util.concurrent.Executor} on which all |
- * listeners will be called. |
+ * @param useSmallerResponses include small responses in throughput |
+ * estimates. |
* @hide as it's a prototype. |
*/ |
- abstract void enableNetworkQualityEstimatorForTesting( |
- boolean useLocalHostRequests, boolean useSmallerResponses, Executor executor); |
+ abstract void configureNetworkQualityEstimatorForTesting( |
+ boolean useLocalHostRequests, boolean useSmallerResponses); |
/** |
* Registers a listener that gets called whenever the network quality |
@@ -978,6 +1027,8 @@ public abstract class CronetEngine { |
* |
* @param listener the listener for finished requests. |
* |
+ * TODO(tbansal): http://crbug.com/618034 Remove this API, once all embedders have switched to |
+ * using a request finished listener that provides its own executor. |
* @hide as it's a prototype. |
*/ |
public abstract void addRequestFinishedListener(RequestFinishedListener listener); |
@@ -987,6 +1038,8 @@ public abstract class CronetEngine { |
* |
* @param listener the listener to remove. |
* |
+ * TODO(tbansal): http://crbug.com/618034 Remove this API, once all embedders have switched to |
+ * using a request finished listener that provides its own executor. |
* @hide it's a prototype. |
*/ |
public abstract void removeRequestFinishedListener(RequestFinishedListener listener); |
@@ -1107,9 +1160,11 @@ public abstract class CronetEngine { |
/** |
* Interface to listen for finished requests that were created via this CronetEngine instance. |
* |
+ * TODO(tbansal): http://crbug.com/618034 Remove this API, and replace it with a listener |
+ * whose executor is bound to the lifetime of the listener. |
* @hide as it's a prototype. |
*/ |
- public interface RequestFinishedListener { // TODO(klm): Add a convenience abstract class. |
+ public interface RequestFinishedListener { |
/** |
* Invoked with request info. |
* @param requestInfo {@link UrlRequestInfo} for finished request. |