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/file_path.h" | |
10 #include "base/logging.h" | 9 #include "base/logging.h" |
11 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
12 #include "base/time.h" | 11 #include "base/time.h" |
12 #include "base/utf_string_conversions.h" | |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 | 15 |
16 static SystemMonitor* g_system_monitor = NULL; | 16 static SystemMonitor* g_system_monitor = NULL; |
17 | 17 |
18 #if defined(ENABLE_BATTERY_MONITORING) | 18 #if defined(ENABLE_BATTERY_MONITORING) |
19 // The amount of time (in ms) to wait before running the initial | 19 // The amount of time (in ms) to wait before running the initial |
20 // battery check. | 20 // battery check. |
21 static int kDelayedBatteryCheckMs = 10 * 1000; | 21 static int kDelayedBatteryCheckMs = 10 * 1000; |
22 #endif // defined(ENABLE_BATTERY_MONITORING) | 22 #endif // defined(ENABLE_BATTERY_MONITORING) |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 NotifySuspend(); | 79 NotifySuspend(); |
80 } | 80 } |
81 break; | 81 break; |
82 } | 82 } |
83 } | 83 } |
84 | 84 |
85 void SystemMonitor::ProcessDevicesChanged() { | 85 void SystemMonitor::ProcessDevicesChanged() { |
86 NotifyDevicesChanged(); | 86 NotifyDevicesChanged(); |
87 } | 87 } |
88 | 88 |
89 void SystemMonitor::ProcessMediaDeviceAttached(const DeviceIdType& id, | 89 void SystemMonitor::ProcessMediaDeviceAttached( |
90 const std::string& name, | 90 const std::string& id, |
91 const FilePath& path) { | 91 const string16& name, |
92 media_device_map_.insert(std::make_pair(id, MakeTuple(id, name, path))); | 92 MediaDeviceType type, |
93 NotifyMediaDeviceAttached(id, name, path); | 93 const FilePath::StringType& location) { |
94 MediaDeviceInfo info(id, name, type, location); | |
95 media_device_map_.insert(std::make_pair(id, info)); | |
vandebo (ex-Chrome)
2012/07/20 00:27:41
As estade raised yesterday, we should probably loo
Lei Zhang
2012/07/20 00:46:25
Done.
| |
96 NotifyMediaDeviceAttached(id, name, type, location); | |
94 } | 97 } |
95 | 98 |
96 void SystemMonitor::ProcessMediaDeviceDetached(const DeviceIdType& id) { | 99 void SystemMonitor::ProcessMediaDeviceDetached(const std::string& id) { |
97 MediaDeviceMap::iterator it = media_device_map_.find(id); | 100 MediaDeviceMap::iterator it = media_device_map_.find(id); |
98 if (it != media_device_map_.end()) | 101 if (it != media_device_map_.end()) |
99 media_device_map_.erase(it); | 102 media_device_map_.erase(it); |
100 NotifyMediaDeviceDetached(id); | 103 NotifyMediaDeviceDetached(id); |
101 } | 104 } |
102 | 105 |
103 std::vector<SystemMonitor::MediaDeviceInfo> | 106 std::vector<SystemMonitor::MediaDeviceInfo> |
104 SystemMonitor::GetAttachedMediaDevices() const { | 107 SystemMonitor::GetAttachedMediaDevices() const { |
105 std::vector<MediaDeviceInfo> results; | 108 std::vector<MediaDeviceInfo> results; |
106 for (MediaDeviceMap::const_iterator it = media_device_map_.begin(); | 109 for (MediaDeviceMap::const_iterator it = media_device_map_.begin(); |
(...skipping 19 matching lines...) Expand all Loading... | |
126 void SystemMonitor::RemoveDevicesChangedObserver(DevicesChangedObserver* obs) { | 129 void SystemMonitor::RemoveDevicesChangedObserver(DevicesChangedObserver* obs) { |
127 devices_changed_observer_list_->RemoveObserver(obs); | 130 devices_changed_observer_list_->RemoveObserver(obs); |
128 } | 131 } |
129 | 132 |
130 void SystemMonitor::NotifyDevicesChanged() { | 133 void SystemMonitor::NotifyDevicesChanged() { |
131 DVLOG(1) << "DevicesChanged"; | 134 DVLOG(1) << "DevicesChanged"; |
132 devices_changed_observer_list_->Notify( | 135 devices_changed_observer_list_->Notify( |
133 &DevicesChangedObserver::OnDevicesChanged); | 136 &DevicesChangedObserver::OnDevicesChanged); |
134 } | 137 } |
135 | 138 |
136 void SystemMonitor::NotifyMediaDeviceAttached(const DeviceIdType& id, | 139 void SystemMonitor::NotifyMediaDeviceAttached( |
137 const std::string& name, | 140 const std::string& id, |
138 const FilePath& path) { | 141 const string16& name, |
139 DVLOG(1) << "MediaDeviceAttached with name " << name << " and id " << id; | 142 MediaDeviceType type, |
143 const FilePath::StringType& location) { | |
144 DVLOG(1) << "MediaDeviceAttached with name " << UTF16ToUTF8(name) | |
145 << " and id " << id; | |
140 devices_changed_observer_list_->Notify( | 146 devices_changed_observer_list_->Notify( |
141 &DevicesChangedObserver::OnMediaDeviceAttached, id, name, path); | 147 &DevicesChangedObserver::OnMediaDeviceAttached, id, name, type, location); |
142 } | 148 } |
143 | 149 |
144 void SystemMonitor::NotifyMediaDeviceDetached(const DeviceIdType& id) { | 150 void SystemMonitor::NotifyMediaDeviceDetached(const std::string& id) { |
145 DVLOG(1) << "MediaDeviceDetached for id " << id; | 151 DVLOG(1) << "MediaDeviceDetached for id " << id; |
146 devices_changed_observer_list_->Notify( | 152 devices_changed_observer_list_->Notify( |
147 &DevicesChangedObserver::OnMediaDeviceDetached, id); | 153 &DevicesChangedObserver::OnMediaDeviceDetached, id); |
148 } | 154 } |
149 | 155 |
150 void SystemMonitor::NotifyPowerStateChange() { | 156 void SystemMonitor::NotifyPowerStateChange() { |
151 DVLOG(1) << "PowerStateChange: " << (BatteryPower() ? "On" : "Off") | 157 DVLOG(1) << "PowerStateChange: " << (BatteryPower() ? "On" : "Off") |
152 << " battery"; | 158 << " battery"; |
153 power_observer_list_->Notify(&PowerObserver::OnPowerStateChange, | 159 power_observer_list_->Notify(&PowerObserver::OnPowerStateChange, |
154 BatteryPower()); | 160 BatteryPower()); |
155 } | 161 } |
156 | 162 |
157 void SystemMonitor::NotifySuspend() { | 163 void SystemMonitor::NotifySuspend() { |
158 DVLOG(1) << "Power Suspending"; | 164 DVLOG(1) << "Power Suspending"; |
159 power_observer_list_->Notify(&PowerObserver::OnSuspend); | 165 power_observer_list_->Notify(&PowerObserver::OnSuspend); |
160 } | 166 } |
161 | 167 |
162 void SystemMonitor::NotifyResume() { | 168 void SystemMonitor::NotifyResume() { |
163 DVLOG(1) << "Power Resuming"; | 169 DVLOG(1) << "Power Resuming"; |
164 power_observer_list_->Notify(&PowerObserver::OnResume); | 170 power_observer_list_->Notify(&PowerObserver::OnResume); |
165 } | 171 } |
166 | 172 |
167 void SystemMonitor::BatteryCheck() { | 173 void SystemMonitor::BatteryCheck() { |
168 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); | 174 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); |
169 } | 175 } |
170 | 176 |
171 } // namespace base | 177 } // namespace base |
OLD | NEW |