Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(649)

Unified Diff: base/system_monitor/system_monitor.cc

Issue 10905237: Fix a potential multi-thread issue when manipulating removable storage map (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: use mutable for lock Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: base/system_monitor/system_monitor.cc
diff --git a/base/system_monitor/system_monitor.cc b/base/system_monitor/system_monitor.cc
index f30c8935c9a999b38382f78e879c9319a4eba13f..2616275dfbc64db88abaa6abb0fa85e8cf561a7d 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) {
« base/system_monitor/system_monitor.h ('K') | « base/system_monitor/system_monitor.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698