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 "services/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> |
11 #include <memory> | 11 #include <memory> |
12 #include <string> | 12 #include <string> |
13 #include <utility> | 13 #include <utility> |
14 #include <vector> | 14 #include <vector> |
15 | 15 |
16 #include "base/macros.h" | 16 #include "base/macros.h" |
17 #include "base/metrics/histogram_macros.h" | 17 #include "base/metrics/histogram_macros.h" |
18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
19 #include "base/threading/thread.h" | 19 #include "base/threading/thread.h" |
20 #include "base/values.h" | 20 #include "base/values.h" |
21 #include "base/version.h" | 21 #include "base/version.h" |
22 #include "dbus/bus.h" | 22 #include "dbus/bus.h" |
23 #include "dbus/message.h" | 23 #include "dbus/message.h" |
24 #include "dbus/object_path.h" | 24 #include "dbus/object_path.h" |
25 #include "dbus/object_proxy.h" | 25 #include "dbus/object_proxy.h" |
26 #include "dbus/property.h" | 26 #include "dbus/property.h" |
27 #include "dbus/values_util.h" | 27 #include "dbus/values_util.h" |
28 #include "device/battery/battery_status_manager_linux-inl.h" | 28 #include "services/device/battery/battery_status_manager_linux-inl.h" |
29 | 29 |
30 namespace device { | 30 namespace device { |
31 namespace { | 31 namespace { |
32 const char kBatteryNotifierThreadName[] = "BatteryStatusNotifier"; | 32 const char kBatteryNotifierThreadName[] = "BatteryStatusNotifier"; |
33 | 33 |
34 class UPowerProperties : public dbus::PropertySet { | 34 class UPowerProperties : public dbus::PropertySet { |
35 public: | 35 public: |
36 UPowerProperties(dbus::ObjectProxy* object_proxy, | 36 UPowerProperties(dbus::ObjectProxy* object_proxy, |
37 const PropertyChangedCallback callback); | 37 const PropertyChangedCallback callback); |
38 ~UPowerProperties() override; | 38 ~UPowerProperties() override; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); | 120 &method_call, dbus::ObjectProxy::TIMEOUT_USE_DEFAULT)); |
121 | 121 |
122 if (response) { | 122 if (response) { |
123 dbus::MessageReader reader(response.get()); | 123 dbus::MessageReader reader(response.get()); |
124 reader.PopObjectPath(&display_device_path); | 124 reader.PopObjectPath(&display_device_path); |
125 } | 125 } |
126 return display_device_path; | 126 return display_device_path; |
127 } | 127 } |
128 | 128 |
129 void UpdateNumberBatteriesHistogram(int count) { | 129 void UpdateNumberBatteriesHistogram(int count) { |
130 UMA_HISTOGRAM_CUSTOM_COUNTS( | 130 UMA_HISTOGRAM_CUSTOM_COUNTS("BatteryStatus.NumberBatteriesLinux", count, 1, 5, |
131 "BatteryStatus.NumberBatteriesLinux", count, 1, 5, 6); | 131 6); |
132 } | 132 } |
133 | 133 |
134 class BatteryProperties : public dbus::PropertySet { | 134 class BatteryProperties : public dbus::PropertySet { |
135 public: | 135 public: |
136 BatteryProperties(dbus::ObjectProxy* object_proxy, | 136 BatteryProperties(dbus::ObjectProxy* object_proxy, |
137 const PropertyChangedCallback callback); | 137 const PropertyChangedCallback callback); |
138 ~BatteryProperties() override; | 138 ~BatteryProperties() override; |
139 | 139 |
140 void ConnectSignals() override; | 140 void ConnectSignals() override; |
141 | 141 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 } | 353 } |
354 | 354 |
355 void StopListening() { | 355 void StopListening() { |
356 DCHECK(OnWatcherThread()); | 356 DCHECK(OnWatcherThread()); |
357 ShutdownDBusConnection(); | 357 ShutdownDBusConnection(); |
358 } | 358 } |
359 | 359 |
360 void SetDBusForTesting(dbus::Bus* bus) { system_bus_ = bus; } | 360 void SetDBusForTesting(dbus::Bus* bus) { system_bus_ = bus; } |
361 | 361 |
362 private: | 362 private: |
363 bool OnWatcherThread() { | 363 bool OnWatcherThread() { return task_runner()->BelongsToCurrentThread(); } |
364 return task_runner()->BelongsToCurrentThread(); | |
365 } | |
366 | 364 |
367 void InitDBus() { | 365 void InitDBus() { |
368 DCHECK(OnWatcherThread()); | 366 DCHECK(OnWatcherThread()); |
369 | 367 |
370 dbus::Bus::Options options; | 368 dbus::Bus::Options options; |
371 options.bus_type = dbus::Bus::SYSTEM; | 369 options.bus_type = dbus::Bus::SYSTEM; |
372 options.connection_type = dbus::Bus::PRIVATE; | 370 options.connection_type = dbus::Bus::PRIVATE; |
373 system_bus_ = new dbus::Bus(options); | 371 system_bus_ = new dbus::Bus(options); |
374 } | 372 } |
375 | 373 |
376 bool IsDaemonVersionBelow_0_99() { | 374 bool IsDaemonVersionBelow_0_99() { |
377 base::Version daemon_version = upower_->properties()->daemon_version(); | 375 base::Version daemon_version = upower_->properties()->daemon_version(); |
378 return daemon_version.IsValid() && | 376 return daemon_version.IsValid() && |
379 daemon_version.CompareTo(base::Version("0.99")) < 0; | 377 daemon_version.CompareTo(base::Version("0.99")) < 0; |
380 } | 378 } |
381 | 379 |
382 void FindBatteryDevice() { | 380 void FindBatteryDevice() { |
383 // Move the currently watched battery_ device to a stack-local variable such | 381 // Move the currently watched battery_ device to a stack-local variable such |
384 // that we can enumerate all devices (once more): | 382 // that we can enumerate all devices (once more): |
385 // first testing the display device, then testing all devices from | 383 // first testing the display device, then testing all devices from |
386 // EnumerateDevices. We will monitor the first battery device we find. | 384 // EnumerateDevices. We will monitor the first battery device we find. |
387 // - That may be the same device we did monitor on entering this method; | 385 // - That may be the same device we did monitor on entering this method; |
388 // then we'll use the same BatteryObject instance, that was moved to | 386 // then we'll use the same BatteryObject instance, that was moved to |
389 // current - see UseCurrentOrCreateBattery(). | 387 // current - see UseCurrentOrCreateBattery(). |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
613 return manager; | 611 return manager; |
614 } | 612 } |
615 | 613 |
616 // static | 614 // static |
617 std::unique_ptr<BatteryStatusManager> BatteryStatusManager::Create( | 615 std::unique_ptr<BatteryStatusManager> BatteryStatusManager::Create( |
618 const BatteryStatusService::BatteryUpdateCallback& callback) { | 616 const BatteryStatusService::BatteryUpdateCallback& callback) { |
619 return base::MakeUnique<BatteryStatusManagerLinux>(callback); | 617 return base::MakeUnique<BatteryStatusManagerLinux>(callback); |
620 } | 618 } |
621 | 619 |
622 } // namespace device | 620 } // namespace device |
OLD | NEW |