OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |