Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.net; | 5 package org.chromium.net; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.os.Build; | 8 import android.os.Build; |
| 9 import android.os.ConditionVariable; | 9 import android.os.ConditionVariable; |
| 10 import android.os.Handler; | 10 import android.os.Handler; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 | 73 |
| 74 @GuardedBy("mNetworkQualityLock") | 74 @GuardedBy("mNetworkQualityLock") |
| 75 private final ObserverList<RequestFinishedListener> mFinishedListenerList = | 75 private final ObserverList<RequestFinishedListener> mFinishedListenerList = |
| 76 new ObserverList<RequestFinishedListener>(); | 76 new ObserverList<RequestFinishedListener>(); |
| 77 | 77 |
| 78 @UsedByReflection("CronetEngine.java") | 78 @UsedByReflection("CronetEngine.java") |
| 79 public CronetUrlRequestContext(final CronetEngine.Builder builder) { | 79 public CronetUrlRequestContext(final CronetEngine.Builder builder) { |
| 80 CronetLibraryLoader.ensureInitialized(builder.getContext(), builder); | 80 CronetLibraryLoader.ensureInitialized(builder.getContext(), builder); |
| 81 nativeSetMinLogLevel(getLoggingLevel()); | 81 nativeSetMinLogLevel(getLoggingLevel()); |
| 82 synchronized (mLock) { | 82 synchronized (mLock) { |
| 83 mNetworkQualityEstimatorEnabled = builder.networkQualityEstimatorEna bled(); | |
| 84 mNetworkQualityExecutor = builder.networkQualityEstimatorExecutor(); | |
| 83 mUrlRequestContextAdapter = nativeCreateRequestContextAdapter( | 85 mUrlRequestContextAdapter = nativeCreateRequestContextAdapter( |
| 84 createNativeUrlRequestContextConfig(builder.getContext(), bu ilder)); | 86 createNativeUrlRequestContextConfig(builder.getContext(), bu ilder)); |
| 85 if (mUrlRequestContextAdapter == 0) { | 87 if (mUrlRequestContextAdapter == 0) { |
| 86 throw new NullPointerException("Context Adapter creation failed. "); | 88 throw new NullPointerException("Context Adapter creation failed. "); |
| 87 } | 89 } |
| 88 } | 90 } |
| 89 | 91 |
| 90 // Init native Chromium URLRequestContext on main UI thread. | 92 // Init native Chromium URLRequestContext on main UI thread. |
| 91 Runnable task = new Runnable() { | 93 Runnable task = new Runnable() { |
| 92 @Override | 94 @Override |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 110 | 112 |
| 111 static long createNativeUrlRequestContextConfig( | 113 static long createNativeUrlRequestContextConfig( |
| 112 final Context context, CronetEngine.Builder builder) { | 114 final Context context, CronetEngine.Builder builder) { |
| 113 final long urlRequestContextConfig = nativeCreateRequestContextConfig( | 115 final long urlRequestContextConfig = nativeCreateRequestContextConfig( |
| 114 builder.getUserAgent(), builder.storagePath(), builder.quicEnabl ed(), | 116 builder.getUserAgent(), builder.storagePath(), builder.quicEnabl ed(), |
| 115 builder.getDefaultQuicUserAgentId(context), builder.http2Enabled (), | 117 builder.getDefaultQuicUserAgentId(context), builder.http2Enabled (), |
| 116 builder.sdchEnabled(), builder.dataReductionProxyKey(), | 118 builder.sdchEnabled(), builder.dataReductionProxyKey(), |
| 117 builder.dataReductionProxyPrimaryProxy(), builder.dataReductionP roxyFallbackProxy(), | 119 builder.dataReductionProxyPrimaryProxy(), builder.dataReductionP roxyFallbackProxy(), |
| 118 builder.dataReductionProxySecureProxyCheckUrl(), builder.cacheDi sabled(), | 120 builder.dataReductionProxySecureProxyCheckUrl(), builder.cacheDi sabled(), |
| 119 builder.httpCacheMode(), builder.httpCacheMaxSize(), builder.exp erimentalOptions(), | 121 builder.httpCacheMode(), builder.httpCacheMaxSize(), builder.exp erimentalOptions(), |
| 120 builder.mockCertVerifier()); | 122 builder.mockCertVerifier(), builder.networkQualityEstimatorEnabl ed()); |
| 121 for (Builder.QuicHint quicHint : builder.quicHints()) { | 123 for (Builder.QuicHint quicHint : builder.quicHints()) { |
| 122 nativeAddQuicHint(urlRequestContextConfig, quicHint.mHost, quicHint. mPort, | 124 nativeAddQuicHint(urlRequestContextConfig, quicHint.mHost, quicHint. mPort, |
| 123 quicHint.mAlternatePort); | 125 quicHint.mAlternatePort); |
| 124 } | 126 } |
| 125 for (Builder.Pkp pkp : builder.publicKeyPins()) { | 127 for (Builder.Pkp pkp : builder.publicKeyPins()) { |
| 126 nativeAddPkp(urlRequestContextConfig, pkp.mHost, pkp.mHashes, pkp.mI ncludeSubdomains, | 128 nativeAddPkp(urlRequestContextConfig, pkp.mHost, pkp.mHashes, pkp.mI ncludeSubdomains, |
| 127 pkp.mExpirationDate.getTime()); | 129 pkp.mExpirationDate.getTime()); |
| 128 } | 130 } |
| 129 return urlRequestContextConfig; | 131 return urlRequestContextConfig; |
| 130 } | 132 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 215 } | 217 } |
| 216 } | 218 } |
| 217 | 219 |
| 218 // This method is intentionally non-static to ensure Cronet native library | 220 // This method is intentionally non-static to ensure Cronet native library |
| 219 // is loaded by class constructor. | 221 // is loaded by class constructor. |
| 220 @Override | 222 @Override |
| 221 public byte[] getGlobalMetricsDeltas() { | 223 public byte[] getGlobalMetricsDeltas() { |
| 222 return nativeGetHistogramDeltas(); | 224 return nativeGetHistogramDeltas(); |
| 223 } | 225 } |
| 224 | 226 |
| 227 // TODO(tbansal): http://crbug.com/618034 Remove this API. | |
| 225 @Override | 228 @Override |
| 226 public void enableNetworkQualityEstimator(Executor executor) { | 229 public void enableNetworkQualityEstimator(Executor executor) { |
| 227 enableNetworkQualityEstimatorForTesting(false, false, executor); | |
| 228 } | |
| 229 | |
| 230 @VisibleForTesting | |
| 231 @Override | |
| 232 void enableNetworkQualityEstimatorForTesting( | |
| 233 boolean useLocalHostRequests, boolean useSmallerResponses, Executor executor) { | |
| 234 if (mNetworkQualityEstimatorEnabled) { | 230 if (mNetworkQualityEstimatorEnabled) { |
| 235 throw new IllegalStateException("Network quality estimator already e nabled"); | 231 throw new IllegalStateException("Network quality estimator already e nabled"); |
| 236 } | 232 } |
| 237 mNetworkQualityEstimatorEnabled = true; | 233 mNetworkQualityEstimatorEnabled = true; |
| 238 if (executor == null) { | 234 if (executor == null) { |
| 239 throw new NullPointerException("Network quality estimator requires a n executor"); | 235 throw new NullPointerException("Network quality estimator requires a n executor"); |
| 240 } | 236 } |
| 241 mNetworkQualityExecutor = executor; | 237 mNetworkQualityExecutor = executor; |
| 242 synchronized (mLock) { | 238 synchronized (mLock) { |
| 243 checkHaveAdapter(); | 239 checkHaveAdapter(); |
| 244 nativeEnableNetworkQualityEstimator( | 240 nativeEnableNetworkQualityEstimator(mUrlRequestContextAdapter); |
| 241 } | |
| 242 } | |
| 243 | |
| 244 @VisibleForTesting | |
| 245 @Override | |
| 246 void configureNetworkQualityEstimatorForTesting( | |
| 247 boolean useLocalHostRequests, boolean useSmallerResponses) { | |
| 248 if (!mNetworkQualityEstimatorEnabled) { | |
|
bengr
2016/06/07 20:53:16
I was wondering if you even need this variable. E.
tbansal1
2016/06/07 21:37:17
Done.
| |
| 249 throw new IllegalStateException("Network quality estimator must be e nabled"); | |
| 250 } | |
| 251 synchronized (mLock) { | |
| 252 checkHaveAdapter(); | |
| 253 nativeConfigureNetworkQualityEstimatorForTesting( | |
| 245 mUrlRequestContextAdapter, useLocalHostRequests, useSmallerR esponses); | 254 mUrlRequestContextAdapter, useLocalHostRequests, useSmallerR esponses); |
| 246 } | 255 } |
| 247 } | 256 } |
| 248 | 257 |
| 249 @Override | 258 @Override |
| 250 public void addRttListener(NetworkQualityRttListener listener) { | 259 public void addRttListener(NetworkQualityRttListener listener) { |
| 251 if (!mNetworkQualityEstimatorEnabled) { | 260 if (!mNetworkQualityEstimatorEnabled) { |
| 252 throw new IllegalStateException("Network quality estimator must be e nabled"); | 261 throw new IllegalStateException("Network quality estimator must be e nabled"); |
| 253 } | 262 } |
| 254 synchronized (mNetworkQualityLock) { | 263 synchronized (mNetworkQualityLock) { |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 failException); | 480 failException); |
| 472 } | 481 } |
| 473 } | 482 } |
| 474 | 483 |
| 475 // Native methods are implemented in cronet_url_request_context_adapter.cc. | 484 // Native methods are implemented in cronet_url_request_context_adapter.cc. |
| 476 private static native long nativeCreateRequestContextConfig(String userAgent , | 485 private static native long nativeCreateRequestContextConfig(String userAgent , |
| 477 String storagePath, boolean quicEnabled, String quicUserAgentId, boo lean http2Enabled, | 486 String storagePath, boolean quicEnabled, String quicUserAgentId, boo lean http2Enabled, |
| 478 boolean sdchEnabled, String dataReductionProxyKey, | 487 boolean sdchEnabled, String dataReductionProxyKey, |
| 479 String dataReductionProxyPrimaryProxy, String dataReductionProxyFall backProxy, | 488 String dataReductionProxyPrimaryProxy, String dataReductionProxyFall backProxy, |
| 480 String dataReductionProxySecureProxyCheckUrl, boolean disableCache, int httpCacheMode, | 489 String dataReductionProxySecureProxyCheckUrl, boolean disableCache, int httpCacheMode, |
| 481 long httpCacheMaxSize, String experimentalOptions, long mockCertVeri fier); | 490 long httpCacheMaxSize, String experimentalOptions, long mockCertVeri fier, |
| 491 boolean enableNetworkQualityEstimator); | |
| 482 | 492 |
| 483 private static native void nativeAddQuicHint( | 493 private static native void nativeAddQuicHint( |
| 484 long urlRequestContextConfig, String host, int port, int alternatePo rt); | 494 long urlRequestContextConfig, String host, int port, int alternatePo rt); |
| 485 | 495 |
| 486 private static native void nativeAddPkp(long urlRequestContextConfig, String host, | 496 private static native void nativeAddPkp(long urlRequestContextConfig, String host, |
| 487 byte[][] hashes, boolean includeSubdomains, long expirationTime); | 497 byte[][] hashes, boolean includeSubdomains, long expirationTime); |
| 488 | 498 |
| 489 private static native long nativeCreateRequestContextAdapter(long urlRequest ContextConfig); | 499 private static native long nativeCreateRequestContextAdapter(long urlRequest ContextConfig); |
| 490 | 500 |
| 491 private static native int nativeSetMinLogLevel(int loggingLevel); | 501 private static native int nativeSetMinLogLevel(int loggingLevel); |
| 492 | 502 |
| 493 private static native byte[] nativeGetHistogramDeltas(); | 503 private static native byte[] nativeGetHistogramDeltas(); |
| 494 | 504 |
| 495 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 505 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 496 private native void nativeDestroy(long nativePtr); | 506 private native void nativeDestroy(long nativePtr); |
| 497 | 507 |
| 498 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 508 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 499 private native void nativeStartNetLogToFile(long nativePtr, | 509 private native void nativeStartNetLogToFile(long nativePtr, |
| 500 String fileName, boolean logAll); | 510 String fileName, boolean logAll); |
| 501 | 511 |
| 502 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 512 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 503 private native void nativeStopNetLog(long nativePtr); | 513 private native void nativeStopNetLog(long nativePtr); |
| 504 | 514 |
| 505 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 515 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 506 private native void nativeInitRequestContextOnMainThread(long nativePtr); | 516 private native void nativeInitRequestContextOnMainThread(long nativePtr); |
| 507 | 517 |
| 508 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 518 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 509 private native void nativeEnableNetworkQualityEstimator( | 519 private native void nativeConfigureNetworkQualityEstimatorForTesting( |
| 510 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp onses); | 520 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp onses); |
| 511 | 521 |
| 512 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 522 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 523 private native void nativeEnableNetworkQualityEstimator(long nativePtr); | |
| 524 | |
| 525 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | |
| 513 private native void nativeProvideRTTObservations(long nativePtr, boolean sho uld); | 526 private native void nativeProvideRTTObservations(long nativePtr, boolean sho uld); |
| 514 | 527 |
| 515 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 528 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 516 private native void nativeProvideThroughputObservations(long nativePtr, bool ean should); | 529 private native void nativeProvideThroughputObservations(long nativePtr, bool ean should); |
| 517 } | 530 } |
| OLD | NEW |