Chromium Code Reviews| 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 d540bc38e057ba3fed71cc63a6c4d35c5bbd4b15..6db4b0138ac40c825cfc99622a99a47cf812f283 100644 |
| --- a/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java |
| +++ b/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java |
| @@ -10,8 +10,10 @@ import org.chromium.base.CalledByNative; |
| import org.chromium.base.JNINamespace; |
| import org.chromium.base.NativeClassQualifiedName; |
| +import java.util.ArrayList; |
| + |
| /** |
| - * Triggers updates to the underlying network state in native Chrome. |
| + * Triggers updates to the underlying network state in Chrome. |
| * By default, connectivity is assumed and changes must pushed from |
| * the embedder via the forceConnectivityState function. |
| * Embedders may choose to have this class auto-detect changes in |
| @@ -20,6 +22,11 @@ import org.chromium.base.NativeClassQualifiedName; |
| */ |
| @JNINamespace("net") |
| public class NetworkChangeNotifier { |
| + /** Alerted when the connection type of the network changes. */ |
|
nilesh
2012/09/22 00:40:24
Please add a comment.
onConnectionTypeChanged will
gone
2012/09/24 18:28:24
Done.
|
| + public interface ConnectionTypeObserver { |
| + public void onConnectionTypeChanged(int connectionType); |
| + } |
| + |
| // These constants must always match the ones in network_change_notifier.h. |
| public static final int CONNECTION_UNKNOWN = 0; |
| public static final int CONNECTION_ETHERNET = 1; |
| @@ -31,15 +38,15 @@ public class NetworkChangeNotifier { |
| private final Context mContext; |
| private int mNativeChangeNotifier; |
| + private ArrayList<ConnectionTypeObserver> mConnectionTypeObservers; |
| private NetworkChangeNotifierAutoDetect mAutoDetector; |
| private static NetworkChangeNotifier sInstance; |
| - // Private constructor - instances are only created via the create factory |
| - // function, which is only called from native. |
| private NetworkChangeNotifier(Context context, int nativeChangeNotifier) { |
| mContext = context; |
| mNativeChangeNotifier = nativeChangeNotifier; |
| + mConnectionTypeObservers = new ArrayList<ConnectionTypeObserver>(); |
| } |
| private void destroy() { |
| @@ -47,6 +54,7 @@ public class NetworkChangeNotifier { |
| mAutoDetector.destroy(); |
| } |
| mNativeChangeNotifier = 0; |
| + mConnectionTypeObservers.clear(); |
| } |
| /** |
| @@ -142,10 +150,29 @@ public class NetworkChangeNotifier { |
| } |
| } |
| + /** |
| + * Alerts all observers of a connection change. |
| + */ |
| void notifyObserversOfConnectionTypeChange(int newConnectionType) { |
| if (mNativeChangeNotifier != 0) { |
| nativeNotifyObserversOfConnectionTypeChange(mNativeChangeNotifier, newConnectionType); |
| } |
| + |
| + for (ConnectionTypeObserver observer : mConnectionTypeObservers) { |
| + observer.onConnectionTypeChanged(newConnectionType); |
| + } |
| + } |
| + |
| + /** |
| + * Adds an observer for any connection type changes. |
| + */ |
| + public static void addConnectionTypeObserver(ConnectionTypeObserver observer) { |
|
nilesh
2012/09/22 00:40:24
No removeConnectionTypeObserver ?
I think this is
gone
2012/09/24 18:28:24
Done.
|
| + assert sInstance != null; |
| + sInstance.addConnectionTypeObserverInternal(observer); |
| + } |
| + |
| + private void addConnectionTypeObserverInternal(ConnectionTypeObserver observer) { |
| + mConnectionTypeObservers.add(observer); |
| } |
| @NativeClassQualifiedName("NetworkChangeNotifierAndroid") |