| 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.content.Context; | 7 import android.content.Context; |
| 8 import android.os.Build; | 8 import android.os.Build; |
| 9 import android.os.ConditionVariable; | 9 import android.os.ConditionVariable; |
| 10 import android.os.Handler; | 10 import android.os.Handler; |
| 11 import android.os.Looper; | 11 import android.os.Looper; |
| 12 import android.os.Process; | 12 import android.os.Process; |
| 13 import android.util.Log; | 13 import android.util.Log; |
| 14 | 14 |
| 15 import org.chromium.base.ObserverList; | 15 import org.chromium.base.ObserverList; |
| 16 import org.chromium.base.VisibleForTesting; | 16 import org.chromium.base.VisibleForTesting; |
| 17 import org.chromium.base.annotations.CalledByNative; | 17 import org.chromium.base.annotations.CalledByNative; |
| 18 import org.chromium.base.annotations.JNINamespace; | 18 import org.chromium.base.annotations.JNINamespace; |
| 19 import org.chromium.base.annotations.NativeClassQualifiedName; | 19 import org.chromium.base.annotations.NativeClassQualifiedName; |
| 20 import org.chromium.base.annotations.UsedByReflection; | 20 import org.chromium.base.annotations.UsedByReflection; |
| 21 import org.chromium.net.BidirectionalStream; | 21 import org.chromium.net.BidirectionalStream; |
| 22 import org.chromium.net.CronetEngine; | 22 import org.chromium.net.CronetEngine; |
| 23 import org.chromium.net.NetworkQualityRttListener; | 23 import org.chromium.net.NetworkQualityRttListener; |
| 24 import org.chromium.net.NetworkQualityThroughputListener; | 24 import org.chromium.net.NetworkQualityThroughputListener; |
| 25 import org.chromium.net.RequestFinishedListener; | 25 import org.chromium.net.RequestFinishedInfo; |
| 26 import org.chromium.net.UrlRequest; | 26 import org.chromium.net.UrlRequest; |
| 27 import org.chromium.net.urlconnection.CronetHttpURLConnection; | 27 import org.chromium.net.urlconnection.CronetHttpURLConnection; |
| 28 import org.chromium.net.urlconnection.CronetURLStreamHandlerFactory; | 28 import org.chromium.net.urlconnection.CronetURLStreamHandlerFactory; |
| 29 | 29 |
| 30 import java.net.Proxy; | 30 import java.net.Proxy; |
| 31 import java.net.URL; | 31 import java.net.URL; |
| 32 import java.net.URLConnection; | 32 import java.net.URLConnection; |
| 33 import java.net.URLStreamHandlerFactory; | 33 import java.net.URLStreamHandlerFactory; |
| 34 import java.util.ArrayList; | 34 import java.util.ArrayList; |
| 35 import java.util.Collection; | 35 import java.util.Collection; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 65 | 65 |
| 66 private boolean mNetworkQualityEstimatorEnabled; | 66 private boolean mNetworkQualityEstimatorEnabled; |
| 67 | 67 |
| 68 /** | 68 /** |
| 69 * Locks operations on network quality listeners, because listener | 69 * Locks operations on network quality listeners, because listener |
| 70 * addition and removal may occur on a different thread from notification. | 70 * addition and removal may occur on a different thread from notification. |
| 71 */ | 71 */ |
| 72 private final Object mNetworkQualityLock = new Object(); | 72 private final Object mNetworkQualityLock = new Object(); |
| 73 | 73 |
| 74 /** | 74 /** |
| 75 * Locks operations on the list of RequestFinishedListeners, because operati
ons can happen on | 75 * Locks operations on the list of RequestFinishedInfo.Listeners, because op
erations can happen |
| 76 * any thread. | 76 * on any thread. |
| 77 */ | 77 */ |
| 78 private final Object mFinishedListenerLock = new Object(); | 78 private final Object mFinishedListenerLock = new Object(); |
| 79 | 79 |
| 80 @GuardedBy("mNetworkQualityLock") | 80 @GuardedBy("mNetworkQualityLock") |
| 81 private final ObserverList<NetworkQualityRttListener> mRttListenerList = | 81 private final ObserverList<NetworkQualityRttListener> mRttListenerList = |
| 82 new ObserverList<NetworkQualityRttListener>(); | 82 new ObserverList<NetworkQualityRttListener>(); |
| 83 | 83 |
| 84 @GuardedBy("mNetworkQualityLock") | 84 @GuardedBy("mNetworkQualityLock") |
| 85 private final ObserverList<NetworkQualityThroughputListener> mThroughputList
enerList = | 85 private final ObserverList<NetworkQualityThroughputListener> mThroughputList
enerList = |
| 86 new ObserverList<NetworkQualityThroughputListener>(); | 86 new ObserverList<NetworkQualityThroughputListener>(); |
| 87 | 87 |
| 88 @GuardedBy("mFinishedListenerLock") | 88 @GuardedBy("mFinishedListenerLock") |
| 89 private final List<RequestFinishedListener> mFinishedListenerList = | 89 private final List<RequestFinishedInfo.Listener> mFinishedListenerList = |
| 90 new ArrayList<RequestFinishedListener>(); | 90 new ArrayList<RequestFinishedInfo.Listener>(); |
| 91 | 91 |
| 92 /** | 92 /** |
| 93 * Synchronize access to mCertVerifierData. | 93 * Synchronize access to mCertVerifierData. |
| 94 */ | 94 */ |
| 95 private ConditionVariable mWaitGetCertVerifierDataComplete = new ConditionVa
riable(); | 95 private ConditionVariable mWaitGetCertVerifierDataComplete = new ConditionVa
riable(); |
| 96 | 96 |
| 97 /** Holds CertVerifier data. */ | 97 /** Holds CertVerifier data. */ |
| 98 private String mCertVerifierData; | 98 private String mCertVerifierData; |
| 99 | 99 |
| 100 @UsedByReflection("CronetEngine.java") | 100 @UsedByReflection("CronetEngine.java") |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 if (mThroughputListenerList.isEmpty()) { | 332 if (mThroughputListenerList.isEmpty()) { |
| 333 synchronized (mLock) { | 333 synchronized (mLock) { |
| 334 checkHaveAdapter(); | 334 checkHaveAdapter(); |
| 335 nativeProvideThroughputObservations(mUrlRequestContextAdapte
r, false); | 335 nativeProvideThroughputObservations(mUrlRequestContextAdapte
r, false); |
| 336 } | 336 } |
| 337 } | 337 } |
| 338 } | 338 } |
| 339 } | 339 } |
| 340 | 340 |
| 341 @Override | 341 @Override |
| 342 public void addRequestFinishedListener(RequestFinishedListener listener) { | 342 public void addRequestFinishedListener(RequestFinishedInfo.Listener listener
) { |
| 343 synchronized (mFinishedListenerLock) { | 343 synchronized (mFinishedListenerLock) { |
| 344 mFinishedListenerList.add(listener); | 344 mFinishedListenerList.add(listener); |
| 345 } | 345 } |
| 346 } | 346 } |
| 347 | 347 |
| 348 @Override | 348 @Override |
| 349 public void removeRequestFinishedListener(RequestFinishedListener listener)
{ | 349 public void removeRequestFinishedListener(RequestFinishedInfo.Listener liste
ner) { |
| 350 synchronized (mFinishedListenerLock) { | 350 synchronized (mFinishedListenerLock) { |
| 351 mFinishedListenerList.remove(listener); | 351 mFinishedListenerList.remove(listener); |
| 352 } | 352 } |
| 353 } | 353 } |
| 354 | 354 |
| 355 @Override | 355 @Override |
| 356 public URLConnection openConnection(URL url) { | 356 public URLConnection openConnection(URL url) { |
| 357 return openConnection(url, Proxy.NO_PROXY); | 357 return openConnection(url, Proxy.NO_PROXY); |
| 358 } | 358 } |
| 359 | 359 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 469 } | 469 } |
| 470 | 470 |
| 471 @SuppressWarnings("unused") | 471 @SuppressWarnings("unused") |
| 472 @CalledByNative | 472 @CalledByNative |
| 473 private void onGetCertVerifierData(String certVerifierData) { | 473 private void onGetCertVerifierData(String certVerifierData) { |
| 474 mCertVerifierData = certVerifierData; | 474 mCertVerifierData = certVerifierData; |
| 475 mWaitGetCertVerifierDataComplete.open(); | 475 mWaitGetCertVerifierDataComplete.open(); |
| 476 } | 476 } |
| 477 | 477 |
| 478 void reportFinished(final CronetUrlRequest request) { | 478 void reportFinished(final CronetUrlRequest request) { |
| 479 final UrlRequestInfo requestInfo = request.getRequestInfo(); | 479 final RequestFinishedInfo requestInfo = request.getRequestFinishedInfo()
; |
| 480 ArrayList<RequestFinishedListener> currentListeners; | 480 ArrayList<RequestFinishedInfo.Listener> currentListeners; |
| 481 synchronized (mFinishedListenerLock) { | 481 synchronized (mFinishedListenerLock) { |
| 482 currentListeners = new ArrayList<RequestFinishedListener>(mFinishedL
istenerList); | 482 currentListeners = new ArrayList<RequestFinishedInfo.Listener>(mFini
shedListenerList); |
| 483 } | 483 } |
| 484 for (final RequestFinishedListener listener : currentListeners) { | 484 for (final RequestFinishedInfo.Listener listener : currentListeners) { |
| 485 Runnable task = new Runnable() { | 485 Runnable task = new Runnable() { |
| 486 @Override | 486 @Override |
| 487 public void run() { | 487 public void run() { |
| 488 listener.onRequestFinished(requestInfo); | 488 listener.onRequestFinished(requestInfo); |
| 489 } | 489 } |
| 490 }; | 490 }; |
| 491 postObservationTaskToExecutor(listener.getExecutor(), task); | 491 postObservationTaskToExecutor(listener.getExecutor(), task); |
| 492 } | 492 } |
| 493 } | 493 } |
| 494 | 494 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 541 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 541 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 542 private native void nativeConfigureNetworkQualityEstimatorForTesting( | 542 private native void nativeConfigureNetworkQualityEstimatorForTesting( |
| 543 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp
onses); | 543 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp
onses); |
| 544 | 544 |
| 545 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 545 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 546 private native void nativeProvideRTTObservations(long nativePtr, boolean sho
uld); | 546 private native void nativeProvideRTTObservations(long nativePtr, boolean sho
uld); |
| 547 | 547 |
| 548 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 548 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 549 private native void nativeProvideThroughputObservations(long nativePtr, bool
ean should); | 549 private native void nativeProvideThroughputObservations(long nativePtr, bool
ean should); |
| 550 } | 550 } |
| OLD | NEW |