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

Unified Diff: components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/DistilledPagePrefs.java

Issue 426153006: Ensure Java DistilledPagePrefs observers can only be added once. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: styling Created 6 years, 4 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 | « chrome/android/javatests/src/org/chromium/chrome/browser/dom_distiller/DistilledPagePrefsTest.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/DistilledPagePrefs.java
diff --git a/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/DistilledPagePrefs.java b/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/DistilledPagePrefs.java
index d69d4fb8adaaa486d85fe3872f551ad39c4dfd74..3ba9f7ea82d8c7facdf39e2a982de411cd0d1a03 100644
--- a/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/DistilledPagePrefs.java
+++ b/components/dom_distiller/android/java/src/org/chromium/components/dom_distiller/core/DistilledPagePrefs.java
@@ -65,19 +65,29 @@ public final class DistilledPagePrefs {
mObserverMap = new HashMap<Observer, DistilledPagePrefsObserverWrapper>();
}
- public void addObserver(Observer obs) {
+ /*
+ * Adds the observer to listen to changes in DistilledPagePrefs.
+ * @return whether the observerMap was changed as a result of the call.
+ */
+ public boolean addObserver(Observer obs) {
+ if (mObserverMap.containsKey(obs)) return false;
DistilledPagePrefsObserverWrapper wrappedObserver =
new DistilledPagePrefsObserverWrapper(obs);
nativeAddObserver(mDistilledPagePrefsAndroid, wrappedObserver.getNativePtr());
mObserverMap.put(obs, wrappedObserver);
+ return true;
}
- public void removeObserver(Observer obs) {
+ /*
+ * Removes the observer and unregisters it from DistilledPagePrefs changes.
+ * @return whether the observer was removed as a result of the call.
+ */
+ public boolean removeObserver(Observer obs) {
DistilledPagePrefsObserverWrapper wrappedObserver = mObserverMap.remove(obs);
- if (wrappedObserver != null) {
- nativeRemoveObserver(mDistilledPagePrefsAndroid, wrappedObserver.getNativePtr());
- wrappedObserver.destroy();
- }
+ if (wrappedObserver == null) return false;
+ nativeRemoveObserver(mDistilledPagePrefsAndroid, wrappedObserver.getNativePtr());
+ wrappedObserver.destroy();
+ return true;
}
public void setTheme(Theme theme) {
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/dom_distiller/DistilledPagePrefsTest.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698