Skip to content
Permalink
Browse files

chore: remove last instances of base::Bind (#18178)

* chore: remove last instances of base::Bind

* MessageBoxCallback is a OnceCallback

* convert permission helepr cbs to Once

* convert ResponseCallback to Once
  • Loading branch information...
codebytere committed May 29, 2019
1 parent 96371b6 commit 9af50721157d097533f16918d63e28470944cf8b
@@ -100,16 +100,17 @@ class Menu : public mate::TrackableObject<Menu>,
bool WorksWhenHiddenAt(int index) const;

// Stored delegate methods.
base::Callback<bool(v8::Local<v8::Value>, int)> is_checked_;
base::Callback<bool(v8::Local<v8::Value>, int)> is_enabled_;
base::Callback<bool(v8::Local<v8::Value>, int)> is_visible_;
base::Callback<bool(v8::Local<v8::Value>, int)> works_when_hidden_;
base::Callback<v8::Local<v8::Value>(v8::Local<v8::Value>, int, bool)>
base::RepeatingCallback<bool(v8::Local<v8::Value>, int)> is_checked_;
base::RepeatingCallback<bool(v8::Local<v8::Value>, int)> is_enabled_;
base::RepeatingCallback<bool(v8::Local<v8::Value>, int)> is_visible_;
base::RepeatingCallback<bool(v8::Local<v8::Value>, int)> works_when_hidden_;
base::RepeatingCallback<v8::Local<v8::Value>(v8::Local<v8::Value>, int, bool)>
get_accelerator_;
base::Callback<bool(v8::Local<v8::Value>, int)> should_register_accelerator_;
base::Callback<void(v8::Local<v8::Value>, v8::Local<v8::Value>, int)>
base::RepeatingCallback<bool(v8::Local<v8::Value>, int)>
should_register_accelerator_;
base::RepeatingCallback<void(v8::Local<v8::Value>, v8::Local<v8::Value>, int)>
execute_command_;
base::Callback<void(v8::Local<v8::Value>)> menu_will_show_;
base::RepeatingCallback<void(v8::Local<v8::Value>)> menu_will_show_;

DISALLOW_COPY_AND_ASSIGN(Menu);
};
@@ -40,9 +40,10 @@ void RegisterSchemesAsPrivileged(v8::Local<v8::Value> val,

class Protocol : public mate::TrackableObject<Protocol> {
public:
using Handler =
base::Callback<void(const base::DictionaryValue&, v8::Local<v8::Value>)>;
using CompletionCallback = base::Callback<void(v8::Local<v8::Value>)>;
using Handler = base::RepeatingCallback<void(const base::DictionaryValue&,
v8::Local<v8::Value>)>;
using CompletionCallback =
base::RepeatingCallback<void(v8::Local<v8::Value>)>;

static mate::Handle<Protocol> Create(v8::Isolate* isolate,
AtomBrowserContext* browser_context);
@@ -48,7 +48,8 @@ class ProtocolNS : public mate::TrackableObject<ProtocolNS> {
~ProtocolNS() override;

// Callback types.
using CompletionCallback = base::Callback<void(v8::Local<v8::Value>)>;
using CompletionCallback =
base::RepeatingCallback<void(v8::Local<v8::Value>)>;

// JS APIs.
ProtocolError RegisterProtocol(ProtocolType type,
@@ -66,7 +66,8 @@ class SystemPreferences : public mate::EventEmitter<SystemPreferences>

#elif defined(OS_MACOSX)
using NotificationCallback =
base::Callback<void(const std::string&, const base::DictionaryValue&)>;
base::RepeatingCallback<void(const std::string&,
const base::DictionaryValue&)>;

void PostNotification(const std::string& name,
const base::DictionaryValue& user_info,
@@ -211,7 +211,8 @@ class TopLevelWindow : public mate::TrackableObject<TopLevelWindow>,
void SetIcon(mate::Handle<NativeImage> icon);
#endif
#if defined(OS_WIN)
typedef base::Callback<void(v8::Local<v8::Value>, v8::Local<v8::Value>)>
typedef base::RepeatingCallback<void(v8::Local<v8::Value>,
v8::Local<v8::Value>)>
MessageCallback;
bool HookWindowMessage(UINT message, const MessageCallback& callback);
bool IsWindowMessageHooked(UINT message);
@@ -9,8 +9,8 @@

#include "atom/browser/atom_browser_context.h"
#include "atom/browser/net/atom_network_delegate.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/net_converter.h"
#include "atom/common/native_mate_converters/once_callback.h"
#include "atom/common/native_mate_converters/value_converter.h"
#include "base/task/post_task.h"
#include "content/public/browser/browser_task_traits.h"
@@ -28,7 +28,7 @@ class FrameSubscriber : public content::WebContentsObserver,
public viz::mojom::FrameSinkVideoConsumer {
public:
using FrameCaptureCallback =
base::Callback<void(const gfx::Image&, const gfx::Rect&)>;
base::RepeatingCallback<void(const gfx::Image&, const gfx::Rect&)>;

FrameSubscriber(content::WebContents* web_contents,
const FrameCaptureCallback& callback,
@@ -561,7 +561,7 @@ void AtomBrowserClient::AllowCertificateError(
bool is_main_frame_request,
bool strict_enforcement,
bool expired_previous_decision,
const base::Callback<void(content::CertificateRequestResultType)>&
const base::RepeatingCallback<void(content::CertificateRequestResultType)>&
callback) {
if (delegate_) {
delegate_->AllowCertificateError(
@@ -743,21 +743,21 @@ content::BrowserMainParts* AtomBrowserClient::CreateBrowserMainParts(

void AtomBrowserClient::WebNotificationAllowed(
int render_process_id,
const base::RepeatingCallback<void(bool, bool)>& callback) {
base::OnceCallback<void(bool, bool)> callback) {
content::WebContents* web_contents =
WebContentsPreferences::GetWebContentsFromProcessID(render_process_id);
if (!web_contents) {
callback.Run(false, false);
std::move(callback).Run(false, false);
return;
}
auto* permission_helper =
WebContentsPermissionHelper::FromWebContents(web_contents);
if (!permission_helper) {
callback.Run(false, false);
std::move(callback).Run(false, false);
return;
}
permission_helper->RequestWebNotificationPermission(
base::Bind(callback, web_contents->IsAudioMuted()));
base::BindOnce(std::move(callback), web_contents->IsAudioMuted()));
}

void AtomBrowserClient::RenderProcessHostDestroyed(
@@ -809,9 +809,9 @@ void HandleExternalProtocolInUI(
return;

GURL escaped_url(net::EscapeExternalHandlerValue(url.spec()));
auto callback = base::Bind(&OnOpenExternal, escaped_url);
permission_helper->RequestOpenExternalPermission(callback, has_user_gesture,
url);
auto callback = base::BindOnce(&OnOpenExternal, escaped_url);
permission_helper->RequestOpenExternalPermission(std::move(callback),
has_user_gesture, url);
}

bool AtomBrowserClient::HandleExternalProtocol(
@@ -52,7 +52,7 @@ class AtomBrowserClient : public content::ContentBrowserClient,
NotificationPresenter* GetNotificationPresenter();

void WebNotificationAllowed(int render_process_id,
const base::Callback<void(bool, bool)>& callback);
base::OnceCallback<void(bool, bool)> callback);

// content::NavigatorDelegate
std::vector<std::unique_ptr<content::NavigationThrottle>>
@@ -95,9 +95,9 @@ void AtomJavaScriptDialogManager::RunJavaScriptDialog(
window, atom::MessageBoxType::kNone, buttons, default_id, cancel_id,
atom::MessageBoxOptions::MESSAGE_BOX_NONE, "",
base::UTF16ToUTF8(message_text), "", checkbox, false, gfx::ImageSkia(),
base::Bind(&AtomJavaScriptDialogManager::OnMessageBoxCallback,
base::Unretained(this), base::Passed(std::move(callback)),
origin));
base::BindOnce(&AtomJavaScriptDialogManager::OnMessageBoxCallback,
base::Unretained(this), base::Passed(std::move(callback)),
origin));
}

void AtomJavaScriptDialogManager::RunBeforeUnloadDialog(
@@ -523,15 +523,15 @@ void CommonWebContentsDelegate::DevToolsIndexPath(
scoped_refptr<DevToolsFileSystemIndexer::FileSystemIndexingJob>(
devtools_file_system_indexer_->IndexPath(
file_system_path, excluded_folders,
base::Bind(
base::BindRepeating(
&CommonWebContentsDelegate::OnDevToolsIndexingWorkCalculated,
weak_factory_.GetWeakPtr(), request_id, file_system_path),
base::Bind(&CommonWebContentsDelegate::OnDevToolsIndexingWorked,
weak_factory_.GetWeakPtr(), request_id,
file_system_path),
base::Bind(&CommonWebContentsDelegate::OnDevToolsIndexingDone,
weak_factory_.GetWeakPtr(), request_id,
file_system_path)));
base::BindRepeating(
&CommonWebContentsDelegate::OnDevToolsIndexingWorked,
weak_factory_.GetWeakPtr(), request_id, file_system_path),
base::BindRepeating(
&CommonWebContentsDelegate::OnDevToolsIndexingDone,
weak_factory_.GetWeakPtr(), request_id, file_system_path)));
}

void CommonWebContentsDelegate::DevToolsStopIndexing(int request_id) {
@@ -553,8 +553,9 @@ void CommonWebContentsDelegate::DevToolsSearchInPath(
}
devtools_file_system_indexer_->SearchInPath(
file_system_path, query,
base::Bind(&CommonWebContentsDelegate::OnDevToolsSearchCompleted,
weak_factory_.GetWeakPtr(), request_id, file_system_path));
base::BindRepeating(&CommonWebContentsDelegate::OnDevToolsSearchCompleted,
weak_factory_.GetWeakPtr(), request_id,
file_system_path));
}

void CommonWebContentsDelegate::OnDevToolsIndexingWorkCalculated(
@@ -70,17 +70,16 @@ void RunSimpleListener(const AtomNetworkDelegate::SimpleListener& listener,
return listener.Run(*(details.get()));
}

void RunResponseListener(
const AtomNetworkDelegate::ResponseListener& listener,
std::unique_ptr<base::DictionaryValue> details,
int render_process_id,
int render_frame_id,
const AtomNetworkDelegate::ResponseCallback& callback) {
void RunResponseListener(const AtomNetworkDelegate::ResponseListener& listener,
std::unique_ptr<base::DictionaryValue> details,
int render_process_id,
int render_frame_id,
AtomNetworkDelegate::ResponseCallback callback) {
int32_t id = GetWebContentsID(render_process_id, render_frame_id);
// id must be greater than zero
if (id)
details->SetInteger("webContentsId", id);
return listener.Run(*(details.get()), callback);
return listener.Run(*(details.get()), std::move(callback));
}

// Test whether the URL of |request| matches |patterns|.
@@ -484,12 +483,12 @@ int AtomNetworkDelegate::HandleResponseEvent(
callbacks_[request->identifier()] = std::move(callback);

ResponseCallback response =
base::Bind(&AtomNetworkDelegate::OnListenerResultInUI<Out>,
base::Unretained(this), request->identifier(), out);
base::BindOnce(&AtomNetworkDelegate::OnListenerResultInUI<Out>,
base::Unretained(this), request->identifier(), out);
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(RunResponseListener, info.listener, std::move(details),
render_process_id, render_frame_id, response));
render_process_id, render_frame_id, std::move(response)));
return net::ERR_IO_PENDING;
}

@@ -32,10 +32,13 @@ class LoginHandler;

class AtomNetworkDelegate : public net::NetworkDelegate {
public:
using ResponseCallback = base::Callback<void(const base::DictionaryValue&)>;
using SimpleListener = base::Callback<void(const base::DictionaryValue&)>;
using ResponseListener = base::Callback<void(const base::DictionaryValue&,
const ResponseCallback&)>;
using ResponseCallback =
base::OnceCallback<void(const base::DictionaryValue&)>;
using SimpleListener =
base::RepeatingCallback<void(const base::DictionaryValue&)>;
using ResponseListener =
base::RepeatingCallback<void(const base::DictionaryValue&,
ResponseCallback)>;

enum SimpleEvent {
kOnSendHeaders,
@@ -265,8 +265,8 @@ OffScreenRenderWidgetHostView::OffScreenRenderWidgetHostView(

if (content::GpuDataManager::GetInstance()->HardwareAccelerationEnabled()) {
video_consumer_.reset(new OffScreenVideoConsumer(
this, base::Bind(&OffScreenRenderWidgetHostView::OnPaint,
weak_ptr_factory_.GetWeakPtr())));
this, base::BindRepeating(&OffScreenRenderWidgetHostView::OnPaint,
weak_ptr_factory_.GetWeakPtr())));
video_consumer_->SetActive(IsPainting());
video_consumer_->SetFrameRate(GetFrameRate());
}
@@ -503,8 +503,8 @@ void OffScreenRenderWidgetHostView::InitAsPopup(

parent_host_view_->set_popup_host_view(this);
parent_callback_ =
base::Bind(&OffScreenRenderWidgetHostView::OnPopupPaint,
parent_host_view_->weak_ptr_factory_.GetWeakPtr());
base::BindRepeating(&OffScreenRenderWidgetHostView::OnPopupPaint,
parent_host_view_->weak_ptr_factory_.GetWeakPtr());

popup_position_ = pos;

@@ -741,8 +741,8 @@ OffScreenRenderWidgetHostView::CreateHostDisplayClient(
ui::Compositor* compositor) {
host_display_client_ = new OffScreenHostDisplayClient(
gfx::kNullAcceleratedWidget,
base::Bind(&OffScreenRenderWidgetHostView::OnPaint,
weak_ptr_factory_.GetWeakPtr()));
base::BindRepeating(&OffScreenRenderWidgetHostView::OnPaint,
weak_ptr_factory_.GetWeakPtr()));
host_display_client_->SetActive(IsPainting());
return base::WrapUnique(host_display_client_);
}
@@ -1084,8 +1084,9 @@ void OffScreenRenderWidgetHostView::SetupFrameRate(bool force) {
} else {
begin_frame_timer_.reset(new AtomBeginFrameTimer(
frame_rate_threshold_us_,
base::Bind(&OffScreenRenderWidgetHostView::OnBeginFrameTimerTick,
weak_ptr_factory_.GetWeakPtr())));
base::BindRepeating(
&OffScreenRenderWidgetHostView::OnBeginFrameTimerTick,
weak_ptr_factory_.GetWeakPtr())));
}
}

@@ -48,12 +48,12 @@ void OnPointerLockResponse(content::WebContents* web_contents, bool allowed) {
web_contents->GotResponseToLockMouseRequest(allowed);
}

void OnPermissionResponse(base::Callback<void(bool)> callback,
void OnPermissionResponse(base::OnceCallback<void(bool)> callback,
blink::mojom::PermissionStatus status) {
if (status == blink::mojom::PermissionStatus::GRANTED)
callback.Run(true);
std::move(callback).Run(true);
else
callback.Run(false);
std::move(callback).Run(false);
}

} // namespace
@@ -66,7 +66,7 @@ WebContentsPermissionHelper::~WebContentsPermissionHelper() {}

void WebContentsPermissionHelper::RequestPermission(
content::PermissionType permission,
const base::RepeatingCallback<void(bool)>& callback,
base::OnceCallback<void(bool)> 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::BindRepeating(&OnPermissionResponse, callback));
base::BindOnce(&OnPermissionResponse, std::move(callback)));
}

bool WebContentsPermissionHelper::CheckPermission(
@@ -90,10 +90,10 @@ bool WebContentsPermissionHelper::CheckPermission(
}

void WebContentsPermissionHelper::RequestFullscreenPermission(
const base::Callback<void(bool)>& callback) {
base::OnceCallback<void(bool)> callback) {
RequestPermission(
static_cast<content::PermissionType>(PermissionType::FULLSCREEN),
callback);
std::move(callback));
}

void WebContentsPermissionHelper::RequestMediaAccessPermission(
@@ -121,26 +121,27 @@ void WebContentsPermissionHelper::RequestMediaAccessPermission(
}

void WebContentsPermissionHelper::RequestWebNotificationPermission(
const base::RepeatingCallback<void(bool)>& callback) {
RequestPermission(content::PermissionType::NOTIFICATIONS, callback);
base::OnceCallback<void(bool)> callback) {
RequestPermission(content::PermissionType::NOTIFICATIONS,
std::move(callback));
}

void WebContentsPermissionHelper::RequestPointerLockPermission(
bool user_gesture) {
RequestPermission(
static_cast<content::PermissionType>(PermissionType::POINTER_LOCK),
base::BindRepeating(&OnPointerLockResponse, web_contents_), user_gesture);
base::BindOnce(&OnPointerLockResponse, web_contents_), user_gesture);
}

void WebContentsPermissionHelper::RequestOpenExternalPermission(
const base::RepeatingCallback<void(bool)>& callback,
base::OnceCallback<void(bool)> callback,
bool user_gesture,
const GURL& url) {
base::DictionaryValue details;
details.SetString("externalURL", url.spec());
RequestPermission(
static_cast<content::PermissionType>(PermissionType::OPEN_EXTERNAL),
callback, user_gesture, &details);
std::move(callback), user_gesture, &details);
}

bool WebContentsPermissionHelper::CheckMediaAccessPermission(

0 comments on commit 9af5072

Please sign in to comment.
You can’t perform that action at this time.