| 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; | 8 import android.os.Handler; |
| 9 import android.os.Looper; | 9 import android.os.Looper; |
| 10 import android.os.Process; | 10 import android.os.Process; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 private String mCertVerifierData; | 141 private String mCertVerifierData; |
| 142 | 142 |
| 143 private ConditionVariable mStopNetLogCompleted; | 143 private ConditionVariable mStopNetLogCompleted; |
| 144 | 144 |
| 145 /** | 145 /** |
| 146 * True if a NetLog observer is active. | 146 * True if a NetLog observer is active. |
| 147 */ | 147 */ |
| 148 @GuardedBy("mLock") | 148 @GuardedBy("mLock") |
| 149 private boolean mIsLogging; | 149 private boolean mIsLogging; |
| 150 | 150 |
| 151 /** | |
| 152 * True if a NetLog observer that writes to disk with a bounded amount of sp
ace has been | |
| 153 * activated by calling StartNetLogToDisk(). | |
| 154 */ | |
| 155 @GuardedBy("mLock") | |
| 156 private boolean mNetLogToDisk; | |
| 157 | |
| 158 @UsedByReflection("CronetEngine.java") | 151 @UsedByReflection("CronetEngine.java") |
| 159 public CronetUrlRequestContext(final CronetEngineBuilderImpl builder) { | 152 public CronetUrlRequestContext(final CronetEngineBuilderImpl builder) { |
| 160 CronetLibraryLoader.ensureInitialized(builder.getContext(), builder); | 153 CronetLibraryLoader.ensureInitialized(builder.getContext(), builder); |
| 161 nativeSetMinLogLevel(getLoggingLevel()); | 154 nativeSetMinLogLevel(getLoggingLevel()); |
| 162 synchronized (mLock) { | 155 synchronized (mLock) { |
| 163 mUrlRequestContextAdapter = | 156 mUrlRequestContextAdapter = |
| 164 nativeCreateRequestContextAdapter(createNativeUrlRequestCont
extConfig(builder)); | 157 nativeCreateRequestContextAdapter(createNativeUrlRequestCont
extConfig(builder)); |
| 165 if (mUrlRequestContextAdapter == 0) { | 158 if (mUrlRequestContextAdapter == 0) { |
| 166 throw new NullPointerException("Context Adapter creation failed.
"); | 159 throw new NullPointerException("Context Adapter creation failed.
"); |
| 167 } | 160 } |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 } | 267 } |
| 275 nativeDestroy(mUrlRequestContextAdapter); | 268 nativeDestroy(mUrlRequestContextAdapter); |
| 276 mUrlRequestContextAdapter = 0; | 269 mUrlRequestContextAdapter = 0; |
| 277 } | 270 } |
| 278 } | 271 } |
| 279 | 272 |
| 280 @Override | 273 @Override |
| 281 public void startNetLogToFile(String fileName, boolean logAll) { | 274 public void startNetLogToFile(String fileName, boolean logAll) { |
| 282 synchronized (mLock) { | 275 synchronized (mLock) { |
| 283 checkHaveAdapter(); | 276 checkHaveAdapter(); |
| 284 if (!nativeStartNetLogToFile(mUrlRequestContextAdapter, fileName, lo
gAll)) { | 277 nativeStartNetLogToFile(mUrlRequestContextAdapter, fileName, logAll)
; |
| 285 throw new RuntimeException("Unable to start NetLog"); | |
| 286 } | |
| 287 mIsLogging = true; | 278 mIsLogging = true; |
| 288 } | 279 } |
| 289 } | 280 } |
| 290 | 281 |
| 291 @Override | 282 @Override |
| 292 public void startNetLogToDisk(String dirPath, boolean logAll, int maxSize) { | 283 public void startNetLogToDisk(String dirPath, boolean logAll, int maxSize) { |
| 293 synchronized (mLock) { | 284 synchronized (mLock) { |
| 294 checkHaveAdapter(); | 285 checkHaveAdapter(); |
| 295 nativeStartNetLogToDisk(mUrlRequestContextAdapter, dirPath, logAll,
maxSize); | 286 nativeStartNetLogToDisk(mUrlRequestContextAdapter, dirPath, logAll,
maxSize); |
| 296 mIsLogging = true; | 287 mIsLogging = true; |
| 297 mNetLogToDisk = true; | |
| 298 } | 288 } |
| 299 } | 289 } |
| 300 | 290 |
| 301 @Override | 291 @Override |
| 302 public void stopNetLog() { | 292 public void stopNetLog() { |
| 303 synchronized (mLock) { | 293 synchronized (mLock) { |
| 304 if (!mIsLogging) { | 294 if (!mIsLogging) { |
| 305 return; | 295 return; |
| 306 } | 296 } |
| 307 checkHaveAdapter(); | 297 checkHaveAdapter(); |
| 308 nativeStopNetLog(mUrlRequestContextAdapter); | 298 nativeStopNetLog(mUrlRequestContextAdapter); |
| 309 mIsLogging = false; | 299 mIsLogging = false; |
| 310 if (!mNetLogToDisk) { | |
| 311 return; | |
| 312 } | |
| 313 mStopNetLogCompleted = new ConditionVariable(); | 300 mStopNetLogCompleted = new ConditionVariable(); |
| 314 } | 301 } |
| 315 mStopNetLogCompleted.block(); | 302 mStopNetLogCompleted.block(); |
| 316 } | 303 } |
| 317 | 304 |
| 318 @CalledByNative | 305 @CalledByNative |
| 319 public void stopNetLogCompleted() { | 306 public void stopNetLogCompleted() { |
| 320 synchronized (mLock) { | |
| 321 mNetLogToDisk = false; | |
| 322 } | |
| 323 mStopNetLogCompleted.open(); | 307 mStopNetLogCompleted.open(); |
| 324 } | 308 } |
| 325 | 309 |
| 326 @Override | 310 @Override |
| 327 public String getCertVerifierData(long timeout) { | 311 public String getCertVerifierData(long timeout) { |
| 328 if (timeout < 0) { | 312 if (timeout < 0) { |
| 329 throw new IllegalArgumentException("timeout must be a positive value
"); | 313 throw new IllegalArgumentException("timeout must be a positive value
"); |
| 330 } else if (timeout == 0) { | 314 } else if (timeout == 0) { |
| 331 timeout = 100; | 315 timeout = 100; |
| 332 } | 316 } |
| (...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 710 private static native long nativeCreateRequestContextAdapter(long urlRequest
ContextConfig); | 694 private static native long nativeCreateRequestContextAdapter(long urlRequest
ContextConfig); |
| 711 | 695 |
| 712 private static native int nativeSetMinLogLevel(int loggingLevel); | 696 private static native int nativeSetMinLogLevel(int loggingLevel); |
| 713 | 697 |
| 714 private static native byte[] nativeGetHistogramDeltas(); | 698 private static native byte[] nativeGetHistogramDeltas(); |
| 715 | 699 |
| 716 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 700 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 717 private native void nativeDestroy(long nativePtr); | 701 private native void nativeDestroy(long nativePtr); |
| 718 | 702 |
| 719 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 703 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 720 private native boolean nativeStartNetLogToFile(long nativePtr, String fileNa
me, boolean logAll); | 704 private native void nativeStartNetLogToFile(long nativePtr, String fileName,
boolean logAll); |
| 721 | 705 |
| 722 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 706 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 723 private native void nativeStartNetLogToDisk( | 707 private native void nativeStartNetLogToDisk( |
| 724 long nativePtr, String dirPath, boolean logAll, int maxSize); | 708 long nativePtr, String dirPath, boolean logAll, int maxSize); |
| 725 | 709 |
| 726 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 710 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 727 private native void nativeStopNetLog(long nativePtr); | 711 private native void nativeStopNetLog(long nativePtr); |
| 728 | 712 |
| 729 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 713 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 730 private native void nativeGetCertVerifierData(long nativePtr); | 714 private native void nativeGetCertVerifierData(long nativePtr); |
| 731 | 715 |
| 732 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 716 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 733 private native void nativeInitRequestContextOnMainThread(long nativePtr); | 717 private native void nativeInitRequestContextOnMainThread(long nativePtr); |
| 734 | 718 |
| 735 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 719 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 736 private native void nativeConfigureNetworkQualityEstimatorForTesting(long na
tivePtr, | 720 private native void nativeConfigureNetworkQualityEstimatorForTesting(long na
tivePtr, |
| 737 boolean useLocalHostRequests, boolean useSmallerResponses, boolean d
isableOfflineCheck); | 721 boolean useLocalHostRequests, boolean useSmallerResponses, boolean d
isableOfflineCheck); |
| 738 | 722 |
| 739 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 723 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 740 private native void nativeProvideRTTObservations(long nativePtr, boolean sho
uld); | 724 private native void nativeProvideRTTObservations(long nativePtr, boolean sho
uld); |
| 741 | 725 |
| 742 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 726 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 743 private native void nativeProvideThroughputObservations(long nativePtr, bool
ean should); | 727 private native void nativeProvideThroughputObservations(long nativePtr, bool
ean should); |
| 744 | 728 |
| 745 public boolean isNetworkThread(Thread thread) { | 729 public boolean isNetworkThread(Thread thread) { |
| 746 return thread == mNetworkThread; | 730 return thread == mNetworkThread; |
| 747 } | 731 } |
| 748 } | 732 } |
| OLD | NEW |