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 952123149a6de58cb51b377e47b13b802f8bbcca..9f1af9e96fba1ba336b64100a79043f977ce0568 100644 |
--- a/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java |
+++ b/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java |
@@ -31,7 +31,6 @@ public class NetworkChangeNotifier { |
private final Context mContext; |
private int mNativeChangeNotifier; |
- private int mConnectionType; |
private NetworkChangeNotifierAutoDetect mAutoDetector; |
private static NetworkChangeNotifier sInstance; |
@@ -41,7 +40,6 @@ public class NetworkChangeNotifier { |
private NetworkChangeNotifier(Context context, int nativeChangeNotifier) { |
mContext = context; |
mNativeChangeNotifier = nativeChangeNotifier; |
- mConnectionType = CONNECTION_UNKNOWN; |
sInstance = this; |
} |
@@ -60,16 +58,27 @@ public class NetworkChangeNotifier { |
sInstance.setAutoDetectConnectivityStateInternal(shouldAutoDetect); |
} |
+ private void destroyAutoDetector() { |
+ if (mAutoDetector != null) { |
+ mAutoDetector.destroy(); |
+ mAutoDetector = null; |
+ } |
+ } |
+ |
private void setAutoDetectConnectivityStateInternal(boolean shouldAutoDetect) { |
if (shouldAutoDetect) { |
if (mAutoDetector == null) { |
- mAutoDetector = new NetworkChangeNotifierAutoDetect(this, mContext); |
+ mAutoDetector = new NetworkChangeNotifierAutoDetect( |
+ new NetworkChangeNotifierAutoDetect.Observer() { |
+ @Override |
+ public void onConnectionTypeChanged(int newConnectionType) { |
+ notifyNativeObservers(newConnectionType); |
+ } |
+ }, |
+ mContext); |
} |
} else { |
- if (mAutoDetector != null) { |
- mAutoDetector.destroy(); |
- mAutoDetector = null; |
- } |
+ destroyAutoDetector(); |
} |
} |
@@ -87,32 +96,25 @@ public class NetworkChangeNotifier { |
} |
private void forceConnectivityStateInternal(boolean forceOnline) { |
- boolean connectionCurrentlyExists = mConnectionType != CONNECTION_NONE; |
+ if (mNativeChangeNotifier == 0) { |
+ return; |
+ } |
+ boolean connectionCurrentlyExists = |
+ nativeGetConnectionType(mNativeChangeNotifier) != CONNECTION_NONE; |
if (connectionCurrentlyExists != forceOnline) { |
- mConnectionType = forceOnline ? CONNECTION_UNKNOWN : CONNECTION_NONE; |
- notifyNativeObservers(); |
+ notifyNativeObservers(forceOnline ? CONNECTION_UNKNOWN : CONNECTION_NONE); |
} |
} |
- void notifyNativeObservers() { |
+ private void notifyNativeObservers(int newConnectionType) { |
if (mNativeChangeNotifier != 0) { |
- nativeNotifyObservers(mNativeChangeNotifier); |
+ nativeNotifyObservers(mNativeChangeNotifier, newConnectionType); |
} |
} |
@CalledByNative |
- private int connectionType() { |
- if (mAutoDetector != null) { |
- return mAutoDetector.connectionType(); |
- } |
- return mConnectionType; |
- } |
- |
- @CalledByNative |
private void destroy() { |
- if (mAutoDetector != null) { |
- mAutoDetector.destroy(); |
- } |
+ destroyAutoDetector(); |
mNativeChangeNotifier = 0; |
sInstance = null; |
} |
@@ -123,7 +125,10 @@ public class NetworkChangeNotifier { |
} |
@NativeClassQualifiedName("android::NetworkChangeNotifier") |
- private native void nativeNotifyObservers(int nativePtr); |
+ private native void nativeNotifyObservers(int nativePtr, int newConnectionType); |
+ |
+ @NativeClassQualifiedName("android::NetworkChangeNotifier") |
+ private native int nativeGetConnectionType(int nativePtr); |
// For testing only. |
public static NetworkChangeNotifierAutoDetect getAutoDetectorForTest() { |