Chromium Code Reviews| 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..1e677695f01e58e09e2caa17ef19eb7eb6d6c52c 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,8 +203,7 @@ 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) { |
| + for (auto iter = instance_map_.begin(); iter != instance_map_.end(); ++iter) { |
|
danakj
2016/09/16 19:49:14
can this be a for (const auto& pair : instance_map
Avi (use Gerrit)
2016/09/16 20:08:50
Done.
|
| mount_points->push_back(MountPointInfo(iter->first, iter->second->path())); |
| } |
| } |
| @@ -249,20 +247,14 @@ void ExternalMountPoints::RevokeAllFileSystems() { |
| NameToInstance instance_map_copy; |
| { |
| base::AutoLock locker(lock_); |
| - instance_map_copy = instance_map_; |
| - instance_map_.clear(); |
| + instance_map_copy.swap(instance_map_); |
|
danakj
2016/09/16 19:49:14
Can you leave a comment saying we're moving these
Avi (use Gerrit)
2016/09/16 20:08:51
Done.
|
| path_to_name_map_.clear(); |
| } |
| - base::STLDeleteContainerPairSecondPointers(instance_map_copy.begin(), |
| - instance_map_copy.end()); |
| } |
| ExternalMountPoints::ExternalMountPoints() {} |
|
danakj
2016/09/16 19:49:14
= default while you're here?
Avi (use Gerrit)
2016/09/16 20:08:51
Done.
|
| -ExternalMountPoints::~ExternalMountPoints() { |
| - base::STLDeleteContainerPairSecondPointers(instance_map_.begin(), |
| - instance_map_.end()); |
| -} |
| +ExternalMountPoints::~ExternalMountPoints() {} |
|
danakj
2016/09/16 19:49:14
= default?
Avi (use Gerrit)
2016/09/16 20:08:50
Done.
|
| FileSystemURL ExternalMountPoints::CrackFileSystemURL( |
| const FileSystemURL& url) const { |
| @@ -312,7 +304,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; |