Chromium Embedded Framework (CEF)  145.0.1+g472e75d+chromium-145.0.7632.5
base Namespace Reference

Namespaces

 cef_internal
 
 PlatformThread
 A namespace for low-level thread functions.
 

Classes

class  AtomicFlag
 A flag that can safely be set from one thread and read from other threads. More...
 
class  AtomicRefCount
 
class  OnceCallback< R(Args...)>
 
class  RepeatingCallback< R(Args...)>
 
class  OnceCallback
 
class  RepeatingCallback
 
class  ScopedClosureRunner
 ScopedClosureRunner is akin to std::unique_ptr<> for Closures. More...
 
class  PlatformThreadRef
 Used for thread checking and debugging. More...
 
class  RefCounted
 A base class for reference counted classes. More...
 
struct  DefaultRefCountedTraits
 Default traits for RefCounted<T>. More...
 
class  RefCountedThreadSafe
 A thread-safe variant of RefCounted<T> More...
 
struct  DefaultRefCountedThreadSafeTraits
 Default traits for RefCountedThreadSafe<T>. More...
 
class  RefCountedData
 A thread-safe wrapper for some piece of data so we can place other things in scoped_refptrs<>. More...
 
class  RefCountedDeleteOnSequence
 
class  ThreadChecker
 ThreadChecker is a helper class used to help verify that some methods of a class are called from the same thread. More...
 
class  WeakPtr
 The WeakPtr class holds a weak reference to |T*|. More...
 
class  WeakPtrFactory
 A class may be composed of a WeakPtrFactory and thereby control how it exposes weak pointers to itself. More...
 

Typedefs

using OnceClosure = OnceCallback< void()>
 Syntactic sugar to make OnceClosure<void()> and RepeatingClosure<void()> easier to declare since they will be used in a lot of APIs with delayed execution. More...
 
using RepeatingClosure = RepeatingCallback< void()>
 
typedef cef_platform_thread_id_t PlatformThreadId
 Used for logging. More...
 
using ScopedAllowCrossThreadRefCountAccess = cef_subtle::ScopedAllowCrossThreadRefCountAccess
 

Functions

template<typename Functor , typename... Args>
auto BindOnce (Functor &&functor, Args &&... args)
 Bind as OnceCallback. More...
 
template<typename Functor , typename... Args>
auto BindRepeating (Functor &&functor, Args &&... args)
 Bind as RepeatingCallback. More...
 
BindFailedCheckPreviousErrors BindOnce (...)
 
BindFailedCheckPreviousErrors BindRepeating (...)
 
template<typename T >
cef_internal::UnretainedWrapper< T > Unretained (T *o)
 Unretained() allows binding a non-refcounted class, and to disable refcounting on arguments that are refcounted. More...
 
template<typename T >
cef_internal::RetainedRefWrapper< T > RetainedRef (T *o)
 RetainedRef() accepts a ref counted object and retains a reference to it. More...
 
template<typename T >
cef_internal::RetainedRefWrapper< T > RetainedRef (scoped_refptr< T > o)
 
template<typename T >
cef_internal::OwnedWrapper< T > 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 > Owned (std::unique_ptr< T, Deleter > &&ptr)
 
