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.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(), builder.exp erimentalOptions(), | |
| 109 builder.mockCertVerifier()); | |
| 110 for (Builder.QuicHint quicHint : builder.quicHints()) { | |
| 111 nativeAddQuicHint(urlRequestContextConfig, quicHint.mHost, quicHint. mPort, | |
|
xunjieli
2015/12/01 17:30:38
I don't really like adding multiple JNI calls here
pauljensen
2015/12/02 03:50:01
I don't really like it either, but I'm not too wor
| |
| 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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 393 void postObservationTaskToNetworkQualityExecutor(Runnable task) { | 409 void postObservationTaskToNetworkQualityExecutor(Runnable task) { |
| 394 try { | 410 try { |
| 395 mNetworkQualityExecutor.execute(task); | 411 mNetworkQualityExecutor.execute(task); |
| 396 } catch (RejectedExecutionException failException) { | 412 } catch (RejectedExecutionException failException) { |
| 397 Log.e(CronetUrlRequestContext.LOG_TAG, "Exception posting task to ex ecutor", | 413 Log.e(CronetUrlRequestContext.LOG_TAG, "Exception posting task to ex ecutor", |
| 398 failException); | 414 failException); |
| 399 } | 415 } |
| 400 } | 416 } |
| 401 | 417 |
| 402 // Native methods are implemented in cronet_url_request_context_adapter.cc. | 418 // Native methods are implemented in cronet_url_request_context_adapter.cc. |
| 403 private static native long nativeCreateRequestContextAdapter(String config); | 419 private static native long nativeCreateRequestContextConfig(String userAgent , |
| 420 String storagePath, boolean quicEnabled, boolean http2Enabled, boole an sdchEnabled, | |
| 421 String dataReductionProxyKey, String dataReductionProxyPrimaryProxy, | |
| 422 String dataReductionProxyFallbackProxy, String dataReductionProxySec ureProxyCheckUrl, | |
| 423 boolean disableCache, int httpCacheMode, long httpCacheMaxSize, | |
| 424 String experimentalOptions, long mockCertVerifier); | |
| 425 | |
| 426 private static native void nativeAddQuicHint( | |
| 427 long urlRequestContextConfig, String host, int port, int alternatePo rt); | |
| 428 | |
| 429 private static native long nativeCreateRequestContextAdapter(long urlRequest ContextConfig); | |
|
xunjieli
2015/12/01 17:30:38
Not sure whether we should consolidate nativeCreat
pauljensen
2015/12/02 03:50:01
I split it for a few reasons:
1. The ChromiumURLRe
| |
| 404 | 430 |
| 405 private static native int nativeSetMinLogLevel(int loggingLevel); | 431 private static native int nativeSetMinLogLevel(int loggingLevel); |
| 406 | 432 |
| 407 private static native byte[] nativeGetHistogramDeltas(); | 433 private static native byte[] nativeGetHistogramDeltas(); |
| 408 | 434 |
| 409 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 435 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 410 private native void nativeDestroy(long nativePtr); | 436 private native void nativeDestroy(long nativePtr); |
| 411 | 437 |
| 412 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 438 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 413 private native void nativeStartNetLogToFile(long nativePtr, | 439 private native void nativeStartNetLogToFile(long nativePtr, |
| 414 String fileName, boolean logAll); | 440 String fileName, boolean logAll); |
| 415 | 441 |
| 416 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 442 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 417 private native void nativeStopNetLog(long nativePtr); | 443 private native void nativeStopNetLog(long nativePtr); |
| 418 | 444 |
| 419 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 445 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 420 private native void nativeInitRequestContextOnMainThread(long nativePtr); | 446 private native void nativeInitRequestContextOnMainThread(long nativePtr); |
| 421 | 447 |
| 422 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 448 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 423 private native void nativeEnableNetworkQualityEstimator( | 449 private native void nativeEnableNetworkQualityEstimator( |
| 424 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp onses); | 450 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp onses); |
| 425 | 451 |
| 426 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 452 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 427 private native void nativeProvideRTTObservations(long nativePtr, boolean sho uld); | 453 private native void nativeProvideRTTObservations(long nativePtr, boolean sho uld); |
| 428 | 454 |
| 429 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 455 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 430 private native void nativeProvideThroughputObservations(long nativePtr, bool ean should); | 456 private native void nativeProvideThroughputObservations(long nativePtr, bool ean should); |
| 431 } | 457 } |
| OLD | NEW |