OLD | NEW |
---|---|
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/string_util.h" | |
Lei Zhang
2012/02/14 02:14:24
not needed?
vandebo (ex-Chrome)
2012/02/14 21:23:23
Done.
| |
9 #include "base/time.h" | 10 #include "base/time.h" |
10 | 11 |
11 namespace base { | 12 namespace base { |
12 | 13 |
13 static SystemMonitor* g_system_monitor = NULL; | 14 static SystemMonitor* g_system_monitor = NULL; |
Lei Zhang
2012/02/14 01:07:22
Should this be a LazyInstance?
vandebo (ex-Chrome)
2012/02/14 21:23:23
SystemMonitor is setup in BrowserMainLoop, so ther
| |
14 | 15 |
15 #if defined(ENABLE_BATTERY_MONITORING) | 16 #if defined(ENABLE_BATTERY_MONITORING) |
16 // The amount of time (in ms) to wait before running the initial | 17 // The amount of time (in ms) to wait before running the initial |
17 // battery check. | 18 // battery check. |
18 static int kDelayedBatteryCheckMs = 10 * 1000; | 19 static int kDelayedBatteryCheckMs = 10 * 1000; |
19 #endif // defined(ENABLE_BATTERY_MONITORING) | 20 #endif // defined(ENABLE_BATTERY_MONITORING) |
20 | 21 |
21 SystemMonitor::SystemMonitor() | 22 SystemMonitor::SystemMonitor() |
22 : power_observer_list_(new ObserverListThreadSafe<PowerObserver>()), | 23 : power_observer_list_(new ObserverListThreadSafe<PowerObserver>()), |
23 devices_changed_observer_list_( | 24 devices_changed_observer_list_( |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
76 NotifySuspend(); | 77 NotifySuspend(); |
77 } | 78 } |
78 break; | 79 break; |
79 } | 80 } |
80 } | 81 } |
81 | 82 |
82 void SystemMonitor::ProcessDevicesChanged() { | 83 void SystemMonitor::ProcessDevicesChanged() { |
83 NotifyDevicesChanged(); | 84 NotifyDevicesChanged(); |
84 } | 85 } |
85 | 86 |
87 void SystemMonitor::ProcessMediaDeviceAttached(const DeviceIdType& id, | |
88 const std::string& name, | |
89 const FilePath& path) { | |
90 NotifyMediaDeviceAttached(id, name, path); | |
91 } | |
92 | |
93 void SystemMonitor::ProcessMediaDeviceDetached(const DeviceIdType& id) { | |
94 NotifyMediaDeviceDetached(id); | |
95 } | |
96 | |
86 void SystemMonitor::AddPowerObserver(PowerObserver* obs) { | 97 void SystemMonitor::AddPowerObserver(PowerObserver* obs) { |
87 power_observer_list_->AddObserver(obs); | 98 power_observer_list_->AddObserver(obs); |
88 } | 99 } |
89 | 100 |
90 void SystemMonitor::RemovePowerObserver(PowerObserver* obs) { | 101 void SystemMonitor::RemovePowerObserver(PowerObserver* obs) { |
91 power_observer_list_->RemoveObserver(obs); | 102 power_observer_list_->RemoveObserver(obs); |
92 } | 103 } |
93 | 104 |
94 void SystemMonitor::AddDevicesChangedObserver(DevicesChangedObserver* obs) { | 105 void SystemMonitor::AddDevicesChangedObserver(DevicesChangedObserver* obs) { |
95 devices_changed_observer_list_->AddObserver(obs); | 106 devices_changed_observer_list_->AddObserver(obs); |
96 } | 107 } |
97 | 108 |
98 void SystemMonitor::RemoveDevicesChangedObserver(DevicesChangedObserver* obs) { | 109 void SystemMonitor::RemoveDevicesChangedObserver(DevicesChangedObserver* obs) { |
99 devices_changed_observer_list_->RemoveObserver(obs); | 110 devices_changed_observer_list_->RemoveObserver(obs); |
100 } | 111 } |
101 | 112 |
102 void SystemMonitor::NotifyDevicesChanged() { | 113 void SystemMonitor::NotifyDevicesChanged() { |
103 DVLOG(1) << "DevicesChanged"; | 114 DVLOG(1) << "DevicesChanged"; |
104 devices_changed_observer_list_->Notify( | 115 devices_changed_observer_list_->Notify( |
105 &DevicesChangedObserver::OnDevicesChanged); | 116 &DevicesChangedObserver::OnDevicesChanged); |
106 } | 117 } |
107 | 118 |
119 void SystemMonitor::NotifyMediaDeviceAttached(const DeviceIdType& id, | |
120 const std::string& name, | |
121 const FilePath& path) { | |
122 DVLOG(1) << "MediaDeviceAttached with name " << name << " and id " << id; | |
123 devices_changed_observer_list_->Notify( | |
124 &DevicesChangedObserver::OnMediaDeviceAttached, id, name, path); | |
125 } | |
126 | |
127 void SystemMonitor::NotifyMediaDeviceDetached(const DeviceIdType& id) { | |
128 DVLOG(1) << "MediaDeviceDetached for id " << id; | |
129 devices_changed_observer_list_->Notify( | |
130 &DevicesChangedObserver::OnMediaDeviceDetached, id); | |
131 } | |
132 | |
108 void SystemMonitor::NotifyPowerStateChange() { | 133 void SystemMonitor::NotifyPowerStateChange() { |
109 DVLOG(1) << "PowerStateChange: " << (BatteryPower() ? "On" : "Off") | 134 DVLOG(1) << "PowerStateChange: " << (BatteryPower() ? "On" : "Off") |
110 << " battery"; | 135 << " battery"; |
111 power_observer_list_->Notify(&PowerObserver::OnPowerStateChange, | 136 power_observer_list_->Notify(&PowerObserver::OnPowerStateChange, |
112 BatteryPower()); | 137 BatteryPower()); |
113 } | 138 } |
114 | 139 |
115 void SystemMonitor::NotifySuspend() { | 140 void SystemMonitor::NotifySuspend() { |
116 DVLOG(1) << "Power Suspending"; | 141 DVLOG(1) << "Power Suspending"; |
117 power_observer_list_->Notify(&PowerObserver::OnSuspend); | 142 power_observer_list_->Notify(&PowerObserver::OnSuspend); |
118 } | 143 } |
119 | 144 |
120 void SystemMonitor::NotifyResume() { | 145 void SystemMonitor::NotifyResume() { |
121 DVLOG(1) << "Power Resuming"; | 146 DVLOG(1) << "Power Resuming"; |
122 power_observer_list_->Notify(&PowerObserver::OnResume); | 147 power_observer_list_->Notify(&PowerObserver::OnResume); |
123 } | 148 } |
124 | 149 |
125 void SystemMonitor::BatteryCheck() { | 150 void SystemMonitor::BatteryCheck() { |
Lei Zhang
2012/02/14 01:58:01
Also, this can be wrapped in #if defined(ENABLE_BA
vandebo (ex-Chrome)
2012/02/14 21:23:23
It could be, but I'm not sure there's any gain to
Lei Zhang
2012/02/15 22:55:45
It's just dead code on non-Windows platforms. No p
vandebo (ex-Chrome)
2012/02/15 23:13:36
Fine. Done.
| |
126 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); | 151 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); |
127 } | 152 } |
128 | 153 |
129 } // namespace base | 154 } // namespace base |
OLD | NEW |