From 529b91bc6e964c7de591eec8154d455866dd7385 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Sat, 19 Jun 2021 15:54:45 -0400 Subject: [PATCH] tests: Convert usage of base::Bind to Once or Repeating (see issue #3140) --- tests/cefclient/browser/client_handler.cc | 58 +- tests/cefclient/browser/client_handler_osr.cc | 3 +- tests/cefclient/browser/dialog_handler_gtk.cc | 22 +- tests/cefclient/browser/dialog_handler_gtk.h | 2 +- tests/cefclient/browser/image_cache.cc | 22 +- tests/cefclient/browser/image_cache.h | 20 +- .../main_message_loop_multithreaded_gtk.cc | 2 +- .../main_message_loop_multithreaded_win.cc | 2 +- tests/cefclient/browser/media_router_test.cc | 20 +- .../browser/osr_render_handler_win.cc | 4 +- tests/cefclient/browser/osr_window_win.cc | 24 +- tests/cefclient/browser/print_handler_gtk.cc | 24 +- tests/cefclient/browser/root_window.cc | 4 +- tests/cefclient/browser/root_window.h | 7 +- tests/cefclient/browser/root_window_gtk.cc | 47 +- tests/cefclient/browser/root_window_gtk.h | 2 +- tests/cefclient/browser/root_window_mac.h | 2 +- tests/cefclient/browser/root_window_mac.mm | 24 +- .../cefclient/browser/root_window_manager.cc | 46 +- tests/cefclient/browser/root_window_manager.h | 7 +- tests/cefclient/browser/root_window_views.cc | 131 ++-- tests/cefclient/browser/root_window_views.h | 21 +- tests/cefclient/browser/root_window_win.cc | 26 +- tests/cefclient/browser/root_window_win.h | 2 +- tests/cefclient/browser/server_test.cc | 28 +- tests/cefclient/browser/test_runner.cc | 29 +- tests/cefclient/browser/urlrequest_test.cc | 18 +- tests/cefclient/browser/views_window.cc | 10 +- tests/cefclient/browser/views_window.h | 2 +- .../browser/window_test_runner_gtk.cc | 8 +- .../browser/window_test_runner_win.cc | 8 +- tests/cefclient/cefclient_gtk.cc | 12 +- tests/cefclient/cefclient_mac.mm | 8 +- tests/cefclient/cefclient_win.cc | 12 +- tests/cefsimple/simple_handler.cc | 4 +- tests/ceftests/cookie_unittest.cc | 198 +++--- tests/ceftests/cors_unittest.cc | 36 +- tests/ceftests/devtools_message_unittest.cc | 25 +- tests/ceftests/dialog_unittest.cc | 4 +- tests/ceftests/display_unittest.cc | 2 +- tests/ceftests/download_unittest.cc | 67 ++- tests/ceftests/draggable_regions_unittest.cc | 4 +- .../extensions/background_unittest.cc | 8 +- .../extensions/chrome_alarms_unittest.cc | 6 +- .../extensions/chrome_storage_unittest.cc | 6 +- .../extensions/chrome_tabs_unittest.cc | 6 +- tests/ceftests/extensions/view_unittest.cc | 7 +- tests/ceftests/frame_unittest.cc | 26 +- tests/ceftests/jsdialog_unittest.cc | 8 +- tests/ceftests/life_span_unittest.cc | 4 +- tests/ceftests/message_router_unittest.cc | 15 +- tests/ceftests/navigation_unittest.cc | 8 +- tests/ceftests/os_rendering_unittest.cc | 5 +- tests/ceftests/osr_accessibility_unittest.cc | 28 +- tests/ceftests/osr_display_unittest.cc | 22 +- tests/ceftests/plugin_unittest.cc | 8 +- tests/ceftests/preference_unittest.cc | 7 +- tests/ceftests/process_message_unittest.cc | 5 +- tests/ceftests/request_context_unittest.cc | 8 +- tests/ceftests/request_handler_unittest.cc | 4 +- tests/ceftests/request_unittest.cc | 2 +- tests/ceftests/resource_manager_unittest.cc | 89 +-- .../resource_request_handler_unittest.cc | 84 +-- tests/ceftests/run_all_unittests.cc | 8 +- tests/ceftests/scheme_handler_unittest.cc | 26 +- tests/ceftests/server_unittest.cc | 77 ++- tests/ceftests/test_handler.cc | 44 +- tests/ceftests/test_handler.h | 9 +- tests/ceftests/test_request.cc | 33 +- tests/ceftests/test_request.h | 13 +- tests/ceftests/test_server.cc | 84 ++- tests/ceftests/test_server.h | 17 +- tests/ceftests/test_server_unittest.cc | 35 +- tests/ceftests/thread_helper.cc | 22 +- tests/ceftests/thread_helper.h | 28 +- tests/ceftests/thread_unittest.cc | 63 +- tests/ceftests/tracing_unittest.cc | 13 +- tests/ceftests/urlrequest_unittest.cc | 566 +++++++++--------- tests/ceftests/v8_unittest.cc | 14 +- tests/ceftests/views/button_unittest.cc | 44 +- tests/ceftests/views/scroll_view_unittest.cc | 7 +- tests/ceftests/views/test_window_delegate.cc | 61 +- tests/ceftests/views/test_window_delegate.h | 22 +- tests/ceftests/views/textfield_unittest.cc | 12 +- tests/ceftests/views/window_unittest.cc | 146 ++--- tests/ceftests/waitable_event_unittest.cc | 2 +- tests/ceftests/webui_unittest.cc | 12 +- tests/shared/browser/extension_util.cc | 38 +- tests/shared/browser/main_message_loop.cc | 6 +- tests/shared/browser/main_message_loop.h | 7 +- 90 files changed, 1430 insertions(+), 1332 deletions(-) diff --git a/tests/cefclient/browser/client_handler.cc b/tests/cefclient/browser/client_handler.cc index 1af059bc1..0827343d1 100644 --- a/tests/cefclient/browser/client_handler.cc +++ b/tests/cefclient/browser/client_handler.cc @@ -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(); + 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 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 browser) { ss << ""; - 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(); + 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 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 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 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 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 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; } diff --git a/tests/cefclient/browser/client_handler_osr.cc b/tests/cefclient/browser/client_handler_osr.cc index bc1e98b66..5b3ac1533 100644 --- a/tests/cefclient/browser/client_handler_osr.cc +++ b/tests/cefclient/browser/client_handler_osr.cc @@ -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; } diff --git a/tests/cefclient/browser/dialog_handler_gtk.cc b/tests/cefclient/browser/dialog_handler_gtk.cc index 81758be71..27f2d5010 100644 --- a/tests/cefclient/browser/dialog_handler_gtk.cc +++ b/tests/cefclient/browser/dialog_handler_gtk.cc @@ -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 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 browser, - base::Callback callback) { + base::OnceCallback 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 diff --git a/tests/cefclient/browser/dialog_handler_gtk.h b/tests/cefclient/browser/dialog_handler_gtk.h index 4c7994200..4cfb0726c 100644 --- a/tests/cefclient/browser/dialog_handler_gtk.h +++ b/tests/cefclient/browser/dialog_handler_gtk.h @@ -65,7 +65,7 @@ class ClientDialogHandlerGtk : public CefDialogHandler, void OnJSDialogContinue(OnJSDialogParams params, GtkWindow* window); void GetWindowAndContinue(CefRefPtr browser, - base::Callback callback); + base::OnceCallback callback); static void OnDialogResponse(GtkDialog* dialog, gint response_id, diff --git a/tests/cefclient/browser/image_cache.cc b/tests/cefclient/browser/image_cache.cc index 446da68da..c72003cd4 100644 --- a/tests/cefclient/browser/image_cache.cc +++ b/tests/cefclient/browser/image_cache.cc @@ -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 diff --git a/tests/cefclient/browser/image_cache.h b/tests/cefclient/browser/image_cache.h index 7d92589ab..421467281 100644 --- a/tests/cefclient/browser/image_cache.h +++ b/tests/cefclient/browser/image_cache.h @@ -33,7 +33,7 @@ class ImageCache // Image scale factor (usually 1.0f or 2.0f). float scale_factor_; }; - typedef std::vector ImageRepSet; + using ImageRepSet = std::vector; // 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 ImageInfoSet; + using ImageInfoSet = std::vector; - typedef std::vector> ImageSet; + using ImageSet = std::vector>; - typedef base::Callback LoadImagesCallback; + using LoadImagesCallback = + base::OnceCallback; // 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 ImageContentSet; + using ImageContentSet = std::vector; // 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 CreateImage(const std::string& image_id, const ImageContent& content); // Map image ID to image representation. Only accessed on the UI thread. - typedef std::map> ImageMap; + using ImageMap = std::map>; ImageMap image_map_; }; diff --git a/tests/cefclient/browser/main_message_loop_multithreaded_gtk.cc b/tests/cefclient/browser/main_message_loop_multithreaded_gtk.cc index 876948e4c..736a106d4 100644 --- a/tests/cefclient/browser/main_message_loop_multithreaded_gtk.cc +++ b/tests/cefclient/browser/main_message_loop_multithreaded_gtk.cc @@ -105,7 +105,7 @@ int MainMessageLoopMultithreadedGtk::Run() { } void MainMessageLoopMultithreadedGtk::Quit() { - PostTask(CefCreateClosureTask(base::Bind( + PostTask(CefCreateClosureTask(base::BindOnce( &MainMessageLoopMultithreadedGtk::DoQuit, base::Unretained(this)))); } diff --git a/tests/cefclient/browser/main_message_loop_multithreaded_win.cc b/tests/cefclient/browser/main_message_loop_multithreaded_win.cc index 2f6b23427..2da484c60 100644 --- a/tests/cefclient/browser/main_message_loop_multithreaded_win.cc +++ b/tests/cefclient/browser/main_message_loop_multithreaded_win.cc @@ -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 task) { diff --git a/tests/cefclient/browser/media_router_test.cc b/tests/cefclient/browser/media_router_test.cc index 9c7144b97..65437227b 100644 --- a/tests/cefclient/browser/media_router_test.cc +++ b/tests/cefclient/browser/media_router_test.cc @@ -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 - CallbackType; + using CallbackType = + base::OnceCallback; - 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 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))); } } diff --git a/tests/cefclient/browser/osr_render_handler_win.cc b/tests/cefclient/browser/osr_render_handler_win.cc index 6c9cb3fca..b81a9021a 100644 --- a/tests/cefclient/browser/osr_render_handler_win.cc +++ b/tests/cefclient/browser/osr_render_handler_win.cc @@ -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_) { diff --git a/tests/cefclient/browser/osr_window_win.cc b/tests/cefclient/browser/osr_window_win.cc index e87d60b74..5f981f93e 100644 --- a/tests/cefclient/browser/osr_window_win.cc +++ b/tests/cefclient/browser/osr_window_win.cc @@ -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 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)); } } diff --git a/tests/cefclient/browser/print_handler_gtk.cc b/tests/cefclient/browser/print_handler_gtk.cc index 0b823f8b5..c6f333559 100644 --- a/tests/cefclient/browser/print_handler_gtk.cc +++ b/tests/cefclient/browser/print_handler_gtk.cc @@ -5,6 +5,7 @@ #include "tests/cefclient/browser/print_handler_gtk.h" +#include #include #include @@ -282,20 +283,17 @@ GtkWindow* GetWindow(CefRefPtr browser) { return nullptr; } -void RunCallback(base::Callback callback, GtkWindow* window) { - callback.Run(window); -} - void GetWindowAndContinue(CefRefPtr browser, - base::Callback callback) { + base::OnceCallback 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 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; } diff --git a/tests/cefclient/browser/root_window.cc b/tests/cefclient/browser/root_window.cc index 45ae80974..5b8468a04 100644 --- a/tests/cefclient/browser/root_window.cc +++ b/tests/cefclient/browser/root_window.cc @@ -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()); } } diff --git a/tests/cefclient/browser/root_window.h b/tests/cefclient/browser/root_window.h index 7ee847dc0..c5d859b3e 100644 --- a/tests/cefclient/browser/root_window.h +++ b/tests/cefclient/browser/root_window.h @@ -6,6 +6,7 @@ #define CEF_TESTS_CEFCLIENT_BROWSER_ROOT_WINDOW_H_ #pragma once +#include #include #include @@ -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 extension, const CefRect& source_bounds, CefRefPtr 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 config, const CefBrowserSettings& settings) = 0; // Initialize as a popup window. This is used to attach a new native window to diff --git a/tests/cefclient/browser/root_window_gtk.cc b/tests/cefclient/browser/root_window_gtk.cc index 1e775da2a..20ae683fc 100644 --- a/tests/cefclient/browser/root_window_gtk.cc +++ b/tests/cefclient/browser/root_window_gtk.cc @@ -108,25 +108,25 @@ RootWindowGtk::~RootWindowGtk() { } void RootWindowGtk::Init(RootWindow::Delegate* delegate, - const RootWindowConfig& config, + std::unique_ptr 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 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; } diff --git a/tests/cefclient/browser/root_window_gtk.h b/tests/cefclient/browser/root_window_gtk.h index c52e7b67a..6af0c48ba 100644 --- a/tests/cefclient/browser/root_window_gtk.h +++ b/tests/cefclient/browser/root_window_gtk.h @@ -26,7 +26,7 @@ class RootWindowGtk : public RootWindow, public BrowserWindow::Delegate { // RootWindow methods. void Init(RootWindow::Delegate* delegate, - const RootWindowConfig& config, + std::unique_ptr config, const CefBrowserSettings& settings) override; void InitAsPopup(RootWindow::Delegate* delegate, bool with_controls, diff --git a/tests/cefclient/browser/root_window_mac.h b/tests/cefclient/browser/root_window_mac.h index 575113346..7a5d43551 100644 --- a/tests/cefclient/browser/root_window_mac.h +++ b/tests/cefclient/browser/root_window_mac.h @@ -30,7 +30,7 @@ class RootWindowMac : public RootWindow, public BrowserWindow::Delegate { // RootWindow methods. void Init(RootWindow::Delegate* delegate, - const RootWindowConfig& config, + std::unique_ptr config, const CefBrowserSettings& settings) override; void InitAsPopup(RootWindow::Delegate* delegate, bool with_controls, diff --git a/tests/cefclient/browser/root_window_mac.mm b/tests/cefclient/browser/root_window_mac.mm index 1ad2fb28e..a2fdd6f77 100644 --- a/tests/cefclient/browser/root_window_mac.mm +++ b/tests/cefclient/browser/root_window_mac.mm @@ -86,7 +86,7 @@ class RootWindowMacImpl // RootWindow methods. void Init(RootWindow::Delegate* delegate, - const RootWindowConfig& config, + std::unique_ptr 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 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 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, diff --git a/tests/cefclient/browser/root_window_manager.cc b/tests/cefclient/browser/root_window_manager.cc index 91cc49971..933539732 100644 --- a/tests/cefclient/browser/root_window_manager.cc +++ b/tests/cefclient/browser/root_window_manager.cc @@ -123,13 +123,13 @@ RootWindowManager::~RootWindowManager() { } scoped_refptr RootWindowManager::CreateRootWindow( - const RootWindowConfig& config) { + std::unique_ptr config) { CefBrowserSettings settings; MainContext::Get()->PopulateBrowserSettings(&settings); scoped_refptr 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 RootWindowManager::CreateRootWindowAsExtension( CefRefPtr extension, const CefRect& source_bounds, CefRefPtr 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 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(); + 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 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 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 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 extension, const CefRect& source_bounds, CefRefPtr 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); } } diff --git a/tests/cefclient/browser/root_window_manager.h b/tests/cefclient/browser/root_window_manager.h index 84db6e8e0..82f4e1712 100644 --- a/tests/cefclient/browser/root_window_manager.h +++ b/tests/cefclient/browser/root_window_manager.h @@ -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 CreateRootWindow(const RootWindowConfig& config); + scoped_refptr CreateRootWindow( + std::unique_ptr 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 extension, const CefRect& source_bounds, CefRefPtr 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 extension, const CefRect& source_bounds, CefRefPtr parent_window, - const base::Closure& close_callback, + base::OnceClosure close_callback, bool with_osr) override; void CleanupOnUIThread(); diff --git a/tests/cefclient/browser/root_window_views.cc b/tests/cefclient/browser/root_window_views.cc index b08537da1..d4135bc52 100644 --- a/tests/cefclient/browser/root_window_views.cc +++ b/tests/cefclient/browser/root_window_views.cc @@ -4,6 +4,8 @@ #include "tests/cefclient/browser/root_window_views.h" +#include + #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 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(); + 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 RootWindowViews::GetParentWindow() { CEF_REQUIRE_UI_THREAD(); - return parent_window_; + return config_->parent_window; } CefRect RootWindowViews::GetWindowBounds() { @@ -242,7 +232,7 @@ void RootWindowViews::OnViewsWindowCreated(CefRefPtr 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 window) { // Continue on the main thread. MAIN_POST_CLOSURE( - base::Bind(&RootWindowViews::NotifyViewsWindowDestroyed, this)); + base::BindOnce(&RootWindowViews::NotifyViewsWindowDestroyed, this)); } void RootWindowViews::OnViewsWindowActivated(CefRefPtr window) { @@ -264,7 +254,7 @@ void RootWindowViews::OnViewsWindowActivated(CefRefPtr 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 extension, - const CefRect& source_bounds, - CefRefPtr parent_window, - const base::Closure& close_callback) { +void RootWindowViews::CreateExtensionWindow(CefRefPtr extension, + const CefRect& source_bounds, + CefRefPtr 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 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 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 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& 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 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(); } } diff --git a/tests/cefclient/browser/root_window_views.h b/tests/cefclient/browser/root_window_views.h index 5b4d23030..2cabd97f7 100644 --- a/tests/cefclient/browser/root_window_views.h +++ b/tests/cefclient/browser/root_window_views.h @@ -28,7 +28,7 @@ class RootWindowViews : public RootWindow, // RootWindow methods: void Init(RootWindow::Delegate* delegate, - const RootWindowConfig& config, + std::unique_ptr config, const CefBrowserSettings& settings) override; void InitAsPopup(RootWindow::Delegate* delegate, bool with_controls, @@ -64,7 +64,7 @@ class RootWindowViews : public RootWindow, void CreateExtensionWindow(CefRefPtr extension, const CefRect& source_bounds, CefRefPtr 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 parent_window_; - bool is_popup_; + std::unique_ptr config_; + bool is_popup_ = false; CefRect initial_bounds_; - base::Closure close_callback_; - bool position_on_resize_; + bool position_on_resize_ = false; CefRefPtr client_handler_; - bool initialized_; - bool window_destroyed_; - bool browser_destroyed_; + bool initialized_ = false; + bool window_destroyed_ = false; + bool browser_destroyed_ = false; CefRefPtr browser_; diff --git a/tests/cefclient/browser/root_window_win.cc b/tests/cefclient/browser/root_window_win.cc index 8080ec9b3..c0341217c 100644 --- a/tests/cefclient/browser/root_window_win.cc +++ b/tests/cefclient/browser/root_window_win.cc @@ -146,32 +146,32 @@ RootWindowWin::~RootWindowWin() { } void RootWindowWin::Init(RootWindow::Delegate* delegate, - const RootWindowConfig& config, + std::unique_ptr 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)); } } diff --git a/tests/cefclient/browser/root_window_win.h b/tests/cefclient/browser/root_window_win.h index ebf2bd8fc..d7c149848 100644 --- a/tests/cefclient/browser/root_window_win.h +++ b/tests/cefclient/browser/root_window_win.h @@ -29,7 +29,7 @@ class RootWindowWin : public RootWindow, public BrowserWindow::Delegate { // RootWindow methods. void Init(RootWindow::Delegate* delegate, - const RootWindowConfig& config, + std::unique_ptr config, const CefBrowserSettings& settings) override; void InitAsPopup(RootWindow::Delegate* delegate, bool with_controls, diff --git a/tests/cefclient/browser/server_test.cc b/tests/cefclient/browser/server_test.cc index 93516af21..e57e9f304 100644 --- a/tests/cefclient/browser/server_test.cc +++ b/tests/cefclient/browser/server_test.cc @@ -5,6 +5,7 @@ #include "tests/cefclient/browser/server_test.h" #include +#include #include #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 CompleteCallback; + using CompleteCallback = base::OnceCallback; 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; } diff --git a/tests/cefclient/browser/test_runner.cc b/tests/cefclient/browser/test_runner.cc index 69611ac26..a1ed39d2e 100644 --- a/tests/cefclient/browser/test_runner.cc +++ b/tests/cefclient/browser/test_runner.cc @@ -152,10 +152,11 @@ void RunRequestTest(CefRefPtr browser) { } void RunNewWindowTest(CefRefPtr browser) { - RootWindowConfig config; - config.with_controls = true; - config.with_osr = browser->GetHost()->IsWindowRenderingDisabled(); - MainContext::Get()->GetRootWindowManager()->CreateRootWindow(config); + auto config = std::make_unique(); + config->with_controls = true; + config->with_osr = browser->GetHost()->IsWindowRenderingDisabled(); + MainContext::Get()->GetRootWindowManager()->CreateRootWindow( + std::move(config)); } void RunPopupWindowTest(CefRefPtr browser) { @@ -201,7 +202,7 @@ void RunPluginInfoTest(CefRefPtr browser) { void ModifyZoom(CefRefPtr 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 browser, float dsf) { MainMessageLoop::Get()->PostClosure( - base::Bind(&PromptHandler::SetDSFOnMainThread, browser, dsf)); + base::BindOnce(&PromptHandler::SetDSFOnMainThread, browser, dsf)); } static void SetDSFOnMainThread(CefRefPtr browser, float dsf) { @@ -291,7 +292,7 @@ void Prompt(CefRefPtr browser, void PromptFPS(CefRefPtr 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 browser) { void PromptDSF(CefRefPtr 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 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 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 browser) { void PrintToPDF(CefRefPtr 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 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( diff --git a/tests/cefclient/browser/urlrequest_test.cc b/tests/cefclient/browser/urlrequest_test.cc index d008751dc..ea53197ca 100644 --- a/tests/cefclient/browser/urlrequest_test.cc +++ b/tests/cefclient/browser/urlrequest_test.cc @@ -4,6 +4,7 @@ #include "tests/cefclient/browser/urlrequest_test.h" +#include #include #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 - Callback; + using Callback = + base::OnceCallback; - 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 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; } diff --git a/tests/cefclient/browser/views_window.cc b/tests/cefclient/browser/views_window.cc index 73f0a7328..1232c8c42 100644 --- a/tests/cefclient/browser/views_window.cc +++ b/tests/cefclient/browser/views_window.cc @@ -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 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; } diff --git a/tests/cefclient/browser/views_window.h b/tests/cefclient/browser/views_window.h index d729de283..91f23fd37 100644 --- a/tests/cefclient/browser/views_window.h +++ b/tests/cefclient/browser/views_window.h @@ -78,7 +78,7 @@ class ViewsWindow : public CefBrowserViewDelegate, virtual void CreateExtensionWindow(CefRefPtr extension, const CefRect& source_bounds, CefRefPtr 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; diff --git a/tests/cefclient/browser/window_test_runner_gtk.cc b/tests/cefclient/browser/window_test_runner_gtk.cc index ff79991a7..bce9407c2 100644 --- a/tests/cefclient/browser/window_test_runner_gtk.cc +++ b/tests/cefclient/browser/window_test_runner_gtk.cc @@ -115,19 +115,19 @@ void WindowTestRunnerGtk::SetPos(CefRefPtr 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 browser) { - MAIN_POST_CLOSURE(base::Bind(MinimizeImpl, browser)); + MAIN_POST_CLOSURE(base::BindOnce(MinimizeImpl, browser)); } void WindowTestRunnerGtk::Maximize(CefRefPtr browser) { - MAIN_POST_CLOSURE(base::Bind(MaximizeImpl, browser)); + MAIN_POST_CLOSURE(base::BindOnce(MaximizeImpl, browser)); } void WindowTestRunnerGtk::Restore(CefRefPtr browser) { - MAIN_POST_CLOSURE(base::Bind(RestoreImpl, browser)); + MAIN_POST_CLOSURE(base::BindOnce(RestoreImpl, browser)); } } // namespace window_test diff --git a/tests/cefclient/browser/window_test_runner_win.cc b/tests/cefclient/browser/window_test_runner_win.cc index 1faf6a158..fff1b98cf 100644 --- a/tests/cefclient/browser/window_test_runner_win.cc +++ b/tests/cefclient/browser/window_test_runner_win.cc @@ -104,7 +104,7 @@ void WindowTestRunnerWin::SetPos(CefRefPtr 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 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 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 browser) { RestoreImpl(browser); } else { // Execute on the main application thread. - MAIN_POST_CLOSURE(base::Bind(RestoreImpl, browser)); + MAIN_POST_CLOSURE(base::BindOnce(RestoreImpl, browser)); } } diff --git a/tests/cefclient/cefclient_gtk.cc b/tests/cefclient/cefclient_gtk.cc index d551b79cc..859feac3c 100644 --- a/tests/cefclient/cefclient_gtk.cc +++ b/tests/cefclient/cefclient_gtk.cc @@ -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(); + 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(); diff --git a/tests/cefclient/cefclient_mac.mm b/tests/cefclient/cefclient_mac.mm index dbd9d88f7..eddb2dd1c 100644 --- a/tests/cefclient/cefclient_mac.mm +++ b/tests/cefclient/cefclient_mac.mm @@ -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(); + 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 { diff --git a/tests/cefclient/cefclient_win.cc b/tests/cefclient/cefclient_win.cc index e446376d9..631370122 100644 --- a/tests/cefclient/cefclient_win.cc +++ b/tests/cefclient/cefclient_win.cc @@ -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(); + 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. diff --git a/tests/cefsimple/simple_handler.cc b/tests/cefsimple/simple_handler.cc index 5c4ae7938..fd1864897 100644 --- a/tests/cefsimple/simple_handler.cc +++ b/tests/cefsimple/simple_handler.cc @@ -131,8 +131,8 @@ void SimpleHandler::OnLoadError(CefRefPtr 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; } diff --git a/tests/ceftests/cookie_unittest.cc b/tests/ceftests/cookie_unittest.cc index 67861d79f..ea33bbbfd 100644 --- a/tests/ceftests/cookie_unittest.cc +++ b/tests/ceftests/cookie_unittest.cc @@ -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 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 manager, bool deleteCookies, CefRefPtr 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 manager, void VisitAllCookies(CefRefPtr 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 manager, bool deleteCookies, CefRefPtr 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 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 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 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 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 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; } diff --git a/tests/ceftests/cors_unittest.cc b/tests/ceftests/cors_unittest.cc index 70220771e..69ddb54ae 100644 --- a/tests/ceftests/cors_unittest.cc +++ b/tests/ceftests/cors_unittest.cc @@ -294,24 +294,22 @@ struct TestSetup { class TestServerObserver : public test_server::ObserverHelper { public: - typedef base::Callback 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 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 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) { diff --git a/tests/ceftests/devtools_message_unittest.cc b/tests/ceftests/devtools_message_unittest.cc index f0e3fcbcc..92257605e 100644 --- a/tests/ceftests/devtools_message_unittest.cc +++ b/tests/ceftests/devtools_message_unittest.cc @@ -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 registration_; diff --git a/tests/ceftests/dialog_unittest.cc b/tests/ceftests/dialog_unittest.cc index ee98d4dcd..29f004cb1 100644 --- a/tests/ceftests/dialog_unittest.cc +++ b/tests/ceftests/dialog_unittest.cc @@ -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); } diff --git a/tests/ceftests/display_unittest.cc b/tests/ceftests/display_unittest.cc index 62844599f..71e2e2e7c 100644 --- a/tests/ceftests/display_unittest.cc +++ b/tests/ceftests/display_unittest.cc @@ -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: diff --git a/tests/ceftests/download_unittest.cc b/tests/ceftests/download_unittest.cc index 60273982f..6470311b0 100644 --- a/tests/ceftests/download_unittest.cc +++ b/tests/ceftests/download_unittest.cc @@ -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 + +#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 DelayCallback; +using DelayCallback = base::OnceCallback; 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; + 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 Create(CefRefPtr browser, CefRefPtr frame, const CefString& scheme_name, CefRefPtr 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 self) { + return base::BindOnce(&DownloadTestHandler::OnDelayCallback, self); + }, + CefRefPtr(this)); + } CefRefPtr scheme_factory = - new DownloadSchemeHandlerFactory(delay_callback, + new DownloadSchemeHandlerFactory(delay_callback_vendor, &got_download_request_); CefRefPtr 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 request_context_; // Used with NAVIGATED and PENDING test modes. - base::Closure delay_callback_; + base::OnceClosure delay_callback_; // Used with PENDING test mode. CefRefPtr download_item_callback_; diff --git a/tests/ceftests/draggable_regions_unittest.cc b/tests/ceftests/draggable_regions_unittest.cc index fea4fc081..b37e63cb6 100644 --- a/tests/ceftests/draggable_regions_unittest.cc +++ b/tests/ceftests/draggable_regions_unittest.cc @@ -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: { diff --git a/tests/ceftests/extensions/background_unittest.cc b/tests/ceftests/extensions/background_unittest.cc index b7961d2a3..3b625817c 100644 --- a/tests/ceftests/extensions/background_unittest.cc +++ b/tests/ceftests/extensions/background_unittest.cc @@ -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 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 extension_; diff --git a/tests/ceftests/extensions/chrome_alarms_unittest.cc b/tests/ceftests/extensions/chrome_alarms_unittest.cc index a4abc86b2..25809a411 100644 --- a/tests/ceftests/extensions/chrome_alarms_unittest.cc +++ b/tests/ceftests/extensions/chrome_alarms_unittest.cc @@ -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 extension() const { return extension_; } diff --git a/tests/ceftests/extensions/chrome_storage_unittest.cc b/tests/ceftests/extensions/chrome_storage_unittest.cc index f71d6d8d5..28fe1c35c 100644 --- a/tests/ceftests/extensions/chrome_storage_unittest.cc +++ b/tests/ceftests/extensions/chrome_storage_unittest.cc @@ -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 extension() const { return extension_; } diff --git a/tests/ceftests/extensions/chrome_tabs_unittest.cc b/tests/ceftests/extensions/chrome_tabs_unittest.cc index ae0306e00..cb2bdfb2c 100644 --- a/tests/ceftests/extensions/chrome_tabs_unittest.cc +++ b/tests/ceftests/extensions/chrome_tabs_unittest.cc @@ -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 GetActiveBrowser(CefRefPtr 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 extension() const { return extension_; } diff --git a/tests/ceftests/extensions/view_unittest.cc b/tests/ceftests/extensions/view_unittest.cc index 444ed1e3e..0e04e4471 100644 --- a/tests/ceftests/extensions/view_unittest.cc +++ b/tests/ceftests/extensions/view_unittest.cc @@ -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 extension_; diff --git a/tests/ceftests/frame_unittest.cc b/tests/ceftests/frame_unittest.cc index b300f7cef..a9abd0370 100644 --- a/tests/ceftests/frame_unittest.cc +++ b/tests/ceftests/frame_unittest.cc @@ -106,7 +106,7 @@ const int kMaxMultiNavNavigations = 4; // Abstract base class representing expectations that result from a navigation. class FrameNavExpectations { public: - typedef base::Callback, CefRefPtr)> + typedef base::OnceCallback, CefRefPtr)> 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 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 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 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()); diff --git a/tests/ceftests/jsdialog_unittest.cc b/tests/ceftests/jsdialog_unittest.cc index 3cb59f4ce..d6ddcf8a9 100644 --- a/tests/ceftests/jsdialog_unittest.cc +++ b/tests/ceftests/jsdialog_unittest.cc @@ -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; diff --git a/tests/ceftests/life_span_unittest.cc b/tests/ceftests/life_span_unittest.cc index 10107ede8..7c1f95b3a 100644 --- a/tests/ceftests/life_span_unittest.cc +++ b/tests/ceftests/life_span_unittest.cc @@ -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() { diff --git a/tests/ceftests/message_router_unittest.cc b/tests/ceftests/message_router_unittest.cc index 72a56bf2f..d939a060c 100644 --- a/tests/ceftests/message_router_unittest.cc +++ b/tests/ceftests/message_router_unittest.cc @@ -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)); } } diff --git a/tests/ceftests/navigation_unittest.cc b/tests/ceftests/navigation_unittest.cc index 2c529d6e1..89138c2d7 100644 --- a/tests/ceftests/navigation_unittest.cc +++ b/tests/ceftests/navigation_unittest.cc @@ -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(); } diff --git a/tests/ceftests/os_rendering_unittest.cc b/tests/ceftests/os_rendering_unittest.cc index c969de2a8..07e984e18 100644 --- a/tests/ceftests/os_rendering_unittest.cc +++ b/tests/ceftests/os_rendering_unittest.cc @@ -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 { diff --git a/tests/ceftests/osr_accessibility_unittest.cc b/tests/ceftests/osr_accessibility_unittest.cc index ea8662950..77fdf6e71 100644 --- a/tests/ceftests/osr_accessibility_unittest.cc +++ b/tests/ceftests/osr_accessibility_unittest.cc @@ -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 GetUpdateList(CefRefPtr 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. diff --git a/tests/ceftests/osr_display_unittest.cc b/tests/ceftests/osr_display_unittest.cc index 67ecf86cd..9721689a2 100644 --- a/tests/ceftests/osr_display_unittest.cc +++ b/tests/ceftests/osr_display_unittest.cc @@ -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')"); diff --git a/tests/ceftests/plugin_unittest.cc b/tests/ceftests/plugin_unittest.cc index 38697994c..1d1029422 100644 --- a/tests/ceftests/plugin_unittest.cc +++ b/tests/ceftests/plugin_unittest.cc @@ -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 GetContextMenuHandler() override { diff --git a/tests/ceftests/preference_unittest.cc b/tests/ceftests/preference_unittest.cc index c6ba8eaf0..863cc74e7 100644 --- a/tests/ceftests/preference_unittest.cc +++ b/tests/ceftests/preference_unittest.cc @@ -250,7 +250,8 @@ void ValidateDefaults(CefRefPtr context, bool reset, CefRefPtr 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 val) { void ValidateSetGet(CefRefPtr context, CefRefPtr 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 context, void ValidateGet(CefRefPtr context, CefRefPtr event) { if (!CefCurrentlyOn(TID_UI)) { - CefPostTask(TID_UI, base::Bind(ValidateGet, context, event)); + CefPostTask(TID_UI, base::BindOnce(ValidateGet, context, event)); return; } diff --git a/tests/ceftests/process_message_unittest.cc b/tests/ceftests/process_message_unittest.cc index 92bac0cc7..a91b2ab29 100644 --- a/tests/ceftests/process_message_unittest.cc +++ b/tests/ceftests/process_message_unittest.cc @@ -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); } diff --git a/tests/ceftests/request_context_unittest.cc b/tests/ceftests/request_context_unittest.cc index e0676ab6f..6126563c8 100644 --- a/tests/ceftests/request_context_unittest.cc +++ b/tests/ceftests/request_context_unittest.cc @@ -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)); } } diff --git a/tests/ceftests/request_handler_unittest.cc b/tests/ceftests/request_handler_unittest.cc index ab7732cbf..1de00609d 100644 --- a/tests/ceftests/request_handler_unittest.cc +++ b/tests/ceftests/request_handler_unittest.cc @@ -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, diff --git a/tests/ceftests/request_unittest.cc b/tests/ceftests/request_unittest.cc index 8b5bf65a1..b10ad41b2 100644 --- a/tests/ceftests/request_unittest.cc +++ b/tests/ceftests/request_unittest.cc @@ -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); diff --git a/tests/ceftests/resource_manager_unittest.cc b/tests/ceftests/resource_manager_unittest.cc index ceca51644..b4dc9b3db 100644 --- a/tests/ceftests/resource_manager_unittest.cc +++ b/tests/ceftests/resource_manager_unittest.cc @@ -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 #include #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 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, ¤t_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 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 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 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 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 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; diff --git a/tests/ceftests/resource_request_handler_unittest.cc b/tests/ceftests/resource_request_handler_unittest.cc index 50e47f2d1..3b40c0210 100644 --- a/tests/ceftests/resource_request_handler_unittest.cc +++ b/tests/ceftests/resource_request_handler_unittest.cc @@ -30,17 +30,17 @@ class NormalResourceHandler : public CefStreamResourceHandler { const CefString& mime_type, CefResponse::HeaderMap header_map, CefRefPtr 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 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 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 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 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 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 "Redirect"; } - 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 "Redirect"; } - 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 frame) { class StringVisitor : public CefStringVisitor { public: - typedef base::Callback - VisitorCallback; + using VisitorCallback = + base::OnceCallback; - 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) { diff --git a/tests/ceftests/run_all_unittests.cc b/tests/ceftests/run_all_unittests.cc index d6f65b03b..58709c38c 100644 --- a/tests/ceftests/run_all_unittests.cc +++ b/tests/ceftests/run_all_unittests.cc @@ -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 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 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(); diff --git a/tests/ceftests/scheme_handler_unittest.cc b/tests/ceftests/scheme_handler_unittest.cc index 175bef4b1..66ee5231b 100644 --- a/tests/ceftests/scheme_handler_unittest.cc +++ b/tests/ceftests/scheme_handler_unittest.cc @@ -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; } diff --git a/tests/ceftests/server_unittest.cc b/tests/ceftests/server_unittest.cc index 40e4768a9..8ce4df3bf 100644 --- a/tests/ceftests/server_unittest.cc +++ b/tests/ceftests/server_unittest.cc @@ -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 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 { 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 { 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 { 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 { 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 { 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 { // 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 /* 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 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 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 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 request_; HttpServerResponse response_; CefRefPtr 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)); } } diff --git a/tests/ceftests/test_handler.cc b/tests/ceftests/test_handler.cc index 727f7c53f..fed752eac 100644 --- a/tests/ceftests/test_handler.cc +++ b/tests/ceftests/test_handler.cc @@ -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; } diff --git a/tests/ceftests/test_handler.h b/tests/ceftests/test_handler.h index 7161d818b..aa862b1ce 100644 --- a/tests/ceftests/test_handler.h +++ b/tests/ceftests/test_handler.h @@ -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 weak_ptr_factory_; diff --git a/tests/ceftests/test_request.cc b/tests/ceftests/test_request.cc index 8554be28f..0a92131df 100644 --- a/tests/ceftests/test_request.cc +++ b/tests/ceftests/test_request.cc @@ -5,6 +5,7 @@ #include "tests/ceftests/test_request.h" #include +#include #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 client = new RequestClient( - config.has_credentials_, config.username_, config.password_, callback); + CefRefPtr 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 CreateResourceHandler( void GetAllCookies(CefRefPtr 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 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); } diff --git a/tests/ceftests/test_request.h b/tests/ceftests/test_request.h index 9e2f9251f..ff17c894b 100644 --- a/tests/ceftests/test_request.h +++ b/tests/ceftests/test_request.h @@ -45,7 +45,7 @@ struct State { bool response_was_cached_ = false; }; -typedef base::Callback RequestDoneCallback; +using RequestDoneCallback = base::OnceCallback; 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 CreateResourceHandler( CefRefPtr response, const std::string& response_data); -typedef std::vector CookieVector; -typedef base::Callback CookieDoneCallback; +using CookieVector = std::vector; +using CookieDoneCallback = + base::OnceCallback; // Retrieves all cookies from |manager| and executes |callback| upon completion. // If |deleteCookies| is true the cookies will also be deleted. void GetAllCookies(CefRefPtr 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 manager, const CefString& url, bool includeHttpOnly, bool deleteCookies, - const CookieDoneCallback& callback); + CookieDoneCallback callback); } // namespace test_request diff --git a/tests/ceftests/test_server.cc b/tests/ceftests/test_server.cc index f49053a31..63f5ef275 100644 --- a/tests/ceftests/test_server.cc +++ b/tests/ceftests/test_server.cc @@ -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 handler_; std::string origin_; - typedef std::vector StartDoneCallbackList; + using StartDoneCallbackList = std::vector; StartDoneCallbackList start_callback_list_; DoneCallback stop_callback_; - typedef std::vector ObserverList; + using ObserverList = std::vector; 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 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 server, void ServerHandler::NotifyClientDisconnected(CefRefPtr 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 server, const CefString& client_address, CefRefPtr 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 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 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 AddObserver(Observer* observer, - const DoneCallback& callback) { + DoneCallback callback) { DCHECK(observer); CefRefPtr registration = new ObserverRegistration(observer); - InitializeRegistration(registration, callback); + InitializeRegistration(registration, std::move(callback)); return registration.get(); } -CefRefPtr AddObserverAndStart( - Observer* observer, - const StartDoneCallback& callback) { - return AddObserver(observer, base::Bind(Start, callback)); +CefRefPtr AddObserverAndStart(Observer* observer, + StartDoneCallback callback) { + return AddObserver(observer, base::BindOnce(Start, std::move(callback))); } void SendResponse(CefRefPtr 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() { diff --git a/tests/ceftests/test_server.h b/tests/ceftests/test_server.h index 319bb692b..48e39b56e 100644 --- a/tests/ceftests/test_server.h +++ b/tests/ceftests/test_server.h @@ -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 - StartDoneCallback; +using StartDoneCallback = + base::OnceCallback; // 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 AddObserver(Observer* observer, - const DoneCallback& callback); + DoneCallback callback); // Combination of AddObserver() followed by Start(). -CefRefPtr AddObserverAndStart( - Observer* observer, - const StartDoneCallback& callback); +CefRefPtr AddObserverAndStart(Observer* observer, + StartDoneCallback callback); // Helper for sending a fully qualified response. void SendResponse(CefRefPtr server, diff --git a/tests/ceftests/test_server_unittest.cc b/tests/ceftests/test_server_unittest.cc index 7872bb06b..7f6bbb28f 100644 --- a/tests/ceftests/test_server_unittest.cc +++ b/tests/ceftests/test_server_unittest.cc @@ -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 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 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 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); diff --git a/tests/ceftests/thread_helper.cc b/tests/ceftests/thread_helper.cc index dffac1b0f..326c95dc6 100644 --- a/tests/ceftests/thread_helper.cc +++ b/tests/ceftests/thread_helper.cc @@ -4,6 +4,8 @@ #include "tests/ceftests/thread_helper.h" +#include + #include "include/wrapper/cef_closure_task.h" void SignalEvent(CefRefPtr event) { @@ -13,7 +15,7 @@ void SignalEvent(CefRefPtr event) { void WaitForThread(CefThreadId thread_id, int64 delay_ms) { CefRefPtr 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 task_runner, int64 delay_ms) { CefRefPtr 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& test_impl, + base::OnceClosure test_impl, CefRefPtr 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)>& test_impl, + base::OnceCallback)> test_impl, CefRefPtr 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); } diff --git a/tests/ceftests/thread_helper.h b/tests/ceftests/thread_helper.h index 0561663ed..e68ecd417 100644 --- a/tests/ceftests/thread_helper.h +++ b/tests/ceftests/thread_helper.h @@ -35,15 +35,15 @@ void WaitForThread(CefRefPtr 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& test_impl, + base::OnceClosure test_impl, CefRefPtr event); -#define NAMED_THREAD_TEST(thread_id, test_case_name, test_name) \ - TEST(test_case_name, test_name) { \ - CefRefPtr 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 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)>& test_impl, + base::OnceCallback)> test_impl, CefRefPtr); -#define NAMED_THREAD_TEST_ASYNC(thread_id, test_case_name, test_name) \ - TEST(test_case_name, test_name) { \ - CefRefPtr 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 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 diff --git a/tests/ceftests/thread_unittest.cc b/tests/ceftests/thread_unittest.cc index 166001bf8..cef547373 100644 --- a/tests/ceftests/thread_unittest.cc +++ b/tests/ceftests/thread_unittest.cc @@ -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 { // 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 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 owner_task_runner() const { @@ -94,14 +95,14 @@ class ThreadTest : public base::RefCountedThreadSafe { private: // Helper for PostOnTestThreadAndCallback(). - void ExecuteOnTestThread(const base::Closure& test_task, + void ExecuteOnTestThread(base::OnceClosure test_task, CefRefPtr 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 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 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() { diff --git a/tests/ceftests/tracing_unittest.cc b/tests/ceftests/tracing_unittest.cc index b8be786cf..938737f63 100644 --- a/tests/ceftests/tracing_unittest.cc +++ b/tests/ceftests/tracing_unittest.cc @@ -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) { diff --git a/tests/ceftests/urlrequest_unittest.cc b/tests/ceftests/urlrequest_unittest.cc index cc2467f90..27030e804 100644 --- a/tests/ceftests/urlrequest_unittest.cc +++ b/tests/ceftests/urlrequest_unittest.cc @@ -4,6 +4,7 @@ #include #include +#include #include #include "include/base/cef_callback.h" @@ -201,9 +202,9 @@ struct RequestRunSettings { // Used only with the server backend. int expected_receive_count = -1; - typedef base::Callback - NextRequestCallback; + using NextRequestCallback = + base::OnceCallback; // If non-null this callback will be executed before subsequent requests are // sent. @@ -307,18 +308,15 @@ class RequestDataMap { class TestCompletionCallback : public CefCompletionCallback { public: - explicit TestCompletionCallback(const base::Closure& complete_callback) - : complete_callback_(complete_callback) { + explicit TestCompletionCallback(base::OnceClosure complete_callback) + : complete_callback_(std::move(complete_callback)) { EXPECT_FALSE(complete_callback_.is_null()); } - void OnComplete() override { - complete_callback_.Run(); - complete_callback_.Reset(); - } + void OnComplete() override { std::move(complete_callback_).Run(); } private: - base::Closure complete_callback_; + base::OnceClosure complete_callback_; IMPLEMENT_REFCOUNTING(TestCompletionCallback); }; @@ -381,21 +379,21 @@ void GetUploadData(CefRefPtr request, std::string& data) { // Set a cookie so that we can test if it's sent with the request. void SetTestCookie(CefRefPtr request_context, bool server_backend, - const base::Closure& callback) { + base::OnceClosure callback) { class Callback : public CefSetCookieCallback { public: - explicit Callback(const base::Closure& callback) : callback_(callback) { + explicit Callback(base::OnceClosure callback) + : callback_(std::move(callback)) { EXPECT_FALSE(callback_.is_null()); } void OnComplete(bool success) override { EXPECT_TRUE(success); - callback_.Run(); - callback_.Reset(); + std::move(callback_).Run(); } private: - base::Closure callback_; + base::OnceClosure callback_; IMPLEMENT_REFCOUNTING(Callback); }; @@ -407,23 +405,25 @@ void SetTestCookie(CefRefPtr request_context, CefString(&cookie.path) = "/"; cookie.has_expires = false; EXPECT_TRUE(request_context->GetCookieManager(nullptr)->SetCookie( - GetRequestOrigin(server_backend), cookie, new Callback(callback))); + GetRequestOrigin(server_backend), cookie, + new Callback(std::move(callback)))); } -typedef base::Callback GetTestCookieCallback; +using GetTestCookieCallback = + base::OnceCallback; // Tests if the save cookie has been set. If set, it will be deleted at the same // time. void GetTestCookie(CefRefPtr request_context, bool server_backend, - const GetTestCookieCallback& callback) { + GetTestCookieCallback callback) { class Visitor : public CefCookieVisitor { public: - explicit Visitor(const GetTestCookieCallback& callback) - : callback_(callback), cookie_exists_(false) { + explicit Visitor(GetTestCookieCallback callback) + : callback_(std::move(callback)), cookie_exists_(false) { EXPECT_FALSE(callback_.is_null()); } - ~Visitor() override { callback_.Run(cookie_exists_); } + ~Visitor() override { std::move(callback_).Run(cookie_exists_); } bool Visit(const CefCookie& cookie, int count, @@ -448,7 +448,7 @@ void GetTestCookie(CefRefPtr request_context, CefRefPtr cookie_manager = request_context->GetCookieManager(nullptr); cookie_manager->VisitUrlCookies(GetRequestOrigin(server_backend), true, - new Visitor(callback)); + new Visitor(std::move(callback))); } std::string GetHeaderValue(const CefRequest::HeaderMap& header_map, @@ -573,12 +573,12 @@ bool IsAuthorized(CefRefPtr request, class RequestSchemeHandlerOld : public CefResourceHandler { public: RequestSchemeHandlerOld(RequestRunSettings* settings, - const base::Closure& destroy_callback) - : settings_(settings), destroy_callback_(destroy_callback) {} + base::OnceClosure destroy_callback) + : settings_(settings), destroy_callback_(std::move(destroy_callback)) {} ~RequestSchemeHandlerOld() override { EXPECT_EQ(1, cancel_ct_); - destroy_callback_.Run(); + std::move(destroy_callback_).Run(); } bool ProcessRequest(CefRefPtr request, @@ -635,7 +635,7 @@ class RequestSchemeHandlerOld : public CefResourceHandler { private: // |settings_| is not owned by this object. RequestRunSettings* settings_; - base::Closure destroy_callback_; + base::OnceClosure destroy_callback_; std::string response_data_; size_t offset_ = 0; @@ -649,12 +649,12 @@ class RequestSchemeHandlerOld : public CefResourceHandler { class RequestSchemeHandler : public CefResourceHandler { public: RequestSchemeHandler(RequestRunSettings* settings, - const base::Closure& destroy_callback) - : settings_(settings), destroy_callback_(destroy_callback) {} + base::OnceClosure destroy_callback) + : settings_(settings), destroy_callback_(std::move(destroy_callback)) {} ~RequestSchemeHandler() override { EXPECT_EQ(1, cancel_ct_); - destroy_callback_.Run(); + std::move(destroy_callback_).Run(); } bool Open(CefRefPtr request, @@ -743,7 +743,7 @@ class RequestSchemeHandler : public CefResourceHandler { private: // |settings_| is not owned by this object. RequestRunSettings* settings_; - base::Closure destroy_callback_; + base::OnceClosure destroy_callback_; std::string response_data_; size_t offset_ = 0; @@ -759,14 +759,14 @@ class RequestRedirectSchemeHandlerOld : public CefResourceHandler { public: RequestRedirectSchemeHandlerOld(CefRefPtr request, CefRefPtr response, - const base::Closure& destroy_callback) + base::OnceClosure destroy_callback) : request_(request), response_(response), - destroy_callback_(destroy_callback) {} + destroy_callback_(std::move(destroy_callback)) {} ~RequestRedirectSchemeHandlerOld() override { EXPECT_EQ(1, cancel_ct_); - destroy_callback_.Run(); + std::move(destroy_callback_).Run(); } bool ProcessRequest(CefRefPtr request, @@ -814,7 +814,7 @@ class RequestRedirectSchemeHandlerOld : public CefResourceHandler { private: CefRefPtr request_; CefRefPtr response_; - base::Closure destroy_callback_; + base::OnceClosure destroy_callback_; int cancel_ct_ = 0; @@ -826,14 +826,14 @@ class RequestRedirectSchemeHandler : public CefResourceHandler { public: RequestRedirectSchemeHandler(CefRefPtr request, CefRefPtr response, - const base::Closure& destroy_callback) + base::OnceClosure destroy_callback) : request_(request), response_(response), - destroy_callback_(destroy_callback) {} + destroy_callback_(std::move(destroy_callback)) {} ~RequestRedirectSchemeHandler() override { EXPECT_EQ(1, cancel_ct_); - destroy_callback_.Run(); + std::move(destroy_callback_).Run(); } bool Open(CefRefPtr request, @@ -897,7 +897,7 @@ class RequestRedirectSchemeHandler : public CefResourceHandler { private: CefRefPtr request_; CefRefPtr response_; - base::Closure destroy_callback_; + base::OnceClosure destroy_callback_; int cancel_ct_ = 0; @@ -910,8 +910,8 @@ class RequestRedirectSchemeHandler : public CefResourceHandler { class IncompleteSchemeHandlerOld : public CefResourceHandler { public: IncompleteSchemeHandlerOld(RequestRunSettings* settings, - const base::Closure& destroy_callback) - : settings_(settings), destroy_callback_(destroy_callback) { + base::OnceClosure destroy_callback) + : settings_(settings), destroy_callback_(std::move(destroy_callback)) { EXPECT_NE(settings_->incomplete_type, RequestRunSettings::INCOMPLETE_NONE); } @@ -928,7 +928,7 @@ class IncompleteSchemeHandlerOld : public CefResourceHandler { EXPECT_EQ(0, read_response_ct_); } - destroy_callback_.Run(); + std::move(destroy_callback_).Run(); } bool ProcessRequest(CefRefPtr request, @@ -990,7 +990,7 @@ class IncompleteSchemeHandlerOld : public CefResourceHandler { private: RequestRunSettings* const settings_; - const base::Closure destroy_callback_; + base::OnceClosure destroy_callback_; int process_request_ct_ = 0; int get_response_headers_ct_ = 0; @@ -1006,8 +1006,8 @@ class IncompleteSchemeHandlerOld : public CefResourceHandler { class IncompleteSchemeHandler : public CefResourceHandler { public: IncompleteSchemeHandler(RequestRunSettings* settings, - const base::Closure& destroy_callback) - : settings_(settings), destroy_callback_(destroy_callback) { + base::OnceClosure destroy_callback) + : settings_(settings), destroy_callback_(std::move(destroy_callback)) { EXPECT_NE(settings_->incomplete_type, RequestRunSettings::INCOMPLETE_NONE); } @@ -1024,7 +1024,7 @@ class IncompleteSchemeHandler : public CefResourceHandler { EXPECT_EQ(0, read_ct_); } - destroy_callback_.Run(); + std::move(destroy_callback_).Run(); } bool Open(CefRefPtr request, @@ -1103,7 +1103,7 @@ class IncompleteSchemeHandler : public CefResourceHandler { private: RequestRunSettings* const settings_; - const base::Closure destroy_callback_; + base::OnceClosure destroy_callback_; int open_ct_ = 0; int get_response_headers_ct_ = 0; @@ -1128,30 +1128,36 @@ class RequestSchemeHandlerFactory : public CefSchemeHandlerFactory { EXPECT_IO_THREAD(); handler_create_ct_++; - const base::Closure destroy_callback = - base::Bind(&RequestSchemeHandlerFactory::OnHandlerDestroyed, this); + auto destroy_callback = + base::BindOnce(&RequestSchemeHandlerFactory::OnHandlerDestroyed, this); RequestDataMap::Entry entry = data_map_.Find(request->GetURL()); if (entry.type == RequestDataMap::Entry::TYPE_NORMAL) { if (entry.settings->incomplete_type == RequestRunSettings::INCOMPLETE_NONE) { if (TestOldResourceAPI()) { - return new RequestSchemeHandlerOld(entry.settings, destroy_callback); + return new RequestSchemeHandlerOld(entry.settings, + std::move(destroy_callback)); } - return new RequestSchemeHandler(entry.settings, destroy_callback); + return new RequestSchemeHandler(entry.settings, + std::move(destroy_callback)); } if (TestOldResourceAPI()) { - return new IncompleteSchemeHandlerOld(entry.settings, destroy_callback); + return new IncompleteSchemeHandlerOld(entry.settings, + std::move(destroy_callback)); } - return new IncompleteSchemeHandler(entry.settings, destroy_callback); + return new IncompleteSchemeHandler(entry.settings, + std::move(destroy_callback)); } else if (entry.type == RequestDataMap::Entry::TYPE_REDIRECT) { if (TestOldResourceAPI()) { - return new RequestRedirectSchemeHandlerOld( - entry.redirect_request, entry.redirect_response, destroy_callback); + return new RequestRedirectSchemeHandlerOld(entry.redirect_request, + entry.redirect_response, + std::move(destroy_callback)); } - return new RequestRedirectSchemeHandler( - entry.redirect_request, entry.redirect_response, destroy_callback); + return new RequestRedirectSchemeHandler(entry.redirect_request, + entry.redirect_response, + std::move(destroy_callback)); } // Unknown test. @@ -1181,9 +1187,9 @@ class RequestSchemeHandlerFactory : public CefSchemeHandlerFactory { void OnHandlerDestroyed() { if (!CefCurrentlyOn(TID_IO)) { - CefPostTask( - TID_IO, - base::Bind(&RequestSchemeHandlerFactory::OnHandlerDestroyed, this)); + CefPostTask(TID_IO, + base::BindOnce( + &RequestSchemeHandlerFactory::OnHandlerDestroyed, this)); return; } @@ -1192,15 +1198,15 @@ class RequestSchemeHandlerFactory : public CefSchemeHandlerFactory { MaybeShutdown(); } - void Shutdown(const base::Closure& complete_callback) { + void Shutdown(base::OnceClosure complete_callback) { if (!CefCurrentlyOn(TID_IO)) { - CefPostTask(TID_IO, base::Bind(&RequestSchemeHandlerFactory::Shutdown, - this, complete_callback)); + CefPostTask(TID_IO, base::BindOnce(&RequestSchemeHandlerFactory::Shutdown, + this, std::move(complete_callback))); return; } EXPECT_TRUE(shutdown_callback_.is_null()); - shutdown_callback_ = complete_callback; + shutdown_callback_ = std::move(complete_callback); data_map_.SetOwnerTaskRunner(nullptr); @@ -1211,8 +1217,7 @@ class RequestSchemeHandlerFactory : public CefSchemeHandlerFactory { void MaybeShutdown() { if (!shutdown_callback_.is_null() && handler_create_ct_ == handler_destroy_ct_) { - shutdown_callback_.Run(); - shutdown_callback_.Reset(); + std::move(shutdown_callback_).Run(); } } @@ -1220,7 +1225,7 @@ class RequestSchemeHandlerFactory : public CefSchemeHandlerFactory { int handler_create_ct_ = 0; int handler_destroy_ct_ = 0; - base::Closure shutdown_callback_; + base::OnceClosure shutdown_callback_; IMPLEMENT_REFCOUNTING(RequestSchemeHandlerFactory); DISALLOW_COPY_AND_ASSIGN(RequestSchemeHandlerFactory); @@ -1254,7 +1259,7 @@ class RequestServerHandler : 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_connection_ct_ < 0) { @@ -1266,18 +1271,18 @@ class RequestServerHandler : public test_server::ObserverHelper { initialized_ = true; EXPECT_TRUE(complete_callback_.is_null()); - complete_callback_ = complete_callback; + complete_callback_ = std::move(complete_callback); Initialize(); } // Results in a call to VerifyResults() and eventual execution of the // |complete_callback| on the UI thread via RequestServerHandler 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(); } @@ -1461,8 +1466,8 @@ class RequestServerHandler : public test_server::ObserverHelper { CefRefPtr task_runner = server->GetTaskRunner(); if (!task_runner->BelongsToCurrentThread()) { task_runner->PostTask(CefCreateClosureTask( - base::Bind(RequestServerHandler::SendResponse, server, connection_id, - response, response_data))); + base::BindOnce(RequestServerHandler::SendResponse, server, + connection_id, response, response_data))); return; } @@ -1505,8 +1510,7 @@ class RequestServerHandler : public test_server::ObserverHelper { } EXPECT_FALSE(complete_callback_.is_null()); - complete_callback_.Run(); - complete_callback_.Reset(); + std::move(complete_callback_).Run(); } RequestDataMap data_map_; @@ -1514,7 +1518,7 @@ class RequestServerHandler : 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. @@ -1538,18 +1542,18 @@ class RequestServerHandler : public test_server::ObserverHelper { // Executes the tests. class RequestTestRunner : public base::RefCountedThreadSafe { public: - typedef base::Callback TestCallback; + using TestCallback = base::RepeatingCallback; RequestTestRunner(bool is_browser_process, bool is_server_backend, bool use_frame_method, bool run_in_browser_process, - const base::Closure& incomplete_request_callback) + base::OnceClosure incomplete_request_callback) : is_browser_process_(is_browser_process), is_server_backend_(is_server_backend), use_frame_method_(use_frame_method), run_in_browser_process_(run_in_browser_process), - incomplete_request_callback_(incomplete_request_callback) { + incomplete_request_callback_(std::move(incomplete_request_callback)) { owner_task_runner_ = CefTaskRunner::GetForCurrentThread(); EXPECT_TRUE(owner_task_runner_.get()); EXPECT_TRUE(owner_task_runner_->BelongsToCurrentThread()); @@ -1557,9 +1561,10 @@ class RequestTestRunner : public base::RefCountedThreadSafe { void Initialize() { // Helper macro for registering test callbacks. -#define REGISTER_TEST(test_mode, setup_method, run_method) \ - RegisterTest(test_mode, base::Bind(&RequestTestRunner::setup_method, this), \ - base::Bind(&RequestTestRunner::run_method, this)); +#define REGISTER_TEST(test_mode, setup_method, run_method) \ + RegisterTest(test_mode, \ + base::BindRepeating(&RequestTestRunner::setup_method, this), \ + base::BindRepeating(&RequestTestRunner::run_method, this)); // Register the test callbacks. REGISTER_TEST(REQTEST_GET, SetupGetTest, SingleRunTest); @@ -1626,76 +1631,79 @@ class RequestTestRunner : public base::RefCountedThreadSafe { // Called in both the browser and render process to setup the test. void SetupTest(RequestTestMode test_mode, - const base::Closure& complete_callback) { + base::OnceClosure complete_callback) { EXPECT_TRUE(owner_task_runner_->BelongsToCurrentThread()); - const base::Closure& safe_complete_callback = base::Bind( - &RequestTestRunner::CompleteOnCorrectThread, this, complete_callback); - TestMap::const_iterator it = test_map_.find(test_mode); if (it != test_map_.end()) { - it->second.setup.Run(base::Bind(&RequestTestRunner::SetupContinue, this, - safe_complete_callback)); + auto safe_complete_callback = + base::BindOnce(&RequestTestRunner::CompleteOnCorrectThread, this, + std::move(complete_callback)); + it->second.setup.Run(base::BindOnce(&RequestTestRunner::SetupContinue, + this, + std::move(safe_complete_callback))); } else { // Unknown test. ADD_FAILURE(); - complete_callback.Run(); + std::move(complete_callback).Run(); } } // Called in either the browser or render process to run the test. void RunTest(RequestTestMode test_mode, CefRefPtr frame, - const base::Closure& complete_callback) { + base::OnceClosure complete_callback) { EXPECT_TRUE(owner_task_runner_->BelongsToCurrentThread()); frame_ = frame; - const base::Closure& safe_complete_callback = base::Bind( - &RequestTestRunner::CompleteOnCorrectThread, this, complete_callback); - TestMap::const_iterator it = test_map_.find(test_mode); if (it != test_map_.end()) { - it->second.run.Run(safe_complete_callback); + auto safe_complete_callback = + base::BindOnce(&RequestTestRunner::CompleteOnCorrectThread, this, + std::move(complete_callback)); + it->second.run.Run(std::move(safe_complete_callback)); } else { // Unknown test. ADD_FAILURE(); - complete_callback.Run(); + std::move(complete_callback).Run(); } } // Called in both the browser and render process to shut down the test. - void ShutdownTest(const base::Closure& complete_callback) { + void ShutdownTest(base::OnceClosure complete_callback) { EXPECT_TRUE(owner_task_runner_->BelongsToCurrentThread()); - const base::Closure& safe_complete_callback = base::Bind( - &RequestTestRunner::CompleteOnCorrectThread, this, complete_callback); + auto safe_complete_callback = + base::BindOnce(&RequestTestRunner::CompleteOnCorrectThread, this, + std::move(complete_callback)); if (!post_file_tmpdir_.IsEmpty()) { EXPECT_TRUE(is_browser_process_); CefPostTask(TID_FILE_USER_VISIBLE, - base::Bind(&RequestTestRunner::RunDeleteTempDirectory, this, - safe_complete_callback)); + base::BindOnce(&RequestTestRunner::RunDeleteTempDirectory, + this, std::move(safe_complete_callback))); return; } // Continue with test shutdown. - RunShutdown(safe_complete_callback); + RunShutdown(std::move(safe_complete_callback)); } private: // Continued after |settings_| is populated for the test. - void SetupContinue(const base::Closure& complete_callback) { + void SetupContinue(base::OnceClosure complete_callback) { if (!owner_task_runner_->BelongsToCurrentThread()) { - owner_task_runner_->PostTask(CefCreateClosureTask(base::Bind( - &RequestTestRunner::SetupContinue, this, complete_callback))); + owner_task_runner_->PostTask(CefCreateClosureTask( + base::BindOnce(&RequestTestRunner::SetupContinue, this, + std::move(complete_callback)))); return; } if (is_browser_process_) { - SetupTestBackend(complete_callback); + SetupTestBackend(std::move(complete_callback)); } else { - complete_callback.Run(); + std::move(complete_callback).Run(); } } @@ -1724,12 +1732,12 @@ class RequestTestRunner : public base::RefCountedThreadSafe { settings_.response_data = "GET TEST SUCCESS"; } - void SetupGetTest(const base::Closure& complete_callback) { + void SetupGetTest(base::OnceClosure complete_callback) { SetupGetTestShared(); - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupGetNoDataTest(const base::Closure& complete_callback) { + void SetupGetNoDataTest(base::OnceClosure complete_callback) { // Start with the normal get test. SetupGetTestShared(); @@ -1738,10 +1746,10 @@ class RequestTestRunner : public base::RefCountedThreadSafe { settings_.expect_download_data = false; - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupGetPartialContentTest(const base::Closure& complete_callback) { + void SetupGetPartialContentTest(base::OnceClosure complete_callback) { // Start with the normal get test. SetupGetTestShared(); @@ -1752,10 +1760,10 @@ class RequestTestRunner : public base::RefCountedThreadSafe { settings_.response->SetStatusText("Partial Content"); settings_.expected_download_offset = 4; - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupGetAllowCookiesTest(const base::Closure& complete_callback) { + void SetupGetAllowCookiesTest(base::OnceClosure complete_callback) { // Start with the normal get test. SetupGetTestShared(); @@ -1765,10 +1773,10 @@ class RequestTestRunner : public base::RefCountedThreadSafe { settings_.expect_save_cookie = true; settings_.expect_send_cookie = true; - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupGetRedirectTest(const base::Closure& complete_callback) { + void SetupGetRedirectTest(base::OnceClosure complete_callback) { // Start with the normal get test. SetupGetTestShared(); @@ -1786,10 +1794,10 @@ class RequestTestRunner : public base::RefCountedThreadSafe { headerMap.insert(std::make_pair("Location", settings_.request->GetURL())); settings_.redirect_response->SetHeaderMap(headerMap); - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupGetRedirectStopTest(const base::Closure& complete_callback) { + void SetupGetRedirectStopTest(base::OnceClosure complete_callback) { settings_.request = CefRequest::Create(); settings_.request->SetURL(GetTestURL("GetTest.html")); settings_.request->SetMethod("GET"); @@ -1824,10 +1832,10 @@ class RequestTestRunner : public base::RefCountedThreadSafe { settings_.expected_send_count = 1; settings_.expected_receive_count = 1; - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupGetRedirectLocationTest(const base::Closure& complete_callback) { + void SetupGetRedirectLocationTest(base::OnceClosure complete_callback) { // Start with the normal get test. SetupGetTestShared(); @@ -1845,10 +1853,10 @@ class RequestTestRunner : public base::RefCountedThreadSafe { headerMap.insert(std::make_pair("LoCaTioN", GetTestPath("GetTest.html"))); settings_.redirect_response->SetHeaderMap(headerMap); - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupGetReferrerTest(const base::Closure& complete_callback) { + void SetupGetReferrerTest(base::OnceClosure complete_callback) { settings_.request = CefRequest::Create(); settings_.request->SetURL(GetTestURL("GetTest.html")); settings_.request->SetMethod("GET"); @@ -1865,10 +1873,10 @@ class RequestTestRunner : public base::RefCountedThreadSafe { settings_.response_data = "GET TEST SUCCESS"; - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupGetAuthTest(const base::Closure& complete_callback) { + void SetupGetAuthTest(base::OnceClosure complete_callback) { // Start with the normal get test. SetupGetTestShared(); @@ -1887,7 +1895,7 @@ class RequestTestRunner : public base::RefCountedThreadSafe { settings_.expected_receive_count = 2; settings_.expected_send_count = 2; - complete_callback.Run(); + std::move(complete_callback).Run(); } void SetupPostTestShared() { @@ -1904,12 +1912,12 @@ class RequestTestRunner : public base::RefCountedThreadSafe { settings_.response_data = "POST TEST SUCCESS"; } - void SetupPostTest(const base::Closure& complete_callback) { + void SetupPostTest(base::OnceClosure complete_callback) { SetupPostTestShared(); - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupPostFileTest(const base::Closure& complete_callback) { + void SetupPostFileTest(base::OnceClosure complete_callback) { // This test is only supported in the browser process. EXPECT_TRUE(is_browser_process_); @@ -1925,11 +1933,11 @@ class RequestTestRunner : public base::RefCountedThreadSafe { settings_.response_data = "POST TEST SUCCESS"; CefPostTask(TID_FILE_USER_VISIBLE, - base::Bind(&RequestTestRunner::SetupPostFileTestContinue, this, - complete_callback)); + base::BindOnce(&RequestTestRunner::SetupPostFileTestContinue, + this, std::move(complete_callback))); } - void SetupPostFileTestContinue(const base::Closure& complete_callback) { + void SetupPostFileTestContinue(base::OnceClosure complete_callback) { EXPECT_TRUE(CefCurrentlyOn(TID_FILE_USER_VISIBLE)); EXPECT_TRUE(post_file_tmpdir_.CreateUniqueTempDir()); @@ -1941,10 +1949,10 @@ class RequestTestRunner : public base::RefCountedThreadSafe { EXPECT_EQ(static_cast(sizeof(content) - 1), write_ct); SetUploadFile(settings_.request, path); - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupPostWithProgressTest(const base::Closure& complete_callback) { + void SetupPostWithProgressTest(base::OnceClosure complete_callback) { // Start with the normal post test. SetupPostTestShared(); @@ -1953,10 +1961,10 @@ class RequestTestRunner : public base::RefCountedThreadSafe { settings_.expect_upload_progress = true; - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupPostRedirectTest(const base::Closure& complete_callback) { + void SetupPostRedirectTest(base::OnceClosure complete_callback) { // Start with the normal post test. SetupPostTestShared(); @@ -1976,10 +1984,10 @@ class RequestTestRunner : public base::RefCountedThreadSafe { headerMap.insert(std::make_pair("Location", settings_.request->GetURL())); settings_.redirect_response->SetHeaderMap(headerMap); - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupPostRedirectToGetTest(const base::Closure& complete_callback) { + void SetupPostRedirectToGetTest(base::OnceClosure complete_callback) { // Start with the normal post test. SetupPostTestShared(); @@ -2005,10 +2013,10 @@ class RequestTestRunner : public base::RefCountedThreadSafe { headerMap.insert(std::make_pair("Location", settings_.request->GetURL())); settings_.redirect_response->SetHeaderMap(headerMap); - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupHeadTest(const base::Closure& complete_callback) { + void SetupHeadTest(base::OnceClosure complete_callback) { settings_.request = CefRequest::Create(); settings_.request->SetURL(GetTestURL("HeadTest.html")); settings_.request->SetMethod("HEAD"); @@ -2024,7 +2032,7 @@ class RequestTestRunner : public base::RefCountedThreadSafe { settings_.expect_download_progress = false; settings_.expect_download_data = false; - complete_callback.Run(); + std::move(complete_callback).Run(); } void SetupCacheShared(const std::string& name, bool with_cache_control) { @@ -2042,7 +2050,7 @@ class RequestTestRunner : public base::RefCountedThreadSafe { } } - void SetupCacheWithControlTest(const base::Closure& complete_callback) { + void SetupCacheWithControlTest(base::OnceClosure complete_callback) { SetupCacheShared("CacheWithControlTest.html", true); // Send multiple requests. With the Cache-Control response header the 2nd+ @@ -2050,24 +2058,24 @@ class RequestTestRunner : public base::RefCountedThreadSafe { settings_.expected_send_count = 3; settings_.expected_receive_count = 1; settings_.setup_next_request = - base::Bind(&RequestTestRunner::SetupCacheWithControlTestNext, this); + base::BindOnce(&RequestTestRunner::SetupCacheWithControlTestNext, this); - complete_callback.Run(); + std::move(complete_callback).Run(); } void SetupCacheWithControlTestNext(int next_send_count, - const base::Closure& complete_callback) { + base::OnceClosure complete_callback) { // Only handle from the cache. settings_.expect_response_was_cached = true; // The following requests will use the same setup, so no more callbacks // are required. - settings_.setup_next_request.Reset(); + EXPECT_TRUE(settings_.setup_next_request.is_null()); - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupCacheWithoutControlTest(const base::Closure& complete_callback) { + void SetupCacheWithoutControlTest(base::OnceClosure complete_callback) { SetupCacheShared("CacheWithoutControlTest.html", false); // Send multiple requests. Without the Cache-Control response header all @@ -2075,10 +2083,10 @@ class RequestTestRunner : public base::RefCountedThreadSafe { settings_.expected_send_count = 3; settings_.expected_receive_count = 3; - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupCacheSkipFlagTest(const base::Closure& complete_callback) { + void SetupCacheSkipFlagTest(base::OnceClosure complete_callback) { SetupCacheShared("CacheSkipFlagTest.html", true); // Skip the cache despite the the Cache-Control response header. @@ -2092,13 +2100,13 @@ class RequestTestRunner : public base::RefCountedThreadSafe { settings_.expected_send_count = 3; settings_.expected_receive_count = 2; settings_.setup_next_request = - base::Bind(&RequestTestRunner::SetupCacheSkipFlagTestNext, this); + base::BindOnce(&RequestTestRunner::SetupCacheSkipFlagTestNext, this); - complete_callback.Run(); + std::move(complete_callback).Run(); } void SetupCacheSkipFlagTestNext(int next_send_count, - const base::Closure& complete_callback) { + base::OnceClosure complete_callback) { // Recreate the request object because the existing object will now be // read-only. EXPECT_TRUE(settings_.request->IsReadOnly()); @@ -2107,13 +2115,13 @@ class RequestTestRunner : public base::RefCountedThreadSafe { // Expect a cached response. settings_.expect_response_was_cached = true; settings_.setup_next_request = - base::Bind(&RequestTestRunner::SetupCacheSkipFlagTestLast, this); + base::BindOnce(&RequestTestRunner::SetupCacheSkipFlagTestLast, this); - complete_callback.Run(); + std::move(complete_callback).Run(); } void SetupCacheSkipFlagTestLast(int next_send_count, - const base::Closure& complete_callback) { + base::OnceClosure complete_callback) { // Recreate the request object because the existing object will now be // read-only. EXPECT_TRUE(settings_.request->IsReadOnly()); @@ -2124,12 +2132,12 @@ class RequestTestRunner : public base::RefCountedThreadSafe { // Expect the cache to be skipped. settings_.expect_response_was_cached = false; - settings_.setup_next_request.Reset(); + EXPECT_TRUE(settings_.setup_next_request.is_null()); - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupCacheSkipHeaderTest(const base::Closure& complete_callback) { + void SetupCacheSkipHeaderTest(base::OnceClosure complete_callback) { SetupCacheShared("CacheSkipHeaderTest.html", true); // Skip the cache despite the the Cache-Control response header. @@ -2145,13 +2153,13 @@ class RequestTestRunner : public base::RefCountedThreadSafe { settings_.expected_send_count = 3; settings_.expected_receive_count = 2; settings_.setup_next_request = - base::Bind(&RequestTestRunner::SetupCacheSkipHeaderTestNext, this); + base::BindOnce(&RequestTestRunner::SetupCacheSkipHeaderTestNext, this); - complete_callback.Run(); + std::move(complete_callback).Run(); } void SetupCacheSkipHeaderTestNext(int next_send_count, - const base::Closure& complete_callback) { + base::OnceClosure complete_callback) { // Recreate the request object because the existing object will now be // read-only. EXPECT_TRUE(settings_.request->IsReadOnly()); @@ -2160,13 +2168,13 @@ class RequestTestRunner : public base::RefCountedThreadSafe { // Expect a cached response. settings_.expect_response_was_cached = true; settings_.setup_next_request = - base::Bind(&RequestTestRunner::SetupCacheSkipHeaderTestLast, this); + base::BindOnce(&RequestTestRunner::SetupCacheSkipHeaderTestLast, this); - complete_callback.Run(); + std::move(complete_callback).Run(); } void SetupCacheSkipHeaderTestLast(int next_send_count, - const base::Closure& complete_callback) { + base::OnceClosure complete_callback) { // Recreate the request object because the existing object will now be // read-only. EXPECT_TRUE(settings_.request->IsReadOnly()); @@ -2177,12 +2185,12 @@ class RequestTestRunner : public base::RefCountedThreadSafe { // Expect the cache to be skipped. settings_.expect_response_was_cached = false; - settings_.setup_next_request.Reset(); + EXPECT_TRUE(settings_.setup_next_request.is_null()); - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupCacheOnlyFailureFlagTest(const base::Closure& complete_callback) { + void SetupCacheOnlyFailureFlagTest(base::OnceClosure complete_callback) { SetupCacheShared("CacheOnlyFailureFlagTest.html", true); // Only handle from the cache. @@ -2196,10 +2204,10 @@ class RequestTestRunner : public base::RefCountedThreadSafe { // The request is expected to fail. settings_.SetRequestFailureExpected(ERR_CACHE_MISS); - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupCacheOnlyFailureHeaderTest(const base::Closure& complete_callback) { + void SetupCacheOnlyFailureHeaderTest(base::OnceClosure complete_callback) { SetupCacheShared("CacheOnlyFailureFlagTest.html", true); // Only handle from the cache. @@ -2215,10 +2223,10 @@ class RequestTestRunner : public base::RefCountedThreadSafe { // The request is expected to fail. settings_.SetRequestFailureExpected(ERR_CACHE_MISS); - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupCacheOnlySuccessFlagTest(const base::Closure& complete_callback) { + void SetupCacheOnlySuccessFlagTest(base::OnceClosure complete_callback) { SetupCacheShared("CacheOnlySuccessFlagTest.html", false); // Send multiple requests. The 1st request will be handled normally. The @@ -2227,13 +2235,13 @@ class RequestTestRunner : public base::RefCountedThreadSafe { settings_.expected_send_count = 3; settings_.expected_receive_count = 1; settings_.setup_next_request = - base::Bind(&RequestTestRunner::SetupCacheOnlySuccessFlagNext, this); + base::BindOnce(&RequestTestRunner::SetupCacheOnlySuccessFlagNext, this); - complete_callback.Run(); + std::move(complete_callback).Run(); } void SetupCacheOnlySuccessFlagNext(int next_send_count, - const base::Closure& complete_callback) { + base::OnceClosure complete_callback) { // Recreate the request object because the existing object will now be // read-only. EXPECT_TRUE(settings_.request->IsReadOnly()); @@ -2245,12 +2253,12 @@ class RequestTestRunner : public base::RefCountedThreadSafe { // The following requests will use the same setup, so no more callbacks // are required. - settings_.setup_next_request.Reset(); + EXPECT_TRUE(settings_.setup_next_request.is_null()); - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupCacheOnlySuccessHeaderTest(const base::Closure& complete_callback) { + void SetupCacheOnlySuccessHeaderTest(base::OnceClosure complete_callback) { SetupCacheShared("CacheOnlySuccessHeaderTest.html", false); // Send multiple requests. The 1st request will be handled normally. The @@ -2258,14 +2266,14 @@ class RequestTestRunner : public base::RefCountedThreadSafe { // require cached data. settings_.expected_send_count = 3; settings_.expected_receive_count = 1; - settings_.setup_next_request = - base::Bind(&RequestTestRunner::SetupCacheOnlySuccessHeaderNext, this); + settings_.setup_next_request = base::BindOnce( + &RequestTestRunner::SetupCacheOnlySuccessHeaderNext, this); - complete_callback.Run(); + std::move(complete_callback).Run(); } void SetupCacheOnlySuccessHeaderNext(int next_send_count, - const base::Closure& complete_callback) { + base::OnceClosure complete_callback) { // Recreate the request object because the existing object will now be // read-only. EXPECT_TRUE(settings_.request->IsReadOnly()); @@ -2279,12 +2287,12 @@ class RequestTestRunner : public base::RefCountedThreadSafe { // The following requests will use the same setup, so no more callbacks // are required. - settings_.setup_next_request.Reset(); + EXPECT_TRUE(settings_.setup_next_request.is_null()); - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupCacheDisableFlagTest(const base::Closure& complete_callback) { + void SetupCacheDisableFlagTest(base::OnceClosure complete_callback) { SetupCacheShared("CacheDisableFlagTest.html", true); // Disable the cache despite the the Cache-Control response header. @@ -2297,13 +2305,13 @@ class RequestTestRunner : public base::RefCountedThreadSafe { settings_.expected_send_count = 3; settings_.expected_receive_count = 1; settings_.setup_next_request = - base::Bind(&RequestTestRunner::SetupCacheDisableFlagTestNext, this); + base::BindOnce(&RequestTestRunner::SetupCacheDisableFlagTestNext, this); - complete_callback.Run(); + std::move(complete_callback).Run(); } void SetupCacheDisableFlagTestNext(int next_send_count, - const base::Closure& complete_callback) { + base::OnceClosure complete_callback) { // Recreate the request object because the existing object will now be // read-only. EXPECT_TRUE(settings_.request->IsReadOnly()); @@ -2317,12 +2325,12 @@ class RequestTestRunner : public base::RefCountedThreadSafe { // The following requests will use the same setup, so no more callbacks // are required. - settings_.setup_next_request.Reset(); + EXPECT_TRUE(settings_.setup_next_request.is_null()); - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupCacheDisableHeaderTest(const base::Closure& complete_callback) { + void SetupCacheDisableHeaderTest(base::OnceClosure complete_callback) { SetupCacheShared("CacheDisableHeaderTest.html", true); // Disable the cache despite the the Cache-Control response header. @@ -2336,14 +2344,14 @@ class RequestTestRunner : public base::RefCountedThreadSafe { // from the cache should fail. settings_.expected_send_count = 3; settings_.expected_receive_count = 1; - settings_.setup_next_request = - base::Bind(&RequestTestRunner::SetupCacheDisableHeaderTestNext, this); + settings_.setup_next_request = base::BindOnce( + &RequestTestRunner::SetupCacheDisableHeaderTestNext, this); - complete_callback.Run(); + std::move(complete_callback).Run(); } void SetupCacheDisableHeaderTestNext(int next_send_count, - const base::Closure& complete_callback) { + base::OnceClosure complete_callback) { // Recreate the request object because the existing object will now be // read-only. EXPECT_TRUE(settings_.request->IsReadOnly()); @@ -2359,13 +2367,12 @@ class RequestTestRunner : public base::RefCountedThreadSafe { // The following requests will use the same setup, so no more callbacks // are required. - settings_.setup_next_request.Reset(); + EXPECT_TRUE(settings_.setup_next_request.is_null()); - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupIncompleteProcessRequestTest( - const base::Closure& complete_callback) { + void SetupIncompleteProcessRequestTest(base::OnceClosure complete_callback) { // Start with the normal get test. SetupGetTestShared(); @@ -2379,10 +2386,10 @@ class RequestTestRunner : public base::RefCountedThreadSafe { settings_.expect_download_progress = false; settings_.expect_download_data = false; - complete_callback.Run(); + std::move(complete_callback).Run(); } - void SetupIncompleteReadResponseTest(const base::Closure& complete_callback) { + void SetupIncompleteReadResponseTest(base::OnceClosure complete_callback) { // Start with the normal get test. SetupGetTestShared(); @@ -2399,11 +2406,11 @@ class RequestTestRunner : public base::RefCountedThreadSafe { settings_.expect_download_progress = is_browser_process_; settings_.expect_download_data = false; - complete_callback.Run(); + std::move(complete_callback).Run(); } // Send a request. |complete_callback| will be executed on request completion. - void SendRequest(const test_request::RequestDoneCallback& done_callback) { + void SendRequest(test_request::RequestDoneCallback done_callback) { if (!is_browser_process_) { // Render process requests must use CefFrame::CreateURLRequest. EXPECT_TRUE(use_frame_method_); @@ -2431,11 +2438,10 @@ class RequestTestRunner : public base::RefCountedThreadSafe { config.request_context_ = request_context_; } - test_request::Send(config, done_callback); + test_request::Send(config, std::move(done_callback)); if (settings_.incomplete_type != RequestRunSettings::INCOMPLETE_NONE) { - incomplete_request_callback_.Run(); - incomplete_request_callback_.Reset(); + std::move(incomplete_request_callback_).Run(); } } @@ -2508,32 +2514,32 @@ class RequestTestRunner : public base::RefCountedThreadSafe { } // Run a test with a single request. - void SingleRunTest(const base::Closure& complete_callback) { - SendRequest(base::Bind(&RequestTestRunner::SingleRunTestComplete, this, - complete_callback)); + void SingleRunTest(base::OnceClosure complete_callback) { + SendRequest(base::BindOnce(&RequestTestRunner::SingleRunTestComplete, this, + std::move(complete_callback))); } - void SingleRunTestComplete(const base::Closure& complete_callback, + void SingleRunTestComplete(base::OnceClosure complete_callback, const test_request::State& completed_client) { VerifyResponse(&completed_client); - complete_callback.Run(); + std::move(complete_callback).Run(); } // Run a test with multiple requests. - void MultipleRunTest(const base::Closure& complete_callback) { + void MultipleRunTest(base::OnceClosure complete_callback) { EXPECT_GT(settings_.expected_send_count, 0); EXPECT_GE(settings_.expected_receive_count, 0); - MultipleRunTestContinue(complete_callback, 1); + MultipleRunTestContinue(std::move(complete_callback), 1); } - void MultipleRunTestContinue(const base::Closure& complete_callback, + void MultipleRunTestContinue(base::OnceClosure complete_callback, int send_count) { // Send the next request. - SendRequest(base::Bind(&RequestTestRunner::MultipleRunTestNext, this, - complete_callback, send_count)); + SendRequest(base::BindOnce(&RequestTestRunner::MultipleRunTestNext, this, + std::move(complete_callback), send_count)); } - void MultipleRunTestNext(const base::Closure& complete_callback, + void MultipleRunTestNext(base::OnceClosure complete_callback, int send_count, const test_request::State& completed_client) { // Verify the completed request. @@ -2541,24 +2547,21 @@ class RequestTestRunner : public base::RefCountedThreadSafe { if (send_count == settings_.expected_send_count) { // All requests complete. - complete_callback.Run(); + std::move(complete_callback).Run(); return; } const int next_send_count = send_count + 1; - const base::Closure& continue_callback = - base::Bind(&RequestTestRunner::MultipleRunTestContinue, this, - complete_callback, next_send_count); + auto continue_callback = + base::BindOnce(&RequestTestRunner::MultipleRunTestContinue, this, + std::move(complete_callback), next_send_count); if (!settings_.setup_next_request.is_null()) { // Provide an opportunity to modify expectations before the next request. - // Copy the callback object in case |settings_.setup_next_request| is - // modified as a result of the call. - RequestRunSettings::NextRequestCallback next_callback = - settings_.setup_next_request; - next_callback.Run(next_send_count, continue_callback); + std::move(settings_.setup_next_request) + .Run(next_send_count, std::move(continue_callback)); } else { - continue_callback.Run(); + std::move(continue_callback).Run(); } } @@ -2570,43 +2573,44 @@ class RequestTestRunner : public base::RefCountedThreadSafe { test_map_.insert(std::make_pair(test_mode, entry)); } - void CompleteOnCorrectThread(const base::Closure& complete_callback) { + void CompleteOnCorrectThread(base::OnceClosure complete_callback) { if (!owner_task_runner_->BelongsToCurrentThread()) { owner_task_runner_->PostTask(CefCreateClosureTask( - base::Bind(&RequestTestRunner::CompleteOnCorrectThread, this, - complete_callback))); + base::BindOnce(&RequestTestRunner::CompleteOnCorrectThread, this, + std::move(complete_callback)))); return; } - complete_callback.Run(); + std::move(complete_callback).Run(); } - void RunDeleteTempDirectory(const base::Closure& complete_callback) { + void RunDeleteTempDirectory(base::OnceClosure complete_callback) { EXPECT_TRUE(CefCurrentlyOn(TID_FILE_USER_VISIBLE)); EXPECT_TRUE(post_file_tmpdir_.Delete()); EXPECT_TRUE(post_file_tmpdir_.IsEmpty()); // Continue with test shutdown. - RunShutdown(complete_callback); + RunShutdown(std::move(complete_callback)); } - void RunShutdown(const base::Closure& complete_callback) { + void RunShutdown(base::OnceClosure complete_callback) { if (!owner_task_runner_->BelongsToCurrentThread()) { - owner_task_runner_->PostTask(CefCreateClosureTask(base::Bind( - &RequestTestRunner::RunShutdown, this, complete_callback))); + owner_task_runner_->PostTask(CefCreateClosureTask( + base::BindOnce(&RequestTestRunner::RunShutdown, this, + std::move(complete_callback)))); return; } if (is_browser_process_) { - ShutdownTestBackend(complete_callback); + ShutdownTestBackend(std::move(complete_callback)); } else { - complete_callback.Run(); + std::move(complete_callback).Run(); } } // Create the backend for the current test. Called during test setup. - void SetupTestBackend(const base::Closure& complete_callback) { + void SetupTestBackend(base::OnceClosure complete_callback) { // Backends are only created in the browser process. EXPECT_TRUE(is_browser_process_); @@ -2614,13 +2618,14 @@ class RequestTestRunner : public base::RefCountedThreadSafe { EXPECT_TRUE(settings_.response.get() || settings_.expected_status == UR_FAILED); - if (is_server_backend_) - StartServer(complete_callback); - else - AddSchemeHandler(complete_callback); + if (is_server_backend_) { + StartServer(std::move(complete_callback)); + } else { + AddSchemeHandler(std::move(complete_callback)); + } } - void StartServer(const base::Closure& complete_callback) { + void StartServer(base::OnceClosure complete_callback) { EXPECT_FALSE(server_handler_); server_handler_ = new RequestServerHandler(); @@ -2631,10 +2636,10 @@ class RequestTestRunner : public base::RefCountedThreadSafe { settings_.expected_receive_count); } - server_handler_->CreateServer(complete_callback); + server_handler_->CreateServer(std::move(complete_callback)); } - void AddSchemeHandler(const base::Closure& complete_callback) { + void AddSchemeHandler(base::OnceClosure complete_callback) { EXPECT_FALSE(scheme_factory_); // Add the factory registration. @@ -2648,34 +2653,35 @@ class RequestTestRunner : public base::RefCountedThreadSafe { // Any further calls will come from the IO thread. scheme_factory_->SetOwnerTaskRunner(CefTaskRunner::GetForThread(TID_IO)); - complete_callback.Run(); + std::move(complete_callback).Run(); } // Shutdown the backend for the current test. Called during test shutdown. - void ShutdownTestBackend(const base::Closure& complete_callback) { + void ShutdownTestBackend(base::OnceClosure complete_callback) { // Backends are only created in the browser process. EXPECT_TRUE(is_browser_process_); - if (is_server_backend_) - ShutdownServer(complete_callback); - else - RemoveSchemeHandler(complete_callback); + if (is_server_backend_) { + ShutdownServer(std::move(complete_callback)); + } else { + RemoveSchemeHandler(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 RemoveSchemeHandler(const base::Closure& complete_callback) { + void RemoveSchemeHandler(base::OnceClosure complete_callback) { EXPECT_TRUE(scheme_factory_); // Remove the factory registration. request_context_->RegisterSchemeHandlerFactory( GetRequestScheme(false), GetRequestHost(false, false), nullptr); - scheme_factory_->Shutdown(complete_callback); + scheme_factory_->Shutdown(std::move(complete_callback)); scheme_factory_ = nullptr; } @@ -2685,7 +2691,7 @@ class RequestTestRunner : public base::RefCountedThreadSafe { const bool run_in_browser_process_; // Used with incomplete request tests. - base::Closure incomplete_request_callback_; + base::OnceClosure incomplete_request_callback_; // Primary thread runner for the object that owns us. In the browser process // this will be the UI thread and in the renderer process this will be the @@ -2745,13 +2751,14 @@ class RequestRendererTest : public ClientAppRenderer::Delegate { test_mode_ = static_cast(args->GetInt(0)); test_runner_ = new RequestTestRunner( false, args->GetBool(1), use_frame_method, false, - base::Bind(&RequestRendererTest::OnIncompleteRequest, this)); + base::BindOnce(&RequestRendererTest::OnIncompleteRequest, this)); test_runner_->Initialize(); // Setup the test. This will create the objects that we test against but // not register any backend (because we're in the render process). test_runner_->SetupTest( - test_mode_, base::Bind(&RequestRendererTest::OnSetupComplete, this)); + test_mode_, + base::BindOnce(&RequestRendererTest::OnSetupComplete, this)); return true; } @@ -2767,7 +2774,7 @@ class RequestRendererTest : public ClientAppRenderer::Delegate { // Run the test. test_runner_->RunTest( test_mode_, frame_, - base::Bind(&RequestRendererTest::OnRunComplete, this)); + base::BindOnce(&RequestRendererTest::OnRunComplete, this)); } void OnRunComplete() { @@ -2775,7 +2782,7 @@ class RequestRendererTest : public ClientAppRenderer::Delegate { // Shutdown the test. test_runner_->ShutdownTest( - base::Bind(&RequestRendererTest::OnShutdownComplete, this)); + base::BindOnce(&RequestRendererTest::OnShutdownComplete, this)); } void OnIncompleteRequest() { @@ -2859,7 +2866,7 @@ class RequestTestHandler : public TestHandler { void PreSetupStart() { CefPostTask(TID_FILE_USER_VISIBLE, - base::Bind(&RequestTestHandler::PreSetupFileTasks, this)); + base::BindOnce(&RequestTestHandler::PreSetupFileTasks, this)); } void PreSetupFileTasks() { @@ -2873,7 +2880,7 @@ class RequestTestHandler : public TestHandler { } CefPostTask(TID_UI, - base::Bind(&RequestTestHandler::PreSetupContinue, this)); + base::BindOnce(&RequestTestHandler::PreSetupContinue, this)); } void PreSetupContinue() { @@ -2881,7 +2888,7 @@ class RequestTestHandler : public TestHandler { test_runner_ = new RequestTestRunner( true, test_server_backend_, test_frame_method_, test_in_browser_, - base::Bind(&RequestTestHandler::OnIncompleteRequest, this)); + base::BindOnce(&RequestTestHandler::OnIncompleteRequest, this)); test_runner_->Initialize(); // Get or create the request context. @@ -2925,27 +2932,27 @@ class RequestTestHandler : public TestHandler { void PreSetupComplete() { if (!CefCurrentlyOn(TID_UI)) { CefPostTask(TID_UI, - base::Bind(&RequestTestHandler::PreSetupComplete, this)); + base::BindOnce(&RequestTestHandler::PreSetupComplete, this)); return; } // Setup the test. This will create the objects that we test against and // register the backend. test_runner_->SetupTest( - test_mode_, base::Bind(&RequestTestHandler::OnSetupComplete, this)); + test_mode_, base::BindOnce(&RequestTestHandler::OnSetupComplete, this)); } // Browser process setup is complete. void OnSetupComplete() { // Start post-setup actions. SetTestCookie(test_runner_->GetRequestContext(), test_server_backend_, - base::Bind(&RequestTestHandler::PostSetupComplete, this)); + base::BindOnce(&RequestTestHandler::PostSetupComplete, this)); } void PostSetupComplete() { if (!CefCurrentlyOn(TID_UI)) { CefPostTask(TID_UI, - base::Bind(&RequestTestHandler::PostSetupComplete, this)); + base::BindOnce(&RequestTestHandler::PostSetupComplete, this)); return; } @@ -2961,7 +2968,7 @@ class RequestTestHandler : public TestHandler { test_running_ = true; test_runner_->RunTest( test_mode_, nullptr /* frame */, - base::Bind(&RequestTestHandler::OnRunComplete, this)); + base::BindOnce(&RequestTestHandler::OnRunComplete, this)); } } else { AddResource(test_url_, "TEST", "text/html"); @@ -3013,7 +3020,7 @@ class RequestTestHandler : public TestHandler { test_running_ = true; test_runner_->RunTest( test_mode_, frame, - base::Bind(&RequestTestHandler::OnRunComplete, this)); + base::BindOnce(&RequestTestHandler::OnRunComplete, this)); return; } @@ -3080,8 +3087,8 @@ class RequestTestHandler : public TestHandler { // close to abort in-progress requests. void OnIncompleteRequest() { if (!CefCurrentlyOn(TID_UI)) { - CefPostTask(TID_UI, - base::Bind(&RequestTestHandler::OnIncompleteRequest, this)); + CefPostTask(TID_UI, base::BindOnce( + &RequestTestHandler::OnIncompleteRequest, this)); return; } @@ -3093,20 +3100,20 @@ class RequestTestHandler : public TestHandler { // triggered by browser destruction. SetSignalCompletionWhenAllBrowsersClose(false); CefPostDelayedTask( - TID_UI, base::Bind(&TestHandler::CloseBrowser, GetBrowser(), false), + TID_UI, base::BindOnce(&TestHandler::CloseBrowser, GetBrowser(), false), 1000); } // Test run is complete. It ran in either the browser or render process. void OnRunComplete() { GetTestCookie(test_runner_->GetRequestContext(), test_server_backend_, - base::Bind(&RequestTestHandler::PostRunComplete, this)); + base::BindOnce(&RequestTestHandler::PostRunComplete, this)); } void PostRunComplete(bool has_save_cookie) { if (!CefCurrentlyOn(TID_UI)) { - CefPostTask(TID_UI, base::Bind(&RequestTestHandler::PostRunComplete, this, - has_save_cookie)); + CefPostTask(TID_UI, base::BindOnce(&RequestTestHandler::PostRunComplete, + this, has_save_cookie)); return; } @@ -3114,7 +3121,7 @@ class RequestTestHandler : public TestHandler { // Shut down the browser side of the test. test_runner_->ShutdownTest( - base::Bind(&RequestTestHandler::MaybeClearAuthCredentials, this)); + base::BindOnce(&RequestTestHandler::MaybeClearAuthCredentials, this)); } void MaybeClearAuthCredentials() { @@ -3124,7 +3131,7 @@ class RequestTestHandler : public TestHandler { // test runs when using the global request context. test_runner_->GetRequestContext()->ClearHttpAuthCredentials( new TestCompletionCallback( - base::Bind(&RequestTestHandler::DestroyTest, this))); + base::BindOnce(&RequestTestHandler::DestroyTest, this))); return; } @@ -3179,7 +3186,7 @@ class RequestTestHandler : public TestHandler { void OnTestComplete() { if (!CefCurrentlyOn(TID_UI)) { CefPostTask(TID_UI, - base::Bind(&RequestTestHandler::OnTestComplete, this)); + base::BindOnce(&RequestTestHandler::OnTestComplete, this)); return; } @@ -3475,7 +3482,8 @@ class InvalidURLTestClient : public CefURLRequestClient { } void RunTest() { - CefPostTask(TID_UI, base::Bind(&InvalidURLTestClient::RunOnUIThread, this)); + CefPostTask(TID_UI, + base::BindOnce(&InvalidURLTestClient::RunOnUIThread, this)); // Wait for the test to complete. event_->Wait(); @@ -3486,8 +3494,8 @@ class InvalidURLTestClient : public CefURLRequestClient { EXPECT_EQ(ERR_UNKNOWN_URL_SCHEME, client->GetRequestError()); // Let the call stack unwind before signaling completion. - CefPostTask(TID_UI, - base::Bind(&InvalidURLTestClient::CompleteOnUIThread, this)); + CefPostTask(TID_UI, base::BindOnce( + &InvalidURLTestClient::CompleteOnUIThread, this)); } void OnUploadProgress(CefRefPtr request, diff --git a/tests/ceftests/v8_unittest.cc b/tests/ceftests/v8_unittest.cc index 9c4fc308c..a7f392c0c 100644 --- a/tests/ceftests/v8_unittest.cc +++ b/tests/ceftests/v8_unittest.cc @@ -2580,10 +2580,10 @@ class V8RendererTest : public ClientAppRenderer::Delegate, CefRefPtr& 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); } diff --git a/tests/ceftests/views/button_unittest.cc b/tests/ceftests/views/button_unittest.cc index 059b29088..d437d15ce 100644 --- a/tests/ceftests/views/button_unittest.cc +++ b/tests/ceftests/views/button_unittest.cc @@ -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 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(); + 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 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(); + 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 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(); + config->on_window_created = + base::BindOnce(RunMenuButtonCustomPopupClick, can_activate); + config->close_window = false; + TestWindowDelegate::RunTest(event, std::move(config)); } void MenuButtonCustomPopupActivateImpl(CefRefPtr event) { diff --git a/tests/ceftests/views/scroll_view_unittest.cc b/tests/ceftests/views/scroll_view_unittest.cc index a212be003..67c4b1dce 100644 --- a/tests/ceftests/views/scroll_view_unittest.cc +++ b/tests/ceftests/views/scroll_view_unittest.cc @@ -132,9 +132,10 @@ void RunScrollViewLayout(bool with_delegate, CefRefPtr window) { } void ScrollViewLayout(CefRefPtr 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(); + config->on_window_created = + base::BindOnce(RunScrollViewLayout, with_delegate); + TestWindowDelegate::RunTest(event, std::move(config)); } void ScrollViewLayoutWithDelegateImpl(CefRefPtr event) { diff --git a/tests/ceftests/views/test_window_delegate.cc b/tests/ceftests/views/test_window_delegate.cc index 0d5ee47e6..841d58dc6 100644 --- a/tests/ceftests/views/test_window_delegate.cc +++ b/tests/ceftests/views/test_window_delegate.cc @@ -27,10 +27,10 @@ const int TestWindowDelegate::kWSize = 400; // static void TestWindowDelegate::RunTest(CefRefPtr event, - const Config& config) { + std::unique_ptr 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 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 window) { @@ -74,15 +74,15 @@ void TestWindowDelegate::OnWindowCreated(CefRefPtr 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 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 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 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 window) { } bool TestWindowDelegate::IsFrameless(CefRefPtr window) { - return config_.frameless; + return config_->frameless; } CefRect TestWindowDelegate::GetInitialBounds(CefRefPtr 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 view) { bool TestWindowDelegate::OnAccelerator(CefRefPtr 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 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 event, - const Config& config, + std::unique_ptr 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() { diff --git a/tests/ceftests/views/test_window_delegate.h b/tests/ceftests/views/test_window_delegate.h index 1c7b0f90e..385998da0 100644 --- a/tests/ceftests/views/test_window_delegate.h +++ b/tests/ceftests/views/test_window_delegate.h @@ -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 + #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)> OnWindowCreatedCallback; - typedef base::Callback)> OnWindowDestroyedCallback; - typedef base::Callback, int)> OnAcceleratorCallback; - typedef base::Callback, const CefKeyEvent&)> - OnKeyEventCallback; + using OnWindowCreatedCallback = + base::OnceCallback)>; + using OnWindowDestroyedCallback = + base::OnceCallback)>; + using OnAcceleratorCallback = + base::RepeatingCallback, int)>; + using OnKeyEventCallback = + base::RepeatingCallback, 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 event, const Config& config); + static void RunTest(CefRefPtr event, + std::unique_ptr config); // CefWindowDelegate methods: void OnWindowCreated(CefRefPtr window) override; @@ -51,7 +57,7 @@ class TestWindowDelegate : public CefWindowDelegate { private: TestWindowDelegate(CefRefPtr event, - const Config& config, + std::unique_ptr config, const CefSize& window_size); ~TestWindowDelegate() override; @@ -59,7 +65,7 @@ class TestWindowDelegate : public CefWindowDelegate { void OnTimeoutWindow(); CefRefPtr event_; - const Config config_; + std::unique_ptr config_; const CefSize window_size_; CefRefPtr window_; diff --git a/tests/ceftests/views/textfield_unittest.cc b/tests/ceftests/views/textfield_unittest.cc index eec745954..77633a7c4 100644 --- a/tests/ceftests/views/textfield_unittest.cc +++ b/tests/ceftests/views/textfield_unittest.cc @@ -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 window) { } void TextfieldKeyEventImpl(CefRefPtr event) { - TestWindowDelegate::Config config; - config.on_window_created = base::Bind(RunTextfieldKeyEvent); - config.close_window = false; - TestWindowDelegate::RunTest(event, config); + auto config = std::make_unique(); + config->on_window_created = base::BindOnce(RunTextfieldKeyEvent); + config->close_window = false; + TestWindowDelegate::RunTest(event, std::move(config)); } } // namespace diff --git a/tests/ceftests/views/window_unittest.cc b/tests/ceftests/views/window_unittest.cc index ad1b5c981..058caf024 100644 --- a/tests/ceftests/views/window_unittest.cc +++ b/tests/ceftests/views/window_unittest.cc @@ -37,14 +37,14 @@ void ExpectCloseRects(const CefRect& expected, } void WindowCreateImpl(CefRefPtr event) { - TestWindowDelegate::Config config; - TestWindowDelegate::RunTest(event, config); + auto config = std::make_unique(); + TestWindowDelegate::RunTest(event, std::move(config)); } void WindowCreateFramelessImpl(CefRefPtr event) { - TestWindowDelegate::Config config; - config.frameless = true; - TestWindowDelegate::RunTest(event, config); + auto config = std::make_unique(); + config->frameless = true; + TestWindowDelegate::RunTest(event, std::move(config)); } void RunWindowShow(CefRefPtr window) { @@ -56,10 +56,10 @@ void RunWindowShow(CefRefPtr window) { } void WindowCreateWithOriginImpl(CefRefPtr 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(); + config->window_origin = {100, 200}; + config->on_window_created = base::BindOnce(RunWindowShow); + TestWindowDelegate::RunTest(event, std::move(config)); } void RunWindowShowHide(CefRefPtr window) { @@ -70,16 +70,16 @@ void RunWindowShowHide(CefRefPtr window) { } void WindowShowHideImpl(CefRefPtr event) { - TestWindowDelegate::Config config; - config.on_window_created = base::Bind(RunWindowShowHide); - TestWindowDelegate::RunTest(event, config); + auto config = std::make_unique(); + config->on_window_created = base::BindOnce(RunWindowShowHide); + TestWindowDelegate::RunTest(event, std::move(config)); } void WindowShowHideFramelessImpl(CefRefPtr event) { - TestWindowDelegate::Config config; - config.on_window_created = base::Bind(RunWindowShowHide); - config.frameless = true; - TestWindowDelegate::RunTest(event, config); + auto config = std::make_unique(); + 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 window) { } void WindowLayoutAndCoordsImpl(CefRefPtr event) { - TestWindowDelegate::Config config; - config.on_window_created = base::Bind(RunWindowLayoutAndCoords); - TestWindowDelegate::RunTest(event, config); + auto config = std::make_unique(); + config->on_window_created = base::BindOnce(RunWindowLayoutAndCoords); + TestWindowDelegate::RunTest(event, std::move(config)); } void WindowLayoutAndCoordsFramelessImpl(CefRefPtr event) { - TestWindowDelegate::Config config; - config.on_window_created = base::Bind(RunWindowLayoutAndCoords); - config.frameless = true; - TestWindowDelegate::RunTest(event, config); + auto config = std::make_unique(); + config->on_window_created = base::BindOnce(RunWindowLayoutAndCoords); + config->frameless = true; + TestWindowDelegate::RunTest(event, std::move(config)); } void VerifyRestore(CefRefPtr window) { @@ -234,7 +234,8 @@ void VerifyMaximize(CefRefPtr 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 window) { @@ -247,22 +248,23 @@ void RunWindowMaximize(CefRefPtr 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 event) { - TestWindowDelegate::Config config; - config.on_window_created = base::Bind(RunWindowMaximize); - config.close_window = false; - TestWindowDelegate::RunTest(event, config); + auto config = std::make_unique(); + config->on_window_created = base::BindOnce(RunWindowMaximize); + config->close_window = false; + TestWindowDelegate::RunTest(event, std::move(config)); } void WindowMaximizeFramelessImpl(CefRefPtr 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(); + config->on_window_created = base::BindOnce(RunWindowMaximize); + config->frameless = true; + config->close_window = false; + TestWindowDelegate::RunTest(event, std::move(config)); } void VerifyMinimize(CefRefPtr window) { @@ -276,7 +278,8 @@ void VerifyMinimize(CefRefPtr 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 window) { @@ -289,22 +292,23 @@ void RunWindowMinimize(CefRefPtr 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 event) { - TestWindowDelegate::Config config; - config.on_window_created = base::Bind(RunWindowMinimize); - config.close_window = false; - TestWindowDelegate::RunTest(event, config); + auto config = std::make_unique(); + config->on_window_created = base::BindOnce(RunWindowMinimize); + config->close_window = false; + TestWindowDelegate::RunTest(event, std::move(config)); } void WindowMinimizeFramelessImpl(CefRefPtr 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(); + config->on_window_created = base::BindOnce(RunWindowMinimize); + config->frameless = true; + config->close_window = false; + TestWindowDelegate::RunTest(event, std::move(config)); } void VerifyFullscreenExit(CefRefPtr window) { @@ -326,7 +330,7 @@ void VerifyFullscreen(CefRefPtr 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 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 event) { - TestWindowDelegate::Config config; - config.on_window_created = base::Bind(RunWindowFullscreen); - config.close_window = false; - TestWindowDelegate::RunTest(event, config); + auto config = std::make_unique(); + config->on_window_created = base::BindOnce(RunWindowFullscreen); + config->close_window = false; + TestWindowDelegate::RunTest(event, std::move(config)); } void WindowFullscreenFramelessImpl(CefRefPtr 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(); + config->on_window_created = base::BindOnce(RunWindowFullscreen); + config->frameless = true; + config->close_window = false; + TestWindowDelegate::RunTest(event, std::move(config)); } void RunWindowIcon(CefRefPtr window) { @@ -376,16 +380,16 @@ void RunWindowIcon(CefRefPtr window) { } void WindowIconImpl(CefRefPtr event) { - TestWindowDelegate::Config config; - config.on_window_created = base::Bind(RunWindowIcon); - TestWindowDelegate::RunTest(event, config); + auto config = std::make_unique(); + config->on_window_created = base::BindOnce(RunWindowIcon); + TestWindowDelegate::RunTest(event, std::move(config)); } void WindowIconFramelessImpl(CefRefPtr event) { - TestWindowDelegate::Config config; - config.on_window_created = base::Bind(RunWindowIcon); - config.frameless = true; - TestWindowDelegate::RunTest(event, config); + auto config = std::make_unique(); + 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 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 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(); + 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 diff --git a/tests/ceftests/waitable_event_unittest.cc b/tests/ceftests/waitable_event_unittest.cc index 000f816b4..abda26687 100644 --- a/tests/ceftests/waitable_event_unittest.cc +++ b/tests/ceftests/waitable_event_unittest.cc @@ -68,7 +68,7 @@ TEST(WaitableEventTest, WaitAndDelete) { CefRefPtr 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(); diff --git a/tests/ceftests/webui_unittest.cc b/tests/ceftests/webui_unittest.cc index d099cfddd..aca2f1365 100644 --- a/tests/ceftests/webui_unittest.cc +++ b/tests/ceftests/webui_unittest.cc @@ -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 + #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) { diff --git a/tests/shared/browser/extension_util.cc b/tests/shared/browser/extension_util.cc index 690dd27ad..7b774b866 100644 --- a/tests/shared/browser/extension_util.cc +++ b/tests/shared/browser/extension_util.cc @@ -4,6 +4,8 @@ #include "tests/shared/browser/extension_util.h" +#include + #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 /*manifest*/)> - ManifestCallback; +using ManifestCallback = + base::OnceCallback /*manifest*/)>; -void RunManifestCallback(const ManifestCallback& callback, +void RunManifestCallback(ManifestCallback callback, CefRefPtr 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 request_context, @@ -166,16 +169,17 @@ void LoadExtension(CefRefPtr request_context, CefRefPtr 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; } diff --git a/tests/shared/browser/main_message_loop.cc b/tests/shared/browser/main_message_loop.cc index 481e2b429..23446e06f 100644 --- a/tests/shared/browser/main_message_loop.cc +++ b/tests/shared/browser/main_message_loop.cc @@ -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)); } diff --git a/tests/shared/browser/main_message_loop.h b/tests/shared/browser/main_message_loop.h index a24900e87..8d8903fd8 100644 --- a/tests/shared/browser/main_message_loop.h +++ b/tests/shared/browser/main_message_loop.h @@ -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, base::Unretained(x))); + client::MainMessageLoop::Get()->PostClosure(base::BindOnce( + &DeleteOnMainThread::Destruct, base::Unretained(x))); } } };