OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "base/power_monitor/power_monitor_device_source.h" | 5 #include "base/power_monitor/power_monitor_device_source.h" |
6 | 6 |
7 #include "base/threading/thread_task_runner_handle.h" | 7 #include "base/threading/thread_task_runner_handle.h" |
8 #include "base/time/time.h" | |
9 #include "build/build_config.h" | |
10 | 8 |
11 namespace base { | 9 namespace base { |
12 | 10 |
13 #if defined(ENABLE_BATTERY_MONITORING) | |
14 // The amount of time (in ms) to wait before running the initial | |
15 // battery check. | |
16 static int kDelayedBatteryCheckMs = 10 * 1000; | |
17 #endif // defined(ENABLE_BATTERY_MONITORING) | |
18 | |
19 PowerMonitorDeviceSource::PowerMonitorDeviceSource() { | 11 PowerMonitorDeviceSource::PowerMonitorDeviceSource() { |
20 DCHECK(ThreadTaskRunnerHandle::IsSet()); | 12 DCHECK(ThreadTaskRunnerHandle::IsSet()); |
21 #if defined(ENABLE_BATTERY_MONITORING) | 13 |
22 delayed_battery_check_.Start(FROM_HERE, | |
23 base::TimeDelta::FromMilliseconds(kDelayedBatteryCheckMs), this, | |
24 &PowerMonitorDeviceSource::BatteryCheck); | |
25 #endif // defined(ENABLE_BATTERY_MONITORING) | |
26 #if defined(OS_MACOSX) | 14 #if defined(OS_MACOSX) |
27 PlatformInit(); | 15 PlatformInit(); |
28 #endif | 16 #endif |
| 17 |
| 18 #if defined(OS_WIN) || defined(OS_MACOSX) |
| 19 // Provide the correct battery status if possible. Others platforms, such as |
| 20 // Android and ChromeOS, will update their status once their backends are |
| 21 // actually initialized. |
| 22 SetInitialOnBatteryPowerState(IsOnBatteryPowerImpl()); |
| 23 #endif |
29 } | 24 } |
30 | 25 |
31 PowerMonitorDeviceSource::~PowerMonitorDeviceSource() { | 26 PowerMonitorDeviceSource::~PowerMonitorDeviceSource() { |
32 #if defined(OS_MACOSX) | 27 #if defined(OS_MACOSX) |
33 PlatformDestroy(); | 28 PlatformDestroy(); |
34 #endif | 29 #endif |
35 } | 30 } |
36 | 31 |
37 void PowerMonitorDeviceSource::BatteryCheck() { | |
38 ProcessPowerEvent(PowerMonitorSource::POWER_STATE_EVENT); | |
39 } | |
40 | |
41 } // namespace base | 32 } // namespace base |
OLD | NEW |