OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_REF_COUNTED_H_ | 5 #ifndef BASE_MEMORY_REF_COUNTED_H_ |
6 #define BASE_REF_COUNTED_H_ | 6 #define BASE_MEMORY_REF_COUNTED_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/atomic_ref_count.h" | 9 #include "base/atomic_ref_count.h" |
10 #include "base/base_api.h" | 10 #include "base/base_api.h" |
11 #include "base/threading/thread_collision_warner.h" | 11 #include "base/threading/thread_collision_warner.h" |
12 | 12 |
13 namespace base { | 13 namespace base { |
14 | 14 |
15 namespace subtle { | 15 namespace subtle { |
16 | 16 |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 static void DeleteInternal(const T* x) { delete x; } | 149 static void DeleteInternal(const T* x) { delete x; } |
150 | 150 |
151 DISALLOW_COPY_AND_ASSIGN(RefCountedThreadSafe); | 151 DISALLOW_COPY_AND_ASSIGN(RefCountedThreadSafe); |
152 }; | 152 }; |
153 | 153 |
154 // | 154 // |
155 // A wrapper for some piece of data so we can place other things in | 155 // A wrapper for some piece of data so we can place other things in |
156 // scoped_refptrs<>. | 156 // scoped_refptrs<>. |
157 // | 157 // |
158 template<typename T> | 158 template<typename T> |
159 class RefCountedData : public base::RefCounted< base::RefCountedData<T> > { | 159 class RefCountedData : public RefCounted< RefCountedData<T> > { |
160 public: | 160 public: |
161 RefCountedData() : data() {} | 161 RefCountedData() : data() {} |
162 RefCountedData(const T& in_value) : data(in_value) {} | 162 RefCountedData(const T& in_value) : data(in_value) {} |
163 | 163 |
164 T data; | 164 T data; |
165 }; | 165 }; |
166 | 166 |
167 } // namespace base | 167 } // namespace base |
168 | 168 |
169 // | 169 // |
170 // A smart pointer class for reference counted objects. Use this class instead | 170 // A smart pointer class for reference counted objects. Use this class instead |
171 // of calling AddRef and Release manually on a reference counted object to | 171 // of calling AddRef and Release manually on a reference counted object to |
172 // avoid common memory leaks caused by forgetting to Release an object | 172 // avoid common memory leaks caused by forgetting to Release an object |
173 // reference. Sample usage: | 173 // reference. Sample usage: |
174 // | 174 // |
175 // class MyFoo : public RefCounted<MyFoo> { | 175 // class MyFoo : public base::RefCounted<MyFoo> { |
176 // ... | 176 // ... |
177 // }; | 177 // }; |
178 // | 178 // |
179 // void some_function() { | 179 // void some_function() { |
180 // scoped_refptr<MyFoo> foo = new MyFoo(); | 180 // scoped_refptr<MyFoo> foo = new MyFoo(); |
181 // foo->Method(param); | 181 // foo->Method(param); |
182 // // |foo| is released when this function returns | 182 // // |foo| is released when this function returns |
183 // } | 183 // } |
184 // | 184 // |
185 // void some_other_function() { | 185 // void some_other_function() { |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
289 T* ptr_; | 289 T* ptr_; |
290 }; | 290 }; |
291 | 291 |
292 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without | 292 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without |
293 // having to retype all the template arguments | 293 // having to retype all the template arguments |
294 template <typename T> | 294 template <typename T> |
295 scoped_refptr<T> make_scoped_refptr(T* t) { | 295 scoped_refptr<T> make_scoped_refptr(T* t) { |
296 return scoped_refptr<T>(t); | 296 return scoped_refptr<T>(t); |
297 } | 297 } |
298 | 298 |
299 #endif // BASE_REF_COUNTED_H_ | 299 #endif // BASE_MEMORY_REF_COUNTED_H_ |
OLD | NEW |