Index: chrome/browser/chromeos/file_system_provider/service.cc |
diff --git a/chrome/browser/chromeos/file_system_provider/service.cc b/chrome/browser/chromeos/file_system_provider/service.cc |
index 9694296201e9a0091dbe10b30ba22bb9b0d0bab2..fab0af3593d567ee2c5b5a6bc7c90b0d69c29407 100644 |
--- a/chrome/browser/chromeos/file_system_provider/service.cc |
+++ b/chrome/browser/chromeos/file_system_provider/service.cc |
@@ -43,7 +43,7 @@ Service::Service(Profile* profile, |
: profile_(profile), |
extension_registry_(extension_registry), |
file_system_factory_(base::Bind(CreateProvidedFileSystem)), |
- next_id_(1), |
+ next_index_(1), |
weak_ptr_factory_(this) { |
extension_registry_->AddObserver(this); |
} |
@@ -53,7 +53,8 @@ Service::~Service() { |
ProvidedFileSystemMap::iterator it = file_system_map_.begin(); |
while (it != file_system_map_.end()) { |
- const int file_system_id = it->first; |
+ const std::string file_system_id = |
+ it->second->GetFileSystemInfo().file_system_id(); |
const std::string extension_id = |
it->second->GetFileSystemInfo().extension_id(); |
++it; |
@@ -85,10 +86,21 @@ void Service::SetFileSystemFactoryForTests( |
file_system_factory_ = factory_callback; |
} |
-int Service::MountFileSystem(const std::string& extension_id, |
- const std::string& file_system_name) { |
+bool Service::MountFileSystem(const std::string& extension_id, |
+ const std::string& file_system_id, |
+ const std::string& file_system_name) { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |
+ // If already exists a file system provided by the same extension with this |
+ // id, then abort. |
+ if (GetProvidedFileSystem(extension_id, file_system_id)) { |
+ FOR_EACH_OBSERVER(Observer, |
+ observers_, |
+ OnProvidedFileSystemMount(ProvidedFileSystemInfo(), |
+ base::File::FILE_ERROR_EXISTS)); |
+ return false; |
+ } |
+ |
// Restrict number of file systems to prevent system abusing. |
if (file_system_map_.size() + 1 > kMaxFileSystems) { |
FOR_EACH_OBSERVER( |
@@ -96,11 +108,13 @@ int Service::MountFileSystem(const std::string& extension_id, |
observers_, |
OnProvidedFileSystemMount(ProvidedFileSystemInfo(), |
base::File::FILE_ERROR_TOO_MANY_OPENED)); |
- return 0; |
+ return false; |
} |
- // The provided file system id is unique per service, so per profile. |
- int file_system_id = next_id_; |
+ // The provided file system index is unique per service, so per profile. |
+ // The index is used internally. Externally a file system id is used, which |
+ // is unique per extension. |
+ int index = next_index_; |
fileapi::ExternalMountPoints* const mount_points = |
fileapi::ExternalMountPoints::GetSystemInstance(); |
@@ -109,7 +123,7 @@ int Service::MountFileSystem(const std::string& extension_id, |
// The mount point path and name are unique per system, since they are system |
// wide. This is necessary for copying between profiles. |
const base::FilePath& mount_path = |
- util::GetMountPath(profile_, extension_id, file_system_id); |
+ util::GetMountPath(profile_, extension_id, index); |
const std::string mount_point_name = mount_path.BaseName().AsUTF8Unsafe(); |
if (!mount_points->RegisterFileSystem(mount_point_name, |
@@ -121,7 +135,7 @@ int Service::MountFileSystem(const std::string& extension_id, |
observers_, |
OnProvidedFileSystemMount(ProvidedFileSystemInfo(), |
base::File::FILE_ERROR_INVALID_OPERATION)); |
- return 0; |
+ return false; |
} |
// Store the file system descriptor. Use the mount point name as the file |
@@ -139,27 +153,26 @@ int Service::MountFileSystem(const std::string& extension_id, |
ProvidedFileSystemInterface* file_system = |
file_system_factory_.Run(router, file_system_info); |
DCHECK(file_system); |
- file_system_map_[file_system_id] = file_system; |
- mount_point_name_to_id_map_[mount_point_name] = file_system_id; |
+ file_system_map_[FileSystemKey(extension_id, file_system_id)] = file_system; |
+ mount_point_name_to_key_map_[mount_point_name] = |
+ FileSystemKey(extension_id, file_system_id); |
FOR_EACH_OBSERVER( |
Observer, |
observers_, |
OnProvidedFileSystemMount(file_system_info, base::File::FILE_OK)); |
- next_id_++; |
- return file_system_id; |
+ next_index_++; |
+ return true; |
} |
bool Service::UnmountFileSystem(const std::string& extension_id, |
- int file_system_id) { |
+ const std::string& file_system_id) { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |
const ProvidedFileSystemMap::iterator file_system_it = |
- file_system_map_.find(file_system_id); |
- if (file_system_it == file_system_map_.end() || |
- file_system_it->second->GetFileSystemInfo().extension_id() != |
- extension_id) { |
+ file_system_map_.find(FileSystemKey(extension_id, file_system_id)); |
+ if (file_system_it == file_system_map_.end()) { |
const ProvidedFileSystemInfo empty_file_system_info; |
FOR_EACH_OBSERVER( |
Observer, |
@@ -192,7 +205,7 @@ bool Service::UnmountFileSystem(const std::string& extension_id, |
observers_, |
OnProvidedFileSystemUnmount(file_system_info, base::File::FILE_OK)); |
- mount_point_name_to_id_map_.erase(mount_point_name); |
+ mount_point_name_to_key_map_.erase(mount_point_name); |
delete file_system_it->second; |
file_system_map_.erase(file_system_it); |
@@ -200,11 +213,12 @@ bool Service::UnmountFileSystem(const std::string& extension_id, |
return true; |
} |
-bool Service::RequestUnmount(int file_system_id) { |
+bool Service::RequestUnmount(const std::string& extension_id, |
+ const std::string& file_system_id) { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |
ProvidedFileSystemMap::iterator file_system_it = |
- file_system_map_.find(file_system_id); |
+ file_system_map_.find(FileSystemKey(extension_id, file_system_id)); |
if (file_system_it == file_system_map_.end()) |
return false; |
@@ -229,16 +243,13 @@ std::vector<ProvidedFileSystemInfo> Service::GetProvidedFileSystemInfoList() { |
ProvidedFileSystemInterface* Service::GetProvidedFileSystem( |
const std::string& extension_id, |
- int file_system_id) { |
+ const std::string& file_system_id) { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |
const ProvidedFileSystemMap::const_iterator file_system_it = |
- file_system_map_.find(file_system_id); |
- if (file_system_it == file_system_map_.end() || |
- file_system_it->second->GetFileSystemInfo().extension_id() != |
- extension_id) { |
+ file_system_map_.find(FileSystemKey(extension_id, file_system_id)); |
+ if (file_system_it == file_system_map_.end()) |
return NULL; |
- } |
return file_system_it->second; |
} |
@@ -267,9 +278,9 @@ ProvidedFileSystemInterface* Service::GetProvidedFileSystem( |
const std::string& mount_point_name) { |
DCHECK_CURRENTLY_ON(BrowserThread::UI); |
- const MountPointNameToIdMap::const_iterator mapping_it = |
- mount_point_name_to_id_map_.find(mount_point_name); |
- if (mapping_it == mount_point_name_to_id_map_.end()) |
+ const MountPointNameToKeyMap::const_iterator mapping_it = |
+ mount_point_name_to_key_map_.find(mount_point_name); |
+ if (mapping_it == mount_point_name_to_key_map_.end()) |
return NULL; |
const ProvidedFileSystemMap::const_iterator file_system_it = |