| 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.os.Build; | 7 import android.os.Build; |
| 8 import android.os.ConditionVariable; | 8 import android.os.ConditionVariable; |
| 9 import android.os.Handler; | 9 import android.os.Handler; |
| 10 import android.os.Looper; | 10 import android.os.Looper; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 new ObserverList<NetworkQualityRttListener>(); | 66 new ObserverList<NetworkQualityRttListener>(); |
| 67 | 67 |
| 68 @GuardedBy("mNetworkQualityLock") | 68 @GuardedBy("mNetworkQualityLock") |
| 69 private final ObserverList<NetworkQualityThroughputListener> mThroughputList
enerList = | 69 private final ObserverList<NetworkQualityThroughputListener> mThroughputList
enerList = |
| 70 new ObserverList<NetworkQualityThroughputListener>(); | 70 new ObserverList<NetworkQualityThroughputListener>(); |
| 71 | 71 |
| 72 @UsedByReflection("CronetEngine.java") | 72 @UsedByReflection("CronetEngine.java") |
| 73 public CronetUrlRequestContext(CronetEngine.Builder builder) { | 73 public CronetUrlRequestContext(CronetEngine.Builder builder) { |
| 74 CronetLibraryLoader.ensureInitialized(builder.getContext(), builder); | 74 CronetLibraryLoader.ensureInitialized(builder.getContext(), builder); |
| 75 nativeSetMinLogLevel(getLoggingLevel()); | 75 nativeSetMinLogLevel(getLoggingLevel()); |
| 76 mUrlRequestContextAdapter = | 76 mUrlRequestContextAdapter = nativeCreateRequestContextAdapter(builder.to
JSONString()); |
| 77 nativeCreateRequestContextAdapter(createNativeUrlRequestContextC
onfig(builder)); | |
| 78 if (mUrlRequestContextAdapter == 0) { | 77 if (mUrlRequestContextAdapter == 0) { |
| 79 throw new NullPointerException("Context Adapter creation failed."); | 78 throw new NullPointerException("Context Adapter creation failed."); |
| 80 } | 79 } |
| 81 | 80 |
| 82 // Init native Chromium URLRequestContext on main UI thread. | 81 // Init native Chromium URLRequestContext on main UI thread. |
| 83 Runnable task = new Runnable() { | 82 Runnable task = new Runnable() { |
| 84 @Override | 83 @Override |
| 85 public void run() { | 84 public void run() { |
| 86 synchronized (mLock) { | 85 synchronized (mLock) { |
| 87 // mUrlRequestContextAdapter is guaranteed to exist until | 86 // mUrlRequestContextAdapter is guaranteed to exist until |
| 88 // initialization on main and network threads completes and | 87 // initialization on main and network threads completes and |
| 89 // initNetworkThread is called back on network thread. | 88 // initNetworkThread is called back on network thread. |
| 90 nativeInitRequestContextOnMainThread(mUrlRequestContextAdapt
er); | 89 nativeInitRequestContextOnMainThread(mUrlRequestContextAdapt
er); |
| 91 } | 90 } |
| 92 } | 91 } |
| 93 }; | 92 }; |
| 94 // Run task immediately or post it to the UI thread. | 93 // Run task immediately or post it to the UI thread. |
| 95 if (Looper.getMainLooper() == Looper.myLooper()) { | 94 if (Looper.getMainLooper() == Looper.myLooper()) { |
| 96 task.run(); | 95 task.run(); |
| 97 } else { | 96 } else { |
| 98 new Handler(Looper.getMainLooper()).post(task); | 97 new Handler(Looper.getMainLooper()).post(task); |
| 99 } | 98 } |
| 100 } | 99 } |
| 101 | 100 |
| 102 static long createNativeUrlRequestContextConfig(CronetEngine.Builder builder
) { | |
| 103 final long urlRequestContextConfig = nativeCreateRequestContextConfig( | |
| 104 builder.getUserAgent(), builder.storagePath(), builder.quicEnabl
ed(), | |
| 105 builder.http2Enabled(), builder.sdchEnabled(), builder.dataReduc
tionProxyKey(), | |
| 106 builder.dataReductionProxyPrimaryProxy(), builder.dataReductionP
roxyFallbackProxy(), | |
| 107 builder.dataReductionProxySecureProxyCheckUrl(), builder.cacheDi
sabled(), | |
| 108 builder.httpCacheMode(), builder.httpCacheMaxSize(), builder.exp
erimentalOptions(), | |
| 109 builder.mockCertVerifier()); | |
| 110 for (Builder.QuicHint quicHint : builder.quicHints()) { | |
| 111 nativeAddQuicHint(urlRequestContextConfig, quicHint.mHost, quicHint.
mPort, | |
| 112 quicHint.mAlternatePort); | |
| 113 } | |
| 114 for (Builder.Pkp pkp : builder.publicKeyPins()) { | |
| 115 nativeAddPkp(urlRequestContextConfig, pkp.mHost, pkp.mHashes, pkp.mI
ncludeSubdomains, | |
| 116 pkp.mExpirationDate.getTime()); | |
| 117 } | |
| 118 return urlRequestContextConfig; | |
| 119 } | |
| 120 | |
| 121 @Override | 101 @Override |
| 122 public UrlRequest createRequest(String url, UrlRequest.Callback callback, Ex
ecutor executor) { | 102 public UrlRequest createRequest(String url, UrlRequest.Callback callback, Ex
ecutor executor) { |
| 123 synchronized (mLock) { | 103 synchronized (mLock) { |
| 124 checkHaveAdapter(); | 104 checkHaveAdapter(); |
| 125 return new CronetUrlRequest(this, mUrlRequestContextAdapter, url, | 105 return new CronetUrlRequest(this, mUrlRequestContextAdapter, url, |
| 126 UrlRequest.Builder.REQUEST_PRIORITY_MEDIUM, callback, execut
or); | 106 UrlRequest.Builder.REQUEST_PRIORITY_MEDIUM, callback, execut
or); |
| 127 } | 107 } |
| 128 } | 108 } |
| 129 | 109 |
| 130 @Override | 110 @Override |
| (...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 void postObservationTaskToNetworkQualityExecutor(Runnable task) { | 393 void postObservationTaskToNetworkQualityExecutor(Runnable task) { |
| 414 try { | 394 try { |
| 415 mNetworkQualityExecutor.execute(task); | 395 mNetworkQualityExecutor.execute(task); |
| 416 } catch (RejectedExecutionException failException) { | 396 } catch (RejectedExecutionException failException) { |
| 417 Log.e(CronetUrlRequestContext.LOG_TAG, "Exception posting task to ex
ecutor", | 397 Log.e(CronetUrlRequestContext.LOG_TAG, "Exception posting task to ex
ecutor", |
| 418 failException); | 398 failException); |
| 419 } | 399 } |
| 420 } | 400 } |
| 421 | 401 |
| 422 // Native methods are implemented in cronet_url_request_context_adapter.cc. | 402 // Native methods are implemented in cronet_url_request_context_adapter.cc. |
| 423 private static native long nativeCreateRequestContextConfig(String userAgent
, | 403 private static native long nativeCreateRequestContextAdapter(String config); |
| 424 String storagePath, boolean quicEnabled, boolean http2Enabled, boole
an sdchEnabled, | |
| 425 String dataReductionProxyKey, String dataReductionProxyPrimaryProxy, | |
| 426 String dataReductionProxyFallbackProxy, String dataReductionProxySec
ureProxyCheckUrl, | |
| 427 boolean disableCache, int httpCacheMode, long httpCacheMaxSize, | |
| 428 String experimentalOptions, long mockCertVerifier); | |
| 429 | |
| 430 private static native void nativeAddQuicHint( | |
| 431 long urlRequestContextConfig, String host, int port, int alternatePo
rt); | |
| 432 | |
| 433 private static native void nativeAddPkp(long urlRequestContextConfig, String
host, | |
| 434 byte[][] hashes, boolean includeSubdomains, long expirationTime); | |
| 435 | |
| 436 private static native long nativeCreateRequestContextAdapter(long urlRequest
ContextConfig); | |
| 437 | 404 |
| 438 private static native int nativeSetMinLogLevel(int loggingLevel); | 405 private static native int nativeSetMinLogLevel(int loggingLevel); |
| 439 | 406 |
| 440 private static native byte[] nativeGetHistogramDeltas(); | 407 private static native byte[] nativeGetHistogramDeltas(); |
| 441 | 408 |
| 442 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 409 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 443 private native void nativeDestroy(long nativePtr); | 410 private native void nativeDestroy(long nativePtr); |
| 444 | 411 |
| 445 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 412 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 446 private native void nativeStartNetLogToFile(long nativePtr, | 413 private native void nativeStartNetLogToFile(long nativePtr, |
| 447 String fileName, boolean logAll); | 414 String fileName, boolean logAll); |
| 448 | 415 |
| 449 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 416 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 450 private native void nativeStopNetLog(long nativePtr); | 417 private native void nativeStopNetLog(long nativePtr); |
| 451 | 418 |
| 452 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 419 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 453 private native void nativeInitRequestContextOnMainThread(long nativePtr); | 420 private native void nativeInitRequestContextOnMainThread(long nativePtr); |
| 454 | 421 |
| 455 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 422 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 456 private native void nativeEnableNetworkQualityEstimator( | 423 private native void nativeEnableNetworkQualityEstimator( |
| 457 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp
onses); | 424 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp
onses); |
| 458 | 425 |
| 459 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 426 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 460 private native void nativeProvideRTTObservations(long nativePtr, boolean sho
uld); | 427 private native void nativeProvideRTTObservations(long nativePtr, boolean sho
uld); |
| 461 | 428 |
| 462 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 429 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 463 private native void nativeProvideThroughputObservations(long nativePtr, bool
ean should); | 430 private native void nativeProvideThroughputObservations(long nativePtr, bool
ean should); |
| 464 } | 431 } |
| OLD | NEW |