OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
12 #include "base/time.h" | 12 #include "base/time.h" |
13 #include "base/utf_string_conversions.h" | 13 #include "base/utf_string_conversions.h" |
14 | 14 |
15 namespace base { | 15 namespace base { |
16 | 16 |
17 static SystemMonitor* g_system_monitor = NULL; | 17 static SystemMonitor* g_system_monitor = NULL; |
18 | 18 |
19 #if defined(ENABLE_BATTERY_MONITORING) | 19 #if defined(ENABLE_BATTERY_MONITORING) |
20 // The amount of time (in ms) to wait before running the initial | 20 // The amount of time (in ms) to wait before running the initial |
21 // battery check. | 21 // battery check. |
22 static int kDelayedBatteryCheckMs = 10 * 1000; | 22 static int kDelayedBatteryCheckMs = 10 * 1000; |
23 #endif // defined(ENABLE_BATTERY_MONITORING) | 23 #endif // defined(ENABLE_BATTERY_MONITORING) |
24 | 24 |
25 SystemMonitor::MediaDeviceInfo::MediaDeviceInfo( | 25 SystemMonitor::MediaDeviceInfo::MediaDeviceInfo( |
26 const std::string& id, | 26 const std::string& id, |
27 const string16& device_name, | 27 const string16& device_name, |
28 MediaDeviceType device_type, | |
29 const FilePath::StringType& device_location) | 28 const FilePath::StringType& device_location) |
30 : unique_id(id), | 29 : unique_id(id), |
31 name(device_name), | 30 name(device_name), |
32 type(device_type), | |
33 location(device_location) { | 31 location(device_location) { |
34 } | 32 } |
35 | 33 |
36 SystemMonitor::SystemMonitor() | 34 SystemMonitor::SystemMonitor() |
37 : power_observer_list_(new ObserverListThreadSafe<PowerObserver>()), | 35 : power_observer_list_(new ObserverListThreadSafe<PowerObserver>()), |
38 devices_changed_observer_list_( | 36 devices_changed_observer_list_( |
39 new ObserverListThreadSafe<DevicesChangedObserver>()), | 37 new ObserverListThreadSafe<DevicesChangedObserver>()), |
40 battery_in_use_(false), | 38 battery_in_use_(false), |
41 suspended_(false) { | 39 suspended_(false) { |
42 DCHECK(!g_system_monitor); | 40 DCHECK(!g_system_monitor); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 } | 92 } |
95 } | 93 } |
96 | 94 |
97 void SystemMonitor::ProcessDevicesChanged(DeviceType device_type) { | 95 void SystemMonitor::ProcessDevicesChanged(DeviceType device_type) { |
98 NotifyDevicesChanged(device_type); | 96 NotifyDevicesChanged(device_type); |
99 } | 97 } |
100 | 98 |
101 void SystemMonitor::ProcessMediaDeviceAttached( | 99 void SystemMonitor::ProcessMediaDeviceAttached( |
102 const std::string& id, | 100 const std::string& id, |
103 const string16& name, | 101 const string16& name, |
104 MediaDeviceType type, | |
105 const FilePath::StringType& location) { | 102 const FilePath::StringType& location) { |
106 MediaDeviceInfo info(id, name, type, location); | 103 MediaDeviceInfo info(id, name, location); |
107 if (ContainsKey(media_device_map_, id)) { | 104 if (ContainsKey(media_device_map_, id)) { |
108 // This can happen if our unique id scheme fails. Ignore the incoming | 105 // This can happen if our unique id scheme fails. Ignore the incoming |
109 // non-unique attachment. | 106 // non-unique attachment. |
110 return; | 107 return; |
111 } | 108 } |
112 media_device_map_.insert(std::make_pair(id, info)); | 109 media_device_map_.insert(std::make_pair(id, info)); |
113 NotifyMediaDeviceAttached(id, name, type, location); | 110 NotifyMediaDeviceAttached(id, name, location); |
114 } | 111 } |
115 | 112 |
116 void SystemMonitor::ProcessMediaDeviceDetached(const std::string& id) { | 113 void SystemMonitor::ProcessMediaDeviceDetached(const std::string& id) { |
117 MediaDeviceMap::iterator it = media_device_map_.find(id); | 114 MediaDeviceMap::iterator it = media_device_map_.find(id); |
118 if (it == media_device_map_.end()) | 115 if (it == media_device_map_.end()) |
119 return; | 116 return; |
120 media_device_map_.erase(it); | 117 media_device_map_.erase(it); |
121 NotifyMediaDeviceDetached(id); | 118 NotifyMediaDeviceDetached(id); |
122 } | 119 } |
123 | 120 |
(...skipping 26 matching lines...) Expand all Loading... |
150 | 147 |
151 void SystemMonitor::NotifyDevicesChanged(DeviceType device_type) { | 148 void SystemMonitor::NotifyDevicesChanged(DeviceType device_type) { |
152 DVLOG(1) << "DevicesChanged with device type " << device_type; | 149 DVLOG(1) << "DevicesChanged with device type " << device_type; |
153 devices_changed_observer_list_->Notify( | 150 devices_changed_observer_list_->Notify( |
154 &DevicesChangedObserver::OnDevicesChanged, device_type); | 151 &DevicesChangedObserver::OnDevicesChanged, device_type); |
155 } | 152 } |
156 | 153 |
157 void SystemMonitor::NotifyMediaDeviceAttached( | 154 void SystemMonitor::NotifyMediaDeviceAttached( |
158 const std::string& id, | 155 const std::string& id, |
159 const string16& name, | 156 const string16& name, |
160 MediaDeviceType type, | |
161 const FilePath::StringType& location) { | 157 const FilePath::StringType& location) { |
162 DVLOG(1) << "MediaDeviceAttached with name " << UTF16ToUTF8(name) | 158 DVLOG(1) << "MediaDeviceAttached with name " << UTF16ToUTF8(name) |
163 << " and id " << id; | 159 << " and id " << id; |
164 devices_changed_observer_list_->Notify( | 160 devices_changed_observer_list_->Notify( |
165 &DevicesChangedObserver::OnMediaDeviceAttached, id, name, type, location); | 161 &DevicesChangedObserver::OnMediaDeviceAttached, id, name, location); |
166 } | 162 } |
167 | 163 |
168 void SystemMonitor::NotifyMediaDeviceDetached(const std::string& id) { | 164 void SystemMonitor::NotifyMediaDeviceDetached(const std::string& id) { |
169 DVLOG(1) << "MediaDeviceDetached for id " << id; | 165 DVLOG(1) << "MediaDeviceDetached for id " << id; |
170 devices_changed_observer_list_->Notify( | 166 devices_changed_observer_list_->Notify( |
171 &DevicesChangedObserver::OnMediaDeviceDetached, id); | 167 &DevicesChangedObserver::OnMediaDeviceDetached, id); |
172 } | 168 } |
173 | 169 |
174 void SystemMonitor::NotifyPowerStateChange() { | 170 void SystemMonitor::NotifyPowerStateChange() { |
175 DVLOG(1) << "PowerStateChange: " << (BatteryPower() ? "On" : "Off") | 171 DVLOG(1) << "PowerStateChange: " << (BatteryPower() ? "On" : "Off") |
(...skipping 10 matching lines...) Expand all Loading... |
186 void SystemMonitor::NotifyResume() { | 182 void SystemMonitor::NotifyResume() { |
187 DVLOG(1) << "Power Resuming"; | 183 DVLOG(1) << "Power Resuming"; |
188 power_observer_list_->Notify(&PowerObserver::OnResume); | 184 power_observer_list_->Notify(&PowerObserver::OnResume); |
189 } | 185 } |
190 | 186 |
191 void SystemMonitor::BatteryCheck() { | 187 void SystemMonitor::BatteryCheck() { |
192 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); | 188 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); |
193 } | 189 } |
194 | 190 |
195 } // namespace base | 191 } // namespace base |
OLD | NEW |