| 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 96 } |
| 97 | 97 |
| 98 void SystemMonitor::ProcessDevicesChanged(DeviceType device_type) { | 98 void SystemMonitor::ProcessDevicesChanged(DeviceType device_type) { |
| 99 NotifyDevicesChanged(device_type); | 99 NotifyDevicesChanged(device_type); |
| 100 } | 100 } |
| 101 | 101 |
| 102 void SystemMonitor::ProcessRemovableStorageAttached( | 102 void SystemMonitor::ProcessRemovableStorageAttached( |
| 103 const std::string& id, | 103 const std::string& id, |
| 104 const string16& name, | 104 const string16& name, |
| 105 const FilePath::StringType& location) { | 105 const FilePath::StringType& location) { |
| 106 if (ContainsKey(removable_storage_map_, id)) { | 106 { |
| 107 // This can happen if our unique id scheme fails. Ignore the incoming | 107 base::AutoLock lock(removable_storage_lock_); |
| 108 // non-unique attachment. | 108 if (ContainsKey(removable_storage_map_, id)) { |
| 109 return; | 109 // This can happen if our unique id scheme fails. Ignore the incoming |
| 110 // non-unique attachment. |
| 111 return; |
| 112 } |
| 113 RemovableStorageInfo info(id, name, location); |
| 114 removable_storage_map_.insert(std::make_pair(id, info)); |
| 110 } | 115 } |
| 111 RemovableStorageInfo info(id, name, location); | |
| 112 removable_storage_map_.insert(std::make_pair(id, info)); | |
| 113 NotifyRemovableStorageAttached(id, name, location); | 116 NotifyRemovableStorageAttached(id, name, location); |
| 114 } | 117 } |
| 115 | 118 |
| 116 void SystemMonitor::ProcessRemovableStorageDetached(const std::string& id) { | 119 void SystemMonitor::ProcessRemovableStorageDetached(const std::string& id) { |
| 117 RemovableStorageMap::iterator it = removable_storage_map_.find(id); | 120 { |
| 118 if (it == removable_storage_map_.end()) | 121 base::AutoLock lock(removable_storage_lock_); |
| 119 return; | 122 RemovableStorageMap::iterator it = removable_storage_map_.find(id); |
| 120 removable_storage_map_.erase(it); | 123 if (it == removable_storage_map_.end()) |
| 124 return; |
| 125 removable_storage_map_.erase(it); |
| 126 } |
| 121 NotifyRemovableStorageDetached(id); | 127 NotifyRemovableStorageDetached(id); |
| 122 } | 128 } |
| 123 | 129 |
| 124 std::vector<SystemMonitor::RemovableStorageInfo> | 130 std::vector<SystemMonitor::RemovableStorageInfo> |
| 125 SystemMonitor::GetAttachedRemovableStorage() const { | 131 SystemMonitor::GetAttachedRemovableStorage() { |
| 126 std::vector<RemovableStorageInfo> results; | 132 std::vector<RemovableStorageInfo> results; |
| 133 |
| 134 base::AutoLock lock(removable_storage_lock_); |
| 127 for (RemovableStorageMap::const_iterator it = removable_storage_map_.begin(); | 135 for (RemovableStorageMap::const_iterator it = removable_storage_map_.begin(); |
| 128 it != removable_storage_map_.end(); | 136 it != removable_storage_map_.end(); |
| 129 ++it) { | 137 ++it) { |
| 130 results.push_back(it->second); | 138 results.push_back(it->second); |
| 131 } | 139 } |
| 132 return results; | 140 return results; |
| 133 } | 141 } |
| 134 | 142 |
| 135 void SystemMonitor::AddPowerObserver(PowerObserver* obs) { | 143 void SystemMonitor::AddPowerObserver(PowerObserver* obs) { |
| 136 power_observer_list_->AddObserver(obs); | 144 power_observer_list_->AddObserver(obs); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 void SystemMonitor::NotifyResume() { | 193 void SystemMonitor::NotifyResume() { |
| 186 DVLOG(1) << "Power Resuming"; | 194 DVLOG(1) << "Power Resuming"; |
| 187 power_observer_list_->Notify(&PowerObserver::OnResume); | 195 power_observer_list_->Notify(&PowerObserver::OnResume); |
| 188 } | 196 } |
| 189 | 197 |
| 190 void SystemMonitor::BatteryCheck() { | 198 void SystemMonitor::BatteryCheck() { |
| 191 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); | 199 ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); |
| 192 } | 200 } |
| 193 | 201 |
| 194 } // namespace base | 202 } // namespace base |
| OLD | NEW |