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

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

Issue 10928193: Add native-side unit test for Android NetworkChangeNotifier (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebasing Created 8 years, 3 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: 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..7f1bdc32ed0305e744b6e0af65b0e5aebf6e7297 100644
--- a/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java
+++ b/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java
@@ -42,7 +42,41 @@ public class NetworkChangeNotifier {
mContext = context;
mNativeChangeNotifier = nativeChangeNotifier;
mConnectionType = CONNECTION_UNKNOWN;
- sInstance = this;
+ }
+
+ private void destroy() {
+ if (mAutoDetector != null) {
+ mAutoDetector.destroy();
+ }
+ mNativeChangeNotifier = 0;
+ }
+
+ /**
+ * Creates the singleton used by the native-side NetworkChangeNotifier.
+ */
+ @CalledByNative
+ static NetworkChangeNotifier createInstance(Context context, int nativeChangeNotifier) {
+ assert sInstance == null;
+ sInstance = new NetworkChangeNotifier(context, nativeChangeNotifier);
+ return sInstance;
+ }
+
+ /**
+ * Destroys the singleton used by the native-side NetworkChangeNotifier.
+ */
+ @CalledByNative
+ private static void destroyInstance() {
+ assert sInstance != null;
+ sInstance.destroy();
+ sInstance = null;
+ }
+
+ /**
+ * Returns the instance used by the native-side NetworkChangeNotifier.
+ */
+ public static NetworkChangeNotifier getInstance() {
+ assert sInstance != null;
+ return sInstance;
}
/**
@@ -80,6 +114,7 @@ public class NetworkChangeNotifier {
* @param networkAvailable True if the NetworkChangeNotifier should
* perceive a "connected" state, false implies "disconnected".
*/
+ @CalledByNative
public static void forceConnectivityState(boolean networkAvailable) {
assert sInstance != null;
setAutoDetectConnectivityState(false);
@@ -90,13 +125,13 @@ public class NetworkChangeNotifier {
boolean connectionCurrentlyExists = mConnectionType != CONNECTION_NONE;
if (connectionCurrentlyExists != forceOnline) {
mConnectionType = forceOnline ? CONNECTION_UNKNOWN : CONNECTION_NONE;
- notifyNativeObservers();
+ notifyObserversOfConnectionTypeChange();
}
}
- void notifyNativeObservers() {
+ void notifyObserversOfConnectionTypeChange() {
if (mNativeChangeNotifier != 0) {
- nativeNotifyObservers(mNativeChangeNotifier);
+ nativeNotifyObserversOfConnectionTypeChange(mNativeChangeNotifier);
}
}
@@ -108,25 +143,12 @@ public class NetworkChangeNotifier {
return mConnectionType;
}
- @CalledByNative
- private void destroy() {
- if (mAutoDetector != null) {
- mAutoDetector.destroy();
- }
- mNativeChangeNotifier = 0;
- sInstance = null;
- }
-
- @CalledByNative
- private static NetworkChangeNotifier create(Context context, int nativeNetworkChangeNotifier) {
- return new NetworkChangeNotifier(context, nativeNetworkChangeNotifier);
- }
-
- @NativeClassQualifiedName("android::NetworkChangeNotifier")
- private native void nativeNotifyObservers(int nativePtr);
+ @NativeClassQualifiedName("NetworkChangeNotifierAndroid")
+ private native void nativeNotifyObserversOfConnectionTypeChange(int nativePtr);
// For testing only.
public static NetworkChangeNotifierAutoDetect getAutoDetectorForTest() {
+ assert sInstance != null;
return sInstance.mAutoDetector;
}
}
« no previous file with comments | « content/shell/shell_browser_main_parts.cc ('k') | net/android/java/src/org/chromium/net/NetworkChangeNotifierAutoDetect.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698