chore: convert base::Bind instances across some files (#18112)
This commit is contained in:
parent
4808f30538
commit
cc00fa8874
7 changed files with 34 additions and 30 deletions
|
@ -124,11 +124,11 @@ void AtomDownloadManagerDelegate::OnDownloadPathGenerated(
|
||||||
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
v8::Isolate* isolate = v8::Isolate::GetCurrent();
|
||||||
atom::util::Promise dialog_promise(isolate);
|
atom::util::Promise dialog_promise(isolate);
|
||||||
auto dialog_callback =
|
auto dialog_callback =
|
||||||
base::Bind(&AtomDownloadManagerDelegate::OnDownloadSaveDialogDone,
|
base::BindOnce(&AtomDownloadManagerDelegate::OnDownloadSaveDialogDone,
|
||||||
base::Unretained(this), download_id, callback);
|
base::Unretained(this), download_id, callback);
|
||||||
|
|
||||||
file_dialog::ShowSaveDialog(settings, std::move(dialog_promise));
|
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 {
|
} else {
|
||||||
callback.Run(path, download::DownloadItem::TARGET_DISPOSITION_PROMPT,
|
callback.Run(path, download::DownloadItem::TARGET_DISPOSITION_PROMPT,
|
||||||
download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, path,
|
download::DOWNLOAD_DANGER_TYPE_NOT_DANGEROUS, path,
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// found in the LICENSE file.
|
// found in the LICENSE file.
|
||||||
|
|
||||||
#include "atom/browser/lib/bluetooth_chooser.h"
|
#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 "atom/common/native_mate_converters/string16_converter.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ void BluetoothChooser::ShowDiscoveryState(DiscoveryState state) {
|
||||||
} else {
|
} else {
|
||||||
bool prevent_default = api_web_contents_->Emit(
|
bool prevent_default = api_web_contents_->Emit(
|
||||||
"select-bluetooth-device", GetDeviceList(),
|
"select-bluetooth-device", GetDeviceList(),
|
||||||
base::Bind(&OnDeviceChosen, event_handler_));
|
base::BindOnce(&OnDeviceChosen, event_handler_));
|
||||||
if (!prevent_default) {
|
if (!prevent_default) {
|
||||||
auto it = device_map_.begin();
|
auto it = device_map_.begin();
|
||||||
auto device_id = it->first;
|
auto device_id = it->first;
|
||||||
|
@ -102,9 +102,9 @@ void BluetoothChooser::AddOrUpdateDevice(const std::string& device_id,
|
||||||
if (changed) {
|
if (changed) {
|
||||||
// Emit a select-bluetooth-device handler to allow for user to listen for
|
// Emit a select-bluetooth-device handler to allow for user to listen for
|
||||||
// bluetooth device found.
|
// bluetooth device found.
|
||||||
bool prevent_default =
|
bool prevent_default = api_web_contents_->Emit(
|
||||||
api_web_contents_->Emit("select-bluetooth-device", GetDeviceList(),
|
"select-bluetooth-device", GetDeviceList(),
|
||||||
base::Bind(&OnDeviceChosen, event_handler_));
|
base::BindOnce(&OnDeviceChosen, event_handler_));
|
||||||
|
|
||||||
// If emit not implimented select first device that matches the filters
|
// If emit not implimented select first device that matches the filters
|
||||||
// provided.
|
// provided.
|
||||||
|
|
|
@ -131,8 +131,8 @@ int URLRequestAsarJob::ReadRawData(net::IOBuffer* dest, int dest_size) {
|
||||||
|
|
||||||
int rv = stream_->Read(
|
int rv = stream_->Read(
|
||||||
dest, dest_size,
|
dest, dest_size,
|
||||||
base::Bind(&URLRequestAsarJob::DidRead, weak_ptr_factory_.GetWeakPtr(),
|
base::BindOnce(&URLRequestAsarJob::DidRead,
|
||||||
WrapRefCounted(dest)));
|
weak_ptr_factory_.GetWeakPtr(), WrapRefCounted(dest)));
|
||||||
if (rv >= 0) {
|
if (rv >= 0) {
|
||||||
remaining_bytes_ -= rv;
|
remaining_bytes_ -= rv;
|
||||||
DCHECK_GE(remaining_bytes_, 0);
|
DCHECK_GE(remaining_bytes_, 0);
|
||||||
|
@ -257,9 +257,9 @@ void URLRequestAsarJob::DidFetchMetaInfo(const FileMetaInfo* meta_info) {
|
||||||
|
|
||||||
int flags =
|
int flags =
|
||||||
base::File::FLAG_OPEN | base::File::FLAG_READ | base::File::FLAG_ASYNC;
|
base::File::FLAG_OPEN | base::File::FLAG_READ | base::File::FLAG_ASYNC;
|
||||||
int rv = stream_->Open(
|
int rv = stream_->Open(meta_info_.file_path, flags,
|
||||||
meta_info_.file_path, flags,
|
base::BindOnce(&URLRequestAsarJob::DidOpen,
|
||||||
base::Bind(&URLRequestAsarJob::DidOpen, weak_ptr_factory_.GetWeakPtr()));
|
weak_ptr_factory_.GetWeakPtr()));
|
||||||
if (rv != net::ERR_IO_PENDING)
|
if (rv != net::ERR_IO_PENDING)
|
||||||
DidOpen(rv);
|
DidOpen(rv);
|
||||||
}
|
}
|
||||||
|
@ -297,9 +297,9 @@ void URLRequestAsarJob::DidOpen(int result) {
|
||||||
seek_offset_ = byte_range_.first_byte_position() + read_offset;
|
seek_offset_ = byte_range_.first_byte_position() + read_offset;
|
||||||
|
|
||||||
if (remaining_bytes_ > 0 && seek_offset_ != 0) {
|
if (remaining_bytes_ > 0 && seek_offset_ != 0) {
|
||||||
int rv =
|
int rv = stream_->Seek(seek_offset_,
|
||||||
stream_->Seek(seek_offset_, base::Bind(&URLRequestAsarJob::DidSeek,
|
base::BindOnce(&URLRequestAsarJob::DidSeek,
|
||||||
weak_ptr_factory_.GetWeakPtr()));
|
weak_ptr_factory_.GetWeakPtr()));
|
||||||
if (rv != net::ERR_IO_PENDING) {
|
if (rv != net::ERR_IO_PENDING) {
|
||||||
// stream_->Seek() failed, so pass an intentionally erroneous value
|
// stream_->Seek() failed, so pass an intentionally erroneous value
|
||||||
// into DidSeek().
|
// into DidSeek().
|
||||||
|
|
|
@ -66,7 +66,7 @@ WebContentsPermissionHelper::~WebContentsPermissionHelper() {}
|
||||||
|
|
||||||
void WebContentsPermissionHelper::RequestPermission(
|
void WebContentsPermissionHelper::RequestPermission(
|
||||||
content::PermissionType permission,
|
content::PermissionType permission,
|
||||||
const base::Callback<void(bool)>& callback,
|
const base::RepeatingCallback<void(bool)>& callback,
|
||||||
bool user_gesture,
|
bool user_gesture,
|
||||||
const base::DictionaryValue* details) {
|
const base::DictionaryValue* details) {
|
||||||
auto* rfh = web_contents_->GetMainFrame();
|
auto* rfh = web_contents_->GetMainFrame();
|
||||||
|
@ -75,7 +75,7 @@ void WebContentsPermissionHelper::RequestPermission(
|
||||||
auto origin = web_contents_->GetLastCommittedURL();
|
auto origin = web_contents_->GetLastCommittedURL();
|
||||||
permission_manager->RequestPermissionWithDetails(
|
permission_manager->RequestPermissionWithDetails(
|
||||||
permission, rfh, origin, false, details,
|
permission, rfh, origin, false, details,
|
||||||
base::Bind(&OnPermissionResponse, std::move(callback)));
|
base::BindRepeating(&OnPermissionResponse, callback));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WebContentsPermissionHelper::CheckPermission(
|
bool WebContentsPermissionHelper::CheckPermission(
|
||||||
|
@ -121,7 +121,7 @@ void WebContentsPermissionHelper::RequestMediaAccessPermission(
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContentsPermissionHelper::RequestWebNotificationPermission(
|
void WebContentsPermissionHelper::RequestWebNotificationPermission(
|
||||||
const base::Callback<void(bool)>& callback) {
|
const base::RepeatingCallback<void(bool)>& callback) {
|
||||||
RequestPermission(content::PermissionType::NOTIFICATIONS, callback);
|
RequestPermission(content::PermissionType::NOTIFICATIONS, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,11 +129,11 @@ void WebContentsPermissionHelper::RequestPointerLockPermission(
|
||||||
bool user_gesture) {
|
bool user_gesture) {
|
||||||
RequestPermission(
|
RequestPermission(
|
||||||
static_cast<content::PermissionType>(PermissionType::POINTER_LOCK),
|
static_cast<content::PermissionType>(PermissionType::POINTER_LOCK),
|
||||||
base::Bind(&OnPointerLockResponse, web_contents_), user_gesture);
|
base::BindRepeating(&OnPointerLockResponse, web_contents_), user_gesture);
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContentsPermissionHelper::RequestOpenExternalPermission(
|
void WebContentsPermissionHelper::RequestOpenExternalPermission(
|
||||||
const base::Callback<void(bool)>& callback,
|
const base::RepeatingCallback<void(bool)>& callback,
|
||||||
bool user_gesture,
|
bool user_gesture,
|
||||||
const GURL& url) {
|
const GURL& url) {
|
||||||
base::DictionaryValue details;
|
base::DictionaryValue details;
|
||||||
|
|
|
@ -25,15 +25,17 @@ class WebContentsPermissionHelper
|
||||||
};
|
};
|
||||||
|
|
||||||
// Asynchronous Requests
|
// Asynchronous Requests
|
||||||
void RequestFullscreenPermission(const base::Callback<void(bool)>& callback);
|
void RequestFullscreenPermission(
|
||||||
|
const base::RepeatingCallback<void(bool)>& callback);
|
||||||
void RequestMediaAccessPermission(const content::MediaStreamRequest& request,
|
void RequestMediaAccessPermission(const content::MediaStreamRequest& request,
|
||||||
content::MediaResponseCallback callback);
|
content::MediaResponseCallback callback);
|
||||||
void RequestWebNotificationPermission(
|
void RequestWebNotificationPermission(
|
||||||
const base::Callback<void(bool)>& callback);
|
const base::RepeatingCallback<void(bool)>& callback);
|
||||||
void RequestPointerLockPermission(bool user_gesture);
|
void RequestPointerLockPermission(bool user_gesture);
|
||||||
void RequestOpenExternalPermission(const base::Callback<void(bool)>& callback,
|
void RequestOpenExternalPermission(
|
||||||
bool user_gesture,
|
const base::RepeatingCallback<void(bool)>& callback,
|
||||||
const GURL& url);
|
bool user_gesture,
|
||||||
|
const GURL& url);
|
||||||
|
|
||||||
// Synchronous Checks
|
// Synchronous Checks
|
||||||
bool CheckMediaAccessPermission(const GURL& security_origin,
|
bool CheckMediaAccessPermission(const GURL& security_origin,
|
||||||
|
@ -44,7 +46,7 @@ class WebContentsPermissionHelper
|
||||||
friend class content::WebContentsUserData<WebContentsPermissionHelper>;
|
friend class content::WebContentsUserData<WebContentsPermissionHelper>;
|
||||||
|
|
||||||
void RequestPermission(content::PermissionType permission,
|
void RequestPermission(content::PermissionType permission,
|
||||||
const base::Callback<void(bool)>& callback,
|
const base::RepeatingCallback<void(bool)>& callback,
|
||||||
bool user_gesture = false,
|
bool user_gesture = false,
|
||||||
const base::DictionaryValue* details = nullptr);
|
const base::DictionaryValue* details = nullptr);
|
||||||
|
|
||||||
|
|
|
@ -52,8 +52,8 @@ class FileSelectHelper : public base::RefCounted<FileSelectHelper>,
|
||||||
atom::util::Promise promise(isolate);
|
atom::util::Promise promise(isolate);
|
||||||
|
|
||||||
file_dialog::ShowOpenDialog(settings, std::move(promise));
|
file_dialog::ShowOpenDialog(settings, std::move(promise));
|
||||||
auto callback = base::Bind(&FileSelectHelper::OnOpenDialogDone, this);
|
auto callback = base::BindOnce(&FileSelectHelper::OnOpenDialogDone, this);
|
||||||
ignore_result(promise.Then(callback));
|
ignore_result(promise.Then(std::move(callback)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ShowSaveDialog(const file_dialog::DialogSettings& settings) {
|
void ShowSaveDialog(const file_dialog::DialogSettings& settings) {
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
|
|
||||||
#include "atom/common/api/locker.h"
|
#include "atom/common/api/locker.h"
|
||||||
#include "atom/common/native_mate_converters/callback.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 "base/task/post_task.h"
|
||||||
#include "content/public/browser/browser_task_traits.h"
|
#include "content/public/browser/browser_task_traits.h"
|
||||||
#include "content/public/browser/browser_thread.h"
|
#include "content/public/browser/browser_thread.h"
|
||||||
|
@ -104,7 +105,8 @@ class Promise {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename ReturnType, typename... ArgTypes>
|
template <typename ReturnType, typename... ArgTypes>
|
||||||
v8::MaybeLocal<v8::Promise> Then(base::Callback<ReturnType(ArgTypes...)> cb) {
|
v8::MaybeLocal<v8::Promise> Then(
|
||||||
|
base::OnceCallback<ReturnType(ArgTypes...)> cb) {
|
||||||
v8::HandleScope handle_scope(isolate());
|
v8::HandleScope handle_scope(isolate());
|
||||||
v8::Context::Scope context_scope(
|
v8::Context::Scope context_scope(
|
||||||
v8::Local<v8::Context>::New(isolate(), GetContext()));
|
v8::Local<v8::Context>::New(isolate(), GetContext()));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue