Ensure Java DistilledPagePrefs observers can only be added once.
The Java DistilledPagePrefs observers are wrapped in a native observer, which is only deleted when the observer is removed again. Since the reference to this native observer wrapper is kept in a Java map with the real Java observer as the key, the second time addObserver(foo) is called with the same observer, the first reference is lost, and the native object is leaked. For example, the following would leak a native object: addObserver(foo); addObserver(foo); removeObserver(foo); removeObserver(foo); It is already safe to remove an observer if it is not currently an observer, and this CL ensures that an observer can only be added once, so the second calls to addObserver(foo) and removeObserver(foo) will be no-ops. addObserver and removeObserver will return a boolean based on whether they have successfully completed the operation. BUG=383630 Review URL: https://codereview.chromium.org/426153006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287911 0039d316-1c4b-4281-b951-d872f2087c98
Showing
Please register or sign in to comment