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> |
| 8 #include <stdint.h> |
| 9 |
7 #include "base/macros.h" | 10 #include "base/macros.h" |
8 #include "base/metrics/histogram.h" | 11 #include "base/metrics/histogram.h" |
9 #include "base/threading/thread.h" | 12 #include "base/threading/thread.h" |
10 #include "base/values.h" | 13 #include "base/values.h" |
11 #include "dbus/bus.h" | 14 #include "dbus/bus.h" |
12 #include "dbus/message.h" | 15 #include "dbus/message.h" |
13 #include "dbus/object_path.h" | 16 #include "dbus/object_path.h" |
14 #include "dbus/object_proxy.h" | 17 #include "dbus/object_proxy.h" |
15 #include "dbus/property.h" | 18 #include "dbus/property.h" |
16 #include "dbus/values_util.h" | 19 #include "dbus/values_util.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
140 const dbus::ObjectPath& device_path = device_paths->at(i); | 143 const dbus::ObjectPath& device_path = device_paths->at(i); |
141 dbus::ObjectProxy* device_proxy = system_bus_->GetObjectProxy( | 144 dbus::ObjectProxy* device_proxy = system_bus_->GetObjectProxy( |
142 kUPowerServiceName, device_path); | 145 kUPowerServiceName, device_path); |
143 scoped_ptr<base::DictionaryValue> dictionary = | 146 scoped_ptr<base::DictionaryValue> dictionary = |
144 GetPropertiesAsDictionary(device_proxy); | 147 GetPropertiesAsDictionary(device_proxy); |
145 | 148 |
146 if (!dictionary) | 149 if (!dictionary) |
147 continue; | 150 continue; |
148 | 151 |
149 bool is_present = GetPropertyAsBoolean(*dictionary, "IsPresent", false); | 152 bool is_present = GetPropertyAsBoolean(*dictionary, "IsPresent", false); |
150 uint32 type = static_cast<uint32>( | 153 uint32_t type = static_cast<uint32_t>( |
151 GetPropertyAsDouble(*dictionary, "Type", UPOWER_DEVICE_TYPE_UNKNOWN)); | 154 GetPropertyAsDouble(*dictionary, "Type", UPOWER_DEVICE_TYPE_UNKNOWN)); |
152 | 155 |
153 if (!is_present || type != UPOWER_DEVICE_TYPE_BATTERY) { | 156 if (!is_present || type != UPOWER_DEVICE_TYPE_BATTERY) { |
154 system_bus_->RemoveObjectProxy(kUPowerServiceName, | 157 system_bus_->RemoveObjectProxy(kUPowerServiceName, |
155 device_path, | 158 device_path, |
156 base::Bind(&base::DoNothing)); | 159 base::Bind(&base::DoNothing)); |
157 continue; | 160 continue; |
158 } | 161 } |
159 | 162 |
160 if (battery_proxy_) { | 163 if (battery_proxy_) { |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 DISALLOW_COPY_AND_ASSIGN(BatteryStatusManagerLinux); | 320 DISALLOW_COPY_AND_ASSIGN(BatteryStatusManagerLinux); |
318 }; | 321 }; |
319 | 322 |
320 } // namespace | 323 } // namespace |
321 | 324 |
322 BatteryStatus ComputeWebBatteryStatus(const base::DictionaryValue& dictionary) { | 325 BatteryStatus ComputeWebBatteryStatus(const base::DictionaryValue& dictionary) { |
323 BatteryStatus status; | 326 BatteryStatus status; |
324 if (!dictionary.HasKey("State")) | 327 if (!dictionary.HasKey("State")) |
325 return status; | 328 return status; |
326 | 329 |
327 uint32 state = static_cast<uint32>( | 330 uint32_t state = static_cast<uint32_t>( |
328 GetPropertyAsDouble(dictionary, "State", UPOWER_DEVICE_STATE_UNKNOWN)); | 331 GetPropertyAsDouble(dictionary, "State", UPOWER_DEVICE_STATE_UNKNOWN)); |
329 status.charging = state != UPOWER_DEVICE_STATE_DISCHARGING && | 332 status.charging = state != UPOWER_DEVICE_STATE_DISCHARGING && |
330 state != UPOWER_DEVICE_STATE_EMPTY; | 333 state != UPOWER_DEVICE_STATE_EMPTY; |
331 double percentage = GetPropertyAsDouble(dictionary, "Percentage", 100); | 334 double percentage = GetPropertyAsDouble(dictionary, "Percentage", 100); |
332 // Convert percentage to a value between 0 and 1 with 2 digits of precision. | 335 // Convert percentage to a value between 0 and 1 with 2 digits of precision. |
333 // This is to bring it in line with other platforms like Mac and Android where | 336 // This is to bring it in line with other platforms like Mac and Android where |
334 // we report level with 1% granularity. It also serves the purpose of reducing | 337 // we report level with 1% granularity. It also serves the purpose of reducing |
335 // the possibility of fingerprinting and triggers less level change events on | 338 // the possibility of fingerprinting and triggers less level change events on |
336 // the blink side. | 339 // the blink side. |
337 // TODO(timvolodine): consider moving this rounding to the blink side. | 340 // TODO(timvolodine): consider moving this rounding to the blink side. |
(...skipping 27 matching lines...) Expand all Loading... |
365 } | 368 } |
366 | 369 |
367 // static | 370 // static |
368 scoped_ptr<BatteryStatusManager> BatteryStatusManager::Create( | 371 scoped_ptr<BatteryStatusManager> BatteryStatusManager::Create( |
369 const BatteryStatusService::BatteryUpdateCallback& callback) { | 372 const BatteryStatusService::BatteryUpdateCallback& callback) { |
370 return scoped_ptr<BatteryStatusManager>( | 373 return scoped_ptr<BatteryStatusManager>( |
371 new BatteryStatusManagerLinux(callback)); | 374 new BatteryStatusManagerLinux(callback)); |
372 } | 375 } |
373 | 376 |
374 } // namespace device | 377 } // namespace device |
OLD | NEW |