OwnedRef()
// OwnedRef() 在回调中存储一个对象绑定并将对象的引用传递给绑定函数。
template <typename T>
internal::OwnedRefWrapper<std::decay_t<T>> OwnedRef(T&& t) {
return internal::OwnedRefWrapper<std::decay_t<T>>(std::forward<T>(t));
}
template <typename T>
inline internal::OwnedWrapper<T> Owned(T* o) {
return internal::OwnedWrapper<T>(o);
}
template <typename T, typename Deleter = std::default_delete<T>>
class OwnedWrapper {
public:
explicit OwnedWrapper(T* o) : ptr_(o) {}
explicit OwnedWrapper(std::unique_ptr<T, Deleter>&& ptr)
: ptr_(std::move(ptr)) {}
T* get() const { return ptr_.get(); }
private:
std::unique_ptr<T, Deleter> ptr_;
};
base::MakeRefCounted
构造一个 T 的实例,它是一个 ref 计数类型,并包装 将对象放入 scoped_refptr<T>。
// Constructs an instance of T, which is a ref counted type, and wraps the
// object into a scoped_refptr<T>.
template <typename T, typename... Args>
scoped_refptr<T> MakeRefCounted(Args&&... args) {
T* obj = new T(std::forward<Args>(args)...);
return subtle::AdoptRefIfNeeded(obj, T::kRefCountPreference);
}
chromium的base源码阅读之scoped_refptr_leapmotion的博客-CSDN博客_scoped_refptr