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

Unified Diff: cc/base/ref_counted_managed.h

Issue 1127253002: Revert "cc: Remove Tile refcounting and RefCountedManaged." (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 | « cc/base/BUILD.gn ('k') | cc/cc.gyp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/base/ref_counted_managed.h
diff --git a/cc/base/ref_counted_managed.h b/cc/base/ref_counted_managed.h
new file mode 100644
index 0000000000000000000000000000000000000000..8bb836f015957ceecac9ee7d0e04193bb0ee3e91
--- /dev/null
+++ b/cc/base/ref_counted_managed.h
@@ -0,0 +1,65 @@
+// Copyright 2013 The Chromium 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 CC_BASE_REF_COUNTED_MANAGED_H_
+#define CC_BASE_REF_COUNTED_MANAGED_H_
+
+#include "base/logging.h"
+#include "base/memory/ref_counted.h"
+#include "cc/base/cc_export.h"
+
+namespace cc {
+
+template <typename T> class RefCountedManaged;
+
+template <typename T>
+class CC_EXPORT RefCountedManager {
+ protected:
+ RefCountedManager() : live_object_count_(0) {}
+ ~RefCountedManager() {
+ CHECK_EQ(0, live_object_count_);
+ }
+
+ virtual void Release(T* object) = 0;
+
+ private:
+ friend class RefCountedManaged<T>;
+ int live_object_count_;
+};
+
+template <typename T>
+class CC_EXPORT RefCountedManaged : public base::subtle::RefCountedBase {
+ public:
+ explicit RefCountedManaged(RefCountedManager<T>* manager)
+ : manager_(manager) {
+ manager_->live_object_count_++;
+ }
+
+ void AddRef() const {
+ base::subtle::RefCountedBase::AddRef();
+ }
+
+ void Release() {
+ if (base::subtle::RefCountedBase::Release()) {
+ DCHECK_GT(manager_->live_object_count_, 0);
+ manager_->live_object_count_--;
+
+ // This must be the last statement in case manager deletes
+ // the object immediately.
+ manager_->Release(static_cast<T*>(this));
+ }
+ }
+
+ protected:
+ ~RefCountedManaged() {}
+
+ private:
+ RefCountedManager<T>* manager_;
+
+ DISALLOW_COPY_AND_ASSIGN(RefCountedManaged<T>);
+};
+
+} // namespace cc
+
+#endif // CC_BASE_REF_COUNTED_MANAGED_H_
« no previous file with comments | « cc/base/BUILD.gn ('k') | cc/cc.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698