Chromium Code Reviews| 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.os.ConditionVariable; | 7 import android.os.ConditionVariable; |
| 8 import android.os.Handler; | 8 import android.os.Handler; |
| 9 import android.os.Looper; | 9 import android.os.Looper; |
| 10 import android.os.Process; | 10 import android.os.Process; |
| (...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 339 public byte[] getGlobalMetricsDeltas() { | 339 public byte[] getGlobalMetricsDeltas() { |
| 340 return nativeGetHistogramDeltas(); | 340 return nativeGetHistogramDeltas(); |
| 341 } | 341 } |
| 342 | 342 |
| 343 @Override | 343 @Override |
| 344 public int getEffectiveConnectionType() { | 344 public int getEffectiveConnectionType() { |
| 345 if (!mNetworkQualityEstimatorEnabled) { | 345 if (!mNetworkQualityEstimatorEnabled) { |
| 346 throw new IllegalStateException("Network quality estimator must be e nabled"); | 346 throw new IllegalStateException("Network quality estimator must be e nabled"); |
| 347 } | 347 } |
| 348 synchronized (mNetworkQualityLock) { | 348 synchronized (mNetworkQualityLock) { |
| 349 return mEffectiveConnectionType; | 349 return convertConnectionTypeToApiValue(mEffectiveConnectionType); |
| 350 } | 350 } |
| 351 } | 351 } |
| 352 | 352 |
| 353 @Override | 353 @Override |
| 354 public int getHttpRttMs() { | 354 public int getHttpRttMs() { |
| 355 if (!mNetworkQualityEstimatorEnabled) { | 355 if (!mNetworkQualityEstimatorEnabled) { |
| 356 throw new IllegalStateException("Network quality estimator must be e nabled"); | 356 throw new IllegalStateException("Network quality estimator must be e nabled"); |
| 357 } | 357 } |
| 358 synchronized (mNetworkQualityLock) { | 358 synchronized (mNetworkQualityLock) { |
| 359 return mHttpRttMs; | 359 return mHttpRttMs != RttThroughputValues.INVALID_RTT_THROUGHPUT |
| 360 ? mHttpRttMs | |
| 361 : CONNECTION_METRIC_UNKNOWN; | |
| 360 } | 362 } |
| 361 } | 363 } |
| 362 | 364 |
| 363 @Override | 365 @Override |
| 364 public int getTransportRttMs() { | 366 public int getTransportRttMs() { |
| 365 if (!mNetworkQualityEstimatorEnabled) { | 367 if (!mNetworkQualityEstimatorEnabled) { |
| 366 throw new IllegalStateException("Network quality estimator must be e nabled"); | 368 throw new IllegalStateException("Network quality estimator must be e nabled"); |
| 367 } | 369 } |
| 368 synchronized (mNetworkQualityLock) { | 370 synchronized (mNetworkQualityLock) { |
| 369 return mTransportRttMs; | 371 return mTransportRttMs != RttThroughputValues.INVALID_RTT_THROUGHPUT |
| 372 ? mTransportRttMs | |
| 373 : CONNECTION_METRIC_UNKNOWN; | |
| 370 } | 374 } |
| 371 } | 375 } |
| 372 | 376 |
| 373 @Override | 377 @Override |
| 374 public int getDownstreamThroughputKbps() { | 378 public int getDownstreamThroughputKbps() { |
| 375 if (!mNetworkQualityEstimatorEnabled) { | 379 if (!mNetworkQualityEstimatorEnabled) { |
| 376 throw new IllegalStateException("Network quality estimator must be e nabled"); | 380 throw new IllegalStateException("Network quality estimator must be e nabled"); |
| 377 } | 381 } |
| 378 synchronized (mNetworkQualityLock) { | 382 synchronized (mNetworkQualityLock) { |
| 379 return mDownstreamThroughputKbps; | 383 return mDownstreamThroughputKbps != RttThroughputValues.INVALID_RTT_ THROUGHPUT |
| 384 ? mDownstreamThroughputKbps | |
| 385 : CONNECTION_METRIC_UNKNOWN; | |
| 380 } | 386 } |
| 381 } | 387 } |
| 382 | 388 |
| 383 @VisibleForTesting | 389 @VisibleForTesting |
| 384 @Override | 390 @Override |
| 385 public void configureNetworkQualityEstimatorForTesting( | 391 public void configureNetworkQualityEstimatorForTesting( |
| 386 boolean useLocalHostRequests, boolean useSmallerResponses) { | 392 boolean useLocalHostRequests, boolean useSmallerResponses) { |
| 387 if (!mNetworkQualityEstimatorEnabled) { | 393 if (!mNetworkQualityEstimatorEnabled) { |
| 388 throw new IllegalStateException("Network quality estimator must be e nabled"); | 394 throw new IllegalStateException("Network quality estimator must be e nabled"); |
| 389 } | 395 } |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 545 if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) { | 551 if (Log.isLoggable(LOG_TAG, Log.VERBOSE)) { |
| 546 loggingLevel = LOG_VERBOSE; | 552 loggingLevel = LOG_VERBOSE; |
| 547 } else if (Log.isLoggable(LOG_TAG, Log.DEBUG)) { | 553 } else if (Log.isLoggable(LOG_TAG, Log.DEBUG)) { |
| 548 loggingLevel = LOG_DEBUG; | 554 loggingLevel = LOG_DEBUG; |
| 549 } else { | 555 } else { |
| 550 loggingLevel = LOG_NONE; | 556 loggingLevel = LOG_NONE; |
| 551 } | 557 } |
| 552 return loggingLevel; | 558 return loggingLevel; |
| 553 } | 559 } |
| 554 | 560 |
| 561 private static int convertConnectionTypeToApiValue( | |
| 562 @EffectiveConnectionType.EffectiveConnectionTypeEnum int type) { | |
| 563 switch (type) { | |
| 564 case EffectiveConnectionType.TYPE_OFFLINE: | |
| 565 return EFFECTIVE_CONNECTION_TYPE_OFFLINE; | |
| 566 case EffectiveConnectionType.TYPE_SLOW_2G: | |
| 567 return EFFECTIVE_CONNECTION_TYPE_SLOW_2G; | |
| 568 case EffectiveConnectionType.TYPE_2G: | |
| 569 return EFFECTIVE_CONNECTION_TYPE_2G; | |
| 570 case EffectiveConnectionType.TYPE_3G: | |
| 571 return EFFECTIVE_CONNECTION_TYPE_3G; | |
| 572 case EffectiveConnectionType.TYPE_4G: | |
| 573 return EFFECTIVE_CONNECTION_TYPE_4G; | |
| 574 default: | |
| 575 return EFFECTIVE_CONNECTION_TYPE_UNKNOWN; | |
|
pauljensen
2016/11/11 15:13:23
can we change this to:
case EffectiveConnectionT
kapishnikov
2016/11/11 16:55:22
Good idea! Done.
| |
| 576 } | |
| 577 } | |
| 578 | |
| 555 @SuppressWarnings("unused") | 579 @SuppressWarnings("unused") |
| 556 @CalledByNative | 580 @CalledByNative |
| 557 private void initNetworkThread() { | 581 private void initNetworkThread() { |
| 558 mNetworkThread = Thread.currentThread(); | 582 mNetworkThread = Thread.currentThread(); |
| 559 mInitCompleted.open(); | 583 mInitCompleted.open(); |
| 560 Thread.currentThread().setName("ChromiumNet"); | 584 Thread.currentThread().setName("ChromiumNet"); |
| 561 Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); | 585 Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
| 562 } | 586 } |
| 563 | 587 |
| 564 @SuppressWarnings("unused") | 588 @SuppressWarnings("unused") |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 695 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 719 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 696 private native void nativeProvideRTTObservations(long nativePtr, boolean sho uld); | 720 private native void nativeProvideRTTObservations(long nativePtr, boolean sho uld); |
| 697 | 721 |
| 698 @NativeClassQualifiedName("CronetURLRequestContextAdapter") | 722 @NativeClassQualifiedName("CronetURLRequestContextAdapter") |
| 699 private native void nativeProvideThroughputObservations(long nativePtr, bool ean should); | 723 private native void nativeProvideThroughputObservations(long nativePtr, bool ean should); |
| 700 | 724 |
| 701 public boolean isNetworkThread(Thread thread) { | 725 public boolean isNetworkThread(Thread thread) { |
| 702 return thread == mNetworkThread; | 726 return thread == mNetworkThread; |
| 703 } | 727 } |
| 704 } | 728 } |
| OLD | NEW |