summaryrefslogtreecommitdiffstats
path: root/base/power_monitor/power_monitor_device_source.cc
blob: 0a3997517ec2e1d11edddfb6f98bf34ede69c8db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/power_monitor/power_monitor_device_source.h"

#include "base/time/time.h"

namespace base {

#if defined(ENABLE_BATTERY_MONITORING)
// The amount of time (in ms) to wait before running the initial
// battery check.
static int kDelayedBatteryCheckMs = 10 * 1000;
#endif  // defined(ENABLE_BATTERY_MONITORING)

PowerMonitorDeviceSource::PowerMonitorDeviceSource() {
  DCHECK(MessageLoop::current());
#if defined(ENABLE_BATTERY_MONITORING)
  delayed_battery_check_.Start(FROM_HERE,
      base::TimeDelta::FromMilliseconds(kDelayedBatteryCheckMs), this,
      &PowerMonitorDeviceSource::BatteryCheck);
#endif  // defined(ENABLE_BATTERY_MONITORING)
#if defined(OS_MACOSX)
  PlatformInit();
#endif
}

PowerMonitorDeviceSource::~PowerMonitorDeviceSource() {
#if defined(OS_MACOSX)
  PlatformDestroy();
#endif
}

void PowerMonitorDeviceSource::BatteryCheck() {
  ProcessPowerEvent(PowerMonitorSource::POWER_STATE_EVENT);
}

}  // namespace base