Add ICU message format support
[chromium-blink-merge.git] / base / power_monitor / power_monitor_source.cc
blob6868cb19e338e17b7d5c960b606b8f22845893da
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
3 // found in the LICENSE file.
5 #include "base/power_monitor/power_monitor_source.h"
7 #include "base/power_monitor/power_monitor.h"
9 namespace base {
11 PowerMonitorSource::PowerMonitorSource()
12 : on_battery_power_(false),
13 suspended_(false) {
16 PowerMonitorSource::~PowerMonitorSource() {
19 bool PowerMonitorSource::IsOnBatteryPower() {
20 AutoLock auto_lock(battery_lock_);
21 return on_battery_power_;
24 void PowerMonitorSource::ProcessPowerEvent(PowerEvent event_id) {
25 PowerMonitor* monitor = PowerMonitor::Get();
26 if (!monitor)
27 return;
29 PowerMonitorSource* source = monitor->Source();
31 // Suppress duplicate notifications. Some platforms may
32 // send multiple notifications of the same event.
33 switch (event_id) {
34 case POWER_STATE_EVENT:
36 bool new_on_battery_power = source->IsOnBatteryPowerImpl();
37 bool changed = false;
40 AutoLock auto_lock(source->battery_lock_);
41 if (source->on_battery_power_ != new_on_battery_power) {
42 changed = true;
43 source->on_battery_power_ = new_on_battery_power;
47 if (changed)
48 monitor->NotifyPowerStateChange(new_on_battery_power);
50 break;
51 case RESUME_EVENT:
52 if (source->suspended_) {
53 source->suspended_ = false;
54 monitor->NotifyResume();
56 break;
57 case SUSPEND_EVENT:
58 if (!source->suspended_) {
59 source->suspended_ = true;
60 monitor->NotifySuspend();
62 break;
66 } // namespace base