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

10907: Fix threading for certain adblock service methods. #6250

Merged
merged 1 commit into from
Aug 3, 2020

Conversation

iefremov
Copy link
Contributor

Fix brave/brave-browser#10907

Some functionality of adblock service must be used only on
certain TaskRunner, so this fixes a couple of methods that
were previously called from UI thread. It also required
making the corresponding extension shields API functions
async. I also did some small code style improvements.

Submitter Checklist:

Test Plan:

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

After-merge Checklist:

  • The associated issue milestone is set to the smallest version that the
    changes has landed on.
  • All relevant documentation has been updated.

Fix brave/brave-browser#10907

Some functionality of adblock service must be used only on
certain TaskRunner, so this fixes a couple of methods that
were previously called from UI thread. It also required
making the corresponding extension shields API functions
async. I also did some small code style improvements.
@iefremov iefremov requested review from antonok-edm and bridiver July 29, 2020 15:18
@@ -54,60 +54,90 @@ BraveShieldsUrlCosmeticResourcesFunction::Run() {
std::unique_ptr<brave_shields::UrlCosmeticResources::Params> params(
brave_shields::UrlCosmeticResources::Params::Create(*args_));
EXTENSION_FUNCTION_VALIDATE(params.get());
g_brave_browser_process->ad_block_service()->GetTaskRunner()
Copy link
Contributor Author

@iefremov iefremov Jul 29, 2020

Choose a reason for hiding this comment

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

@antonok-edm This is not super illustrative example of async code - here it is implicitly asserted that all services run on the same task runner exposed by any of them. It would be better for these services to expose async api accepting callbacks for passing resulted values, dealing with task runners inside 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.

@bridiver could you please elaborate

base::Optional<base::Value> resources = g_brave_browser_process->
ad_block_service()->UrlCosmeticResources(params->url);
ad_block_service()->UrlCosmeticResources(url);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think a better fix here would be to have UrlCosmeticResources take a callback so the threading is handled in the service instead of the caller

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed in slack, I suggest to keep it as is for now, since there are less changes and thus less risks. Also this is aligned with other methods of adblock service (there is no single method taking a callback actually).

I want to refactor the service and improve threading work while fixing brave/brave-browser#10765

@iefremov iefremov requested a review from bridiver July 30, 2020 06:46
@iefremov iefremov mentioned this pull request Jul 30, 2020
32 tasks
@iefremov iefremov merged commit 872a342 into master Aug 3, 2020
@iefremov iefremov deleted the ie_cosmetic_crash branch August 3, 2020 06:50
@iefremov iefremov added this to the 1.12.x - Release milestone Aug 3, 2020
@iefremov iefremov restored the ie_cosmetic_crash branch August 4, 2020 04:00
@mihaiplesa mihaiplesa deleted the ie_cosmetic_crash branch June 10, 2021 20:12
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.

[Desktop] Crashes in Adblock Engine
2 participants