| 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_linux.h" | 5 #include "device/battery/battery_status_manager_linux.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <limits> | 10 #include <limits> |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 257 properties_.reset(); // before the proxy is deleted. | 257 properties_.reset(); // before the proxy is deleted. |
| 258 dbus_->RemoveObjectProxy(kUPowerServiceName, proxy_->object_path(), | 258 dbus_->RemoveObjectProxy(kUPowerServiceName, proxy_->object_path(), |
| 259 base::Bind(&base::DoNothing)); | 259 base::Bind(&base::DoNothing)); |
| 260 } | 260 } |
| 261 | 261 |
| 262 bool BatteryObject::IsValid() { | 262 bool BatteryObject::IsValid() { |
| 263 return properties_->is_present() && | 263 return properties_->is_present() && |
| 264 properties_->type() == UPOWER_DEVICE_TYPE_BATTERY; | 264 properties_->type() == UPOWER_DEVICE_TYPE_BATTERY; |
| 265 } | 265 } |
| 266 | 266 |
| 267 BatteryStatus ComputeWebBatteryStatus(BatteryProperties* properties) { | 267 mojom::BatteryStatus ComputeWebBatteryStatus(BatteryProperties* properties) { |
| 268 BatteryStatus status; | 268 mojom::BatteryStatus status; |
| 269 uint32_t state = properties->state(); | 269 uint32_t state = properties->state(); |
| 270 status.charging = state != UPOWER_DEVICE_STATE_DISCHARGING && | 270 status.charging = state != UPOWER_DEVICE_STATE_DISCHARGING && |
| 271 state != UPOWER_DEVICE_STATE_EMPTY; | 271 state != UPOWER_DEVICE_STATE_EMPTY; |
| 272 // Convert percentage to a value between 0 and 1 with 2 digits of precision. | 272 // Convert percentage to a value between 0 and 1 with 2 digits of precision. |
| 273 // This is to bring it in line with other platforms like Mac and Android where | 273 // This is to bring it in line with other platforms like Mac and Android where |
| 274 // we report level with 1% granularity. It also serves the purpose of reducing | 274 // we report level with 1% granularity. It also serves the purpose of reducing |
| 275 // the possibility of fingerprinting and triggers less level change events on | 275 // the possibility of fingerprinting and triggers less level change events on |
| 276 // the blink side. | 276 // the blink side. |
| 277 // TODO(timvolodine): consider moving this rounding to the blink side. | 277 // TODO(timvolodine): consider moving this rounding to the blink side. |
| 278 status.level = round(properties->percentage()) / 100.f; | 278 status.level = round(properties->percentage()) / 100.f; |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 num_batteries++; | 430 num_batteries++; |
| 431 } | 431 } |
| 432 | 432 |
| 433 UpdateNumberBatteriesHistogram(num_batteries); | 433 UpdateNumberBatteriesHistogram(num_batteries); |
| 434 } | 434 } |
| 435 | 435 |
| 436 if (battery_) { | 436 if (battery_) { |
| 437 battery_->properties()->ConnectSignals(); | 437 battery_->properties()->ConnectSignals(); |
| 438 NotifyBatteryStatus(); | 438 NotifyBatteryStatus(); |
| 439 } else { | 439 } else { |
| 440 callback_.Run(BatteryStatus()); | 440 callback_.Run(mojom::BatteryStatus()); |
| 441 return; | 441 return; |
| 442 } | 442 } |
| 443 | 443 |
| 444 if (IsDaemonVersionBelow_0_99()) { | 444 if (IsDaemonVersionBelow_0_99()) { |
| 445 // UPower Version 0.99 replaced the Changed signal with the | 445 // UPower Version 0.99 replaced the Changed signal with the |
| 446 // PropertyChanged signal. For older versions we need to listen | 446 // PropertyChanged signal. For older versions we need to listen |
| 447 // to the Changed signal. | 447 // to the Changed signal. |
| 448 battery_->proxy()->ConnectToSignal( | 448 battery_->proxy()->ConnectToSignal( |
| 449 kUPowerDeviceInterfaceName, kUPowerDeviceSignalChanged, | 449 kUPowerDeviceInterfaceName, kUPowerDeviceSignalChanged, |
| 450 base::Bind(&BatteryStatusNotificationThread::BatteryChanged, | 450 base::Bind(&BatteryStatusNotificationThread::BatteryChanged, |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 618 } | 618 } |
| 619 | 619 |
| 620 // static | 620 // static |
| 621 std::unique_ptr<BatteryStatusManager> BatteryStatusManager::Create( | 621 std::unique_ptr<BatteryStatusManager> BatteryStatusManager::Create( |
| 622 const BatteryStatusService::BatteryUpdateCallback& callback) { | 622 const BatteryStatusService::BatteryUpdateCallback& callback) { |
| 623 return std::unique_ptr<BatteryStatusManager>( | 623 return std::unique_ptr<BatteryStatusManager>( |
| 624 new BatteryStatusManagerLinux(callback)); | 624 new BatteryStatusManagerLinux(callback)); |
| 625 } | 625 } |
| 626 | 626 |
| 627 } // namespace device | 627 } // namespace device |
| OLD | NEW |