-
Notifications
You must be signed in to change notification settings - Fork 893
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
Navigator.getBattery should return constant result #567
Conversation
40af933
to
dc036ef
Compare
#include "net/proxy_resolution/proxy_resolver_v8.h" | ||
#include "third_party/blink/renderer/core/execution_context/execution_context.h" |
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.
why are we still overriding this at all?
} | ||
|
||
bool BatteryManager::charging() { | ||
return true; |
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.
shouldn't this be false?
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.
We are not using this function at all, I picked true
as the default value for charging. Shouldn't be hard to change this to false.
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.
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 you check the values on a fully charged and plugged in laptop?
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.
Chrome:
Fully charged:
charging: true
chargingTime: 0
dischargingTime: Infinity
level: 1
onchargingchange: null
onchargingtimechange: null
ondischargingtimechange: null
onlevelchange: null
89%
charging: false
chargingTime: Infinity
dischargingTime: 5820
level: 0.89
onchargingchange: null
onchargingtimechange: null
ondischargingtimechange: null
onlevelchange: null
Brave (with fix):
Fully charged:
charging: true
chargingTime: 0
dischargingTime: Infinity
level: 1
onchargingchange: null
onchargingtimechange: null
ondischargingtimechange: null
onlevelchange: null
89%:
[[PromiseValue]]: BatteryManager
charging: true
chargingTime: 0
dischargingTime: Infinity
level: 1
onchargingchange: null
onchargingtimechange: null
ondischargingtimechange: null
onlevelchange: null
|
||
BatteryManager* BatteryManager::Create(ExecutionContext* context) { | ||
BatteryManager* battery_manager = new BatteryManager(context); | ||
battery_manager->PauseIfNeeded(); |
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 we need to call this here because Pause/Unpause are noops anyway
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.
Without this a DCHECK
is invoked when the BatteryManager destructor is called [30122:775:1005/101814.262486:FATAL:pausable_object.cc(49)] Check failed: pause_if_needed_called_.
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.
👍
|
||
ScriptPromise BatteryManager::StartRequest(ScriptState* script_state) { | ||
if (!battery_property_) { | ||
BatteryStatus* status = new BatteryStatus(); |
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.
battery status is never used and this will leak memory for every page
} | ||
|
||
void BatteryManager::UnregisterWithDispatcher() { | ||
return; |
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.
upstream sets battery_property_ to null here and I think that might be necessary for GC of the Member
property
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.
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.
sorry, wrong method. Happens in ContextDestroyed below which is now correct
Navigator.getBattery should return constant result
Navigator.getBattery should return constant result
fix brave/brave-browser#1398
Submitter Checklist:
git rebase -i
to squash commits (if needed).Test Plan:
navigator.getBattery()
getBattery
again and verify the values remain the same.Reviewer Checklist: