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

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

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/files/file_util_proxy.cc ('k') | base/memory/weak_ptr.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) 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 // Weak pointers are pointers to an object that do not affect its lifetime, 5 // Weak pointers are pointers to an object that do not affect its lifetime,
6 // and which may be invalidated (i.e. reset to NULL) by the object, or its 6 // and which may be invalidated (i.e. reset to NULL) by the object, or its
7 // owner, at any time, most commonly when the object is about to be deleted. 7 // owner, at any time, most commonly when the object is about to be deleted.
8 8
9 // Weak pointers are useful when an object needs to be accessed safely by one 9 // Weak pointers are useful when an object needs to be accessed safely by one
10 // or more objects other than its owner, and those callers can cope with the 10 // or more objects other than its owner, and those callers can cope with the
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 WeakReference GetRef() const; 120 WeakReference GetRef() const;
121 121
122 bool HasRefs() const { 122 bool HasRefs() const {
123 return flag_.get() && !flag_->HasOneRef(); 123 return flag_.get() && !flag_->HasOneRef();
124 } 124 }
125 125
126 void Invalidate(); 126 void Invalidate();
127 127
128 // Remove this when crbug.com/234964 is addressed. 128 // Remove this when crbug.com/234964 is addressed.
129 void DetachFromThreadHack() { 129 void DetachFromThreadHack() {
130 if (flag_) flag_->DetachFromThreadHack(); 130 if (flag_.get())
131 flag_->DetachFromThreadHack();
131 } 132 }
132 133
133 private: 134 private:
134 mutable scoped_refptr<WeakReference::Flag> flag_; 135 mutable scoped_refptr<WeakReference::Flag> flag_;
135 }; 136 };
136 137
137 // This class simplifies the implementation of WeakPtr's type conversion 138 // This class simplifies the implementation of WeakPtr's type conversion
138 // constructor by avoiding the need for a public accessor for ref_. A 139 // constructor by avoiding the need for a public accessor for ref_. A
139 // WeakPtr<T> cannot access the private members of WeakPtr<U>, so this 140 // WeakPtr<T> cannot access the private members of WeakPtr<U>, so this
140 // base class gives us a way to access ref_ in a protected fashion. 141 // base class gives us a way to access ref_ in a protected fashion.
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 // base::WeakPtr<Derived> ptr = derived.AsWeakPtr(); // Fails. 329 // base::WeakPtr<Derived> ptr = derived.AsWeakPtr(); // Fails.
329 330
330 template <typename Derived> 331 template <typename Derived>
331 WeakPtr<Derived> AsWeakPtr(Derived* t) { 332 WeakPtr<Derived> AsWeakPtr(Derived* t) {
332 return internal::SupportsWeakPtrBase::StaticAsWeakPtr<Derived>(t); 333 return internal::SupportsWeakPtrBase::StaticAsWeakPtr<Derived>(t);
333 } 334 }
334 335
335 } // namespace base 336 } // namespace base
336 337
337 #endif // BASE_MEMORY_WEAK_PTR_H_ 338 #endif // BASE_MEMORY_WEAK_PTR_H_
OLDNEW
« no previous file with comments | « base/files/file_util_proxy.cc ('k') | base/memory/weak_ptr.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698