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

Unified Diff: net/android/java/src/org/chromium/net/NetworkChangeNotifier.java

Issue 780293003: [NetInfo] Add MaxBandwidthChanged notification and implement on Android (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@maxbandwidth_android
Patch Set: Don't monitor RSSI if there is no permission to act on it Created 6 years 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: net/android/java/src/org/chromium/net/NetworkChangeNotifier.java
diff --git a/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java b/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java
index 928af78e55e7a201e7fedc8b752fefee40a6b4a8..34c7c5a2fd53c8f07f5c30bbc5c1da1adb1845b5 100644
--- a/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java
+++ b/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java
@@ -147,14 +147,17 @@ public class NetworkChangeNotifier {
new NetworkChangeNotifierAutoDetect.Observer() {
@Override
public void onConnectionTypeChanged(int newConnectionType) {
- updateCurrentMaxBandwidth(mAutoDetector.getCurrentMaxBandwidthInMbps());
updateCurrentConnectionType(newConnectionType);
}
+ @Override
+ public void onMaxBandwidthChanged(double maxBandwidthMbps) {
+ updateCurrentMaxBandwidth(maxBandwidthMbps);
+ }
},
mContext,
alwaysWatchForChanges);
- updateCurrentMaxBandwidth(mAutoDetector.getCurrentMaxBandwidthInMbps());
updateCurrentConnectionType(mAutoDetector.getCurrentConnectionType());
+ updateCurrentMaxBandwidth(mAutoDetector.getCurrentMaxBandwidthInMbps());
}
} else {
destroyAutoDetector();
@@ -177,9 +180,9 @@ public class NetworkChangeNotifier {
boolean connectionCurrentlyExists =
mCurrentConnectionType != ConnectionType.CONNECTION_NONE;
if (connectionCurrentlyExists != forceOnline) {
- updateCurrentMaxBandwidth(forceOnline ? Double.POSITIVE_INFINITY : 0.0);
updateCurrentConnectionType(forceOnline ? ConnectionType.CONNECTION_UNKNOWN
: ConnectionType.CONNECTION_NONE);
+ updateCurrentMaxBandwidth(forceOnline ? Double.POSITIVE_INFINITY : 0.0);
}
}
@@ -188,8 +191,10 @@ public class NetworkChangeNotifier {
notifyObserversOfConnectionTypeChange(newConnectionType);
}
- private void updateCurrentMaxBandwidth(double maxBandwidth) {
- mCurrentMaxBandwidth = maxBandwidth;
+ private void updateCurrentMaxBandwidth(double maxBandwidthMbps) {
+ if (maxBandwidthMbps == mCurrentMaxBandwidth) return;
+ mCurrentMaxBandwidth = maxBandwidthMbps;
+ notifyObserversOfMaxBandwidthChange(maxBandwidthMbps);
}
/**
@@ -205,6 +210,16 @@ public class NetworkChangeNotifier {
}
/**
+ * Alerts all observers of a bandwidth change.
+ */
+ void notifyObserversOfMaxBandwidthChange(double maxBandwidthMbps) {
+ for (Long nativeChangeNotifier : mNativeChangeNotifiers) {
+ nativeNotifyMaxBandwidthChanged(nativeChangeNotifier, maxBandwidthMbps);
+ }
+ }
+
+
+ /**
* Adds an observer for any connection type changes.
*/
public static void addConnectionTypeObserver(ConnectionTypeObserver observer) {
@@ -229,6 +244,9 @@ public class NetworkChangeNotifier {
@NativeClassQualifiedName("NetworkChangeNotifierDelegateAndroid")
private native void nativeNotifyConnectionTypeChanged(long nativePtr, int newConnectionType);
+ @NativeClassQualifiedName("NetworkChangeNotifierDelegateAndroid")
+ private native void nativeNotifyMaxBandwidthChanged(long nativePtr, double maxBandwidthMbps);
+
private static native double nativeGetMaxBandwidthForConnectionSubtype(int subtype);
// For testing only.

Powered by Google App Engine
This is Rietveld 408576698