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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 * on any thread. This should be used for fine-grained locking only. In part icular, don't call | 86 * on any thread. This should be used for fine-grained locking only. In part icular, don't call |
86 * any UrlRequest methods that acquire mUrlRequestAdapterLock while holding this lock. | 87 * any UrlRequest methods that acquire mUrlRequestAdapterLock while holding this lock. |
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") |
96 @EffectiveConnectionType | |
xunjieli
2016/10/20 01:02:43
From the build output, this doesn't seem to work f
tbansal1
2016/10/20 01:05:53
Done in PS#7.
| |
95 private int mEffectiveConnectionType = EffectiveConnectionType.TYPE_UNKNOWN; | 97 private int mEffectiveConnectionType = EffectiveConnectionType.TYPE_UNKNOWN; |
96 | 98 |
99 /** | |
100 * Current estimate of the HTTP RTT (in milliseconds) computed by the | |
101 * network quality estimator. | |
102 */ | |
103 @GuardedBy("mNetworkQualityLock") | |
104 private int mHttpRttMs = RttThroughputValues.INVALID_RTT_THROUGHPUT; | |
105 | |
106 /** | |
107 * Current estimate of the transport RTT (in milliseconds) computed by the | |
108 * network quality estimator. | |
109 */ | |
110 @GuardedBy("mNetworkQualityLock") | |
111 private int mTransportRttMs = RttThroughputValues.INVALID_RTT_THROUGHPUT; | |
112 | |
113 /** | |
114 * Current estimate of the downstream throughput (in kilobits per second) | |
115 * computed by the network quality estimator. | |
116 */ | |
117 @GuardedBy("mNetworkQualityLock") | |
118 private int mDownstreamThroughputKbps = RttThroughputValues.INVALID_RTT_THRO UGHPUT; | |
119 | |
97 @GuardedBy("mNetworkQualityLock") | 120 @GuardedBy("mNetworkQualityLock") |
98 private final ObserverList<NetworkQualityRttListener> mRttListenerList = | 121 private final ObserverList<NetworkQualityRttListener> mRttListenerList = |
99 new ObserverList<NetworkQualityRttListener>(); | 122 new ObserverList<NetworkQualityRttListener>(); |
100 | 123 |
101 @GuardedBy("mNetworkQualityLock") | 124 @GuardedBy("mNetworkQualityLock") |
102 private final ObserverList<NetworkQualityThroughputListener> mThroughputList enerList = | 125 private final ObserverList<NetworkQualityThroughputListener> mThroughputList enerList = |
103 new ObserverList<NetworkQualityThroughputListener>(); | 126 new ObserverList<NetworkQualityThroughputListener>(); |
104 | 127 |
105 @GuardedBy("mFinishedListenerLock") | 128 @GuardedBy("mFinishedListenerLock") |
106 private final List<RequestFinishedInfo.Listener> mFinishedListenerList = | 129 private final List<RequestFinishedInfo.Listener> mFinishedListenerList = |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
320 public byte[] getGlobalMetricsDeltas() { | 343 public byte[] getGlobalMetricsDeltas() { |
321 return nativeGetHistogramDeltas(); | 344 return nativeGetHistogramDeltas(); |
322 } | 345 } |
323 | 346 |
324 @Override | 347 @Override |
325 public int getEffectiveConnectionType() { | 348 public int getEffectiveConnectionType() { |
326 if (!mNetworkQualityEstimatorEnabled) { | 349 if (!mNetworkQualityEstimatorEnabled) { |
327 throw new IllegalStateException("Network quality estimator must be e nabled"); | 350 throw new IllegalStateException("Network quality estimator must be e nabled"); |
328 } | 351 } |
329 synchronized (mNetworkQualityLock) { | 352 synchronized (mNetworkQualityLock) { |
330 synchronized (mLock) { | |
331 checkHaveAdapter(); | |
332 } | |
333 return mEffectiveConnectionType; | 353 return mEffectiveConnectionType; |
334 } | 354 } |
335 } | 355 } |
336 | 356 |
357 @Override | |
358 public int getHttpRttMs() { | |
359 if (!mNetworkQualityEstimatorEnabled) { | |
360 throw new IllegalStateException("Network quality estimator must be e nabled"); | |
361 } | |
362 synchronized (mNetworkQualityLock) { | |
363 return mHttpRttMs; | |
364 } | |
365 } | |
366 | |
367 @Override | |
368 public int getTransportRttMs() { | |
369 if (!mNetworkQualityEstimatorEnabled) { | |
370 throw new IllegalStateException("Network quality estimator must be e nabled"); | |
371 } | |
372 synchronized (mNetworkQualityLock) { | |
373 return mTransportRttMs; | |
374 } | |
375 } | |
376 | |
377 @Override | |
378 public int getDownstreamThroughputKbps() { | |
379 if (!mNetworkQualityEstimatorEnabled) { | |
380 throw new IllegalStateException("Network quality estimator must be e nabled"); | |
381 } | |
382 synchronized (mNetworkQualityLock) { | |
383 return mDownstreamThroughputKbps; | |
384 } | |
385 } | |
386 | |
337 @VisibleForTesting | 387 @VisibleForTesting |
338 @Override | 388 @Override |
339 public void configureNetworkQualityEstimatorForTesting( | 389 public void configureNetworkQualityEstimatorForTesting( |
340 boolean useLocalHostRequests, boolean useSmallerResponses) { | 390 boolean useLocalHostRequests, boolean useSmallerResponses) { |
341 if (!mNetworkQualityEstimatorEnabled) { | 391 if (!mNetworkQualityEstimatorEnabled) { |
342 throw new IllegalStateException("Network quality estimator must be e nabled"); | 392 throw new IllegalStateException("Network quality estimator must be e nabled"); |
343 } | 393 } |
344 synchronized (mLock) { | 394 synchronized (mLock) { |
345 checkHaveAdapter(); | 395 checkHaveAdapter(); |
346 nativeConfigureNetworkQualityEstimatorForTesting( | 396 nativeConfigureNetworkQualityEstimatorForTesting( |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
520 private void onEffectiveConnectionTypeChanged(int effectiveConnectionType) { | 570 private void onEffectiveConnectionTypeChanged(int effectiveConnectionType) { |
521 synchronized (mNetworkQualityLock) { | 571 synchronized (mNetworkQualityLock) { |
522 // Convert the enum returned by the network quality estimator to an enum of type | 572 // Convert the enum returned by the network quality estimator to an enum of type |
523 // EffectiveConnectionType. | 573 // EffectiveConnectionType. |
524 mEffectiveConnectionType = effectiveConnectionType; | 574 mEffectiveConnectionType = effectiveConnectionType; |
525 } | 575 } |
526 } | 576 } |
527 | 577 |
528 @SuppressWarnings("unused") | 578 @SuppressWarnings("unused") |
529 @CalledByNative | 579 @CalledByNative |
580 private void onRTTOrThroughputEstimatesComputed( | |
581 final int httpRttMs, final int transportRttMs, final int downstreamT hroughputKbps) { | |
582 synchronized (mNetworkQualityLock) { | |
583 mHttpRttMs = httpRttMs; | |
584 mTransportRttMs = transportRttMs; | |
585 mDownstreamThroughputKbps = downstreamThroughputKbps; | |
586 } | |
587 } | |
588 | |
589 @SuppressWarnings("unused") | |
590 @CalledByNative | |
530 private void onRttObservation(final int rttMs, final long whenMs, final int source) { | 591 private void onRttObservation(final int rttMs, final long whenMs, final int source) { |
531 synchronized (mNetworkQualityLock) { | 592 synchronized (mNetworkQualityLock) { |
532 for (final NetworkQualityRttListener listener : mRttListenerList) { | 593 for (final NetworkQualityRttListener listener : mRttListenerList) { |
533 Runnable task = new Runnable() { | 594 Runnable task = new Runnable() { |
534 @Override | 595 @Override |
535 public void run() { | 596 public void run() { |
536 listener.onRttObservation(rttMs, whenMs, source); | 597 listener.onRttObservation(rttMs, whenMs, source); |
537 } | 598 } |
538 }; | 599 }; |
539 postObservationTaskToExecutor(listener.getExecutor(), task); | 600 postObservationTaskToExecutor(listener.getExecutor(), task); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
638 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 699 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
639 private native void nativeProvideRTTObservations(long nativePtr, boolean sho uld); | 700 private native void nativeProvideRTTObservations(long nativePtr, boolean sho uld); |
640 | 701 |
641 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 702 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
642 private native void nativeProvideThroughputObservations(long nativePtr, bool ean should); | 703 private native void nativeProvideThroughputObservations(long nativePtr, bool ean should); |
643 | 704 |
644 public boolean isNetworkThread(Thread thread) { | 705 public boolean isNetworkThread(Thread thread) { |
645 return thread == mNetworkThread; | 706 return thread == mNetworkThread; |
646 } | 707 } |
647 } | 708 } |
OLD | NEW |