template<typename T >
cef_internal::OwnedRefWrapper< std::decay_t< T > > 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 >
 requires (!std::is_lvalue_reference_v< T >) inline cef_internal
 Passed() is for transferring movable-but-not-copyable types (eg. More...
 
template<typename T >
cef_internal::PassedWrapper< T > Passed (T *scoper)
 
template<typename T >
cef_internal::IgnoreResultHelper< T > IgnoreResult (T data)
 IgnoreResult() is used to adapt a function or callback with a return type to one with a void return. More...
 
template<typename... Args>
RepeatingCallback< void(Args...)> ForwardRepeatingCallbacks (std::initializer_list< RepeatingCallback< void(Args...)>> &&cbs)
 Wraps the given RepeatingCallbacks and return one RepeatingCallbacks with an identical signature. More...
 
template<typename... Args>
std::pair< OnceCallback< void(Args...)>, OnceCallback< void(Args...)> > SplitOnceCallback (OnceCallback< void(Args...)> callback)
 Wraps the given OnceCallback and returns two OnceCallbacks with an identical signature. More...
 
template<typename... Preargs, typename... Args, typename R >
RepeatingCallback< R(Preargs..., Args...)> IgnoreArgs (RepeatingCallback< R(Args...)> callback)
 Adapts callback for use in a context which is expecting a callback with additional parameters. More...
 
template<typename... Preargs, typename... Args, typename R >
OnceCallback< R(Preargs..., Args...)> IgnoreArgs (OnceCallback< R(Args...)> callback)
 As above, but for OnceCallback. More...
 
constexpr auto NullCallback ()
 Returns a placeholder type that will implicitly convert into a null callback, similar to how std::nullopt / std::nullptr work in conjunction with std::optional and various smart pointer types. More...
 
constexpr auto DoNothing ()
 Returns a placeholder type that will implicitly convert into a callback that does nothing, similar to how std::nullopt / std::nullptr work in conjunction with std::optional and various smart pointer types. More...
 
template<typename Signature >
constexpr auto NullCallbackAs ()
 Similar to the above, but with a type hint. More...
 
template<typename Signature >
constexpr auto DoNothingAs ()
 
template<typename... Args>
constexpr auto DoNothingWithBoundArgs (Args &&... args)
 Similar to DoNothing above, but with bound arguments. More...
 
template<typename T >
constexpr OnceCallback< T(void)> ReturnValueOnce (T value)
 Creates a callback that returns value when invoked. More...
 
template<typename T >
void DeletePointer (T *obj)
 Useful for creating a Closure that will delete a pointer when invoked. More...
 
template<typename R , typename... Args>
auto CallbackToBlock (base::OnceCallback< R(Args...)> callback)
 Creates an Objective-C block with the same signature as the corresponding callback. More...
 
template<typename R , typename... Args>
auto CallbackToBlock (base::RepeatingCallback< R(Args...)> callback)
 
IMMEDIATE_CRASH_ALWAYS_INLINE void ImmediateCrash ()
 
template<typename T >
bool operator== (const RefCountedData< T > &lhs, const RefCountedData< T > &rhs)
 
template<typename T >
scoped_refptr< T > AdoptRef (T *t)
 
template<typename T , typename... Args>
scoped_refptr< T > MakeRefCounted (Args &&... args)
 
template<typename T >
scoped_refptr< T > WrapRefCounted (T *t)
 
template<typename T >
 requires (!std::is_function_v< T >) const expr T *to_address(T *p) noexcept
 Note that calling std::to_address() with a function pointer renders the program ill-formed. More...
 
 requires (const P &p)
 
constexpr auto to_address (const P &p) noexcept
 
template<class T >
bool operator!= (const WeakPtr< T > &weak_ptr, std::nullptr_t)
 Allow callers to compare WeakPtrs against nullptr to test validity. More...
 
template<class T >
bool operator!= (std::nullptr_t, const WeakPtr< T > &weak_ptr)
 
template<class T >
bool operator== (const WeakPtr< T > &weak_ptr, std::nullptr_t)
 
template<class T >
bool operator== (std::nullptr_t, const WeakPtr< T > &weak_ptr)
 

Variables

template<typename T >
concept IsBaseCallback
 IsBaseCallback<T> is satisfied if and only if T is an instantiation of base::OnceCallback<Signature> or base::RepeatingCallback<Signature>. More...
 
template<typename T >
concept IsComplete
 True if T is completely defined. More...
 
template<typename T , template< typename... > class C>
concept is_instantiation = cef_internal::is_instantiation_v<T, C>
 True if and only if the type T is an instantiation of the template C with some set of type arguments. More...
 
template<typename T >
concept IsRefCountedType
 
template<typename P >
requires requires { typename P::element_type
 These constraints cover the cases where std::to_address()'s fancy pointer overload is well-specified. More...
 

Typedef Documentation

◆ OnceClosure

using base::OnceClosure = typedef OnceCallback<void()>

Syntactic sugar to make OnceClosure<void()> and RepeatingClosure<void()> easier to declare since they will be used in a lot of APIs with delayed execution.

◆ PlatformThreadId

typedef cef_platform_thread_id_t base::PlatformThreadId

Used for logging.

Always an integer value.

◆ RepeatingClosure

using base::RepeatingClosure = typedef RepeatingCallback<void()>

◆ ScopedAllowCrossThreadRefCountAccess

using base::ScopedAllowCrossThreadRefCountAccess = typedef cef_subtle::ScopedAllowCrossThreadRefCountAccess

Function Documentation

◆ AdoptRef()

template<typename T >
scoped_refptr< T > base::AdoptRef ( T *  t)

◆ BindOnce() [1/2]

BindFailedCheckPreviousErrors base::BindOnce (   ...)

◆ BindOnce() [2/2]

template<typename Functor , typename... Args>
auto base::BindOnce ( Functor &&  functor,
Args &&...  args 
)
inline

Bind as OnceCallback.

◆ BindRepeating() [1/2]

BindFailedCheckPreviousErrors base::BindRepeating (   ...)

◆ BindRepeating() [2/2]

template<typename Functor , typename... Args>
auto base::BindRepeating ( Functor &&  functor,
Args &&...  args 
)
inline

◆ CallbackToBlock() [1/2]

template<typename R , typename... Args>
auto base::CallbackToBlock ( base::OnceCallback< R(Args...)>  callback)

Creates an Objective-C block with the same signature as the corresponding callback.

Can be used to implement a callback based API internally based on a block based Objective-C API.

Overloaded to work with both repeating and one shot callbacks. Calling the block wrapping a base::OnceCallback<...> multiple times will crash (there is no way to mark the block as callable only once). Only use that when you know that Objective-C API will only invoke the block once.

◆ CallbackToBlock() [2/2]

template<typename R , typename... Args>
auto base::CallbackToBlock ( base::RepeatingCallback< R(Args...)>  callback)

◆ DeletePointer()

template<typename T >
void base::DeletePointer ( T *  obj)

Useful for creating a Closure that will delete a pointer when invoked.

Only use this when necessary. In most cases MessageLoop::DeleteSoon() is a better fit.

◆ DoNothing()

constexpr auto base::DoNothing ( )
constexpr

Returns a placeholder type that will implicitly convert into a callback that does nothing, similar to how std::nullopt / std::nullptr work in conjunction with std::optional and various smart pointer types.

◆ DoNothingAs()

template<typename Signature >
constexpr auto base::DoNothingAs ( )
constexpr

◆ DoNothingWithBoundArgs()

template<typename... Args>
constexpr auto base::DoNothingWithBoundArgs ( Args &&...  args)
constexpr

Similar to DoNothing above, but with bound arguments.

This helper is useful for keeping objects alive until the callback runs. Example:

void F(base::OnceCallback<void(int)> result_callback);

std::unique_ptr<MyClass> ptr;
F(base::DoNothingWithBoundArgs(std::move(ptr)));

◆ ForwardRepeatingCallbacks()

template<typename... Args>
RepeatingCallback<void(Args...)> base::ForwardRepeatingCallbacks ( std::initializer_list< RepeatingCallback< void(Args...)>> &&  cbs)

Wraps the given RepeatingCallbacks and return one RepeatingCallbacks with an identical signature.

On invocation of this callback, all the given RepeatingCallbacks will be called with the same arguments. Unbound arguments must be copyable.

◆ IgnoreArgs() [1/2]

template<typename... Preargs, typename... Args, typename R >
OnceCallback<R(Preargs..., Args...)> base::IgnoreArgs ( OnceCallback< R(Args...)>  callback)

As above, but for OnceCallback.

◆ IgnoreArgs() [2/2]

template<typename... Preargs, typename... Args, typename R >
RepeatingCallback<R(Preargs..., Args...)> base::IgnoreArgs ( RepeatingCallback< R(Args...)>  callback)

Adapts callback for use in a context which is expecting a callback with additional parameters.

Returns a null callback if callback is null.

Usage:

  bool LogError(char* error_message) {
    if (error_message) {
      cout << "Log: " << error_message << endl;
      return false;
    }
    return true;
  }
  base::RepeatingCallback<bool(int, char*)> cb =
     base::IgnoreArgs<int>(base::BindRepeating(&LogError));
  CHECK_EQ(true, cb.Run(42, nullptr));

Note in the example above that the type(s) passed to IgnoreArgs represent the additional prepended parameters (those which will be "ignored").

◆ IgnoreResult()

template<typename T >
cef_internal::IgnoreResultHelper<T> base::IgnoreResult ( data)
inline

IgnoreResult() is used to adapt a function or callback with a return type to one with a void return.

This is most useful if you have a function with, say, a pesky ignorable bool return that you want to use with PostTask or something else that expect a callback with a void return.

EXAMPLE OF IgnoreResult():

  int DoSomething(int arg) { cout << arg << endl; }

  // Assign to a callback with a void return type.
  OnceCallback<void(int)> cb = BindOnce(IgnoreResult(&DoSomething));
  std::move(cb).Run(1);  // Prints "1".

  // Prints "2" on |ml|.
  ml->PostTask(FROM_HERE, BindOnce(IgnoreResult(&DoSomething), 2);

◆ ImmediateCrash()

IMMEDIATE_CRASH_ALWAYS_INLINE void base::ImmediateCrash ( )

◆ MakeRefCounted()

template<typename T , typename... Args>
scoped_refptr<T> base::MakeRefCounted ( Args &&...  args)

◆ NullCallback()

constexpr auto base::NullCallback ( )
constexpr

Returns a placeholder type that will implicitly convert into a null callback, similar to how std::nullopt / std::nullptr work in conjunction with std::optional and various smart pointer types.

◆ NullCallbackAs()

template<typename Signature >
constexpr auto base::NullCallbackAs ( )
constexpr

Similar to the above, but with a type hint.

Useful for disambiguating among multiple function overloads that take callbacks with different signatures:

void F(base::OnceCallback<void()> callback);     // 1
void F(base::OnceCallback<void(int)> callback);  // 2

F(base::NullCallbackAs<void()>());               // calls 1
F(base::DoNothingAs<void(int)>());               // calls 2

◆ operator!=() [1/2]

template<class T >
bool base::operator!= ( const WeakPtr< T > &  weak_ptr,
std::nullptr_t   
)

Allow callers to compare WeakPtrs against nullptr to test validity.

◆ operator!=() [2/2]

template<class T >
bool base::operator!= ( std::nullptr_t  ,
const WeakPtr< T > &  weak_ptr 
)

◆ operator==() [1/3]

template<typename T >
bool base::operator== ( const RefCountedData< T > &  lhs,
const RefCountedData< T > &  rhs 
)

◆ operator==() [2/3]

template<class T >
bool base::operator== ( const WeakPtr< T > &  weak_ptr,
std::nullptr_t   
)

◆ operator==() [3/3]

template<class T >
bool base::operator== ( std::nullptr_t  ,
const WeakPtr< T > &  weak_ptr 
)

◆ Owned() [1/2]

template<typename T , typename Deleter >
cef_internal::OwnedWrapper<T, Deleter> base::Owned ( std::unique_ptr< T, Deleter > &&  ptr)
inline

◆ Owned() [2/2]

template<typename T >
cef_internal::OwnedWrapper<T> base::Owned ( T *  o)
inline

Owned() transfers ownership of an object to the callback resulting from bind; the object will be deleted when the callback is deleted.

EXAMPLE OF Owned():

  void foo(int* arg) { cout << *arg << endl }

  int* pn = new int(1);
  RepeatingClosure foo_callback = BindRepeating(&foo, Owned(pn));

  foo_callback.Run();  // Prints "1"
  foo_callback.Run();  // Prints "1"
  *pn = 2;
  foo_callback.Run();  // Prints "2"

  foo_callback.Reset();  // |pn| is deleted.  Also will happen when
                         // |foo_callback| goes out of scope.

Without Owned(), someone would have to know to delete |pn| when the last reference to the callback is deleted.

◆ OwnedRef()

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.

EXAMPLE OF OwnedRef():

  void foo(int& arg) { cout << ++arg << endl }

  int counter = 0;
  RepeatingClosure foo_callback = BindRepeating(&foo, OwnedRef(counter));

  foo_callback.Run();  // Prints "1"
  foo_callback.Run();  // Prints "2"
  foo_callback.Run();  // Prints "3"

  cout << counter;     // Prints "0", OwnedRef creates a copy of counter.

Supports OnceCallbacks as well, useful to pass placeholder arguments:

  void bar(int& ignore, const std::string& s) { cout << s << endl }

  OnceClosure bar_callback = BindOnce(&bar, OwnedRef(0), "Hello");

  std::move(bar_callback).Run(); // Prints "Hello"

Without OwnedRef() it would not be possible to pass a mutable reference to an object owned by the callback.

◆ Passed()

template<typename T >
cef_internal::PassedWrapper<T> base::Passed ( T *  scoper)
inline

◆ requires() [1/3]

template<typename T >
base::requires ( !std::is_function_v< T >  ) const
noexcept

Note that calling std::to_address() with a function pointer renders the program ill-formed.

◆ requires() [2/3]

template<typename T >
base::requires ( !std::is_lvalue_reference_v< T >  )

Passed() is for transferring movable-but-not-copyable types (eg.

unique_ptr) through a RepeatingCallback. Logically, this signifies a destructive transfer of the state of the argument into the target function. Invoking RepeatingCallback::Run() twice on a callback that was created with a Passed() argument will CHECK() because the first invocation would have already transferred ownership to the target function.

Note that Passed() is not necessary with BindOnce(), as std::move() does the same thing. Avoid Passed() in favor of std::move() with BindOnce().

EXAMPLE OF Passed():

  void TakesOwnership(std::unique_ptr<Foo> arg) { }
  std::unique_ptr<Foo> CreateFoo() { return std::make_unique<Foo>();
  }

  auto f = std::make_unique<Foo>();

  // |cb| is given ownership of Foo(). |f| is now NULL.
  // You can use std::move(f) in place of &f, but it's more verbose.
  RepeatingClosure cb = BindRepeating(&TakesOwnership, Passed(&f));

  // Run was never called so |cb| still owns Foo() and deletes
  // it on Reset().
  cb.Reset();

  // |cb| is given a new Foo created by CreateFoo().
  cb = BindRepeating(&TakesOwnership, Passed(CreateFoo()));

  // |arg| in TakesOwnership() is given ownership of Foo(). |cb|
  // no longer owns Foo() and, if reset, would not delete Foo().
  cb.Run();  // Foo() is now transferred to |arg| and deleted.
  cb.Run();  // This CHECK()s since Foo() already been used once.

We offer 2 syntaxes for calling Passed(). The first takes an rvalue and is best suited for use with the return value of a function or other temporary rvalues. The second takes a pointer to the scoper and is just syntactic sugar to avoid having to write Passed(std::move(scoper)).

Both versions of Passed() prevent T from being an lvalue reference. The first via use of enable_if, and the second takes a T* which will not bind to T&.

DEPRECATED - Do not use in new code. See https://crbug.com/1326449

◆ requires() [3/3]

base::requires ( const P &  p)

◆ RetainedRef() [1/2]

template<typename T >
cef_internal::RetainedRefWrapper<T> base::RetainedRef ( scoped_refptr< T >  o)
inline

◆ RetainedRef() [2/2]

template<typename T >
cef_internal::RetainedRefWrapper<T> base::RetainedRef ( T *  o)
inline

RetainedRef() accepts a ref counted object and retains a reference to it.

When the callback is called, the object is passed as a raw pointer.

EXAMPLE OF RetainedRef():

   void foo(RefCountedBytes* bytes) {}

   scoped_refptr<RefCountedBytes> bytes = ...;
   OnceClosure callback = BindOnce(&foo, base::RetainedRef(bytes));
   std::move(callback).Run();

Without RetainedRef, the scoped_refptr would try to implicitly convert to a raw pointer and fail compilation:

   OnceClosure callback = BindOnce(&foo, bytes); // ERROR!

◆ ReturnValueOnce()

template<typename T >
constexpr OnceCallback<T(void)> base::ReturnValueOnce ( value)
constexpr

Creates a callback that returns value when invoked.

This helper is useful for implementing factories that return a constant value. Example:

void F(base::OnceCallback<Widget()> factory);

Widget widget = ...;
F(base::ReturnValueOnce(std::move(widget)));

◆ SplitOnceCallback()

template<typename... Args>
std::pair<OnceCallback<void(Args...)>, OnceCallback<void(Args...)> > base::SplitOnceCallback ( OnceCallback< void(Args...)>  callback)

Wraps the given OnceCallback and returns two OnceCallbacks with an identical signature.

On first invokation of either returned callbacks, the original callback is invoked. Invoking the remaining callback results in a crash.

◆ to_address()

constexpr auto base::to_address ( const P &  p)
constexprnoexcept

◆ Unretained()

template<typename T >
cef_internal::UnretainedWrapper<T> base::Unretained ( T *  o)
inline

Unretained() allows binding a non-refcounted class, and to disable refcounting on arguments that are refcounted.

CEF simplified: no dangling pointer detection (UnsafeDangling, UnsafeDanglingUntriaged removed).

Example of Unretained() usage:

  class Foo {
   public:
    void func() { cout << "Foo:f" << endl; }
  };

  // In some function somewhere.
  Foo foo;
  OnceClosure foo_callback =
      BindOnce(&Foo::func, Unretained(&foo));
  std::move(foo_callback).Run();  // Prints "Foo:f".

Without the Unretained() wrapper on |&foo|, the above call would fail to compile because Foo does not support the AddRef() and Release() methods.

◆ WrapRefCounted()

template<typename T >
scoped_refptr<T> base::WrapRefCounted ( T *  t)

Variable Documentation

◆ is_instantiation

template<typename T , template< typename... > class C>
concept base::is_instantiation = cef_internal::is_instantiation_v<T, C>

True if and only if the type T is an instantiation of the template C with some set of type arguments.

Note that there is no allowance for reference or const/volatile qualifiers; if these are a concern you probably want to feed through std::decay_t<T>.

◆ IsBaseCallback

template<typename T >
concept base::IsBaseCallback
Initial value:
=
cef_internal::IsBaseCallbackImpl<std::decay_t<T>>::value

IsBaseCallback<T> is satisfied if and only if T is an instantiation of base::OnceCallback<Signature> or base::RepeatingCallback<Signature>.

◆ IsComplete

template<typename T >
concept base::IsComplete
Initial value:
= requires { sizeof(T); } ||
std::is_function_v<std::remove_cvref_t<T>>
requires requires
These constraints cover the cases where std::to_address()'s fancy pointer overload is well-specified.
Definition: cef_to_address.h:72

True if T is completely defined.

◆ IsRefCountedType

template<typename T >
concept base::IsRefCountedType
Initial value:
= requires(T& x) {
x.AddRef();
x.Release();
}

◆ requires

template<typename P >
requires base::requires { typename P::element_type

These constraints cover the cases where std::to_address()'s fancy pointer overload is well-specified.

Note: We check for P::element_type or operator->() instead of directly checking std::pointer_traits<P>::to_address(p) because on GCC 10's libstdc++, instantiating std::pointer_traits<P> for non-pointer-like types triggers a static_assert that cannot be caught by SFINAE/requires.