| 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 new ObserverList<NetworkQualityRttListener>(); | 68 new ObserverList<NetworkQualityRttListener>(); |
| 69 | 69 |
| 70 @GuardedBy("mNetworkQualityLock") | 70 @GuardedBy("mNetworkQualityLock") |
| 71 private final ObserverList<NetworkQualityThroughputListener> mThroughputList
enerList = | 71 private final ObserverList<NetworkQualityThroughputListener> mThroughputList
enerList = |
| 72 new ObserverList<NetworkQualityThroughputListener>(); | 72 new ObserverList<NetworkQualityThroughputListener>(); |
| 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 /** |
| 79 * Synchronize access to mCertVerifierData. |
| 80 */ |
| 81 private ConditionVariable mWaitGetCertVerifierDataComplete = new ConditionVa
riable(); |
| 82 private static final long CERT_VERIFIER_DATA_TIMEOUT_MS = 30; |
| 83 |
| 84 /** Holds CertVerifier data. */ |
| 85 private String mCertVerifierData; |
| 86 |
| 78 @UsedByReflection("CronetEngine.java") | 87 @UsedByReflection("CronetEngine.java") |
| 79 public CronetUrlRequestContext(final CronetEngine.Builder builder) { | 88 public CronetUrlRequestContext(final CronetEngine.Builder builder) { |
| 80 CronetLibraryLoader.ensureInitialized(builder.getContext(), builder); | 89 CronetLibraryLoader.ensureInitialized(builder.getContext(), builder); |
| 81 nativeSetMinLogLevel(getLoggingLevel()); | 90 nativeSetMinLogLevel(getLoggingLevel()); |
| 82 synchronized (mLock) { | 91 synchronized (mLock) { |
| 83 mUrlRequestContextAdapter = nativeCreateRequestContextAdapter( | 92 mUrlRequestContextAdapter = nativeCreateRequestContextAdapter( |
| 84 createNativeUrlRequestContextConfig(builder.getContext(), bu
ilder)); | 93 createNativeUrlRequestContextConfig(builder.getContext(), bu
ilder)); |
| 85 if (mUrlRequestContextAdapter == 0) { | 94 if (mUrlRequestContextAdapter == 0) { |
| 86 throw new NullPointerException("Context Adapter creation failed.
"); | 95 throw new NullPointerException("Context Adapter creation failed.
"); |
| 87 } | 96 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 110 | 119 |
| 111 static long createNativeUrlRequestContextConfig( | 120 static long createNativeUrlRequestContextConfig( |
| 112 final Context context, CronetEngine.Builder builder) { | 121 final Context context, CronetEngine.Builder builder) { |
| 113 final long urlRequestContextConfig = nativeCreateRequestContextConfig( | 122 final long urlRequestContextConfig = nativeCreateRequestContextConfig( |
| 114 builder.getUserAgent(), builder.storagePath(), builder.quicEnabl
ed(), | 123 builder.getUserAgent(), builder.storagePath(), builder.quicEnabl
ed(), |
| 115 builder.getDefaultQuicUserAgentId(context), builder.http2Enabled
(), | 124 builder.getDefaultQuicUserAgentId(context), builder.http2Enabled
(), |
| 116 builder.sdchEnabled(), builder.dataReductionProxyKey(), | 125 builder.sdchEnabled(), builder.dataReductionProxyKey(), |
| 117 builder.dataReductionProxyPrimaryProxy(), builder.dataReductionP
roxyFallbackProxy(), | 126 builder.dataReductionProxyPrimaryProxy(), builder.dataReductionP
roxyFallbackProxy(), |
| 118 builder.dataReductionProxySecureProxyCheckUrl(), builder.cacheDi
sabled(), | 127 builder.dataReductionProxySecureProxyCheckUrl(), builder.cacheDi
sabled(), |
| 119 builder.httpCacheMode(), builder.httpCacheMaxSize(), builder.exp
erimentalOptions(), | 128 builder.httpCacheMode(), builder.httpCacheMaxSize(), builder.exp
erimentalOptions(), |
| 120 builder.mockCertVerifier()); | 129 builder.mockCertVerifier(), builder.certVerifierData()); |
| 121 for (Builder.QuicHint quicHint : builder.quicHints()) { | 130 for (Builder.QuicHint quicHint : builder.quicHints()) { |
| 122 nativeAddQuicHint(urlRequestContextConfig, quicHint.mHost, quicHint.
mPort, | 131 nativeAddQuicHint(urlRequestContextConfig, quicHint.mHost, quicHint.
mPort, |
| 123 quicHint.mAlternatePort); | 132 quicHint.mAlternatePort); |
| 124 } | 133 } |
| 125 for (Builder.Pkp pkp : builder.publicKeyPins()) { | 134 for (Builder.Pkp pkp : builder.publicKeyPins()) { |
| 126 nativeAddPkp(urlRequestContextConfig, pkp.mHost, pkp.mHashes, pkp.mI
ncludeSubdomains, | 135 nativeAddPkp(urlRequestContextConfig, pkp.mHost, pkp.mHashes, pkp.mI
ncludeSubdomains, |
| 127 pkp.mExpirationDate.getTime()); | 136 pkp.mExpirationDate.getTime()); |
| 128 } | 137 } |
| 129 return urlRequestContextConfig; | 138 return urlRequestContextConfig; |
| 130 } | 139 } |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 } | 215 } |
| 207 | 216 |
| 208 @Override | 217 @Override |
| 209 public void stopNetLog() { | 218 public void stopNetLog() { |
| 210 synchronized (mLock) { | 219 synchronized (mLock) { |
| 211 checkHaveAdapter(); | 220 checkHaveAdapter(); |
| 212 nativeStopNetLog(mUrlRequestContextAdapter); | 221 nativeStopNetLog(mUrlRequestContextAdapter); |
| 213 } | 222 } |
| 214 } | 223 } |
| 215 | 224 |
| 225 @Override |
| 226 public String getCertVerifierData() { |
| 227 synchronized (mLock) { |
| 228 checkHaveAdapter(); |
| 229 nativeGetCertVerifierData(mUrlRequestContextAdapter); |
| 230 } |
| 231 mWaitGetCertVerifierDataComplete.block(CERT_VERIFIER_DATA_TIMEOUT_MS); |
| 232 mWaitGetCertVerifierDataComplete.close(); |
| 233 return mCertVerifierData; |
| 234 } |
| 235 |
| 216 // This method is intentionally non-static to ensure Cronet native library | 236 // This method is intentionally non-static to ensure Cronet native library |
| 217 // is loaded by class constructor. | 237 // is loaded by class constructor. |
| 218 @Override | 238 @Override |
| 219 public byte[] getGlobalMetricsDeltas() { | 239 public byte[] getGlobalMetricsDeltas() { |
| 220 return nativeGetHistogramDeltas(); | 240 return nativeGetHistogramDeltas(); |
| 221 } | 241 } |
| 222 | 242 |
| 223 @Override | 243 @Override |
| 224 public void enableNetworkQualityEstimator(Executor executor) { | 244 public void enableNetworkQualityEstimator(Executor executor) { |
| 225 enableNetworkQualityEstimatorForTesting(false, false, executor); | 245 enableNetworkQualityEstimatorForTesting(false, false, executor); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 synchronized (mNetworkQualityLock) { | 457 synchronized (mNetworkQualityLock) { |
| 438 for (NetworkQualityThroughputListener listener : mThroughput
ListenerList) { | 458 for (NetworkQualityThroughputListener listener : mThroughput
ListenerList) { |
| 439 listener.onThroughputObservation(throughputKbps, whenMs,
source); | 459 listener.onThroughputObservation(throughputKbps, whenMs,
source); |
| 440 } | 460 } |
| 441 } | 461 } |
| 442 } | 462 } |
| 443 }; | 463 }; |
| 444 postObservationTaskToNetworkQualityExecutor(task); | 464 postObservationTaskToNetworkQualityExecutor(task); |
| 445 } | 465 } |
| 446 | 466 |
| 467 @SuppressWarnings("unused") |
| 468 @CalledByNative |
| 469 private void onGetCertVerifierData(String certVerifierData) { |
| 470 mCertVerifierData = certVerifierData; |
| 471 mWaitGetCertVerifierDataComplete.open(); |
| 472 } |
| 473 |
| 447 void reportFinished(final CronetUrlRequest request) { | 474 void reportFinished(final CronetUrlRequest request) { |
| 448 if (mNetworkQualityEstimatorEnabled) { | 475 if (mNetworkQualityEstimatorEnabled) { |
| 449 Runnable task = new Runnable() { | 476 Runnable task = new Runnable() { |
| 450 @Override | 477 @Override |
| 451 public void run() { | 478 public void run() { |
| 452 synchronized (mNetworkQualityLock) { | 479 synchronized (mNetworkQualityLock) { |
| 453 UrlRequestInfo requestInfo = request.getRequestInfo(); | 480 UrlRequestInfo requestInfo = request.getRequestInfo(); |
| 454 for (RequestFinishedListener listener : mFinishedListene
rList) { | 481 for (RequestFinishedListener listener : mFinishedListene
rList) { |
| 455 listener.onRequestFinished(requestInfo); | 482 listener.onRequestFinished(requestInfo); |
| 456 } | 483 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 469 failException); | 496 failException); |
| 470 } | 497 } |
| 471 } | 498 } |
| 472 | 499 |
| 473 // Native methods are implemented in cronet_url_request_context_adapter.cc. | 500 // Native methods are implemented in cronet_url_request_context_adapter.cc. |
| 474 private static native long nativeCreateRequestContextConfig(String userAgent
, | 501 private static native long nativeCreateRequestContextConfig(String userAgent
, |
| 475 String storagePath, boolean quicEnabled, String quicUserAgentId, boo
lean http2Enabled, | 502 String storagePath, boolean quicEnabled, String quicUserAgentId, boo
lean http2Enabled, |
| 476 boolean sdchEnabled, String dataReductionProxyKey, | 503 boolean sdchEnabled, String dataReductionProxyKey, |
| 477 String dataReductionProxyPrimaryProxy, String dataReductionProxyFall
backProxy, | 504 String dataReductionProxyPrimaryProxy, String dataReductionProxyFall
backProxy, |
| 478 String dataReductionProxySecureProxyCheckUrl, boolean disableCache,
int httpCacheMode, | 505 String dataReductionProxySecureProxyCheckUrl, boolean disableCache,
int httpCacheMode, |
| 479 long httpCacheMaxSize, String experimentalOptions, long mockCertVeri
fier); | 506 long httpCacheMaxSize, String experimentalOptions, long mockCertVeri
fier, |
| 507 String certVerifierData); |
| 480 | 508 |
| 481 private static native void nativeAddQuicHint( | 509 private static native void nativeAddQuicHint( |
| 482 long urlRequestContextConfig, String host, int port, int alternatePo
rt); | 510 long urlRequestContextConfig, String host, int port, int alternatePo
rt); |
| 483 | 511 |
| 484 private static native void nativeAddPkp(long urlRequestContextConfig, String
host, | 512 private static native void nativeAddPkp(long urlRequestContextConfig, String
host, |
| 485 byte[][] hashes, boolean includeSubdomains, long expirationTime); | 513 byte[][] hashes, boolean includeSubdomains, long expirationTime); |
| 486 | 514 |
| 487 private static native long nativeCreateRequestContextAdapter(long urlRequest
ContextConfig); | 515 private static native long nativeCreateRequestContextAdapter(long urlRequest
ContextConfig); |
| 488 | 516 |
| 489 private static native int nativeSetMinLogLevel(int loggingLevel); | 517 private static native int nativeSetMinLogLevel(int loggingLevel); |
| 490 | 518 |
| 491 private static native byte[] nativeGetHistogramDeltas(); | 519 private static native byte[] nativeGetHistogramDeltas(); |
| 492 | 520 |
| 493 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 521 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 494 private native void nativeDestroy(long nativePtr); | 522 private native void nativeDestroy(long nativePtr); |
| 495 | 523 |
| 496 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 524 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 497 private native void nativeStartNetLogToFile(long nativePtr, | 525 private native void nativeStartNetLogToFile(long nativePtr, |
| 498 String fileName, boolean logAll); | 526 String fileName, boolean logAll); |
| 499 | 527 |
| 500 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 528 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 501 private native void nativeStopNetLog(long nativePtr); | 529 private native void nativeStopNetLog(long nativePtr); |
| 502 | 530 |
| 503 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 531 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 532 private native void nativeGetCertVerifierData(long nativePtr); |
| 533 |
| 534 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 504 private native void nativeInitRequestContextOnMainThread(long nativePtr); | 535 private native void nativeInitRequestContextOnMainThread(long nativePtr); |
| 505 | 536 |
| 506 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 537 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 507 private native void nativeEnableNetworkQualityEstimator( | 538 private native void nativeEnableNetworkQualityEstimator( |
| 508 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp
onses); | 539 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp
onses); |
| 509 | 540 |
| 510 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 541 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 511 private native void nativeProvideRTTObservations(long nativePtr, boolean sho
uld); | 542 private native void nativeProvideRTTObservations(long nativePtr, boolean sho
uld); |
| 512 | 543 |
| 513 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 544 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 514 private native void nativeProvideThroughputObservations(long nativePtr, bool
ean should); | 545 private native void nativeProvideThroughputObservations(long nativePtr, bool
ean should); |
| 515 } | 546 } |
| OLD | NEW |