| 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.EffectiveConnectionType; | 23 import org.chromium.net.EffectiveConnectionType; |
| 24 import org.chromium.net.NetworkQualityRttListener; | 24 import org.chromium.net.NetworkQualityRttListener; |
| 25 import org.chromium.net.NetworkQualityThroughputListener; | 25 import org.chromium.net.NetworkQualityThroughputListener; |
| 26 import org.chromium.net.RequestFinishedInfo; | 26 import org.chromium.net.RequestFinishedInfo; |
| 27 import org.chromium.net.RttThroughputValues; | |
| 28 import org.chromium.net.UrlRequest; | 27 import org.chromium.net.UrlRequest; |
| 29 import org.chromium.net.urlconnection.CronetHttpURLConnection; | 28 import org.chromium.net.urlconnection.CronetHttpURLConnection; |
| 30 import org.chromium.net.urlconnection.CronetURLStreamHandlerFactory; | 29 import org.chromium.net.urlconnection.CronetURLStreamHandlerFactory; |
| 31 | 30 |
| 32 import java.net.Proxy; | 31 import java.net.Proxy; |
| 33 import java.net.URL; | 32 import java.net.URL; |
| 34 import java.net.URLConnection; | 33 import java.net.URLConnection; |
| 35 import java.net.URLStreamHandlerFactory; | 34 import java.net.URLStreamHandlerFactory; |
| 36 import java.util.ArrayList; | 35 import java.util.ArrayList; |
| 37 import java.util.Collection; | 36 import java.util.Collection; |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 */ | 87 */ |
| 89 private final Object mFinishedListenerLock = new Object(); | 88 private final Object mFinishedListenerLock = new Object(); |
| 90 | 89 |
| 91 /** | 90 /** |
| 92 * Current effective connection type as computed by the network quality | 91 * Current effective connection type as computed by the network quality |
| 93 * estimator. | 92 * estimator. |
| 94 */ | 93 */ |
| 95 @GuardedBy("mNetworkQualityLock") | 94 @GuardedBy("mNetworkQualityLock") |
| 96 private int mEffectiveConnectionType = EffectiveConnectionType.TYPE_UNKNOWN; | 95 private int mEffectiveConnectionType = EffectiveConnectionType.TYPE_UNKNOWN; |
| 97 | 96 |
| 98 /** | |
| 99 * Current estimate of the HTTP RTT (in milliseconds) computed by the | |
| 100 * network quality estimator. | |
| 101 */ | |
| 102 @GuardedBy("mNetworkQualityLock") | |
| 103 private int mHttpRttMs = RttThroughputValues.INVALID_RTT_THROUGHPUT; | |
| 104 | |
| 105 /** | |
| 106 * Current estimate of the transport RTT (in milliseconds) computed by the | |
| 107 * network quality estimator. | |
| 108 */ | |
| 109 @GuardedBy("mNetworkQualityLock") | |
| 110 private int mTransportRttMs = RttThroughputValues.INVALID_RTT_THROUGHPUT; | |
| 111 | |
| 112 /** | |
| 113 * Current estimate of the downstream throughput (in kilobits per second) | |
| 114 * computed by the network quality estimator. | |
| 115 */ | |
| 116 @GuardedBy("mNetworkQualityLock") | |
| 117 private int mDownstreamThroughputKbps = RttThroughputValues.INVALID_RTT_THRO
UGHPUT; | |
| 118 | |
| 119 @GuardedBy("mNetworkQualityLock") | 97 @GuardedBy("mNetworkQualityLock") |
| 120 private final ObserverList<NetworkQualityRttListener> mRttListenerList = | 98 private final ObserverList<NetworkQualityRttListener> mRttListenerList = |
| 121 new ObserverList<NetworkQualityRttListener>(); | 99 new ObserverList<NetworkQualityRttListener>(); |
| 122 | 100 |
| 123 @GuardedBy("mNetworkQualityLock") | 101 @GuardedBy("mNetworkQualityLock") |
| 124 private final ObserverList<NetworkQualityThroughputListener> mThroughputList
enerList = | 102 private final ObserverList<NetworkQualityThroughputListener> mThroughputList
enerList = |
| 125 new ObserverList<NetworkQualityThroughputListener>(); | 103 new ObserverList<NetworkQualityThroughputListener>(); |
| 126 | 104 |
| 127 @GuardedBy("mFinishedListenerLock") | 105 @GuardedBy("mFinishedListenerLock") |
| 128 private final List<RequestFinishedInfo.Listener> mFinishedListenerList = | 106 private final List<RequestFinishedInfo.Listener> mFinishedListenerList = |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 public byte[] getGlobalMetricsDeltas() { | 320 public byte[] getGlobalMetricsDeltas() { |
| 343 return nativeGetHistogramDeltas(); | 321 return nativeGetHistogramDeltas(); |
| 344 } | 322 } |
| 345 | 323 |
| 346 @Override | 324 @Override |
| 347 public int getEffectiveConnectionType() { | 325 public int getEffectiveConnectionType() { |
| 348 if (!mNetworkQualityEstimatorEnabled) { | 326 if (!mNetworkQualityEstimatorEnabled) { |
| 349 throw new IllegalStateException("Network quality estimator must be e
nabled"); | 327 throw new IllegalStateException("Network quality estimator must be e
nabled"); |
| 350 } | 328 } |
| 351 synchronized (mNetworkQualityLock) { | 329 synchronized (mNetworkQualityLock) { |
| 330 synchronized (mLock) { |
| 331 checkHaveAdapter(); |
| 332 } |
| 352 return mEffectiveConnectionType; | 333 return mEffectiveConnectionType; |
| 353 } | 334 } |
| 354 } | 335 } |
| 355 | 336 |
| 356 @Override | |
| 357 public int getHttpRttMs() { | |
| 358 if (!mNetworkQualityEstimatorEnabled) { | |
| 359 throw new IllegalStateException("Network quality estimator must be e
nabled"); | |
| 360 } | |
| 361 synchronized (mNetworkQualityLock) { | |
| 362 return mHttpRttMs; | |
| 363 } | |
| 364 } | |
| 365 | |
| 366 @Override | |
| 367 public int getTransportRttMs() { | |
| 368 if (!mNetworkQualityEstimatorEnabled) { | |
| 369 throw new IllegalStateException("Network quality estimator must be e
nabled"); | |
| 370 } | |
| 371 synchronized (mNetworkQualityLock) { | |
| 372 return mTransportRttMs; | |
| 373 } | |
| 374 } | |
| 375 | |
| 376 @Override | |
| 377 public int getDownstreamThroughputKbps() { | |
| 378 if (!mNetworkQualityEstimatorEnabled) { | |
| 379 throw new IllegalStateException("Network quality estimator must be e
nabled"); | |
| 380 } | |
| 381 synchronized (mNetworkQualityLock) { | |
| 382 return mDownstreamThroughputKbps; | |
| 383 } | |
| 384 } | |
| 385 | |
| 386 @VisibleForTesting | 337 @VisibleForTesting |
| 387 @Override | 338 @Override |
| 388 public void configureNetworkQualityEstimatorForTesting( | 339 public void configureNetworkQualityEstimatorForTesting( |
| 389 boolean useLocalHostRequests, boolean useSmallerResponses) { | 340 boolean useLocalHostRequests, boolean useSmallerResponses) { |
| 390 if (!mNetworkQualityEstimatorEnabled) { | 341 if (!mNetworkQualityEstimatorEnabled) { |
| 391 throw new IllegalStateException("Network quality estimator must be e
nabled"); | 342 throw new IllegalStateException("Network quality estimator must be e
nabled"); |
| 392 } | 343 } |
| 393 synchronized (mLock) { | 344 synchronized (mLock) { |
| 394 checkHaveAdapter(); | 345 checkHaveAdapter(); |
| 395 nativeConfigureNetworkQualityEstimatorForTesting( | 346 nativeConfigureNetworkQualityEstimatorForTesting( |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 567 @SuppressWarnings("unused") | 518 @SuppressWarnings("unused") |
| 568 @CalledByNative | 519 @CalledByNative |
| 569 private void onEffectiveConnectionTypeChanged(int effectiveConnectionType) { | 520 private void onEffectiveConnectionTypeChanged(int effectiveConnectionType) { |
| 570 synchronized (mNetworkQualityLock) { | 521 synchronized (mNetworkQualityLock) { |
| 571 // Convert the enum returned by the network quality estimator to an
enum of type | 522 // Convert the enum returned by the network quality estimator to an
enum of type |
| 572 // EffectiveConnectionType. | 523 // EffectiveConnectionType. |
| 573 mEffectiveConnectionType = effectiveConnectionType; | 524 mEffectiveConnectionType = effectiveConnectionType; |
| 574 } | 525 } |
| 575 } | 526 } |
| 576 | 527 |
| 577 @SuppressWarnings("unused") | |
| 578 @CalledByNative | |
| 579 private void onRTTOrThroughputEstimatesComputed( | |
| 580 final int httpRttMs, final int transportRttMs, final int downstreamT
hroughputKbps) { | |
| 581 synchronized (mNetworkQualityLock) { | |
| 582 mHttpRttMs = httpRttMs; | |
| 583 mTransportRttMs = transportRttMs; | |
| 584 mDownstreamThroughputKbps = downstreamThroughputKbps; | |
| 585 } | |
| 586 } | |
| 587 | |
| 588 @SuppressWarnings("unused") | 528 @SuppressWarnings("unused") |
| 589 @CalledByNative | 529 @CalledByNative |
| 590 private void onRttObservation(final int rttMs, final long whenMs, final int
source) { | 530 private void onRttObservation(final int rttMs, final long whenMs, final int
source) { |
| 591 synchronized (mNetworkQualityLock) { | 531 synchronized (mNetworkQualityLock) { |
| 592 for (final NetworkQualityRttListener listener : mRttListenerList) { | 532 for (final NetworkQualityRttListener listener : mRttListenerList) { |
| 593 Runnable task = new Runnable() { | 533 Runnable task = new Runnable() { |
| 594 @Override | 534 @Override |
| 595 public void run() { | 535 public void run() { |
| 596 listener.onRttObservation(rttMs, whenMs, source); | 536 listener.onRttObservation(rttMs, whenMs, source); |
| 597 } | 537 } |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 698 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 638 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 699 private native void nativeProvideRTTObservations(long nativePtr, boolean sho
uld); | 639 private native void nativeProvideRTTObservations(long nativePtr, boolean sho
uld); |
| 700 | 640 |
| 701 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 641 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 702 private native void nativeProvideThroughputObservations(long nativePtr, bool
ean should); | 642 private native void nativeProvideThroughputObservations(long nativePtr, bool
ean should); |
| 703 | 643 |
| 704 public boolean isNetworkThread(Thread thread) { | 644 public boolean isNetworkThread(Thread thread) { |
| 705 return thread == mNetworkThread; | 645 return thread == mNetworkThread; |
| 706 } | 646 } |
| 707 } | 647 } |
| OLD | NEW |