Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(137)

Side by Side Diff: base/power_monitor/power_monitor_source.cc

Issue 17074009: Created multi-process-friendly PowerMonitor interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing windows unit test errors Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/power_monitor/power_monitor_source.h ('k') | base/power_monitor/power_monitor_test_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "base/power_monitor/power_monitor_source.h"
6
7 #include "base/power_monitor/power_monitor.h"
8
9 namespace base {
10
11 PowerMonitorSource::PowerMonitorSource()
12 : on_battery_power_(false),
13 suspended_(false) {
14 }
15
16 PowerMonitorSource::~PowerMonitorSource() {
17 }
18
19 bool PowerMonitorSource::IsOnBatteryPower() {
20 AutoLock auto_lock(battery_lock_);
21 return on_battery_power_;
22 }
23
24 void PowerMonitorSource::ProcessPowerEvent(PowerEvent event_id) {
25 PowerMonitor* monitor = PowerMonitor::Get();
26 if (!monitor)
27 return;
28
29 PowerMonitorSource* source = monitor->Source();
30
31 // Suppress duplicate notifications. Some platforms may
32 // send multiple notifications of the same event.
33 switch (event_id) {
34 case POWER_STATE_EVENT:
35 {
36 bool new_on_battery_power = source->IsOnBatteryPowerImpl();
37 bool changed = false;
38
39 {
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;
44 }
45 }
46
47 if (changed)
48 monitor->NotifyPowerStateChange(new_on_battery_power);
49 }
50 break;
51 case RESUME_EVENT:
52 if (source->suspended_) {
53 source->suspended_ = false;
54 monitor->NotifyResume();
55 }
56 break;
57 case SUSPEND_EVENT:
58 if (!source->suspended_) {
59 source->suspended_ = true;
60 monitor->NotifySuspend();
61 }
62 break;
63 }
64 }
65
66 } // namespace base
OLDNEW
« no previous file with comments | « base/power_monitor/power_monitor_source.h ('k') | base/power_monitor/power_monitor_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698