Skip to content

Commit

Permalink
chore: convert more files away from base::Bind (#18121)
Browse files Browse the repository at this point in the history
* chore: convert more files away from base::Bind

* use BindOnce for JsAsker
  • Loading branch information
codebytere authored and John Kleinschmidt committed May 3, 2019
1 parent c25c31e commit 0755857
Show file tree
Hide file tree
Showing 24 changed files with 86 additions and 71 deletions.
4 changes: 2 additions & 2 deletions atom/browser/api/atom_api_url_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
#include "atom/browser/api/atom_api_session.h"
#include "atom/browser/net/atom_url_request.h"
#include "atom/common/api/event_emitter_caller.h"
#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/gurl_converter.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/string16_converter.h"
#include "atom/common/node_includes.h"
#include "native_mate/dictionary.h"
Expand Down Expand Up @@ -365,7 +365,7 @@ void URLRequest::OnAuthenticationRequired(
}

Emit("login", auth_info,
base::Bind(&AtomURLRequest::PassLoginInformation, atom_request_));
base::BindOnce(&AtomURLRequest::PassLoginInformation, atom_request_));
}

void URLRequest::OnResponseStarted(
Expand Down
16 changes: 10 additions & 6 deletions atom/browser/api/atom_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,8 @@ WebContents::WebContents(v8::Isolate* isolate,
#if BUILDFLAG(ENABLE_OSR)
if (embedder_ && embedder_->IsOffScreen()) {
auto* view = new OffScreenWebContentsView(
false, base::Bind(&WebContents::OnPaint, base::Unretained(this)));
false,
base::BindRepeating(&WebContents::OnPaint, base::Unretained(this)));
params.view = view;
params.delegate_view = view;

Expand All @@ -363,7 +364,8 @@ WebContents::WebContents(v8::Isolate* isolate,

content::WebContents::CreateParams params(session->browser_context());
auto* view = new OffScreenWebContentsView(
transparent, base::Bind(&WebContents::OnPaint, base::Unretained(this)));
transparent,
base::BindRepeating(&WebContents::OnPaint, base::Unretained(this)));
params.view = view;
params.delegate_view = view;

Expand Down Expand Up @@ -640,8 +642,9 @@ void WebContents::EnterFullscreenModeForTab(
const blink::WebFullscreenOptions& options) {
auto* permission_helper =
WebContentsPermissionHelper::FromWebContents(source);
auto callback = base::Bind(&WebContents::OnEnterFullscreenModeForTab,
base::Unretained(this), source, origin, options);
auto callback =
base::BindRepeating(&WebContents::OnEnterFullscreenModeForTab,
base::Unretained(this), source, origin, options);
permission_helper->RequestFullscreenPermission(callback);
}

Expand Down Expand Up @@ -680,8 +683,9 @@ bool WebContents::HandleContextMenu(content::RenderFrameHost* render_frame_host,
const content::ContextMenuParams& params) {
if (params.custom_context.is_pepper_menu) {
Emit("pepper-context-menu", std::make_pair(params, web_contents()),
base::Bind(&content::WebContents::NotifyContextMenuClosed,
base::Unretained(web_contents()), params.custom_context));
base::BindOnce(&content::WebContents::NotifyContextMenuClosed,
base::Unretained(web_contents()),
params.custom_context));
} else {
Emit("context-menu", std::make_pair(params, web_contents()));
}
Expand Down
2 changes: 1 addition & 1 deletion atom/browser/atom_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ content::BrowserMainParts* AtomBrowserClient::CreateBrowserMainParts(

void AtomBrowserClient::WebNotificationAllowed(
int render_process_id,
const base::Callback<void(bool, bool)>& callback) {
const base::RepeatingCallback<void(bool, bool)>& callback) {
content::WebContents* web_contents =
WebContentsPreferences::GetWebContentsFromProcessID(render_process_id);
if (!web_contents) {
Expand Down
6 changes: 3 additions & 3 deletions atom/browser/atom_browser_main_parts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ void OverrideLinuxAppDataPath() {
int BrowserX11ErrorHandler(Display* d, XErrorEvent* error) {
if (!g_in_x11_io_error_handler && base::ThreadTaskRunnerHandle::IsSet()) {
base::ThreadTaskRunnerHandle::Get()->PostTask(
FROM_HERE, base::Bind(&ui::LogErrorEventDescription, d, *error));
FROM_HERE, base::BindOnce(&ui::LogErrorEventDescription, d, *error));
}
return 0;
}
Expand Down Expand Up @@ -394,8 +394,8 @@ void AtomBrowserMainParts::PreMainMessageLoopRun() {

// Start idle gc.
gc_timer_.Start(FROM_HERE, base::TimeDelta::FromMinutes(1),
base::Bind(&v8::Isolate::LowMemoryNotification,
base::Unretained(js_env_->isolate())));
base::BindRepeating(&v8::Isolate::LowMemoryNotification,
base::Unretained(js_env_->isolate())));

content::WebUIControllerFactory::RegisterFactory(
AtomWebUIControllerFactory::GetInstance());
Expand Down
7 changes: 4 additions & 3 deletions atom/browser/mac/in_app_purchase_observer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ - (void)runCallback:(NSArray*)transactions {

// Send the callback to the browser thread.
base::PostTaskWithTraits(FROM_HERE, {content::BrowserThread::UI},
base::Bind(callback_, converted));
base::BindOnce(callback_, converted));
}

/**
Expand Down Expand Up @@ -184,8 +184,9 @@ - (void)paymentQueue:(SKPaymentQueue*)queue

TransactionObserver::TransactionObserver() : weak_ptr_factory_(this) {
obeserver_ = [[InAppTransactionObserver alloc]
initWithCallback:base::Bind(&TransactionObserver::OnTransactionsUpdated,
weak_ptr_factory_.GetWeakPtr())];
initWithCallback:base::BindRepeating(
&TransactionObserver::OnTransactionsUpdated,
weak_ptr_factory_.GetWeakPtr())];
}

TransactionObserver::~TransactionObserver() {
Expand Down
14 changes: 7 additions & 7 deletions atom/browser/net/atom_cert_verifier.cc
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ class CertVerifierRequest : public AtomCertVerifier::Request {
void Start(const net::NetLogWithSource& net_log) {
int error = cert_verifier_->default_verifier()->Verify(
params_, &result_,
base::Bind(&CertVerifierRequest::OnDefaultVerificationDone,
weak_ptr_factory_.GetWeakPtr()),
base::BindOnce(&CertVerifierRequest::OnDefaultVerificationDone,
weak_ptr_factory_.GetWeakPtr()),
&default_verifier_request_, net_log);
if (error != net::ERR_IO_PENDING)
OnDefaultVerificationDone(error);
Expand All @@ -96,20 +96,20 @@ class CertVerifierRequest : public AtomCertVerifier::Request {
request->default_result = net::ErrorToString(error);
request->error_code = error;
request->certificate = params_.certificate();
auto response_callback = base::Bind(&CertVerifierRequest::OnResponseInUI,
weak_ptr_factory_.GetWeakPtr());
auto response_callback = base::BindOnce(
&CertVerifierRequest::OnResponseInUI, weak_ptr_factory_.GetWeakPtr());
base::PostTaskWithTraits(
FROM_HERE, {BrowserThread::UI},
base::BindOnce(&CertVerifierRequest::OnVerifyRequestInUI,
cert_verifier_->verify_proc(), std::move(request),
response_callback));
std::move(response_callback)));
}

static void OnVerifyRequestInUI(
const AtomCertVerifier::VerifyProc& verify_proc,
std::unique_ptr<VerifyRequestParams> request,
const base::Callback<void(int)>& response_callback) {
verify_proc.Run(*(request.get()), response_callback);
base::OnceCallback<void(int)> response_callback) {
verify_proc.Run(*(request.get()), std::move(response_callback));
}

static void OnResponseInUI(base::WeakPtr<CertVerifierRequest> self,
Expand Down
6 changes: 3 additions & 3 deletions atom/browser/net/js_asker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include <utility>

#include "atom/common/native_mate_converters/callback.h"
#include "atom/common/native_mate_converters/once_callback.h"
#include "content/public/browser/browser_thread.h"

namespace atom {
Expand All @@ -29,14 +29,14 @@ void JsAsker::AskForOptions(
v8::Isolate* isolate,
const JavaScriptHandler& handler,
std::unique_ptr<base::DictionaryValue> request_details,
const BeforeStartCallback& before_start) {
BeforeStartCallback before_start) {
DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
v8::Locker locker(isolate);
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = isolate->GetCurrentContext();
v8::Context::Scope context_scope(context);
handler.Run(*(request_details.get()),
mate::ConvertToV8(isolate, before_start));
mate::ConvertToV8(isolate, std::move(before_start)));
}

// static
Expand Down
4 changes: 2 additions & 2 deletions atom/browser/net/js_asker.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace atom {

using JavaScriptHandler =
base::Callback<void(const base::DictionaryValue&, v8::Local<v8::Value>)>;
using BeforeStartCallback = base::Callback<void(mate::Arguments* args)>;
using BeforeStartCallback = base::OnceCallback<void(mate::Arguments* args)>;

class JsAsker {
public:
Expand All @@ -34,7 +34,7 @@ class JsAsker {
v8::Isolate* isolate,
const JavaScriptHandler& handler,
std::unique_ptr<base::DictionaryValue> request_details,
const BeforeStartCallback& before_start);
BeforeStartCallback before_start);

// Test whether the |options| means an error.
static bool IsErrorOptions(base::Value* value, int* error);
Expand Down
7 changes: 4 additions & 3 deletions atom/browser/net/url_request_async_asar_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ void URLRequestAsyncAsarJob::Start() {
FillRequestDetails(request_details.get(), request());
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(&JsAsker::AskForOptions, base::Unretained(isolate()),
handler(), std::move(request_details),
base::Bind(&BeforeStartInUI, weak_factory_.GetWeakPtr())));
base::BindOnce(
&JsAsker::AskForOptions, base::Unretained(isolate()), handler(),
std::move(request_details),
base::BindOnce(&BeforeStartInUI, weak_factory_.GetWeakPtr())));
}

void URLRequestAsyncAsarJob::StartAsync(std::unique_ptr<base::Value> options,
Expand Down
7 changes: 4 additions & 3 deletions atom/browser/net/url_request_buffer_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ void URLRequestBufferJob::Start() {
FillRequestDetails(request_details.get(), request());
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(&JsAsker::AskForOptions, base::Unretained(isolate()),
handler(), std::move(request_details),
base::Bind(&BeforeStartInUI, weak_factory_.GetWeakPtr())));
base::BindOnce(
&JsAsker::AskForOptions, base::Unretained(isolate()), handler(),
std::move(request_details),
base::BindOnce(&BeforeStartInUI, weak_factory_.GetWeakPtr())));
}

void URLRequestBufferJob::StartAsync(std::unique_ptr<base::Value> options,
Expand Down
7 changes: 4 additions & 3 deletions atom/browser/net/url_request_fetch_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ void URLRequestFetchJob::Start() {
FillRequestDetails(request_details.get(), request());
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(&JsAsker::AskForOptions, base::Unretained(isolate()),
handler(), std::move(request_details),
base::Bind(&BeforeStartInUI, weak_factory_.GetWeakPtr())));
base::BindOnce(
&JsAsker::AskForOptions, base::Unretained(isolate()), handler(),
std::move(request_details),
base::BindOnce(&BeforeStartInUI, weak_factory_.GetWeakPtr())));
}

void URLRequestFetchJob::StartAsync(
Expand Down
7 changes: 4 additions & 3 deletions atom/browser/net/url_request_stream_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,10 @@ void URLRequestStreamJob::Start() {
FillRequestDetails(request_details.get(), request());
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(&JsAsker::AskForOptions, base::Unretained(isolate()),
handler(), std::move(request_details),
base::Bind(&BeforeStartInUI, weak_factory_.GetWeakPtr())));
base::BindOnce(
&JsAsker::AskForOptions, base::Unretained(isolate()), handler(),
std::move(request_details),
base::BindOnce(&BeforeStartInUI, weak_factory_.GetWeakPtr())));
}

void URLRequestStreamJob::StartAsync(
Expand Down
7 changes: 4 additions & 3 deletions atom/browser/net/url_request_string_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ void URLRequestStringJob::Start() {
FillRequestDetails(request_details.get(), request());
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::UI},
base::BindOnce(&JsAsker::AskForOptions, base::Unretained(isolate()),
handler(), std::move(request_details),
base::Bind(&BeforeStartInUI, weak_factory_.GetWeakPtr())));
base::BindOnce(
&JsAsker::AskForOptions, base::Unretained(isolate()), handler(),
std::move(request_details),
base::BindOnce(&BeforeStartInUI, weak_factory_.GetWeakPtr())));
}

void URLRequestStringJob::StartAsync(std::unique_ptr<base::Value> options,
Expand Down
6 changes: 3 additions & 3 deletions atom/browser/notifications/platform_notification_service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ void PlatformNotificationService::DisplayNotification(
if (notification) {
browser_client_->WebNotificationAllowed(
render_process_host->GetID(),
base::Bind(&OnWebNotificationAllowed, notification,
notification_resources.notification_icon,
notification_data));
base::BindRepeating(&OnWebNotificationAllowed, notification,
notification_resources.notification_icon,
notification_data));
}
}

Expand Down
6 changes: 3 additions & 3 deletions atom/browser/notifications/win/windows_toast_notification.cc
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ IFACEMETHODIMP ToastEventHandler::Invoke(
IInspectable* args) {
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::UI},
base::Bind(&Notification::NotificationClicked, notification_));
base::BindOnce(&Notification::NotificationClicked, notification_));
if (IsDebuggingNotifications())
LOG(INFO) << "Notification clicked";

Expand All @@ -427,7 +427,7 @@ IFACEMETHODIMP ToastEventHandler::Invoke(
ABI::Windows::UI::Notifications::IToastDismissedEventArgs* e) {
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::UI},
base::Bind(&Notification::NotificationDismissed, notification_));
base::BindOnce(&Notification::NotificationDismissed, notification_));
if (IsDebuggingNotifications())
LOG(INFO) << "Notification dismissed";

Expand All @@ -439,7 +439,7 @@ IFACEMETHODIMP ToastEventHandler::Invoke(
ABI::Windows::UI::Notifications::IToastFailedEventArgs* e) {
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::UI},
base::Bind(&Notification::NotificationFailed, notification_));
base::BindOnce(&Notification::NotificationFailed, notification_));
if (IsDebuggingNotifications())
LOG(INFO) << "Notification failed";

Expand Down
3 changes: 2 additions & 1 deletion atom/browser/osr/osr_video_consumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ namespace atom {

class OffScreenRenderWidgetHostView;

typedef base::Callback<void(const gfx::Rect&, const SkBitmap&)> OnPaintCallback;
typedef base::RepeatingCallback<void(const gfx::Rect&, const SkBitmap&)>
OnPaintCallback;

class OffScreenVideoConsumer : public viz::mojom::FrameSinkVideoConsumer {
public:
Expand Down
11 changes: 6 additions & 5 deletions atom/browser/ui/inspectable_web_contents_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -726,8 +726,8 @@ void InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend(
int id = 0;
dict->GetInteger(kFrontendHostId, &id);
embedder_message_dispatcher_->Dispatch(
base::Bind(&InspectableWebContentsImpl::SendMessageAck,
weak_factory_.GetWeakPtr(), id),
base::BindRepeating(&InspectableWebContentsImpl::SendMessageAck,
weak_factory_.GetWeakPtr(), id),
method, params);
}

Expand Down Expand Up @@ -763,8 +763,9 @@ void InspectableWebContentsImpl::RenderFrameHostChanged(
return;
frontend_host_ = content::DevToolsFrontendHost::Create(
new_host,
base::Bind(&InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend,
weak_factory_.GetWeakPtr()));
base::BindRepeating(
&InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend,
weak_factory_.GetWeakPtr()));
}

void InspectableWebContentsImpl::WebContentsDestroyed() {
Expand Down Expand Up @@ -866,7 +867,7 @@ void InspectableWebContentsImpl::ReadyToCommitNavigation(
}
frontend_host_ = content::DevToolsFrontendHost::Create(
web_contents()->GetMainFrame(),
base::Bind(
base::BindRepeating(
&InspectableWebContentsImpl::HandleMessageFromDevToolsFrontend,
base::Unretained(this)));
return;
Expand Down
4 changes: 2 additions & 2 deletions atom/browser/ui/views/menu_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ views::MenuItemView* MenuDelegate::GetSiblingMenu(
if (!switch_in_progress) {
base::PostTaskWithTraits(
FROM_HERE, {content::BrowserThread::UI},
base::Bind(&views::MenuRunner::Cancel,
base::Unretained(menu_runner_.get())));
base::BindOnce(&views::MenuRunner::Cancel,
base::Unretained(menu_runner_.get())));
}
}

Expand Down
4 changes: 2 additions & 2 deletions atom/browser/ui/win/notify_icon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ void NotifyIcon::PopUpContextMenu(const gfx::Point& pos,
menu_runner_.reset(new views::MenuRunner(
menu_model != nullptr ? menu_model : menu_model_,
views::MenuRunner::CONTEXT_MENU | views::MenuRunner::HAS_MNEMONICS,
base::Bind(&NotifyIcon::OnContextMenuClosed,
weak_factory_.GetWeakPtr())));
base::BindRepeating(&NotifyIcon::OnContextMenuClosed,
weak_factory_.GetWeakPtr())));
menu_runner_->RunMenuAt(widget_.get(), NULL, rect,
views::MenuAnchorPosition::kTopLeft,
ui::MENU_SOURCE_MOUSE);
Expand Down
5 changes: 3 additions & 2 deletions atom/browser/zoom_level_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,9 @@ void ZoomLevelDelegate::InitHostZoomMap(content::HostZoomMap* host_zoom_map) {
// by calls to HostZoomMap::SetZoomLevelForHost().
ExtractPerHostZoomLevels(host_zoom_dictionary);
}
zoom_subscription_ = host_zoom_map_->AddZoomLevelChangedCallback(base::Bind(
&ZoomLevelDelegate::OnZoomLevelChanged, base::Unretained(this)));
zoom_subscription_ =
host_zoom_map_->AddZoomLevelChangedCallback(base::BindRepeating(
&ZoomLevelDelegate::OnZoomLevelChanged, base::Unretained(this)));
}

} // namespace atom
5 changes: 3 additions & 2 deletions atom/common/api/atom_api_command_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ void Initialize(v8::Local<v8::Object> exports,
dict.SetMethod("hasSwitch", &HasSwitch);
dict.SetMethod("getSwitchValue", &GetSwitchValue);
dict.SetMethod("appendSwitch", &AppendSwitch);
dict.SetMethod("appendArgument", base::Bind(&base::CommandLine::AppendArg,
base::Unretained(command_line)));
dict.SetMethod("appendArgument",
base::BindRepeating(&base::CommandLine::AppendArg,
base::Unretained(command_line)));
}

} // namespace
Expand Down

0 comments on commit 0755857

Please sign in to comment.