| 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.impl; | 5 package org.chromium.net.impl; |
| 6 | 6 |
| 7 import android.os.ConditionVariable; | 7 import android.os.ConditionVariable; |
| 8 import android.os.Handler; | |
| 9 import android.os.Looper; | |
| 10 import android.os.Process; | 8 import android.os.Process; |
| 11 | 9 |
| 12 import org.chromium.base.Log; | 10 import org.chromium.base.Log; |
| 13 import org.chromium.base.ObserverList; | 11 import org.chromium.base.ObserverList; |
| 14 import org.chromium.base.VisibleForTesting; | 12 import org.chromium.base.VisibleForTesting; |
| 15 import org.chromium.base.annotations.CalledByNative; | 13 import org.chromium.base.annotations.CalledByNative; |
| 16 import org.chromium.base.annotations.JNINamespace; | 14 import org.chromium.base.annotations.JNINamespace; |
| 17 import org.chromium.base.annotations.NativeClassQualifiedName; | 15 import org.chromium.base.annotations.NativeClassQualifiedName; |
| 18 import org.chromium.base.annotations.UsedByReflection; | 16 import org.chromium.base.annotations.UsedByReflection; |
| 19 import org.chromium.net.BidirectionalStream; | 17 import org.chromium.net.BidirectionalStream; |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 nativeSetMinLogLevel(getLoggingLevel()); | 152 nativeSetMinLogLevel(getLoggingLevel()); |
| 155 synchronized (mLock) { | 153 synchronized (mLock) { |
| 156 mUrlRequestContextAdapter = | 154 mUrlRequestContextAdapter = |
| 157 nativeCreateRequestContextAdapter(createNativeUrlRequestCont
extConfig(builder)); | 155 nativeCreateRequestContextAdapter(createNativeUrlRequestCont
extConfig(builder)); |
| 158 if (mUrlRequestContextAdapter == 0) { | 156 if (mUrlRequestContextAdapter == 0) { |
| 159 throw new NullPointerException("Context Adapter creation failed.
"); | 157 throw new NullPointerException("Context Adapter creation failed.
"); |
| 160 } | 158 } |
| 161 mNetworkQualityEstimatorEnabled = builder.networkQualityEstimatorEna
bled(); | 159 mNetworkQualityEstimatorEnabled = builder.networkQualityEstimatorEna
bled(); |
| 162 } | 160 } |
| 163 | 161 |
| 164 // Init native Chromium URLRequestContext on main UI thread. | 162 // Init native Chromium URLRequestContext on init thread. |
| 165 Runnable task = new Runnable() { | 163 CronetLibraryLoader.postToInitThread(new Runnable() { |
| 166 @Override | 164 @Override |
| 167 public void run() { | 165 public void run() { |
| 168 CronetLibraryLoader.ensureInitializedOnMainThread(builder.getCon
text()); | 166 CronetLibraryLoader.ensureInitializedOnInitThread(builder.getCon
text()); |
| 169 synchronized (mLock) { | 167 synchronized (mLock) { |
| 170 // mUrlRequestContextAdapter is guaranteed to exist until | 168 // mUrlRequestContextAdapter is guaranteed to exist until |
| 171 // initialization on main and network threads completes and | 169 // initialization on init and network threads completes and |
| 172 // initNetworkThread is called back on network thread. | 170 // initNetworkThread is called back on network thread. |
| 173 nativeInitRequestContextOnMainThread(mUrlRequestContextAdapt
er); | 171 nativeInitRequestContextOnInitThread(mUrlRequestContextAdapt
er); |
| 174 } | 172 } |
| 175 } | 173 } |
| 176 }; | 174 }); |
| 177 // Run task immediately or post it to the UI thread. | |
| 178 if (Looper.getMainLooper() == Looper.myLooper()) { | |
| 179 task.run(); | |
| 180 } else { | |
| 181 new Handler(Looper.getMainLooper()).post(task); | |
| 182 } | |
| 183 } | 175 } |
| 184 | 176 |
| 185 @VisibleForTesting | 177 @VisibleForTesting |
| 186 public static long createNativeUrlRequestContextConfig(CronetEngineBuilderIm
pl builder) { | 178 public static long createNativeUrlRequestContextConfig(CronetEngineBuilderIm
pl builder) { |
| 187 final long urlRequestContextConfig = nativeCreateRequestContextConfig( | 179 final long urlRequestContextConfig = nativeCreateRequestContextConfig( |
| 188 builder.getUserAgent(), builder.storagePath(), builder.quicEnabl
ed(), | 180 builder.getUserAgent(), builder.storagePath(), builder.quicEnabl
ed(), |
| 189 builder.getDefaultQuicUserAgentId(), builder.http2Enabled(), bui
lder.sdchEnabled(), | 181 builder.getDefaultQuicUserAgentId(), builder.http2Enabled(), bui
lder.sdchEnabled(), |
| 190 builder.dataReductionProxyKey(), builder.dataReductionProxyPrima
ryProxy(), | 182 builder.dataReductionProxyKey(), builder.dataReductionProxyPrima
ryProxy(), |
| 191 builder.dataReductionProxyFallbackProxy(), | 183 builder.dataReductionProxyFallbackProxy(), |
| 192 builder.dataReductionProxySecureProxyCheckUrl(), builder.cacheDi
sabled(), | 184 builder.dataReductionProxySecureProxyCheckUrl(), builder.cacheDi
sabled(), |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 checkHaveAdapter(); | 238 checkHaveAdapter(); |
| 247 if (mActiveRequestCount.get() != 0) { | 239 if (mActiveRequestCount.get() != 0) { |
| 248 throw new IllegalStateException("Cannot shutdown with active req
uests."); | 240 throw new IllegalStateException("Cannot shutdown with active req
uests."); |
| 249 } | 241 } |
| 250 // Destroying adapter stops the network thread, so it cannot be | 242 // Destroying adapter stops the network thread, so it cannot be |
| 251 // called on network thread. | 243 // called on network thread. |
| 252 if (Thread.currentThread() == mNetworkThread) { | 244 if (Thread.currentThread() == mNetworkThread) { |
| 253 throw new IllegalThreadStateException("Cannot shutdown from netw
ork thread."); | 245 throw new IllegalThreadStateException("Cannot shutdown from netw
ork thread."); |
| 254 } | 246 } |
| 255 } | 247 } |
| 256 // Wait for init to complete on main and network thread (without lock, | 248 // Wait for init to complete on init and network thread (without lock, |
| 257 // so other thread could access it). | 249 // so other thread could access it). |
| 258 mInitCompleted.block(); | 250 mInitCompleted.block(); |
| 259 | 251 |
| 260 // If not logging, this is a no-op. | 252 // If not logging, this is a no-op. |
| 261 stopNetLog(); | 253 stopNetLog(); |
| 262 | 254 |
| 263 synchronized (mLock) { | 255 synchronized (mLock) { |
| 264 // It is possible that adapter is already destroyed on another threa
d. | 256 // It is possible that adapter is already destroyed on another threa
d. |
| 265 if (!haveRequestContextAdapter()) { | 257 if (!haveRequestContextAdapter()) { |
| 266 return; | 258 return; |
| (...skipping 442 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 private native void nativeStartNetLogToDisk( | 701 private native void nativeStartNetLogToDisk( |
| 710 long nativePtr, String dirPath, boolean logAll, int maxSize); | 702 long nativePtr, String dirPath, boolean logAll, int maxSize); |
| 711 | 703 |
| 712 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 704 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 713 private native void nativeStopNetLog(long nativePtr); | 705 private native void nativeStopNetLog(long nativePtr); |
| 714 | 706 |
| 715 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 707 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 716 private native void nativeGetCertVerifierData(long nativePtr); | 708 private native void nativeGetCertVerifierData(long nativePtr); |
| 717 | 709 |
| 718 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 710 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 719 private native void nativeInitRequestContextOnMainThread(long nativePtr); | 711 private native void nativeInitRequestContextOnInitThread(long nativePtr); |
| 720 | 712 |
| 721 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 713 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 722 private native void nativeConfigureNetworkQualityEstimatorForTesting(long na
tivePtr, | 714 private native void nativeConfigureNetworkQualityEstimatorForTesting(long na
tivePtr, |
| 723 boolean useLocalHostRequests, boolean useSmallerResponses, boolean d
isableOfflineCheck); | 715 boolean useLocalHostRequests, boolean useSmallerResponses, boolean d
isableOfflineCheck); |
| 724 | 716 |
| 725 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 717 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 726 private native void nativeProvideRTTObservations(long nativePtr, boolean sho
uld); | 718 private native void nativeProvideRTTObservations(long nativePtr, boolean sho
uld); |
| 727 | 719 |
| 728 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 720 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 729 private native void nativeProvideThroughputObservations(long nativePtr, bool
ean should); | 721 private native void nativeProvideThroughputObservations(long nativePtr, bool
ean should); |
| 730 | 722 |
| 731 public boolean isNetworkThread(Thread thread) { | 723 public boolean isNetworkThread(Thread thread) { |
| 732 return thread == mNetworkThread; | 724 return thread == mNetworkThread; |
| 733 } | 725 } |
| 734 } | 726 } |
| OLD | NEW |