Chromium Embedded Framework (CEF)  130.1.2+g48f3ef6+chromium-130.0.6723.44
cef_cancelable_callback.h File Reference

CancelableCallback is a wrapper around base::Callback that allows cancellation of a callback. More...

#include <utility>
#include "include/base/cef_bind.h"
#include "include/base/cef_callback.h"
#include "include/base/cef_compiler_specific.h"
#include "include/base/cef_logging.h"
#include "include/base/cef_weak_ptr.h"
#include "include/base/internal/cef_callback_internal.h"

Namespaces

 base
 

Typedefs

template<typename Signature >
using base::CancelableOnceCallback = internal::CancelableCallbackImpl< OnceCallback< Signature > >
 Consider using base::WeakPtr directly instead of base::CancelableCallback for the task cancellation. More...
 
using base::CancelableOnceClosure = CancelableOnceCallback< void()>
 
template<typename Signature >
using base::CancelableRepeatingCallback = internal::CancelableCallbackImpl< RepeatingCallback< Signature > >
 
using base::CancelableRepeatingClosure = CancelableRepeatingCallback< void()>
 

Detailed Description

CancelableCallback is a wrapper around base::Callback that allows cancellation of a callback.

CancelableCallback takes a reference on the wrapped callback until this object is destroyed or Reset()/Cancel() are called.

NOTE:

Calling CancelableCallback::Cancel() brings the object back to its natural, default-constructed state, i.e., CancelableCallback::callback() will return a null callback.

THREAD-SAFETY:

CancelableCallback objects must be created on, posted to, cancelled on, and destroyed on the same thread.

EXAMPLE USAGE:

In the following example, the test is verifying that RunIntensiveTest() Quit()s the message loop within 4 seconds. The cancelable callback is posted to the message loop, the intensive test runs, the message loop is run, then the callback is cancelled.

  RunLoop run_loop;

  void TimeoutCallback(const std::string& timeout_message) {
    FAIL() << timeout_message;
    run_loop.QuitWhenIdle();
  }

  CancelableOnceClosure timeout(
      base::BindOnce(&TimeoutCallback, "Test timed out."));
  ThreadTaskRunnerHandle::Get()->PostDelayedTask(FROM_HERE,
                                                 timeout.callback(),
                                                 TimeDelta::FromSeconds(4));
  RunIntensiveTest();
  run_loop.Run();
  // Hopefully this is hit before the timeout callback runs.
  timeout.Cancel();