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

Side by Side Diff: base/bind_helpers.h

Issue 8224026: Add a PassScopedPtr into base/memory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed it. Created 9 years, 1 month 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/base.gypi ('k') | base/bind_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 // 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(), base::Owned(), 9 // The public functions are base::Unretained(), base::Owned(),
10 // base::ConstRef(), and base::IgnoreReturn(). 10 // base::ConstRef(), and base::IgnoreReturn().
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 typedef T* ForwardType; 315 typedef T* ForwardType;
316 static ForwardType Unwrap(const scoped_refptr<T>& o) { return o.get(); } 316 static ForwardType Unwrap(const scoped_refptr<T>& o) { return o.get(); }
317 }; 317 };
318 318
319 template <typename T> 319 template <typename T>
320 struct UnwrapTraits<WeakPtr<T> > { 320 struct UnwrapTraits<WeakPtr<T> > {
321 typedef const WeakPtr<T>& ForwardType; 321 typedef const WeakPtr<T>& ForwardType;
322 static ForwardType Unwrap(const WeakPtr<T>& o) { return o; } 322 static ForwardType Unwrap(const WeakPtr<T>& o) { return o; }
323 }; 323 };
324 324
325 /*
326 template <typename T>
327 struct UnwrapTraits<subtle::PassScopedPtrAnchor<T> > {
328 typedef PassScopedPtr<T> ForwardType;
329 static PassScopedPtr<T> Unwrap(subtle::PassScopedPtrAnchor<T>& o) {
330 return &o;
331 }
332 };
333 */
334
335 template <typename T>
336 struct UnwrapTraits<subtle::PassScopedPtrAnchor<T> > {
337 typedef subtle::PassScopedPtrAnchor<T>* ForwardType;
338 static subtle::PassScopedPtrAnchor<T>*
339 Unwrap(subtle::PassScopedPtrAnchor<T>& o) {
340 return &o;
341 }
342 };
343
325 template <typename T> 344 template <typename T>
326 struct UnwrapTraits<OwnedWrapper<T> > { 345 struct UnwrapTraits<OwnedWrapper<T> > {
327 typedef T* ForwardType; 346 typedef T* ForwardType;
328 static ForwardType Unwrap(const OwnedWrapper<T>& o) { 347 static ForwardType Unwrap(const OwnedWrapper<T>& o) {
329 return o.get(); 348 return o.get();
330 } 349 }
331 }; 350 };
332 351
333 // Utility for handling different refcounting semantics in the Bind() 352 // Utility for handling different refcounting semantics in the Bind()
334 // function. 353 // function.
335 template <bool, typename T> 354 template <bool, typename T>
336 struct MaybeRefcount; 355 struct MaybeRefcount;
337 356
338 template <typename T> 357 template <typename T>
339 struct MaybeRefcount<false, T> { 358 struct MaybeRefcount<false, T> {
340 static void AddRef(const T&) {} 359 static void AddRef(const T&) {}
341 static void Release(const T&) {} 360 static void Release(const T&) {}
342 }; 361 };
343 362
344 template <typename T, size_t n> 363 template <typename T, size_t n>
345 struct MaybeRefcount<false, T[n]> { 364 struct MaybeRefcount<false, T[n]> {
346 static void AddRef(const T*) {} 365 static void AddRef(const T*) {}
347 static void Release(const T*) {} 366 static void Release(const T*) {}
348 }; 367 };
349 368
350 template <typename T> 369 template <typename T>
370 struct MaybeRefcount<false, PassScopedPtr<T> > {
371 static void AddRef(const subtle::PassScopedPtrAnchor<T>&) {}
372 static void Release(const subtle::PassScopedPtrAnchor<T>&) {}
373 };
374
375 template <typename T>
351 struct MaybeRefcount<true, T*> { 376 struct MaybeRefcount<true, T*> {
352 static void AddRef(T* o) { o->AddRef(); } 377 static void AddRef(T* o) { o->AddRef(); }
353 static void Release(T* o) { o->Release(); } 378 static void Release(T* o) { o->Release(); }
354 }; 379 };
355 380
356 template <typename T> 381 template <typename T>
357 struct MaybeRefcount<true, UnretainedWrapper<T> > { 382 struct MaybeRefcount<true, UnretainedWrapper<T> > {
358 static void AddRef(const UnretainedWrapper<T>&) {} 383 static void AddRef(const UnretainedWrapper<T>&) {}
359 static void Release(const UnretainedWrapper<T>&) {} 384 static void Release(const UnretainedWrapper<T>&) {}
360 }; 385 };
(...skipping 12 matching lines...) Expand all
373 static void Release(const scoped_refptr<T>& o) {} 398 static void Release(const scoped_refptr<T>& o) {}
374 }; 399 };
375 400
376 template <typename T> 401 template <typename T>
377 struct MaybeRefcount<true, const T*> { 402 struct MaybeRefcount<true, const T*> {
378 static void AddRef(const T* o) { o->AddRef(); } 403 static void AddRef(const T* o) { o->AddRef(); }
379 static void Release(const T* o) { o->Release(); } 404 static void Release(const T* o) { o->Release(); }
380 }; 405 };
381 406
382 template <typename T> 407 template <typename T>
408 struct MaybeRefcount<true, PassScopedPtr<T> > {
409 static void AddRef(const subtle::PassScopedPtrAnchor<T>&) {}
410 static void Release(const subtle::PassScopedPtrAnchor<T>&) {}
411 };
412
413 template <typename T>
383 struct MaybeRefcount<true, WeakPtr<T> > { 414 struct MaybeRefcount<true, WeakPtr<T> > {
384 static void AddRef(const WeakPtr<T>&) {} 415 static void AddRef(const WeakPtr<T>&) {}
385 static void Release(const WeakPtr<T>&) {} 416 static void Release(const WeakPtr<T>&) {}
386 }; 417 };
387 418
388 template <typename R> 419 template <typename R>
389 void VoidReturnAdapter(Callback<R(void)> callback) { 420 void VoidReturnAdapter(Callback<R(void)> callback) {
390 callback.Run(); 421 callback.Run();
391 } 422 }
392 423
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 template <typename T> 466 template <typename T>
436 static inline internal::IgnoreResultHelper<Callback<T> > 467 static inline internal::IgnoreResultHelper<Callback<T> >
437 IgnoreResult(const Callback<T>& data) { 468 IgnoreResult(const Callback<T>& data) {
438 return internal::IgnoreResultHelper<Callback<T> >(data); 469 return internal::IgnoreResultHelper<Callback<T> >(data);
439 } 470 }
440 471
441 472
442 } // namespace base 473 } // namespace base
443 474
444 #endif // BASE_BIND_HELPERS_H_ 475 #endif // BASE_BIND_HELPERS_H_
OLDNEW
« no previous file with comments | « base/base.gypi ('k') | base/bind_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698