Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(567)

Side by Side Diff: components/cronet/android/java/src/org/chromium/net/impl/CronetUrlRequestContext.java

Issue 2214163002: Revert of Expose effective connection type to Cronet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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;
24 import org.chromium.net.NetworkQualityRttListener; 23 import org.chromium.net.NetworkQualityRttListener;
25 import org.chromium.net.NetworkQualityThroughputListener; 24 import org.chromium.net.NetworkQualityThroughputListener;
26 import org.chromium.net.RequestFinishedInfo; 25 import org.chromium.net.RequestFinishedInfo;
27 import org.chromium.net.UrlRequest; 26 import org.chromium.net.UrlRequest;
28 import org.chromium.net.urlconnection.CronetHttpURLConnection; 27 import org.chromium.net.urlconnection.CronetHttpURLConnection;
29 import org.chromium.net.urlconnection.CronetURLStreamHandlerFactory; 28 import org.chromium.net.urlconnection.CronetURLStreamHandlerFactory;
30 29
31 import java.net.Proxy; 30 import java.net.Proxy;
32 import java.net.URL; 31 import java.net.URL;
33 import java.net.URLConnection; 32 import java.net.URLConnection;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 * addition and removal may occur on a different thread from notification. 70 * addition and removal may occur on a different thread from notification.
72 */ 71 */
73 private final Object mNetworkQualityLock = new Object(); 72 private final Object mNetworkQualityLock = new Object();
74 73
75 /** 74 /**
76 * Locks operations on the list of RequestFinishedInfo.Listeners, because op erations can happen 75 * Locks operations on the list of RequestFinishedInfo.Listeners, because op erations can happen
77 * on any thread. 76 * on any thread.
78 */ 77 */
79 private final Object mFinishedListenerLock = new Object(); 78 private final Object mFinishedListenerLock = new Object();
80 79
81 /**
82 * Current effective connection type as computed by the network quality
83 * estimator.
84 */
85 @GuardedBy("mNetworkQualityLock")
86 private int mEffectiveConnectionType =
87 EffectiveConnectionType.EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
88
89 @GuardedBy("mNetworkQualityLock") 80 @GuardedBy("mNetworkQualityLock")
90 private final ObserverList<NetworkQualityRttListener> mRttListenerList = 81 private final ObserverList<NetworkQualityRttListener> mRttListenerList =
91 new ObserverList<NetworkQualityRttListener>(); 82 new ObserverList<NetworkQualityRttListener>();
92 83
93 @GuardedBy("mNetworkQualityLock") 84 @GuardedBy("mNetworkQualityLock")
94 private final ObserverList<NetworkQualityThroughputListener> mThroughputList enerList = 85 private final ObserverList<NetworkQualityThroughputListener> mThroughputList enerList =
95 new ObserverList<NetworkQualityThroughputListener>(); 86 new ObserverList<NetworkQualityThroughputListener>();
96 87
97 @GuardedBy("mFinishedListenerLock") 88 @GuardedBy("mFinishedListenerLock")
98 private final List<RequestFinishedInfo.Listener> mFinishedListenerList = 89 private final List<RequestFinishedInfo.Listener> mFinishedListenerList =
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 return mCertVerifierData; 253 return mCertVerifierData;
263 } 254 }
264 255
265 // This method is intentionally non-static to ensure Cronet native library 256 // This method is intentionally non-static to ensure Cronet native library
266 // is loaded by class constructor. 257 // is loaded by class constructor.
267 @Override 258 @Override
268 public byte[] getGlobalMetricsDeltas() { 259 public byte[] getGlobalMetricsDeltas() {
269 return nativeGetHistogramDeltas(); 260 return nativeGetHistogramDeltas();
270 } 261 }
271 262
272 @Override
273 public int getEffectiveConnectionType() {
274 if (!mNetworkQualityEstimatorEnabled) {
275 throw new IllegalStateException("Network quality estimator must be e nabled");
276 }
277 synchronized (mNetworkQualityLock) {
278 checkHaveAdapter();
279 return mEffectiveConnectionType;
280 }
281 }
282
283 @VisibleForTesting 263 @VisibleForTesting
284 @Override 264 @Override
285 public void configureNetworkQualityEstimatorForTesting( 265 public void configureNetworkQualityEstimatorForTesting(
286 boolean useLocalHostRequests, boolean useSmallerResponses) { 266 boolean useLocalHostRequests, boolean useSmallerResponses) {
287 if (!mNetworkQualityEstimatorEnabled) { 267 if (!mNetworkQualityEstimatorEnabled) {
288 throw new IllegalStateException("Network quality estimator must be e nabled"); 268 throw new IllegalStateException("Network quality estimator must be e nabled");
289 } 269 }
290 synchronized (mLock) { 270 synchronized (mLock) {
291 checkHaveAdapter(); 271 checkHaveAdapter();
292 nativeConfigureNetworkQualityEstimatorForTesting( 272 nativeConfigureNetworkQualityEstimatorForTesting(
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 private void initNetworkThread() { 429 private void initNetworkThread() {
450 synchronized (mLock) { 430 synchronized (mLock) {
451 mNetworkThread = Thread.currentThread(); 431 mNetworkThread = Thread.currentThread();
452 mInitCompleted.open(); 432 mInitCompleted.open();
453 } 433 }
454 Thread.currentThread().setName("ChromiumNet"); 434 Thread.currentThread().setName("ChromiumNet");
455 Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); 435 Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
456 } 436 }
457 437
458 @SuppressWarnings("unused") 438 @SuppressWarnings("unused")
459 @CalledByNative
460 private void onEffectiveConnectionTypeChanged(int effectiveConnectionType) {
461 synchronized (mNetworkQualityLock) {
462 // Convert the enum returned by the network quality estimator to an enum of type
463 // EffectiveConnectionType.
464 mEffectiveConnectionType =
465 EffectiveConnectionType.getEffectiveConnectionType(effective ConnectionType);
466 }
467 }
468
469 @SuppressWarnings("unused")
470 @CalledByNative 439 @CalledByNative
471 private void onRttObservation(final int rttMs, final long whenMs, final int source) { 440 private void onRttObservation(final int rttMs, final long whenMs, final int source) {
472 synchronized (mNetworkQualityLock) { 441 synchronized (mNetworkQualityLock) {
473 for (final NetworkQualityRttListener listener : mRttListenerList) { 442 for (final NetworkQualityRttListener listener : mRttListenerList) {
474 Runnable task = new Runnable() { 443 Runnable task = new Runnable() {
475 @Override 444 @Override
476 public void run() { 445 public void run() {
477 listener.onRttObservation(rttMs, whenMs, source); 446 listener.onRttObservation(rttMs, whenMs, source);
478 } 447 }
479 }; 448 };
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
572 @NativeClassQualifiedName("CronetURLRequestContextAdapter") 541 @NativeClassQualifiedName("CronetURLRequestContextAdapter")
573 private native void nativeConfigureNetworkQualityEstimatorForTesting( 542 private native void nativeConfigureNetworkQualityEstimatorForTesting(
574 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp onses); 543 long nativePtr, boolean useLocalHostRequests, boolean useSmallerResp onses);
575 544
576 @NativeClassQualifiedName("CronetURLRequestContextAdapter") 545 @NativeClassQualifiedName("CronetURLRequestContextAdapter")
577 private native void nativeProvideRTTObservations(long nativePtr, boolean sho uld); 546 private native void nativeProvideRTTObservations(long nativePtr, boolean sho uld);
578 547
579 @NativeClassQualifiedName("CronetURLRequestContextAdapter") 548 @NativeClassQualifiedName("CronetURLRequestContextAdapter")
580 private native void nativeProvideThroughputObservations(long nativePtr, bool ean should); 549 private native void nativeProvideThroughputObservations(long nativePtr, bool ean should);
581 } 550 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698