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

Side by Side Diff: base/memory/ref_counted.h

Issue 9232069: Add assert() for scoped_refptr<T>::operator->() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use assert() instead Created 8 years, 10 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
10
9 #include "base/atomic_ref_count.h" 11 #include "base/atomic_ref_count.h"
10 #include "base/base_export.h" 12 #include "base/base_export.h"
11 #include "base/threading/thread_collision_warner.h" 13 #include "base/threading/thread_collision_warner.h"
12 14
13 namespace base { 15 namespace base {
14 16
15 namespace subtle { 17 namespace subtle {
16 18
17 class BASE_EXPORT RefCountedBase { 19 class BASE_EXPORT RefCountedBase {
18 public: 20 public:
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 ptr_->AddRef(); 238 ptr_->AddRef();
237 } 239 }
238 240
239 ~scoped_refptr() { 241 ~scoped_refptr() {
240 if (ptr_) 242 if (ptr_)
241 ptr_->Release(); 243 ptr_->Release();
242 } 244 }
243 245
244 T* get() const { return ptr_; } 246 T* get() const { return ptr_; }
245 operator T*() const { return ptr_; } 247 operator T*() const { return ptr_; }
246 T* operator->() const { return ptr_; } 248 T* operator->() const {
249 assert(ptr_ != NULL);
jar (doing other things) 2012/01/28 02:47:22 Could you clarify when this would be significant?
250 return ptr_;
251 }
247 252
248 // Release a pointer. 253 // Release a pointer.
249 // The return value is the current pointer held by this object. 254 // The return value is the current pointer held by this object.
250 // If this object holds a NULL pointer, the return value is NULL. 255 // If this object holds a NULL pointer, the return value is NULL.
251 // After this operation, this object will hold a NULL pointer, 256 // After this operation, this object will hold a NULL pointer,
252 // and will not own the object any more. 257 // and will not own the object any more.
253 T* release() { 258 T* release() {
254 T* retVal = ptr_; 259 T* retVal = ptr_;
255 ptr_ = NULL; 260 ptr_ = NULL;
256 return retVal; 261 return retVal;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 }; 296 };
292 297
293 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without 298 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without
294 // having to retype all the template arguments 299 // having to retype all the template arguments
295 template <typename T> 300 template <typename T>
296 scoped_refptr<T> make_scoped_refptr(T* t) { 301 scoped_refptr<T> make_scoped_refptr(T* t) {
297 return scoped_refptr<T>(t); 302 return scoped_refptr<T>(t);
298 } 303 }
299 304
300 #endif // BASE_MEMORY_REF_COUNTED_H_ 305 #endif // BASE_MEMORY_REF_COUNTED_H_
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698