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

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/net/qualityprovider/NetworkQualityProviderHelper.java

Issue 1235373006: Upstream changes for NetworkQualityProvider (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Removed context Created 5 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 side-by-side diff with in-line comments
Download patch
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;
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698