tests: Convert usage of base::Bind to Once or Repeating (see issue #3140)

This commit is contained in:
Marshall Greenblatt 2021-06-19 15:54:45 -04:00
parent ed1840ddb5
commit 529b91bc6e
90 changed files with 1430 additions and 1332 deletions

View File

@ -276,7 +276,7 @@ ClientHandler::ClientHandler(Delegate* delegate,
void ClientHandler::DetachDelegate() {
if (!CURRENTLY_ON_MAIN_THREAD()) {
// Execute this method on the main thread.
MAIN_POST_CLOSURE(base::Bind(&ClientHandler::DetachDelegate, this));
MAIN_POST_CLOSURE(base::BindOnce(&ClientHandler::DetachDelegate, this));
return;
}
@ -717,11 +717,12 @@ bool ClientHandler::OnOpenURLFromTab(
target_disposition == WOD_NEW_FOREGROUND_TAB) {
// Handle middle-click and ctrl + left-click by opening the URL in a new
// browser window.
RootWindowConfig config;
config.with_controls = true;
config.with_osr = is_osr();
config.url = target_url;
MainContext::Get()->GetRootWindowManager()->CreateRootWindow(config);
auto config = std::make_unique<RootWindowConfig>();
config->with_controls = true;
config->with_osr = is_osr();
config->url = target_url;
MainContext::Get()->GetRootWindowManager()->CreateRootWindow(
std::move(config));
return true;
}
@ -935,8 +936,8 @@ void ClientHandler::ShowDevTools(CefRefPtr<CefBrowser> browser,
const CefPoint& inspect_element_at) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&ClientHandler::ShowDevTools, this, browser,
inspect_element_at));
CefPostTask(TID_UI, base::BindOnce(&ClientHandler::ShowDevTools, this,
browser, inspect_element_at));
return;
}
@ -1015,18 +1016,19 @@ void ClientHandler::ShowSSLInformation(CefRefPtr<CefBrowser> browser) {
ss << "</body></html>";
RootWindowConfig config;
config.with_controls = false;
config.with_osr = is_osr();
config.url = test_runner::GetDataURI(ss.str(), "text/html");
MainContext::Get()->GetRootWindowManager()->CreateRootWindow(config);
auto config = std::make_unique<RootWindowConfig>();
config->with_controls = false;
config->with_osr = is_osr();
config->url = test_runner::GetDataURI(ss.str(), "text/html");
MainContext::Get()->GetRootWindowManager()->CreateRootWindow(
std::move(config));
}
void ClientHandler::SetStringResource(const std::string& page,
const std::string& data) {
if (!CefCurrentlyOn(TID_IO)) {
CefPostTask(TID_IO, base::Bind(&ClientHandler::SetStringResource, this,
page, data));
CefPostTask(TID_IO, base::BindOnce(&ClientHandler::SetStringResource, this,
page, data));
return;
}
@ -1053,7 +1055,7 @@ void ClientHandler::NotifyBrowserCreated(CefRefPtr<CefBrowser> browser) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
// Execute this method on the main thread.
MAIN_POST_CLOSURE(
base::Bind(&ClientHandler::NotifyBrowserCreated, this, browser));
base::BindOnce(&ClientHandler::NotifyBrowserCreated, this, browser));
return;
}
@ -1065,7 +1067,7 @@ void ClientHandler::NotifyBrowserClosing(CefRefPtr<CefBrowser> browser) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
// Execute this method on the main thread.
MAIN_POST_CLOSURE(
base::Bind(&ClientHandler::NotifyBrowserClosing, this, browser));
base::BindOnce(&ClientHandler::NotifyBrowserClosing, this, browser));
return;
}
@ -1077,7 +1079,7 @@ void ClientHandler::NotifyBrowserClosed(CefRefPtr<CefBrowser> browser) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
// Execute this method on the main thread.
MAIN_POST_CLOSURE(
base::Bind(&ClientHandler::NotifyBrowserClosed, this, browser));
base::BindOnce(&ClientHandler::NotifyBrowserClosed, this, browser));
return;
}
@ -1088,7 +1090,7 @@ void ClientHandler::NotifyBrowserClosed(CefRefPtr<CefBrowser> browser) {
void ClientHandler::NotifyAddress(const CefString& url) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
// Execute this method on the main thread.
MAIN_POST_CLOSURE(base::Bind(&ClientHandler::NotifyAddress, this, url));
MAIN_POST_CLOSURE(base::BindOnce(&ClientHandler::NotifyAddress, this, url));
return;
}
@ -1099,7 +1101,7 @@ void ClientHandler::NotifyAddress(const CefString& url) {
void ClientHandler::NotifyTitle(const CefString& title) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
// Execute this method on the main thread.
MAIN_POST_CLOSURE(base::Bind(&ClientHandler::NotifyTitle, this, title));
MAIN_POST_CLOSURE(base::BindOnce(&ClientHandler::NotifyTitle, this, title));
return;
}
@ -1110,7 +1112,8 @@ void ClientHandler::NotifyTitle(const CefString& title) {
void ClientHandler::NotifyFavicon(CefRefPtr<CefImage> image) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
// Execute this method on the main thread.
MAIN_POST_CLOSURE(base::Bind(&ClientHandler::NotifyFavicon, this, image));
MAIN_POST_CLOSURE(
base::BindOnce(&ClientHandler::NotifyFavicon, this, image));
return;
}
@ -1122,7 +1125,7 @@ void ClientHandler::NotifyFullscreen(bool fullscreen) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
// Execute this method on the main thread.
MAIN_POST_CLOSURE(
base::Bind(&ClientHandler::NotifyFullscreen, this, fullscreen));
base::BindOnce(&ClientHandler::NotifyFullscreen, this, fullscreen));
return;
}
@ -1134,7 +1137,7 @@ void ClientHandler::NotifyAutoResize(const CefSize& new_size) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
// Execute this method on the main thread.
MAIN_POST_CLOSURE(
base::Bind(&ClientHandler::NotifyAutoResize, this, new_size));
base::BindOnce(&ClientHandler::NotifyAutoResize, this, new_size));
return;
}
@ -1147,8 +1150,8 @@ void ClientHandler::NotifyLoadingState(bool isLoading,
bool canGoForward) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
// Execute this method on the main thread.
MAIN_POST_CLOSURE(base::Bind(&ClientHandler::NotifyLoadingState, this,
isLoading, canGoBack, canGoForward));
MAIN_POST_CLOSURE(base::BindOnce(&ClientHandler::NotifyLoadingState, this,
isLoading, canGoBack, canGoForward));
return;
}
@ -1161,7 +1164,7 @@ void ClientHandler::NotifyDraggableRegions(
if (!CURRENTLY_ON_MAIN_THREAD()) {
// Execute this method on the main thread.
MAIN_POST_CLOSURE(
base::Bind(&ClientHandler::NotifyDraggableRegions, this, regions));
base::BindOnce(&ClientHandler::NotifyDraggableRegions, this, regions));
return;
}
@ -1172,7 +1175,8 @@ void ClientHandler::NotifyDraggableRegions(
void ClientHandler::NotifyTakeFocus(bool next) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
// Execute this method on the main thread.
MAIN_POST_CLOSURE(base::Bind(&ClientHandler::NotifyTakeFocus, this, next));
MAIN_POST_CLOSURE(
base::BindOnce(&ClientHandler::NotifyTakeFocus, this, next));
return;
}

View File

@ -20,7 +20,8 @@ ClientHandlerOsr::ClientHandlerOsr(Delegate* delegate,
void ClientHandlerOsr::DetachOsrDelegate() {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&ClientHandlerOsr::DetachOsrDelegate, this));
CefPostTask(TID_UI,
base::BindOnce(&ClientHandlerOsr::DetachOsrDelegate, this));
return;
}

View File

@ -167,8 +167,8 @@ bool ClientDialogHandlerGtk::OnFileDialog(
params.callback = callback;
GetWindowAndContinue(
browser,
base::Bind(&ClientDialogHandlerGtk::OnFileDialogContinue, this, params));
browser, base::BindOnce(&ClientDialogHandlerGtk::OnFileDialogContinue,
this, params));
return true;
}
@ -190,8 +190,8 @@ bool ClientDialogHandlerGtk::OnJSDialog(CefRefPtr<CefBrowser> browser,
params.callback = callback;
GetWindowAndContinue(
browser,
base::Bind(&ClientDialogHandlerGtk::OnJSDialogContinue, this, params));
browser, base::BindOnce(&ClientDialogHandlerGtk::OnJSDialogContinue, this,
params));
return true;
}
@ -430,16 +430,17 @@ void ClientDialogHandlerGtk::OnJSDialogContinue(OnJSDialogParams params,
void ClientDialogHandlerGtk::GetWindowAndContinue(
CefRefPtr<CefBrowser> browser,
base::Callback<void(GtkWindow*)> callback) {
base::OnceCallback<void(GtkWindow*)> callback) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
MAIN_POST_CLOSURE(base::Bind(&ClientDialogHandlerGtk::GetWindowAndContinue,
this, browser, callback));
MAIN_POST_CLOSURE(
base::BindOnce(&ClientDialogHandlerGtk::GetWindowAndContinue, this,
browser, std::move(callback)));
return;
}
GtkWindow* window = GetWindow(browser);
if (window) {
callback.Run(window);
std::move(callback).Run(window);
}
}
@ -462,8 +463,9 @@ void ClientDialogHandlerGtk::OnDialogResponse(GtkDialog* dialog,
NOTREACHED();
}
CefPostTask(TID_UI, base::Bind(&ClientDialogHandlerGtk::OnResetDialogState,
handler, nullptr));
CefPostTask(TID_UI,
base::BindOnce(&ClientDialogHandlerGtk::OnResetDialogState,
handler, nullptr));
}
} // namespace client

View File

@ -65,7 +65,7 @@ class ClientDialogHandlerGtk : public CefDialogHandler,
void OnJSDialogContinue(OnJSDialogParams params, GtkWindow* window);
void GetWindowAndContinue(CefRefPtr<CefBrowser> browser,
base::Callback<void(GtkWindow*)> callback);
base::OnceCallback<void(GtkWindow*)> callback);
static void OnDialogResponse(GtkDialog* dialog,
gint response_id,

View File

@ -89,13 +89,13 @@ struct ImageCache::ImageContent {
};
void ImageCache::LoadImages(const ImageInfoSet& image_info,
const LoadImagesCallback& callback) {
LoadImagesCallback callback) {
DCHECK(!image_info.empty());
DCHECK(!callback.is_null());
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, base::Bind(&ImageCache::LoadImages, this, image_info,
callback));
CefPostTask(TID_UI, base::BindOnce(&ImageCache::LoadImages, this,
image_info, std::move(callback)));
return;
}
@ -132,10 +132,10 @@ void ImageCache::LoadImages(const ImageInfoSet& image_info,
if (missing_images) {
CefPostTask(TID_FILE_USER_BLOCKING,
base::Bind(&ImageCache::LoadMissing, this, image_info, images,
callback));
base::BindOnce(&ImageCache::LoadMissing, this, image_info,
images, std::move(callback)));
} else {
callback.Run(images);
std::move(callback).Run(images);
}
}
@ -167,7 +167,7 @@ ImageCache::ImageType ImageCache::GetImageType(const std::string& path) {
void ImageCache::LoadMissing(const ImageInfoSet& image_info,
const ImageSet& images,
const LoadImagesCallback& callback) {
LoadImagesCallback callback) {
CEF_REQUIRE_FILE_USER_BLOCKING_THREAD();
DCHECK_EQ(image_info.size(), images.size());
@ -188,8 +188,8 @@ void ImageCache::LoadMissing(const ImageInfoSet& image_info,
contents.push_back(content);
}
CefPostTask(TID_UI, base::Bind(&ImageCache::UpdateCache, this, image_info,
contents, callback));
CefPostTask(TID_UI, base::BindOnce(&ImageCache::UpdateCache, this, image_info,
contents, std::move(callback)));
}
// static
@ -238,7 +238,7 @@ bool ImageCache::LoadImageContents(const std::string& path,
void ImageCache::UpdateCache(const ImageInfoSet& image_info,
const ImageContentSet& contents,
const LoadImagesCallback& callback) {
LoadImagesCallback callback) {
CEF_REQUIRE_UI_THREAD();
DCHECK_EQ(image_info.size(), contents.size());
@ -262,7 +262,7 @@ void ImageCache::UpdateCache(const ImageInfoSet& image_info,
}
}
callback.Run(images);
std::move(callback).Run(images);
}
// static

View File

@ -33,7 +33,7 @@ class ImageCache
// Image scale factor (usually 1.0f or 2.0f).
float scale_factor_;
};
typedef std::vector<ImageRep> ImageRepSet;
using ImageRepSet = std::vector<ImageRep>;
// Unique image that may have multiple representations.
struct ImageInfo {
@ -67,16 +67,16 @@ class ImageCache
// True to force reload.
bool force_reload_;
};
typedef std::vector<ImageInfo> ImageInfoSet;
using ImageInfoSet = std::vector<ImageInfo>;
typedef std::vector<CefRefPtr<CefImage>> ImageSet;
using ImageSet = std::vector<CefRefPtr<CefImage>>;
typedef base::Callback<void(const ImageSet& /*images*/)> LoadImagesCallback;
using LoadImagesCallback =
base::OnceCallback<void(const ImageSet& /*images*/)>;
// Loads the images represented by |image_info|. Executes |callback|
// either synchronously or asychronously on the UI thread after completion.
void LoadImages(const ImageInfoSet& image_info,
const LoadImagesCallback& callback);
void LoadImages(const ImageInfoSet& image_info, LoadImagesCallback callback);
// Returns an image that has already been cached. Must be called on the
// UI thread.
@ -98,12 +98,12 @@ class ImageCache
static ImageType GetImageType(const std::string& path);
struct ImageContent;
typedef std::vector<ImageContent> ImageContentSet;
using ImageContentSet = std::vector<ImageContent>;
// Load missing image contents on the FILE thread.
void LoadMissing(const ImageInfoSet& image_info,
const ImageSet& images,
const LoadImagesCallback& callback);
LoadImagesCallback callback);
static bool LoadImageContents(const ImageInfo& info, ImageContent* content);
static bool LoadImageContents(const std::string& path,
bool internal,
@ -113,12 +113,12 @@ class ImageCache
// Create missing CefImage representations on the UI thread.
void UpdateCache(const ImageInfoSet& image_info,
const ImageContentSet& contents,
const LoadImagesCallback& callback);
LoadImagesCallback callback);
static CefRefPtr<CefImage> CreateImage(const std::string& image_id,
const ImageContent& content);
// Map image ID to image representation. Only accessed on the UI thread.
typedef std::map<std::string, CefRefPtr<CefImage>> ImageMap;
using ImageMap = std::map<std::string, CefRefPtr<CefImage>>;
ImageMap image_map_;
};

View File

@ -105,7 +105,7 @@ int MainMessageLoopMultithreadedGtk::Run() {
}
void MainMessageLoopMultithreadedGtk::Quit() {
PostTask(CefCreateClosureTask(base::Bind(
PostTask(CefCreateClosureTask(base::BindOnce(
&MainMessageLoopMultithreadedGtk::DoQuit, base::Unretained(this))));
}

View File

@ -83,7 +83,7 @@ int MainMessageLoopMultithreadedWin::Run() {
void MainMessageLoopMultithreadedWin::Quit() {
// Execute PostQuitMessage(0) on the main thread.
PostClosure(base::Bind(::PostQuitMessage, 0));
PostClosure(base::BindOnce(::PostQuitMessage, 0));
}
void MainMessageLoopMultithreadedWin::PostTask(CefRefPtr<CefTask> task) {

View File

@ -149,18 +149,17 @@ class MediaObserver : public CefMediaObserver {
class DeviceInfoCallback : public CefMediaSinkDeviceInfoCallback {
public:
// Callback to be executed when the device info is available.
typedef base::Callback<void(const std::string& sink_id,
const CefMediaSinkDeviceInfo& device_info)>
CallbackType;
using CallbackType =
base::OnceCallback<void(const std::string& sink_id,
const CefMediaSinkDeviceInfo& device_info)>;
DeviceInfoCallback(const std::string& sink_id, const CallbackType& callback)
: sink_id_(sink_id), callback_(callback) {}
DeviceInfoCallback(const std::string& sink_id, CallbackType callback)
: sink_id_(sink_id), callback_(std::move(callback)) {}
void OnMediaSinkDeviceInfo(
const CefMediaSinkDeviceInfo& device_info) override {
CEF_REQUIRE_UI_THREAD();
callback_.Run(sink_id_, device_info);
callback_.Reset();
std::move(callback_).Run(sink_id_, device_info);
}
private:
@ -187,9 +186,6 @@ class MediaObserver : public CefMediaObserver {
return;
}
DeviceInfoCallback::CallbackType callback = base::Bind(
&MediaObserver::OnSinkDeviceInfo, this, pending_sink_query_id_);
MediaSinkVector::const_iterator it = sinks.begin();
for (size_t idx = 0; it != sinks.end(); ++it, ++idx) {
CefRefPtr<CefMediaSink> sink = *it;
@ -200,7 +196,9 @@ class MediaObserver : public CefMediaObserver {
// Request the device info asynchronously. Send the response once all
// callbacks have executed.
sink->GetDeviceInfo(new DeviceInfoCallback(sink_id, callback));
auto callback = base::BindOnce(&MediaObserver::OnSinkDeviceInfo, this,
pending_sink_query_id_);
sink->GetDeviceInfo(new DeviceInfoCallback(sink_id, std::move(callback)));
}
}

View File

@ -69,8 +69,8 @@ void OsrRenderHandlerWin::TriggerBeginFrame(uint64_t last_time_us,
// Trigger again after the necessary delay to maintain the desired frame rate.
CefPostDelayedTask(TID_UI,
base::Bind(&OsrRenderHandlerWin::TriggerBeginFrame,
weak_factory_.GetWeakPtr(), now, delay_us),
base::BindOnce(&OsrRenderHandlerWin::TriggerBeginFrame,
weak_factory_.GetWeakPtr(), now, delay_us),
int64(offset / 1000.0));
if (settings_.external_begin_frame_enabled && browser_) {

View File

@ -127,7 +127,7 @@ void OsrWindowWin::CreateBrowser(HWND parent_hwnd,
CreateBrowserHelper* helper =
new CreateBrowserHelper(parent_hwnd, rect, handler, startup_url,
settings, extra_info, request_context, this);
CefPostTask(TID_UI, base::Bind(CreateBrowserWithHelper, helper));
CefPostTask(TID_UI, base::BindOnce(CreateBrowserWithHelper, helper));
return;
}
@ -158,8 +158,8 @@ void OsrWindowWin::ShowPopup(HWND parent_hwnd,
size_t height) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&OsrWindowWin::ShowPopup, this, parent_hwnd,
x, y, width, height));
CefPostTask(TID_UI, base::BindOnce(&OsrWindowWin::ShowPopup, this,
parent_hwnd, x, y, width, height));
return;
}
@ -184,7 +184,7 @@ void OsrWindowWin::ShowPopup(HWND parent_hwnd,
void OsrWindowWin::Show() {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&OsrWindowWin::Show, this));
CefPostTask(TID_UI, base::BindOnce(&OsrWindowWin::Show, this));
return;
}
@ -208,7 +208,7 @@ void OsrWindowWin::Show() {
void OsrWindowWin::Hide() {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&OsrWindowWin::Hide, this));
CefPostTask(TID_UI, base::BindOnce(&OsrWindowWin::Hide, this));
return;
}
@ -228,8 +228,8 @@ void OsrWindowWin::Hide() {
void OsrWindowWin::SetBounds(int x, int y, size_t width, size_t height) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&OsrWindowWin::SetBounds, this, x, y, width,
height));
CefPostTask(TID_UI, base::BindOnce(&OsrWindowWin::SetBounds, this, x, y,
width, height));
return;
}
@ -243,7 +243,7 @@ void OsrWindowWin::SetBounds(int x, int y, size_t width, size_t height) {
void OsrWindowWin::SetFocus() {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&OsrWindowWin::SetFocus, this));
CefPostTask(TID_UI, base::BindOnce(&OsrWindowWin::SetFocus, this));
return;
}
@ -256,8 +256,8 @@ void OsrWindowWin::SetFocus() {
void OsrWindowWin::SetDeviceScaleFactor(float device_scale_factor) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&OsrWindowWin::SetDeviceScaleFactor, this,
device_scale_factor));
CefPostTask(TID_UI, base::BindOnce(&OsrWindowWin::SetDeviceScaleFactor,
this, device_scale_factor));
return;
}
@ -347,7 +347,7 @@ void OsrWindowWin::NotifyNativeWindowCreated(HWND hwnd) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
// Execute this method on the main thread.
MAIN_POST_CLOSURE(
base::Bind(&OsrWindowWin::NotifyNativeWindowCreated, this, hwnd));
base::BindOnce(&OsrWindowWin::NotifyNativeWindowCreated, this, hwnd));
return;
}
@ -921,7 +921,7 @@ void OsrWindowWin::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
if (hwnd_) {
// Show the browser window. Called asynchronously so that the browser has
// time to create associated internal objects.
CefPostTask(TID_UI, base::Bind(&OsrWindowWin::Show, this));
CefPostTask(TID_UI, base::BindOnce(&OsrWindowWin::Show, this));
}
}

View File

@ -5,6 +5,7 @@
#include "tests/cefclient/browser/print_handler_gtk.h"
#include <memory>
#include <vector>
#include <gtk/gtk.h>
@ -282,20 +283,17 @@ GtkWindow* GetWindow(CefRefPtr<CefBrowser> browser) {
return nullptr;
}
void RunCallback(base::Callback<void(GtkWindow*)> callback, GtkWindow* window) {
callback.Run(window);
}
void GetWindowAndContinue(CefRefPtr<CefBrowser> browser,
base::Callback<void(GtkWindow*)> callback) {
base::OnceCallback<void(GtkWindow*)> callback) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
MAIN_POST_CLOSURE(base::Bind(GetWindowAndContinue, browser, callback));
MAIN_POST_CLOSURE(
base::BindOnce(GetWindowAndContinue, browser, std::move(callback)));
return;
}
GtkWindow* window = GetWindow(browser);
if (window) {
CefPostTask(TID_UI, base::Bind(RunCallback, callback, window));
CefPostTask(TID_UI, base::BindOnce(std::move(callback), window));
}
}
@ -543,8 +541,8 @@ struct ClientPrintHandlerGtk::PrintHandler {
// Continue() will result in a call to ClientPrintHandlerGtk::OnPrintReset
// which deletes |this|. Execute it asnychronously so the call stack has a
// chance to unwind.
CefPostTask(TID_UI, base::Bind(&CefPrintJobCallback::Continue,
job_callback_.get()));
CefPostTask(TID_UI, base::BindOnce(&CefPrintJobCallback::Continue,
job_callback_.get()));
job_callback_ = nullptr;
}
@ -598,10 +596,10 @@ bool ClientPrintHandlerGtk::OnPrintDialog(
CefRefPtr<CefPrintDialogCallback> callback) {
CEF_REQUIRE_UI_THREAD();
GetWindowAndContinue(
browser, base::Bind(&PrintHandler::OnPrintDialog,
base::Unretained(print_handler_.get()), has_selection,
callback));
GetWindowAndContinue(browser,
base::BindOnce(&PrintHandler::OnPrintDialog,
base::Unretained(print_handler_.get()),
has_selection, callback));
return true;
}

View File

