diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/system_monitor/system_monitor.cc | 28 | ||||
-rw-r--r-- | base/system_monitor/system_monitor.h | 3 |
2 files changed, 21 insertions, 10 deletions
diff --git a/base/system_monitor/system_monitor.cc b/base/system_monitor/system_monitor.cc index f30c893..2616275 100644 --- a/base/system_monitor/system_monitor.cc +++ b/base/system_monitor/system_monitor.cc @@ -103,27 +103,35 @@ void SystemMonitor::ProcessRemovableStorageAttached( const std::string& id, const string16& name, const FilePath::StringType& location) { - if (ContainsKey(removable_storage_map_, id)) { - // This can happen if our unique id scheme fails. Ignore the incoming - // non-unique attachment. - return; + { + base::AutoLock lock(removable_storage_lock_); + if (ContainsKey(removable_storage_map_, id)) { + // This can happen if our unique id scheme fails. Ignore the incoming + // non-unique attachment. + return; + } + RemovableStorageInfo info(id, name, location); + removable_storage_map_.insert(std::make_pair(id, info)); } - RemovableStorageInfo info(id, name, location); - removable_storage_map_.insert(std::make_pair(id, info)); NotifyRemovableStorageAttached(id, name, location); } void SystemMonitor::ProcessRemovableStorageDetached(const std::string& id) { - RemovableStorageMap::iterator it = removable_storage_map_.find(id); - if (it == removable_storage_map_.end()) - return; - removable_storage_map_.erase(it); + { + base::AutoLock lock(removable_storage_lock_); + RemovableStorageMap::iterator it = removable_storage_map_.find(id); + if (it == removable_storage_map_.end()) + return; + removable_storage_map_.erase(it); + } NotifyRemovableStorageDetached(id); } std::vector<SystemMonitor::RemovableStorageInfo> SystemMonitor::GetAttachedRemovableStorage() const { std::vector<RemovableStorageInfo> results; + + base::AutoLock lock(removable_storage_lock_); for (RemovableStorageMap::const_iterator it = removable_storage_map_.begin(); it != removable_storage_map_.end(); ++it) { diff --git a/base/system_monitor/system_monitor.h b/base/system_monitor/system_monitor.h index 48d512b..f5224a4 100644 --- a/base/system_monitor/system_monitor.h +++ b/base/system_monitor/system_monitor.h @@ -13,6 +13,7 @@ #include "base/basictypes.h" #include "base/file_path.h" #include "base/string16.h" +#include "base/synchronization/lock.h" #include "build/build_config.h" // Windows HiRes timers drain the battery faster so we need to know the battery @@ -219,6 +220,8 @@ class BASE_EXPORT SystemMonitor { std::vector<id> notification_observers_; #endif + // For manipulating removable_storage_map_ structure. + mutable base::Lock removable_storage_lock_; // Map of all the attached removable storage devices. RemovableStorageMap removable_storage_map_; |