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" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 // This can happen if our unique id scheme fails. Ignore the incoming | 97 // This can happen if our unique id scheme fails. Ignore the incoming |
98 // non-unique attachment. | 98 // non-unique attachment. |
99 return; | 99 return; |
100 } | 100 } |
101 media_device_map_.insert(std::make_pair(id, info)); | 101 media_device_map_.insert(std::make_pair(id, info)); |
102 NotifyMediaDeviceAttached(id, name, type, location); | 102 NotifyMediaDeviceAttached(id, name, type, location); |
103 } | 103 } |
104 | 104 |
105 void SystemMonitor::ProcessMediaDeviceDetached(const std::string& id) { | 105 void SystemMonitor::ProcessMediaDeviceDetached(const std::string& id) { |
106 MediaDeviceMap::iterator it = media_device_map_.find(id); | 106 MediaDeviceMap::iterator it = media_device_map_.find(id); |
| 107 const FilePath::StringType location = it->second.location; |
107 if (it != media_device_map_.end()) | 108 if (it != media_device_map_.end()) |
108 media_device_map_.erase(it); | 109 media_device_map_.erase(it); |
109 NotifyMediaDeviceDetached(id); | 110 NotifyMediaDeviceDetached(id, location); |
110 } | 111 } |
111 | 112 |
112 std::vector<SystemMonitor::MediaDeviceInfo> | 113 std::vector<SystemMonitor::MediaDeviceInfo> |
113 SystemMonitor::GetAttachedMediaDevices() const { | 114 SystemMonitor::GetAttachedMediaDevices() const { |
114 std::vector<MediaDeviceInfo> results; | 115 std::vector<MediaDeviceInfo> results; |
115 for (MediaDeviceMap::const_iterator it = media_device_map_.begin(); | 116 for (MediaDeviceMap::const_iterator it = media_device_map_.begin(); |
116 it != media_device_map_.end(); | 117 it != media_device_map_.end(); |
117 ++it) { | 118 ++it) { |
118 results.push_back(it->second); | 119 results.push_back(it->second); |
119 } | 120 } |
(...skipping 26 matching lines...) Expand all Loading... |
146 const std::string& id, | 147 const std::string& id, |
147 const string16& name, | 148 const string16& name, |
148 MediaDeviceType type, | 149 MediaDeviceType type, |
149 const FilePath::StringType& location) { | 150 const FilePath::StringType& location) { |
150 DVLOG(1) << "MediaDeviceAttached with name " << UTF16ToUTF8(name) | 151 DVLOG(1) << "MediaDeviceAttached with name " << UTF16ToUTF8(name) |
151 << " and id " << id; | 152 << " and id " << id; |
152 devices_changed_observer_list_->Notify( | 153 devices_changed_observer_list_->Notify( |
153 &DevicesChangedObserver::OnMediaDeviceAttached, id, name, type, location); | 154 &DevicesChangedObserver::OnMediaDeviceAttached, id, name, type, location); |
154 } | 155 } |
155 | 156 |
156 void SystemMonitor::NotifyMediaDeviceDetached(const std::string& id) { | 157 void SystemMonitor::NotifyMediaDeviceDetached( |
| 158 const std::string& id, |
| 159 const FilePath::StringType& location) { |
157 DVLOG(1) << "MediaDeviceDetached for id " << id; | 160 DVLOG(1) << "MediaDeviceDetached for id " << id; |
158 devices_changed_observer_list_->Notify( | 161 devices_changed_observer_list_->Notify( |
159 &DevicesChangedObserver::OnMediaDeviceDetached, id); | 162 &DevicesChangedObserver::OnMediaDeviceDetached, id, location); |
160 } | 163 } |
161 | 164 |
162 void SystemMonitor::NotifyPowerStateChange() { | 165 void SystemMonitor::NotifyPowerStateChange() { |
163 DVLOG(1) << "PowerStateChange: " << (BatteryPower() ? "On" : "Off") | 166 DVLOG(1) << "PowerStateChange: " << (BatteryPower() ? "On" : "Off") |
164 << " battery"; | 167 << " battery"; |
165 power_observer_list_->Notify(&PowerObserver::OnPowerStateChange, | 168 power_observer_list_->Notify(&PowerObserver::OnPowerStateChange, |
166 BatteryPower()); | 169 BatteryPower()); |
167 } | 170 } |
168 | 171 |
169 void SystemMonitor::NotifySuspend() { | 172 void SystemMonitor::NotifySuspend() { |
170 DVLOG(1) << "Power Suspending"; | 173 DVLOG(1) << "Power Suspending"; |
171 power_observer_list_->Notify(&PowerObserver::OnSuspend); | 174 power_observer_list_->Notify(&PowerObserver::OnSuspend); |
172 } | 175 } |
173 | 176 |
174 void SystemMonitor::NotifyResume() { | 177 void SystemMonitor::NotifyResume() { |
175 DVLOG(1) << "Power Resuming"; | 178 DVLOG(1) << "Power Resuming"; |
176 power_observer_list_->Notify(&PowerObserver::OnResume); | 179 power_observer_list_->Notify(&PowerObserver::OnResume); |
177 } | 180 } |
178 | 181 |
179 void SystemMonitor::BatteryCheck() { | 182 void SystemMonitor::BatteryCheck() { |
180 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); | 183 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); |
181 } | 184 } |
182 | 185 |
183 } // namespace base | 186 } // namespace base |
OLD | NEW |