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_VALUE; |
| 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_VAL
UE; |
| 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_VALUE; |
| 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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) { | 352 synchronized (mLock) { |
331 checkHaveAdapter(); | 353 checkHaveAdapter(); |
332 } | 354 } |
333 return mEffectiveConnectionType; | 355 return mEffectiveConnectionType; |
334 } | 356 } |
335 } | 357 } |
336 | 358 |
| 359 @Override |
| 360 public int getHttpRttMs() { |
| 361 if (!mNetworkQualityEstimatorEnabled) { |
| 362 throw new IllegalStateException("Network quality estimator must be e
nabled"); |
| 363 } |
| 364 synchronized (mNetworkQualityLock) { |
| 365 synchronized (mLock) { |
| 366 checkHaveAdapter(); |
| 367 } |
| 368 return mHttpRttMs; |
| 369 } |
| 370 } |
| 371 |
| 372 @Override |
| 373 public int getTransportRttMs() { |
| 374 if (!mNetworkQualityEstimatorEnabled) { |
| 375 throw new IllegalStateException("Network quality estimator must be e
nabled"); |
| 376 } |
| 377 synchronized (mNetworkQualityLock) { |
| 378 synchronized (mLock) { |
| 379 checkHaveAdapter(); |
| 380 } |
| 381 return mTransportRttMs; |
| 382 } |
| 383 } |
| 384 |
| 385 @Override |
| 386 public int getDownstreamThroughputKbps() { |
| 387 if (!mNetworkQualityEstimatorEnabled) { |
| 388 throw new IllegalStateException("Network quality estimator must be e
nabled"); |
| 389 } |
| 390 synchronized (mNetworkQualityLock) { |
| 391 synchronized (mLock) { |
| 392 checkHaveAdapter(); |
| 393 } |
| 394 return mDownstreamThroughputKbps; |
| 395 } |
| 396 } |
| 397 |
337 @VisibleForTesting | 398 @VisibleForTesting |
338 @Override | 399 @Override |
339 public void configureNetworkQualityEstimatorForTesting( | 400 public void configureNetworkQualityEstimatorForTesting( |
340 boolean useLocalHostRequests, boolean useSmallerResponses) { | 401 boolean useLocalHostRequests, boolean useSmallerResponses) { |
341 if (!mNetworkQualityEstimatorEnabled) { | 402 if (!mNetworkQualityEstimatorEnabled) { |
342 throw new IllegalStateException("Network quality estimator must be e
nabled"); | 403 throw new IllegalStateException("Network quality estimator must be e
nabled"); |
343 } | 404 } |
344 synchronized (mLock) { | 405 synchronized (mLock) { |
345 checkHaveAdapter(); | 406 checkHaveAdapter(); |
346 nativeConfigureNetworkQualityEstimatorForTesting( | 407 nativeConfigureNetworkQualityEstimatorForTesting( |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
520 private void onEffectiveConnectionTypeChanged(int effectiveConnectionType) { | 581 private void onEffectiveConnectionTypeChanged(int effectiveConnectionType) { |
521 synchronized (mNetworkQualityLock) { | 582 synchronized (mNetworkQualityLock) { |
522 // Convert the enum returned by the network quality estimator to an
enum of type | 583 // Convert the enum returned by the network quality estimator to an
enum of type |
523 // EffectiveConnectionType. | 584 // EffectiveConnectionType. |
524 mEffectiveConnectionType = effectiveConnectionType; | 585 mEffectiveConnectionType = effectiveConnectionType; |
525 } | 586 } |
526 } | 587 } |
527 | 588 |
528 @SuppressWarnings("unused") | 589 @SuppressWarnings("unused") |
529 @CalledByNative | 590 @CalledByNative |
| 591 private void onRTTOrThroughputEstimatesComputed( |
| 592 final int httpRttMs, final int transportRttMs, final int downstreamT
hroughputKbps) { |
| 593 synchronized (mNetworkQualityLock) { |
| 594 mHttpRttMs = httpRttMs; |
| 595 mTransportRttMs = transportRttMs; |
| 596 mDownstreamThroughputKbps = downstreamThroughputKbps; |
| 597 } |
| 598 } |
| 599 |
| 600 @SuppressWarnings("unused") |
| 601 @CalledByNative |
530 private void onRttObservation(final int rttMs, final long whenMs, final int
source) { | 602 private void onRttObservation(final int rttMs, final long whenMs, final int
source) { |
531 synchronized (mNetworkQualityLock) { | 603 synchronized (mNetworkQualityLock) { |
532 for (final NetworkQualityRttListener listener : mRttListenerList) { | 604 for (final NetworkQualityRttListener listener : mRttListenerList) { |
533 Runnable task = new Runnable() { | 605 Runnable task = new Runnable() { |
534 @Override | 606 @Override |
535 public void run() { | 607 public void run() { |
536 listener.onRttObservation(rttMs, whenMs, source); | 608 listener.onRttObservation(rttMs, whenMs, source); |
537 } | 609 } |
538 }; | 610 }; |
539 postObservationTaskToExecutor(listener.getExecutor(), task); | 611 postObservationTaskToExecutor(listener.getExecutor(), task); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
638 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 710 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
639 private native void nativeProvideRTTObservations(long nativePtr, boolean sho
uld); | 711 private native void nativeProvideRTTObservations(long nativePtr, boolean sho
uld); |
640 | 712 |
641 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 713 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
642 private native void nativeProvideThroughputObservations(long nativePtr, bool
ean should); | 714 private native void nativeProvideThroughputObservations(long nativePtr, bool
ean should); |
643 | 715 |
644 public boolean isNetworkThread(Thread thread) { | 716 public boolean isNetworkThread(Thread thread) { |
645 return thread == mNetworkThread; | 717 return thread == mNetworkThread; |
646 } | 718 } |
647 } | 719 } |
OLD | NEW |