| 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_manager_win.h" | 5 #include "device/battery/battery_status_manager_win.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/strings/string16.h" | 10 #include "base/strings/string16.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 } else { | 76 } else { |
| 77 // Could not create a message window, execute callback with the default | 77 // Could not create a message window, execute callback with the default |
| 78 // values. | 78 // values. |
| 79 callback_.Run(BatteryStatus()); | 79 callback_.Run(BatteryStatus()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 UpdateNumberBatteriesHistogram(); | 82 UpdateNumberBatteriesHistogram(); |
| 83 } | 83 } |
| 84 | 84 |
| 85 void Stop() { | 85 void Stop() { |
| 86 if (power_handle_) | 86 if (power_handle_) { |
| 87 UnregisterNotification(power_handle_); | 87 UnregisterNotification(power_handle_); |
| 88 if (battery_change_handle_) | 88 power_handle_ = NULL; |
| 89 } |
| 90 if (battery_change_handle_) { |
| 89 UnregisterNotification(battery_change_handle_); | 91 UnregisterNotification(battery_change_handle_); |
| 92 battery_change_handle_ = NULL; |
| 93 } |
| 90 window_.reset(); | 94 window_.reset(); |
| 91 } | 95 } |
| 92 | 96 |
| 93 private: | 97 private: |
| 94 void BatteryChanged() { | 98 void BatteryChanged() { |
| 95 SYSTEM_POWER_STATUS win_status; | 99 SYSTEM_POWER_STATUS win_status; |
| 96 if (GetSystemPowerStatus(&win_status)) | 100 if (GetSystemPowerStatus(&win_status)) |
| 97 callback_.Run(ComputeWebBatteryStatus(win_status)); | 101 callback_.Run(ComputeWebBatteryStatus(win_status)); |
| 98 else | 102 else |
| 99 callback_.Run(BatteryStatus()); | 103 callback_.Run(BatteryStatus()); |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 } | 207 } |
| 204 | 208 |
| 205 // static | 209 // static |
| 206 scoped_ptr<BatteryStatusManager> BatteryStatusManager::Create( | 210 scoped_ptr<BatteryStatusManager> BatteryStatusManager::Create( |
| 207 const BatteryStatusService::BatteryUpdateCallback& callback) { | 211 const BatteryStatusService::BatteryUpdateCallback& callback) { |
| 208 return scoped_ptr<BatteryStatusManager>( | 212 return scoped_ptr<BatteryStatusManager>( |
| 209 new BatteryStatusManagerWin(callback)); | 213 new BatteryStatusManagerWin(callback)); |
| 210 } | 214 } |
| 211 | 215 |
| 212 } // namespace device | 216 } // namespace device |
| OLD | NEW |