| OLD | NEW |
| 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 // It also defines a set of simple functions and utilities that people want | 9 // It also defines a set of simple functions and utilities that people want |
| 10 // when using Callback<> and Bind(). | 10 // when using Callback<> and Bind(). |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 // | 218 // |
| 219 // The current implementation has the benefit though of leaving ParamTraits<> | 219 // The current implementation has the benefit though of leaving ParamTraits<> |
| 220 // fully in callback_internal.h as well as avoiding type conversions during | 220 // fully in callback_internal.h as well as avoiding type conversions during |
| 221 // storage. | 221 // storage. |
| 222 template <typename T> | 222 template <typename T> |
| 223 class OwnedWrapper { | 223 class OwnedWrapper { |
| 224 public: | 224 public: |
| 225 explicit OwnedWrapper(T* o) : ptr_(o) {} | 225 explicit OwnedWrapper(T* o) : ptr_(o) {} |
| 226 ~OwnedWrapper() { delete ptr_; } | 226 ~OwnedWrapper() { delete ptr_; } |
| 227 T* get() const { return ptr_; } | 227 T* get() const { return ptr_; } |
| 228 OwnedWrapper(const OwnedWrapper& other) { | 228 OwnedWrapper(OwnedWrapper&& other) { |
| 229 ptr_ = other.ptr_; | 229 ptr_ = other.ptr_; |
| 230 other.ptr_ = NULL; | 230 other.ptr_ = NULL; |
| 231 } | 231 } |
| 232 | 232 |
| 233 private: | 233 private: |
| 234 mutable T* ptr_; | 234 mutable T* ptr_; |
| 235 }; | 235 }; |
| 236 | 236 |
| 237 // PassedWrapper is a copyable adapter for a scoper that ignores const. | 237 // PassedWrapper is a copyable adapter for a scoper that ignores const. |
| 238 // | 238 // |
| (...skipping 16 matching lines...) Expand all Loading... |
| 255 // bound to a Callback. We guard this explicitly at the call of Passed() | 255 // bound to a Callback. We guard this explicitly at the call of Passed() |
| 256 // to make for clear errors. Things not given to Passed() will be forwarded | 256 // to make for clear errors. Things not given to Passed() will be forwarded |
| 257 // and stored by value which will not work for general move-only types. | 257 // and stored by value which will not work for general move-only types. |
| 258 // 2) is_valid_ is distinct from NULL because it is valid to bind a "NULL" | 258 // 2) is_valid_ is distinct from NULL because it is valid to bind a "NULL" |
| 259 // scoper to a Callback and allow the Callback to execute once. | 259 // scoper to a Callback and allow the Callback to execute once. |
| 260 template <typename T> | 260 template <typename T> |
| 261 class PassedWrapper { | 261 class PassedWrapper { |
| 262 public: | 262 public: |
| 263 explicit PassedWrapper(T&& scoper) | 263 explicit PassedWrapper(T&& scoper) |
| 264 : is_valid_(true), scoper_(std::move(scoper)) {} | 264 : is_valid_(true), scoper_(std::move(scoper)) {} |
| 265 PassedWrapper(const PassedWrapper& other) | 265 PassedWrapper(PassedWrapper&& other) |
| 266 : is_valid_(other.is_valid_), scoper_(std::move(other.scoper_)) {} | 266 : is_valid_(other.is_valid_), scoper_(std::move(other.scoper_)) {} |
| 267 T Take() const { | 267 T Take() const { |
| 268 CHECK(is_valid_); | 268 CHECK(is_valid_); |
| 269 is_valid_ = false; | 269 is_valid_ = false; |
| 270 return std::move(scoper_); | 270 return std::move(scoper_); |
| 271 } | 271 } |
| 272 | 272 |
| 273 private: | 273 private: |
| 274 mutable bool is_valid_; | 274 mutable bool is_valid_; |
| 275 mutable T scoper_; | 275 mutable T scoper_; |
| (...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 493 | 493 |
| 494 template <typename T> | 494 template <typename T> |
| 495 struct IsWeakReceiver<internal::ConstRefWrapper<T>> : IsWeakReceiver<T> {}; | 495 struct IsWeakReceiver<internal::ConstRefWrapper<T>> : IsWeakReceiver<T> {}; |
| 496 | 496 |
| 497 template <typename T> | 497 template <typename T> |
| 498 struct IsWeakReceiver<WeakPtr<T>> : std::true_type {}; | 498 struct IsWeakReceiver<WeakPtr<T>> : std::true_type {}; |
| 499 | 499 |
| 500 } // namespace base | 500 } // namespace base |
| 501 | 501 |
| 502 #endif // BASE_BIND_HELPERS_H_ | 502 #endif // BASE_BIND_HELPERS_H_ |
| OLD | NEW |