1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CC_BASE_REF_COUNTED_MANAGED_H_
6 #define CC_BASE_REF_COUNTED_MANAGED_H_
8 #include "base/logging.h"
9 #include "base/memory/ref_counted.h"
10 #include "cc/base/cc_export.h"
14 template <typename T
> class RefCountedManaged
;
17 class CC_EXPORT RefCountedManager
{
19 RefCountedManager() : live_object_count_(0) {}
20 ~RefCountedManager() {
21 CHECK_EQ(0, live_object_count_
);
24 virtual void Release(T
* object
) = 0;
27 friend class RefCountedManaged
<T
>;
28 int live_object_count_
;
32 class CC_EXPORT RefCountedManaged
: public base::subtle::RefCountedBase
{
34 explicit RefCountedManaged(RefCountedManager
<T
>* manager
)
36 manager_
->live_object_count_
++;
40 base::subtle::RefCountedBase::AddRef();
44 if (base::subtle::RefCountedBase::Release()) {
45 DCHECK_GT(manager_
->live_object_count_
, 0);
46 manager_
->live_object_count_
--;
48 // This must be the last statement in case manager deletes
49 // the object immediately.
50 manager_
->Release(static_cast<T
*>(this));
55 ~RefCountedManaged() {}
58 RefCountedManager
<T
>* manager_
;
60 DISALLOW_COPY_AND_ASSIGN(RefCountedManaged
<T
>);
65 #endif // CC_BASE_REF_COUNTED_MANAGED_H_