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 17 matching lines...) Expand all Loading... | |
| 28 * CronetEngine using Chromium HTTP stack implementation. | 28 * CronetEngine using Chromium HTTP stack implementation. |
| 29 */ | 29 */ |
| 30 @JNINamespace("cronet") | 30 @JNINamespace("cronet") |
| 31 @UsedByReflection("CronetEngine.java") | 31 @UsedByReflection("CronetEngine.java") |
| 32 class CronetUrlRequestContext extends CronetEngine { | 32 class CronetUrlRequestContext extends CronetEngine { |
| 33 private static final int LOG_NONE = 3; // LOG(FATAL), no VLOG. | 33 private static final int LOG_NONE = 3; // LOG(FATAL), no VLOG. |
| 34 private static final int LOG_DEBUG = -1; // LOG(FATAL...INFO), VLOG(1) | 34 private static final int LOG_DEBUG = -1; // LOG(FATAL...INFO), VLOG(1) |
| 35 private static final int LOG_VERBOSE = -2; // LOG(FATAL...INFO), VLOG(2) | 35 private static final int LOG_VERBOSE = -2; // LOG(FATAL...INFO), VLOG(2) |
| 36 static final String LOG_TAG = "ChromiumNetwork"; | 36 static final String LOG_TAG = "ChromiumNetwork"; |
| 37 | 37 |
| 38 // For Testing. | |
| 39 private static long sNativeMockCertVerifier = 0; | |
| 40 | |
| 38 /** | 41 /** |
| 39 * Synchronize access to mUrlRequestContextAdapter and shutdown routine. | 42 * Synchronize access to mUrlRequestContextAdapter and shutdown routine. |
| 40 */ | 43 */ |
| 41 private final Object mLock = new Object(); | 44 private final Object mLock = new Object(); |
| 42 private final ConditionVariable mInitCompleted = new ConditionVariable(false ); | 45 private final ConditionVariable mInitCompleted = new ConditionVariable(false ); |
| 43 private final AtomicInteger mActiveRequestCount = new AtomicInteger(0); | 46 private final AtomicInteger mActiveRequestCount = new AtomicInteger(0); |
| 44 | 47 |
| 45 private long mUrlRequestContextAdapter = 0; | 48 private long mUrlRequestContextAdapter = 0; |
| 46 private Thread mNetworkThread; | 49 private Thread mNetworkThread; |
| 47 | 50 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 63 | 66 |
| 64 @UsedByReflection("CronetEngine.java") | 67 @UsedByReflection("CronetEngine.java") |
| 65 public CronetUrlRequestContext(CronetEngine.Builder builder) { | 68 public CronetUrlRequestContext(CronetEngine.Builder builder) { |
| 66 CronetLibraryLoader.ensureInitialized(builder.getContext(), builder); | 69 CronetLibraryLoader.ensureInitialized(builder.getContext(), builder); |
| 67 nativeSetMinLogLevel(getLoggingLevel()); | 70 nativeSetMinLogLevel(getLoggingLevel()); |
| 68 mUrlRequestContextAdapter = nativeCreateRequestContextAdapter(builder.to String()); | 71 mUrlRequestContextAdapter = nativeCreateRequestContextAdapter(builder.to String()); |
| 69 if (mUrlRequestContextAdapter == 0) { | 72 if (mUrlRequestContextAdapter == 0) { |
| 70 throw new NullPointerException("Context Adapter creation failed."); | 73 throw new NullPointerException("Context Adapter creation failed."); |
| 71 } | 74 } |
| 72 | 75 |
| 76 if (sNativeMockCertVerifier != 0) { | |
| 77 nativeSetMockCertVerifierForTesting(mUrlRequestContextAdapter, sNati veMockCertVerifier); | |
|
mef
2015/10/12 18:27:13
Would it make sense to have a 'SetMockCertVerifier
xunjieli
2015/10/13 01:58:02
Great idea! Didn't realize we can serialize a nati
| |
| 78 } | |
| 79 | |
| 73 // Init native Chromium URLRequestContext on main UI thread. | 80 // Init native Chromium URLRequestContext on main UI thread. |
| 74 Runnable task = new Runnable() { | 81 Runnable task = new Runnable() { |
| 75 @Override | 82 @Override |
| 76 public void run() { | 83 public void run() { |
| 77 synchronized (mLock) { | 84 synchronized (mLock) { |
| 78 // mUrlRequestContextAdapter is guaranteed to exist until | 85 // mUrlRequestContextAdapter is guaranteed to exist until |
| 79 // initialization on main and network threads completes and | 86 // initialization on main and network threads completes and |
| 80 // initNetworkThread is called back on network thread. | 87 // initNetworkThread is called back on network thread. |
| 81 nativeInitRequestContextOnMainThread(mUrlRequestContextAdapt er); | 88 nativeInitRequestContextOnMainThread(mUrlRequestContextAdapt er); |
| 82 } | 89 } |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 350 | 357 |
| 351 void postObservationTaskToNetworkQualityExecutor(Runnable task) { | 358 void postObservationTaskToNetworkQualityExecutor(Runnable task) { |
| 352 try { | 359 try { |
| 353 mNetworkQualityExecutor.execute(task); | 360 mNetworkQualityExecutor.execute(task); |
| 354 } catch (RejectedExecutionException failException) { | 361 } catch (RejectedExecutionException failException) { |
| 355 Log.e(CronetUrlRequestContext.LOG_TAG, "Exception posting task to ex ecutor", | 362 Log.e(CronetUrlRequestContext.LOG_TAG, "Exception posting task to ex ecutor", |
| 356 failException); | 363 failException); |
| 357 } | 364 } |
| 358 } | 365 } |
| 359 | 366 |
| 367 /** | |
| 368 * Sets a mock cert verifier for testing. | |
| 369 * @param nativeMockCertVerifier a pointer to the native net::MockCertVerifi er. | |
| 370 */ | |
| 371 static void setMockCertVerifierForTesting(long nativeMockCertVerifier) { | |
| 372 sNativeMockCertVerifier = nativeMockCertVerifier; | |
| 373 } | |
| 374 | |
| 360 // Native methods are implemented in cronet_url_request_context.cc. | 375 // Native methods are implemented in cronet_url_request_context.cc. |
| 361 private static native long nativeCreateRequestContextAdapter(String config); | 376 private static native long nativeCreateRequestContextAdapter(String config); |
| 362 | 377 |
| 363 private static native int nativeSetMinLogLevel(int loggingLevel); | 378 private static native int nativeSetMinLogLevel(int loggingLevel); |
| 364 | 379 |
| 365 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 380 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 381 private static native void nativeSetMockCertVerifierForTesting( | |
| 382 long nativePtr, long mockCertVerifier); | |
| 383 | |
| 384 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | |
| 366 private native void nativeDestroy(long nativePtr); | 385 private native void nativeDestroy(long nativePtr); |
| 367 | 386 |
| 368 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 387 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 369 private native void nativeStartNetLogToFile(long nativePtr, | 388 private native void nativeStartNetLogToFile(long nativePtr, |
| 370 String fileName, boolean logAll); | 389 String fileName, boolean logAll); |
| 371 | 390 |
| 372 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 391 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 373 private native void nativeStopNetLog(long nativePtr); | 392 private native void nativeStopNetLog(long nativePtr); |
| 374 | 393 |
| 375 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 394 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 376 private native void nativeInitRequestContextOnMainThread(long nativePtr); | 395 private native void nativeInitRequestContextOnMainThread(long nativePtr); |
| 377 | 396 |
| 378 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 397 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 379 private native void nativeEnableNetworkQualityEstimator( | 398 private native void nativeEnableNetworkQualityEstimator( |
| 380 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp onses); | 399 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp onses); |
| 381 | 400 |
| 382 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 401 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 383 private native void nativeProvideRTTObservations(long nativePtr, boolean sho uld); | 402 private native void nativeProvideRTTObservations(long nativePtr, boolean sho uld); |
| 384 | 403 |
| 385 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 404 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 386 private native void nativeProvideThroughputObservations(long nativePtr, bool ean should); | 405 private native void nativeProvideThroughputObservations(long nativePtr, bool ean should); |
| 387 } | 406 } |
| OLD | NEW |