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

Side by Side Diff: base/system_monitor/system_monitor.cc

Issue 8528044: Revert 109960 - Send WM_DEVICECHANGE message through SystemMonitor (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 1 month 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/system_monitor/system_monitor.h ('k') | base/system_monitor/system_monitor_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/system_monitor/system_monitor.h" 5 #include "base/system_monitor/system_monitor.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 10
11 namespace base { 11 namespace base {
12 12
13 static SystemMonitor* g_system_monitor = NULL; 13 static SystemMonitor* g_system_monitor = NULL;
14 14
15 #if defined(ENABLE_BATTERY_MONITORING) 15 #if defined(ENABLE_BATTERY_MONITORING)
16 // The amount of time (in ms) to wait before running the initial 16 // The amount of time (in ms) to wait before running the initial
17 // battery check. 17 // battery check.
18 static int kDelayedBatteryCheckMs = 10 * 1000; 18 static int kDelayedBatteryCheckMs = 10 * 1000;
19 #endif // defined(ENABLE_BATTERY_MONITORING) 19 #endif // defined(ENABLE_BATTERY_MONITORING)
20 20
21 SystemMonitor::SystemMonitor() 21 SystemMonitor::SystemMonitor()
22 : power_observer_list_(new ObserverListThreadSafe<PowerObserver>()), 22 : observer_list_(new ObserverListThreadSafe<PowerObserver>()),
23 devices_changed_observer_list_(
24 new ObserverListThreadSafe<DevicesChangedObserver>()),
25 battery_in_use_(false), 23 battery_in_use_(false),
26 suspended_(false) { 24 suspended_(false) {
27 DCHECK(!g_system_monitor); 25 DCHECK(!g_system_monitor);
28 g_system_monitor = this; 26 g_system_monitor = this;
29 27
30 DCHECK(MessageLoop::current()); 28 DCHECK(MessageLoop::current());
31 #if defined(ENABLE_BATTERY_MONITORING) 29 #if defined(ENABLE_BATTERY_MONITORING)
32 delayed_battery_check_.Start(FROM_HERE, 30 delayed_battery_check_.Start(FROM_HERE,
33 base::TimeDelta::FromMilliseconds(kDelayedBatteryCheckMs), this, 31 base::TimeDelta::FromMilliseconds(kDelayedBatteryCheckMs), this,
34 &SystemMonitor::BatteryCheck); 32 &SystemMonitor::BatteryCheck);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 break; 70 break;
73 case SUSPEND_EVENT: 71 case SUSPEND_EVENT:
74 if (!suspended_) { 72 if (!suspended_) {
75 suspended_ = true; 73 suspended_ = true;
76 NotifySuspend(); 74 NotifySuspend();
77 } 75 }
78 break; 76 break;
79 } 77 }
80 } 78 }
81 79
82 void SystemMonitor::ProcessDevicesChanged() { 80 void SystemMonitor::AddObserver(PowerObserver* obs) {
83 NotifyDevicesChanged(); 81 observer_list_->AddObserver(obs);
84 } 82 }
85 83
86 void SystemMonitor::AddPowerObserver(PowerObserver* obs) { 84 void SystemMonitor::RemoveObserver(PowerObserver* obs) {
87 power_observer_list_->AddObserver(obs); 85 observer_list_->RemoveObserver(obs);
88 }
89
90 void SystemMonitor::RemovePowerObserver(PowerObserver* obs) {
91 power_observer_list_->RemoveObserver(obs);
92 }
93
94 void SystemMonitor::AddDevicesChangedObserver(DevicesChangedObserver* obs) {
95 devices_changed_observer_list_->AddObserver(obs);
96 }
97
98 void SystemMonitor::RemoveDevicesChangedObserver(DevicesChangedObserver* obs) {
99 devices_changed_observer_list_->RemoveObserver(obs);
100 }
101
102 void SystemMonitor::NotifyDevicesChanged() {
103 DVLOG(1) << "DevicesChanged";
104 devices_changed_observer_list_->Notify(
105 &DevicesChangedObserver::OnDevicesChanged);
106 } 86 }
107 87
108 void SystemMonitor::NotifyPowerStateChange() { 88 void SystemMonitor::NotifyPowerStateChange() {
109 DVLOG(1) << "PowerStateChange: " << (BatteryPower() ? "On" : "Off") 89 DVLOG(1) << "PowerStateChange: " << (BatteryPower() ? "On" : "Off")
110 << " battery"; 90 << " battery";
111 power_observer_list_->Notify(&PowerObserver::OnPowerStateChange, 91 observer_list_->Notify(&PowerObserver::OnPowerStateChange, BatteryPower());
112 BatteryPower());
113 } 92 }
114 93
115 void SystemMonitor::NotifySuspend() { 94 void SystemMonitor::NotifySuspend() {
116 DVLOG(1) << "Power Suspending"; 95 DVLOG(1) << "Power Suspending";
117 power_observer_list_->Notify(&PowerObserver::OnSuspend); 96 observer_list_->Notify(&PowerObserver::OnSuspend);
118 } 97 }
119 98
120 void SystemMonitor::NotifyResume() { 99 void SystemMonitor::NotifyResume() {
121 DVLOG(1) << "Power Resuming"; 100 DVLOG(1) << "Power Resuming";
122 power_observer_list_->Notify(&PowerObserver::OnResume); 101 observer_list_->Notify(&PowerObserver::OnResume);
123 } 102 }
124 103
125 void SystemMonitor::BatteryCheck() { 104 void SystemMonitor::BatteryCheck() {
126 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); 105 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT);
127 } 106 }
128 107
129 } // namespace base 108 } // namespace base
OLDNEW
« no previous file with comments | « base/system_monitor/system_monitor.h ('k') | base/system_monitor/system_monitor_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698