Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(140)

Side by Side Diff: components/cronet/android/java/src/org/chromium/net/CronetUrlRequestContext.java

Issue 1429863008: [Cronet] Remove JSON serialization of CronetEngine.Builder (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix component_unittests Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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,
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
101 @Override 121 @Override
102 public UrlRequest createRequest(String url, UrlRequest.Callback callback, Ex ecutor executor) { 122 public UrlRequest createRequest(String url, UrlRequest.Callback callback, Ex ecutor executor) {
103 synchronized (mLock) { 123 synchronized (mLock) {
104 checkHaveAdapter(); 124 checkHaveAdapter();
105 return new CronetUrlRequest(this, mUrlRequestContextAdapter, url, 125 return new CronetUrlRequest(this, mUrlRequestContextAdapter, url,
106 UrlRequest.Builder.REQUEST_PRIORITY_MEDIUM, callback, execut or); 126 UrlRequest.Builder.REQUEST_PRIORITY_MEDIUM, callback, execut or);
107 } 127 }
108 } 128 }
109 129
110 @Override 130 @Override
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 void postObservationTaskToNetworkQualityExecutor(Runnable task) { 413 void postObservationTaskToNetworkQualityExecutor(Runnable task) {
394 try { 414 try {
395 mNetworkQualityExecutor.execute(task); 415 mNetworkQualityExecutor.execute(task);
396 } catch (RejectedExecutionException failException) { 416 } catch (RejectedExecutionException failException) {
397 Log.e(CronetUrlRequestContext.LOG_TAG, "Exception posting task to ex ecutor", 417 Log.e(CronetUrlRequestContext.LOG_TAG, "Exception posting task to ex ecutor",
398 failException); 418 failException);
399 } 419 }
400 } 420 }
401 421
402 // Native methods are implemented in cronet_url_request_context_adapter.cc. 422 // Native methods are implemented in cronet_url_request_context_adapter.cc.
403 private static native long nativeCreateRequestContextAdapter(String config); 423 private static native long nativeCreateRequestContextConfig(String userAgent ,
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);
404 437
405 private static native int nativeSetMinLogLevel(int loggingLevel); 438 private static native int nativeSetMinLogLevel(int loggingLevel);
406 439
407 private static native byte[] nativeGetHistogramDeltas(); 440 private static native byte[] nativeGetHistogramDeltas();
408 441
409 @NativeClassQualifiedName("CronetURLRequestContextAdapter") 442 @NativeClassQualifiedName("CronetURLRequestContextAdapter")
410 private native void nativeDestroy(long nativePtr); 443 private native void nativeDestroy(long nativePtr);
411 444
412 @NativeClassQualifiedName("CronetURLRequestContextAdapter") 445 @NativeClassQualifiedName("CronetURLRequestContextAdapter")
413 private native void nativeStartNetLogToFile(long nativePtr, 446 private native void nativeStartNetLogToFile(long nativePtr,
414 String fileName, boolean logAll); 447 String fileName, boolean logAll);
415 448
416 @NativeClassQualifiedName("CronetURLRequestContextAdapter") 449 @NativeClassQualifiedName("CronetURLRequestContextAdapter")
417 private native void nativeStopNetLog(long nativePtr); 450 private native void nativeStopNetLog(long nativePtr);
418 451
419 @NativeClassQualifiedName("CronetURLRequestContextAdapter") 452 @NativeClassQualifiedName("CronetURLRequestContextAdapter")
420 private native void nativeInitRequestContextOnMainThread(long nativePtr); 453 private native void nativeInitRequestContextOnMainThread(long nativePtr);
421 454
422 @NativeClassQualifiedName("CronetURLRequestContextAdapter") 455 @NativeClassQualifiedName("CronetURLRequestContextAdapter")
423 private native void nativeEnableNetworkQualityEstimator( 456 private native void nativeEnableNetworkQualityEstimator(
424 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp onses); 457 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp onses);
425 458
426 @NativeClassQualifiedName("CronetURLRequestContextAdapter") 459 @NativeClassQualifiedName("CronetURLRequestContextAdapter")
427 private native void nativeProvideRTTObservations(long nativePtr, boolean sho uld); 460 private native void nativeProvideRTTObservations(long nativePtr, boolean sho uld);
428 461
429 @NativeClassQualifiedName("CronetURLRequestContextAdapter") 462 @NativeClassQualifiedName("CronetURLRequestContextAdapter")
430 private native void nativeProvideThroughputObservations(long nativePtr, bool ean should); 463 private native void nativeProvideThroughputObservations(long nativePtr, bool ean should);
431 } 464 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698