Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(668)

Unified Diff: content/browser/battery_status/battery_status_service.cc

Issue 334223003: Battery Status API: end-to-end browsertests and default values. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « content/browser/battery_status/battery_status_browsertest.cc ('k') | content/content_tests.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/battery_status/battery_status_service.cc
diff --git a/content/browser/battery_status/battery_status_service.cc b/content/browser/battery_status/battery_status_service.cc
index dc4c690ab050c07907590a7b57d31b4784bb35d9..21d59d3780d0f2fd75e958d9b7767a6b408f7462 100644
--- a/content/browser/battery_status/battery_status_service.cc
+++ b/content/browser/battery_status/battery_status_service.cc
@@ -11,10 +11,10 @@
namespace content {
BatteryStatusService::BatteryStatusService()
- : status_updated_(false),
+ : update_callback_(base::Bind(&BatteryStatusService::UpdateBatteryStatus,
+ base::Unretained(this))),
+ status_updated_(false),
is_shutdown_(false) {
- update_callback_ = base::Bind(&BatteryStatusService::UpdateBatteryStatus,
- base::Unretained(this));
callback_list_.set_removal_callback(
base::Bind(&BatteryStatusService::ConsumersChanged,
base::Unretained(this)));
@@ -36,8 +36,13 @@ BatteryStatusService::AddCallback(const BatteryUpdateCallback& callback) {
if (!battery_fetcher_)
battery_fetcher_.reset(new BatteryStatusManager(update_callback_));
- if (callback_list_.empty())
- battery_fetcher_->StartListeningBatteryChange();
+ if (callback_list_.empty()) {
+ bool success = battery_fetcher_->StartListeningBatteryChange();
+ if (!success) {
+ // Make sure the promise resolves with the default values in Blink.
+ callback.Run(blink::WebBatteryStatus());
+ }
+ }
if (status_updated_) {
// Send recent status to the new callback if already available.
@@ -80,7 +85,7 @@ void BatteryStatusService::NotifyConsumers(
void BatteryStatusService::Shutdown() {
if (!callback_list_.empty())
- battery_fetcher_->StopListeningBatteryChange();
+ battery_fetcher_->StopListeningBatteryChange();
battery_fetcher_.reset();
is_shutdown_ = true;
}
« no previous file with comments | « content/browser/battery_status/battery_status_browsertest.cc ('k') | content/content_tests.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698