Index: components/cronet/android/java/src/org/chromium/net/CronetUrlRequestContext.java |
diff --git a/components/cronet/android/java/src/org/chromium/net/CronetUrlRequestContext.java b/components/cronet/android/java/src/org/chromium/net/CronetUrlRequestContext.java |
index 7bae2883221d5340a4ddbb23c19c9bf4865d978a..0988e9e163a554a232857ecaf68b3b30629418f4 100644 |
--- a/components/cronet/android/java/src/org/chromium/net/CronetUrlRequestContext.java |
+++ b/components/cronet/android/java/src/org/chromium/net/CronetUrlRequestContext.java |
@@ -12,6 +12,7 @@ import android.os.Looper; |
import android.os.Process; |
import android.util.Log; |
+import org.chromium.base.ObserverList; |
import org.chromium.base.VisibleForTesting; |
import org.chromium.base.annotations.CalledByNative; |
import org.chromium.base.annotations.JNINamespace; |
@@ -42,6 +43,11 @@ class CronetUrlRequestContext extends UrlRequestContext { |
private long mUrlRequestContextAdapter = 0; |
private Thread mNetworkThread; |
+ private final ObserverList<NetworkQualityRTTObserver> mRTTObserverList = |
+ new ObserverList<NetworkQualityRTTObserver>(); |
+ private final ObserverList<NetworkQualityThroughputObserver> mThroughputObserverList = |
+ new ObserverList<NetworkQualityThroughputObserver>(); |
+ |
@UsedByReflection("UrlRequestContext.java") |
public CronetUrlRequestContext(Context context, |
UrlRequestContextConfig config) { |
@@ -148,6 +154,60 @@ class CronetUrlRequestContext extends UrlRequestContext { |
} |
} |
+ @Override |
+ public void enableNetworkQualityEstimator( |
+ boolean useLocalHostRequests, boolean useSmallerResponses) { |
+ synchronized (mLock) { |
+ checkHaveAdapter(); |
+ nativeEnableNetworkQualityEstimator( |
+ mUrlRequestContextAdapter, useLocalHostRequests, useSmallerResponses); |
+ } |
+ } |
+ |
+ @Override |
+ public void addRTTObserver(NetworkQualityRTTObserver observer) { |
+ if (mRTTObserverList.isEmpty()) { |
+ synchronized (mLock) { |
+ checkHaveAdapter(); |
+ nativeProvideRTTObservations(mUrlRequestContextAdapter, true); |
+ } |
+ } |
+ mRTTObserverList.addObserver(observer); |
+ } |
+ |
+ @Override |
+ public void removeRTTObserver(NetworkQualityRTTObserver observer) { |
+ mRTTObserverList.removeObserver(observer); |
+ if (mRTTObserverList.isEmpty()) { |
+ synchronized (mLock) { |
+ checkHaveAdapter(); |
+ nativeProvideRTTObservations(mUrlRequestContextAdapter, false); |
+ } |
+ } |
+ } |
+ |
+ @Override |
+ public void addThroughputObserver(NetworkQualityThroughputObserver observer) { |
+ if (mThroughputObserverList.isEmpty()) { |
+ synchronized (mLock) { |
+ checkHaveAdapter(); |
+ nativeProvideThroughputObservations(mUrlRequestContextAdapter, true); |
+ } |
+ } |
+ mThroughputObserverList.addObserver(observer); |
+ } |
+ |
+ @Override |
+ public void removeThroughputObserver(NetworkQualityThroughputObserver observer) { |
+ mThroughputObserverList.removeObserver(observer); |
mef
2015/08/28 20:53:16
this happens on arbitrary thread.
bengr
2015/08/28 23:51:36
Are you saying that mThroughputObserverList isn't
|
+ if (mThroughputObserverList.isEmpty()) { |
+ synchronized (mLock) { |
+ checkHaveAdapter(); |
+ nativeProvideThroughputObservations(mUrlRequestContextAdapter, false); |
+ } |
+ } |
+ } |
+ |
/** |
* Mark request as started to prevent shutdown when there are active |
* requests. |
@@ -209,6 +269,22 @@ class CronetUrlRequestContext extends UrlRequestContext { |
Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
} |
+ @SuppressWarnings("unused") |
+ @CalledByNative |
+ private void onRTTObservation(int value, int when, int source) { |
+ for (NetworkQualityRTTObserver observer : mRTTObserverList) { |
mef
2015/08/28 20:53:16
this happens on network thread.
If anything, the
bengr
2015/08/28 23:51:36
Good idea. Do you have examples of where you use a
|
+ observer.onRTTObservation(value, when, source); |
+ } |
+ } |
+ |
+ @SuppressWarnings("unused") |
+ @CalledByNative |
+ private void onThroughputObservation(int value, int when, int source) { |
+ for (NetworkQualityThroughputObserver observer : mThroughputObserverList) { |
+ observer.onThroughputObservation(value, when, source); |
+ } |
+ } |
+ |
// Native methods are implemented in cronet_url_request_context.cc. |
private static native long nativeCreateRequestContextAdapter(String config); |
@@ -226,4 +302,14 @@ class CronetUrlRequestContext extends UrlRequestContext { |
@NativeClassQualifiedName("CronetURLRequestContextAdapter") |
private native void nativeInitRequestContextOnMainThread(long nativePtr); |
+ |
+ @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
+ private native void nativeEnableNetworkQualityEstimator( |
+ long nativePtr, boolean useLocalHostRequests, boolean useSmallerResponses); |
+ |
+ @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
+ private native void nativeProvideRTTObservations(long nativePtr, boolean should); |
+ |
+ @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
+ private native void nativeProvideThroughputObservations(long nativePtr, boolean should); |
} |