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