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

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

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

Powered by Google App Engine
This is Rietveld 408576698