| 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_monitor_impl.h" | 5 #include "device/battery/battery_monitor_impl.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 // NOTE: DidChange may be called before AddCallback returns. This is done to | 23 // NOTE: DidChange may be called before AddCallback returns. This is done to |
| 24 // report current status. | 24 // report current status. |
| 25 subscription_ = BatteryStatusService::GetInstance()->AddCallback( | 25 subscription_ = BatteryStatusService::GetInstance()->AddCallback( |
| 26 base::Bind(&BatteryMonitorImpl::DidChange, base::Unretained(this))); | 26 base::Bind(&BatteryMonitorImpl::DidChange, base::Unretained(this))); |
| 27 } | 27 } |
| 28 | 28 |
| 29 BatteryMonitorImpl::~BatteryMonitorImpl() { | 29 BatteryMonitorImpl::~BatteryMonitorImpl() { |
| 30 } | 30 } |
| 31 | 31 |
| 32 void BatteryMonitorImpl::QueryNextStatus( | 32 void BatteryMonitorImpl::QueryNextStatus( |
| 33 const QueryNextStatusCallback& callback) { | 33 const BatteryStatusCallback& callback) { |
| 34 if (!callback_.is_null()) { | 34 if (!callback_.is_null()) { |
| 35 DVLOG(1) << "Overlapped call to QueryNextStatus!"; | 35 DVLOG(1) << "Overlapped call to QueryNextStatus!"; |
| 36 delete this; | 36 delete this; |
| 37 return; | 37 return; |
| 38 } | 38 } |
| 39 callback_ = callback; | 39 callback_ = callback; |
| 40 | 40 |
| 41 if (status_to_report_) | 41 if (status_to_report_) |
| 42 ReportStatus(); | 42 ReportStatus(); |
| 43 } | 43 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 54 } | 54 } |
| 55 | 55 |
| 56 void BatteryMonitorImpl::ReportStatus() { | 56 void BatteryMonitorImpl::ReportStatus() { |
| 57 callback_.Run(status_.Clone()); | 57 callback_.Run(status_.Clone()); |
| 58 callback_.Reset(); | 58 callback_.Reset(); |
| 59 | 59 |
| 60 status_to_report_ = false; | 60 status_to_report_ = false; |
| 61 } | 61 } |
| 62 | 62 |
| 63 } // namespace device | 63 } // namespace device |
| OLD | NEW |