-
Notifications
You must be signed in to change notification settings - Fork 873
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
[Android] Ad notification shows up even when Brave-Beta is not running #7917 #4805
Conversation
|
||
base::OnceClosure completed_closure_local = base::BindOnce(&AdsNotificationHandler::OperationCompleted, | ||
base::Unretained(this), id); | ||
pending_callbacks_.emplace(id, std::move(completed_closure)); | ||
|
||
#if defined (OS_ANDROID) | ||
last_dismissed_notification_id_ = id; | ||
no_ui_shutdown_timer_.Stop(); | ||
#endif | ||
|
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.
If ads_service_
is null
, will this code end up being called twice (due to the if
clause below here that calls OnClose
again)? Wasn't sure, but maybe something to check...
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.
Fixed
} | ||
|
||
#if defined(OS_ANDROID) | ||
bool AdsNotificationHandler::IsHeadless(){ |
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.
Can this function be const?
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 should be static.
const std::string& notification_id) { | ||
|
||
auto iter = pending_callbacks_.find(notification_id); | ||
std::move(iter->second).Run(); |
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.
Seems like we should check iter
here before accessing it (or at least DCHECK
if we're confident that it's impossible).
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.
Fixed
#if defined(OS_ANDROID) | ||
bool AdsNotificationHandler::IsHeadless(){ | ||
auto state = base::android::ApplicationStatusListener::GetState(); | ||
bool uiless = (state == |
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.
Nit: Seems like we use headless
, no_ui
, and uiless
. I would just stick with one everywhere for consistency so it's clear that they all refer to the same thing.
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.
Using headless
everywhere
last_processed_notification_id){ | ||
last_dismissed_notification_id_ = ""; | ||
//wait and close the browser if running headless | ||
no_ui_shutdown_timer_.Stop(); |
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 don't think you need to explicitly call Stop
.
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.
Removed
//If during shutdown a new notification event arrives- | ||
//timer is stopped in corresponding handler function | ||
void AdsNotificationHandler::ShutdownTimerCallback(){ | ||
if (IsHeadless()) { |
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.
Is it safe to assume that any time Android is running in a headless mode, it's due to our ad notifications and is therefore safe to terminate? It seems like it would cause problems if that turned out not to be the case. At a minimum, we should probably have some kind of log here I think.
It seems like the issue we're trying to deal with is that the browser starts up with no UI when a notification is dismissed. Do we understand why that happens though? Maybe there's a less agressive way to deal with that scenario? cc: @bridiver
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 noticed, the Chromium 80 behaves the same way when a web notification is dismissed. But Brave starts serving ads in the background, which is not expected. We also don't want to consume extra battery resources when it's not needed.
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.
If we don't serve ads when we're running in a headless state, would it be a decent compromise? Seems like it may be good to try to follow the "standard" Chromium behavior (such as it is) as much as possible, just to future-proof ourselves when they inevitably change something here.
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.
How about to save some battery charge?
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 don't know too much about the battery cost, but it seems that if Google allows this mode for web notifications they probably decided it was a negligible cost to pay.
Anyway, will approve on my side - don't want to hold this up, but curious what others think.
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.
++
@@ -30,13 +35,18 @@ AdsNotificationHandler::~AdsNotificationHandler() { | |||
void AdsNotificationHandler::OnShow( | |||
Profile* profile, | |||
const std::string& id) { | |||
|
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.
nit: redundant line
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.
LGTM
734cd6c
to
1e77510
Compare
rebased and squashed |
1e77510
to
819f071
Compare
819f071
to
401e6cf
Compare
The only CI error (known issue) is: |
Fixes brave/brave-browser#7917
Submitter Checklist:
npm run lint
)git rebase master
(if needed).git rebase -i
to squash commits (if needed).Test Plan:
Reviewer Checklist:
After-merge Checklist:
changes has landed on.