Chromium Embedded Framework (CEF)  126.2.0+g5c56e98+chromium-126.0.6478.62
cef_bind.h File Reference

base::BindOnce() and base::BindRepeating() are helpers for creating base::OnceCallback and base::RepeatingCallback objects respectively. More...

#include <functional>
#include <memory>
#include <type_traits>
#include <utility>
#include "include/base/cef_build.h"
#include "include/base/cef_compiler_specific.h"
#include "include/base/internal/cef_bind_internal.h"

Namespaces

 base
 

Functions

template<typename Functor , typename... Args>
OnceCallback< cef_internal::MakeUnboundRunType< Functor, Args... > > base::BindOnce (Functor &&functor, Args &&... args)
 Bind as OnceCallback. More...
 
template<typename Functor , typename... Args>
RepeatingCallback< cef_internal::MakeUnboundRunType< Functor, Args... > > base::BindRepeating (Functor &&functor, Args &&... args)
 Bind as RepeatingCallback. More...
 
template<typename Signature >
OnceCallback< Signature > base::BindOnce (OnceCallback< Signature > callback)
 Special cases for binding to a base::Callback without extra bound arguments. More...
 
template<typename Signature >
OnceCallback< Signature > base::BindOnce (RepeatingCallback< Signature > callback)
 
template<typename Signature >
RepeatingCallback< Signature > base::BindRepeating (RepeatingCallback< Signature > callback)
 
template<typename T >
cef_internal::UnretainedWrapper< T > base::Unretained (T *o)
 Unretained() allows binding a non-refcounted class, and to disable refcounting on arguments that are refcounted objects. More...
 
template<typename T >
cef_internal::RetainedRefWrapper< T > base::RetainedRef (T *o)
 RetainedRef() accepts a ref counted object and retains a reference to it. More...
 
template<typename T >
cef_internal::RetainedRefWrapper< T > base::RetainedRef (scoped_refptr< T > o)
 
template<typename T >
cef_internal::OwnedWrapper< T > base::Owned (T *o)
 Owned() transfers ownership of an object to the callback resulting from bind; the object will be deleted when the callback is deleted. More...
 
template<typename T , typename Deleter >
cef_internal::OwnedWrapper< T, Deleter > base::Owned (std::unique_ptr< T, Deleter > &&ptr)
 
template<typename T >
cef_internal::OwnedRefWrapper< std::decay_t< T > > base::OwnedRef (T &&t)
 OwnedRef() stores an object in the callback resulting from bind and passes a reference to the object to the bound function. More...
 
template<typename T , std::enable_if_t<!std::is_lvalue_reference< T >::value > * = nullptr>
cef_internal::PassedWrapper< T > base::Passed (T &&scoper)
 Passed() is for transferring movable-but-not-copyable types (eg. More...
 
template<typename T >
cef_internal::PassedWrapper< T > base::Passed (T *scoper)
 
template<typename T >
cef_internal::IgnoreResultHelper< T > base::IgnoreResult (T data)
 IgnoreResult() is used to adapt a function or callback with a return type to one with a void return. More...
 

Detailed Description

base::BindOnce() and base::BindRepeating() are helpers for creating base::OnceCallback and base::RepeatingCallback objects respectively.

For a runnable object of n-arity, the base::Bind*() family allows partial application of the first m arguments. The remaining n - m arguments must be passed when invoking the callback with Run().

  // The first argument is bound at callback creation; the remaining
  // two must be passed when calling Run() on the callback object.
  base::OnceCallback<long(int, long)> cb = base::BindOnce(
      [](short x, int y, long z) { return x * y * z; }, 42);

When binding to a method, the receiver object must also be specified at callback creation time. When Run() is invoked, the method will be invoked on the specified receiver object.

  class C : public base::RefCounted<C> { void F(); };
  auto instance = base::MakeRefCounted<C>();
  auto cb = base::BindOnce(&C::F, instance);
  std::move(cb).Run();  // Identical to instance->F()

See https://chromium.googlesource.com/chromium/src/+/lkgr/docs/callback.md for the full documentation.