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; |
27 import org.chromium.net.UrlRequest; | 28 import org.chromium.net.UrlRequest; |
28 import org.chromium.net.urlconnection.CronetHttpURLConnection; | 29 import org.chromium.net.urlconnection.CronetHttpURLConnection; |
29 import org.chromium.net.urlconnection.CronetURLStreamHandlerFactory; | 30 import org.chromium.net.urlconnection.CronetURLStreamHandlerFactory; |
30 | 31 |
31 import java.net.Proxy; | 32 import java.net.Proxy; |
32 import java.net.URL; | 33 import java.net.URL; |
33 import java.net.URLConnection; | 34 import java.net.URLConnection; |
34 import java.net.URLStreamHandlerFactory; | 35 import java.net.URLStreamHandlerFactory; |
35 import java.util.ArrayList; | 36 import java.util.ArrayList; |
36 import java.util.Collection; | 37 import java.util.Collection; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 */ | 88 */ |
88 private final Object mFinishedListenerLock = new Object(); | 89 private final Object mFinishedListenerLock = new Object(); |
89 | 90 |
90 /** | 91 /** |
91 * Current effective connection type as computed by the network quality | 92 * Current effective connection type as computed by the network quality |
92 * estimator. | 93 * estimator. |
93 */ | 94 */ |
94 @GuardedBy("mNetworkQualityLock") | 95 @GuardedBy("mNetworkQualityLock") |
95 private int mEffectiveConnectionType = EffectiveConnectionType.TYPE_UNKNOWN; | 96 private int mEffectiveConnectionType = EffectiveConnectionType.TYPE_UNKNOWN; |
96 | 97 |
| 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 |
97 @GuardedBy("mNetworkQualityLock") | 119 @GuardedBy("mNetworkQualityLock") |
98 private final ObserverList<NetworkQualityRttListener> mRttListenerList = | 120 private final ObserverList<NetworkQualityRttListener> mRttListenerList = |
99 new ObserverList<NetworkQualityRttListener>(); | 121 new ObserverList<NetworkQualityRttListener>(); |
100 | 122 |
101 @GuardedBy("mNetworkQualityLock") | 123 @GuardedBy("mNetworkQualityLock") |
102 private final ObserverList<NetworkQualityThroughputListener> mThroughputList
enerList = | 124 private final ObserverList<NetworkQualityThroughputListener> mThroughputList
enerList = |
103 new ObserverList<NetworkQualityThroughputListener>(); | 125 new ObserverList<NetworkQualityThroughputListener>(); |
104 | 126 |
105 @GuardedBy("mFinishedListenerLock") | 127 @GuardedBy("mFinishedListenerLock") |
106 private final List<RequestFinishedInfo.Listener> mFinishedListenerList = | 128 private final List<RequestFinishedInfo.Listener> mFinishedListenerList = |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 public byte[] getGlobalMetricsDeltas() { | 342 public byte[] getGlobalMetricsDeltas() { |
321 return nativeGetHistogramDeltas(); | 343 return nativeGetHistogramDeltas(); |
322 } | 344 } |
323 | 345 |
324 @Override | 346 @Override |
325 public int getEffectiveConnectionType() { | 347 public int getEffectiveConnectionType() { |
326 if (!mNetworkQualityEstimatorEnabled) { | 348 if (!mNetworkQualityEstimatorEnabled) { |
327 throw new IllegalStateException("Network quality estimator must be e
nabled"); | 349 throw new IllegalStateException("Network quality estimator must be e
nabled"); |
328 } | 350 } |
329 synchronized (mNetworkQualityLock) { | 351 synchronized (mNetworkQualityLock) { |
330 synchronized (mLock) { | |
331 checkHaveAdapter(); | |
332 } | |
333 return mEffectiveConnectionType; | 352 return mEffectiveConnectionType; |
334 } | 353 } |
335 } | 354 } |
336 | 355 |
| 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 |
337 @VisibleForTesting | 386 @VisibleForTesting |
338 @Override | 387 @Override |
339 public void configureNetworkQualityEstimatorForTesting( | 388 public void configureNetworkQualityEstimatorForTesting( |
340 boolean useLocalHostRequests, boolean useSmallerResponses) { | 389 boolean useLocalHostRequests, boolean useSmallerResponses) { |
341 if (!mNetworkQualityEstimatorEnabled) { | 390 if (!mNetworkQualityEstimatorEnabled) { |
342 throw new IllegalStateException("Network quality estimator must be e
nabled"); | 391 throw new IllegalStateException("Network quality estimator must be e
nabled"); |
343 } | 392 } |
344 synchronized (mLock) { | 393 synchronized (mLock) { |
345 checkHaveAdapter(); | 394 checkHaveAdapter(); |
346 nativeConfigureNetworkQualityEstimatorForTesting( | 395 nativeConfigureNetworkQualityEstimatorForTesting( |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 private void onEffectiveConnectionTypeChanged(int effectiveConnectionType) { | 569 private void onEffectiveConnectionTypeChanged(int effectiveConnectionType) { |
521 synchronized (mNetworkQualityLock) { | 570 synchronized (mNetworkQualityLock) { |
522 // Convert the enum returned by the network quality estimator to an
enum of type | 571 // Convert the enum returned by the network quality estimator to an
enum of type |
523 // EffectiveConnectionType. | 572 // EffectiveConnectionType. |
524 mEffectiveConnectionType = effectiveConnectionType; | 573 mEffectiveConnectionType = effectiveConnectionType; |
525 } | 574 } |
526 } | 575 } |
527 | 576 |
528 @SuppressWarnings("unused") | 577 @SuppressWarnings("unused") |
529 @CalledByNative | 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") |
| 589 @CalledByNative |
530 private void onRttObservation(final int rttMs, final long whenMs, final int
source) { | 590 private void onRttObservation(final int rttMs, final long whenMs, final int
source) { |
531 synchronized (mNetworkQualityLock) { | 591 synchronized (mNetworkQualityLock) { |
532 for (final NetworkQualityRttListener listener : mRttListenerList) { | 592 for (final NetworkQualityRttListener listener : mRttListenerList) { |
533 Runnable task = new Runnable() { | 593 Runnable task = new Runnable() { |
534 @Override | 594 @Override |
535 public void run() { | 595 public void run() { |
536 listener.onRttObservation(rttMs, whenMs, source); | 596 listener.onRttObservation(rttMs, whenMs, source); |
537 } | 597 } |
538 }; | 598 }; |
539 postObservationTaskToExecutor(listener.getExecutor(), task); | 599 postObservationTaskToExecutor(listener.getExecutor(), task); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 698 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
639 private native void nativeProvideRTTObservations(long nativePtr, boolean sho
uld); | 699 private native void nativeProvideRTTObservations(long nativePtr, boolean sho
uld); |
640 | 700 |
641 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 701 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
642 private native void nativeProvideThroughputObservations(long nativePtr, bool
ean should); | 702 private native void nativeProvideThroughputObservations(long nativePtr, bool
ean should); |
643 | 703 |
644 public boolean isNetworkThread(Thread thread) { | 704 public boolean isNetworkThread(Thread thread) { |
645 return thread == mNetworkThread; | 705 return thread == mNetworkThread; |
646 } | 706 } |
647 } | 707 } |
OLD | NEW |