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

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

Issue 9021020: Fix scoped_refptr assignment operator in the case of having it as a member. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactored as joth suggests Created 9 years 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 | base/memory/ref_counted_unittest.cc » ('j') | 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) 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_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 "base/atomic_ref_count.h" 9 #include "base/atomic_ref_count.h"
10 #include "base/base_export.h" 10 #include "base/base_export.h"
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 T* release() { 253 T* release() {
254 T* retVal = ptr_; 254 T* retVal = ptr_;
255 ptr_ = NULL; 255 ptr_ = NULL;
256 return retVal; 256 return retVal;
257 } 257 }
258 258
259 scoped_refptr<T>& operator=(T* p) { 259 scoped_refptr<T>& operator=(T* p) {
260 // AddRef first so that self assignment should work 260 // AddRef first so that self assignment should work
261 if (p) 261 if (p)
262 p->AddRef(); 262 p->AddRef();
263 if (ptr_ ) 263 T* old_ptr = ptr_;
264 ptr_ ->Release();
265 ptr_ = p; 264 ptr_ = p;
265 if (old_ptr)
266 old_ptr->Release();
266 return *this; 267 return *this;
267 } 268 }
268 269
269 scoped_refptr<T>& operator=(const scoped_refptr<T>& r) { 270 scoped_refptr<T>& operator=(const scoped_refptr<T>& r) {
270 return *this = r.ptr_; 271 return *this = r.ptr_;
271 } 272 }
272 273
273 template <typename U> 274 template <typename U>
274 scoped_refptr<T>& operator=(const scoped_refptr<U>& r) { 275 scoped_refptr<T>& operator=(const scoped_refptr<U>& r) {
275 return *this = r.get(); 276 return *this = r.get();
(...skipping 14 matching lines...) Expand all
290 }; 291 };
291 292
292 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without 293 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without
293 // having to retype all the template arguments 294 // having to retype all the template arguments
294 template <typename T> 295 template <typename T>
295 scoped_refptr<T> make_scoped_refptr(T* t) { 296 scoped_refptr<T> make_scoped_refptr(T* t) {
296 return scoped_refptr<T>(t); 297 return scoped_refptr<T>(t);
297 } 298 }
298 299
299 #endif // BASE_MEMORY_REF_COUNTED_H_ 300 #endif // BASE_MEMORY_REF_COUNTED_H_
OLDNEW
« no previous file with comments | « no previous file | base/memory/ref_counted_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698