Skip to content

Use AdBlockDefaultResourceUpdateInterval for all adblock-related components #21868

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

Merged
merged 3 commits into from
May 14, 2024

Conversation

antonok-edm
Copy link
Collaborator

Resolves brave/brave-browser#35164

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • 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 wiki
    • npm run lint, npm run presubmit wiki, 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:

Test Plan:

@antonok-edm antonok-edm requested review from cuba and simonhong February 2, 2024 00:26
@antonok-edm antonok-edm self-assigned this Feb 2, 2024
void AdBlockComponentServiceManager::CheckAdBlockComponentsUpdate() {
auto runner = base::SequencedTaskRunner::GetCurrentDefault();

runner->PostDelayedTask(FROM_HERE, base::BindOnce([]() {
Copy link
Member

Choose a reason for hiding this comment

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

As @atuchin-m noted at https://github.com/brave/brave-core/pull/20557/files#r1365810455,
It would be great if we could update in a bunch.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

agreed... I don't think we have any API exposed for this though.

The best thing I've found so far is this UpdateClient::Update method that takes multiple component IDs, but we can't call it directly (would have to plumb multiple levels of patching). There's also CrxUpdateService::CheckForUpdates, although we don't have the ability to customize the list of components checked. Maybe that's ok?

@atuchin-m do you have any recommendations?

Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. My point is we'd better optimize the number of requests to the backend to check the update. If we want to update the set of components, ideally we should done the one request.
  2. UpdateClient::Update looks like an internal thing.
  3. CheckForUpdates looks better, maybe it's okay to check the update of all the brave components.
  4. Anyway, scheduling a number of task with random delays doesn't looks reasonable to me. 10 sec usually is not enough to process an update. Do you sure that the next PostTasks don't cancel the previous ones?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also BraveOnDemandUpdater uses priority FOREGROUND, that means there is no chance to combine the requests together. CheckForUpdates uses the same priority internally.

I believe the first thing to do is to understand the right priority to use. if it's BACKGROUND then it's look okay to use CheckForUpdates. Otherwise I believe we need to add CrxUpdateService::OnDemandUpdateMultipleIds via chromium_src here

@iefremov do we have someone who is familiar with component_updater internals?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm somewhat familiar with component_updater internals.

@@ -251,6 +262,35 @@ void AdBlockComponentServiceManager::EnableFilterList(const std::string& uuid,
UpdateFilterListPrefs(uuid, enabled);
}

void AdBlockComponentServiceManager::CheckAdBlockComponentsUpdate() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

For brave/brave-browser#35216, the UI will want to know when this process completes (so that it can show a spinner and updated text, and also an indication if the process fails).

Could this method accept a callback that gets executed when all component updates are done? Or is there some other approach we want to take?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right now OnDemandUpdate has a hardcoded no-op callback. I suppose this could be changed, but let's see if @atuchin-m has any thoughts on the API we should use.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe we could add on demand callback in BraveOnDemandUpdate. Also no problem to use chromium OnDemandUpdater directly (a chromium example)

Also installing or updating a components has a several stages.

  1. Updating the component (including downloading .crx)
  2. Unpacking .crx and registering the new version
  3. Processing the content by a client code (=the adblock code here).
    The callback is about 2 (maybe 1), but definitely not about 3.
    Please be sure that you're waiting for the right things.

@antonok-edm antonok-edm requested a review from atuchin-m February 2, 2024 03:18
@antonok-edm antonok-edm force-pushed the update-all-adblock-components-together branch from b0b67b8 to 4861d72 Compare February 2, 2024 03:25
update_check_timer_.Start(
FROM_HERE, base::Minutes(kComponentUpdateCheckIntervalMins.Get()),
base::BindRepeating(
[](base::WeakPtr<AdBlockComponentServiceManager> component_manager) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: what about base::BindRepeating(AdBlockComponentServiceManager::CheckAdBlockComponentsUpdate, weak_factory_.GetWeakPtr())?

}),
base::Seconds(base::RandInt(0, 10)));

runner->PostDelayedTask(FROM_HERE, base::BindOnce([]() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you please optimize identical blocks here?
There is 3 about the same runner->PostDelayedTask in the method. I hope we could merge it in the one.

void AdBlockComponentServiceManager::CheckAdBlockComponentsUpdate() {
auto runner = base::SequencedTaskRunner::GetCurrentDefault();

runner->PostDelayedTask(FROM_HERE, base::BindOnce([]() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. My point is we'd better optimize the number of requests to the backend to check the update. If we want to update the set of components, ideally we should done the one request.
  2. UpdateClient::Update looks like an internal thing.
  3. CheckForUpdates looks better, maybe it's okay to check the update of all the brave components.
  4. Anyway, scheduling a number of task with random delays doesn't looks reasonable to me. 10 sec usually is not enough to process an update. Do you sure that the next PostTasks don't cancel the previous ones?

void AdBlockComponentServiceManager::CheckAdBlockComponentsUpdate() {
auto runner = base::SequencedTaskRunner::GetCurrentDefault();

runner->PostDelayedTask(FROM_HERE, base::BindOnce([]() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also BraveOnDemandUpdater uses priority FOREGROUND, that means there is no chance to combine the requests together. CheckForUpdates uses the same priority internally.

I believe the first thing to do is to understand the right priority to use. if it's BACKGROUND then it's look okay to use CheckForUpdates. Otherwise I believe we need to add CrxUpdateService::OnDemandUpdateMultipleIds via chromium_src here

@iefremov do we have someone who is familiar with component_updater internals?

@@ -251,6 +262,35 @@ void AdBlockComponentServiceManager::EnableFilterList(const std::string& uuid,
UpdateFilterListPrefs(uuid, enabled);
}

void AdBlockComponentServiceManager::CheckAdBlockComponentsUpdate() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I believe we could add on demand callback in BraveOnDemandUpdate. Also no problem to use chromium OnDemandUpdater directly (a chromium example)

Also installing or updating a components has a several stages.

  1. Updating the component (including downloading .crx)
  2. Unpacking .crx and registering the new version
  3. Processing the content by a client code (=the adblock code here).
    The callback is about 2 (maybe 1), but definitely not about 3.
    Please be sure that you're waiting for the right things.

@antonok-edm
Copy link
Collaborator Author

Thanks to @goodov's work on #23169, this PR's implementation is significantly simpler. Should be ready for re-review.

@antonok-edm antonok-edm force-pushed the update-all-adblock-components-together branch 2 times, most recently from 3262d17 to a7996b7 Compare May 9, 2024 22:49
@antonok-edm antonok-edm requested a review from goodov May 9, 2024 22:50
Copy link
Member

@goodov goodov left a comment

Choose a reason for hiding this comment

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

lgtm with few more nits.

"UwNavFnj8gQDGVvCf+dse8HRMJn00QH0MOypsZSWFZRmF08ybOu/jTiUo/TuIaHL"
"1H8y9SR970LqsUMozu3ioSHtFh/IVgq7Nqy4TljaKsTE+3AdtjiOyHpW9ZaOkA7j"
"2QIDAQAB";

const char kCookieListEnabledHistogram[] = "Brave.Shields.CookieListEnabled";
const char kCookieListPromptHistogram[] = "Brave.Shields.CookieListPrompt";
Copy link
Member

Choose a reason for hiding this comment

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

I expected you to make all strings here to be inline constexpr. What you have right now is wrong.

@antonok-edm antonok-edm force-pushed the update-all-adblock-components-together branch from 45654a4 to 1eba796 Compare May 14, 2024 04:51
@antonok-edm antonok-edm enabled auto-merge May 14, 2024 05:01
@antonok-edm antonok-edm force-pushed the update-all-adblock-components-together branch from 1eba796 to 835551c Compare May 14, 2024 16:43
@antonok-edm antonok-edm merged commit 77af98d into master May 14, 2024
18 checks passed
@antonok-edm antonok-edm deleted the update-all-adblock-components-together branch May 14, 2024 18:22
@github-actions github-actions bot added this to the 1.68.x - Nightly milestone May 14, 2024
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.

Component updater should check for component updates more often (frequency set via Griffin)
6 participants