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

Unified Diff: core/fxcrt/include/cfx_observable.h

Issue 2382723003: Move core/fxcrt/include to core/fxcrt (Closed)
Patch Set: Rebase to master Created 4 years, 3 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 | « core/fxcrt/include/cfx_count_ref.h ('k') | core/fxcrt/include/cfx_retain_ptr.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: core/fxcrt/include/cfx_observable.h
diff --git a/core/fxcrt/include/cfx_observable.h b/core/fxcrt/include/cfx_observable.h
deleted file mode 100644
index a5053f3952d09ccd2b994410ffdf123494112f61..0000000000000000000000000000000000000000
--- a/core/fxcrt/include/cfx_observable.h
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2016 PDFium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef CORE_FXCRT_INCLUDE_CFX_OBSERVABLE_H_
-#define CORE_FXCRT_INCLUDE_CFX_OBSERVABLE_H_
-
-#include <set>
-
-#include "core/fxcrt/include/fx_system.h"
-#include "third_party/base/stl_util.h"
-
-template <class T>
-class CFX_Observable {
- public:
- class ObservedPtr {
- public:
- ObservedPtr() : m_pObservedPtr(nullptr) {}
- explicit ObservedPtr(T* pObservedPtr) : m_pObservedPtr(pObservedPtr) {
- if (m_pObservedPtr)
- m_pObservedPtr->AddObservedPtr(this);
- }
- ObservedPtr(const ObservedPtr& that) = delete;
- ~ObservedPtr() {
- if (m_pObservedPtr)
- m_pObservedPtr->RemoveObservedPtr(this);
- }
- void Reset(T* pObservedPtr = nullptr) {
- if (m_pObservedPtr)
- m_pObservedPtr->RemoveObservedPtr(this);
- m_pObservedPtr = pObservedPtr;
- if (m_pObservedPtr)
- m_pObservedPtr->AddObservedPtr(this);
- }
- void OnDestroy() {
- ASSERT(m_pObservedPtr);
- m_pObservedPtr = nullptr;
- }
- ObservedPtr& operator=(const ObservedPtr& that) = delete;
- bool operator==(const ObservedPtr& that) const {
- return m_pObservedPtr == that.m_pObservedPtr;
- }
- bool operator!=(const ObservedPtr& that) const { return !(*this == that); }
- explicit operator bool() const { return !!m_pObservedPtr; }
- T* Get() const { return m_pObservedPtr; }
- T& operator*() const { return *m_pObservedPtr; }
- T* operator->() const { return m_pObservedPtr; }
-
- private:
- T* m_pObservedPtr;
- };
-
- CFX_Observable() {}
- CFX_Observable(const CFX_Observable& that) = delete;
- ~CFX_Observable() { NotifyObservedPtrs(); }
- void AddObservedPtr(ObservedPtr* pObservedPtr) {
- ASSERT(!pdfium::ContainsKey(m_ObservedPtrs, pObservedPtr));
- m_ObservedPtrs.insert(pObservedPtr);
- }
- void RemoveObservedPtr(ObservedPtr* pObservedPtr) {
- ASSERT(pdfium::ContainsKey(m_ObservedPtrs, pObservedPtr));
- m_ObservedPtrs.erase(pObservedPtr);
- }
- void NotifyObservedPtrs() {
- for (auto* pObservedPtr : m_ObservedPtrs)
- pObservedPtr->OnDestroy();
- m_ObservedPtrs.clear();
- }
- CFX_Observable& operator=(const CFX_Observable& that) = delete;
-
- protected:
- size_t ActiveObservedPtrsForTesting() const { return m_ObservedPtrs.size(); }
-
- private:
- std::set<ObservedPtr*> m_ObservedPtrs;
-};
-
-#endif // CORE_FXCRT_INCLUDE_CFX_OBSERVABLE_H_
« no previous file with comments | « core/fxcrt/include/cfx_count_ref.h ('k') | core/fxcrt/include/cfx_retain_ptr.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698