Chromium Embedded Framework (CEF)  109.0.1+gcd5e37a+chromium-109.0.5414.8
cef_callback_list.h File Reference

A container for a list of callbacks. More...

#include <algorithm>
#include <list>
#include <memory>
#include <utility>
#include "include/base/cef_auto_reset.h"
#include "include/base/cef_bind.h"
#include "include/base/cef_callback.h"
#include "include/base/cef_callback_helpers.h"
#include "include/base/cef_logging.h"
#include "include/base/cef_weak_ptr.h"

Classes

class  base::CallbackListSubscription
 
class  base::OnceCallbackList< Signature >
 
class  base::RepeatingCallbackList< Signature >
 

Namespaces

 base
 

Typedefs

using base::OnceClosureList = OnceCallbackList< void()>
 Syntactic sugar to parallel that used for Callbacks. More...
 
using base::RepeatingClosureList = RepeatingCallbackList< void()>
 

Detailed Description

A container for a list of callbacks.

Provides callers the ability to manually or automatically unregister callbacks at any time, including during callback notification.

TYPICAL USAGE:

class MyWidget {
 public:
  using CallbackList = base::RepeatingCallbackList<void(const Foo&)>;

  // Registers |cb| to be called whenever NotifyFoo() is executed.
  CallbackListSubscription RegisterCallback(CallbackList::CallbackType cb) {
    return callback_list_.Add(std::move(cb));
  }

 private:
  // Calls all registered callbacks, with |foo| as the supplied arg.
  void NotifyFoo(const Foo& foo) {
    callback_list_.Notify(foo);
  }

  CallbackList callback_list_;
};


class MyWidgetListener {
 private:
  void OnFoo(const Foo& foo) {
    // Called whenever MyWidget::NotifyFoo() is executed, unless
    // |foo_subscription_| has been destroyed.
  }

  // Automatically deregisters the callback when deleted (e.g. in
  // ~MyWidgetListener()).  Unretained(this) is safe here since the
  // ScopedClosureRunner does not outlive |this|.
  CallbackListSubscription foo_subscription_ =
      MyWidget::Get()->RegisterCallback(
          base::BindRepeating(&MyWidgetListener::OnFoo,
                              base::Unretained(this)));
};

UNSUPPORTED:

  • Destroying the CallbackList during callback notification.

This is possible to support, but not currently necessary.