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

Side by Side Diff: content/browser/battery_status/battery_status_service.cc

Issue 356873002: battery-status: Implement the battery-status API for chromeos. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/battery_status/battery_status_service.h" 5 #include "content/browser/battery_status/battery_status_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "content/browser/battery_status/battery_status_manager.h" 8 #include "content/browser/battery_status/battery_status_manager.h"
9 #include "content/public/browser/browser_thread.h" 9 #include "content/public/browser/browser_thread.h"
10 10
(...skipping 16 matching lines...) Expand all
27 return Singleton<BatteryStatusService, 27 return Singleton<BatteryStatusService,
28 LeakySingletonTraits<BatteryStatusService> >::get(); 28 LeakySingletonTraits<BatteryStatusService> >::get();
29 } 29 }
30 30
31 scoped_ptr<BatteryStatusService::BatteryUpdateSubscription> 31 scoped_ptr<BatteryStatusService::BatteryUpdateSubscription>
32 BatteryStatusService::AddCallback(const BatteryUpdateCallback& callback) { 32 BatteryStatusService::AddCallback(const BatteryUpdateCallback& callback) {
33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
34 DCHECK(!is_shutdown_); 34 DCHECK(!is_shutdown_);
35 35
36 if (!battery_fetcher_) 36 if (!battery_fetcher_)
37 battery_fetcher_.reset(new BatteryStatusManager(update_callback_)); 37 battery_fetcher_ = BatteryStatusManager::Create(update_callback_);
38 38
39 if (callback_list_.empty()) { 39 if (callback_list_.empty()) {
40 bool success = battery_fetcher_->StartListeningBatteryChange(); 40 bool success = battery_fetcher_->StartListeningBatteryChange();
41 if (!success) { 41 if (!success) {
42 // Make sure the promise resolves with the default values in Blink. 42 // Make sure the promise resolves with the default values in Blink.
43 callback.Run(blink::WebBatteryStatus()); 43 callback.Run(blink::WebBatteryStatus());
44 } 44 }
45 } 45 }
46 46
47 if (status_updated_) { 47 if (status_updated_) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 97
98 void BatteryStatusService::SetBatteryManagerForTesting( 98 void BatteryStatusService::SetBatteryManagerForTesting(
99 BatteryStatusManager* test_battery_manager) { 99 BatteryStatusManager* test_battery_manager) {
100 battery_fetcher_.reset(test_battery_manager); 100 battery_fetcher_.reset(test_battery_manager);
101 blink::WebBatteryStatus status; 101 blink::WebBatteryStatus status;
102 status_ = status; 102 status_ = status;
103 status_updated_ = false; 103 status_updated_ = false;
104 } 104 }
105 105
106 } // namespace content 106 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698