From cc00fa88742bf43e319e07669e6fab0eba9b1851 Mon Sep 17 00:00:00 2001 From: Shelley Vohr Date: Thu, 2 May 2019 16:49:27 -0700 Subject: [PATCH] chore: convert base::Bind instances across some files (#18112) --- atom/browser/atom_download_manager_delegate.cc | 6 +++--- atom/browser/lib/bluetooth_chooser.cc | 10 +++++----- atom/browser/net/asar/url_request_asar_job.cc | 16 ++++++++-------- atom/browser/web_contents_permission_helper.cc | 10 +++++----- atom/browser/web_contents_permission_helper.h | 14 ++++++++------ atom/browser/web_dialog_helper.cc | 4 ++-- atom/common/promise_util.h | 4 +++- 7 files changed, 34 insertions(+), 30 deletions(-) diff --git a/atom/browser/atom_download_manager_delegate.cc b/atom/browser/atom_download_manager_delegate.cc index 2c2a12f8d12..ba418731f64 100644 --- a/atom/browser/atom_download_manager_delegate.cc +++ b/atom/browser/atom_download_manager_delegate.cc @@ -124,11 +124,11 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated( v8::Isolate* isolate = v8::Isolate::GetCurrent(); atom::util::Promise dialog_promise(isolate); auto dialog_callback = - base::Bind(&AtomDownloadManagerDelegate::OnDownloadSaveDialogDone, - base::Unretained(this), download_id, callback); + base::BindOnce(&AtomDownloadManagerDelegate::OnDownloadSaveDialogDone, + base::Unretained(this), download_id, callback); file_dialog::ShowSaveDialog(settings, std::move(dialog_promise)); - ignore_result(dialog_promise.Then(dialog_callback)); + ignore_result(dialog_promise.Then(std::move(dialog_callback))); } else { callback.Run(path, download::DownloadItem::TARGET_DISPOSITION_PROMPT, download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, path, diff --git a/atom/browser/lib/bluetooth_chooser.cc b/atom/browser/lib/bluetooth_chooser.cc index 2a70be9fdc1..827479226c8 100644 --- a/atom/browser/lib/bluetooth_chooser.cc +++ b/atom/browser/lib/bluetooth_chooser.cc @@ -3,7 +3,7 @@ // found in the LICENSE file. #include "atom/browser/lib/bluetooth_chooser.h" -#include "atom/common/native_mate_converters/callback.h" +#include "atom/common/native_mate_converters/once_callback.h" #include "atom/common/native_mate_converters/string16_converter.h" #include "native_mate/dictionary.h" @@ -70,7 +70,7 @@ void BluetoothChooser::ShowDiscoveryState(DiscoveryState state) { } else { bool prevent_default = api_web_contents_->Emit( "select-bluetooth-device", GetDeviceList(), - base::Bind(&OnDeviceChosen, event_handler_)); + base::BindOnce(&OnDeviceChosen, event_handler_)); if (!prevent_default) { auto it = device_map_.begin(); auto device_id = it->first; @@ -102,9 +102,9 @@ void BluetoothChooser::AddOrUpdateDevice(const std::string& device_id, if (changed) { // Emit a select-bluetooth-device handler to allow for user to listen for // bluetooth device found. - bool prevent_default = - api_web_contents_->Emit("select-bluetooth-device", GetDeviceList(), - base::Bind(&OnDeviceChosen, event_handler_)); + bool prevent_default = api_web_contents_->Emit( + "select-bluetooth-device", GetDeviceList(), + base::BindOnce(&OnDeviceChosen, event_handler_)); // If emit not implimented select first device that matches the filters // provided. diff --git a/atom/browser/net/asar/url_request_asar_job.cc b/atom/browser/net/asar/url_request_asar_job.cc index 62f847d01d4..16320ef8d78 100644 --- a/atom/browser/net/asar/url_request_asar_job.cc +++ b/atom/browser/net/asar/url_request_asar_job.cc @@ -131,8 +131,8 @@ int URLRequestAsarJob::ReadRawData(net::IOBuffer* dest, int dest_size) { int rv = stream_->Read( dest, dest_size, - base::Bind(&URLRequestAsarJob::DidRead, weak_ptr_factory_.GetWeakPtr(), - WrapRefCounted(dest))); + base::BindOnce(&URLRequestAsarJob::DidRead, + weak_ptr_factory_.GetWeakPtr(), WrapRefCounted(dest))); if (rv >= 0) { remaining_bytes_ -= rv; DCHECK_GE(remaining_bytes_, 0); @@ -257,9 +257,9 @@ void URLRequestAsarJob::DidFetchMetaInfo(const FileMetaInfo* meta_info) { int flags = base::File::FLAG_OPEN | base::File::FLAG_READ | base::File::FLAG_ASYNC; - int rv = stream_->Open( - meta_info_.file_path, flags, - base::Bind(&URLRequestAsarJob::DidOpen, weak_ptr_factory_.GetWeakPtr())); + int rv = stream_->Open(meta_info_.file_path, flags, + base::BindOnce(&URLRequestAsarJob::DidOpen, + weak_ptr_factory_.GetWeakPtr())); if (rv != net::ERR_IO_PENDING) DidOpen(rv); } @@ -297,9 +297,9 @@ void URLRequestAsarJob::DidOpen(int result) { seek_offset_ = byte_range_.first_byte_position() + read_offset; if (remaining_bytes_ > 0 && seek_offset_ != 0) { - int rv = - stream_->Seek(seek_offset_, base::Bind(&URLRequestAsarJob::DidSeek, - weak_ptr_factory_.GetWeakPtr())); + int rv = stream_->Seek(seek_offset_, + base::BindOnce(&URLRequestAsarJob::DidSeek, + weak_ptr_factory_.GetWeakPtr())); if (rv != net::ERR_IO_PENDING) { // stream_->Seek() failed, so pass an intentionally erroneous value // into DidSeek(). diff --git a/atom/browser/web_contents_permission_helper.cc b/atom/browser/web_contents_permission_helper.cc index acf8baef9a4..aaa14c64db2 100644 --- a/atom/browser/web_contents_permission_helper.cc +++ b/atom/browser/web_contents_permission_helper.cc @@ -66,7 +66,7 @@ WebContentsPermissionHelper::~WebContentsPermissionHelper() {} void WebContentsPermissionHelper::RequestPermission( content::PermissionType permission, - const base::Callback& callback, + const base::RepeatingCallback& callback, bool user_gesture, const base::DictionaryValue* details) { auto* rfh = web_contents_->GetMainFrame(); @@ -75,7 +75,7 @@ void WebContentsPermissionHelper::RequestPermission( auto origin = web_contents_->GetLastCommittedURL(); permission_manager->RequestPermissionWithDetails( permission, rfh, origin, false, details, - base::Bind(&OnPermissionResponse, std::move(callback))); + base::BindRepeating(&OnPermissionResponse, callback)); } bool WebContentsPermissionHelper::CheckPermission( @@ -121,7 +121,7 @@ void WebContentsPermissionHelper::RequestMediaAccessPermission( } void WebContentsPermissionHelper::RequestWebNotificationPermission( - const base::Callback& callback) { + const base::RepeatingCallback& callback) { RequestPermission(content::PermissionType::NOTIFICATIONS, callback); } @@ -129,11 +129,11 @@ void WebContentsPermissionHelper::RequestPointerLockPermission( bool user_gesture) { RequestPermission( static_cast(PermissionType::POINTER_LOCK), - base::Bind(&OnPointerLockResponse, web_contents_), user_gesture); + base::BindRepeating(&OnPointerLockResponse, web_contents_), user_gesture); } void WebContentsPermissionHelper::RequestOpenExternalPermission( - const base::Callback& callback, + const base::RepeatingCallback& callback, bool user_gesture, const GURL& url) { base::DictionaryValue details; diff --git a/atom/browser/web_contents_permission_helper.h b/atom/browser/web_contents_permission_helper.h index 991f5904c94..99d608e8824 100644 --- a/atom/browser/web_contents_permission_helper.h +++ b/atom/browser/web_contents_permission_helper.h @@ -25,15 +25,17 @@ class WebContentsPermissionHelper }; // Asynchronous Requests - void RequestFullscreenPermission(const base::Callback& callback); + void RequestFullscreenPermission( + const base::RepeatingCallback& callback); void RequestMediaAccessPermission(const content::MediaStreamRequest& request, content::MediaResponseCallback callback); void RequestWebNotificationPermission( - const base::Callback& callback); + const base::RepeatingCallback& callback); void RequestPointerLockPermission(bool user_gesture); - void RequestOpenExternalPermission(const base::Callback& callback, - bool user_gesture, - const GURL& url); + void RequestOpenExternalPermission( + const base::RepeatingCallback& callback, + bool user_gesture, + const GURL& url); // Synchronous Checks bool CheckMediaAccessPermission(const GURL& security_origin, @@ -44,7 +46,7 @@ class WebContentsPermissionHelper friend class content::WebContentsUserData; void RequestPermission(content::PermissionType permission, - const base::Callback& callback, + const base::RepeatingCallback& callback, bool user_gesture = false, const base::DictionaryValue* details = nullptr); diff --git a/atom/browser/web_dialog_helper.cc b/atom/browser/web_dialog_helper.cc index 627cba80399..57d30bcb915 100644 --- a/atom/browser/web_dialog_helper.cc +++ b/atom/browser/web_dialog_helper.cc @@ -52,8 +52,8 @@ class FileSelectHelper : public base::RefCounted, atom::util::Promise promise(isolate); file_dialog::ShowOpenDialog(settings, std::move(promise)); - auto callback = base::Bind(&FileSelectHelper::OnOpenDialogDone, this); - ignore_result(promise.Then(callback)); + auto callback = base::BindOnce(&FileSelectHelper::OnOpenDialogDone, this); + ignore_result(promise.Then(std::move(callback))); } void ShowSaveDialog(const file_dialog::DialogSettings& settings) { diff --git a/atom/common/promise_util.h b/atom/common/promise_util.h index 8f19218098e..eaf959d3b63 100644 --- a/atom/common/promise_util.h +++ b/atom/common/promise_util.h @@ -10,6 +10,7 @@ #include "atom/common/api/locker.h" #include "atom/common/native_mate_converters/callback.h" +#include "atom/common/native_mate_converters/once_callback.h" #include "base/task/post_task.h" #include "content/public/browser/browser_task_traits.h" #include "content/public/browser/browser_thread.h" @@ -104,7 +105,8 @@ class Promise { } template - v8::MaybeLocal Then(base::Callback cb) { + v8::MaybeLocal Then( + base::OnceCallback cb) { v8::HandleScope handle_scope(isolate()); v8::Context::Scope context_scope( v8::Local::New(isolate(), GetContext()));