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

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

Issue 2146563002: Expose effective connection type to Cronet (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Patch Created 4 years, 5 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; 5 package org.chromium.net;
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;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 private Executor mNetworkQualityExecutor; 58 private Executor mNetworkQualityExecutor;
59 private boolean mNetworkQualityEstimatorEnabled; 59 private boolean mNetworkQualityEstimatorEnabled;
60 60
61 /** Locks operations on network quality listeners, because listener 61 /** Locks operations on network quality listeners, because listener
62 * addition and removal may occur on a different thread from notification. 62 * addition and removal may occur on a different thread from notification.
63 */ 63 */
64 private final Object mNetworkQualityLock = new Object(); 64 private final Object mNetworkQualityLock = new Object();
65 65
66 @GuardedBy("mNetworkQualityLock") 66 @GuardedBy("mNetworkQualityLock")
67 // Current effective connection type as computed by the network quality
68 // estimator.
69 private int mEffectiveConnectionType =
70 EffectiveConnectionType.EFFECTIVE_CONNECTION_TYPE_UNKNOWN;
71
72 @GuardedBy("mNetworkQualityLock")
67 private final ObserverList<NetworkQualityRttListener> mRttListenerList = 73 private final ObserverList<NetworkQualityRttListener> mRttListenerList =
68 new ObserverList<NetworkQualityRttListener>(); 74 new ObserverList<NetworkQualityRttListener>();
69 75
70 @GuardedBy("mNetworkQualityLock") 76 @GuardedBy("mNetworkQualityLock")
71 private final ObserverList<NetworkQualityThroughputListener> mThroughputList enerList = 77 private final ObserverList<NetworkQualityThroughputListener> mThroughputList enerList =
72 new ObserverList<NetworkQualityThroughputListener>(); 78 new ObserverList<NetworkQualityThroughputListener>();
73 79
74 @GuardedBy("mNetworkQualityLock") 80 @GuardedBy("mNetworkQualityLock")
75 private final ObserverList<RequestFinishedListener> mFinishedListenerList = 81 private final ObserverList<RequestFinishedListener> mFinishedListenerList =
76 new ObserverList<RequestFinishedListener>(); 82 new ObserverList<RequestFinishedListener>();
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 } 267 }
262 if (executor == null) { 268 if (executor == null) {
263 throw new NullPointerException("Request finished listener requires a n executor"); 269 throw new NullPointerException("Request finished listener requires a n executor");
264 } 270 }
265 if (mNetworkQualityExecutor != null) { 271 if (mNetworkQualityExecutor != null) {
266 throw new NullPointerException("Request finished listener executor a lready set"); 272 throw new NullPointerException("Request finished listener executor a lready set");
267 } 273 }
268 mNetworkQualityExecutor = executor; 274 mNetworkQualityExecutor = executor;
269 } 275 }
270 276
277 @Override
278 public int getEffectiveConnectionType() {
279 if (!mNetworkQualityEstimatorEnabled) {
280 throw new IllegalStateException("Network quality estimator must be e nabled");
281 }
282 synchronized (mNetworkQualityLock) {
283 checkHaveAdapter();
284 return mEffectiveConnectionType;
285 }
286 }
287
271 /** 288 /**
272 * TODO(tbansal): http://crbug.com/618034 Remove this API once all 289 * TODO(tbansal): http://crbug.com/618034 Remove this API once all
273 * embedders have switched to using CronetEngine builder for enabling 290 * embedders have switched to using CronetEngine builder for enabling
274 * network quality estimator. 291 * network quality estimator.
275 */ 292 */
276 @Override 293 @Override
277 public void enableNetworkQualityEstimator(Executor executor) { 294 public void enableNetworkQualityEstimator(Executor executor) {
278 if (mNetworkQualityEstimatorEnabled) { 295 if (mNetworkQualityEstimatorEnabled) {
279 throw new IllegalStateException("Network quality estimator already e nabled"); 296 throw new IllegalStateException("Network quality estimator already e nabled");
280 } 297 }
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 synchronized (mLock) { 497 synchronized (mLock) {
481 mNetworkThread = Thread.currentThread(); 498 mNetworkThread = Thread.currentThread();
482 mInitCompleted.open(); 499 mInitCompleted.open();
483 } 500 }
484 Thread.currentThread().setName("ChromiumNet"); 501 Thread.currentThread().setName("ChromiumNet");
485 Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); 502 Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
486 } 503 }
487 504
488 @SuppressWarnings("unused") 505 @SuppressWarnings("unused")
489 @CalledByNative 506 @CalledByNative
507 private void onEffectiveConnectionTypeChanged(int effectiveConnectionType) {
508 synchronized (mNetworkQualityLock) {
509 mEffectiveConnectionType = effectiveConnectionType;
510 }
511 }
512
513 @SuppressWarnings("unused")
514 @CalledByNative
490 private void onRttObservation(final int rttMs, final long whenMs, final int source) { 515 private void onRttObservation(final int rttMs, final long whenMs, final int source) {
491 synchronized (mNetworkQualityLock) { 516 synchronized (mNetworkQualityLock) {
492 for (final NetworkQualityRttListener listener : mRttListenerList) { 517 for (final NetworkQualityRttListener listener : mRttListenerList) {
493 Runnable task = new Runnable() { 518 Runnable task = new Runnable() {
494 @Override 519 @Override
495 public void run() { 520 public void run() {
496 listener.onRttObservation(rttMs, whenMs, source); 521 listener.onRttObservation(rttMs, whenMs, source);
497 } 522 }
498 }; 523 };
499 // Use the executor provided by the listener. If not available, 524 // Use the executor provided by the listener. If not available,
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
612 637
613 @NativeClassQualifiedName("CronetURLRequestContextAdapter") 638 @NativeClassQualifiedName("CronetURLRequestContextAdapter")
614 private native void nativeEnableNetworkQualityEstimator(long nativePtr); 639 private native void nativeEnableNetworkQualityEstimator(long nativePtr);
615 640
616 @NativeClassQualifiedName("CronetURLRequestContextAdapter") 641 @NativeClassQualifiedName("CronetURLRequestContextAdapter")
617 private native void nativeProvideRTTObservations(long nativePtr, boolean sho uld); 642 private native void nativeProvideRTTObservations(long nativePtr, boolean sho uld);
618 643
619 @NativeClassQualifiedName("CronetURLRequestContextAdapter") 644 @NativeClassQualifiedName("CronetURLRequestContextAdapter")
620 private native void nativeProvideThroughputObservations(long nativePtr, bool ean should); 645 private native void nativeProvideThroughputObservations(long nativePtr, bool ean should);
621 } 646 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698