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

Unified Diff: base/android/java/src/org/chromium/base/ObserverList.java

Issue 182623003: ObserverList add/remove methods should return a boolean. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@screen_orientation_listener
Patch Set: rebase Created 6 years, 9 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
« no previous file with comments | « no previous file | base/android/javatests/src/org/chromium/base/ObserverListTest.java » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/android/java/src/org/chromium/base/ObserverList.java
diff --git a/base/android/java/src/org/chromium/base/ObserverList.java b/base/android/java/src/org/chromium/base/ObserverList.java
index f12a2e1faa9eed6f1e17234f34708d03d4f1558d..d10dc6a0ce1d0fa0e859bc47632b435a22cfa533 100644
--- a/base/android/java/src/org/chromium/base/ObserverList.java
+++ b/base/android/java/src/org/chromium/base/ObserverList.java
@@ -53,27 +53,30 @@ public class ObserverList<E> implements Iterable<E> {
* <p/>
* An observer should not be added to the same list more than once. If an iteration is already
* in progress, this observer will be not be visible during that iteration.
+ *
+ * @return true if the observer list changed as a result of the call.
*/
- public void addObserver(E obs) {
+ public boolean addObserver(E obs) {
// Avoid adding null elements to the list as they may be removed on a compaction.
if (obs == null || mObservers.contains(obs)) {
- assert false;
- return;
+ return false;
}
// Structurally modifying the underlying list here. This means we
// cannot use the underlying list's iterator to iterate over the list.
- mObservers.add(obs);
+ return mObservers.add(obs);
}
/**
* Remove an observer from the list if it is in the list.
+ *
+ * @return true if an element was removed as a result of this call.
*/
- public void removeObserver(E obs) {
+ public boolean removeObserver(E obs) {
int index = mObservers.indexOf(obs);
if (index == -1)
- return;
+ return false;
if (mIterationDepth == 0) {
// No one is iterating over the list.
@@ -81,6 +84,8 @@ public class ObserverList<E> implements Iterable<E> {
} else {
mObservers.set(index, null);
}
+
+ return true;
}
public boolean hasObserver(E obs) {
« no previous file with comments | « no previous file | base/android/javatests/src/org/chromium/base/ObserverListTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698