Index: storage/browser/fileapi/external_mount_points.cc |
diff --git a/storage/browser/fileapi/external_mount_points.cc b/storage/browser/fileapi/external_mount_points.cc |
index 927bca4c2a8ec2dd53946e856d485d6225f12852..05eb0233a6de3891c3257b4609caf89ddee8c8c6 100644 |
--- a/storage/browser/fileapi/external_mount_points.cc |
+++ b/storage/browser/fileapi/external_mount_points.cc |
@@ -7,7 +7,7 @@ |
#include "base/files/file_path.h" |
#include "base/lazy_instance.h" |
#include "base/macros.h" |
-#include "base/stl_util.h" |
+#include "base/memory/ptr_util.h" |
#include "storage/browser/fileapi/file_system_url.h" |
namespace { |
@@ -103,7 +103,8 @@ bool ExternalMountPoints::RegisterFileSystem( |
if (!ValidateNewMountPoint(mount_name, type, path)) |
return false; |
- instance_map_[mount_name] = new Instance(type, path, mount_option); |
+ instance_map_[mount_name] = |
+ base::MakeUnique<Instance>(type, path, mount_option); |
if (!path.empty() && IsOverlappingMountPathForbidden(type)) |
path_to_name_map_.insert(std::make_pair(path, mount_name)); |
return true; |
@@ -117,13 +118,12 @@ bool ExternalMountPoints::HandlesFileSystemMountType( |
bool ExternalMountPoints::RevokeFileSystem(const std::string& mount_name) { |
base::AutoLock locker(lock_); |
- NameToInstance::iterator found = instance_map_.find(mount_name); |
+ auto found = instance_map_.find(mount_name); |
if (found == instance_map_.end()) |
return false; |
- Instance* instance = found->second; |
+ Instance* instance = found->second.get(); |
if (IsOverlappingMountPathForbidden(instance->type())) |
path_to_name_map_.erase(NormalizeFilePath(instance->path())); |
- delete found->second; |
instance_map_.erase(found); |
return true; |
} |
@@ -132,7 +132,7 @@ bool ExternalMountPoints::GetRegisteredPath( |
const std::string& filesystem_id, base::FilePath* path) const { |
DCHECK(path); |
base::AutoLock locker(lock_); |
- NameToInstance::const_iterator found = instance_map_.find(filesystem_id); |
+ auto found = instance_map_.find(filesystem_id); |
if (found == instance_map_.end()) |
return false; |
*path = found->second->path(); |
@@ -167,13 +167,12 @@ bool ExternalMountPoints::CrackVirtualPath( |
base::FilePath cracked_path; |
{ |
base::AutoLock locker(lock_); |
- NameToInstance::const_iterator found_instance = |
- instance_map_.find(maybe_mount_name); |
+ auto found_instance = instance_map_.find(maybe_mount_name); |
if (found_instance == instance_map_.end()) |
return false; |
*mount_name = maybe_mount_name; |
- const Instance* instance = found_instance->second; |
+ const Instance* instance = found_instance->second.get(); |
if (type) |
*type = instance->type(); |
cracked_path = instance->path(); |
@@ -204,9 +203,8 @@ void ExternalMountPoints::AddMountPointInfosTo( |
std::vector<MountPointInfo>* mount_points) const { |
base::AutoLock locker(lock_); |
DCHECK(mount_points); |
- for (NameToInstance::const_iterator iter = instance_map_.begin(); |
- iter != instance_map_.end(); ++iter) { |
- mount_points->push_back(MountPointInfo(iter->first, iter->second->path())); |
+ for (const auto& pair : instance_map_) { |
+ mount_points->push_back(MountPointInfo(pair.first, pair.second->path())); |
} |
} |
@@ -249,20 +247,16 @@ void ExternalMountPoints::RevokeAllFileSystems() { |
NameToInstance instance_map_copy; |
{ |
base::AutoLock locker(lock_); |
- instance_map_copy = instance_map_; |
- instance_map_.clear(); |
+ // This swap moves the contents of instance_map_ to the local variable so |
+ // they can be freed outside the lock. |
+ instance_map_copy.swap(instance_map_); |
path_to_name_map_.clear(); |
} |
- base::STLDeleteContainerPairSecondPointers(instance_map_copy.begin(), |
- instance_map_copy.end()); |
} |
-ExternalMountPoints::ExternalMountPoints() {} |
+ExternalMountPoints::ExternalMountPoints() = default; |
-ExternalMountPoints::~ExternalMountPoints() { |
- base::STLDeleteContainerPairSecondPointers(instance_map_.begin(), |
- instance_map_.end()); |
-} |
+ExternalMountPoints::~ExternalMountPoints() = default; |
FileSystemURL ExternalMountPoints::CrackFileSystemURL( |
const FileSystemURL& url) const { |
@@ -312,7 +306,7 @@ bool ExternalMountPoints::ValidateNewMountPoint(const std::string& mount_name, |
return false; |
// Verify there is no registered mount point with the same name. |
- NameToInstance::iterator found = instance_map_.find(mount_name); |
+ auto found = instance_map_.find(mount_name); |
if (found != instance_map_.end()) |
return false; |