@ -4,6 +4,8 @@
#include "tests/cefclient/browser/root_window.h"
#include "include/base/cef_callback_helpers.h"
#include "tests/cefclient/browser/main_context.h"
#include "tests/cefclient/browser/root_window_manager.h"
@ -37,7 +39,7 @@ void RootWindow::OnExtensionsChanged(const ExtensionSet& extensions) {
ExtensionSet::const_iterator it = extensions.begin();
for (; it != extensions.end(); ++it) {
delegate_->CreateExtensionWindow(*it, CefRect(), nullptr, base::Closure(),
delegate_->CreateExtensionWindow(*it, CefRect(), nullptr, base::DoNothing(),
WithWindowlessRendering());
}
}

View File

@ -6,6 +6,7 @@
#define CEF_TESTS_CEFCLIENT_BROWSER_ROOT_WINDOW_H_
#pragma once
#include <memory>
#include <set>
#include <string>
@ -57,7 +58,7 @@ struct RootWindowConfig {
// Callback to be executed when the window is closed. Will be executed on the
// main thread. This is currently only implemented for Views-based windows.
base::Closure close_callback;
base::OnceClosure close_callback;
// Initial URL to load.
std::string url;
@ -104,7 +105,7 @@ class RootWindow
virtual void CreateExtensionWindow(CefRefPtr<CefExtension> extension,
const CefRect& source_bounds,
CefRefPtr<CefWindow> parent_window,
const base::Closure& close_callback,
base::OnceClosure close_callback,
bool with_osr) = 0;
protected:
@ -133,7 +134,7 @@ class RootWindow
// Use RootWindowManager::CreateRootWindow() instead of calling this method
// directly.
virtual void Init(RootWindow::Delegate* delegate,
const RootWindowConfig& config,
std::unique_ptr<RootWindowConfig> config,
const CefBrowserSettings& settings) = 0;
// Initialize as a popup window. This is used to attach a new native window to

View File

@ -108,25 +108,25 @@ RootWindowGtk::~RootWindowGtk() {
}
void RootWindowGtk::Init(RootWindow::Delegate* delegate,
const RootWindowConfig& config,
std::unique_ptr<RootWindowConfig> config,
const CefBrowserSettings& settings) {
DCHECK(delegate);
DCHECK(!initialized_);
delegate_ = delegate;
with_controls_ = config.with_controls;
always_on_top_ = config.always_on_top;
with_osr_ = config.with_osr;
with_extension_ = config.with_extension;
start_rect_ = config.bounds;
with_controls_ = config->with_controls;
always_on_top_ = config->always_on_top;
with_osr_ = config->with_osr;
with_extension_ = config->with_extension;
start_rect_ = config->bounds;
CreateBrowserWindow(config.url);
CreateBrowserWindow(config->url);
initialized_ = true;
// Always post asynchronously to avoid reentrancy of the GDK lock.
MAIN_POST_CLOSURE(base::Bind(&RootWindowGtk::CreateRootWindow, this, settings,
config.initially_hidden));
MAIN_POST_CLOSURE(base::BindOnce(&RootWindowGtk::CreateRootWindow, this,
settings, config->initially_hidden));
}
void RootWindowGtk::InitAsPopup(RootWindow::Delegate* delegate,
@ -450,7 +450,7 @@ void RootWindowGtk::OnBrowserCreated(CefRefPtr<CefBrowser> browser) {
void RootWindowGtk::OnBrowserWindowClosing() {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI,
base::Bind(&RootWindowGtk::OnBrowserWindowClosing, this));
base::BindOnce(&RootWindowGtk::OnBrowserWindowClosing, this));
return;
}
@ -552,7 +552,7 @@ void RootWindowGtk::OnSetDraggableRegions(
void RootWindowGtk::NotifyMoveOrResizeStarted() {
if (!CURRENTLY_ON_MAIN_THREAD()) {
MAIN_POST_CLOSURE(
base::Bind(&RootWindowGtk::NotifyMoveOrResizeStarted, this));
base::BindOnce(&RootWindowGtk::NotifyMoveOrResizeStarted, this));
return;
}
@ -569,7 +569,7 @@ void RootWindowGtk::NotifyMoveOrResizeStarted() {
void RootWindowGtk::NotifySetFocus() {
if (!CURRENTLY_ON_MAIN_THREAD()) {
MAIN_POST_CLOSURE(base::Bind(&RootWindowGtk::NotifySetFocus, this));
MAIN_POST_CLOSURE(base::BindOnce(&RootWindowGtk::NotifySetFocus, this));
return;
}
@ -583,7 +583,7 @@ void RootWindowGtk::NotifySetFocus() {
void RootWindowGtk::NotifyVisibilityChange(bool show) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
MAIN_POST_CLOSURE(
base::Bind(&RootWindowGtk::NotifyVisibilityChange, this, show));
base::BindOnce(&RootWindowGtk::NotifyVisibilityChange, this, show));
return;
}
@ -599,7 +599,7 @@ void RootWindowGtk::NotifyVisibilityChange(bool show) {
void RootWindowGtk::NotifyMenuBarHeight(int height) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
MAIN_POST_CLOSURE(
base::Bind(&RootWindowGtk::NotifyMenuBarHeight, this, height));
base::BindOnce(&RootWindowGtk::NotifyMenuBarHeight, this, height));
return;
}
@ -608,8 +608,8 @@ void RootWindowGtk::NotifyMenuBarHeight(int height) {
void RootWindowGtk::NotifyContentBounds(int x, int y, int width, int height) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
MAIN_POST_CLOSURE(base::Bind(&RootWindowGtk::NotifyContentBounds, this, x,
y, width, height));
MAIN_POST_CLOSURE(base::BindOnce(&RootWindowGtk::NotifyContentBounds, this,
x, y, width, height));
return;
}
@ -632,7 +632,7 @@ void RootWindowGtk::NotifyContentBounds(int x, int y, int width, int height) {
void RootWindowGtk::NotifyLoadURL(const std::string& url) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
MAIN_POST_CLOSURE(base::Bind(&RootWindowGtk::NotifyLoadURL, this, url));
MAIN_POST_CLOSURE(base::BindOnce(&RootWindowGtk::NotifyLoadURL, this, url));
return;
}
@ -645,7 +645,7 @@ void RootWindowGtk::NotifyLoadURL(const std::string& url) {
void RootWindowGtk::NotifyButtonClicked(int id) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
MAIN_POST_CLOSURE(
base::Bind(&RootWindowGtk::NotifyButtonClicked, this, id));
base::BindOnce(&RootWindowGtk::NotifyButtonClicked, this, id));
return;
}
@ -673,7 +673,7 @@ void RootWindowGtk::NotifyButtonClicked(int id) {
void RootWindowGtk::NotifyMenuItem(int id) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
MAIN_POST_CLOSURE(base::Bind(&RootWindowGtk::NotifyMenuItem, this, id));
MAIN_POST_CLOSURE(base::BindOnce(&RootWindowGtk::NotifyMenuItem, this, id));
return;
}
@ -684,7 +684,7 @@ void RootWindowGtk::NotifyMenuItem(int id) {
void RootWindowGtk::NotifyForceClose() {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, base::Bind(&RootWindowGtk::NotifyForceClose, this));
CefPostTask(TID_UI, base::BindOnce(&RootWindowGtk::NotifyForceClose, this));
return;
}
@ -693,7 +693,7 @@ void RootWindowGtk::NotifyForceClose() {
void RootWindowGtk::NotifyCloseBrowser() {
if (!CURRENTLY_ON_MAIN_THREAD()) {
MAIN_POST_CLOSURE(base::Bind(&RootWindowGtk::NotifyCloseBrowser, this));
MAIN_POST_CLOSURE(base::BindOnce(&RootWindowGtk::NotifyCloseBrowser, this));
return;
}
@ -709,8 +709,9 @@ void RootWindowGtk::NotifyDestroyedIfDone(bool window_destroyed,
DCHECK_EQ(1, window_destroyed + browser_destroyed);
if (!CURRENTLY_ON_MAIN_THREAD()) {
MAIN_POST_CLOSURE(base::Bind(&RootWindowGtk::NotifyDestroyedIfDone, this,
window_destroyed, browser_destroyed));
MAIN_POST_CLOSURE(base::BindOnce(&RootWindowGtk::NotifyDestroyedIfDone,
this, window_destroyed,
browser_destroyed));
return;
}

View File

@ -26,7 +26,7 @@ class RootWindowGtk : public RootWindow, public BrowserWindow::Delegate {
// RootWindow methods.
void Init(RootWindow::Delegate* delegate,
const RootWindowConfig& config,
std::unique_ptr<RootWindowConfig> config,
const CefBrowserSettings& settings) override;
void InitAsPopup(RootWindow::Delegate* delegate,
bool with_controls,

View File

@ -30,7 +30,7 @@ class RootWindowMac : public RootWindow, public BrowserWindow::Delegate {
// RootWindow methods.
void Init(RootWindow::Delegate* delegate,
const RootWindowConfig& config,
std::unique_ptr<RootWindowConfig> config,
const CefBrowserSettings& settings) override;
void InitAsPopup(RootWindow::Delegate* delegate,
bool with_controls,

View File

@ -86,7 +86,7 @@ class RootWindowMacImpl
// RootWindow methods.
void Init(RootWindow::Delegate* delegate,
const RootWindowConfig& config,
std::unique_ptr<RootWindowConfig> config,
const CefBrowserSettings& settings);
void InitAsPopup(RootWindow::Delegate* delegate,
bool with_controls,
@ -170,25 +170,25 @@ RootWindowMacImpl::~RootWindowMacImpl() {
}
void RootWindowMacImpl::Init(RootWindow::Delegate* delegate,
const RootWindowConfig& config,
std::unique_ptr<RootWindowConfig> config,
const CefBrowserSettings& settings) {
DCHECK(!initialized_);
with_controls_ = config.with_controls;
with_osr_ = config.with_osr;
with_extension_ = config.with_extension;
start_rect_ = config.bounds;
with_controls_ = config->with_controls;
with_osr_ = config->with_osr;
with_extension_ = config->with_extension;
start_rect_ = config->bounds;
CreateBrowserWindow(config.url);
CreateBrowserWindow(config->url);
initialized_ = true;
// Create the native root window on the main thread.
if (CURRENTLY_ON_MAIN_THREAD()) {
CreateRootWindow(settings, config.initially_hidden);
CreateRootWindow(settings, config->initially_hidden);
} else {
MAIN_POST_CLOSURE(base::Bind(&RootWindowMacImpl::CreateRootWindow, this,
settings, config.initially_hidden));
MAIN_POST_CLOSURE(base::BindOnce(&RootWindowMacImpl::CreateRootWindow, this,
settings, config->initially_hidden));
}
}
@ -644,11 +644,11 @@ RootWindow::Delegate* RootWindowMac::delegate() const {
}
void RootWindowMac::Init(RootWindow::Delegate* delegate,
const RootWindowConfig& config,
std::unique_ptr<RootWindowConfig> config,
const CefBrowserSettings& settings) {
DCHECK(delegate);
delegate_ = delegate;
impl_->Init(delegate, config, settings);
impl_->Init(delegate, std::move(config), settings);
}
void RootWindowMac::InitAsPopup(RootWindow::Delegate* delegate,

View File

@ -123,13 +123,13 @@ RootWindowManager::~RootWindowManager() {
}
scoped_refptr<RootWindow> RootWindowManager::CreateRootWindow(
const RootWindowConfig& config) {
std::unique_ptr<RootWindowConfig> config) {
CefBrowserSettings settings;
MainContext::Get()->PopulateBrowserSettings(&settings);
scoped_refptr<RootWindow> root_window =
RootWindow::Create(MainContext::Get()->UseViews());
root_window->Init(this, config, settings);
root_window->Init(this, std::move(config), settings);
// Store a reference to the root window on the main thread.
OnRootWindowCreated(root_window);
@ -168,7 +168,7 @@ scoped_refptr<RootWindow> RootWindowManager::CreateRootWindowAsExtension(
CefRefPtr<CefExtension> extension,
const CefRect& source_bounds,
CefRefPtr<CefWindow> parent_window,
const base::Closure& close_callback,
base::OnceClosure close_callback,
bool with_controls,
bool with_osr) {
const std::string& extension_url = extension_util::GetExtensionURL(extension);
@ -180,16 +180,16 @@ scoped_refptr<RootWindow> RootWindowManager::CreateRootWindowAsExtension(
// Create an initially hidden browser window that loads the extension URL.
// We'll show the window when the desired size becomes available via
// ClientHandler::OnAutoResize.
RootWindowConfig config;
config.with_controls = with_controls;
config.with_osr = with_osr;
config.with_extension = true;
config.initially_hidden = true;
config.source_bounds = source_bounds;
config.parent_window = parent_window;
config.close_callback = close_callback;
config.url = extension_url;
return CreateRootWindow(config);
auto config = std::make_unique<RootWindowConfig>();
config->with_controls = with_controls;
config->with_osr = with_osr;
config->with_extension = true;
config->initially_hidden = true;
config->source_bounds = source_bounds;
config->parent_window = parent_window;
config->close_callback = std::move(close_callback);
config->url = extension_url;
return CreateRootWindow(std::move(config));
}
bool RootWindowManager::HasRootWindowAsExtension(
@ -239,8 +239,8 @@ CefRefPtr<CefBrowser> RootWindowManager::GetActiveBrowser() const {
void RootWindowManager::CloseAllWindows(bool force) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
// Execute this method on the main thread.
MAIN_POST_CLOSURE(base::Bind(&RootWindowManager::CloseAllWindows,
base::Unretained(this), force));
MAIN_POST_CLOSURE(base::BindOnce(&RootWindowManager::CloseAllWindows,
base::Unretained(this), force));
return;
}
@ -259,8 +259,8 @@ void RootWindowManager::CloseAllWindows(bool force) {
void RootWindowManager::AddExtension(CefRefPtr<CefExtension> extension) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
// Execute this method on the main thread.
MAIN_POST_CLOSURE(base::Bind(&RootWindowManager::AddExtension,
base::Unretained(this), extension));
MAIN_POST_CLOSURE(base::BindOnce(&RootWindowManager::AddExtension,
base::Unretained(this), extension));
return;
}
@ -283,8 +283,8 @@ void RootWindowManager::OnRootWindowCreated(
scoped_refptr<RootWindow> root_window) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
// Execute this method on the main thread.
MAIN_POST_CLOSURE(base::Bind(&RootWindowManager::OnRootWindowCreated,
base::Unretained(this), root_window));
MAIN_POST_CLOSURE(base::BindOnce(&RootWindowManager::OnRootWindowCreated,
base::Unretained(this), root_window));
return;
}
@ -385,8 +385,8 @@ void RootWindowManager::OnRootWindowDestroyed(RootWindow* root_window) {
if (terminate_when_all_windows_closed_ && root_windows_.empty()) {
// All windows have closed. Clean up on the UI thread.
CefPostTask(TID_UI, base::Bind(&RootWindowManager::CleanupOnUIThread,
base::Unretained(this)));
CefPostTask(TID_UI, base::BindOnce(&RootWindowManager::CleanupOnUIThread,
base::Unretained(this)));
}
}
@ -425,13 +425,13 @@ void RootWindowManager::CreateExtensionWindow(
CefRefPtr<CefExtension> extension,
const CefRect& source_bounds,
CefRefPtr<CefWindow> parent_window,
const base::Closure& close_callback,
base::OnceClosure close_callback,
bool with_osr) {
REQUIRE_MAIN_THREAD();
if (!HasRootWindowAsExtension(extension)) {
CreateRootWindowAsExtension(extension, source_bounds, parent_window,
close_callback, false, with_osr);
std::move(close_callback), false, with_osr);
}
}

View File

@ -27,7 +27,8 @@ class RootWindowManager : public RootWindow::Delegate {
// Create a new top-level native window. This method can be called from
// anywhere.
scoped_refptr<RootWindow> CreateRootWindow(const RootWindowConfig& config);
scoped_refptr<RootWindow> CreateRootWindow(
std::unique_ptr<RootWindowConfig> config);
// Create a new native popup window.
// If |with_controls| is true the window will show controls.
@ -50,7 +51,7 @@ class RootWindowManager : public RootWindow::Delegate {
CefRefPtr<CefExtension> extension,
const CefRect& source_bounds,
CefRefPtr<CefWindow> parent_window,
const base::Closure& close_callback,
base::OnceClosure close_callback,
bool with_controls,
bool with_osr);
@ -104,7 +105,7 @@ class RootWindowManager : public RootWindow::Delegate {
void CreateExtensionWindow(CefRefPtr<CefExtension> extension,
const CefRect& source_bounds,
CefRefPtr<CefWindow> parent_window,
const base::Closure& close_callback,
base::OnceClosure close_callback,
bool with_osr) override;
void CleanupOnUIThread();

View File

@ -4,6 +4,8 @@
#include "tests/cefclient/browser/root_window_views.h"
#include <memory>
#include "include/base/cef_build.h"
#include "include/base/cef_callback.h"
#include "include/base/cef_cxx17_backports.h"
@ -20,48 +22,35 @@ static const char* kDefaultImageCache[] = {"menu_icon", "window_icon"};
} // namespace
RootWindowViews::RootWindowViews()
: with_controls_(false),
always_on_top_(false),
with_extension_(false),
initially_hidden_(false),
is_popup_(false),
position_on_resize_(false),
initialized_(false),
window_destroyed_(false),
browser_destroyed_(false) {}
RootWindowViews::RootWindowViews() = default;
RootWindowViews::~RootWindowViews() {
REQUIRE_MAIN_THREAD();
}
void RootWindowViews::Init(RootWindow::Delegate* delegate,
const RootWindowConfig& config,
std::unique_ptr<RootWindowConfig> config,
const CefBrowserSettings& settings) {
DCHECK(delegate);
DCHECK(!config.with_osr); // Windowless rendering is not supported.
DCHECK(!config->with_osr); // Windowless rendering is not supported.
DCHECK(!initialized_);
delegate_ = delegate;
with_controls_ = config.with_controls;
always_on_top_ = config.always_on_top;
with_extension_ = config.with_extension;
initially_hidden_ = config.initially_hidden;
if (initially_hidden_ && !config.source_bounds.IsEmpty()) {
config_ = std::move(config);
if (config_->initially_hidden && !config_->source_bounds.IsEmpty()) {
// The window will be sized and positioned in OnAutoResize().
initial_bounds_ = config.source_bounds;
initial_bounds_ = config_->source_bounds;
position_on_resize_ = true;
} else {
initial_bounds_ = config.bounds;
initial_bounds_ = config_->bounds;
}
parent_window_ = config.parent_window;
close_callback_ = config.close_callback;
CreateClientHandler(config.url);
CreateClientHandler(config_->url);
initialized_ = true;
// Continue initialization on the UI thread.
InitOnUIThread(settings, config.url, delegate_->GetRequestContext(this));
InitOnUIThread(settings, config_->url, delegate_->GetRequestContext(this));
}
void RootWindowViews::InitAsPopup(RootWindow::Delegate* delegate,
@ -78,7 +67,8 @@ void RootWindowViews::InitAsPopup(RootWindow::Delegate* delegate,
DCHECK(!initialized_);
delegate_ = delegate;
with_controls_ = with_controls;
config_ = std::make_unique<RootWindowConfig>();
config_->with_controls = with_controls;
is_popup_ = true;
if (popupFeatures.xSet)
@ -100,7 +90,7 @@ void RootWindowViews::InitAsPopup(RootWindow::Delegate* delegate,
void RootWindowViews::Show(ShowMode mode) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&RootWindowViews::Show, this, mode));
CefPostTask(TID_UI, base::BindOnce(&RootWindowViews::Show, this, mode));
return;
}
@ -124,7 +114,7 @@ void RootWindowViews::Show(ShowMode mode) {
void RootWindowViews::Hide() {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&RootWindowViews::Hide, this));
CefPostTask(TID_UI, base::BindOnce(&RootWindowViews::Hide, this));
return;
}
@ -135,8 +125,8 @@ void RootWindowViews::Hide() {
void RootWindowViews::SetBounds(int x, int y, size_t width, size_t height) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&RootWindowViews::SetBounds, this, x, y,
width, height));
CefPostTask(TID_UI, base::BindOnce(&RootWindowViews::SetBounds, this, x, y,
width, height));
return;
}
@ -149,7 +139,7 @@ void RootWindowViews::SetBounds(int x, int y, size_t width, size_t height) {
void RootWindowViews::Close(bool force) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&RootWindowViews::Close, this, force));
CefPostTask(TID_UI, base::BindOnce(&RootWindowViews::Close, this, force));
return;
}
@ -189,24 +179,24 @@ ClientWindowHandle RootWindowViews::GetWindowHandle() const {
bool RootWindowViews::WithExtension() const {
DCHECK(initialized_);
return with_extension_;
return config_->with_extension;
}
bool RootWindowViews::WithControls() {
DCHECK(initialized_);
return with_controls_;
return config_->with_controls;
}
bool RootWindowViews::WithExtension() {
DCHECK(initialized_);
return with_extension_;
return config_->with_extension;
}
void RootWindowViews::OnExtensionsChanged(const ExtensionSet& extensions) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&RootWindowViews::OnExtensionsChanged, this,
extensions));
CefPostTask(TID_UI, base::BindOnce(&RootWindowViews::OnExtensionsChanged,
this, extensions));
return;
}
@ -220,12 +210,12 @@ void RootWindowViews::OnExtensionsChanged(const ExtensionSet& extensions) {
bool RootWindowViews::InitiallyHidden() {
CEF_REQUIRE_UI_THREAD();
return initially_hidden_;
return config_->initially_hidden;
}
CefRefPtr<CefWindow> RootWindowViews::GetParentWindow() {
CEF_REQUIRE_UI_THREAD();
return parent_window_;
return config_->parent_window;
}
CefRect RootWindowViews::GetWindowBounds() {
@ -242,7 +232,7 @@ void RootWindowViews::OnViewsWindowCreated(CefRefPtr<ViewsWindow> window) {
CEF_REQUIRE_UI_THREAD();
DCHECK(!window_);
window_ = window;
window_->SetAlwaysOnTop(always_on_top_);
window_->SetAlwaysOnTop(config_->always_on_top);
if (!pending_extensions_.empty()) {
window_->OnExtensionsChanged(pending_extensions_);
@ -256,7 +246,7 @@ void RootWindowViews::OnViewsWindowDestroyed(CefRefPtr<ViewsWindow> window) {
// Continue on the main thread.
MAIN_POST_CLOSURE(
base::Bind(&RootWindowViews::NotifyViewsWindowDestroyed, this));
base::BindOnce(&RootWindowViews::NotifyViewsWindowDestroyed, this));
}
void RootWindowViews::OnViewsWindowActivated(CefRefPtr<ViewsWindow> window) {
@ -264,7 +254,7 @@ void RootWindowViews::OnViewsWindowActivated(CefRefPtr<ViewsWindow> window) {
// Continue on the main thread.
MAIN_POST_CLOSURE(
base::Bind(&RootWindowViews::NotifyViewsWindowActivated, this));
base::BindOnce(&RootWindowViews::NotifyViewsWindowActivated, this));
}
ViewsWindow::Delegate* RootWindowViews::GetDelegateForPopup(
@ -281,27 +271,26 @@ ViewsWindow::Delegate* RootWindowViews::GetDelegateForPopup(
return root_window;
}
void RootWindowViews::CreateExtensionWindow(
CefRefPtr<CefExtension> extension,
const CefRect& source_bounds,
CefRefPtr<CefWindow> parent_window,
const base::Closure& close_callback) {
void RootWindowViews::CreateExtensionWindow(CefRefPtr<CefExtension> extension,
const CefRect& source_bounds,
CefRefPtr<CefWindow> parent_window,
base::OnceClosure close_callback) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
// Execute this method on the main thread.
MAIN_POST_CLOSURE(base::Bind(&RootWindowViews::CreateExtensionWindow, this,
extension, source_bounds, parent_window,
close_callback));
MAIN_POST_CLOSURE(base::BindOnce(&RootWindowViews::CreateExtensionWindow,
this, extension, source_bounds,
parent_window, std::move(close_callback)));
return;
}
delegate_->CreateExtensionWindow(extension, source_bounds, parent_window,
close_callback, false);
std::move(close_callback), false);
}
void RootWindowViews::OnTest(int test_id) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
// Execute this method on the main thread.
MAIN_POST_CLOSURE(base::Bind(&RootWindowViews::OnTest, this, test_id));
MAIN_POST_CLOSURE(base::BindOnce(&RootWindowViews::OnTest, this, test_id));
return;
}
@ -311,7 +300,7 @@ void RootWindowViews::OnTest(int test_id) {
void RootWindowViews::OnExit() {
if (!CURRENTLY_ON_MAIN_THREAD()) {
// Execute this method on the main thread.
MAIN_POST_CLOSURE(base::Bind(&RootWindowViews::OnExit, this));
MAIN_POST_CLOSURE(base::BindOnce(&RootWindowViews::OnExit, this));
return;
}
@ -347,18 +336,20 @@ void RootWindowViews::OnBrowserClosed(CefRefPtr<CefBrowser> browser) {
void RootWindowViews::OnSetAddress(const std::string& url) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&RootWindowViews::OnSetAddress, this, url));
CefPostTask(TID_UI,
base::BindOnce(&RootWindowViews::OnSetAddress, this, url));
return;
}
if (window_ && with_controls_)
if (window_ && config_->with_controls)
window_->SetAddress(url);
}
void RootWindowViews::OnSetTitle(const std::string& title) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&RootWindowViews::OnSetTitle, this, title));
CefPostTask(TID_UI,
base::BindOnce(&RootWindowViews::OnSetTitle, this, title));
return;
}
@ -370,7 +361,7 @@ void RootWindowViews::OnSetFavicon(CefRefPtr<CefImage> image) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI,
base::Bind(&RootWindowViews::OnSetFavicon, this, image));
base::BindOnce(&RootWindowViews::OnSetFavicon, this, image));
return;
}
@ -381,8 +372,8 @@ void RootWindowViews::OnSetFavicon(CefRefPtr<CefImage> image) {
void RootWindowViews::OnSetFullscreen(bool fullscreen) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&RootWindowViews::OnSetFullscreen, this,
fullscreen));
CefPostTask(TID_UI, base::BindOnce(&RootWindowViews::OnSetFullscreen, this,
fullscreen));
return;
}
@ -394,7 +385,7 @@ void RootWindowViews::OnAutoResize(const CefSize& new_size) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI,
base::Bind(&RootWindowViews::OnAutoResize, this, new_size));
base::BindOnce(&RootWindowViews::OnAutoResize, this, new_size));
return;
}
@ -422,13 +413,14 @@ void RootWindowViews::OnSetLoadingState(bool isLoading,
bool canGoForward) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&RootWindowViews::OnSetLoadingState, this,
isLoading, canGoBack, canGoForward));
CefPostTask(TID_UI,
base::BindOnce(&RootWindowViews::OnSetLoadingState, this,
isLoading, canGoBack, canGoForward));
return;
}
if (window_) {
if (with_controls_)
if (config_->with_controls)
window_->SetLoadingState(isLoading, canGoBack, canGoForward);
if (isLoading) {
@ -443,8 +435,8 @@ void RootWindowViews::OnSetDraggableRegions(
const std::vector<CefDraggableRegion>& regions) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&RootWindowViews::OnSetDraggableRegions,
this, regions));
CefPostTask(TID_UI, base::BindOnce(&RootWindowViews::OnSetDraggableRegions,
this, regions));
return;
}
@ -455,7 +447,8 @@ void RootWindowViews::OnSetDraggableRegions(
void RootWindowViews::OnTakeFocus(bool next) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&RootWindowViews::OnTakeFocus, this, next));
CefPostTask(TID_UI,
base::BindOnce(&RootWindowViews::OnTakeFocus, this, next));
return;
}
@ -482,8 +475,8 @@ void RootWindowViews::InitOnUIThread(
CefRefPtr<CefRequestContext> request_context) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&RootWindowViews::InitOnUIThread, this,
settings, startup_url, request_context));
CefPostTask(TID_UI, base::BindOnce(&RootWindowViews::InitOnUIThread, this,
settings, startup_url, request_context));
return;
}
@ -495,8 +488,8 @@ void RootWindowViews::InitOnUIThread(
image_set.push_back(ImageCache::ImageInfo::Create2x(kDefaultImageCache[i]));
image_cache_->LoadImages(
image_set, base::Bind(&RootWindowViews::CreateViewsWindow, this, settings,
startup_url, request_context));
image_set, base::BindOnce(&RootWindowViews::CreateViewsWindow, this,
settings, startup_url, request_context));
}
void RootWindowViews::CreateViewsWindow(
@ -535,8 +528,8 @@ void RootWindowViews::NotifyDestroyedIfDone() {
// Notify once both the window and the browser have been destroyed.
if (window_destroyed_ && browser_destroyed_) {
delegate_->OnRootWindowDestroyed(this);
if (!close_callback_.is_null())
close_callback_.Run();
if (!config_->close_callback.is_null())
std::move(config_->close_callback).Run();
}
}

View File

@ -28,7 +28,7 @@ class RootWindowViews : public RootWindow,
// RootWindow methods:
void Init(RootWindow::Delegate* delegate,
const RootWindowConfig& config,
std::unique_ptr<RootWindowConfig> config,
const CefBrowserSettings& settings) override;
void InitAsPopup(RootWindow::Delegate* delegate,
bool with_controls,
@ -64,7 +64,7 @@ class RootWindowViews : public RootWindow,
void CreateExtensionWindow(CefRefPtr<CefExtension> extension,
const CefRect& source_bounds,
CefRefPtr<CefWindow> parent_window,
const base::Closure& close_callback) override;
base::OnceClosure close_callback) override;
void OnTest(int test_id) override;
void OnExit() override;
@ -104,20 +104,15 @@ class RootWindowViews : public RootWindow,
// After initialization all members are only accessed on the main thread
// unless otherwise indicated.
// Members set during initialization.
bool with_controls_;
bool always_on_top_;
bool with_extension_;
bool initially_hidden_;
CefRefPtr<CefWindow> parent_window_;
bool is_popup_;
std::unique_ptr<RootWindowConfig> config_;
bool is_popup_ = false;
CefRect initial_bounds_;
base::Closure close_callback_;
bool position_on_resize_;
bool position_on_resize_ = false;
CefRefPtr<ClientHandler> client_handler_;
bool initialized_;
bool window_destroyed_;
bool browser_destroyed_;
bool initialized_ = false;
bool window_destroyed_ = false;
bool browser_destroyed_ = false;
CefRefPtr<CefBrowser> browser_;

View File

@ -146,32 +146,32 @@ RootWindowWin::~RootWindowWin() {
}
void RootWindowWin::Init(RootWindow::Delegate* delegate,
const RootWindowConfig& config,
std::unique_ptr<RootWindowConfig> config,
const CefBrowserSettings& settings) {
DCHECK(delegate);
DCHECK(!initialized_);
delegate_ = delegate;
with_controls_ = config.with_controls;
always_on_top_ = config.always_on_top;
with_osr_ = config.with_osr;
with_extension_ = config.with_extension;
with_controls_ = config->with_controls;
always_on_top_ = config->always_on_top;
with_osr_ = config->with_osr;
with_extension_ = config->with_extension;
start_rect_.left = config.bounds.x;
start_rect_.top = config.bounds.y;
start_rect_.right = config.bounds.x + config.bounds.width;
start_rect_.bottom = config.bounds.y + config.bounds.height;
start_rect_.left = config->bounds.x;
start_rect_.top = config->bounds.y;
start_rect_.right = config->bounds.x + config->bounds.width;
start_rect_.bottom = config->bounds.y + config->bounds.height;
CreateBrowserWindow(config.url);
CreateBrowserWindow(config->url);
initialized_ = true;
// Create the native root window on the main thread.
if (CURRENTLY_ON_MAIN_THREAD()) {
CreateRootWindow(settings, config.initially_hidden);
CreateRootWindow(settings, config->initially_hidden);
} else {
MAIN_POST_CLOSURE(base::Bind(&RootWindowWin::CreateRootWindow, this,
settings, config.initially_hidden));
MAIN_POST_CLOSURE(base::BindOnce(&RootWindowWin::CreateRootWindow, this,
settings, config->initially_hidden));
}
}

View File

@ -29,7 +29,7 @@ class RootWindowWin : public RootWindow, public BrowserWindow::Delegate {
// RootWindow methods.
void Init(RootWindow::Delegate* delegate,
const RootWindowConfig& config,
std::unique_ptr<RootWindowConfig> config,
const CefBrowserSettings& settings) override;
void InitAsPopup(RootWindow::Delegate* delegate,
bool with_controls,

View File

@ -5,6 +5,7 @@
#include "tests/cefclient/browser/server_test.h"
#include <algorithm>
#include <memory>
#include <string>
#include "include/base/cef_callback.h"
@ -42,25 +43,25 @@ const char kDefaultPath[] = "websocket.html";
// Handles the HTTP/WebSocket server.
class ServerHandler : public CefServerHandler {
public:
typedef base::Callback<void(bool /* success */)> CompleteCallback;
using CompleteCallback = base::OnceCallback<void(bool /* success */)>;
ServerHandler() {}
// |complete_callback| will be executed on the UI thread after completion.
void StartServer(int port, const CompleteCallback& complete_callback) {
void StartServer(int port, CompleteCallback complete_callback) {
CEF_REQUIRE_UI_THREAD();
DCHECK(!server_);
DCHECK(port >= 1025 && port <= 65535);
port_ = port;
complete_callback_ = complete_callback;
complete_callback_ = std::move(complete_callback);
CefServer::CreateServer(kServerAddress, port, kServerBacklog, this);
}
// |complete_callback| will be executed on the UI thread after completion.
void StopServer(const CompleteCallback& complete_callback) {
void StopServer(CompleteCallback complete_callback) {
CEF_REQUIRE_UI_THREAD();
DCHECK(server_);
complete_callback_ = complete_callback;
complete_callback_ = std::move(complete_callback);
server_->Shutdown();
}
@ -159,14 +160,13 @@ class ServerHandler : public CefServerHandler {
private:
void RunCompleteCallback(bool success) {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, base::Bind(&ServerHandler::RunCompleteCallback, this,
success));
CefPostTask(TID_UI, base::BindOnce(&ServerHandler::RunCompleteCallback,
this, success));
return;
}
if (!complete_callback_.is_null()) {
complete_callback_.Run(success);
complete_callback_.Reset();
std::move(complete_callback_).Run(success);
}
}
@ -292,9 +292,9 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
handler_ = new ServerHandler();
// Start the server. OnComplete will be executed upon completion.
handler_->StartServer(port,
base::Bind(&Handler::OnStartComplete,
weak_ptr_factory_.GetWeakPtr(), callback));
handler_->StartServer(
port, base::BindOnce(&Handler::OnStartComplete,
weak_ptr_factory_.GetWeakPtr(), callback));
}
// Stop the server.
@ -306,8 +306,8 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
}
// Stop the server. OnComplete will be executed upon completion.
handler_->StopServer(base::Bind(&Handler::OnStopComplete,
weak_ptr_factory_.GetWeakPtr(), callback));
handler_->StopServer(base::BindOnce(
&Handler::OnStopComplete, weak_ptr_factory_.GetWeakPtr(), callback));
handler_ = nullptr;
}

View File

@ -152,10 +152,11 @@ void RunRequestTest(CefRefPtr<CefBrowser> browser) {
}
void RunNewWindowTest(CefRefPtr<CefBrowser> browser) {
RootWindowConfig config;
config.with_controls = true;
config.with_osr = browser->GetHost()->IsWindowRenderingDisabled();
MainContext::Get()->GetRootWindowManager()->CreateRootWindow(config);
auto config = std::make_unique<RootWindowConfig>();
config->with_controls = true;
config->with_osr = browser->GetHost()->IsWindowRenderingDisabled();
MainContext::Get()->GetRootWindowManager()->CreateRootWindow(
std::move(config));
}
void RunPopupWindowTest(CefRefPtr<CefBrowser> browser) {
@ -201,7 +202,7 @@ void RunPluginInfoTest(CefRefPtr<CefBrowser> browser) {
void ModifyZoom(CefRefPtr<CefBrowser> browser, double delta) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute on the UI thread.
CefPostTask(TID_UI, base::Bind(&ModifyZoom, browser, delta));
CefPostTask(TID_UI, base::BindOnce(&ModifyZoom, browser, delta));
return;
}
@ -264,7 +265,7 @@ class PromptHandler : public CefMessageRouterBrowserSide::Handler {
void SetDSF(CefRefPtr<CefBrowser> browser, float dsf) {
MainMessageLoop::Get()->PostClosure(
base::Bind(&PromptHandler::SetDSFOnMainThread, browser, dsf));
base::BindOnce(&PromptHandler::SetDSFOnMainThread, browser, dsf));
}
static void SetDSFOnMainThread(CefRefPtr<CefBrowser> browser, float dsf) {
@ -291,7 +292,7 @@ void Prompt(CefRefPtr<CefBrowser> browser,
void PromptFPS(CefRefPtr<CefBrowser> browser) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute on the UI thread.
CefPostTask(TID_UI, base::Bind(&PromptFPS, browser));
CefPostTask(TID_UI, base::BindOnce(&PromptFPS, browser));
return;
}
@ -305,7 +306,7 @@ void PromptFPS(CefRefPtr<CefBrowser> browser) {
void PromptDSF(CefRefPtr<CefBrowser> browser) {
if (!MainMessageLoop::Get()->RunsTasksOnCurrentThread()) {
// Execute on the main thread.
MainMessageLoop::Get()->PostClosure(base::Bind(&PromptDSF, browser));
MainMessageLoop::Get()->PostClosure(base::BindOnce(&PromptDSF, browser));
return;
}
@ -320,7 +321,7 @@ void PromptDSF(CefRefPtr<CefBrowser> browser) {
void BeginTracing() {
if (!CefCurrentlyOn(TID_UI)) {
// Execute on the UI thread.
CefPostTask(TID_UI, base::Bind(&BeginTracing));
CefPostTask(TID_UI, base::BindOnce(&BeginTracing));
return;
}
@ -330,7 +331,7 @@ void BeginTracing() {
void EndTracing(CefRefPtr<CefBrowser> browser) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute on the UI thread.
CefPostTask(TID_UI, base::Bind(&EndTracing, browser));
CefPostTask(TID_UI, base::BindOnce(&EndTracing, browser));
return;
}
@ -386,7 +387,7 @@ void EndTracing(CefRefPtr<CefBrowser> browser) {
void PrintToPDF(CefRefPtr<CefBrowser> browser) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute on the UI thread.
CefPostTask(TID_UI, base::Bind(&PrintToPDF, browser));
CefPostTask(TID_UI, base::BindOnce(&PrintToPDF, browser));
return;
}
@ -799,15 +800,15 @@ void SetupResourceManager(CefRefPtr<CefResourceManager> resource_manager,
StringResourceMap* string_resource_map) {
if (!CefCurrentlyOn(TID_IO)) {
// Execute on the browser IO thread.
CefPostTask(TID_IO, base::Bind(SetupResourceManager, resource_manager,
string_resource_map));
CefPostTask(TID_IO, base::BindOnce(SetupResourceManager, resource_manager,
string_resource_map));
return;
}
const std::string& test_origin = kTestOrigin;
// Add the URL filter.
resource_manager->SetUrlFilter(base::Bind(RequestUrlFilter));
resource_manager->SetUrlFilter(base::BindRepeating(RequestUrlFilter));
// Add provider for resource dumps.
resource_manager->AddProvider(

View File

@ -4,6 +4,7 @@
#include "tests/cefclient/browser/urlrequest_test.h"
#include <memory>
#include <string>
#include "include/base/cef_callback.h"
@ -25,11 +26,11 @@ const char kTestMessageName[] = "URLRequestTest";
class RequestClient : public CefURLRequestClient {
public:
// Callback to be executed on request completion.
typedef base::Callback<void(CefURLRequest::ErrorCode /*error_code*/,
const std::string& /*download_data*/)>
Callback;
using Callback =
base::OnceCallback<void(CefURLRequest::ErrorCode /*error_code*/,
const std::string& /*download_data*/)>;
explicit RequestClient(const Callback& callback) : callback_(callback) {
explicit RequestClient(Callback callback) : callback_(std::move(callback)) {
CEF_REQUIRE_UI_THREAD();
DCHECK(!callback_.is_null());
}
@ -43,8 +44,7 @@ class RequestClient : public CefURLRequestClient {
void OnRequestComplete(CefRefPtr<CefURLRequest> request) override {
CEF_REQUIRE_UI_THREAD();
if (!callback_.is_null()) {
callback_.Run(request->GetRequestError(), download_data_);
callback_.Reset();
std::move(callback_).Run(request->GetRequestError(), download_data_);
}
}
@ -122,13 +122,13 @@ class Handler : public CefMessageRouterBrowserSide::Handler {
// It's safe to use base::Unretained() here because there is only one
// RequestClient pending at any given time and we explicitly detach the
// callback in the Handler destructor.
const RequestClient::Callback& request_callback =
base::Bind(&Handler::OnRequestComplete, base::Unretained(this));
auto request_callback =
base::BindOnce(&Handler::OnRequestComplete, base::Unretained(this));
// Create and start a new CefURLRequest associated with the frame, so
// that it shares authentication with ClientHandler::GetAuthCredentials.
urlrequest_ = frame->CreateURLRequest(
cef_request, new RequestClient(request_callback));
cef_request, new RequestClient(std::move(request_callback)));
return true;
}

View File

@ -320,7 +320,7 @@ void ViewsWindow::OnExtensionsChanged(const ExtensionSet& extensions) {
delegate_->GetImageCache()->LoadImages(
image_set,
base::Bind(&ViewsWindow::OnExtensionIconsLoaded, this, extensions));
base::BindOnce(&ViewsWindow::OnExtensionIconsLoaded, this, extensions));
}
CefRefPtr<CefBrowserViewDelegate> ViewsWindow::GetDelegateForPopupBrowserView(
@ -423,7 +423,7 @@ void ViewsWindow::OnMenuButtonPressed(
// Create a window for the extension.
delegate_->CreateExtensionWindow(
extensions_[extension_idx].extension_, menu_button->GetBoundsInScreen(),
window_, base::Bind(&ViewsWindow::OnExtensionWindowClosed, this));
window_, base::BindOnce(&ViewsWindow::OnExtensionWindowClosed, this));
return;
}
@ -983,8 +983,8 @@ void ViewsWindow::OnExtensionIconsLoaded(const ExtensionSet& extensions,
const ImageCache::ImageSet& images) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI, base::Bind(&ViewsWindow::OnExtensionIconsLoaded, this,
extensions, images));
CefPostTask(TID_UI, base::BindOnce(&ViewsWindow::OnExtensionIconsLoaded,
this, extensions, images));
return;
}
@ -1008,7 +1008,7 @@ void ViewsWindow::OnExtensionWindowClosed() {
if (!CefCurrentlyOn(TID_UI)) {
// Execute this method on the UI thread.
CefPostTask(TID_UI,
base::Bind(&ViewsWindow::OnExtensionWindowClosed, this));
base::BindOnce(&ViewsWindow::OnExtensionWindowClosed, this));
return;
}

View File

@ -78,7 +78,7 @@ class ViewsWindow : public CefBrowserViewDelegate,
virtual void CreateExtensionWindow(CefRefPtr<CefExtension> extension,
const CefRect& source_bounds,
CefRefPtr<CefWindow> parent_window,
const base::Closure& close_callback) = 0;
base::OnceClosure close_callback) = 0;
// Called to execute a test. See resource.h for |test_id| values.
virtual void OnTest(int test_id) = 0;

View File

@ -115,19 +115,19 @@ void WindowTestRunnerGtk::SetPos(CefRefPtr<CefBrowser> browser,
int y,
int width,
int height) {
MAIN_POST_CLOSURE(base::Bind(SetPosImpl, browser, x, y, width, height));
MAIN_POST_CLOSURE(base::BindOnce(SetPosImpl, browser, x, y, width, height));
}
void WindowTestRunnerGtk::Minimize(CefRefPtr<CefBrowser> browser) {
MAIN_POST_CLOSURE(base::Bind(MinimizeImpl, browser));
MAIN_POST_CLOSURE(base::BindOnce(MinimizeImpl, browser));
}
void WindowTestRunnerGtk::Maximize(CefRefPtr<CefBrowser> browser) {
MAIN_POST_CLOSURE(base::Bind(MaximizeImpl, browser));
MAIN_POST_CLOSURE(base::BindOnce(MaximizeImpl, browser));
}
void WindowTestRunnerGtk::Restore(CefRefPtr<CefBrowser> browser) {
MAIN_POST_CLOSURE(base::Bind(RestoreImpl, browser));
MAIN_POST_CLOSURE(base::BindOnce(RestoreImpl, browser));
}
} // namespace window_test

View File

@ -104,7 +104,7 @@ void WindowTestRunnerWin::SetPos(CefRefPtr<CefBrowser> browser,
SetPosImpl(browser, x, y, width, height);
} else {
// Execute on the main application thread.
MAIN_POST_CLOSURE(base::Bind(SetPosImpl, browser, x, y, width, height));
MAIN_POST_CLOSURE(base::BindOnce(SetPosImpl, browser, x, y, width, height));
}
}
@ -113,7 +113,7 @@ void WindowTestRunnerWin::Minimize(CefRefPtr<CefBrowser> browser) {
MinimizeImpl(browser);
} else {
// Execute on the main application thread.
MAIN_POST_CLOSURE(base::Bind(MinimizeImpl, browser));
MAIN_POST_CLOSURE(base::BindOnce(MinimizeImpl, browser));
}
}
@ -122,7 +122,7 @@ void WindowTestRunnerWin::Maximize(CefRefPtr<CefBrowser> browser) {
MaximizeImpl(browser);
} else {
// Execute on the main application thread.
MAIN_POST_CLOSURE(base::Bind(MaximizeImpl, browser));
MAIN_POST_CLOSURE(base::BindOnce(MaximizeImpl, browser));
}
}
@ -131,7 +131,7 @@ void WindowTestRunnerWin::Restore(CefRefPtr<CefBrowser> browser) {
RestoreImpl(browser);
} else {
// Execute on the main application thread.
MAIN_POST_CLOSURE(base::Bind(RestoreImpl, browser));
MAIN_POST_CLOSURE(base::BindOnce(RestoreImpl, browser));
}
}

View File

@ -135,14 +135,16 @@ int RunMain(int argc, char* argv[]) {
// Register scheme handlers.
test_runner::RegisterSchemeHandlers();
RootWindowConfig window_config;
window_config.always_on_top = command_line->HasSwitch(switches::kAlwaysOnTop);
window_config.with_controls =
auto window_config = std::make_unique<RootWindowConfig>();
window_config->always_on_top =
command_line->HasSwitch(switches::kAlwaysOnTop);
window_config->with_controls =
!command_line->HasSwitch(switches::kHideControls);
window_config.with_osr = settings.windowless_rendering_enabled ? true : false;
window_config->with_osr =
settings.windowless_rendering_enabled ? true : false;
// Create the first window.
context->GetRootWindowManager()->CreateRootWindow(window_config);
context->GetRootWindowManager()->CreateRootWindow(std::move(window_config));
// Run the message loop. This will block until Quit() is called.
int result = message_loop->Run();

View File

@ -219,13 +219,13 @@ NSMenuItem* GetMenuItemWithAction(NSMenu* menu, SEL action_selector) {
}
}
client::RootWindowConfig window_config;
window_config.with_controls = with_controls_;
window_config.with_osr = with_osr_;
auto window_config = std::make_unique<client::RootWindowConfig>();
window_config->with_controls = with_controls_;
window_config->with_osr = with_osr_;
// Create the first window.
client::MainContext::Get()->GetRootWindowManager()->CreateRootWindow(
window_config);
std::move(window_config));
}
- (void)tryToTerminateApplication:(NSApplication*)app {

View File

@ -99,14 +99,16 @@ int RunMain(HINSTANCE hInstance, int nCmdShow) {
// Register scheme handlers.
test_runner::RegisterSchemeHandlers();
RootWindowConfig window_config;
window_config.always_on_top = command_line->HasSwitch(switches::kAlwaysOnTop);
window_config.with_controls =
auto window_config = std::make_unique<RootWindowConfig>();
window_config->always_on_top =
command_line->HasSwitch(switches::kAlwaysOnTop);
window_config->with_controls =
!command_line->HasSwitch(switches::kHideControls);
window_config.with_osr = settings.windowless_rendering_enabled ? true : false;
window_config->with_osr =
settings.windowless_rendering_enabled ? true : false;
// Create the first window.
context->GetRootWindowManager()->CreateRootWindow(window_config);
context->GetRootWindowManager()->CreateRootWindow(std::move(window_config));
// Run the message loop. This will block until Quit() is called by the
// RootWindowManager after all windows have been destroyed.

View File

@ -131,8 +131,8 @@ void SimpleHandler::OnLoadError(CefRefPtr<CefBrowser> browser,
void SimpleHandler::CloseAllBrowsers(bool force_close) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute on the UI thread.
CefPostTask(TID_UI, base::Bind(&SimpleHandler::CloseAllBrowsers, this,
force_close));
CefPostTask(TID_UI, base::BindOnce(&SimpleHandler::CloseAllBrowsers, this,
force_close));
return;
}

View File

@ -93,12 +93,14 @@ class TestVisitor : public CefCookieVisitor {
public:
TestVisitor(CookieVector* cookies,
bool deleteCookies,
const base::Closure& callback)
: cookies_(cookies), delete_cookies_(deleteCookies), callback_(callback) {
base::OnceClosure callback)
: cookies_(cookies),
delete_cookies_(deleteCookies),
callback_(std::move(callback)) {
EXPECT_TRUE(cookies_);
EXPECT_FALSE(callback_.is_null());
}
~TestVisitor() override { callback_.Run(); }
~TestVisitor() override { std::move(callback_).Run(); }
bool Visit(const CefCookie& cookie,
int count,
@ -114,7 +116,7 @@ class TestVisitor : public CefCookieVisitor {
private:
CookieVector* cookies_;
bool delete_cookies_;
base::Closure callback_;
base::OnceClosure callback_;
IMPLEMENT_REFCOUNTING(TestVisitor);
};
@ -177,10 +179,10 @@ void VisitUrlCookies(CefRefPtr<CefCookieManager> manager,
bool includeHttpOnly,
CookieVector& cookies,
bool deleteCookies,
const base::Closure& callback) {
base::OnceClosure callback) {
EXPECT_TRUE(manager->VisitUrlCookies(
url, includeHttpOnly,
new TestVisitor(&cookies, deleteCookies, callback)));
new TestVisitor(&cookies, deleteCookies, std::move(callback))));
}
// Visit URL cookies. Block on |event|.
@ -191,7 +193,7 @@ void VisitUrlCookies(CefRefPtr<CefCookieManager> manager,
bool deleteCookies,
CefRefPtr<CefWaitableEvent> event) {
VisitUrlCookies(manager, url, includeHttpOnly, cookies, deleteCookies,
base::Bind(&CefWaitableEvent::Signal, event));
base::BindOnce(&CefWaitableEvent::Signal, event));
event->Wait();
}
@ -199,9 +201,9 @@ void VisitUrlCookies(CefRefPtr<CefCookieManager> manager,
void VisitAllCookies(CefRefPtr<CefCookieManager> manager,
CookieVector& cookies,
bool deleteCookies,
const base::Closure& callback) {
base::OnceClosure callback) {
EXPECT_TRUE(manager->VisitAllCookies(
new TestVisitor(&cookies, deleteCookies, callback)));
new TestVisitor(&cookies, deleteCookies, std::move(callback))));
}
// Visit all cookies. Block on |event|.
@ -210,7 +212,7 @@ void VisitAllCookies(CefRefPtr<CefCookieManager> manager,
bool deleteCookies,
CefRefPtr<CefWaitableEvent> event) {
VisitAllCookies(manager, cookies, deleteCookies,
base::Bind(&CefWaitableEvent::Signal, event));
base::BindOnce(&CefWaitableEvent::Signal, event));
event->Wait();
}
@ -601,8 +603,8 @@ class CookieTestJSHandler : public TestHandler {
// Go to the next URL.
void LoadNextURL(CefRefPtr<CefFrame> frame) {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI,
base::Bind(&CookieTestJSHandler::LoadNextURL, this, frame));
CefPostTask(TID_UI, base::BindOnce(&CookieTestJSHandler::LoadNextURL,
this, frame));
return;
}
@ -611,7 +613,8 @@ class CookieTestJSHandler : public TestHandler {
void CompleteTest() {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, base::Bind(&CookieTestJSHandler::CompleteTest, this));
CefPostTask(TID_UI,
base::BindOnce(&CookieTestJSHandler::CompleteTest, this));
return;
}
@ -624,12 +627,13 @@ class CookieTestJSHandler : public TestHandler {
std::string url = frame->GetURL();
if (url == kCookieJSUrl1) {
got_load_end1_.yes();
VerifyCookie(manager_, url, "name1", "value1", true, &got_cookie1_,
base::Bind(&CookieTestJSHandler::LoadNextURL, this, frame));
VerifyCookie(
manager_, url, "name1", "value1", true, &got_cookie1_,
base::BindOnce(&CookieTestJSHandler::LoadNextURL, this, frame));
} else {
got_load_end2_.yes();
VerifyCookie(manager_, url, "name2", "value2", true, &got_cookie2_,
base::Bind(&CookieTestJSHandler::CompleteTest, this));
base::BindOnce(&CookieTestJSHandler::CompleteTest, this));
}
}
@ -640,25 +644,26 @@ class CookieTestJSHandler : public TestHandler {
const std::string& value,
bool deleteCookie,
TrackCallback* callback,
const base::Closure& continue_callback) {
base::OnceClosure continue_callback) {
// Get the cookie.
EXPECT_TRUE(cookies_.empty());
VisitUrlCookies(manager, url, false, cookies_, deleteCookie,
base::Bind(&CookieTestJSHandler::VerifyCookieComplete, this,
name, value, callback, continue_callback));
VisitUrlCookies(
manager, url, false, cookies_, deleteCookie,
base::BindOnce(&CookieTestJSHandler::VerifyCookieComplete, this, name,
value, callback, std::move(continue_callback)));
}
void VerifyCookieComplete(const std::string& name,
const std::string& value,
TrackCallback* callback,
const base::Closure& continue_callback) {
base::OnceClosure continue_callback) {
if (cookies_.size() == 1U && CefString(&cookies_[0].name) == name &&
CefString(&cookies_[0].value) == value) {
callback->yes();
}
cookies_.clear();
continue_callback.Run();
std::move(continue_callback).Run();
}
CefRefPtr<CefCookieManager> manager_;
@ -694,16 +699,13 @@ const char kCustomCookieScheme[] = "ccustom";
class CompletionCallback : public CefCompletionCallback {
public:
explicit CompletionCallback(const base::Closure& callback)
: callback_(callback) {}
explicit CompletionCallback(base::OnceClosure callback)
: callback_(std::move(callback)) {}
void OnComplete() override {
callback_.Run();
callback_.Reset();
}
void OnComplete() override { std::move(callback_).Run(); }
private:
base::Closure callback_;
base::OnceClosure callback_;
IMPLEMENT_REFCOUNTING(CompletionCallback);
};
@ -871,8 +873,8 @@ class CookieTestSchemeHandler : public TestHandler {
// Go to the next URL.
void LoadNextURL(CefRefPtr<CefFrame> frame, const std::string& url) {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, base::Bind(&CookieTestSchemeHandler::LoadNextURL,
this, frame, url));
CefPostTask(TID_UI, base::BindOnce(&CookieTestSchemeHandler::LoadNextURL,
this, frame, url));
return;
}
@ -881,8 +883,8 @@ class CookieTestSchemeHandler : public TestHandler {
void CompleteTest(CefRefPtr<CefBrowser> browser) {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, base::Bind(&CookieTestSchemeHandler::CompleteTest,
this, browser));
CefPostTask(TID_UI, base::BindOnce(&CookieTestSchemeHandler::CompleteTest,
this, browser));
return;
}
@ -900,18 +902,18 @@ class CookieTestSchemeHandler : public TestHandler {
if (url == url1_) {
got_load_end1_.yes();
VerifyCookie(manager_, url, "name1", "value1", true, &got_cookie1_,
base::Bind(&CookieTestSchemeHandler::LoadNextURL, this,
frame, url2_));
base::BindOnce(&CookieTestSchemeHandler::LoadNextURL, this,
frame, url2_));
} else if (url == url2_) {
got_load_end2_.yes();
VerifyCookie(manager_, url, "name2", "value2", false, &got_cookie2_,
base::Bind(&CookieTestSchemeHandler::LoadNextURL, this,
frame, url3_));
base::BindOnce(&CookieTestSchemeHandler::LoadNextURL, this,
frame, url3_));
} else {
got_load_end3_.yes();
VerifyCookie(
manager_, url, "name2", "value2", true, &got_cookie3_,
base::Bind(&CookieTestSchemeHandler::CompleteTest, this, browser));
VerifyCookie(manager_, url, "name2", "value2", true, &got_cookie3_,
base::BindOnce(&CookieTestSchemeHandler::CompleteTest, this,
browser));
}
}
@ -952,25 +954,26 @@ class CookieTestSchemeHandler : public TestHandler {
const std::string& value,
bool deleteCookie,
TrackCallback* callback,
const base::Closure& continue_callback) {
base::OnceClosure continue_callback) {
// Get the cookie.
EXPECT_TRUE(cookies_.empty());
VisitUrlCookies(manager, url, false, cookies_, deleteCookie,
base::Bind(&CookieTestSchemeHandler::VerifyCookieComplete,
this, name, value, callback, continue_callback));
VisitUrlCookies(
manager, url, false, cookies_, deleteCookie,
base::BindOnce(&CookieTestSchemeHandler::VerifyCookieComplete, this,
name, value, callback, std::move(continue_callback)));
}
void VerifyCookieComplete(const std::string& name,
const std::string& value,
TrackCallback* callback,
const base::Closure& continue_callback) {
base::OnceClosure continue_callback) {
if (cookies_.size() == 1U && CefString(&cookies_[0].name) == name &&
CefString(&cookies_[0].value) == value) {
callback->yes();
}
cookies_.clear();
continue_callback.Run();
std::move(continue_callback).Run();
}
const std::string scheme_;
@ -1225,15 +1228,13 @@ class CookieAccessSchemeHandlerFactory : public CefSchemeHandlerFactory,
data_map_.insert(std::make_pair(url, data));
}
void Shutdown(const base::Closure& complete_callback) {
void Shutdown(base::OnceClosure complete_callback) {
if (!CefCurrentlyOn(TID_IO)) {
CefPostTask(TID_IO,
base::Bind(&CookieAccessSchemeHandlerFactory::Shutdown, this,
complete_callback));
CefPostTask(TID_IO, base::BindOnce(std::move(complete_callback)));
return;
}
complete_callback.Run();
std::move(complete_callback).Run();
}
private:
@ -1269,7 +1270,7 @@ class CookieAccessServerHandler : public test_server::ObserverHelper,
// |complete_callback| will be executed on the UI thread after the server is
// started.
void CreateServer(const base::Closure& complete_callback) {
void CreateServer(base::OnceClosure complete_callback) {
EXPECT_UI_THREAD();
if (expected_http_request_ct_ < 0) {
@ -1281,7 +1282,7 @@ class CookieAccessServerHandler : public test_server::ObserverHelper,
initialized_ = true;
EXPECT_TRUE(complete_callback_.is_null());
complete_callback_ = complete_callback;
complete_callback_ = std::move(complete_callback);
Initialize();
}
@ -1289,11 +1290,11 @@ class CookieAccessServerHandler : public test_server::ObserverHelper,
// Results in a call to VerifyResults() and eventual execution of the
// |complete_callback| on the UI thread via CookieAccessServerHandler
// destruction.
void ShutdownServer(const base::Closure& complete_callback) {
void ShutdownServer(base::OnceClosure complete_callback) {
EXPECT_UI_THREAD();
EXPECT_TRUE(complete_callback_.is_null());
complete_callback_ = complete_callback;
complete_callback_ = std::move(complete_callback);
Shutdown();
}
@ -1379,8 +1380,8 @@ class CookieAccessServerHandler : public test_server::ObserverHelper,
CefRefPtr<CefTaskRunner> task_runner = server->GetTaskRunner();
if (!task_runner->BelongsToCurrentThread()) {
task_runner->PostTask(CefCreateClosureTask(
base::Bind(CookieAccessServerHandler::SendResponse, server,
connection_id, response, response_data)));
base::BindOnce(CookieAccessServerHandler::SendResponse, server,
connection_id, response, response_data)));
return;
}
@ -1408,8 +1409,7 @@ class CookieAccessServerHandler : public test_server::ObserverHelper,
EXPECT_UI_THREAD();
EXPECT_FALSE(complete_callback_.is_null());
complete_callback_.Run();
complete_callback_.Reset();
std::move(complete_callback_).Run();
}
// Map of URL to Data.
@ -1419,7 +1419,7 @@ class CookieAccessServerHandler : public test_server::ObserverHelper,
bool initialized_;
// Only accessed on the UI thread.
base::Closure complete_callback_;
base::OnceClosure complete_callback_;
// After initialization the below members are only accessed on the server
// thread.
@ -1511,7 +1511,7 @@ class CookieAccessTestHandler : public RoutingTestHandler,
void DestroyTest() override {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI,
base::Bind(&CookieAccessTestHandler::DestroyTest, this));
base::BindOnce(&CookieAccessTestHandler::DestroyTest, this));
return;
}
@ -1734,29 +1734,30 @@ class CookieAccessTestHandler : public RoutingTestHandler,
}
void RunTestSetupContinue() {
CefPostTask(TID_UI,
base::Bind(&CookieAccessTestHandler::StartBackend, this,
base::Bind(&CookieAccessTestHandler::RunTestContinue,
this)));
CefPostTask(
TID_UI,
base::BindOnce(
&CookieAccessTestHandler::StartBackend, this,
base::BindOnce(&CookieAccessTestHandler::RunTestContinue, this)));
}
void StartBackend(const base::Closure& complete_callback) {
void StartBackend(base::OnceClosure complete_callback) {
if (test_backend_ == SERVER) {
StartServer(complete_callback);
StartServer(std::move(complete_callback));
} else {
StartSchemeHandler(complete_callback);
StartSchemeHandler(std::move(complete_callback));
}
}
void StartServer(const base::Closure& complete_callback) {
void StartServer(base::OnceClosure complete_callback) {
EXPECT_FALSE(server_handler_);
server_handler_ = new CookieAccessServerHandler();
AddResponses(server_handler_);
server_handler_->CreateServer(complete_callback);
server_handler_->CreateServer(std::move(complete_callback));
}
void StartSchemeHandler(const base::Closure& complete_callback) {
void StartSchemeHandler(base::OnceClosure complete_callback) {
// Add the factory registration.
scheme_factory_ = new CookieAccessSchemeHandlerFactory();
AddResponses(scheme_factory_.get());
@ -1765,13 +1766,13 @@ class CookieAccessTestHandler : public RoutingTestHandler,
scheme_factory_.get());
}
complete_callback.Run();
std::move(complete_callback).Run();
}
void RunTestContinue() {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI,
base::Bind(&CookieAccessTestHandler::RunTestContinue, this));
CefPostTask(TID_UI, base::BindOnce(
&CookieAccessTestHandler::RunTestContinue, this));
return;
}
@ -1789,9 +1790,9 @@ class CookieAccessTestHandler : public RoutingTestHandler,
// Destroy the test.
CefPostTask(
TID_UI,
base::Bind(
&CookieAccessTestHandler::ShutdownBackend, handler_,
base::Bind(&CookieAccessTestHandler::DestroyTest, handler_)));
base::BindOnce(&CookieAccessTestHandler::ShutdownBackend, handler_,
base::BindOnce(&CookieAccessTestHandler::DestroyTest,
handler_)));
}
bool Visit(const CefCookie& cookie,
@ -1819,30 +1820,30 @@ class CookieAccessTestHandler : public RoutingTestHandler,
cookie_manager_->VisitAllCookies(new TestVisitor(this));
}
void ShutdownBackend(const base::Closure& complete_callback) {
void ShutdownBackend(base::OnceClosure complete_callback) {
if (test_backend_ == SERVER) {
ShutdownServer(complete_callback);
ShutdownServer(std::move(complete_callback));
} else {
ShutdownSchemeHandler(complete_callback);
ShutdownSchemeHandler(std::move(complete_callback));
}
}
void ShutdownServer(const base::Closure& complete_callback) {
void ShutdownServer(base::OnceClosure complete_callback) {
EXPECT_TRUE(server_handler_);
// |server_handler_| will delete itself after shutdown.
server_handler_->ShutdownServer(complete_callback);
server_handler_->ShutdownServer(std::move(complete_callback));
server_handler_ = nullptr;
}
void ShutdownSchemeHandler(const base::Closure& complete_callback) {
void ShutdownSchemeHandler(base::OnceClosure complete_callback) {
EXPECT_TRUE(scheme_factory_);
if (test_backend_ == SCHEME_HANDLER) {
context_->RegisterSchemeHandlerFactory(scheme_, kCookieAccessDomain,
nullptr);
}
scheme_factory_->Shutdown(complete_callback);
scheme_factory_->Shutdown(std::move(complete_callback));
scheme_factory_ = nullptr;
}
@ -1968,7 +1969,7 @@ class CookieRestartTestHandler : public RoutingTestHandler,
void DestroyTest() override {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI,
base::Bind(&CookieRestartTestHandler::DestroyTest, this));
base::BindOnce(&CookieRestartTestHandler::DestroyTest, this));
return;
}
@ -2203,25 +2204,26 @@ class CookieRestartTestHandler : public RoutingTestHandler,
void RunTestSetupContinue() {
CefPostTask(
TID_UI,
base::Bind(
base::BindOnce(
&CookieRestartTestHandler::StartServer, this,
base::Bind(&CookieRestartTestHandler::RunTestContinue, this)));
base::BindOnce(&CookieRestartTestHandler::RunTestContinue, this)));
}
void StartServer(const base::Closure& complete_callback) {
void StartServer(base::OnceClosure complete_callback) {
EXPECT_FALSE(server_handler_);
server_handler_ = new CookieAccessServerHandler();
AddResponses(server_handler_);
// 2 requests for each URL.
server_handler_->SetExpectedRequestCount(4);
server_handler_->CreateServer(complete_callback);
server_handler_->CreateServer(std::move(complete_callback));
}
void RunTestContinue() {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI,
base::Bind(&CookieRestartTestHandler::RunTestContinue, this));
CefPostTask(
TID_UI,
base::BindOnce(&CookieRestartTestHandler::RunTestContinue, this));
return;
}
@ -2236,11 +2238,11 @@ class CookieRestartTestHandler : public RoutingTestHandler,
: handler_(handler) {}
~TestVisitor() override {
// Destroy the test.
CefPostTask(
TID_UI,
base::Bind(
&CookieRestartTestHandler::ShutdownServer, handler_,
base::Bind(&CookieRestartTestHandler::DestroyTest, handler_)));
CefPostTask(TID_UI,
base::BindOnce(
&CookieRestartTestHandler::ShutdownServer, handler_,
base::BindOnce(&CookieRestartTestHandler::DestroyTest,
handler_)));
}
bool Visit(const CefCookie& cookie,
@ -2268,11 +2270,11 @@ class CookieRestartTestHandler : public RoutingTestHandler,
cookie_manager_->VisitAllCookies(new TestVisitor(this));
}
void ShutdownServer(const base::Closure& complete_callback) {
void ShutdownServer(base::OnceClosure complete_callback) {
EXPECT_TRUE(server_handler_);
// |server_handler_| will delete itself after shutdown.
server_handler_->ShutdownServer(complete_callback);
server_handler_->ShutdownServer(std::move(complete_callback));
server_handler_ = nullptr;
}

View File

@ -294,24 +294,22 @@ struct TestSetup {
class TestServerObserver : public test_server::ObserverHelper {
public:
typedef base::Callback<bool()> CheckDoneCallback;
TestServerObserver(TestSetup* setup,
const base::Closure& ready_callback,
const base::Closure& done_callback)
base::OnceClosure ready_callback,
base::OnceClosure done_callback)
: setup_(setup),
ready_callback_(ready_callback),
done_callback_(done_callback),
ready_callback_(std::move(ready_callback)),
done_callback_(std::move(done_callback)),
weak_ptr_factory_(this) {
DCHECK(setup);
Initialize();
}
~TestServerObserver() override { done_callback_.Run(); }
~TestServerObserver() override { std::move(done_callback_).Run(); }
void OnInitialized(const std::string& server_origin) override {
CEF_REQUIRE_UI_THREAD();
ready_callback_.Run();
std::move(ready_callback_).Run();
}
bool OnHttpRequest(CefRefPtr<CefServer> server,
@ -342,8 +340,8 @@ class TestServerObserver : public test_server::ObserverHelper {
private:
TestSetup* const setup_;
const base::Closure ready_callback_;
const base::Closure done_callback_;
base::OnceClosure ready_callback_;
base::OnceClosure done_callback_;
base::WeakPtrFactory<TestServerObserver> weak_ptr_factory_;
@ -357,7 +355,7 @@ class CorsTestHandler : public RoutingTestHandler {
}
void RunTest() override {
StartServer(base::Bind(&CorsTestHandler::TriggerCreateBrowser, this));
StartServer(base::BindOnce(&CorsTestHandler::TriggerCreateBrowser, this));
// Time out the test after a reasonable period of time.
SetTestTimeout();
@ -500,7 +498,8 @@ class CorsTestHandler : public RoutingTestHandler {
}
void TriggerDestroyTestIfDone() {
CefPostTask(TID_UI, base::Bind(&CorsTestHandler::DestroyTestIfDone, this));
CefPostTask(TID_UI,
base::BindOnce(&CorsTestHandler::DestroyTestIfDone, this));
}
void DestroyTestIfDone() {
@ -514,21 +513,22 @@ class CorsTestHandler : public RoutingTestHandler {
}
}
void StartServer(const base::Closure& next_step) {
void StartServer(base::OnceClosure next_step) {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI,
base::Bind(&CorsTestHandler::StartServer, this, next_step));
CefPostTask(TID_UI, base::BindOnce(&CorsTestHandler::StartServer, this,
std::move(next_step)));
return;
}
if (!setup_->NeedsServer()) {
next_step.Run();
std::move(next_step).Run();
return;
}
// Will delete itself after the server stops.
server_ = new TestServerObserver(
setup_, next_step, base::Bind(&CorsTestHandler::StoppedServer, this));
setup_, std::move(next_step),
base::BindOnce(&CorsTestHandler::StoppedServer, this));
}
void StopServer() {
@ -564,7 +564,7 @@ class CorsTestHandler : public RoutingTestHandler {
DCHECK(setup_->clear_cookies);
test_request::GetAllCookies(
CefCookieManager::GetGlobalManager(nullptr), /*delete_cookies=*/true,
base::Bind(&CorsTestHandler::ClearedCookies, this));
base::BindOnce(&CorsTestHandler::ClearedCookies, this));
}
void ClearedCookies(const test_request::CookieVector& cookies) {

View File

@ -54,8 +54,9 @@ class DevToolsMessageTestHandler : public TestHandler {
if (load_ct_ == 1) {
// STEP 2: 1st load has completed. Now enable page domain notifications
// and wait for the method result.
ExecuteMethod("Page.enable", "",
base::Bind(&DevToolsMessageTestHandler::Navigate, this));
ExecuteMethod(
"Page.enable", "",
base::BindOnce(&DevToolsMessageTestHandler::Navigate, this));
} else if (load_ct_ == 2) {
MaybeDestroyTest();
}
@ -185,7 +186,7 @@ class DevToolsMessageTestHandler : public TestHandler {
// |expected_result| can be a fragment that the result should start with.
void ExecuteMethod(const std::string& method,
const std::string& params,
const base::Closure& next_step,
base::OnceClosure next_step,
const std::string& expected_result = "{}",
bool expected_success = true) {
CHECK(!method.empty());
@ -202,7 +203,7 @@ class DevToolsMessageTestHandler : public TestHandler {
// Set expected result state.
pending_message_ = message.str();
pending_result_next_ = next_step;
pending_result_next_ = std::move(next_step);
pending_result_ = {message_id, expected_success, expected_result};
if (message_id % 2 == 0) {
@ -246,11 +247,10 @@ class DevToolsMessageTestHandler : public TestHandler {
last_result_id_ = result.message_id;
// Continue asynchronously to allow the callstack to unwind.
CefPostTask(TID_UI, pending_result_next_);
CefPostTask(TID_UI, std::move(pending_result_next_));
// Clear expected result state.
pending_message_.clear();
pending_result_next_.Reset();
pending_result_ = {};
}
@ -264,17 +264,16 @@ class DevToolsMessageTestHandler : public TestHandler {
<< "\nand expected params=" << pending_event_.params;
// Continue asynchronously to allow the callstack to unwind.
CefPostTask(TID_UI, pending_event_next_);
CefPostTask(TID_UI, std::move(pending_event_next_));
// Clear expected result state.
pending_event_ = {};
pending_event_next_.Reset();
}
void Navigate() {
pending_event_ = {"Page.frameNavigated", "{\"frame\":"};
pending_event_next_ =
base::Bind(&DevToolsMessageTestHandler::AfterNavigate, this);
base::BindOnce(&DevToolsMessageTestHandler::AfterNavigate, this);
std::stringstream params;
params << "{\"url\":\"" << kTestUrl2 << "\"}";
@ -291,7 +290,7 @@ class DevToolsMessageTestHandler : public TestHandler {
// notifications.
ExecuteMethod(
"Page.disable", "",
base::Bind(&DevToolsMessageTestHandler::AfterPageDisabled, this));
base::BindOnce(&DevToolsMessageTestHandler::AfterPageDisabled, this));
}
void AfterPageDisabled() {
@ -299,7 +298,7 @@ class DevToolsMessageTestHandler : public TestHandler {
// method to verify an error result, and then destroy the test when done.
ExecuteMethod(
"Foo.doesNotExist", "",
base::Bind(&DevToolsMessageTestHandler::MaybeDestroyTest, this),
base::BindOnce(&DevToolsMessageTestHandler::MaybeDestroyTest, this),
/*expected_result=*/
"{\"code\":-32601,\"message\":\"'Foo.doesNotExist' wasn't found\"}",
/*expected_success=*/false);
@ -336,13 +335,13 @@ class DevToolsMessageTestHandler : public TestHandler {
// Tracks the last message ID received.
int last_result_id_ = -1;
// When received, execute this callback.
base::Closure pending_result_next_;
base::OnceClosure pending_result_next_;
// Wait for |pending_event_.method| in OnEvent.
// The params should start with the |pending_event_.params| fragment.
Event pending_event_;
// When received, execute this callback.
base::Closure pending_event_next_;
base::OnceClosure pending_event_next_;
CefRefPtr<CefRegistration> registration_;

View File

@ -115,8 +115,8 @@ class DialogTestHandler : public TestHandler {
TestStringVectorEqual(config_.accept_types, accept_types);
if (config_.callback_async) {
CefPostTask(TID_UI, base::Bind(&DialogTestHandler::ExecuteCallback, this,
callback));
CefPostTask(TID_UI, base::BindOnce(&DialogTestHandler::ExecuteCallback,
this, callback));
} else {
ExecuteCallback(callback);
}

View File

@ -90,7 +90,7 @@ class TitleTestHandler : public TestHandler {
// NextIfReady.
got_loading_state_change_ = true;
CefPostTask(TID_UI,
base::Bind(&TitleTestHandler::NextIfReady, this, browser));
base::BindOnce(&TitleTestHandler::NextIfReady, this, browser));
}
private:

View File

@ -2,6 +2,10 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include <memory>
#include "include/base/cef_callback.h"
#include "include/base/cef_callback_helpers.h"
#include "include/cef_scheme.h"
#include "include/wrapper/cef_closure_task.h"
#include "include/wrapper/cef_scoped_temp_dir.h"
@ -22,13 +26,13 @@ const char kTestContentDisposition[] =
const char kTestMimeType[] = "text/plain";
const char kTestContent[] = "Download test text";
typedef base::Callback<void(const base::Closure& /*callback*/)> DelayCallback;
using DelayCallback = base::OnceCallback<void(base::OnceClosure /*callback*/)>;
class DownloadSchemeHandler : public CefResourceHandler {
public:
DownloadSchemeHandler(const DelayCallback& delay_callback,
DownloadSchemeHandler(DelayCallback delay_callback,
TrackCallback* got_download_request)
: delay_callback_(delay_callback),
: delay_callback_(std::move(delay_callback)),
got_download_request_(got_download_request),
should_delay_(false),
offset_(0) {}
@ -85,9 +89,9 @@ class DownloadSchemeHandler : public CefResourceHandler {
if (should_delay_ && !delay_callback_.is_null()) {
// Delay the download response a single time.
delay_callback_.Run(base::Bind(&DownloadSchemeHandler::ContinueRead, this,
data_out, bytes_to_read, callback));
delay_callback_.Reset();
std::move(delay_callback_)
.Run(base::BindOnce(&DownloadSchemeHandler::ContinueRead, this,
data_out, bytes_to_read, callback));
return true;
}
@ -134,22 +138,27 @@ class DownloadSchemeHandler : public CefResourceHandler {
DISALLOW_COPY_AND_ASSIGN(DownloadSchemeHandler);
};
using DelayCallbackVendor = base::RepeatingCallback<DelayCallback(void)>;
class DownloadSchemeHandlerFactory : public CefSchemeHandlerFactory {
public:
DownloadSchemeHandlerFactory(const DelayCallback& delay_callback,
DownloadSchemeHandlerFactory(const DelayCallbackVendor& delay_callback_vendor,
TrackCallback* got_download_request)
: delay_callback_(delay_callback),
: delay_callback_vendor_(delay_callback_vendor),
got_download_request_(got_download_request) {}
CefRefPtr<CefResourceHandler> Create(CefRefPtr<CefBrowser> browser,
CefRefPtr<CefFrame> frame,
const CefString& scheme_name,
CefRefPtr<CefRequest> request) override {
return new DownloadSchemeHandler(delay_callback_, got_download_request_);
return new DownloadSchemeHandler(delay_callback_vendor_.is_null()
? base::NullCallback()
: delay_callback_vendor_.Run(),
got_download_request_);
}
private:
DelayCallback delay_callback_;
DelayCallbackVendor delay_callback_vendor_;
TrackCallback* got_download_request_;
IMPLEMENT_REFCOUNTING(DownloadSchemeHandlerFactory);
@ -180,12 +189,17 @@ class DownloadTestHandler : public TestHandler {
}
void RunTest() override {
DelayCallback delay_callback;
if (test_mode_ == NAVIGATED || test_mode_ == PENDING)
delay_callback = base::Bind(&DownloadTestHandler::OnDelayCallback, this);
DelayCallbackVendor delay_callback_vendor;
if (test_mode_ == NAVIGATED || test_mode_ == PENDING) {
delay_callback_vendor = base::BindRepeating(
[](CefRefPtr<DownloadTestHandler> self) {
return base::BindOnce(&DownloadTestHandler::OnDelayCallback, self);
},
CefRefPtr<DownloadTestHandler>(this));
}
CefRefPtr<CefSchemeHandlerFactory> scheme_factory =
new DownloadSchemeHandlerFactory(delay_callback,
new DownloadSchemeHandlerFactory(delay_callback_vendor,
&got_download_request_);
CefRefPtr<CefRequestContext> request_context =
@ -255,7 +269,8 @@ class DownloadTestHandler : public TestHandler {
// Destroy the test after a bit because there will be no further
// callbacks.
CefPostDelayedTask(
TID_UI, base::Bind(&DownloadTestHandler::DestroyTest, this), 200);
TID_UI, base::BindOnce(&DownloadTestHandler::DestroyTest, this),
200);
}
} else {
// Begin the download progammatically.
@ -264,17 +279,17 @@ class DownloadTestHandler : public TestHandler {
}
// Callback from the scheme handler when the download request is delayed.
void OnDelayCallback(const base::Closure& callback) {
void OnDelayCallback(base::OnceClosure callback) {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, base::Bind(&DownloadTestHandler::OnDelayCallback,
this, callback));
CefPostTask(TID_UI, base::BindOnce(&DownloadTestHandler::OnDelayCallback,
this, std::move(callback)));
return;
}
got_delay_callback_.yes();
if (test_mode_ == NAVIGATED) {
delay_callback_ = callback;
delay_callback_ = std::move(callback);
ContinueNavigatedIfReady();
} else if (test_mode_ == PENDING) {
ContinuePendingIfReady();
@ -287,8 +302,7 @@ class DownloadTestHandler : public TestHandler {
EXPECT_EQ(test_mode_, NAVIGATED);
if (got_delay_callback_ && got_nav_load_) {
EXPECT_FALSE(delay_callback_.is_null());
delay_callback_.Run();
delay_callback_.Reset();
std::move(delay_callback_).Run();
}
}
@ -414,7 +428,8 @@ class DownloadTestHandler : public TestHandler {
EXPECT_TRUE(temp_dir_.Delete());
EXPECT_TRUE(temp_dir_.IsEmpty());
CefPostTask(TID_UI, base::Bind(&DownloadTestHandler::DestroyTest, this));
CefPostTask(TID_UI,
base::BindOnce(&DownloadTestHandler::DestroyTest, this));
}
void DestroyTest() override {
@ -422,9 +437,9 @@ class DownloadTestHandler : public TestHandler {
// Avoid an endless failure loop.
verified_results_ = true;
// Clean up temp_dir_ on the FILE thread before destroying the test.
CefPostTask(
TID_FILE_USER_VISIBLE,
base::Bind(&DownloadTestHandler::VerifyResultsOnFileThread, this));
CefPostTask(TID_FILE_USER_VISIBLE,
base::BindOnce(
&DownloadTestHandler::VerifyResultsOnFileThread, this));
return;
}
@ -488,7 +503,7 @@ class DownloadTestHandler : public TestHandler {
CefRefPtr<CefRequestContext> request_context_;
// Used with NAVIGATED and PENDING test modes.
base::Closure delay_callback_;
base::OnceClosure delay_callback_;
// Used with PENDING test mode.
CefRefPtr<CefDownloadItemCallback> download_item_callback_;

View File

@ -2,6 +2,7 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include "include/base/cef_callback.h"
#include "include/wrapper/cef_closure_task.h"
#include "tests/ceftests/test_handler.h"
#include "tests/gtest/include/gtest/gtest.h"
@ -139,7 +140,8 @@ class DraggableRegionsTestHandler : public TestHandler, public CefDragHandler {
frame->LoadURL(kTestURLWithoutRegions);
// Needed because this test doesn't call OnDraggableRegionsChanged.
CefPostDelayedTask(
TID_UI, base::Bind(&DraggableRegionsTestHandler::DestroyTest, this),
TID_UI,
base::BindOnce(&DraggableRegionsTestHandler::DestroyTest, this),
500);
break;
case kStepWithoutRegions: {

View File

@ -76,7 +76,7 @@ class BackgroundLoadUnloadTestHandler : public ExtensionTestHandler {
// Will close the browser windows.
CefPostTask(
TID_UI,
base::Bind(&BackgroundLoadUnloadTestHandler::DestroyTest, this));
base::BindOnce(&BackgroundLoadUnloadTestHandler::DestroyTest, this));
}
bool OnBeforeBackgroundBrowser(CefRefPtr<CefExtension> extension,
@ -239,9 +239,9 @@ class BackgroundLoadUnloadTestHandler : public ExtensionTestHandler {
virtual void TriggerDestroyTest() {
// Execute asynchronously so call stacks have a chance to unwind.
CefPostTask(TID_UI,
base::Bind(&BackgroundLoadUnloadTestHandler::UnloadExtension,
this, extension_));
CefPostTask(TID_UI, base::BindOnce(
&BackgroundLoadUnloadTestHandler::UnloadExtension,
this, extension_));
}
CefRefPtr<CefExtension> extension_;

View File

@ -56,7 +56,7 @@ class AlarmsTestHandler : public ExtensionTestHandler {
// Execute asynchronously so call stacks have a chance to unwind.
// Will close the browser windows.
CefPostTask(TID_UI, base::Bind(&AlarmsTestHandler::DestroyTest, this));
CefPostTask(TID_UI, base::BindOnce(&AlarmsTestHandler::DestroyTest, this));
}
// CefLoadHandler methods:
@ -167,8 +167,8 @@ class AlarmsTestHandler : public ExtensionTestHandler {
virtual void TriggerDestroyTest() {
// Execute asynchronously so call stacks have a chance to unwind.
CefPostTask(TID_UI, base::Bind(&AlarmsTestHandler::UnloadExtension, this,
extension_));
CefPostTask(TID_UI, base::BindOnce(&AlarmsTestHandler::UnloadExtension,
this, extension_));
}
CefRefPtr<CefExtension> extension() const { return extension_; }

View File

@ -56,7 +56,7 @@ class StorageTestHandler : public ExtensionTestHandler {
// Execute asynchronously so call stacks have a chance to unwind.
// Will close the browser windows.
CefPostTask(TID_UI, base::Bind(&StorageTestHandler::DestroyTest, this));
CefPostTask(TID_UI, base::BindOnce(&StorageTestHandler::DestroyTest, this));
}
// CefLoadHandler methods:
@ -167,8 +167,8 @@ class StorageTestHandler : public ExtensionTestHandler {
virtual void TriggerDestroyTest() {
// Execute asynchronously so call stacks have a chance to unwind.
CefPostTask(TID_UI, base::Bind(&StorageTestHandler::UnloadExtension, this,
extension_));
CefPostTask(TID_UI, base::BindOnce(&StorageTestHandler::UnloadExtension,
this, extension_));
}
CefRefPtr<CefExtension> extension() const { return extension_; }

View File

@ -68,7 +68,7 @@ class TabsTestHandler : public ExtensionTestHandler {
// Execute asynchronously so call stacks have a chance to unwind.
// Will close the browser windows.
CefPostTask(TID_UI, base::Bind(&TabsTestHandler::DestroyTest, this));
CefPostTask(TID_UI, base::BindOnce(&TabsTestHandler::DestroyTest, this));
}
CefRefPtr<CefBrowser> GetActiveBrowser(CefRefPtr<CefExtension> extension,
@ -272,8 +272,8 @@ class TabsTestHandler : public ExtensionTestHandler {
virtual void TriggerDestroyTest() {
// Execute asynchronously so call stacks have a chance to unwind.
CefPostTask(TID_UI, base::Bind(&TabsTestHandler::UnloadExtension, this,
extension_));
CefPostTask(TID_UI, base::BindOnce(&TabsTestHandler::UnloadExtension, this,
extension_));
}
CefRefPtr<CefExtension> extension() const { return extension_; }

View File

@ -63,7 +63,7 @@ class ViewLoadUnloadTestHandler : public ExtensionTestHandler {
// Execute asynchronously so call stacks have a chance to unwind.
// Will close the browser windows.
CefPostTask(TID_UI,
base::Bind(&ViewLoadUnloadTestHandler::DestroyTest, this));
base::BindOnce(&ViewLoadUnloadTestHandler::DestroyTest, this));
}
// CefLoadHandler methods:
@ -194,8 +194,9 @@ class ViewLoadUnloadTestHandler : public ExtensionTestHandler {
virtual void TriggerDestroyTest() {
// Execute asynchronously so call stacks have a chance to unwind.
CefPostTask(TID_UI, base::Bind(&ViewLoadUnloadTestHandler::UnloadExtension,
this, extension_));
CefPostTask(TID_UI,
base::BindOnce(&ViewLoadUnloadTestHandler::UnloadExtension,
this, extension_));
}
CefRefPtr<CefExtension> extension_;

View File

@ -106,7 +106,7 @@ const int kMaxMultiNavNavigations = 4;
// Abstract base class representing expectations that result from a navigation.
class FrameNavExpectations {
public:
typedef base::Callback<void(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>)>
typedef base::OnceCallback<void(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame>)>
CompletionCallback;
FrameNavExpectations(int nav, bool renderer)
@ -137,9 +137,9 @@ class FrameNavExpectations {
if (!completion_callback_.is_null()) {
// Execute the callback asynchronously to avoid any issues with what's
// currently on the stack.
CefPostTask((renderer_ ? TID_RENDERER : TID_UI),
base::Bind(completion_callback_, browser, frame));
completion_callback_.Reset();
CefPostTask(
(renderer_ ? TID_RENDERER : TID_UI),
base::BindOnce(std::move(completion_callback_), browser, frame));
}
}
@ -153,8 +153,8 @@ class FrameNavExpectations {
// Returns true if this is a renderer-side expectation object.
bool renderer() const { return renderer_; }
void set_completion_callback(const CompletionCallback& completion_callback) {
completion_callback_ = completion_callback;
void set_completion_callback(CompletionCallback completion_callback) {
completion_callback_ = std::move(completion_callback);
}
private:
@ -235,9 +235,9 @@ class FrameNavExpectationsFactoryBrowser : public FrameNavExpectationsFactory {
std::unique_ptr<FrameNavExpectationsBrowser> Create(
int nav,
const FrameNavExpectations::CompletionCallback& completion_callback) {
FrameNavExpectations::CompletionCallback completion_callback) {
auto expectations = Create(nav);
expectations->set_completion_callback(completion_callback);
expectations->set_completion_callback(std::move(completion_callback));
return expectations;
}
@ -257,9 +257,9 @@ class FrameNavExpectationsFactoryRenderer : public FrameNavExpectationsFactory {
std::unique_ptr<FrameNavExpectationsRenderer> Create(
int nav,
const FrameNavExpectations::CompletionCallback& completion_callback) {
FrameNavExpectations::CompletionCallback completion_callback) {
auto expectations = Create(nav);
expectations->set_completion_callback(completion_callback);
expectations->set_completion_callback(std::move(completion_callback));
return expectations;
}
@ -327,7 +327,7 @@ class FrameNavRendererTest : public ClientAppRenderer::Delegate,
if (expectations_)
return;
expectations_ = factory_->Create(
nav_, base::Bind(&FrameNavRendererTest::SendTestResults, this));
nav_, base::BindOnce(&FrameNavRendererTest::SendTestResults, this));
}
// Send the test results.
@ -378,7 +378,7 @@ class FrameNavTestHandler : public TestHandler {
void RunTest() override {
// Create the first expectations object.
expectations_ = factory_->Create(
nav_, base::Bind(&FrameNavTestHandler::RunNextNav, this));
nav_, base::BindOnce(&FrameNavTestHandler::RunNextNav, this));
CefRefPtr<CefDictionaryValue> extra_info = CefDictionaryValue::Create();
extra_info->SetInt(kFrameNavTestCmdKey, factory_->GetID());
@ -407,7 +407,7 @@ class FrameNavTestHandler : public TestHandler {
// Create the next expectations object.
expectations_ = factory_->Create(
nav_, base::Bind(&FrameNavTestHandler::RunNextNav, this));
nav_, base::BindOnce(&FrameNavTestHandler::RunNextNav, this));
// Load the main URL.
browser->GetMainFrame()->LoadURL(expectations_->GetMainURL());

View File

@ -136,8 +136,8 @@ class JSDialogTestHandler : public TestHandler {
callback->Continue(success_, user_input_);
} else if (mode_ == MODE_RUN_DELAYED) {
// Continue asynchronously.
CefPostTask(TID_UI,
base::Bind(&JSDialogTestHandler::Continue, this, callback));
CefPostTask(TID_UI, base::BindOnce(&JSDialogTestHandler::Continue, this,
callback));
}
return true;
@ -162,8 +162,8 @@ class JSDialogTestHandler : public TestHandler {
callback->Continue(success_, user_input_);
} else if (mode_ == MODE_RUN_DELAYED) {
// Continue asynchronously.
CefPostTask(TID_UI,
base::Bind(&JSDialogTestHandler::Continue, this, callback));
CefPostTask(TID_UI, base::BindOnce(&JSDialogTestHandler::Continue, this,
callback));
}
return true;

View File

@ -161,8 +161,8 @@ class LifeSpanTestHandler : public RoutingTestHandler {
// This test will call DestroyTest().
SetDestroyTestExpected(true);
CefPostDelayedTask(TID_UI,
base::Bind(&LifeSpanTestHandler::DelayClose, this), 100);
CefPostDelayedTask(
TID_UI, base::BindOnce(&LifeSpanTestHandler::DelayClose, this), 100);
}
void DelayClose() {

View File

@ -522,8 +522,9 @@ class SingleQueryTestHandler : public SingleLoadTestHandler {
if (sync_callback_) {
ExecuteCallback();
} else {
CefPostTask(TID_UI,
base::Bind(&SingleQueryTestHandler::ExecuteCallback, this));
CefPostTask(
TID_UI,
base::BindOnce(&SingleQueryTestHandler::ExecuteCallback, this));
}
}
@ -761,8 +762,8 @@ class SinglePersistentQueryTestHandler : public SingleLoadTestHandler {
} else {
CefPostTask(
TID_UI,
base::Bind(&SinglePersistentQueryTestHandler::ExecuteCallback,
this));
base::BindOnce(&SinglePersistentQueryTestHandler::ExecuteCallback,
this));
}
}
@ -1902,9 +1903,9 @@ class MultiQuerySingleFrameTestHandler : public SingleLoadTestHandler,
if (!SignalCompletionWhenAllBrowsersClose()) {
// Complete asynchronously so the call stack has a chance to unwind.
CefPostTask(
TID_UI,
base::Bind(&MultiQuerySingleFrameTestHandler::TestComplete, this));
CefPostTask(TID_UI,
base::BindOnce(
&MultiQuerySingleFrameTestHandler::TestComplete, this));
}
}

View File

@ -1792,7 +1792,8 @@ class LoadNavTestHandler : public TestHandler {
// The next navigation should not occur. Therefore call DestroyTest()
// after a reasonable timeout.
CefPostDelayedTask(
TID_UI, base::Bind(&LoadNavTestHandler::DestroyTest, this), 500);
TID_UI, base::BindOnce(&LoadNavTestHandler::DestroyTest, this),
500);
}
} else {
// Done with the test.
@ -2962,7 +2963,7 @@ class CancelBeforeNavTestHandler : public TestHandler {
got_get_resource_handler_.yes();
CefPostTask(TID_UI,
base::Bind(&CancelBeforeNavTestHandler::CancelLoad, this));
base::BindOnce(&CancelBeforeNavTestHandler::CancelLoad, this));
return new UnstartedSchemeHandler();
}
@ -3207,7 +3208,8 @@ class CancelAfterNavTestHandler : public TestHandler {
// The required delay is longer when browser-side navigation is enabled.
CefPostDelayedTask(
TID_UI, base::Bind(&CancelAfterNavTestHandler::CancelLoad, this), 1000);
TID_UI, base::BindOnce(&CancelAfterNavTestHandler::CancelLoad, this),
1000);
return new StalledSchemeHandler();
}

View File

@ -1402,8 +1402,9 @@ class OSRTestHandler : public RoutingTestHandler,
void DestroySucceededTestSoon() {
if (succeeded())
return;
if (++event_count_ == event_total_)
CefPostTask(TID_UI, base::Bind(&OSRTestHandler::DestroyTest, this));
if (++event_count_ == event_total_) {
CefPostTask(TID_UI, base::BindOnce(&OSRTestHandler::DestroyTest, this));
}
}
void DestroyTest() override {

View File

@ -101,8 +101,8 @@ class AccessibilityTestHandler : public TestHandler,
// Post a delayed task to disable Accessibility
CefPostDelayedTask(
TID_UI,
base::Bind(&AccessibilityTestHandler::DisableAccessibility, this,
browser),
base::BindOnce(&AccessibilityTestHandler::DisableAccessibility,
this, browser),
200);
} break;
// Delayed task will posted later after we have initial details
@ -139,10 +139,11 @@ class AccessibilityTestHandler : public TestHandler,
SetEditBoxIdAndRect(update);
EXPECT_NE(edit_box_id_, -1);
// Post a delayed task to hide the span and trigger location change
CefPostDelayedTask(TID_UI,
base::Bind(&AccessibilityTestHandler::HideEditBox,
this, GetBrowser()),
200);
CefPostDelayedTask(
TID_UI,
base::BindOnce(&AccessibilityTestHandler::HideEditBox, this,
GetBrowser()),
200);
}
} break;
case TEST_FOCUS_CHANGE: {
@ -164,8 +165,8 @@ class AccessibilityTestHandler : public TestHandler,
CefPostDelayedTask(
TID_UI,
base::Bind(&AccessibilityTestHandler::SetFocusOnEditBox, this,
GetBrowser()),
base::BindOnce(&AccessibilityTestHandler::SetFocusOnEditBox, this,
GetBrowser()),
200);
} else {
// Retrieve the "focus" event.
@ -180,7 +181,8 @@ class AccessibilityTestHandler : public TestHandler,
// Now Post a delayed task to destroy the test giving
// sufficient time for any accessibility updates to come through
CefPostDelayedTask(
TID_UI, base::Bind(&AccessibilityTestHandler::DestroyTest, this),
TID_UI,
base::BindOnce(&AccessibilityTestHandler::DestroyTest, this),
500);
}
} break;
@ -203,7 +205,7 @@ class AccessibilityTestHandler : public TestHandler,
if (got_hide_edit_box_) {
// Now destroy the test.
CefPostTask(TID_UI,
base::Bind(&AccessibilityTestHandler::DestroyTest, this));
base::BindOnce(&AccessibilityTestHandler::DestroyTest, this));
}
}
@ -251,7 +253,8 @@ class AccessibilityTestHandler : public TestHandler,
// Now Post a delayed task to destroy the test
// giving sufficient time for any accessibility updates to come through
CefPostDelayedTask(
TID_UI, base::Bind(&AccessibilityTestHandler::DestroyTest, this), 500);
TID_UI, base::BindOnce(&AccessibilityTestHandler::DestroyTest, this),
500);
}
static CefRefPtr<CefListValue> GetUpdateList(CefRefPtr<CefValue> value) {
@ -376,7 +379,8 @@ class AccessibilityTestHandler : public TestHandler,
// Now Post a delayed task to destroy the test
// giving sufficient time for any accessibility updates to come through
CefPostDelayedTask(
TID_UI, base::Bind(&AccessibilityTestHandler::DestroyTest, this), 500);
TID_UI, base::BindOnce(&AccessibilityTestHandler::DestroyTest, this),
500);
}
// Find Edit box Id in accessibility tree.

View File

@ -44,12 +44,14 @@ class DisplayTestHandler : public RoutingTestHandler, public CefRenderHandler {
if (!got_paint_[status_]) {
got_paint_[status_].yes();
if (status_ == START)
if (status_ == START) {
OnStartIfDone();
else if (status_ == SHOW)
CefPostTask(TID_UI, base::Bind(&DisplayTestHandler::DestroyTest, this));
else
EXPECT_FALSE(true); // Not reached.
} else if (status_ == SHOW) {
CefPostTask(TID_UI,
base::BindOnce(&DisplayTestHandler::DestroyTest, this));
} else {
ADD_FAILURE();
}
}
}
@ -81,7 +83,7 @@ class DisplayTestHandler : public RoutingTestHandler, public CefRenderHandler {
got_navigate_msg_.yes();
// Wait a bit to verify no OnPaint callback.
CefPostDelayedTask(
TID_UI, base::Bind(&DisplayTestHandler::OnNavigate, this), 250);
TID_UI, base::BindOnce(&DisplayTestHandler::OnNavigate, this), 250);
}
}
callback->Success("");
@ -123,8 +125,9 @@ class DisplayTestHandler : public RoutingTestHandler, public CefRenderHandler {
}
void OnStartIfDone() {
if (got_start_msg_ && got_paint_[START])
CefPostTask(TID_UI, base::Bind(&DisplayTestHandler::OnStart, this));
if (got_start_msg_ && got_paint_[START]) {
CefPostTask(TID_UI, base::BindOnce(&DisplayTestHandler::OnStart, this));
}
}
void OnStart() {
@ -259,7 +262,8 @@ class OsrPopupJSOtherClientTestHandler : public TestHandler,
got_load_end_popup_.yes();
CefPostDelayedTask(
TID_UI,
base::Bind(&OsrPopupJSOtherClientTestHandler::Close, this, browser),
base::BindOnce(&OsrPopupJSOtherClientTestHandler::Close, this,
browser),
100);
} else {
browser->GetMainFrame()->LoadURL("javascript:window.open('about:blank')");

View File

@ -285,19 +285,19 @@ class PluginTestHandler : public RoutingTestHandler,
if (got_context_menu_dismissed_) {
// After context menu display. Destroy the test.
CefPostDelayedTask(TID_UI,
base::Bind(&PluginTestHandler::DestroyTest, this),
base::BindOnce(&PluginTestHandler::DestroyTest, this),
kPdfLoadDelayMs);
} else {
// Trigger the context menu.
CefPostDelayedTask(TID_UI,
base::Bind(&PluginTestHandler::TriggerContextMenu,
this, frame->GetBrowser()),
base::BindOnce(&PluginTestHandler::TriggerContextMenu,
this, frame->GetBrowser()),
kPdfLoadDelayMs);
}
}
void EndTest() {
CefPostTask(TID_UI, base::Bind(&PluginTestHandler::DestroyTest, this));
CefPostTask(TID_UI, base::BindOnce(&PluginTestHandler::DestroyTest, this));
}
CefRefPtr<CefContextMenuHandler> GetContextMenuHandler() override {

View File

@ -250,7 +250,8 @@ void ValidateDefaults(CefRefPtr<CefRequestContext> context,
bool reset,
CefRefPtr<CefWaitableEvent> event) {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, base::Bind(ValidateDefaults, context, reset, event));
CefPostTask(TID_UI,
base::BindOnce(ValidateDefaults, context, reset, event));
return;
}
@ -324,7 +325,7 @@ void PopulateRootSet(CefRefPtr<CefDictionaryValue> val) {
void ValidateSetGet(CefRefPtr<CefRequestContext> context,
CefRefPtr<CefWaitableEvent> event) {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, base::Bind(ValidateSetGet, context, event));
CefPostTask(TID_UI, base::BindOnce(ValidateSetGet, context, event));
return;
}
@ -361,7 +362,7 @@ void ValidateSetGet(CefRefPtr<CefRequestContext> context,
void ValidateGet(CefRefPtr<CefRequestContext> context,
CefRefPtr<CefWaitableEvent> event) {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, base::Bind(ValidateGet, context, event));
CefPostTask(TID_UI, base::BindOnce(ValidateGet, context, event));
return;
}

View File

@ -99,8 +99,9 @@ class SendRecvTestHandler : public TestHandler {
// Send the message to the renderer process.
if (!CefCurrentlyOn(send_thread_)) {
CefPostTask(send_thread_, base::Bind(&SendRecvTestHandler::SendMessage,
this, browser, frame));
CefPostTask(send_thread_,
base::BindOnce(&SendRecvTestHandler::SendMessage, this,
browser, frame));
} else {
SendMessage(browser, frame);
}

View File

@ -336,7 +336,7 @@ class PopupTestHandler : public TestHandler {
~TestVisitor() override {
// Destroy the test.
CefPostTask(TID_UI,
base::Bind(&PopupTestHandler::DestroyTest, handler_));
base::BindOnce(&PopupTestHandler::DestroyTest, handler_));
}
bool Visit(const CefCookie& cookie,
@ -593,7 +593,8 @@ class PopupNavTestHandler : public TestHandler {
if (mode_ == DENY) {
// Wait a bit to make sure the popup window isn't created.
CefPostDelayedTask(
TID_UI, base::Bind(&PopupNavTestHandler::DestroyTest, this), 200);
TID_UI, base::BindOnce(&PopupNavTestHandler::DestroyTest, this),
200);
}
} else if (url == kPopupNavPopupUrl) {
EXPECT_FALSE(got_popup_load_end_);
@ -644,7 +645,8 @@ class PopupNavTestHandler : public TestHandler {
}
if (destroy_test) {
CefPostTask(TID_UI, base::Bind(&PopupNavTestHandler::DestroyTest, this));
CefPostTask(TID_UI,
base::BindOnce(&PopupNavTestHandler::DestroyTest, this));
}
}

View File

@ -284,8 +284,8 @@ class NetNotifyTestHandler : public TestHandler {
explicit TestVisitor(NetNotifyTestHandler* handler) : handler_(handler) {}
~TestVisitor() override {
// Destroy the test.
CefPostTask(TID_UI,
base::Bind(&NetNotifyTestHandler::DestroyTest, handler_));
CefPostTask(TID_UI, base::BindOnce(&NetNotifyTestHandler::DestroyTest,
handler_));
}
bool Visit(const CefCookie& cookie,

View File

@ -586,7 +586,7 @@ class TypeTestHandler : public TestHandler {
get_expectations_.IsDone(false)) {
completed_browser_side_ = true;
// Destroy the test on the UI thread.
CefPostTask(TID_UI, base::Bind(&TypeTestHandler::DestroyTest, this));
CefPostTask(TID_UI, base::BindOnce(&TypeTestHandler::DestroyTest, this));
}
return TestHandler::GetResourceHandler(browser, frame, request);

View File

@ -2,9 +2,11 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include <memory>
#include <vector>
#include "include/base/cef_callback.h"
#include "include/base/cef_lock.h"
#include "include/cef_file_util.h"
#include "include/cef_waitable_event.h"
#include "include/wrapper/cef_closure_task.h"
@ -123,8 +125,8 @@ class ResourceManagerTestHandler : public RoutingTestHandler {
state_->messages_.push_back(request);
callback->Success("");
CefPostTask(TID_UI, base::Bind(&ResourceManagerTestHandler::Continue, this,
browser));
CefPostTask(TID_UI, base::BindOnce(&ResourceManagerTestHandler::Continue,
this, browser));
return true;
}
@ -132,7 +134,7 @@ class ResourceManagerTestHandler : public RoutingTestHandler {
// Wait a bit before destroying the test. Used with ProviderDoNothing.
void DelayedDestroyTest() {
CefPostDelayedTask(
TID_UI, base::Bind(&ResourceManagerTestHandler::DestroyTest, this),
TID_UI, base::BindOnce(&ResourceManagerTestHandler::DestroyTest, this),
100);
}
@ -194,7 +196,7 @@ class TestProvider : public CefResourceManager::Provider {
TrackCallback got_on_request_;
TrackCallback got_on_request_canceled_;
TrackCallback got_destruct_;
base::Closure destruct_callback_;
base::OnceClosure destruct_callback_;
std::string request_url_;
};
@ -204,7 +206,7 @@ class TestProvider : public CefResourceManager::Provider {
CEF_REQUIRE_IO_THREAD();
state_->got_destruct_.yes();
if (!state_->destruct_callback_.is_null())
state_->destruct_callback_.Run();
std::move(state_->destruct_callback_).Run();
}
bool OnRequest(scoped_refptr<CefResourceManager::Request> request) override {
@ -237,27 +239,43 @@ class TestProvider : public CefResourceManager::Provider {
// Helper that blocks on destruction of 1 or more TestProviders.
class ProviderDestructHelper {
public:
explicit ProviderDestructHelper(int expected_count) : current_count_(0) {
event_ = CefWaitableEvent::CreateWaitableEvent(true, false);
callback_ =
base::Bind(&DestructCallback, expected_count, &current_count_, event_);
explicit ProviderDestructHelper(int expected_count)
: expected_count_(expected_count),
event_(CefWaitableEvent::CreateWaitableEvent(true, false)) {
CHECK_GT(expected_count_, 0);
}
const base::Closure& callback() const { return callback_; }
base::OnceClosure callback() {
return base::BindOnce(
[](ProviderDestructHelper* self) { self->DestructCallback(); },
base::Unretained(this));
}
void Wait() { event_->Wait(); }
private:
static void DestructCallback(int expected_count,
int* current_count,
CefRefPtr<CefWaitableEvent> event) {
if (++(*current_count) == expected_count)
void DestructCallback() {
bool signal = false;
{
base::AutoLock lock_scope(lock_);
CHECK_LT(current_count_, expected_count_);
if (++current_count_ == expected_count_)
signal = true;
}
if (signal) {
// Don't access any members after calling Signal(), which causes |this| to
// be deleted on a different thread.
auto event = event_;
event->Signal();
}
}
int current_count_;
const int expected_count_;
int current_count_ = 0;
CefRefPtr<CefWaitableEvent> event_;
base::Closure callback_;
base::Lock lock_;
};
// Test that that the URL retrieved via Request::url() is parsed as expected.
@ -344,11 +362,11 @@ class SimpleTestProvider : public TestProvider {
SimpleTestProvider(State* state,
Mode mode,
CefResourceManager* manager,
base::Closure do_nothing_callback)
base::OnceClosure do_nothing_callback)
: TestProvider(state),
mode_(mode),
manager_(manager),
do_nothing_callback_(do_nothing_callback) {}
do_nothing_callback_(std::move(do_nothing_callback)) {}
bool OnRequest(scoped_refptr<CefResourceManager::Request> request) override {
TestProvider::OnRequest(request);
@ -365,8 +383,7 @@ class SimpleTestProvider : public TestProvider {
manager_->RemoveAllProviders();
else if (mode_ == DO_NOTHING) {
EXPECT_FALSE(do_nothing_callback_.is_null());
do_nothing_callback_.Run();
do_nothing_callback_.Reset();
std::move(do_nothing_callback_).Run();
}
return true;
@ -375,7 +392,7 @@ class SimpleTestProvider : public TestProvider {
private:
Mode mode_;
CefResourceManager* manager_; // Weak reference.
base::Closure do_nothing_callback_;
base::OnceClosure do_nothing_callback_;
DISALLOW_COPY_AND_ASSIGN(SimpleTestProvider);
};
@ -665,7 +682,8 @@ TEST(ResourceManagerTest, ProviderDoNothing) {
state.manager_->AddProvider(
new SimpleTestProvider(
&provider_state1, SimpleTestProvider::DO_NOTHING, nullptr,
base::Bind(&ResourceManagerTestHandler::DelayedDestroyTest, handler)),
base::BindOnce(&ResourceManagerTestHandler::DelayedDestroyTest,
handler)),
0, std::string());
state.manager_->AddProvider(
new SimpleTestProvider(&provider_state2, SimpleTestProvider::DO_NOTHING,
@ -870,14 +888,16 @@ namespace {
class OneShotProvider : public CefResourceManager::Provider {
public:
OneShotProvider(const std::string& content,
const base::Closure& destruct_callback)
: done_(false), content_(content), destruct_callback_(destruct_callback) {
base::OnceClosure destruct_callback)
: done_(false),
content_(content),
destruct_callback_(std::move(destruct_callback)) {
EXPECT_FALSE(content.empty());
}
~OneShotProvider() {
CEF_REQUIRE_IO_THREAD();
destruct_callback_.Run();
std::move(destruct_callback_).Run();
}
bool OnRequest(scoped_refptr<CefResourceManager::Request> request) override {
@ -901,7 +921,7 @@ class OneShotProvider : public CefResourceManager::Provider {
private:
bool done_;
std::string content_;
base::Closure destruct_callback_;
base::OnceClosure destruct_callback_;
DISALLOW_COPY_AND_ASSIGN(OneShotProvider);
};
@ -999,10 +1019,10 @@ class EchoProvider : public CefResourceManager::Provider {
CefRefPtr<CefStreamResourceHandler> handler(
new CefStreamResourceHandler("text/html", stream));
CefPostDelayedTask(
TID_IO,
base::Bind(&CefResourceManager::Request::Continue, request, handler),
delay);
CefPostDelayedTask(TID_IO,
base::BindOnce(&CefResourceManager::Request::Continue,
request, handler),
delay);
return true;
}
@ -1548,7 +1568,7 @@ TEST(ResourceManagerTest, UrlFilter) {
state.urls_.push_back(kUrl);
// Set the URL filter.
state.manager_->SetUrlFilter(base::Bind(TestUrlFilter));
state.manager_->SetUrlFilter(base::BindRepeating(TestUrlFilter));
TestProvider::State provider_state1;
TestProvider::State provider_state2;
@ -1599,7 +1619,7 @@ TEST(ResourceManagerTest, UrlFilterWithQuery) {
state.urls_.push_back(kUrl);
// Set the URL filter.
state.manager_->SetUrlFilter(base::Bind(TestUrlFilterWithQuery));
state.manager_->SetUrlFilter(base::BindRepeating(TestUrlFilterWithQuery));
TestProvider::State provider_state1;
TestProvider::State provider_state2;
@ -1653,7 +1673,7 @@ TEST(ResourceManagerTest, UrlFilterWithFragment) {
state.urls_.push_back(kUrl);
// Set the URL filter.
state.manager_->SetUrlFilter(base::Bind(TestUrlFilterWithFragment));
state.manager_->SetUrlFilter(base::BindRepeating(TestUrlFilterWithFragment));
TestProvider::State provider_state1;
TestProvider::State provider_state2;
@ -1735,7 +1755,8 @@ TEST(ResourceManagerTest, MimeTypeResolver) {
state.urls_.push_back(kUrl);
// Set the mime type resolver.
state.manager_->SetMimeTypeResolver(base::Bind(TestMimeTypeResolver));
state.manager_->SetMimeTypeResolver(
base::BindRepeating(TestMimeTypeResolver));
TestProvider::State provider_state1;
TestProvider::State provider_state2;

View File

@ -30,17 +30,17 @@ class NormalResourceHandler : public CefStreamResourceHandler {
const CefString& mime_type,
CefResponse::HeaderMap header_map,
CefRefPtr<CefStreamReader> stream,
const base::Closure& destroy_callback)
base::OnceClosure destroy_callback)
: CefStreamResourceHandler(status_code,
status_text,
mime_type,
header_map,
stream),
destroy_callback_(destroy_callback) {}
destroy_callback_(std::move(destroy_callback)) {}
~NormalResourceHandler() override {
EXPECT_EQ(1, cancel_ct_);
destroy_callback_.Run();
std::move(destroy_callback_).Run();
}
void Cancel() override {
@ -49,7 +49,7 @@ class NormalResourceHandler : public CefStreamResourceHandler {
}
private:
const base::Closure destroy_callback_;
base::OnceClosure destroy_callback_;
int cancel_ct_ = 0;
};
@ -88,21 +88,21 @@ class CallbackResourceHandler : public CefResourceHandler {
const CefString& mime_type,
CefResponse::HeaderMap header_map,
CefRefPtr<CefStreamReader> stream,
const base::Closure& destroy_callback)
base::OnceClosure destroy_callback)
: mode_(mode),
status_code_(status_code),
status_text_(status_text),
mime_type_(mime_type),
header_map_(header_map),
stream_(stream),
destroy_callback_(destroy_callback) {
destroy_callback_(std::move(destroy_callback)) {
DCHECK(!mime_type_.empty());
DCHECK(stream_.get());
}
~CallbackResourceHandler() override {
EXPECT_EQ(1, cancel_ct_);
destroy_callback_.Run();
std::move(destroy_callback_).Run();
}
bool Open(CefRefPtr<CefRequest> request,
@ -113,7 +113,7 @@ class CallbackResourceHandler : public CefResourceHandler {
if (IsDelayedOpen()) {
// Continue the request asynchronously by executing the callback.
CefPostTask(TID_FILE_USER_VISIBLE,
base::Bind(&CefCallback::Continue, callback));
base::BindOnce(&CefCallback::Continue, callback));
handle_request = false;
return true;
} else if (IsImmediateOpen()) {
@ -153,8 +153,8 @@ class CallbackResourceHandler : public CefResourceHandler {
if (IsDelayedRead()) {
// Continue the request asynchronously by executing the callback.
CefPostTask(TID_FILE_USER_VISIBLE,
base::Bind(&CallbackResourceHandler::ContinueRead, this,
data_out, bytes_to_read, callback));
base::BindOnce(&CallbackResourceHandler::ContinueRead, this,
data_out, bytes_to_read, callback));
return true;
} else if (IsImmediateRead()) {
// Continue the request immediately be executing the callback.
@ -207,7 +207,7 @@ class CallbackResourceHandler : public CefResourceHandler {
const CefResponse::HeaderMap header_map_;
const CefRefPtr<CefStreamReader> stream_;
const base::Closure destroy_callback_;
base::OnceClosure destroy_callback_;
int cancel_ct_ = 0;
IMPLEMENT_REFCOUNTING(CallbackResourceHandler);
@ -225,10 +225,10 @@ class IncompleteResourceHandlerOld : public CefResourceHandler {
IncompleteResourceHandlerOld(TestMode test_mode,
const std::string& mime_type,
const base::Closure& destroy_callback)
base::OnceClosure destroy_callback)
: test_mode_(test_mode),
mime_type_(mime_type),
destroy_callback_(destroy_callback) {}
destroy_callback_(std::move(destroy_callback)) {}
~IncompleteResourceHandlerOld() override {
EXPECT_EQ(1, process_request_ct_);
@ -243,7 +243,7 @@ class IncompleteResourceHandlerOld : public CefResourceHandler {
EXPECT_EQ(0, read_response_ct_);
}
destroy_callback_.Run();
std::move(destroy_callback_).Run();
}
bool ProcessRequest(CefRefPtr<CefRequest> request,
@ -298,7 +298,7 @@ class IncompleteResourceHandlerOld : public CefResourceHandler {
private:
const TestMode test_mode_;
const std::string mime_type_;
const base::Closure destroy_callback_;
base::OnceClosure destroy_callback_;
int process_request_ct_ = 0;
int get_response_headers_ct_ = 0;
@ -320,10 +320,10 @@ class IncompleteResourceHandler : public CefResourceHandler {
IncompleteResourceHandler(TestMode test_mode,
const std::string& mime_type,
const base::Closure& destroy_callback)
base::OnceClosure destroy_callback)
: test_mode_(test_mode),
mime_type_(mime_type),
destroy_callback_(destroy_callback) {}
destroy_callback_(std::move(destroy_callback)) {}
~IncompleteResourceHandler() override {
EXPECT_EQ(1, open_ct_);
@ -338,7 +338,7 @@ class IncompleteResourceHandler : public CefResourceHandler {
EXPECT_EQ(0, read_ct_);
}
destroy_callback_.Run();
std::move(destroy_callback_).Run();
}
bool Open(CefRefPtr<CefRequest> request,
@ -410,7 +410,7 @@ class IncompleteResourceHandler : public CefResourceHandler {
private:
const TestMode test_mode_;
const std::string mime_type_;
const base::Closure destroy_callback_;
base::OnceClosure destroy_callback_;
int open_ct_ = 0;
int get_response_headers_ct_ = 0;
@ -987,7 +987,8 @@ class BasicResponseTest : public TestHandler {
if (!SignalCompletionWhenAllBrowsersClose()) {
// Complete asynchronously so the call stack has a chance to unwind.
CefPostTask(TID_UI, base::Bind(&BasicResponseTest::TestComplete, this));
CefPostTask(TID_UI,
base::BindOnce(&BasicResponseTest::TestComplete, this));
}
}
@ -1039,9 +1040,9 @@ class BasicResponseTest : public TestHandler {
return "<html><body>Redirect</body></html>";
}
base::Closure GetResourceDestroyCallback() {
base::OnceClosure GetResourceDestroyCallback() {
resource_handler_created_ct_++;
return base::Bind(&BasicResponseTest::MaybeDestroyTest, this, true);
return base::BindOnce(&BasicResponseTest::MaybeDestroyTest, this, true);
}
bool GetCallbackResourceHandlerMode(CallbackResourceHandler::Mode& mode) {
@ -1322,14 +1323,14 @@ class BasicResponseTest : public TestHandler {
EXPECT_TRUE(IsIncomplete());
SetSignalCompletionWhenAllBrowsersClose(false);
CefPostDelayedTask(
TID_UI, base::Bind(&TestHandler::CloseBrowser, GetBrowser(), false),
TID_UI, base::BindOnce(&TestHandler::CloseBrowser, GetBrowser(), false),
100);
}
void MaybeDestroyTest(bool from_handler) {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, base::Bind(&BasicResponseTest::MaybeDestroyTest, this,
from_handler));
CefPostTask(TID_UI, base::BindOnce(&BasicResponseTest::MaybeDestroyTest,
this, from_handler));
return;
}
@ -2108,7 +2109,7 @@ class SubresourceResponseTest : public RoutingTestHandler {
if (!SignalCompletionWhenAllBrowsersClose()) {
// Complete asynchronously so the call stack has a chance to unwind.
CefPostTask(TID_UI,
base::Bind(&SubresourceResponseTest::TestComplete, this));
base::BindOnce(&SubresourceResponseTest::TestComplete, this));
}
}
@ -2218,9 +2219,10 @@ class SubresourceResponseTest : public RoutingTestHandler {
return "<html><body>Redirect</body></html>";
}
base::Closure GetResourceDestroyCallback() {
base::OnceClosure GetResourceDestroyCallback() {
resource_handler_created_ct_++;
return base::Bind(&SubresourceResponseTest::MaybeDestroyTest, this, true);
return base::BindOnce(&SubresourceResponseTest::MaybeDestroyTest, this,
true);
}
bool GetCallbackResourceHandlerMode(CallbackResourceHandler::Mode& mode) {
@ -2511,14 +2513,15 @@ class SubresourceResponseTest : public RoutingTestHandler {
EXPECT_TRUE(IsIncomplete());
SetSignalCompletionWhenAllBrowsersClose(false);
CefPostDelayedTask(
TID_UI, base::Bind(&TestHandler::CloseBrowser, GetBrowser(), false),
TID_UI, base::BindOnce(&TestHandler::CloseBrowser, GetBrowser(), false),
100);
}
void MaybeDestroyTest(bool from_handler) {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, base::Bind(&SubresourceResponseTest::MaybeDestroyTest,
this, from_handler));
CefPostTask(TID_UI,
base::BindOnce(&SubresourceResponseTest::MaybeDestroyTest,
this, from_handler));
return;
}
@ -3300,9 +3303,9 @@ class BeforeResourceLoadTest : public TestHandler {
browser->GetMainFrame()->LoadURL(kResourceTestHtml2);
} else {
// Continue or cancel asynchronously.
CefPostTask(TID_UI,
base::Bind(&CefRequestCallback::Continue, callback.get(),
test_mode_ == CONTINUE_ASYNC));
CefPostTask(TID_UI, base::BindOnce(&CefRequestCallback::Continue,
callback.get(),
test_mode_ == CONTINUE_ASYNC));
}
return RV_CONTINUE_ASYNC;
}
@ -3866,15 +3869,14 @@ class ResponseFilterTestHandler : public TestHandler {
void GetOutputContent(CefRefPtr<CefFrame> frame) {
class StringVisitor : public CefStringVisitor {
public:
typedef base::Callback<void(const std::string& /*received_content*/)>
VisitorCallback;
using VisitorCallback =
base::OnceCallback<void(const std::string& /*received_content*/)>;
explicit StringVisitor(const VisitorCallback& callback)
: callback_(callback) {}
explicit StringVisitor(VisitorCallback callback)
: callback_(std::move(callback)) {}
void Visit(const CefString& string) override {
callback_.Run(string);
callback_.Reset();
std::move(callback_).Run(string);
}
private:
@ -3884,7 +3886,7 @@ class ResponseFilterTestHandler : public TestHandler {
};
frame->GetSource(new StringVisitor(
base::Bind(&ResponseFilterTestHandler::VerifyOutput, this)));
base::BindOnce(&ResponseFilterTestHandler::VerifyOutput, this)));
}
void VerifyOutput(const std::string& received_content) {

View File

@ -78,14 +78,14 @@ void RunTestsOnTestThread() {
sleep(100);
// Wait for the test server to stop, and then quit the CEF message loop.
test_server::Stop(base::Bind(QuitMessageLoop));
test_server::Stop(base::BindOnce(QuitMessageLoop));
}
// Called on the UI thread.
void ContinueOnUIThread(CefRefPtr<CefTaskRunner> test_task_runner) {
// Run the test suite on the test thread.
test_task_runner->PostTask(
CefCreateClosureTask(base::Bind(&RunTestsOnTestThread)));
CefCreateClosureTask(base::BindOnce(&RunTestsOnTestThread)));
}
#if defined(OS_LINUX) && defined(CEF_X11)
@ -210,7 +210,7 @@ int main(int argc, char* argv[]) {
// Wait for the test server to stop.
CefRefPtr<CefWaitableEvent> event =
CefWaitableEvent::CreateWaitableEvent(true, false);
test_server::Stop(base::Bind(&CefWaitableEvent::Signal, event));
test_server::Stop(base::BindOnce(&CefWaitableEvent::Signal, event));
event->Wait();
} else {
// Create and start the test thread.
@ -221,7 +221,7 @@ int main(int argc, char* argv[]) {
// Start the tests from the UI thread so that any pending UI tasks get a
// chance to execute first.
CefPostTask(TID_UI,
base::Bind(&ContinueOnUIThread, thread->GetTaskRunner()));
base::BindOnce(&ContinueOnUIThread, thread->GetTaskRunner()));
// Run the CEF message loop.
message_loop->Run();

View File

@ -306,9 +306,9 @@ class ClientSchemeHandlerOld : public CefResourceHandler {
if (handled) {
if (test_results_->delay > 0) {
// Continue after the delay.
CefPostDelayedTask(TID_IO,
base::Bind(&CefCallback::Continue, callback.get()),
test_results_->delay);
CefPostDelayedTask(
TID_IO, base::BindOnce(&CefCallback::Continue, callback.get()),
test_results_->delay);
} else {
// Continue immediately.
callback->Continue();
@ -372,8 +372,8 @@ class ClientSchemeHandlerOld : public CefResourceHandler {
// Continue after a delay.
CefPostDelayedTask(
TID_IO,
base::Bind(&ClientSchemeHandlerOld::ContinueAfterDelay, this,
callback),
base::BindOnce(&ClientSchemeHandlerOld::ContinueAfterDelay, this,
callback),
test_results_->delay);
bytes_read = 0;
return true;
@ -487,9 +487,10 @@ class ClientSchemeHandler : public CefResourceHandler {
if (test_results_->delay > 0) {
// Continue after the delay.
handle_request = false;
CefPostDelayedTask(TID_FILE_USER_BLOCKING,
base::Bind(&CefCallback::Continue, callback.get()),
test_results_->delay);
CefPostDelayedTask(
TID_FILE_USER_BLOCKING,
base::BindOnce(&CefCallback::Continue, callback.get()),
test_results_->delay);
}
return true;
} else if (test_results_->response_error_code != ERR_NONE) {
@ -558,10 +559,11 @@ class ClientSchemeHandler : public CefResourceHandler {
if (test_results_->delay > 0) {
if (!has_delayed_) {
// Continue after a delay.
CefPostDelayedTask(TID_FILE_USER_BLOCKING,
base::Bind(&ClientSchemeHandler::ContinueAfterDelay,
this, data_out, bytes_to_read, callback),
test_results_->delay);
CefPostDelayedTask(
TID_FILE_USER_BLOCKING,
base::BindOnce(&ClientSchemeHandler::ContinueAfterDelay, this,
data_out, bytes_to_read, callback),
test_results_->delay);
bytes_read = 0;
return true;
}

View File

@ -72,11 +72,11 @@ class TestServerHandler : public CefServerHandler {
// started.
// |destroy_callback| will be executed on the UI thread after this handler
// object is destroyed.
TestServerHandler(const base::Closure& start_callback,
const base::Closure& destroy_callback)
TestServerHandler(base::OnceClosure start_callback,
base::OnceClosure destroy_callback)
: initialized_(false),
start_callback_(start_callback),
destroy_callback_(destroy_callback),
start_callback_(std::move(start_callback)),
destroy_callback_(std::move(destroy_callback)),
expected_connection_ct_(0),
actual_connection_ct_(0),
expected_http_request_ct_(0),
@ -107,7 +107,7 @@ class TestServerHandler : public CefServerHandler {
delete *it;
}
destroy_callback_.Run();
std::move(destroy_callback_).Run();
}
// Must be called before CreateServer().
@ -411,13 +411,12 @@ class TestServerHandler : public CefServerHandler {
void RunStartCallback() {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI,
base::Bind(&TestServerHandler::RunStartCallback, this));
base::BindOnce(&TestServerHandler::RunStartCallback, this));
return;
}
EXPECT_FALSE(start_callback_.is_null());
start_callback_.Run();
start_callback_.Reset();
std::move(start_callback_).Run();
}
CefRefPtr<CefServer> server_;
@ -425,8 +424,8 @@ class TestServerHandler : public CefServerHandler {
bool initialized_;
// After initialization only accessed on the UI thread.
base::Closure start_callback_;
base::Closure destroy_callback_;
base::OnceClosure start_callback_;
base::OnceClosure destroy_callback_;
// After initialization the below members are only accessed on the server
// thread.
@ -484,7 +483,7 @@ class HttpTestRunner : public base::RefCountedThreadSafe<HttpTestRunner> {
CreateHttpRequestHandler() = 0;
// Run the request and execute |complete_callback| on completion.
virtual void RunRequest(const base::Closure& complete_callback) = 0;
virtual void RunRequest(base::OnceClosure complete_callback) = 0;
virtual bool VerifyResults() = 0;
virtual std::string ToString() = 0;
@ -513,12 +512,12 @@ class HttpTestRunner : public base::RefCountedThreadSafe<HttpTestRunner> {
EXPECT_FALSE(CefCurrentlyOn(TID_UI));
handler_ = new TestServerHandler(
base::Bind(&HttpTestRunner::OnServerStarted, this),
base::Bind(&HttpTestRunner::OnServerDestroyed, this));
base::BindOnce(&HttpTestRunner::OnServerStarted, this),
base::BindOnce(&HttpTestRunner::OnServerDestroyed, this));
run_event_ = CefWaitableEvent::CreateWaitableEvent(false, false);
CefPostTask(TID_UI, base::Bind(&HttpTestRunner::RunTest, this));
CefPostTask(TID_UI, base::BindOnce(&HttpTestRunner::RunTest, this));
// Block until test completion.
run_event_->Wait();
@ -567,7 +566,7 @@ class HttpTestRunner : public base::RefCountedThreadSafe<HttpTestRunner> {
got_server_destroyed_.yes();
// Allow the call stack to unwind.
CefPostTask(TID_UI, base::Bind(&HttpTestRunner::DestroyTest, this));
CefPostTask(TID_UI, base::BindOnce(&HttpTestRunner::DestroyTest, this));
}
// Run all requests in parallel.
@ -575,7 +574,7 @@ class HttpTestRunner : public base::RefCountedThreadSafe<HttpTestRunner> {
RequestRunnerMap::const_iterator it = request_runner_map_.begin();
for (; it != request_runner_map_.end(); ++it) {
it->second->RunRequest(
base::Bind(&HttpTestRunner::OnRequestComplete, this, it->first));
base::BindOnce(&HttpTestRunner::OnRequestComplete, this, it->first));
}
}
@ -583,14 +582,15 @@ class HttpTestRunner : public base::RefCountedThreadSafe<HttpTestRunner> {
void RunNextRequest() {
RequestRunnerMap::const_iterator it = request_runner_map_.begin();
it->second->RunRequest(
base::Bind(&HttpTestRunner::OnRequestComplete, this, it->first));
base::BindOnce(&HttpTestRunner::OnRequestComplete, this, it->first));
}
void OnRequestComplete(int request_id) {
EXPECT_UI_THREAD()
// Allow the call stack to unwind.
CefPostTask(TID_UI, base::Bind(&HttpTestRunner::OnRequestCompleteContinue,
this, request_id));
CefPostTask(TID_UI,
base::BindOnce(&HttpTestRunner::OnRequestCompleteContinue, this,
request_id));
}
void OnRequestCompleteContinue(int request_id) {
@ -648,8 +648,8 @@ class HttpTestRunner : public base::RefCountedThreadSafe<HttpTestRunner> {
// Use a weak reference to |this| via UIThreadHelper so that the
// test runner can be destroyed before the timeout expires.
GetUIThreadHelper()->PostDelayedTask(
base::Bind(&HttpTestRunner::OnTestTimeout, base::Unretained(this),
timeout_ms),
base::BindOnce(&HttpTestRunner::OnTestTimeout, base::Unretained(this),
timeout_ms),
timeout_ms);
}
@ -866,16 +866,16 @@ class StaticHttpServerRequestHandler
// response.
class StaticHttpURLRequestClient : public CefURLRequestClient {
public:
typedef base::Callback<void(cef_errorcode_t /* error */,
using ResponseCallback =
base::OnceCallback<void(cef_errorcode_t /* error */,
CefRefPtr<CefResponse> /* response */,
const std::string& /* data */)>
ResponseCallback;
const std::string& /* data */)>;
// |response_callback| will be executed on the UI thread when the response
// is complete.
StaticHttpURLRequestClient(CefRefPtr<CefRequest> request,
const ResponseCallback& response_callback)
: request_(request), response_callback_(response_callback) {
ResponseCallback response_callback)
: request_(request), response_callback_(std::move(response_callback)) {
EXPECT_TRUE(request_);
EXPECT_FALSE(response_callback_.is_null());
}
@ -887,9 +887,8 @@ class StaticHttpURLRequestClient : public CefURLRequestClient {
void OnRequestComplete(CefRefPtr<CefURLRequest> request) override {
EXPECT_FALSE(response_callback_.is_null());
response_callback_.Run(request->GetRequestError(), request->GetResponse(),
data_);
response_callback_.Reset();
std::move(response_callback_)
.Run(request->GetRequestError(), request->GetResponse(), data_);
}
void OnUploadProgress(CefRefPtr<CefURLRequest> request,
@ -994,17 +993,17 @@ class StaticHttpRequestRunner : public HttpTestRunner::RequestRunner {
response_);
}
void RunRequest(const base::Closure& complete_callback) override {
void RunRequest(base::OnceClosure complete_callback) override {
EXPECT_UI_THREAD();
EXPECT_FALSE(got_run_request_);
got_run_request_.yes();
complete_callback_ = complete_callback;
complete_callback_ = std::move(complete_callback);
request_client_ = new StaticHttpURLRequestClient(
request_, base::Bind(&StaticHttpRequestRunner::OnResponseComplete,
base::Unretained(this)));
request_, base::BindOnce(&StaticHttpRequestRunner::OnResponseComplete,
base::Unretained(this)));
request_client_->RunRequest();
}
@ -1032,15 +1031,14 @@ class StaticHttpRequestRunner : public HttpTestRunner::RequestRunner {
if (error == ERR_NONE)
VerifyHttpServerResponse(response_, response, data);
complete_callback_.Run();
complete_callback_.Reset();
std::move(complete_callback_).Run();
}
CefRefPtr<CefRequest> request_;
HttpServerResponse response_;
CefRefPtr<StaticHttpURLRequestClient> request_client_;
base::Closure complete_callback_;
base::OnceClosure complete_callback_;
TrackCallback got_run_request_;
TrackCallback got_create_handler_;
@ -1176,8 +1174,8 @@ class WebSocketTestHandler : public RoutingTestHandler {
void RunTest() override {
handler_ = new TestServerHandler(
base::Bind(&WebSocketTestHandler::OnServerStarted, this),
base::Bind(&WebSocketTestHandler::OnServerDestroyed, this));
base::BindOnce(&WebSocketTestHandler::OnServerStarted, this),
base::BindOnce(&WebSocketTestHandler::OnServerDestroyed, this));
OnHandlerCreated(handler_);
handler_->CreateServer();
@ -1256,7 +1254,8 @@ class WebSocketTestHandler : public RoutingTestHandler {
void DestroyTestIfDone() {
if (got_server_destroyed_ && got_done_message_) {
// Allow the call stack to unwind.
CefPostTask(TID_UI, base::Bind(&WebSocketTestHandler::DestroyTest, this));
CefPostTask(TID_UI,
base::BindOnce(&WebSocketTestHandler::DestroyTest, this));
}
}

View File

@ -144,24 +144,26 @@ void TestHandler::Collection::ExecuteTests() {
TestHandler::UIThreadHelper::UIThreadHelper() : weak_ptr_factory_(this) {}
void TestHandler::UIThreadHelper::PostTask(const base::Closure& task) {
void TestHandler::UIThreadHelper::PostTask(base::OnceClosure task) {
EXPECT_UI_THREAD();
CefPostTask(TID_UI, base::Bind(&UIThreadHelper::TaskHelper,
weak_ptr_factory_.GetWeakPtr(), task));
CefPostTask(TID_UI,
base::BindOnce(&UIThreadHelper::TaskHelper,
weak_ptr_factory_.GetWeakPtr(), std::move(task)));
}
void TestHandler::UIThreadHelper::PostDelayedTask(const base::Closure& task,
void TestHandler::UIThreadHelper::PostDelayedTask(base::OnceClosure task,
int delay_ms) {
EXPECT_UI_THREAD();
CefPostDelayedTask(TID_UI,
base::Bind(&UIThreadHelper::TaskHelper,
weak_ptr_factory_.GetWeakPtr(), task),
delay_ms);
CefPostDelayedTask(
TID_UI,
base::BindOnce(&UIThreadHelper::TaskHelper,
weak_ptr_factory_.GetWeakPtr(), std::move(task)),
delay_ms);
}
void TestHandler::UIThreadHelper::TaskHelper(const base::Closure& task) {
void TestHandler::UIThreadHelper::TaskHelper(base::OnceClosure task) {
EXPECT_UI_THREAD();
task.Run();
std::move(task).Run();
}
// TestHandler
@ -311,7 +313,7 @@ void TestHandler::SetupComplete() {
void TestHandler::DestroyTest() {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, base::Bind(&TestHandler::DestroyTest, this));
CefPostTask(TID_UI, base::BindOnce(&TestHandler::DestroyTest, this));
return;
}
@ -350,8 +352,8 @@ void TestHandler::CreateBrowser(const CefString& url,
client::switches::kUseViews);
if (use_views && !CefCurrentlyOn(TID_UI)) {
// Views classes must be accessed on the UI thread.
CefPostTask(TID_UI, base::Bind(&TestHandler::CreateBrowser, this, url,
request_context, extra_info));
CefPostTask(TID_UI, base::BindOnce(&TestHandler::CreateBrowser, this, url,
request_context, extra_info));
return;
}
@ -402,8 +404,8 @@ void TestHandler::AddResource(const std::string& url,
void TestHandler::AddResourceEx(const std::string& url,
const ResourceContent& content) {
if (!CefCurrentlyOn(TID_IO)) {
CefPostTask(TID_IO,
base::Bind(&TestHandler::AddResourceEx, this, url, content));
CefPostTask(TID_IO, base::BindOnce(&TestHandler::AddResourceEx, this, url,
content));
return;
}
@ -418,7 +420,7 @@ void TestHandler::AddResourceEx(const std::string& url,
void TestHandler::ClearResources() {
if (!CefCurrentlyOn(TID_IO)) {
CefPostTask(TID_IO, base::Bind(&TestHandler::ClearResources, this));
CefPostTask(TID_IO, base::BindOnce(&TestHandler::ClearResources, this));
return;
}
@ -427,8 +429,8 @@ void TestHandler::ClearResources() {
void TestHandler::SetTestTimeout(int timeout_ms, bool treat_as_error) {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, base::Bind(&TestHandler::SetTestTimeout, this,
timeout_ms, treat_as_error));
CefPostTask(TID_UI, base::BindOnce(&TestHandler::SetTestTimeout, this,
timeout_ms, treat_as_error));
return;
}
@ -445,14 +447,14 @@ void TestHandler::SetTestTimeout(int timeout_ms, bool treat_as_error) {
// Use a weak reference to |this| via UIThreadHelper so that the TestHandler
// can be destroyed before the timeout expires.
GetUIThreadHelper()->PostDelayedTask(
base::Bind(&TestHandler::OnTestTimeout, base::Unretained(this),
timeout_ms, treat_as_error),
base::BindOnce(&TestHandler::OnTestTimeout, base::Unretained(this),
timeout_ms, treat_as_error),
timeout_ms);
}
void TestHandler::TestComplete() {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, base::Bind(&TestHandler::TestComplete, this));
CefPostTask(TID_UI, base::BindOnce(&TestHandler::TestComplete, this));
return;
}

View File

@ -116,12 +116,13 @@ class TestHandler : public CefClient,
// be executed only if TestHandler::DestroyTest has not yet been called.
// For example:
// GetUIThreadHelper()->PostTask(
// base::Bind(&TestHandler::DoSomething, base::Unretained(this)));
void PostTask(const base::Closure& task);
void PostDelayedTask(const base::Closure& task, int delay_ms);
// base::BindOnce(&TestHandler::DoSomething,
// base::Unretained(this)));
void PostTask(base::OnceClosure task);
void PostDelayedTask(base::OnceClosure task, int delay_ms);
private:
void TaskHelper(const base::Closure& task);
void TaskHelper(base::OnceClosure task);
// Must be the last member.
base::WeakPtrFactory<UIThreadHelper> weak_ptr_factory_;

View File

@ -5,6 +5,7 @@
#include "tests/ceftests/test_request.h"
#include <algorithm>
#include <memory>
#include "include/cef_stream.h"
#include "include/cef_urlrequest.h"
@ -22,11 +23,11 @@ class RequestClient : public CefURLRequestClient, public State {
RequestClient(const bool has_credentials,
const std::string& username,
const std::string& password,
const RequestDoneCallback& done_callback)
RequestDoneCallback done_callback)
: has_credentials_(has_credentials),
username_(username),
password_(password),
done_callback_(done_callback) {
done_callback_(std::move(done_callback)) {
DCHECK(!done_callback_.is_null());
}
@ -84,14 +85,14 @@ class RequestClient : public CefURLRequestClient, public State {
DCHECK(response_->IsReadOnly());
}
done_callback_.Run(*this);
std::move(done_callback_).Run(*this);
}
private:
const bool has_credentials_;
const std::string username_;
const std::string password_;
const RequestDoneCallback done_callback_;
RequestDoneCallback done_callback_;
IMPLEMENT_REFCOUNTING(RequestClient);
DISALLOW_COPY_AND_ASSIGN(RequestClient);
@ -100,14 +101,14 @@ class RequestClient : public CefURLRequestClient, public State {
// Implementation that collects all cookies, and optionally deletes them.
class CookieVisitor : public CefCookieVisitor {
public:
CookieVisitor(bool deleteCookies, const CookieDoneCallback& callback)
: delete_cookies_(deleteCookies), callback_(callback) {
CookieVisitor(bool deleteCookies, CookieDoneCallback callback)
: delete_cookies_(deleteCookies), callback_(std::move(callback)) {
DCHECK(!callback_.is_null());
}
~CookieVisitor() override {
CEF_REQUIRE_UI_THREAD();
callback_.Run(cookies_);
std::move(callback_).Run(cookies_);
}
bool Visit(const CefCookie& cookie,
@ -132,10 +133,11 @@ class CookieVisitor : public CefCookieVisitor {
} // namespace
void Send(const SendConfig& config, const RequestDoneCallback& callback) {
void Send(const SendConfig& config, RequestDoneCallback callback) {
DCHECK(config.request_);
CefRefPtr<RequestClient> client = new RequestClient(
config.has_credentials_, config.username_, config.password_, callback);
CefRefPtr<RequestClient> client =
new RequestClient(config.has_credentials_, config.username_,
config.password_, std::move(callback));
if (config.frame_) {
config.frame_->CreateURLRequest(config.request_, client.get());
} else {
@ -181,9 +183,9 @@ CefRefPtr<CefResourceHandler> CreateResourceHandler(
void GetAllCookies(CefRefPtr<CefCookieManager> manager,
bool deleteCookies,
const CookieDoneCallback& callback) {
bool result =
manager->VisitAllCookies(new CookieVisitor(deleteCookies, callback));
CookieDoneCallback callback) {
bool result = manager->VisitAllCookies(
new CookieVisitor(deleteCookies, std::move(callback)));
DCHECK(result);
}
@ -193,9 +195,10 @@ void GetUrlCookies(CefRefPtr<CefCookieManager> manager,
const CefString& url,
bool includeHttpOnly,
bool deleteCookies,
const CookieDoneCallback& callback) {
CookieDoneCallback callback) {
bool result = manager->VisitUrlCookies(
url, includeHttpOnly, new CookieVisitor(deleteCookies, callback));
url, includeHttpOnly,
new CookieVisitor(deleteCookies, std::move(callback)));
DCHECK(result);
}

View File

@ -45,7 +45,7 @@ struct State {
bool response_was_cached_ = false;
};
typedef base::Callback<void(const State& state)> RequestDoneCallback;
using RequestDoneCallback = base::OnceCallback<void(const State& state)>;
struct SendConfig {
// Send using |frame_| or |request_context_| if non-nullptr.
@ -64,7 +64,7 @@ struct SendConfig {
// Send a request. |callback| will be executed on the calling thread after the
// request completes.
void Send(const SendConfig& config, const RequestDoneCallback& callback);
void Send(const SendConfig& config, RequestDoneCallback callback);
// Removes query and/or fragment components from |url|.
std::string GetPathURL(const std::string& url);
@ -74,14 +74,15 @@ CefRefPtr<CefResourceHandler> CreateResourceHandler(
CefRefPtr<CefResponse> response,
const std::string& response_data);
typedef std::vector<CefCookie> CookieVector;
typedef base::Callback<void(const CookieVector& cookies)> CookieDoneCallback;
using CookieVector = std::vector<CefCookie>;
using CookieDoneCallback =
base::OnceCallback<void(const CookieVector& cookies)>;
// Retrieves all cookies from |manager| and executes |callback| upon completion.
// If |deleteCookies| is true the cookies will also be deleted.
void GetAllCookies(CefRefPtr<CefCookieManager> manager,
bool deleteCookies,
const CookieDoneCallback& callback);
CookieDoneCallback callback);
// Retrieves URL cookies from |manager| and executes |callback| upon completion.
// If |deleteCookies| is true the cookies will also be deleted.
@ -89,7 +90,7 @@ void GetUrlCookies(CefRefPtr<CefCookieManager> manager,
const CefString& url,
bool includeHttpOnly,
bool deleteCookies,
const CookieDoneCallback& callback);
CookieDoneCallback callback);
} // namespace test_request

View File

@ -120,17 +120,17 @@ class ServerManager {
g_manager = nullptr;
}
void Start(const StartDoneCallback& callback) {
void Start(StartDoneCallback callback) {
CEF_REQUIRE_UI_THREAD();
if (!origin_.empty()) {
// The server is already running.
callback.Run(origin_);
std::move(callback).Run(origin_);
return;
}
// If tests run in parallel, and the server is starting, then there may be
// multiple pending callbacks.
start_callback_list_.push_back(callback);
start_callback_list_.push_back(std::move(callback));
// Only create the handler a single time.
if (!handler_) {
@ -138,17 +138,17 @@ class ServerManager {
}
}
void Stop(const DoneCallback& callback) {
void Stop(DoneCallback callback) {
CEF_REQUIRE_UI_THREAD();
if (!handler_) {
// The server is not currently running.
callback.Run();
std::move(callback).Run();
return;
}
// Only 1 stop callback supported.
DCHECK(stop_callback_.is_null());
stop_callback_ = callback;
stop_callback_ = std::move(callback);
handler_->Shutdown();
}
@ -178,9 +178,8 @@ class ServerManager {
DCHECK(origin_.empty());
origin_ = server_origin;
StartDoneCallbackList::const_iterator it = start_callback_list_.begin();
for (; it != start_callback_list_.end(); ++it) {
(*it).Run(origin_);
for (auto& callback : start_callback_list_) {
std::move(callback).Run(origin_);
}
start_callback_list_.clear();
}
@ -197,8 +196,7 @@ class ServerManager {
CEF_REQUIRE_UI_THREAD();
DCHECK(!stop_callback_.is_null());
stop_callback_.Run();
stop_callback_.Reset();
std::move(stop_callback_).Run();
delete this;
}
@ -279,12 +277,12 @@ class ServerManager {
CefRefPtr<ServerHandler> handler_;
std::string origin_;
typedef std::vector<StartDoneCallback> StartDoneCallbackList;
using StartDoneCallbackList = std::vector<StartDoneCallback>;
StartDoneCallbackList start_callback_list_;
DoneCallback stop_callback_;
typedef std::vector<Observer*> ObserverList;
using ObserverList = std::vector<Observer*>;
ObserverList observer_list_;
DISALLOW_COPY_AND_ASSIGN(ServerManager);
@ -305,8 +303,8 @@ ServerManager* GetOrCreateServerManager() {
// static
void ServerHandler::NotifyServerCreated(const std::string& server_origin) {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI,
base::Bind(ServerHandler::NotifyServerCreated, server_origin));
CefPostTask(TID_UI, base::BindOnce(ServerHandler::NotifyServerCreated,
server_origin));
return;
}
@ -316,7 +314,7 @@ void ServerHandler::NotifyServerCreated(const std::string& server_origin) {
// static
void ServerHandler::NotifyServerDestroyed() {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, base::Bind(ServerHandler::NotifyServerDestroyed));
CefPostTask(TID_UI, base::BindOnce(ServerHandler::NotifyServerDestroyed));
return;
}
@ -326,7 +324,8 @@ void ServerHandler::NotifyServerDestroyed() {
// static
void ServerHandler::NotifyServerHandlerDeleted() {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, base::Bind(ServerHandler::NotifyServerHandlerDeleted));
CefPostTask(TID_UI,
base::BindOnce(ServerHandler::NotifyServerHandlerDeleted));
return;
}
@ -337,8 +336,8 @@ void ServerHandler::NotifyServerHandlerDeleted() {
void ServerHandler::NotifyClientConnected(CefRefPtr<CefServer> server,
int connection_id) {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, base::Bind(ServerHandler::NotifyClientConnected, server,
connection_id));
CefPostTask(TID_UI, base::BindOnce(ServerHandler::NotifyClientConnected,
server, connection_id));
return;
}
@ -349,8 +348,8 @@ void ServerHandler::NotifyClientConnected(CefRefPtr<CefServer> server,
void ServerHandler::NotifyClientDisconnected(CefRefPtr<CefServer> server,
int connection_id) {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, base::Bind(ServerHandler::NotifyClientDisconnected,
server, connection_id));
CefPostTask(TID_UI, base::BindOnce(ServerHandler::NotifyClientDisconnected,
server, connection_id));
return;
}
@ -363,8 +362,8 @@ void ServerHandler::NotifyHttpRequest(CefRefPtr<CefServer> server,
const CefString& client_address,
CefRefPtr<CefRequest> request) {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, base::Bind(ServerHandler::NotifyHttpRequest, server,
connection_id, client_address, request));
CefPostTask(TID_UI, base::BindOnce(ServerHandler::NotifyHttpRequest, server,
connection_id, client_address, request));
return;
}
@ -404,10 +403,10 @@ class ObserverRegistration : public CefRegistration {
};
void InitializeRegistration(CefRefPtr<ObserverRegistration> registration,
const DoneCallback& callback) {
DoneCallback callback) {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI,
base::Bind(InitializeRegistration, registration, callback));
CefPostTask(TID_UI, base::BindOnce(InitializeRegistration, registration,
std::move(callback)));
return;
}
@ -415,27 +414,27 @@ void InitializeRegistration(CefRefPtr<ObserverRegistration> registration,
registration->Initialize();
if (!callback.is_null())
callback.Run();
std::move(callback).Run();
}
} // namespace
void Start(const StartDoneCallback& callback) {
void Start(StartDoneCallback callback) {
DCHECK(!callback.is_null());
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, base::Bind(Start, callback));
CefPostTask(TID_UI, base::BindOnce(Start, std::move(callback)));
return;
}
DCHECK(!g_stopping);
GetOrCreateServerManager()->Start(callback);
GetOrCreateServerManager()->Start(std::move(callback));
}
void Stop(const DoneCallback& callback) {
void Stop(DoneCallback callback) {
DCHECK(!callback.is_null());
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI, base::Bind(Stop, callback));
CefPostTask(TID_UI, base::BindOnce(Stop, std::move(callback)));
return;
}
@ -445,25 +444,24 @@ void Stop(const DoneCallback& callback) {
ServerManager* manager = GetServerManager();
if (manager) {
manager->Stop(callback);
manager->Stop(std::move(callback));
} else {
callback.Run();
std::move(callback).Run();
}
}
CefRefPtr<CefRegistration> AddObserver(Observer* observer,
const DoneCallback& callback) {
DoneCallback callback) {
DCHECK(observer);
CefRefPtr<ObserverRegistration> registration =
new ObserverRegistration(observer);
InitializeRegistration(registration, callback);
InitializeRegistration(registration, std::move(callback));
return registration.get();
}
CefRefPtr<CefRegistration> AddObserverAndStart(
Observer* observer,
const StartDoneCallback& callback) {
return AddObserver(observer, base::Bind(Start, callback));
CefRefPtr<CefRegistration> AddObserverAndStart(Observer* observer,
StartDoneCallback callback) {
return AddObserver(observer, base::BindOnce(Start, std::move(callback)));
}
void SendResponse(CefRefPtr<CefServer> server,
@ -501,9 +499,9 @@ void ObserverHelper::Initialize() {
CEF_REQUIRE_UI_THREAD();
DCHECK(state_ == State::NONE);
state_ = State::INITIALIZING;
registration_ = AddObserverAndStart(
this,
base::Bind(&ObserverHelper::OnStartDone, weak_ptr_factory_.GetWeakPtr()));
registration_ =
AddObserverAndStart(this, base::BindOnce(&ObserverHelper::OnStartDone,
weak_ptr_factory_.GetWeakPtr()));
}
void ObserverHelper::Shutdown() {

View File

@ -21,19 +21,19 @@ extern const uint16 kServerPort;
extern const char kServerScheme[];
extern const char kServerOrigin[];
typedef base::Closure DoneCallback;
using DoneCallback = base::OnceClosure;
typedef base::Callback<void(const std::string& server_origin)>
StartDoneCallback;
using StartDoneCallback =
base::OnceCallback<void(const std::string& server_origin)>;
// Starts the server if it is not currently running, and executes |callback| on
// the UI thread. This method should be called by each test case that relies on
// the server.
void Start(const StartDoneCallback& callback);
void Start(StartDoneCallback callback);
// Stops the server if it is currently running, and executes |callback| on the
// UI thread. This method will be called by the test framework on shutdown.
void Stop(const DoneCallback& callback);
void Stop(DoneCallback callback);
// Observer for CefServerHandler callbacks. Methods will be called on the UI
// thread.
@ -70,12 +70,11 @@ class Observer {
// it handled the callback. |callback| will be executed on the UI thread after
// registration is complete.
CefRefPtr<CefRegistration> AddObserver(Observer* observer,
const DoneCallback& callback);
DoneCallback callback);
// Combination of AddObserver() followed by Start().
CefRefPtr<CefRegistration> AddObserverAndStart(
Observer* observer,
const StartDoneCallback& callback);
CefRefPtr<CefRegistration> AddObserverAndStart(Observer* observer,
StartDoneCallback callback);
// Helper for sending a fully qualified response.
void SendResponse(CefRefPtr<CefServer> server,

View File

@ -42,10 +42,10 @@ class TestServerObserver : public test_server::ObserverHelper {
public:
TestServerObserver(TestState* state,
const std::string& path,
const base::Closure& done_callback)
base::OnceClosure done_callback)
: state_(state),
path_(path),
done_callback_(done_callback),
done_callback_(std::move(done_callback)),
weak_ptr_factory_(this) {
DCHECK(state);
DCHECK(!path.empty());
@ -53,7 +53,7 @@ class TestServerObserver : public test_server::ObserverHelper {
Initialize();
}
~TestServerObserver() override { done_callback_.Run(); }
~TestServerObserver() override { std::move(done_callback_).Run(); }
void OnInitialized(const std::string& server_origin) override {
CEF_REQUIRE_UI_THREAD();
@ -73,8 +73,8 @@ class TestServerObserver : public test_server::ObserverHelper {
config.request_ = CefRequest::Create();
config.request_->SetURL(url_);
test_request::Send(config,
base::Bind(&TestServerObserver::OnRequestResponse,
weak_ptr_factory_.GetWeakPtr()));
base::BindOnce(&TestServerObserver::OnRequestResponse,
weak_ptr_factory_.GetWeakPtr()));
}
bool OnClientConnected(CefRefPtr<CefServer> server,
@ -143,8 +143,8 @@ class TestServerObserver : public test_server::ObserverHelper {
EXPECT_STREQ(kResponseData, state.download_data_.c_str());
// Trigger shutdown asynchronously.
CefPostTask(TID_UI, base::Bind(&TestServerObserver::Shutdown,
weak_ptr_factory_.GetWeakPtr()));
CefPostTask(TID_UI, base::BindOnce(&TestServerObserver::Shutdown,
weak_ptr_factory_.GetWeakPtr()));
}
bool OnClientDisconnected(CefRefPtr<CefServer> server,
@ -187,7 +187,7 @@ class TestServerObserver : public test_server::ObserverHelper {
private:
TestState* const state_;
const std::string path_;
const base::Closure done_callback_;
base::OnceClosure done_callback_;
std::string url_;
int connection_id_ = -1;
@ -199,15 +199,15 @@ class TestServerObserver : public test_server::ObserverHelper {
void CreateObserverOnUIThread(TestState* state,
const std::string& path,
const base::Closure& done_callback) {
base::OnceClosure done_callback) {
if (!CefCurrentlyOn(TID_UI)) {
CefPostTask(TID_UI,
base::Bind(CreateObserverOnUIThread, base::Unretained(state),
path, done_callback));
CefPostTask(TID_UI, base::BindOnce(CreateObserverOnUIThread,
base::Unretained(state), path,
std::move(done_callback)));
return;
}
new TestServerObserver(state, path, done_callback);
new TestServerObserver(state, path, std::move(done_callback));
}
void SignalIfDone(CefRefPtr<CefWaitableEvent> event,
@ -226,7 +226,7 @@ TEST(TestServerTest, ObserverHelperSingle) {
TestState state;
CreateObserverOnUIThread(&state, "/TestServerTest.ObserverHelperSingle",
base::Bind(&CefWaitableEvent::Signal, event));
base::BindOnce(&CefWaitableEvent::Signal, event));
event->TimedWait(2000);
EXPECT_TRUE(state.ExpectAll());
@ -240,13 +240,12 @@ TEST(TestServerTest, ObserverHelperMultiple) {
size_t count = 0;
const size_t size = base::size(states);
const base::Closure& done_callback =
base::Bind(SignalIfDone, event, base::Unretained(&count), size);
for (size_t i = 0; i < size; ++i) {
std::stringstream ss;
ss << "/TestServerTest.ObserverHelperMultiple" << i;
CreateObserverOnUIThread(&states[i], ss.str(), done_callback);
auto done_callback =
base::BindOnce(SignalIfDone, event, base::Unretained(&count), size);
CreateObserverOnUIThread(&states[i], ss.str(), std::move(done_callback));
}
event->TimedWait(2000);

View File

@ -4,6 +4,8 @@
#include "tests/ceftests/thread_helper.h"
#include <memory>
#include "include/wrapper/cef_closure_task.h"
void SignalEvent(CefRefPtr<CefWaitableEvent> event) {
@ -13,7 +15,7 @@ void SignalEvent(CefRefPtr<CefWaitableEvent> event) {
void WaitForThread(CefThreadId thread_id, int64 delay_ms) {
CefRefPtr<CefWaitableEvent> event =
CefWaitableEvent::CreateWaitableEvent(true, false);
CefPostDelayedTask(thread_id, base::Bind(SignalEvent, event), delay_ms);
CefPostDelayedTask(thread_id, base::BindOnce(SignalEvent, event), delay_ms);
event->Wait();
}
@ -21,32 +23,32 @@ void WaitForThread(CefRefPtr<CefTaskRunner> task_runner, int64 delay_ms) {
CefRefPtr<CefWaitableEvent> event =
CefWaitableEvent::CreateWaitableEvent(true, false);
task_runner->PostDelayedTask(
CefCreateClosureTask(base::Bind(SignalEvent, event)), delay_ms);
CefCreateClosureTask(base::BindOnce(SignalEvent, event)), delay_ms);
event->Wait();
}
void RunOnThread(CefThreadId thread_id,
const base::Callback<void(void)>& test_impl,
base::OnceClosure test_impl,
CefRefPtr<CefWaitableEvent> event) {
if (!CefCurrentlyOn(thread_id)) {
CefPostTask(thread_id,
base::Bind(RunOnThread, thread_id, test_impl, event));
CefPostTask(thread_id, base::BindOnce(RunOnThread, thread_id,
std::move(test_impl), event));
return;
}
test_impl.Run();
std::move(test_impl).Run();
SignalEvent(event);
}
void RunOnThreadAsync(
CefThreadId thread_id,
const base::Callback<void(CefRefPtr<CefWaitableEvent>)>& test_impl,
base::OnceCallback<void(CefRefPtr<CefWaitableEvent>)> test_impl,
CefRefPtr<CefWaitableEvent> event) {
if (!CefCurrentlyOn(thread_id)) {
CefPostTask(thread_id,
base::Bind(RunOnThreadAsync, thread_id, test_impl, event));
CefPostTask(thread_id, base::BindOnce(RunOnThreadAsync, thread_id,
std::move(test_impl), event));
return;
}
test_impl.Run(event);
std::move(test_impl).Run(event);
}

View File

@ -35,15 +35,15 @@ void WaitForThread(CefRefPtr<CefTaskRunner> task_runner, int64 delay_ms = 0);
// Executes |test_impl| on the specified |thread_id|. |event| will be signaled
// once execution is complete.
void RunOnThread(CefThreadId thread_id,
const base::Callback<void(void)>& test_impl,
base::OnceClosure test_impl,
CefRefPtr<CefWaitableEvent> event);
#define NAMED_THREAD_TEST(thread_id, test_case_name, test_name) \
TEST(test_case_name, test_name) { \
CefRefPtr<CefWaitableEvent> event = \
CefWaitableEvent::CreateWaitableEvent(true, false); \
RunOnThread(thread_id, base::Bind(test_name##Impl), event); \
event->Wait(); \
#define NAMED_THREAD_TEST(thread_id, test_case_name, test_name) \
TEST(test_case_name, test_name) { \
CefRefPtr<CefWaitableEvent> event = \
CefWaitableEvent::CreateWaitableEvent(true, false); \
RunOnThread(thread_id, base::BindOnce(test_name##Impl), event); \
event->Wait(); \
}
// Execute "test_case_name.test_name" test on the named thread. The test
@ -54,15 +54,15 @@ void RunOnThread(CefThreadId thread_id,
// Like RunOnThread() but |test_impl| is responsible for signaling |event|.
void RunOnThreadAsync(
CefThreadId thread_id,
const base::Callback<void(CefRefPtr<CefWaitableEvent>)>& test_impl,
base::OnceCallback<void(CefRefPtr<CefWaitableEvent>)> test_impl,
CefRefPtr<CefWaitableEvent>);
#define NAMED_THREAD_TEST_ASYNC(thread_id, test_case_name, test_name) \
TEST(test_case_name, test_name) { \
CefRefPtr<CefWaitableEvent> event = \
CefWaitableEvent::CreateWaitableEvent(true, false); \
RunOnThreadAsync(thread_id, base::Bind(test_name##Impl), event); \
event->Wait(); \
#define NAMED_THREAD_TEST_ASYNC(thread_id, test_case_name, test_name) \
TEST(test_case_name, test_name) { \
CefRefPtr<CefWaitableEvent> event = \
CefWaitableEvent::CreateWaitableEvent(true, false); \
RunOnThreadAsync(thread_id, base::BindOnce(test_name##Impl), event); \
event->Wait(); \
}
// Execute "test_case_name.test_name" test on the named thread. The test

View File

@ -3,6 +3,7 @@
// can be found in the LICENSE file.
#include "include/base/cef_callback.h"
#include "include/base/cef_callback_helpers.h"
#include "include/cef_task.h"
#include "include/cef_thread.h"
#include "include/wrapper/cef_closure_task.h"
@ -60,13 +61,13 @@ class ThreadTest : public base::RefCountedThreadSafe<ThreadTest> {
// Execute |test_task| on the test thread. After execution |callback| will be
// posted to |callback_task_runner|.
void PostOnTestThreadAndCallback(
const base::Closure& test_task,
base::OnceClosure test_task,
CefRefPtr<CefTaskRunner> callback_task_runner,
const base::Closure& callback) {
base::OnceClosure callback) {
EXPECT_TRUE(thread_.get());
thread_task_runner_->PostTask(CefCreateClosureTask(
base::Bind(&ThreadTest::ExecuteOnTestThread, this, test_task,
callback_task_runner, callback)));
thread_task_runner_->PostTask(CefCreateClosureTask(base::BindOnce(
&ThreadTest::ExecuteOnTestThread, this, std::move(test_task),
callback_task_runner, std::move(callback))));
}
CefRefPtr<CefTaskRunner> owner_task_runner() const {
@ -94,14 +95,14 @@ class ThreadTest : public base::RefCountedThreadSafe<ThreadTest> {
private:
// Helper for PostOnTestThreadAndCallback().
void ExecuteOnTestThread(const base::Closure& test_task,
void ExecuteOnTestThread(base::OnceClosure test_task,
CefRefPtr<CefTaskRunner> callback_task_runner,
const base::Closure& callback) {
base::OnceClosure callback) {
AssertTestThread();
test_task.Run();
std::move(test_task).Run();
callback_task_runner->PostTask(CefCreateClosureTask(callback));
callback_task_runner->PostTask(CefCreateClosureTask(std::move(callback)));
}
CefRefPtr<CefTaskRunner> owner_task_runner_;
@ -130,11 +131,11 @@ namespace {
class SimpleThreadTest : public ThreadTest {
public:
SimpleThreadTest(size_t expected_task_count,
const base::Closure& task_callback,
const base::Closure& done_callback)
base::OnceClosure task_callback,
base::OnceClosure done_callback)
: expected_task_count_(expected_task_count),
task_callback_(task_callback),
done_callback_(done_callback),
task_callback_(std::move(task_callback)),
done_callback_(std::move(done_callback)),
got_task_count_(0U),
got_done_count_(0U) {}
@ -144,9 +145,9 @@ class SimpleThreadTest : public ThreadTest {
for (size_t i = 0U; i < expected_task_count_; ++i) {
// Execute Task() on the test thread and then call Done() on this thread.
PostOnTestThreadAndCallback(base::Bind(&SimpleThreadTest::Task, this),
owner_task_runner(),
base::Bind(&SimpleThreadTest::Done, this));
PostOnTestThreadAndCallback(
base::BindOnce(&SimpleThreadTest::Task, this), owner_task_runner(),
base::BindOnce(&SimpleThreadTest::Done, this));
}
}
@ -163,18 +164,18 @@ class SimpleThreadTest : public ThreadTest {
AssertTestThread();
got_task_count_++;
if (!task_callback_.is_null())
task_callback_.Run();
std::move(task_callback_).Run();
}
void Done() {
AssertOwnerThread();
if (++got_done_count_ == expected_task_count_ && !done_callback_.is_null())
done_callback_.Run();
std::move(done_callback_).Run();
}
const size_t expected_task_count_;
base::Closure task_callback_;
base::Closure done_callback_;
base::OnceClosure task_callback_;
base::OnceClosure done_callback_;
size_t got_task_count_;
size_t got_done_count_;
@ -207,23 +208,23 @@ class BrowserThreadTestHandler : public TestHandler {
// Run the test on the desired owner thread.
CefPostTask(
owner_thread_id_,
base::Bind(&BrowserThreadTestHandler::RunThreadTestOnOwnerThread,
this));
base::BindOnce(&BrowserThreadTestHandler::RunThreadTestOnOwnerThread,
this));
return;
}
EXPECT_FALSE(thread_test_.get());
thread_test_ = new SimpleThreadTest(
3, base::Closure(),
base::Bind(&BrowserThreadTestHandler::DoneOnOwnerThread, this));
3, base::DoNothing(),
base::BindOnce(&BrowserThreadTestHandler::DoneOnOwnerThread, this));
thread_test_->RunTest();
}
void DoneOnOwnerThread() {
// Let the call stack unwind before destroying |thread_test_|.
CefPostTask(
owner_thread_id_,
base::Bind(&BrowserThreadTestHandler::DestroyTestOnOwnerThread, this));
CefPostTask(owner_thread_id_,
base::BindOnce(
&BrowserThreadTestHandler::DestroyTestOnOwnerThread, this));
}
void DestroyTestOnOwnerThread() {
@ -239,7 +240,7 @@ class BrowserThreadTestHandler : public TestHandler {
// Call DestroyTest() on the UI thread.
CefPostTask(TID_UI,
base::Bind(&BrowserThreadTestHandler::DestroyTest, this));
base::BindOnce(&BrowserThreadTestHandler::DestroyTest, this));
}
void OnLoadingStateChange(CefRefPtr<CefBrowser> browser,
@ -381,8 +382,8 @@ class RenderThreadRendererTest : public ClientAppRenderer::Delegate {
browser_ = browser;
EXPECT_FALSE(thread_test_.get());
thread_test_ = new SimpleThreadTest(
3, base::Closure(),
base::Bind(&RenderThreadRendererTest::Done, this));
3, base::DoNothing(),
base::BindOnce(&RenderThreadRendererTest::Done, this));
thread_test_->RunTest();
return true;
}
@ -395,7 +396,7 @@ class RenderThreadRendererTest : public ClientAppRenderer::Delegate {
void Done() {
// Let the call stack unwind before destroying |thread_test_|.
CefPostTask(TID_RENDERER,
base::Bind(&RenderThreadRendererTest::DestroyTest, this));
base::BindOnce(&RenderThreadRendererTest::DestroyTest, this));
}
void DestroyTest() {

View File

@ -80,7 +80,8 @@ class TracingTestHandler : public CefEndTracingCallback,
void ExecuteTest() {
// Run the test.
CefPostTask(TID_UI, base::Bind(&TracingTestHandler::BeginTracing, this));
CefPostTask(TID_UI,
base::BindOnce(&TracingTestHandler::BeginTracing, this));
// Wait for the test to complete.
completion_event_->Wait();
@ -102,8 +103,8 @@ class TracingTestHandler : public CefEndTracingCallback,
EXPECT_UI_THREAD();
// Add some delay to avoid timing-related test failures.
CefPostDelayedTask(TID_UI,
base::Bind(&TracingTestHandler::TestTracing, this), 50);
CefPostDelayedTask(
TID_UI, base::BindOnce(&TracingTestHandler::TestTracing, this), 50);
}
void TestTracing() {
@ -343,9 +344,9 @@ class TracingTestHandler : public CefEndTracingCallback,
void OnEndTracingComplete(const CefString& tracing_file) override {
EXPECT_UI_THREAD();
CefPostTask(
TID_FILE_USER_VISIBLE,
base::Bind(&TracingTestHandler::ReadTracingFile, this, tracing_file));
CefPostTask(TID_FILE_USER_VISIBLE,
base::BindOnce(&TracingTestHandler::ReadTracingFile, this,
tracing_file));
}
void ReadTracingFile(const std::string& file_path) {

File diff suppressed because it is too large Load Diff

View File

@ -2580,10 +2580,10 @@ class V8RendererTest : public ClientAppRenderer::Delegate,
CefRefPtr<CefV8Value>& retval,
CefString& exception) override {
if (name == "notify_test_done") {
CefPostDelayedTask(
TID_RENDERER,
base::Bind(&V8RendererTest::DestroyTest, renderer_test_.get()),
1000);
CefPostDelayedTask(TID_RENDERER,
base::BindOnce(&V8RendererTest::DestroyTest,
renderer_test_.get()),
1000);
return true;
}
@ -2685,7 +2685,7 @@ class V8RendererTest : public ClientAppRenderer::Delegate,
const std::string& message_name = message->GetName();
if (message_name == kV8RunTestMsg) {
// Run the test asynchronously.
CefPostTask(TID_RENDERER, base::Bind(&V8RendererTest::RunTest, this));
CefPostTask(TID_RENDERER, base::BindOnce(&V8RendererTest::RunTest, this));
return true;
}
return false;
@ -2736,8 +2736,8 @@ class V8RendererTest : public ClientAppRenderer::Delegate,
// is no longer possible.
CefPostDelayedTask(
TID_RENDERER,
base::Bind(&CefFrame::ExecuteJavaScript, frame.get(),
"window.DevToolsLoaded()", frame->GetURL(), 0),
base::BindOnce(&CefFrame::ExecuteJavaScript, frame.get(),
"window.DevToolsLoaded()", frame->GetURL(), 0),
500);
}

View File

@ -217,7 +217,7 @@ void RunLabelButtonClick(bool with_text,
window->Show();
// Wait a bit before trying to click the button.
CefPostDelayedTask(TID_UI, base::Bind(ClickButton, window, kButtonID),
CefPostDelayedTask(TID_UI, base::BindOnce(ClickButton, window, kButtonID),
kClickDelayMS);
}
@ -225,12 +225,12 @@ void LabelButtonClick(CefRefPtr<CefWaitableEvent> event,
bool with_button_frame,
bool with_button_text,
bool with_button_image) {
TestWindowDelegate::Config config;
config.on_window_created =
base::Bind(RunLabelButtonClick, with_button_text, with_button_image);
config.frameless = false;
config.close_window = false;
TestWindowDelegate::RunTest(event, config);
auto config = std::make_unique<TestWindowDelegate::Config>();
config->on_window_created =
base::BindOnce(RunLabelButtonClick, with_button_text, with_button_image);
config->frameless = false;
config->close_window = false;
TestWindowDelegate::RunTest(event, std::move(config));
}
void LabelButtonClickFramedWithTextWithImageFramelessWindowImpl(
@ -393,7 +393,7 @@ class TestMenuButtonDelegate : public CefMenuButtonDelegate,
EXPECT_FALSE(model->SetFontList(4, font));
// Wait a bit before trying to click the menu item.
CefPostDelayedTask(TID_UI, base::Bind(ClickMenuItem, menu_button),
CefPostDelayedTask(TID_UI, base::BindOnce(ClickMenuItem, menu_button),
kClickDelayMS);
menu_button->ShowMenu(model, screen_point, CEF_MENU_ANCHOR_TOPLEFT);
@ -453,7 +453,7 @@ void RunMenuButtonClick(bool with_text,
window->Show();
// Wait a bit before trying to click the button.
CefPostDelayedTask(TID_UI, base::Bind(ClickButton, window, kButtonID),
CefPostDelayedTask(TID_UI, base::BindOnce(ClickButton, window, kButtonID),
kClickDelayMS);
}
@ -461,12 +461,12 @@ void MenuButtonClick(CefRefPtr<CefWaitableEvent> event,
bool with_button_frame,
bool with_button_text,
bool with_button_image) {
TestWindowDelegate::Config config;
config.on_window_created =
base::Bind(RunMenuButtonClick, with_button_text, with_button_image);
config.frameless = false;
config.close_window = false;
TestWindowDelegate::RunTest(event, config);
auto config = std::make_unique<TestWindowDelegate::Config>();
config->on_window_created =
base::BindOnce(RunMenuButtonClick, with_button_text, with_button_image);
config->frameless = false;
config->close_window = false;
TestWindowDelegate::RunTest(event, std::move(config));
}
void MenuButtonClickFramedWithTextWithImageFramelessWindowImpl(
@ -549,7 +549,7 @@ class TestMenuButtonCustomPopupDelegate : public CefMenuButtonDelegate,
popup_window_->Show();
// Wait a bit before trying to click the popup button.
CefPostDelayedTask(TID_UI, base::Bind(ClickMenuItem, menu_button),
CefPostDelayedTask(TID_UI, base::BindOnce(ClickMenuItem, menu_button),
kClickDelayMS);
}
@ -614,17 +614,17 @@ void RunMenuButtonCustomPopupClick(bool can_activate,
window->Show();
// Wait a bit before trying to click the button.
CefPostDelayedTask(TID_UI, base::Bind(ClickButton, window, kButtonID),
CefPostDelayedTask(TID_UI, base::BindOnce(ClickButton, window, kButtonID),
kClickDelayMS);
}
void MenuButtonCustomPopupClick(CefRefPtr<CefWaitableEvent> event,
bool can_activate) {
TestWindowDelegate::Config config;
config.on_window_created =
base::Bind(RunMenuButtonCustomPopupClick, can_activate);
config.close_window = false;
TestWindowDelegate::RunTest(event, config);
auto config = std::make_unique<TestWindowDelegate::Config>();
config->on_window_created =
base::BindOnce(RunMenuButtonCustomPopupClick, can_activate);
config->close_window = false;
TestWindowDelegate::RunTest(event, std::move(config));
}
void MenuButtonCustomPopupActivateImpl(CefRefPtr<CefWaitableEvent> event) {

View File

@ -132,9 +132,10 @@ void RunScrollViewLayout(bool with_delegate, CefRefPtr<CefWindow> window) {
}
void ScrollViewLayout(CefRefPtr<CefWaitableEvent> event, bool with_delegate) {
TestWindowDelegate::Config config;
config.on_window_created = base::Bind(RunScrollViewLayout, with_delegate);
TestWindowDelegate::RunTest(event, config);
auto config = std::make_unique<TestWindowDelegate::Config>();
config->on_window_created =
base::BindOnce(RunScrollViewLayout, with_delegate);
TestWindowDelegate::RunTest(event, std::move(config));
}
void ScrollViewLayoutWithDelegateImpl(CefRefPtr<CefWaitableEvent> event) {

View File

@ -27,10 +27,10 @@ const int TestWindowDelegate::kWSize = 400;
// static
void TestWindowDelegate::RunTest(CefRefPtr<CefWaitableEvent> event,
const Config& config) {
std::unique_ptr<Config> config) {
#if defined(OS_WIN)
RECT rect = {0, 0, config.window_size, config.window_size};
if (!config.frameless) {
RECT rect = {0, 0, config->window_size, config->window_size};
if (!config->frameless) {
// The size value is for the client area. Calculate the whole window size
// based on the default frame window style.
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,
@ -38,11 +38,11 @@ void TestWindowDelegate::RunTest(CefRefPtr<CefWaitableEvent> event,
}
CefSize window_size = CefSize(rect.right - rect.left, rect.bottom - rect.top);
#else
CefSize window_size = CefSize(config.window_size, config.window_size);
CefSize window_size = CefSize(config->window_size, config->window_size);
#endif
CefWindow::CreateTopLevelWindow(
new TestWindowDelegate(event, config, window_size));
new TestWindowDelegate(event, std::move(config), window_size));
}
void TestWindowDelegate::OnWindowCreated(CefRefPtr<CefWindow> window) {
@ -74,15 +74,15 @@ void TestWindowDelegate::OnWindowCreated(CefRefPtr<CefWindow> window) {
// Size will come from GetGetInitialBounds() or GetPreferredSize() on
// initial Window creation.
EXPECT_TRUE(got_get_initial_bounds_);
if (config_.window_origin.IsEmpty())
if (config_->window_origin.IsEmpty())
EXPECT_TRUE(got_get_preferred_size_);
else
EXPECT_FALSE(got_get_preferred_size_);
CefRect client_bounds = window->GetBounds();
if (!config_.window_origin.IsEmpty()) {
EXPECT_EQ(config_.window_origin.x, client_bounds.x);
EXPECT_EQ(config_.window_origin.y, client_bounds.y);
if (!config_->window_origin.IsEmpty()) {
EXPECT_EQ(config_->window_origin.x, client_bounds.x);
EXPECT_EQ(config_->window_origin.y, client_bounds.y);
} else {
// Default origin is the upper-left corner of the display's work area.
auto work_area = display->GetWorkArea();
@ -90,9 +90,9 @@ void TestWindowDelegate::OnWindowCreated(CefRefPtr<CefWindow> window) {
EXPECT_EQ(work_area.y, client_bounds.y);
}
if (config_.frameless) {
EXPECT_EQ(config_.window_size, client_bounds.width);
EXPECT_EQ(config_.window_size, client_bounds.height);
if (config_->frameless) {
EXPECT_EQ(config_->window_size, client_bounds.width);
EXPECT_EQ(config_->window_size, client_bounds.height);
} else {
// Client area bounds calculation might have off-by-one errors on Windows
// due to non-client frame size being calculated internally in pixels and
@ -102,19 +102,20 @@ void TestWindowDelegate::OnWindowCreated(CefRefPtr<CefWindow> window) {
}
// Run the callback.
if (!config_.on_window_created.is_null())
config_.on_window_created.Run(window);
if (!config_->on_window_created.is_null())
std::move(config_->on_window_created).Run(window);
if (config_.close_window) {
if (config_->close_window) {
// Close the window asynchronously.
CefPostTask(TID_UI, base::Bind(&TestWindowDelegate::OnCloseWindow, this));
CefPostTask(TID_UI,
base::BindOnce(&TestWindowDelegate::OnCloseWindow, this));
} else if (!CefCommandLine::GetGlobalCommandLine()->HasSwitch(
"disable-test-timeout")) {
// Timeout the test after a reasonable delay. Use a WeakPtr so that the
// delayed task doesn't keep this object alive.
CefPostDelayedTask(TID_UI,
base::Bind(&TestWindowDelegate::OnTimeoutWindow,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&TestWindowDelegate::OnTimeoutWindow,
weak_ptr_factory_.GetWeakPtr()),
kTestTimeout);
}
}
@ -128,8 +129,8 @@ void TestWindowDelegate::OnWindowDestroyed(CefRefPtr<CefWindow> window) {
EXPECT_FALSE(window->IsDrawn());
// Run the callback.
if (!config_.on_window_destroyed.is_null())
config_.on_window_destroyed.Run(window);
if (!config_->on_window_destroyed.is_null())
std::move(config_->on_window_destroyed).Run(window);
window_ = nullptr;
@ -138,13 +139,13 @@ void TestWindowDelegate::OnWindowDestroyed(CefRefPtr<CefWindow> window) {
}
bool TestWindowDelegate::IsFrameless(CefRefPtr<CefWindow> window) {
return config_.frameless;
return config_->frameless;
}
CefRect TestWindowDelegate::GetInitialBounds(CefRefPtr<CefWindow> window) {
got_get_initial_bounds_ = true;
if (!config_.window_origin.IsEmpty()) {
return CefRect(config_.window_origin.x, config_.window_origin.y,
if (!config_->window_origin.IsEmpty()) {
return CefRect(config_->window_origin.x, config_->window_origin.y,
window_size_.width, window_size_.height);
}
@ -159,30 +160,30 @@ CefSize TestWindowDelegate::GetPreferredSize(CefRefPtr<CefView> view) {
bool TestWindowDelegate::OnAccelerator(CefRefPtr<CefWindow> window,
int command_id) {
if (!config_.on_accelerator.is_null())
return config_.on_accelerator.Run(window_, command_id);
if (!config_->on_accelerator.is_null())
return config_->on_accelerator.Run(window_, command_id);
return false;
}
bool TestWindowDelegate::OnKeyEvent(CefRefPtr<CefWindow> window,
const CefKeyEvent& event) {
if (!config_.on_key_event.is_null())
return config_.on_key_event.Run(window_, event);
if (!config_->on_key_event.is_null())
return config_->on_key_event.Run(window_, event);
return false;
}
TestWindowDelegate::TestWindowDelegate(CefRefPtr<CefWaitableEvent> event,
const Config& config,
std::unique_ptr<Config> config,
const CefSize& window_size)
: event_(event),
config_(config),
config_(std::move(config)),
window_size_(window_size),
weak_ptr_factory_(this) {}
TestWindowDelegate::~TestWindowDelegate() {
// Complete the test (signal the event) asynchronously so objects on the call
// stack have a chance to unwind.
CefPostTask(TID_UI, base::Bind(SignalEvent, event_));
CefPostTask(TID_UI, base::BindOnce(SignalEvent, event_));
}
void TestWindowDelegate::OnCloseWindow() {

View File

@ -2,6 +2,8 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include <memory>
#include "include/base/cef_callback.h"
#include "include/base/cef_weak_ptr.h"
#include "include/cef_waitable_event.h"
@ -14,11 +16,14 @@ class TestWindowDelegate : public CefWindowDelegate {
static const int kWSize;
// Test execution callback.
typedef base::Callback<void(CefRefPtr<CefWindow>)> OnWindowCreatedCallback;
typedef base::Callback<void(CefRefPtr<CefWindow>)> OnWindowDestroyedCallback;
typedef base::Callback<bool(CefRefPtr<CefWindow>, int)> OnAcceleratorCallback;
typedef base::Callback<bool(CefRefPtr<CefWindow>, const CefKeyEvent&)>
OnKeyEventCallback;
using OnWindowCreatedCallback =
base::OnceCallback<void(CefRefPtr<CefWindow>)>;
using OnWindowDestroyedCallback =
base::OnceCallback<void(CefRefPtr<CefWindow>)>;
using OnAcceleratorCallback =
base::RepeatingCallback<bool(CefRefPtr<CefWindow>, int)>;
using OnKeyEventCallback =
base::RepeatingCallback<bool(CefRefPtr<CefWindow>, const CefKeyEvent&)>;
struct Config {
OnWindowCreatedCallback on_window_created;
@ -37,7 +42,8 @@ class TestWindowDelegate : public CefWindowDelegate {
// without a frame. If |close_window| is true the Window will be closed
// immediately after |window_test| returns. Otherwise, the caller is
// responsible for closing the Window passed to |window_test|.
static void RunTest(CefRefPtr<CefWaitableEvent> event, const Config& config);
static void RunTest(CefRefPtr<CefWaitableEvent> event,
std::unique_ptr<Config> config);
// CefWindowDelegate methods:
void OnWindowCreated(CefRefPtr<CefWindow> window) override;
@ -51,7 +57,7 @@ class TestWindowDelegate : public CefWindowDelegate {
private:
TestWindowDelegate(CefRefPtr<CefWaitableEvent> event,
const Config& config,
std::unique_ptr<Config> config,
const CefSize& window_size);
~TestWindowDelegate() override;
@ -59,7 +65,7 @@ class TestWindowDelegate : public CefWindowDelegate {
void OnTimeoutWindow();
CefRefPtr<CefWaitableEvent> event_;
const Config config_;
std::unique_ptr<Config> config_;
const CefSize window_size_;
CefRefPtr<CefWindow> window_;

View File

@ -199,8 +199,8 @@ class TestTextfieldDelegate : public CefTextfieldDelegate {
if (event.type == KEYEVENT_RAWKEYDOWN &&
event.windows_key_code == VKEY_RETURN) {
// Got the whole string. Finish the test asynchronously.
CefPostTask(TID_UI, base::Bind(&TestTextfieldDelegate::FinishTest, this,
textfield));
CefPostTask(TID_UI, base::BindOnce(&TestTextfieldDelegate::FinishTest,
this, textfield));
return true;
}
@ -276,10 +276,10 @@ void RunTextfieldKeyEvent(CefRefPtr<CefWindow> window) {
}
void TextfieldKeyEventImpl(CefRefPtr<CefWaitableEvent> event) {
TestWindowDelegate::Config config;
config.on_window_created = base::Bind(RunTextfieldKeyEvent);
config.close_window = false;
TestWindowDelegate::RunTest(event, config);
auto config = std::make_unique<TestWindowDelegate::Config>();
config->on_window_created = base::BindOnce(RunTextfieldKeyEvent);
config->close_window = false;
TestWindowDelegate::RunTest(event, std::move(config));
}
} // namespace

View File

@ -37,14 +37,14 @@ void ExpectCloseRects(const CefRect& expected,
}
void WindowCreateImpl(CefRefPtr<CefWaitableEvent> event) {
TestWindowDelegate::Config config;
TestWindowDelegate::RunTest(event, config);
auto config = std::make_unique<TestWindowDelegate::Config>();
TestWindowDelegate::RunTest(event, std::move(config));
}
void WindowCreateFramelessImpl(CefRefPtr<CefWaitableEvent> event) {
TestWindowDelegate::Config config;
config.frameless = true;
TestWindowDelegate::RunTest(event, config);
auto config = std::make_unique<TestWindowDelegate::Config>();
config->frameless = true;
TestWindowDelegate::RunTest(event, std::move(config));
}
void RunWindowShow(CefRefPtr<CefWindow> window) {
@ -56,10 +56,10 @@ void RunWindowShow(CefRefPtr<CefWindow> window) {
}
void WindowCreateWithOriginImpl(CefRefPtr<CefWaitableEvent> event) {
TestWindowDelegate::Config config;
config.window_origin = {100, 200};
config.on_window_created = base::Bind(RunWindowShow);
TestWindowDelegate::RunTest(event, config);
auto config = std::make_unique<TestWindowDelegate::Config>();
config->window_origin = {100, 200};
config->on_window_created = base::BindOnce(RunWindowShow);
TestWindowDelegate::RunTest(event, std::move(config));
}
void RunWindowShowHide(CefRefPtr<CefWindow> window) {
@ -70,16 +70,16 @@ void RunWindowShowHide(CefRefPtr<CefWindow> window) {
}
void WindowShowHideImpl(CefRefPtr<CefWaitableEvent> event) {
TestWindowDelegate::Config config;
config.on_window_created = base::Bind(RunWindowShowHide);
TestWindowDelegate::RunTest(event, config);
auto config = std::make_unique<TestWindowDelegate::Config>();
config->on_window_created = base::BindOnce(RunWindowShowHide);
TestWindowDelegate::RunTest(event, std::move(config));
}
void WindowShowHideFramelessImpl(CefRefPtr<CefWaitableEvent> event) {
TestWindowDelegate::Config config;
config.on_window_created = base::Bind(RunWindowShowHide);
config.frameless = true;
TestWindowDelegate::RunTest(event, config);
auto config = std::make_unique<TestWindowDelegate::Config>();
config->on_window_created = base::BindOnce(RunWindowShowHide);
config->frameless = true;
TestWindowDelegate::RunTest(event, std::move(config));
}
const int kWPanel1ID = 1;
@ -203,16 +203,16 @@ void RunWindowLayoutAndCoords(CefRefPtr<CefWindow> window) {
}
void WindowLayoutAndCoordsImpl(CefRefPtr<CefWaitableEvent> event) {
TestWindowDelegate::Config config;
config.on_window_created = base::Bind(RunWindowLayoutAndCoords);
TestWindowDelegate::RunTest(event, config);
auto config = std::make_unique<TestWindowDelegate::Config>();
config->on_window_created = base::BindOnce(RunWindowLayoutAndCoords);
TestWindowDelegate::RunTest(event, std::move(config));
}
void WindowLayoutAndCoordsFramelessImpl(CefRefPtr<CefWaitableEvent> event) {
TestWindowDelegate::Config config;
config.on_window_created = base::Bind(RunWindowLayoutAndCoords);
config.frameless = true;
TestWindowDelegate::RunTest(event, config);
auto config = std::make_unique<TestWindowDelegate::Config>();
config->on_window_created = base::BindOnce(RunWindowLayoutAndCoords);
config->frameless = true;
TestWindowDelegate::RunTest(event, std::move(config));
}
void VerifyRestore(CefRefPtr<CefWindow> window) {
@ -234,7 +234,8 @@ void VerifyMaximize(CefRefPtr<CefWindow> window) {
EXPECT_TRUE(window->IsDrawn());
window->Restore();
CefPostDelayedTask(TID_UI, base::Bind(VerifyRestore, window), kStateDelayMS);
CefPostDelayedTask(TID_UI, base::BindOnce(VerifyRestore, window),
kStateDelayMS);
}
void RunWindowMaximize(CefRefPtr<CefWindow> window) {
@ -247,22 +248,23 @@ void RunWindowMaximize(CefRefPtr<CefWindow> window) {
EXPECT_TRUE(window->IsDrawn());
window->Maximize();
CefPostDelayedTask(TID_UI, base::Bind(VerifyMaximize, window), kStateDelayMS);
CefPostDelayedTask(TID_UI, base::BindOnce(VerifyMaximize, window),
kStateDelayMS);
}
void WindowMaximizeImpl(CefRefPtr<CefWaitableEvent> event) {
TestWindowDelegate::Config config;
config.on_window_created = base::Bind(RunWindowMaximize);
config.close_window = false;
TestWindowDelegate::RunTest(event, config);
auto config = std::make_unique<TestWindowDelegate::Config>();
config->on_window_created = base::BindOnce(RunWindowMaximize);
config->close_window = false;
TestWindowDelegate::RunTest(event, std::move(config));
}
void WindowMaximizeFramelessImpl(CefRefPtr<CefWaitableEvent> event) {
TestWindowDelegate::Config config;
config.on_window_created = base::Bind(RunWindowMaximize);
config.frameless = true;
config.close_window = false;
TestWindowDelegate::RunTest(event, config);
auto config = std::make_unique<TestWindowDelegate::Config>();
config->on_window_created = base::BindOnce(RunWindowMaximize);
config->frameless = true;
config->close_window = false;
TestWindowDelegate::RunTest(event, std::move(config));
}
void VerifyMinimize(CefRefPtr<CefWindow> window) {
@ -276,7 +278,8 @@ void VerifyMinimize(CefRefPtr<CefWindow> window) {
EXPECT_TRUE(window->IsDrawn());
window->Restore();
CefPostDelayedTask(TID_UI, base::Bind(VerifyRestore, window), kStateDelayMS);
CefPostDelayedTask(TID_UI, base::BindOnce(VerifyRestore, window),
kStateDelayMS);
}
void RunWindowMinimize(CefRefPtr<CefWindow> window) {
@ -289,22 +292,23 @@ void RunWindowMinimize(CefRefPtr<CefWindow> window) {
EXPECT_TRUE(window->IsDrawn());
window->Minimize();
CefPostDelayedTask(TID_UI, base::Bind(VerifyMinimize, window), kStateDelayMS);
CefPostDelayedTask(TID_UI, base::BindOnce(VerifyMinimize, window),
kStateDelayMS);
}
void WindowMinimizeImpl(CefRefPtr<CefWaitableEvent> event) {
TestWindowDelegate::Config config;
config.on_window_created = base::Bind(RunWindowMinimize);
config.close_window = false;
TestWindowDelegate::RunTest(event, config);
auto config = std::make_unique<TestWindowDelegate::Config>();
config->on_window_created = base::BindOnce(RunWindowMinimize);
config->close_window = false;
TestWindowDelegate::RunTest(event, std::move(config));
}
void WindowMinimizeFramelessImpl(CefRefPtr<CefWaitableEvent> event) {
TestWindowDelegate::Config config;
config.on_window_created = base::Bind(RunWindowMinimize);
config.frameless = true;
config.close_window = false;
TestWindowDelegate::RunTest(event, config);
auto config = std::make_unique<TestWindowDelegate::Config>();
config->on_window_created = base::BindOnce(RunWindowMinimize);
config->frameless = true;
config->close_window = false;
TestWindowDelegate::RunTest(event, std::move(config));
}
void VerifyFullscreenExit(CefRefPtr<CefWindow> window) {
@ -326,7 +330,7 @@ void VerifyFullscreen(CefRefPtr<CefWindow> window) {
EXPECT_TRUE(window->IsDrawn());
window->SetFullscreen(false);
CefPostDelayedTask(TID_UI, base::Bind(VerifyFullscreenExit, window),
CefPostDelayedTask(TID_UI, base::BindOnce(VerifyFullscreenExit, window),
kStateDelayMS);
}
@ -340,23 +344,23 @@ void RunWindowFullscreen(CefRefPtr<CefWindow> window) {
EXPECT_TRUE(window->IsDrawn());
window->SetFullscreen(true);
CefPostDelayedTask(TID_UI, base::Bind(VerifyFullscreen, window),
CefPostDelayedTask(TID_UI, base::BindOnce(VerifyFullscreen, window),
kStateDelayMS);
}
void WindowFullscreenImpl(CefRefPtr<CefWaitableEvent> event) {
TestWindowDelegate::Config config;
config.on_window_created = base::Bind(RunWindowFullscreen);
config.close_window = false;
TestWindowDelegate::RunTest(event, config);
auto config = std::make_unique<TestWindowDelegate::Config>();
config->on_window_created = base::BindOnce(RunWindowFullscreen);
config->close_window = false;
TestWindowDelegate::RunTest(event, std::move(config));
}
void WindowFullscreenFramelessImpl(CefRefPtr<CefWaitableEvent> event) {
TestWindowDelegate::Config config;
config.on_window_created = base::Bind(RunWindowFullscreen);
config.frameless = true;
config.close_window = false;
TestWindowDelegate::RunTest(event, config);
auto config = std::make_unique<TestWindowDelegate::Config>();
config->on_window_created = base::BindOnce(RunWindowFullscreen);
config->frameless = true;
config->close_window = false;
TestWindowDelegate::RunTest(event, std::move(config));
}
void RunWindowIcon(CefRefPtr<CefWindow> window) {
@ -376,16 +380,16 @@ void RunWindowIcon(CefRefPtr<CefWindow> window) {
}
void WindowIconImpl(CefRefPtr<CefWaitableEvent> event) {
TestWindowDelegate::Config config;
config.on_window_created = base::Bind(RunWindowIcon);
TestWindowDelegate::RunTest(event, config);
auto config = std::make_unique<TestWindowDelegate::Config>();
config->on_window_created = base::BindOnce(RunWindowIcon);
TestWindowDelegate::RunTest(event, std::move(config));
}
void WindowIconFramelessImpl(CefRefPtr<CefWaitableEvent> event) {
TestWindowDelegate::Config config;
config.on_window_created = base::Bind(RunWindowIcon);
config.frameless = true;
TestWindowDelegate::RunTest(event, config);
auto config = std::make_unique<TestWindowDelegate::Config>();
config->on_window_created = base::BindOnce(RunWindowIcon);
config->frameless = true;
TestWindowDelegate::RunTest(event, std::move(config));
}
const int kChar = 'A';
@ -456,7 +460,7 @@ void RunWindowAccelerator(CefRefPtr<CefWindow> window) {
window->SetAccelerator(kCloseWindowId, kChar, false, false, true);
window->Show();
CefPostDelayedTask(TID_UI, base::Bind(TriggerAccelerator, window),
CefPostDelayedTask(TID_UI, base::BindOnce(TriggerAccelerator, window),
kStateDelayMS);
}
@ -476,13 +480,13 @@ void WindowAcceleratorImpl(CefRefPtr<CefWaitableEvent> event) {
got_key_event_alt_count = 0;
got_key_event_char = false;
TestWindowDelegate::Config config;
config.on_window_created = base::Bind(RunWindowAccelerator);
config.on_window_destroyed = base::Bind(VerifyWindowAccelerator);
config.on_accelerator = base::Bind(OnAccelerator);
config.on_key_event = base::Bind(OnKeyEvent);
config.close_window = false;
TestWindowDelegate::RunTest(event, config);
auto config = std::make_unique<TestWindowDelegate::Config>();
config->on_window_created = base::BindOnce(RunWindowAccelerator);
config->on_window_destroyed = base::BindOnce(VerifyWindowAccelerator);
config->on_accelerator = base::BindRepeating(OnAccelerator);
config->on_key_event = base::BindRepeating(OnKeyEvent);
config->close_window = false;
TestWindowDelegate::RunTest(event, std::move(config));
}
} // namespace

View File

@ -68,7 +68,7 @@ TEST(WaitableEventTest, WaitAndDelete) {
CefRefPtr<CefThread> thread = CefThread::CreateThread("waitable_event_test");
thread->GetTaskRunner()->PostDelayedTask(
CefCreateClosureTask(
base::Bind(SignalEvent, base::Unretained(event.get()))),
base::BindOnce(SignalEvent, base::Unretained(event.get()))),
10);
event->Wait();

View File

@ -2,6 +2,8 @@
// reserved. Use of this source code is governed by a BSD-style license that
// can be found in the LICENSE file.
#include <memory>
#include "include/base/cef_callback.h"
#include "include/cef_callback.h"
#include "include/cef_parser.h"
@ -37,18 +39,18 @@ class WebUITestHandler : public TestHandler {
}
void NextNav() {
base::Closure next_action;
base::OnceClosure next_action;
if (++url_index_ < url_list_.size()) {
next_action =
base::Bind(&WebUITestHandler::LoadURL, this, url_list_[url_index_]);
next_action = base::BindOnce(&WebUITestHandler::LoadURL, this,
url_list_[url_index_]);
} else {
next_action = base::Bind(&WebUITestHandler::DestroyTest, this);
next_action = base::BindOnce(&WebUITestHandler::DestroyTest, this);
}
// Wait a bit for the WebUI content to finish loading before performing the
// next action.
CefPostDelayedTask(TID_UI, next_action, 200);
CefPostDelayedTask(TID_UI, std::move(next_action), 200);
}
void LoadURL(const std::string& url) {

View File

@ -4,6 +4,8 @@
#include "tests/shared/browser/extension_util.h"
#include <memory>
#include "include/base/cef_callback.h"
#include "include/base/cef_cxx17_backports.h"
#include "include/cef_parser.h"
@ -55,26 +57,27 @@ std::string GetInternalPath(const std::string& extension_path) {
return internal_path;
}
typedef base::Callback<void(CefRefPtr<CefDictionaryValue> /*manifest*/)>
ManifestCallback;
using ManifestCallback =
base::OnceCallback<void(CefRefPtr<CefDictionaryValue> /*manifest*/)>;
void RunManifestCallback(const ManifestCallback& callback,
void RunManifestCallback(ManifestCallback callback,
CefRefPtr<CefDictionaryValue> manifest) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute on the browser UI thread.
CefPostTask(TID_UI, base::Bind(RunManifestCallback, callback, manifest));
CefPostTask(TID_UI, base::BindOnce(std::move(callback), manifest));
return;
}
callback.Run(manifest);
std::move(callback).Run(manifest);
}
// Asynchronously reads the manifest and executes |callback| on the UI thread.
void GetInternalManifest(const std::string& extension_path,
const ManifestCallback& callback) {
ManifestCallback callback) {
if (!CefCurrentlyOn(TID_FILE_USER_BLOCKING)) {
// Execute on the browser FILE thread.
CefPostTask(TID_FILE_USER_BLOCKING,
base::Bind(GetInternalManifest, extension_path, callback));
base::BindOnce(GetInternalManifest, extension_path,
std::move(callback)));
return;
}
@ -84,7 +87,7 @@ void GetInternalManifest(const std::string& extension_path,
if (!LoadBinaryResource(manifest_path.c_str(), manifest_contents) ||
manifest_contents.empty()) {
LOG(ERROR) << "Failed to load manifest from " << manifest_path;
RunManifestCallback(callback, nullptr);
RunManifestCallback(std::move(callback), nullptr);
return;
}
@ -96,11 +99,11 @@ void GetInternalManifest(const std::string& extension_path,
error_msg = "Incorrectly formatted dictionary contents.";
LOG(ERROR) << "Failed to parse manifest from " << manifest_path << "; "
<< error_msg.ToString();
RunManifestCallback(callback, nullptr);
RunManifestCallback(std::move(callback), nullptr);
return;
}
RunManifestCallback(callback, value->GetDictionary());
RunManifestCallback(std::move(callback), value->GetDictionary());
}
void LoadExtensionWithManifest(CefRefPtr<CefRequestContext> request_context,
@ -166,16 +169,17 @@ void LoadExtension(CefRefPtr<CefRequestContext> request_context,
CefRefPtr<CefExtensionHandler> handler) {
if (!CefCurrentlyOn(TID_UI)) {
// Execute on the browser UI thread.
CefPostTask(TID_UI, base::Bind(LoadExtension, request_context,
extension_path, handler));
CefPostTask(TID_UI, base::BindOnce(LoadExtension, request_context,
extension_path, handler));
return;
}
if (IsInternalExtension(extension_path)) {
// Read the extension manifest and load asynchronously.
GetInternalManifest(extension_path,
base::Bind(LoadExtensionWithManifest, request_context,
extension_path, handler));
GetInternalManifest(
extension_path,
base::BindOnce(LoadExtensionWithManifest, request_context,
extension_path, handler));
} else {
// Load the extension from disk.
request_context->LoadExtension(extension_path, nullptr, handler);
@ -189,8 +193,8 @@ void AddInternalExtensionToResourceManager(
if (!CefCurrentlyOn(TID_IO)) {
// Execute on the browser IO thread.
CefPostTask(TID_IO, base::Bind(AddInternalExtensionToResourceManager,
extension, resource_manager));
CefPostTask(TID_IO, base::BindOnce(AddInternalExtensionToResourceManager,
extension, resource_manager));
return;
}

View File

@ -30,7 +30,11 @@ MainMessageLoop* MainMessageLoop::Get() {
return g_main_message_loop;
}
void MainMessageLoop::PostClosure(const base::Closure& closure) {
void MainMessageLoop::PostClosure(base::OnceClosure closure) {
PostTask(CefCreateClosureTask(std::move(closure)));
}
void MainMessageLoop::PostClosure(const base::RepeatingClosure& closure) {
PostTask(CefCreateClosureTask(closure));
}

View File

@ -48,7 +48,8 @@ class MainMessageLoop {
#endif
// Post a closure for execution on the main message loop.
void PostClosure(const base::Closure& closure);
void PostClosure(base::OnceClosure closure);
void PostClosure(const base::RepeatingClosure& closure);
protected:
// Only allow deletion via std::unique_ptr.
@ -97,8 +98,8 @@ struct DeleteOnMainThread {
if (CURRENTLY_ON_MAIN_THREAD()) {
delete x;
} else {
client::MainMessageLoop::Get()->PostClosure(
base::Bind(&DeleteOnMainThread::Destruct<T>, base::Unretained(x)));
client::MainMessageLoop::Get()->PostClosure(base::BindOnce(
&DeleteOnMainThread::Destruct<T>, base::Unretained(x)));
}
}
};