Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_MEMORY_REF_COUNTED_H_ | 5 #ifndef BASE_MEMORY_REF_COUNTED_H_ |
| 6 #define BASE_MEMORY_REF_COUNTED_H_ | 6 #define BASE_MEMORY_REF_COUNTED_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <cassert> | 9 #include <cassert> |
| 10 | 10 |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 157 // A wrapper for some piece of data so we can place other things in | 157 // A wrapper for some piece of data so we can place other things in |
| 158 // scoped_refptrs<>. | 158 // scoped_refptrs<>. |
| 159 // | 159 // |
| 160 template<typename T> | 160 template<typename T> |
| 161 class RefCountedData : public base::RefCounted< base::RefCountedData<T> > { | 161 class RefCountedData : public base::RefCounted< base::RefCountedData<T> > { |
| 162 public: | 162 public: |
| 163 RefCountedData() : data() {} | 163 RefCountedData() : data() {} |
| 164 RefCountedData(const T& in_value) : data(in_value) {} | 164 RefCountedData(const T& in_value) : data(in_value) {} |
| 165 | 165 |
| 166 T data; | 166 T data; |
| 167 | |
| 168 protected: | |
| 169 ~RefCountedData() {} | |
|
darin (slow to review)
2012/05/22 18:01:31
probably you want to make this destructor virtual
Ryan Sleevi
2012/05/22 18:36:20
See the thread I started on chromium-dev regarding
| |
| 170 | |
| 171 private: | |
| 172 friend class base::RefCounted<base::RefCountedData<T> >; | |
| 167 }; | 173 }; |
| 168 | 174 |
| 169 } // namespace base | 175 } // namespace base |
| 170 | 176 |
| 171 // | 177 // |
| 172 // A smart pointer class for reference counted objects. Use this class instead | 178 // A smart pointer class for reference counted objects. Use this class instead |
| 173 // of calling AddRef and Release manually on a reference counted object to | 179 // of calling AddRef and Release manually on a reference counted object to |
| 174 // avoid common memory leaks caused by forgetting to Release an object | 180 // avoid common memory leaks caused by forgetting to Release an object |
| 175 // reference. Sample usage: | 181 // reference. Sample usage: |
| 176 // | 182 // |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 }; | 302 }; |
| 297 | 303 |
| 298 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without | 304 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without |
| 299 // having to retype all the template arguments | 305 // having to retype all the template arguments |
| 300 template <typename T> | 306 template <typename T> |
| 301 scoped_refptr<T> make_scoped_refptr(T* t) { | 307 scoped_refptr<T> make_scoped_refptr(T* t) { |
| 302 return scoped_refptr<T>(t); | 308 return scoped_refptr<T>(t); |
| 303 } | 309 } |
| 304 | 310 |
| 305 #endif // BASE_MEMORY_REF_COUNTED_H_ | 311 #endif // BASE_MEMORY_REF_COUNTED_H_ |
| OLD | NEW |