| 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 "device/battery/battery_status_service.h" | 5 #include "device/battery/battery_status_service.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 BatteryStatusService::~BatteryStatusService() { | 28 BatteryStatusService::~BatteryStatusService() { |
| 29 } | 29 } |
| 30 | 30 |
| 31 BatteryStatusService* BatteryStatusService::GetInstance() { | 31 BatteryStatusService* BatteryStatusService::GetInstance() { |
| 32 return base::Singleton< | 32 return base::Singleton< |
| 33 BatteryStatusService, | 33 BatteryStatusService, |
| 34 base::LeakySingletonTraits<BatteryStatusService>>::get(); | 34 base::LeakySingletonTraits<BatteryStatusService>>::get(); |
| 35 } | 35 } |
| 36 | 36 |
| 37 scoped_ptr<BatteryStatusService::BatteryUpdateSubscription> | 37 std::unique_ptr<BatteryStatusService::BatteryUpdateSubscription> |
| 38 BatteryStatusService::AddCallback(const BatteryUpdateCallback& callback) { | 38 BatteryStatusService::AddCallback(const BatteryUpdateCallback& callback) { |
| 39 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); | 39 DCHECK(main_thread_task_runner_->BelongsToCurrentThread()); |
| 40 DCHECK(!is_shutdown_); | 40 DCHECK(!is_shutdown_); |
| 41 | 41 |
| 42 if (!battery_fetcher_) | 42 if (!battery_fetcher_) |
| 43 battery_fetcher_ = BatteryStatusManager::Create(update_callback_); | 43 battery_fetcher_ = BatteryStatusManager::Create(update_callback_); |
| 44 | 44 |
| 45 if (callback_list_.empty()) { | 45 if (callback_list_.empty()) { |
| 46 bool success = battery_fetcher_->StartListeningBatteryChange(); | 46 bool success = battery_fetcher_->StartListeningBatteryChange(); |
| 47 // On failure pass the default values back. | 47 // On failure pass the default values back. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 battery_fetcher_.reset(); | 93 battery_fetcher_.reset(); |
| 94 is_shutdown_ = true; | 94 is_shutdown_ = true; |
| 95 } | 95 } |
| 96 | 96 |
| 97 const BatteryStatusService::BatteryUpdateCallback& | 97 const BatteryStatusService::BatteryUpdateCallback& |
| 98 BatteryStatusService::GetUpdateCallbackForTesting() const { | 98 BatteryStatusService::GetUpdateCallbackForTesting() const { |
| 99 return update_callback_; | 99 return update_callback_; |
| 100 } | 100 } |
| 101 | 101 |
| 102 void BatteryStatusService::SetBatteryManagerForTesting( | 102 void BatteryStatusService::SetBatteryManagerForTesting( |
| 103 scoped_ptr<BatteryStatusManager> test_battery_manager) { | 103 std::unique_ptr<BatteryStatusManager> test_battery_manager) { |
| 104 battery_fetcher_ = std::move(test_battery_manager); | 104 battery_fetcher_ = std::move(test_battery_manager); |
| 105 status_ = BatteryStatus(); | 105 status_ = BatteryStatus(); |
| 106 status_updated_ = false; | 106 status_updated_ = false; |
| 107 } | 107 } |
| 108 | 108 |
| 109 } // namespace device | 109 } // namespace device |
| OLD | NEW |