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

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: Addressed bengr comments 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..ba41612c71218b77ff8c18df7ca4cd4b5b36670f
--- /dev/null
+++ b/chrome/android/java/src/org/chromium/chrome/browser/net/qualityprovider/NetworkQualityProviderHelper.java
@@ -0,0 +1,98 @@
+// 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 {
nyquist 2015/07/22 14:47:00 This class can not be instantiated externally, and
tbansal1 2015/07/22 21:11:30 Done.
+ private static Context sContext = null;
+ private static NonThreadSafe sThreadCheck = null;
+
+ private NetworkQualityProviderHelper() {}
+
+ @CalledByNative
+ private static NetworkQualityProviderHelper create(Context context) {
nyquist 2015/07/22 14:47:00 Why is this class here instead of just using the N
tbansal1 2015/07/22 21:11:30 OK, seems like my understanding is incorrect. I th
nyquist 2015/07/22 21:42:44 I don't know what your plan was for who should own
+ 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;
+
+ final NetworkQualityProvider networkQualityProvider =
nyquist 2015/07/22 14:47:00 Why not store this reference in the constructor in
tbansal1 2015/07/22 21:11:29 Good idea, Done.
+ ((ChromeApplication) sContext).getNetworkQualityProvider();
+ return networkQualityProvider.isEstimateAvailable();
+ }
+
+ @CalledByNative
+ private static int getRTTMilliseconds() {
+ assert sThreadCheck.calledOnValidThread();
+ if (sContext == null) return NetworkQualityProvider.NO_VALUE;
+
+ final NetworkQualityProvider networkQualityProvider =
nyquist 2015/07/22 14:47:00 Nit: Unnecessary final throughout this class.
tbansal1 2015/07/22 21:11:30 Done.
+ ((ChromeApplication) sContext).getNetworkQualityProvider();
+ return networkQualityProvider.getRTTMilliseconds();
+ }
+
+ @CalledByNative
+ private static int getDownstreamThroughputKbps() {
+ assert sThreadCheck.calledOnValidThread();
+ if (sContext == null) return NetworkQualityProvider.NO_VALUE;
+
+ final NetworkQualityProvider networkQualityProvider =
+ ((ChromeApplication) sContext).getNetworkQualityProvider();
+ return convertLongToInt(networkQualityProvider.getDownstreamThroughputKbps());
+ }
+
+ @CalledByNative
+ private static int getUpstreamThroughputKbps() {
+ assert sThreadCheck.calledOnValidThread();
+ if (sContext == null) return NetworkQualityProvider.NO_VALUE;
+
+ final NetworkQualityProvider networkQualityProvider =
+ ((ChromeApplication) sContext).getNetworkQualityProvider();
+ return convertLongToInt(networkQualityProvider.getUpstreamThroughputKbps());
+ }
+
+ @CalledByNative
+ private static int getTimeSinceLastUpdateSeconds() {
+ assert sThreadCheck.calledOnValidThread();
+ if (sContext == null) return NetworkQualityProvider.NO_VALUE;
+
+ final NetworkQualityProvider networkQualityProvider =
+ ((ChromeApplication) sContext).getNetworkQualityProvider();
+ return convertLongToInt(networkQualityProvider.getTimeSinceLastUpdateSeconds());
+ }
+
+ @CalledByNative
+ private static int getNoValue() {
+ assert sThreadCheck.calledOnValidThread();
+ return NetworkQualityProvider.NO_VALUE;
+ }
+
+ 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