diff options
author | nileshagrawal@chromium.org <nileshagrawal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-05 04:12:44 +0000 |
---|---|---|
committer | nileshagrawal@chromium.org <nileshagrawal@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-03-05 04:12:44 +0000 |
commit | 2fb7f01bfe274a1571735967b03fee926d920b2a (patch) | |
tree | cf93929e670ae1dba1b30aa6332217b333782b7a /net/android | |
parent | 618bec8b95a6f7b26e912b8aff677aef3aef2403 (diff) | |
download | chromium_src-2fb7f01bfe274a1571735967b03fee926d920b2a.zip chromium_src-2fb7f01bfe274a1571735967b03fee926d920b2a.tar.gz chromium_src-2fb7f01bfe274a1571735967b03fee926d920b2a.tar.bz2 |
Android: Use ObserverList to maintain a list of observers/listeners
Using ObserverList allows for observers adding/removing themselves/others while they are being notified, in a safe way
BUG=
Review URL: https://chromiumcodereview.appspot.com/12388057
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@186090 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/android')
-rw-r--r-- | net/android/java/src/org/chromium/net/NetworkChangeNotifier.java | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java b/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java index b161a86..58360b4 100644 --- a/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java +++ b/net/android/java/src/org/chromium/net/NetworkChangeNotifier.java @@ -9,9 +9,9 @@ import android.content.Context; import org.chromium.base.CalledByNative; import org.chromium.base.JNINamespace; import org.chromium.base.NativeClassQualifiedName; +import org.chromium.base.ObserverList; import java.util.ArrayList; -import java.util.concurrent.CopyOnWriteArrayList; /** * Triggers updates to the underlying network state in Chrome. @@ -44,7 +44,7 @@ public class NetworkChangeNotifier { private final Context mContext; private final ArrayList<Integer> mNativeChangeNotifiers; - private final CopyOnWriteArrayList<ConnectionTypeObserver> mConnectionTypeObservers; + private final ObserverList<ConnectionTypeObserver> mConnectionTypeObservers; private NetworkChangeNotifierAutoDetect mAutoDetector; private int mCurrentConnectionType = CONNECTION_UNKNOWN; @@ -53,7 +53,7 @@ public class NetworkChangeNotifier { private NetworkChangeNotifier(Context context) { mContext = context; mNativeChangeNotifiers = new ArrayList<Integer>(); - mConnectionTypeObservers = new CopyOnWriteArrayList<ConnectionTypeObserver>(); + mConnectionTypeObservers = new ObserverList<ConnectionTypeObserver>(); } /** @@ -183,20 +183,20 @@ public class NetworkChangeNotifier { } private void addConnectionTypeObserverInternal(ConnectionTypeObserver observer) { - if (!mConnectionTypeObservers.contains(observer)) { - mConnectionTypeObservers.add(observer); + if (!mConnectionTypeObservers.hasObserver(observer)) { + mConnectionTypeObservers.addObserver(observer); } } /** * Removes an observer for any connection type changes. */ - public static boolean removeConnectionTypeObserver(ConnectionTypeObserver observer) { - return getInstance().removeConnectionTypeObserverInternal(observer); + public static void removeConnectionTypeObserver(ConnectionTypeObserver observer) { + getInstance().removeConnectionTypeObserverInternal(observer); } - private boolean removeConnectionTypeObserverInternal(ConnectionTypeObserver observer) { - return mConnectionTypeObservers.remove(observer); + private void removeConnectionTypeObserverInternal(ConnectionTypeObserver observer) { + mConnectionTypeObservers.removeObserver(observer); } @NativeClassQualifiedName("NetworkChangeNotifierDelegateAndroid") |