summaryrefslogtreecommitdiffstats
path: root/base/system_monitor
diff options
context:
space:
mode:
authorhongbo.min@intel.com <hongbo.min@intel.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-13 03:14:18 +0000
committerhongbo.min@intel.com <hongbo.min@intel.com@0039d316-1c4b-4281-b951-d872f2087c98>2012-09-13 03:14:18 +0000
commitef9bc06a1de19b6a5c33f709f0aff53bdc7415a3 (patch)
tree739a33fab03ff74eb3d74a9e7510621d5c3eae3c /base/system_monitor
parent231d7b5bd1aaea6d64d2e38bceb7e9b031f0f045 (diff)
downloadchromium_src-ef9bc06a1de19b6a5c33f709f0aff53bdc7415a3.zip
chromium_src-ef9bc06a1de19b6a5c33f709f0aff53bdc7415a3.tar.gz
chromium_src-ef9bc06a1de19b6a5c33f709f0aff53bdc7415a3.tar.bz2
Fix a potential multi-thread issue when manipulating removable storage map
TBR=willchan@chromium.org BUG=None Review URL: https://chromiumcodereview.appspot.com/10905237 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@156486 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/system_monitor')
-rw-r--r--base/system_monitor/system_monitor.cc28
-rw-r--r--base/system_monitor/system_monitor.h3
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_;