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

Side by Side Diff: base/bind_helpers.h

Issue 7015064: Support binding WeakPtr<> to methods with void return types. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix a few comments. Created 9 years, 7 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 | base/bind_internal.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) 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 // This defines a set of argument wrappers and related factory methods that 5 // This defines a set of argument wrappers and related factory methods that
6 // can be used specify the refcounting and reference semantics of arguments 6 // can be used specify the refcounting and reference semantics of arguments
7 // that are bound by the Bind() function in base/bind.h. 7 // that are bound by the Bind() function in base/bind.h.
8 // 8 //
9 // The public functions are base::Unretained() and base::ConstRef(). 9 // The public functions are base::Unretained() and base::ConstRef().
10 // Unretained() allows Bind() to bind a non-refcounted class. 10 // Unretained() allows Bind() to bind a non-refcounted class.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 // 45 //
46 // Note that because ConstRef() takes a reference on |n|, |n| must outlive all 46 // Note that because ConstRef() takes a reference on |n|, |n| must outlive all
47 // its bound callbacks. 47 // its bound callbacks.
48 // 48 //
49 49
50 #ifndef BASE_BIND_HELPERS_H_ 50 #ifndef BASE_BIND_HELPERS_H_
51 #define BASE_BIND_HELPERS_H_ 51 #define BASE_BIND_HELPERS_H_
52 #pragma once 52 #pragma once
53 53
54 #include "base/basictypes.h" 54 #include "base/basictypes.h"
55 #include "base/memory/weak_ptr.h"
55 #include "base/template_util.h" 56 #include "base/template_util.h"
56 57
57 namespace base { 58 namespace base {
58 namespace internal { 59 namespace internal {
59 60
60 // Use the Substitution Failure Is Not An Error (SFINAE) trick to inspect T 61 // Use the Substitution Failure Is Not An Error (SFINAE) trick to inspect T
61 // for the existence of AddRef() and Release() functions of the correct 62 // for the existence of AddRef() and Release() functions of the correct
62 // signature. 63 // signature.
63 // 64 //
64 // http://en.wikipedia.org/wiki/Substitution_failure_is_not_an_error 65 // http://en.wikipedia.org/wiki/Substitution_failure_is_not_an_error
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 T* Unwrap(UnretainedWrapper<T> unretained) { return unretained.get(); } 209 T* Unwrap(UnretainedWrapper<T> unretained) { return unretained.get(); }
209 210
210 template <typename T> 211 template <typename T>
211 const T& Unwrap(ConstRefWrapper<T> const_ref) { 212 const T& Unwrap(ConstRefWrapper<T> const_ref) {
212 return const_ref.get(); 213 return const_ref.get();
213 } 214 }
214 215
215 216
216 // Utility for handling different refcounting semantics in the Bind() 217 // Utility for handling different refcounting semantics in the Bind()
217 // function. 218 // function.
218 template <typename ref, typename T> 219 template <typename IsMethod, typename T>
219 struct MaybeRefcount; 220 struct MaybeRefcount;
220 221
221 template <typename T> 222 template <typename T>
222 struct MaybeRefcount<base::false_type, T> { 223 struct MaybeRefcount<base::false_type, T> {
223 static void AddRef(const T&) {} 224 static void AddRef(const T&) {}
224 static void Release(const T&) {} 225 static void Release(const T&) {}
225 }; 226 };
226 227
227 template <typename T, size_t n> 228 template <typename T, size_t n>
228 struct MaybeRefcount<base::false_type, T[n]> { 229 struct MaybeRefcount<base::false_type, T[n]> {
(...skipping 12 matching lines...) Expand all
241 static void AddRef(T* o) { o->AddRef(); } 242 static void AddRef(T* o) { o->AddRef(); }
242 static void Release(T* o) { o->Release(); } 243 static void Release(T* o) { o->Release(); }
243 }; 244 };
244 245
245 template <typename T> 246 template <typename T>
246 struct MaybeRefcount<base::true_type, const T*> { 247 struct MaybeRefcount<base::true_type, const T*> {
247 static void AddRef(const T* o) { o->AddRef(); } 248 static void AddRef(const T* o) { o->AddRef(); }
248 static void Release(const T* o) { o->Release(); } 249 static void Release(const T* o) { o->Release(); }
249 }; 250 };
250 251
252 template <typename T>
253 struct MaybeRefcount<base::true_type, WeakPtr<T> > {
254 static void AddRef(const WeakPtr<T>&) {}
255 static void Release(const WeakPtr<T>&) {}
256 };
257
251 } // namespace internal 258 } // namespace internal
252 259
253 template <typename T> 260 template <typename T>
254 inline internal::UnretainedWrapper<T> Unretained(T* o) { 261 inline internal::UnretainedWrapper<T> Unretained(T* o) {
255 return internal::UnretainedWrapper<T>(o); 262 return internal::UnretainedWrapper<T>(o);
256 } 263 }
257 264
258 template <typename T> 265 template <typename T>
259 inline internal::ConstRefWrapper<T> ConstRef(const T& o) { 266 inline internal::ConstRefWrapper<T> ConstRef(const T& o) {
260 return internal::ConstRefWrapper<T>(o); 267 return internal::ConstRefWrapper<T>(o);
261 } 268 }
262 269
263 } // namespace base 270 } // namespace base
264 271
265 #endif // BASE_BIND_HELPERS_H_ 272 #endif // BASE_BIND_HELPERS_H_
OLDNEW
« no previous file with comments | « no previous file | base/bind_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698