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/files/file_path.h" | 7 #include "base/files/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" |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
218 std::string mount_name; | 218 std::string mount_name; |
219 FileSystemType cracked_type; | 219 FileSystemType cracked_type; |
220 base::FilePath cracked_path; | 220 base::FilePath cracked_path; |
221 if (!CrackVirtualPath(path, &mount_name, &cracked_type, &cracked_path)) | 221 if (!CrackVirtualPath(path, &mount_name, &cracked_type, &cracked_path)) |
222 return FileSystemURL(); | 222 return FileSystemURL(); |
223 | 223 |
224 return FileSystemURL(origin, type, path, | 224 return FileSystemURL(origin, type, path, |
225 mount_name, cracked_type, cracked_path); | 225 mount_name, cracked_type, cracked_path); |
226 } | 226 } |
227 | 227 |
| 228 bool ExternalMountPoints::GetVirtualPath(const base::FilePath& full_path, |
| 229 base::FilePath* virtual_path) const { |
| 230 DCHECK(virtual_path); |
| 231 |
| 232 base::AutoLock locker(lock_); |
| 233 |
| 234 base::FilePath path = NormalizeFilePath(full_path); |
| 235 std::map<base::FilePath, std::string>::const_reverse_iterator iter( |
| 236 path_to_name_map_.upper_bound(path)); |
| 237 if (iter == path_to_name_map_.rend()) |
| 238 return false; |
| 239 |
| 240 *virtual_path = CreateVirtualRootPath(iter->second); |
| 241 if (iter->first == path) |
| 242 return true; |
| 243 return iter->first.AppendRelativePath(path, virtual_path); |
| 244 } |
| 245 |
228 RemoteFileSystemProxyInterface* ExternalMountPoints::GetRemoteFileSystemProxy( | 246 RemoteFileSystemProxyInterface* ExternalMountPoints::GetRemoteFileSystemProxy( |
229 const std::string& mount_name) const { | 247 const std::string& mount_name) const { |
230 base::AutoLock locker(lock_); | 248 base::AutoLock locker(lock_); |
231 NameToInstance::const_iterator found = instance_map_.find(mount_name); | 249 NameToInstance::const_iterator found = instance_map_.find(mount_name); |
232 if (found == instance_map_.end()) | 250 if (found == instance_map_.end()) |
233 return NULL; | 251 return NULL; |
234 return found->second->remote_proxy(); | 252 return found->second->remote_proxy(); |
235 } | 253 } |
236 | 254 |
237 void ExternalMountPoints::AddMountPointInfosTo( | 255 void ExternalMountPoints::AddMountPointInfosTo( |
238 std::vector<MountPointInfo>* mount_points) const { | 256 std::vector<MountPointInfo>* mount_points) const { |
239 base::AutoLock locker(lock_); | 257 base::AutoLock locker(lock_); |
240 DCHECK(mount_points); | 258 DCHECK(mount_points); |
241 for (NameToInstance::const_iterator iter = instance_map_.begin(); | 259 for (NameToInstance::const_iterator iter = instance_map_.begin(); |
242 iter != instance_map_.end(); ++iter) { | 260 iter != instance_map_.end(); ++iter) { |
243 mount_points->push_back(MountPointInfo(iter->first, iter->second->path())); | 261 mount_points->push_back(MountPointInfo(iter->first, iter->second->path())); |
244 } | 262 } |
245 } | 263 } |
246 | 264 |
247 bool ExternalMountPoints::GetVirtualPath(const base::FilePath& path_in, | |
248 base::FilePath* virtual_path) { | |
249 DCHECK(virtual_path); | |
250 | |
251 base::AutoLock locker(lock_); | |
252 | |
253 base::FilePath path = NormalizeFilePath(path_in); | |
254 std::map<base::FilePath, std::string>::reverse_iterator iter( | |
255 path_to_name_map_.upper_bound(path)); | |
256 if (iter == path_to_name_map_.rend()) | |
257 return false; | |
258 | |
259 *virtual_path = CreateVirtualRootPath(iter->second); | |
260 if (iter->first == path) | |
261 return true; | |
262 return iter->first.AppendRelativePath(path, virtual_path); | |
263 } | |
264 | |
265 base::FilePath ExternalMountPoints::CreateVirtualRootPath( | 265 base::FilePath ExternalMountPoints::CreateVirtualRootPath( |
266 const std::string& mount_name) const { | 266 const std::string& mount_name) const { |
267 return base::FilePath().AppendASCII(mount_name); | 267 return base::FilePath().AppendASCII(mount_name); |
268 } | 268 } |
269 | 269 |
270 ExternalMountPoints::ExternalMountPoints() {} | 270 ExternalMountPoints::ExternalMountPoints() {} |
271 | 271 |
272 ExternalMountPoints::~ExternalMountPoints() { | 272 ExternalMountPoints::~ExternalMountPoints() { |
273 STLDeleteContainerPairSecondPointers(instance_map_.begin(), | 273 STLDeleteContainerPairSecondPointers(instance_map_.begin(), |
274 instance_map_.end()); | 274 instance_map_.end()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 base::FilePath ScopedExternalFileSystem::GetVirtualRootPath() const { | 325 base::FilePath ScopedExternalFileSystem::GetVirtualRootPath() const { |
326 return ExternalMountPoints::GetSystemInstance()-> | 326 return ExternalMountPoints::GetSystemInstance()-> |
327 CreateVirtualRootPath(mount_name_); | 327 CreateVirtualRootPath(mount_name_); |
328 } | 328 } |
329 | 329 |
330 ScopedExternalFileSystem::~ScopedExternalFileSystem() { | 330 ScopedExternalFileSystem::~ScopedExternalFileSystem() { |
331 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(mount_name_); | 331 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(mount_name_); |
332 } | 332 } |
333 | 333 |
334 } // namespace fileapi | 334 } // namespace fileapi |
OLD | NEW |