| 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 = nativeCreateRequestContextAdapter(builder.to
JSONString()); | 76 mUrlRequestContextAdapter = |
| 77 nativeCreateRequestContextAdapter(createNativeUrlRequestContextC
onfig(builder)); |
| 77 if (mUrlRequestContextAdapter == 0) { | 78 if (mUrlRequestContextAdapter == 0) { |
| 78 throw new NullPointerException("Context Adapter creation failed."); | 79 throw new NullPointerException("Context Adapter creation failed."); |
| 79 } | 80 } |
| 80 | 81 |
| 81 // Init native Chromium URLRequestContext on main UI thread. | 82 // Init native Chromium URLRequestContext on main UI thread. |
| 82 Runnable task = new Runnable() { | 83 Runnable task = new Runnable() { |
| 83 @Override | 84 @Override |
| 84 public void run() { | 85 public void run() { |
| 85 synchronized (mLock) { | 86 synchronized (mLock) { |
| 86 // mUrlRequestContextAdapter is guaranteed to exist until | 87 // mUrlRequestContextAdapter is guaranteed to exist until |
| 87 // initialization on main and network threads completes and | 88 // initialization on main and network threads completes and |
| 88 // initNetworkThread is called back on network thread. | 89 // initNetworkThread is called back on network thread. |
| 89 nativeInitRequestContextOnMainThread(mUrlRequestContextAdapt
er); | 90 nativeInitRequestContextOnMainThread(mUrlRequestContextAdapt
er); |
| 90 } | 91 } |
| 91 } | 92 } |
| 92 }; | 93 }; |
| 93 // Run task immediately or post it to the UI thread. | 94 // Run task immediately or post it to the UI thread. |
| 94 if (Looper.getMainLooper() == Looper.myLooper()) { | 95 if (Looper.getMainLooper() == Looper.myLooper()) { |
| 95 task.run(); | 96 task.run(); |
| 96 } else { | 97 } else { |
| 97 new Handler(Looper.getMainLooper()).post(task); | 98 new Handler(Looper.getMainLooper()).post(task); |
| 98 } | 99 } |
| 99 } | 100 } |
| 100 | 101 |
| 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(), |
| 109 builder.experimentalQuicConnectionOptions(), builder.mockCertVer
ifier()); |
| 110 for (Builder.QuicHint quicHint : builder.quicHints()) { |
| 111 nativeAddQuicHint(urlRequestContextConfig, quicHint.mHost, quicHint.
mPort, |
| 112 quicHint.mAlternatePort); |
| 113 } |
| 114 return urlRequestContextConfig; |
| 115 } |
| 116 |
| 101 @Override | 117 @Override |
| 102 public UrlRequest createRequest(String url, UrlRequest.Callback callback, Ex
ecutor executor) { | 118 public UrlRequest createRequest(String url, UrlRequest.Callback callback, Ex
ecutor executor) { |
| 103 synchronized (mLock) { | 119 synchronized (mLock) { |
| 104 checkHaveAdapter(); | 120 checkHaveAdapter(); |
| 105 return new CronetUrlRequest(this, mUrlRequestContextAdapter, url, | 121 return new CronetUrlRequest(this, mUrlRequestContextAdapter, url, |
| 106 UrlRequest.Builder.REQUEST_PRIORITY_MEDIUM, callback, execut
or); | 122 UrlRequest.Builder.REQUEST_PRIORITY_MEDIUM, callback, execut
or); |
| 107 } | 123 } |
| 108 } | 124 } |
| 109 | 125 |
| 110 @Override | 126 @Override |
| (...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 void postObservationTaskToNetworkQualityExecutor(Runnable task) { | 402 void postObservationTaskToNetworkQualityExecutor(Runnable task) { |
| 387 try { | 403 try { |
| 388 mNetworkQualityExecutor.execute(task); | 404 mNetworkQualityExecutor.execute(task); |
| 389 } catch (RejectedExecutionException failException) { | 405 } catch (RejectedExecutionException failException) { |
| 390 Log.e(CronetUrlRequestContext.LOG_TAG, "Exception posting task to ex
ecutor", | 406 Log.e(CronetUrlRequestContext.LOG_TAG, "Exception posting task to ex
ecutor", |
| 391 failException); | 407 failException); |
| 392 } | 408 } |
| 393 } | 409 } |
| 394 | 410 |
| 395 // Native methods are implemented in cronet_url_request_context_adapter.cc. | 411 // Native methods are implemented in cronet_url_request_context_adapter.cc. |
| 396 private static native long nativeCreateRequestContextAdapter(String config); | 412 private static native long nativeCreateRequestContextConfig(String userAgent
, |
| 413 String storagePath, boolean quicEnabled, boolean http2Enabled, boole
an sdchEnabled, |
| 414 String dataReductionProxyKey, String dataReductionProxyPrimaryProxy, |
| 415 String dataReductionProxyFallbackProxy, String dataReductionProxySec
ureProxyCheckUrl, |
| 416 boolean disableCache, int httpCacheMode, long httpCacheMaxSize, |
| 417 String experimentalQuicConnectionOptions, long mockCertVerifier); |
| 418 |
| 419 private static native void nativeAddQuicHint( |
| 420 long urlRequestContextConfig, String host, int port, int alternatePo
rt); |
| 421 |
| 422 private static native long nativeCreateRequestContextAdapter(long urlRequest
ContextConfig); |
| 397 | 423 |
| 398 private static native int nativeSetMinLogLevel(int loggingLevel); | 424 private static native int nativeSetMinLogLevel(int loggingLevel); |
| 399 | 425 |
| 400 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 426 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 401 private native void nativeDestroy(long nativePtr); | 427 private native void nativeDestroy(long nativePtr); |
| 402 | 428 |
| 403 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 429 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 404 private native void nativeStartNetLogToFile(long nativePtr, | 430 private native void nativeStartNetLogToFile(long nativePtr, |
| 405 String fileName, boolean logAll); | 431 String fileName, boolean logAll); |
| 406 | 432 |
| 407 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 433 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 408 private native void nativeStopNetLog(long nativePtr); | 434 private native void nativeStopNetLog(long nativePtr); |
| 409 | 435 |
| 410 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 436 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 411 private native void nativeInitRequestContextOnMainThread(long nativePtr); | 437 private native void nativeInitRequestContextOnMainThread(long nativePtr); |
| 412 | 438 |
| 413 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 439 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 414 private native void nativeEnableNetworkQualityEstimator( | 440 private native void nativeEnableNetworkQualityEstimator( |
| 415 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp
onses); | 441 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp
onses); |
| 416 | 442 |
| 417 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 443 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 418 private native void nativeProvideRTTObservations(long nativePtr, boolean sho
uld); | 444 private native void nativeProvideRTTObservations(long nativePtr, boolean sho
uld); |
| 419 | 445 |
| 420 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 446 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 421 private native void nativeProvideThroughputObservations(long nativePtr, bool
ean should); | 447 private native void nativeProvideThroughputObservations(long nativePtr, bool
ean should); |
| 422 } | 448 } |
| OLD | NEW |