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

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

Issue 10332269: RefCounted types should not have public destructors, base/ edition (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase to ToT Created 8 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/ref_counted.h ('k') | base/message_pump_libevent.h » ('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 help in cases where you have many objects referring back to a 5 // Weak pointers help in cases where you have many objects referring back to a
6 // shared object and you wish for the lifetime of the shared object to not be 6 // shared object and you wish for the lifetime of the shared object to not be
7 // bound to the lifetime of the referrers. In other words, this is useful when 7 // bound to the lifetime of the referrers. In other words, this is useful when
8 // reference counting is not a good fit. 8 // reference counting is not a good fit.
9 // 9 //
10 // Thread-safety notes: 10 // Thread-safety notes:
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 244
245 WeakPtr<T> AsWeakPtr() { 245 WeakPtr<T> AsWeakPtr() {
246 return WeakPtr<T>(weak_reference_owner_.GetRef(), static_cast<T*>(this)); 246 return WeakPtr<T>(weak_reference_owner_.GetRef(), static_cast<T*>(this));
247 } 247 }
248 248
249 // Indicates that this object will be used on another thread from now on. 249 // Indicates that this object will be used on another thread from now on.
250 void DetachFromThread() { 250 void DetachFromThread() {
251 weak_reference_owner_.DetachFromThread(); 251 weak_reference_owner_.DetachFromThread();
252 } 252 }
253 253
254 protected:
255 ~SupportsWeakPtr() {}
256
254 private: 257 private:
255 internal::WeakReferenceOwner weak_reference_owner_; 258 internal::WeakReferenceOwner weak_reference_owner_;
256 DISALLOW_COPY_AND_ASSIGN(SupportsWeakPtr); 259 DISALLOW_COPY_AND_ASSIGN(SupportsWeakPtr);
257 }; 260 };
258 261
259 // Helper function that uses type deduction to safely return a WeakPtr<Derived> 262 // Helper function that uses type deduction to safely return a WeakPtr<Derived>
260 // when Derived doesn't directly extend SupportsWeakPtr<Derived>, instead it 263 // when Derived doesn't directly extend SupportsWeakPtr<Derived>, instead it
261 // extends a Base that extends SupportsWeakPtr<Base>. 264 // extends a Base that extends SupportsWeakPtr<Base>.
262 // 265 //
263 // EXAMPLE: 266 // EXAMPLE:
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
319 322
320 private: 323 private:
321 internal::WeakReferenceOwner weak_reference_owner_; 324 internal::WeakReferenceOwner weak_reference_owner_;
322 T* ptr_; 325 T* ptr_;
323 DISALLOW_IMPLICIT_CONSTRUCTORS(WeakPtrFactory); 326 DISALLOW_IMPLICIT_CONSTRUCTORS(WeakPtrFactory);
324 }; 327 };
325 328
326 } // namespace base 329 } // namespace base
327 330
328 #endif // BASE_MEMORY_WEAK_PTR_H_ 331 #endif // BASE_MEMORY_WEAK_PTR_H_
OLDNEW
« no previous file with comments | « base/memory/ref_counted.h ('k') | base/message_pump_libevent.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698