summaryrefslogtreecommitdiff
path: root/core/fxcrt/include/cfx_observable.h
diff options
context:
space:
mode:
authortsepez <tsepez@chromium.org>2016-09-08 10:25:55 -0700
committerCommit bot <commit-bot@chromium.org>2016-09-08 10:25:55 -0700
commit8832fbf53cf71d4d4cb53986d9cfc024edd2bf1f (patch)
tree00e9dbcc91f89f95552bac3326ac828f8b495507 /core/fxcrt/include/cfx_observable.h
parentd827111fb10c7d8b89bc954ab0934b4009d6643c (diff)
downloadpdfium-8832fbf53cf71d4d4cb53986d9cfc024edd2bf1f.tar.xz
Replace CJS_Runtime::Observer with CFX_Runtime<CJS_Runtime>::Observer
Previously, the observer set a flag which conditionalized a null pointer return. Now, we just clear the pointer. Destruction order matters, so add a method to trigger notifications. Review-Url: https://codereview.chromium.org/2322743002
Diffstat (limited to 'core/fxcrt/include/cfx_observable.h')
-rw-r--r--core/fxcrt/include/cfx_observable.h10
1 files changed, 6 insertions, 4 deletions
diff --git a/core/fxcrt/include/cfx_observable.h b/core/fxcrt/include/cfx_observable.h
index b669e0d3d5..99a9951284 100644
--- a/core/fxcrt/include/cfx_observable.h
+++ b/core/fxcrt/include/cfx_observable.h
@@ -45,10 +45,7 @@ class CFX_Observable {
CFX_Observable() {}
CFX_Observable(const CFX_Observable& that) = delete;
- ~CFX_Observable() {
- for (auto* pObserver : m_Observers)
- pObserver->OnDestroy();
- }
+ ~CFX_Observable() { NotifyObservers(); }
void AddObserver(Observer* pObserver) {
ASSERT(!pdfium::ContainsKey(m_Observers, pObserver));
m_Observers.insert(pObserver);
@@ -57,6 +54,11 @@ class CFX_Observable {
ASSERT(pdfium::ContainsKey(m_Observers, pObserver));
m_Observers.erase(pObserver);
}
+ void NotifyObservers() {
+ for (auto* pObserver : m_Observers)
+ pObserver->OnDestroy();
+ m_Observers.clear();
+ }
CFX_Observable& operator=(const CFX_Observable& that) = delete;
private: