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/remote_file_system_proxy.h" | 12 #include "webkit/fileapi/remote_file_system_proxy.h" |
12 | 13 |
13 namespace { | 14 namespace { |
14 | 15 |
15 // 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 |
16 // 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 |
17 // GetVirtualPath method. Separators cannot be completely stripped, or | 18 // GetVirtualPath method. Separators cannot be completely stripped, or |
18 // GetVirtualPath could not working in some edge cases. | 19 // GetVirtualPath could not working in some edge cases. |
19 // 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 |
20 // 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: |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 void ExternalMountPoints::AddMountPointInfosTo( | 234 void ExternalMountPoints::AddMountPointInfosTo( |
234 std::vector<MountPointInfo>* mount_points) const { | 235 std::vector<MountPointInfo>* mount_points) const { |
235 base::AutoLock locker(lock_); | 236 base::AutoLock locker(lock_); |
236 DCHECK(mount_points); | 237 DCHECK(mount_points); |
237 for (NameToInstance::const_iterator iter = instance_map_.begin(); | 238 for (NameToInstance::const_iterator iter = instance_map_.begin(); |
238 iter != instance_map_.end(); ++iter) { | 239 iter != instance_map_.end(); ++iter) { |
239 mount_points->push_back(MountPointInfo(iter->first, iter->second->path())); | 240 mount_points->push_back(MountPointInfo(iter->first, iter->second->path())); |
240 } | 241 } |
241 } | 242 } |
242 | 243 |
| 244 |
| 245 bool ExternalMountPoints::CanHandleURL(const FileSystemURL& url) const { |
| 246 return url.is_valid() && url.type() == kFileSystemTypeExternal; |
| 247 } |
| 248 |
| 249 FileSystemURL ExternalMountPoints::CrackFileSystemURL( |
| 250 const FileSystemURL& url) const { |
| 251 if (!CanHandleURL(url)) |
| 252 return FileSystemURL(); |
| 253 |
| 254 DCHECK(!url.is_cracked()); |
| 255 |
| 256 std::string mount_name; |
| 257 FileSystemType type; |
| 258 FilePath path; |
| 259 if (!CrackVirtualPath(url.path(), &mount_name, &type, &path)) |
| 260 return FileSystemURL(); |
| 261 |
| 262 return FileSystemURL::CreateForCrackedURL(url, mount_name, type, path); |
| 263 } |
| 264 |
| 265 FileSystemURL ExternalMountPoints::CrackURL(const GURL& url) const { |
| 266 return CrackFileSystemURL(FileSystemURL(url)); |
| 267 } |
| 268 |
| 269 FileSystemURL ExternalMountPoints::CreateCrackedFileSystemURL( |
| 270 const GURL& origin, |
| 271 FileSystemType type, |
| 272 const FilePath& path) const { |
| 273 return CrackFileSystemURL(FileSystemURL(origin, type, path)); |
| 274 } |
| 275 |
243 bool ExternalMountPoints::GetVirtualPath(const FilePath& path_in, | 276 bool ExternalMountPoints::GetVirtualPath(const FilePath& path_in, |
244 FilePath* virtual_path) { | 277 FilePath* virtual_path) { |
245 DCHECK(virtual_path); | 278 DCHECK(virtual_path); |
246 | 279 |
247 base::AutoLock locker(lock_); | 280 base::AutoLock locker(lock_); |
248 | 281 |
249 FilePath path = NormalizeFilePath(path_in); | 282 FilePath path = NormalizeFilePath(path_in); |
250 std::map<FilePath, std::string>::reverse_iterator iter( | 283 std::map<FilePath, std::string>::reverse_iterator iter( |
251 path_to_name_map_.upper_bound(path)); | 284 path_to_name_map_.upper_bound(path)); |
252 if (iter == path_to_name_map_.rend()) | 285 if (iter == path_to_name_map_.rend()) |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 return ExternalMountPoints::GetSystemInstance()-> | 355 return ExternalMountPoints::GetSystemInstance()-> |
323 CreateVirtualRootPath(mount_name_); | 356 CreateVirtualRootPath(mount_name_); |
324 } | 357 } |
325 | 358 |
326 ScopedExternalFileSystem::~ScopedExternalFileSystem() { | 359 ScopedExternalFileSystem::~ScopedExternalFileSystem() { |
327 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(mount_name_); | 360 ExternalMountPoints::GetSystemInstance()->RevokeFileSystem(mount_name_); |
328 } | 361 } |
329 | 362 |
330 } // namespace fileapi | 363 } // namespace fileapi |
331 | 364 |
OLD | NEW |