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

Side by Side Diff: base/memory/weak_ptr.cc

Issue 16160015: Update base/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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 | « base/memory/weak_ptr.h ('k') | base/message_loop_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 #include "base/memory/weak_ptr.h" 5 #include "base/memory/weak_ptr.h"
6 6
7 namespace base { 7 namespace base {
8 namespace internal { 8 namespace internal {
9 9
10 WeakReference::Flag::Flag() : is_valid_(true) { 10 WeakReference::Flag::Flag() : is_valid_(true) {
(...skipping 22 matching lines...) Expand all
33 33
34 WeakReference::WeakReference() { 34 WeakReference::WeakReference() {
35 } 35 }
36 36
37 WeakReference::WeakReference(const Flag* flag) : flag_(flag) { 37 WeakReference::WeakReference(const Flag* flag) : flag_(flag) {
38 } 38 }
39 39
40 WeakReference::~WeakReference() { 40 WeakReference::~WeakReference() {
41 } 41 }
42 42
43 bool WeakReference::is_valid() const { 43 bool WeakReference::is_valid() const { return flag_.get() && flag_->IsValid(); }
44 return flag_ && flag_->IsValid();
45 }
46 44
47 WeakReferenceOwner::WeakReferenceOwner() { 45 WeakReferenceOwner::WeakReferenceOwner() {
48 } 46 }
49 47
50 WeakReferenceOwner::~WeakReferenceOwner() { 48 WeakReferenceOwner::~WeakReferenceOwner() {
51 Invalidate(); 49 Invalidate();
52 } 50 }
53 51
54 WeakReference WeakReferenceOwner::GetRef() const { 52 WeakReference WeakReferenceOwner::GetRef() const {
55 // If we hold the last reference to the Flag then create a new one. 53 // If we hold the last reference to the Flag then create a new one.
56 if (!HasRefs()) 54 if (!HasRefs())
57 flag_ = new WeakReference::Flag(); 55 flag_ = new WeakReference::Flag();
58 56
59 return WeakReference(flag_); 57 return WeakReference(flag_.get());
60 } 58 }
61 59
62 void WeakReferenceOwner::Invalidate() { 60 void WeakReferenceOwner::Invalidate() {
63 if (flag_) { 61 if (flag_.get()) {
64 flag_->Invalidate(); 62 flag_->Invalidate();
65 flag_ = NULL; 63 flag_ = NULL;
66 } 64 }
67 } 65 }
68 66
69 WeakPtrBase::WeakPtrBase() { 67 WeakPtrBase::WeakPtrBase() {
70 } 68 }
71 69
72 WeakPtrBase::~WeakPtrBase() { 70 WeakPtrBase::~WeakPtrBase() {
73 } 71 }
74 72
75 WeakPtrBase::WeakPtrBase(const WeakReference& ref) : ref_(ref) { 73 WeakPtrBase::WeakPtrBase(const WeakReference& ref) : ref_(ref) {
76 } 74 }
77 75
78 } // namespace internal 76 } // namespace internal
79 } // namespace base 77 } // namespace base
OLDNEW
« no previous file with comments | « base/memory/weak_ptr.h ('k') | base/message_loop_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698