| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "webkit/fileapi/external_mount_points.h" | 5 #include "webkit/fileapi/external_mount_points.h" |
| 6 | 6 |
| 7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/stl_util.h" | 10 #include "base/stl_util.h" |
| 11 #include "webkit/fileapi/file_system_url.h" | 11 #include "webkit/fileapi/file_system_url.h" |
| 12 #include "webkit/fileapi/remote_file_system_proxy.h" | 12 #include "webkit/fileapi/remote_file_system_proxy.h" |
| 13 | 13 |
| 14 namespace { | 14 namespace { |
| 15 | 15 |
| 16 // Normalizes file path so it has normalized separators and ends with exactly | 16 // Normalizes file path so it has normalized separators and ends with exactly |
| 17 // one separator. Paths have to be normalized this way for use in | 17 // one separator. Paths have to be normalized this way for use in |
| 18 // GetVirtualPath method. Separators cannot be completely stripped, or | 18 // GetVirtualPath method. Separators cannot be completely stripped, or |
| 19 // GetVirtualPath could not working in some edge cases. | 19 // GetVirtualPath could not working in some edge cases. |
| 20 // For example, /a/b/c(1)/d would be erroneously resolved as c/d if the | 20 // For example, /a/b/c(1)/d would be erroneously resolved as c/d if the |
| 21 // following mount points were registered: "/a/b/c", "/a/b/c(1)". (Note: | 21 // following mount points were registered: "/a/b/c", "/a/b/c(1)". (Note: |
| 22 // "/a/b/c" < "/a/b/c(1)" < "/a/b/c/"). | 22 // "/a/b/c" < "/a/b/c(1)" < "/a/b/c/"). |
| 23 FilePath NormalizeFilePath(const FilePath& path) { | 23 base::FilePath NormalizeFilePath(const base::FilePath& path) { |
| 24 if (path.empty()) | 24 if (path.empty()) |
| 25 return path; | 25 return path; |
| 26 | 26 |
| 27 FilePath::StringType path_str = path.StripTrailingSeparators().value(); | 27 base::FilePath::StringType path_str = path.StripTrailingSeparators().value(); |
| 28 if (!FilePath::IsSeparator(path_str[path_str.length() - 1])) | 28 if (!base::FilePath::IsSeparator(path_str[path_str.length() - 1])) |
| 29 path_str.append(FILE_PATH_LITERAL("/")); | 29 path_str.append(FILE_PATH_LITERAL("/")); |
| 30 | 30 |
| 31 return FilePath(path_str).NormalizePathSeparators(); | 31 return base::FilePath(path_str).NormalizePathSeparators(); |
| 32 } | 32 } |
| 33 | 33 |
| 34 // Wrapper around ref-counted ExternalMountPoints that will be used to lazily | 34 // Wrapper around ref-counted ExternalMountPoints that will be used to lazily |
| 35 // create and initialize LazyInstance system ExternalMountPoints. | 35 // create and initialize LazyInstance system ExternalMountPoints. |
| 36 class SystemMountPointsLazyWrapper { | 36 class SystemMountPointsLazyWrapper { |
| 37 public: | 37 public: |
| 38 SystemMountPointsLazyWrapper() | 38 SystemMountPointsLazyWrapper() |
| 39 : system_mount_points_(fileapi::ExternalMountPoints::CreateRefCounted()) { | 39 : system_mount_points_(fileapi::ExternalMountPoints::CreateRefCounted()) { |
| 40 RegisterDefaultMountPoints(); | 40 RegisterDefaultMountPoints(); |
| 41 } | 41 } |
| 42 | 42 |
| 43 ~SystemMountPointsLazyWrapper() {} | 43 ~SystemMountPointsLazyWrapper() {} |
| 44 | 44 |
| 45 fileapi::ExternalMountPoints* get() { | 45 fileapi::ExternalMountPoints* get() { |
| 46 return system_mount_points_.get(); | 46 return system_mount_points_.get(); |
| 47 } | 47 } |
| 48 | 48 |
| 49 private: | 49 private: |
| 50 void RegisterDefaultMountPoints() { | 50 void RegisterDefaultMountPoints() { |
| 51 #if defined(OS_CHROMEOS) | 51 #if defined(OS_CHROMEOS) |
| 52 // Add default system mount points. | 52 // Add default system mount points. |
| 53 system_mount_points_->RegisterFileSystem( | 53 system_mount_points_->RegisterFileSystem( |
| 54 "archive", | 54 "archive", |
| 55 fileapi::kFileSystemTypeNativeLocal, | 55 fileapi::kFileSystemTypeNativeLocal, |
| 56 FilePath(FILE_PATH_LITERAL("/media/archive"))); | 56 base::FilePath(FILE_PATH_LITERAL("/media/archive"))); |
| 57 system_mount_points_->RegisterFileSystem( | 57 system_mount_points_->RegisterFileSystem( |
| 58 "removable", | 58 "removable", |
| 59 fileapi::kFileSystemTypeNativeLocal, | 59 fileapi::kFileSystemTypeNativeLocal, |
| 60 FilePath(FILE_PATH_LITERAL("/media/removable"))); | 60 base::FilePath(FILE_PATH_LITERAL("/media/removable"))); |
| 61 system_mount_points_->RegisterFileSystem( | 61 system_mount_points_->RegisterFileSystem( |
| 62 "oem", | 62 "oem", |
| 63 fileapi::kFileSystemTypeRestrictedNativeLocal, | 63 fileapi::kFileSystemTypeRestrictedNativeLocal, |
| 64 FilePath(FILE_PATH_LITERAL("/usr/share/oem"))); | 64 base::FilePath(FILE_PATH_LITERAL("/usr/share/oem"))); |
| 65 #endif // defined(OS_CHROMEOS) | 65 #endif // defined(OS_CHROMEOS) |
| 66 } | 66 } |
| 67 | 67 |
| 68 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points_; | 68 scoped_refptr<fileapi::ExternalMountPoints> system_mount_points_; |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 base::LazyInstance<SystemMountPointsLazyWrapper>::Leaky | 71 base::LazyInstance<SystemMountPointsLazyWrapper>::Leaky |
| 72 g_external_mount_points = LAZY_INSTANCE_INITIALIZER; | 72 g_external_mount_points = LAZY_INSTANCE_INITIALIZER; |
| 73 | 73 |
| 74 } // namespace | 74 } // namespace |
| 75 | 75 |
| 76 namespace fileapi { | 76 namespace fileapi { |
| 77 | 77 |
| 78 class ExternalMountPoints::Instance { | 78 class ExternalMountPoints::Instance { |
| 79 public: | 79 public: |
| 80 Instance(FileSystemType type, | 80 Instance(FileSystemType type, |
| 81 const FilePath& path, | 81 const base::FilePath& path, |
| 82 RemoteFileSystemProxyInterface* remote_proxy); | 82 RemoteFileSystemProxyInterface* remote_proxy); |
| 83 | 83 |
| 84 ~Instance(); | 84 ~Instance(); |
| 85 | 85 |
| 86 FileSystemType type() const { return type_; } | 86 FileSystemType type() const { return type_; } |
| 87 const FilePath& path() const { return path_; } | 87 const base::FilePath& path() const { return path_; } |
| 88 RemoteFileSystemProxyInterface* remote_proxy() const { | 88 RemoteFileSystemProxyInterface* remote_proxy() const { |
| 89 return remote_proxy_.get(); | 89 return remote_proxy_.get(); |
| 90 } | 90 } |
| 91 | 91 |
| 92 private: | 92 private: |
| 93 const FileSystemType type_; | 93 const FileSystemType type_; |
| 94 const FilePath path_; | 94 const base::FilePath path_; |
| 95 | 95 |
| 96 // For file systems that have a remote file system proxy. | 96 // For file systems that have a remote file system proxy. |
| 97 scoped_refptr<RemoteFileSystemProxyInterface> remote_proxy_; | 97 scoped_refptr<RemoteFileSystemProxyInterface> remote_proxy_; |
| 98 | 98 |
| 99 DISALLOW_COPY_AND_ASSIGN(Instance); | 99 DISALLOW_COPY_AND_ASSIGN(Instance); |
| 100 }; | 100 }; |
| 101 | 101 |
| 102 ExternalMountPoints::Instance::Instance(FileSystemType type, | 102 ExternalMountPoints::Instance::Instance(FileSystemType type, |
| 103 const FilePath& path, | 103 const base::FilePath& path, |
| 104 RemoteFileSystemProxyInterface* proxy) | 104 RemoteFileSystemProxyInterface* proxy) |
| 105 : type_(type), | 105 : type_(type), |
| 106 path_(path.StripTrailingSeparators()), | 106 path_(path.StripTrailingSeparators()), |
| 107 remote_proxy_(proxy) { | 107 remote_proxy_(proxy) { |
| 108 DCHECK(!proxy || (kFileSystemTypeDrive == type_)); | 108 DCHECK(!proxy || (kFileSystemTypeDrive == type_)); |
| 109 } | 109 } |
| 110 | 110 |
| 111 ExternalMountPoints::Instance::~Instance() {} | 111 ExternalMountPoints::Instance::~Instance() {} |
| 112 | 112 |
| 113 //-------------------------------------------------------------------------- | 113 //-------------------------------------------------------------------------- |
| 114 | 114 |
| 115 // static | 115 // static |
| 116 ExternalMountPoints* ExternalMountPoints::GetSystemInstance() { | 116 ExternalMountPoints* ExternalMountPoints::GetSystemInstance() { |
| 117 return g_external_mount_points.Pointer()->get(); | 117 return g_external_mount_points.Pointer()->get(); |
| 118 } | 118 } |
| 119 | 119 |
| 120 // static | 120 // static |
| 121 scoped_refptr<ExternalMountPoints> ExternalMountPoints::CreateRefCounted() { | 121 scoped_refptr<ExternalMountPoints> ExternalMountPoints::CreateRefCounted() { |
| 122 return new ExternalMountPoints(); | 122 return new ExternalMountPoints(); |
| 123 } | 123 } |
| 124 | 124 |
| 125 bool ExternalMountPoints::RegisterFileSystem( | 125 bool ExternalMountPoints::RegisterFileSystem( |
| 126 const std::string& mount_name, | 126 const std::string& mount_name, |
| 127 FileSystemType type, | 127 FileSystemType type, |
| 128 const FilePath& path) { | 128 const base::FilePath& path) { |
| 129 return RegisterRemoteFileSystem(mount_name, type, NULL, path); | 129 return RegisterRemoteFileSystem(mount_name, type, NULL, path); |
| 130 } | 130 } |
| 131 | 131 |
| 132 bool ExternalMountPoints::RegisterRemoteFileSystem( | 132 bool ExternalMountPoints::RegisterRemoteFileSystem( |
| 133 const std::string& mount_name, | 133 const std::string& mount_name, |
| 134 FileSystemType type, | 134 FileSystemType type, |
| 135 RemoteFileSystemProxyInterface* remote_proxy, | 135 RemoteFileSystemProxyInterface* remote_proxy, |
| 136 const FilePath& path_in) { | 136 const base::FilePath& path_in) { |
| 137 base::AutoLock locker(lock_); | 137 base::AutoLock locker(lock_); |
| 138 | 138 |
| 139 FilePath path = NormalizeFilePath(path_in); | 139 base::FilePath path = NormalizeFilePath(path_in); |
| 140 if (!ValidateNewMountPoint(mount_name, path)) | 140 if (!ValidateNewMountPoint(mount_name, path)) |
| 141 return false; | 141 return false; |
| 142 | 142 |
| 143 instance_map_[mount_name] = new Instance(type, path, remote_proxy); | 143 instance_map_[mount_name] = new Instance(type, path, remote_proxy); |
| 144 if (!path.empty()) | 144 if (!path.empty()) |
| 145 path_to_name_map_.insert(std::make_pair(path, mount_name)); | 145 path_to_name_map_.insert(std::make_pair(path, mount_name)); |
| 146 return true; | 146 return true; |
| 147 } | 147 } |
| 148 | 148 |
| 149 bool ExternalMountPoints::HandlesFileSystemMountType( | 149 bool ExternalMountPoints::HandlesFileSystemMountType( |
| 150 FileSystemType type) const { | 150 FileSystemType type) const { |
| 151 return type == kFileSystemTypeExternal; | 151 return type == kFileSystemTypeExternal; |
| 152 } | 152 } |
| 153 | 153 |
| 154 bool ExternalMountPoints::RevokeFileSystem(const std::string& mount_name) { | 154 bool ExternalMountPoints::RevokeFileSystem(const std::string& mount_name) { |
| 155 base::AutoLock locker(lock_); | 155 base::AutoLock locker(lock_); |
| 156 NameToInstance::iterator found = instance_map_.find(mount_name); | 156 NameToInstance::iterator found = instance_map_.find(mount_name); |
| 157 if (found == instance_map_.end()) | 157 if (found == instance_map_.end()) |
| 158 return false; | 158 return false; |
| 159 Instance* instance = found->second; | 159 Instance* instance = found->second; |
| 160 path_to_name_map_.erase(NormalizeFilePath(instance->path())); | 160 path_to_name_map_.erase(NormalizeFilePath(instance->path())); |
| 161 delete found->second; | 161 delete found->second; |
| 162 instance_map_.erase(found); | 162 instance_map_.erase(found); |
| 163 return true; | 163 return true; |
| 164 } | 164 } |
| 165 | 165 |
| 166 bool ExternalMountPoints::GetRegisteredPath( | 166 bool ExternalMountPoints::GetRegisteredPath( |
| 167 const std::string& filesystem_id, FilePath* path) const { | 167 const std::string& filesystem_id, base::FilePath* path) const { |
| 168 DCHECK(path); | 168 DCHECK(path); |
| 169 base::AutoLock locker(lock_); | 169 base::AutoLock locker(lock_); |
| 170 NameToInstance::const_iterator found = instance_map_.find(filesystem_id); | 170 NameToInstance::const_iterator found = instance_map_.find(filesystem_id); |
| 171 if (found == instance_map_.end()) | 171 if (found == instance_map_.end()) |
| 172 return false; | 172 return false; |
| 173 *path = found->second->path(); | 173 *path = found->second->path(); |
| 174 return true; | 174 return true; |
| 175 } | 175 } |
| 176 | 176 |
| 177 bool ExternalMountPoints::CrackVirtualPath(const FilePath& virtual_path, | 177 bool ExternalMountPoints::CrackVirtualPath(const base::FilePath& virtual_path, |
| 178 std::string* mount_name, | 178 std::string* mount_name, |
| 179 FileSystemType* type, | 179 FileSystemType* type, |
| 180 FilePath* path) const { | 180 base::FilePath* path) const { |
| 181 DCHECK(mount_name); | 181 DCHECK(mount_name); |
| 182 DCHECK(path); | 182 DCHECK(path); |
| 183 | 183 |
| 184 // The path should not contain any '..' references. | 184 // The path should not contain any '..' references. |
| 185 if (virtual_path.ReferencesParent()) | 185 if (virtual_path.ReferencesParent()) |
| 186 return false; | 186 return false; |
| 187 | 187 |
| 188 // The virtual_path should comprise of <mount_name> and <relative_path> parts. | 188 // The virtual_path should comprise of <mount_name> and <relative_path> parts. |
| 189 std::vector<FilePath::StringType> components; | 189 std::vector<base::FilePath::StringType> components; |
| 190 virtual_path.GetComponents(&components); | 190 virtual_path.GetComponents(&components); |
| 191 if (components.size() < 1) | 191 if (components.size() < 1) |
| 192 return false; | 192 return false; |
| 193 | 193 |
| 194 std::vector<FilePath::StringType>::iterator component_iter = | 194 std::vector<base::FilePath::StringType>::iterator component_iter = |
| 195 components.begin(); | 195 components.begin(); |
| 196 std::string maybe_mount_name = FilePath(*component_iter++).MaybeAsASCII(); | 196 std::string maybe_mount_name = base::FilePath(*component_iter++).MaybeAsASCII(
); |
| 197 if (maybe_mount_name.empty()) | 197 if (maybe_mount_name.empty()) |
| 198 return false; | 198 return false; |
| 199 | 199 |
| 200 FilePath cracked_path; | 200 base::FilePath cracked_path; |
| 201 { | 201 { |
| 202 base::AutoLock locker(lock_); | 202 base::AutoLock locker(lock_); |
| 203 NameToInstance::const_iterator found_instance = | 203 NameToInstance::const_iterator found_instance = |
| 204 instance_map_.find(maybe_mount_name); | 204 instance_map_.find(maybe_mount_name); |
| 205 if (found_instance == instance_map_.end()) | 205 if (found_instance == instance_map_.end()) |
| 206 return false; | 206 return false; |
| 207 | 207 |
| 208 *mount_name = maybe_mount_name; | 208 *mount_name = maybe_mount_name; |
| 209 const Instance* instance = found_instance->second; | 209 const Instance* instance = found_instance->second; |
| 210 if (type) | 210 if (type) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 223 if (!filesystem_url.is_valid()) | 223 if (!filesystem_url.is_valid()) |
| 224 return FileSystemURL(); | 224 return FileSystemURL(); |
| 225 return CreateCrackedFileSystemURL(filesystem_url.origin(), | 225 return CreateCrackedFileSystemURL(filesystem_url.origin(), |
| 226 filesystem_url.mount_type(), | 226 filesystem_url.mount_type(), |
| 227 filesystem_url.path()); | 227 filesystem_url.path()); |
| 228 } | 228 } |
| 229 | 229 |
| 230 FileSystemURL ExternalMountPoints::CreateCrackedFileSystemURL( | 230 FileSystemURL ExternalMountPoints::CreateCrackedFileSystemURL( |
| 231 const GURL& origin, | 231 const GURL& origin, |
| 232 FileSystemType type, | 232 FileSystemType type, |
| 233 const FilePath& path) const { | 233 const base::FilePath& path) const { |
| 234 if (!HandlesFileSystemMountType(type)) | 234 if (!HandlesFileSystemMountType(type)) |
| 235 return FileSystemURL(); | 235 return FileSystemURL(); |
| 236 | 236 |
| 237 std::string mount_name; | 237 std::string mount_name; |
| 238 FileSystemType cracked_type; | 238 FileSystemType cracked_type; |
| 239 FilePath cracked_path; | 239 base::FilePath cracked_path; |
| 240 if (!CrackVirtualPath(path, &mount_name, &cracked_type, &cracked_path)) | 240 if (!CrackVirtualPath(path, &mount_name, &cracked_type, &cracked_path)) |
| 241 return FileSystemURL(); | 241 return FileSystemURL(); |
| 242 | 242 |
| 243 return FileSystemURL(origin, type, path, | 243 return FileSystemURL(origin, type, path, |
| 244 mount_name, cracked_type, cracked_path); | 244 mount_name, cracked_type, cracked_path); |
| 245 } | 245 } |
| 246 | 246 |
| 247 RemoteFileSystemProxyInterface* ExternalMountPoints::GetRemoteFileSystemProxy( | 247 RemoteFileSystemProxyInterface* ExternalMountPoints::GetRemoteFileSystemProxy( |
| 248 const std::string& mount_name) const { | 248 const std::string& mount_name) const { |
| 249 base::AutoLock locker(lock_); | 249 base::AutoLock locker(lock_); |
| 250 NameToInstance::const_iterator found = instance_map_.find(mount_name); | 250 NameToInstance::const_iterator found = instance_map_.find(mount_name); |
| 251 if (found == instance_map_.end()) | 251 if (found == instance_map_.end()) |
| 252 return NULL; | 252 return NULL; |
| 253 return found->second->remote_proxy(); | 253 return found->second->remote_proxy(); |
| 254 } | 254 } |
| 255 | 255 |
| 256 void ExternalMountPoints::AddMountPointInfosTo( | 256 void ExternalMountPoints::AddMountPointInfosTo( |
| 257 std::vector<MountPointInfo>* mount_points) const { | 257 std::vector<MountPointInfo>* mount_points) const { |
| 258 base::AutoLock locker(lock_); | 258 base::AutoLock locker(lock_); |
| 259 DCHECK(mount_points); | 259 DCHECK(mount_points); |
| 260 for (NameToInstance::const_iterator iter = instance_map_.begin(); | 260 for (NameToInstance::const_iterator iter = instance_map_.begin(); |
| 261 iter != instance_map_.end(); ++iter) { | 261 iter != instance_map_.end(); ++iter) { |
| 262 mount_points->push_back(MountPointInfo(iter->first, iter->second->path())); | 262 mount_points->push_back(MountPointInfo(iter->first, iter->second->path())); |
| 263 } | 263 } |
| 264 } | 264 } |
| 265 | 265 |
| 266 bool ExternalMountPoints::GetVirtualPath(const FilePath& path_in, | 266 bool ExternalMountPoints::GetVirtualPath(const base::FilePath& path_in, |
| 267 FilePath* virtual_path) { | 267 base::FilePath* virtual_path) { |
| 268 DCHECK(virtual_path); | 268 DCHECK(virtual_path); |
| 269 | 269 |
| 270 base::AutoLock locker(lock_); | 270 base::AutoLock locker(lock_); |
| 271 | 271 |
| 272 FilePath path = NormalizeFilePath(path_in); | 272 base::FilePath path = NormalizeFilePath(path_in); |
| 273 std::map<FilePath, std::string>::reverse_iterator iter( | 273 std::map<base::FilePath, std::string>::reverse_iterator iter( |
| 274 path_to_name_map_.upper_bound(path)); | 274 path_to_name_map_.upper_bound(path)); |
| 275 if (iter == path_to_name_map_.rend()) | 275 if (iter == path_to_name_map_.rend()) |
| 276 return false; | 276 return false; |
| 277 | 277 |
| 278 *virtual_path = CreateVirtualRootPath(iter->second); | 278 *virtual_path = CreateVirtualRootPath(iter->second); |
| 279 if (iter->first == path) | 279 if (iter->first == path) |
| 280 return true; | 280 return true; |
| 281 return iter->first.AppendRelativePath(path, virtual_path); | 281 return iter->first.AppendRelativePath(path, virtual_path); |
| 282 } | 282 } |
| 283 | 283 |
| 284 FilePath ExternalMountPoints::CreateVirtualRootPath( | 284 base::FilePath ExternalMountPoints::CreateVirtualRootPath( |
| 285 const std::string& mount_name) const { | 285 const std::string& mount_name) const { |
| 286 return FilePath().AppendASCII(mount_name); | 286 return base::FilePath().AppendASCII(mount_name); |
| 287 } | 287 } |
| 288 | 288 |
| 289 ExternalMountPoints::ExternalMountPoints() {} | 289 ExternalMountPoints::ExternalMountPoints() {} |
| 290 | 290 |
| 291 ExternalMountPoints::~ExternalMountPoints() { | 291 ExternalMountPoints::~ExternalMountPoints() { |
| 292 STLDeleteContainerPairSecondPointers(instance_map_.begin(), | 292 STLDeleteContainerPairSecondPointers(instance_map_.begin(), |
| 293 instance_map_.end()); | 293 instance_map_.end()); |
| 294 } | 294 } |
| 295 | 295 |
| 296 bool ExternalMountPoints::ValidateNewMountPoint(const std::string& mount_name, | 296 bool ExternalMountPoints::ValidateNewMountPoint(const std::string& mount_name, |
| 297 const FilePath& path) { | 297 const base::FilePath& path) { |
| 298 lock_.AssertAcquired(); | 298 lock_.AssertAcquired(); |
| 299 | 299 |
| 300 // Mount name must not be empty. | 300 // Mount name must not be empty. |
| 301 if (mount_name.empty()) | 301 if (mount_name.empty()) |
| 302 return false; | 302 return false; |
| 303 | 303 |
| 304 // Verify there is no registered mount point with the same name. | 304 // Verify there is no registered mount point with the same name. |
| 305 NameToInstance::iterator found = instance_map_.find(mount_name); | 305 NameToInstance::iterator found = instance_map_.find(mount_name); |
| 306 if (found != instance_map_.end()) | 306 if (found != instance_map_.end()) |
| 307 return false; | 307 return false; |
| 308 | 308 |
| 309 // Allow empty paths. | 309 // Allow empty paths. |
| 310 if (path.empty()) | 310 if (path.empty()) |
| 311 return true; | 311 return true; |
| 312 | 312 |
| 313 // Verify path is legal. | 313 // Verify path is legal. |
| 314 if (path.ReferencesParent() || !path.IsAbsolute()) | 314 if (path.ReferencesParent() || !path.IsAbsolute()) |
| 315 return false; | 315 return false; |
| 316 | 316 |
| 317 // Check there the new path does not overlap with one of the existing ones. | 317 // Check there the new path does not overlap with one of the existing ones. |
| 318 std::map<FilePath, std::string>::reverse_iterator potential_parent( | 318 std::map<base::FilePath, std::string>::reverse_iterator potential_parent( |
| 319 path_to_name_map_.upper_bound(path)); | 319 path_to_name_map_.upper_bound(path)); |
| 320 if (potential_parent != path_to_name_map_.rend()) { | 320 if (potential_parent != path_to_name_map_.rend()) { |
| 321 if (potential_parent->first == path || | 321 if (potential_parent->first == path || |
| 322 potential_parent->first.IsParent(path)) { | 322 potential_parent->first.IsParent(path)) { |
| 323 return false; | 323 return false; |
| 324 } | 324 } |
| 325 } | 325 } |
| 326 | 326 |
| 327 std::map<FilePath, std::string>::iterator potential_child = | 327 std::map<base::FilePath, std::string>::iterator potential_child = |
| 328 path_to_name_map_.upper_bound(path); | 328 path_to_name_map_.upper_bound(path); |
| 329 if (potential_child == path_to_name_map_.end()) | 329 if (potential_child == path_to_name_map_.end()) |
| 330 return true; | 330 return true; |
| 331 return !(potential_child->first == path) && | 331 return !(potential_child->first == path) && |
| 332 !path.IsParent(potential_child->first); | 332 !path.IsParent(potential_child->first); |
| 333 } | 333 } |
| 334 | 334 |
| 335 ScopedExternalFileSystem::ScopedExternalFileSystem( | 335 ScopedExternalFileSystem::ScopedExternalFileSystem( |
| 336 const std::string& mount_name, | 336 const std::string& mount_name, |
| 337 FileSystemType type, | 337 FileSystemType type, |
| 338 const FilePath& path) | 338 const base::FilePath& path) |
| 339 : mount_name_(mount_name) { | 339 : mount_name_(mount_name) { |
| 340 ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( | 340 ExternalMountPoints::GetSystemInstance()->RegisterFileSystem( |
| 341 mount_name, type, path); | 341 mount_name, type, path); |
| 342 } | 342 } |
| 343 | 343 |
| 344 FilePath ScopedExternalFileSystem::GetVirtualRootPath() const { | 344 base::FilePath ScopedExternalFileSystem::GetVirtualRootPath() const { |
| 345 return ExternalMountPoints::GetSystemInstance()-> | 345 return ExternalMountPoints::GetSystemInstance()-> |
| 346 CreateVirtualRootPath(mount_name_); | 346 CreateVirtualRootPath(mount_name_); |
| 347 } | 347 } |
| 348 | 348 |
| 349 ScopedExternalFileSystem::~ScopedExternalFileSystem() { | 349 ScopedExternalFileSystem::~ScopedExternalFileSystem() { |
| 350 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(mount_name_); | 350 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(mount_name_); |
| 351 } | 351 } |
| 352 | 352 |
| 353 } // namespace fileapi | 353 } // namespace fileapi |
| 354 | 354 |
| OLD | NEW |