Chromium Code Reviews| Index: chrome/android/java/src/org/chromium/chrome/browser/net/qualityprovider/NetworkQualityProviderHelper.java |
| diff --git a/chrome/android/java/src/org/chromium/chrome/browser/net/qualityprovider/NetworkQualityProviderHelper.java b/chrome/android/java/src/org/chromium/chrome/browser/net/qualityprovider/NetworkQualityProviderHelper.java |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..824c4722f2128873b53803ecba07d8fb6ad7dd08 |
| --- /dev/null |
| +++ b/chrome/android/java/src/org/chromium/chrome/browser/net/qualityprovider/NetworkQualityProviderHelper.java |
| @@ -0,0 +1,92 @@ |
| +// Copyright 2015 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +package org.chromium.chrome.browser.net.qualityprovider; |
| + |
| +import android.content.Context; |
| + |
| +import org.chromium.base.CalledByNative; |
| +import org.chromium.chrome.browser.ChromeApplication; |
| +import org.chromium.chrome.browser.util.NonThreadSafe; |
| + |
| +/** |
| + * This class is responsible for helping the native code communicate with the APIs provided by |
| + * the operating system through NetworkQualityProvider. |
| + */ |
| +public class NetworkQualityProviderHelper { |
| + private static Context sContext = null; |
| + private static NonThreadSafe sThreadCheck = null; |
| + |
| + private NetworkQualityProviderHelper() {} |
| + |
| + @CalledByNative |
| + private static NetworkQualityProviderHelper create(Context context) { |
| + assert sThreadCheck == null; |
| + assert sContext == null; |
| + assert context != null; |
| + sThreadCheck = new NonThreadSafe(); |
| + sContext = context; |
| + return new NetworkQualityProviderHelper(); |
| + } |
| + |
| + @CalledByNative |
| + private static boolean isEstimateAvailable() { |
| + assert sThreadCheck.calledOnValidThread(); |
| + if (sContext == null) return false; |
|
bengr
2015/07/21 00:06:48
Braces, on every if statement.
tbansal1
2015/07/21 16:18:25
Please see the reply on the other file.
|
| + |
| + final NetworkQualityProvider networkQualityProvider = |
| + ((ChromeApplication) sContext).getNetworkQualityProvider(); |
| + return networkQualityProvider.isEstimateAvailable(); |
| + } |
| + |
| + @CalledByNative |
| + private static int getRTTMilliseconds() { |
| + assert sThreadCheck.calledOnValidThread(); |
| + if (sContext == null) return 0; |
| + |
| + final NetworkQualityProvider networkQualityProvider = |
| + ((ChromeApplication) sContext).getNetworkQualityProvider(); |
| + return networkQualityProvider.getRTTMilliseconds(); |
| + } |
| + |
| + @CalledByNative |
| + private static int getDownstreamThroughputKbps() { |
| + assert sThreadCheck.calledOnValidThread(); |
| + if (sContext == null) return 0; |
| + |
| + final NetworkQualityProvider networkQualityProvider = |
| + ((ChromeApplication) sContext).getNetworkQualityProvider(); |
| + return convertLongToInt(networkQualityProvider.getDownstreamThroughputKbps()); |
| + } |
| + |
| + @CalledByNative |
| + private static int getUpstreamThroughputKbps() { |
| + assert sThreadCheck.calledOnValidThread(); |
| + if (sContext == null) return 0; |
| + |
| + final NetworkQualityProvider networkQualityProvider = |
| + ((ChromeApplication) sContext).getNetworkQualityProvider(); |
| + return convertLongToInt(networkQualityProvider.getUpstreamThroughputKbps()); |
| + } |
| + |
| + @CalledByNative |
| + private static int getTimeSinceLastUpdateSeconds() { |
| + assert sThreadCheck.calledOnValidThread(); |
| + if (sContext == null) return 0; |
| + |
| + final NetworkQualityProvider networkQualityProvider = |
| + ((ChromeApplication) sContext).getNetworkQualityProvider(); |
| + return convertLongToInt(networkQualityProvider.getTimeSinceLastUpdateSeconds()); |
| + } |
| + |
| + private static int convertLongToInt(long value) { |
| + if (value > Integer.MAX_VALUE) { |
| + return Integer.MAX_VALUE; |
| + } |
| + if (value < Integer.MIN_VALUE) { |
| + return Integer.MIN_VALUE; |
| + } |
| + return (int) value; |
| + } |
| +} |