Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move away from using base::{Bind,Callback,Closure}() #8811

Merged
merged 1 commit into from
May 21, 2021
Merged

Conversation

mariospr
Copy link
Contributor

base::{Bind,Callback,Closure}() have been deprecatedfor a while now,
are finally gone on Chromium 92, so it would be good to migrate all
current instances in the code (and stop introducing new ones) to the
Once/Repeating variants instead to easy further rebases.

This patch changes ALL instances of those old definitions and move
to using the Once variants whenever possible (as they are preferred)
and Repeating variants in every other case.

Last, this patch also makes some changes in brave_rewards_api.{h,cc}
to use weak pointers instead of base::Unretained() when binding
callbacks, for extra safety (and consistency with existing code).

[1] https://chromium-review.googlesource.com/c/chromium/src/+/2867526

Resolves brave/brave-browser#15855

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

@mariospr mariospr requested a review from bridiver May 14, 2021 17:27
@mariospr mariospr requested a review from iefremov as a code owner May 14, 2021 17:27
@mariospr mariospr self-assigned this May 14, 2021
@mariospr mariospr requested review from simonhong and a team as code owners May 14, 2021 17:27
@mariospr mariospr changed the title Move away from using base::{Bind,Callback,Closure}() #15855 Move away from using base::{Bind,Callback,Closure}() May 14, 2021
Copy link
Collaborator

@zenparsing zenparsing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rewards changes look good.

virtual void GetPublisherMinVisitTime(
const GetPublisherMinVisitTimeCallback& callback) = 0;
GetPublisherMinVisitTimeCallback callback) = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for these fixes!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My pleasure!

Copy link
Member

@yrliou yrliou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for wallet, ipfs, decentralized DNS changes.

base::Bind(
&BraveRewardsNativeWorker::OnBalance,
weak_factory_.GetWeakPtr()));
rewards_service->FetchBalance(base::BindRepeating(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mariospr can you check this file also? I found that all methods from RewardsService receives once callback type?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! Another instance of this, sorry. Fixed now too (+ reviewed again the PR and couldn't find more problems)

Copy link
Member

@simonhong simonhong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM for not-owned files except browser/brave_rewards/android/brave_rewards_native_worker.cc

mariospr added a commit that referenced this pull request May 18, 2021
This patch migrates from base::Bind() to base::BindRepeating(), and
from base::{Callback,Closure} to base::Repeating{Callback,Closure}
just to unblock the Cr92 rebase while the right fix is not yet, merged
to master (see #8811).

Chromium changes:

https://chromium.googlesource.com/chromium/src/+/6cc94b53393c1275843e43d3bbd6eda1f40fdd78

commit 6cc94b53393c1275843e43d3bbd6eda1f40fdd78
Author: Colin Blundell <blundell@chromium.org>
Date:   Wed May 5 11:13:38 2021 +0000

    [base::Bind conversion] Remove deprecated APIs

    This CL removes the following deprecated APIs:

    - base::Bind()
    - base::Callback
    - base::Closure
    - base::CancelableCallback
    - base::CancelableClosure

    It also converts the remaining simple usages of these APIs that the
    removal shook out.

    The behavior that these APIs provided is still available the *Repeating*
    variants. However, consider strongly whether using these variants is
    actually necessary in your case or whether the *Once* variants will
    suffice: unless your callback *objects* (note: not variables!) need to
    be called multiple times, they most likely can and should be the Once
    variants.

    Bug: 714018
@iefremov
Copy link
Contributor

browser/net
browser/p3a
components/p3a
components/speedreader

lgtm

@@ -636,6 +642,10 @@ void BraveRewardsAttestPromotionFunction::OnAttestPromotion(
Respond(TwoArguments(base::Value(static_cast<int>(result)), std::move(data)));
}

BraveRewardsGetPendingContributionsTotalFunction::
BraveRewardsGetPendingContributionsTotalFunction()
: weak_factory_(this) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functions are refcounted, so I gather we don't need weak pointers for them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I'll remove this and also update the other pre-existing cases in that file.

Copy link
Contributor

@iefremov iefremov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mariospr
Copy link
Contributor Author

@bridiver @mkarolin Could any of you take a quick look to this one? Ivan and others already LGTM'ed this PR, but it's still requiring a patch-reviewers OWNER approval.

Thanks in advance!

rewards_service->GetAnonWalletStatus(base::Bind(
&BraveRewardsGetAnonWalletStatusFunction::OnGetAnonWalletStatus,
this));
rewards_service->GetAnonWalletStatus(base::BindOnce(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mariospr this is not valid as is, just pass this as it was before. Bind will accept a refcounted pointer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! true... fixed now, sorry for the second overlook

base::{Bind,Callback,Closure}() have been deprecatedfor a while now,
are finally gone on Chromium 92, so it would be good to migrate all
current instances in the code (and stop introducing new ones) to the
Once/Repeating variants instead to easy further rebases.

This patch changes ALL instances of those old definitions and move
to using the Once variants whenever possible (as they are preferred)
and Repeating variants in every other case.

Last, this patch also makes some changes in brave_rewards_api.{h,cc}
to use weak pointers instead of base::Unretained() when binding
callbacks, for extra safety (and consistency with existing code).

[1] https://chromium-review.googlesource.com/c/chromium/src/+/2867526

Resolves brave/brave-browser#15855
@mariospr
Copy link
Contributor Author

Thanks for the reviews everyone. Android and Mac bots failed with unrelated failures so merging

@mariospr mariospr merged commit 671e91d into master May 21, 2021
@mariospr mariospr deleted the issues/15855 branch May 21, 2021 09:13
@mariospr mariospr added this to the 1.27.x - Nightly milestone May 21, 2021
@simonhong simonhong mentioned this pull request May 28, 2021
23 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move away from using base::{Bind,Callback,Closure}()
7 participants