Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Unified Diff: webkit/fileapi/external_mount_points.cc

Issue 12258021: Fix filesystem API file_handlers to work for drive on ChromeOS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webkit/fileapi/external_mount_points.cc
diff --git a/webkit/fileapi/external_mount_points.cc b/webkit/fileapi/external_mount_points.cc
index 5c84c1bb248e49456e94b1d85b2fae022b7e4d97..b53c34b859485fcbe67ba7ab4a7ec46023f02c9a 100644
--- a/webkit/fileapi/external_mount_points.cc
+++ b/webkit/fileapi/external_mount_points.cc
@@ -244,12 +244,20 @@ FileSystemURL ExternalMountPoints::CreateCrackedFileSystemURL(
mount_name, cracked_type, cracked_path);
}
-RemoteFileSystemProxyInterface* ExternalMountPoints::GetRemoteFileSystemProxy(
- const std::string& mount_name) const {
+RemoteFileSystemProxyInterface*
+ExternalMountPoints::GetRemoteFileSystemProxyForPath(
+ const base::FilePath& full_path) const {
base::AutoLock locker(lock_);
- NameToInstance::const_iterator found = instance_map_.find(mount_name);
+
+ std::string mount_point;
+ if (!GetMountPointForPath(full_path, &mount_point, NULL))
+ return NULL;
+
+ // Get mount point instance.
+ NameToInstance::const_iterator found = instance_map_.find(mount_point);
if (found == instance_map_.end())
return NULL;
+
return found->second->remote_proxy();
}
@@ -263,22 +271,21 @@ void ExternalMountPoints::AddMountPointInfosTo(
}
}
-bool ExternalMountPoints::GetVirtualPath(const base::FilePath& path_in,
+bool ExternalMountPoints::GetVirtualPath(const base::FilePath& path,
base::FilePath* virtual_path) {
DCHECK(virtual_path);
base::AutoLock locker(lock_);
- base::FilePath path = NormalizeFilePath(path_in);
- std::map<base::FilePath, std::string>::reverse_iterator iter(
- path_to_name_map_.upper_bound(path));
- if (iter == path_to_name_map_.rend())
+ std::string mount_point_name;
+ base::FilePath mount_point_root;
+ if (!GetMountPointForPath(path, &mount_point_name, &mount_point_root))
return false;
- *virtual_path = CreateVirtualRootPath(iter->second);
- if (iter->first == path)
+ *virtual_path = CreateVirtualRootPath(mount_point_name);
+ if (mount_point_root == path)
return true;
- return iter->first.AppendRelativePath(path, virtual_path);
+ return mount_point_root.AppendRelativePath(path, virtual_path);
}
base::FilePath ExternalMountPoints::CreateVirtualRootPath(
@@ -332,6 +339,31 @@ bool ExternalMountPoints::ValidateNewMountPoint(const std::string& mount_name,
!path.IsParent(potential_child->first);
}
+bool ExternalMountPoints::GetMountPointForPath(
+ const base::FilePath& path,
+ std::string* mount_point_name,
+ base::FilePath* mount_point_root) const {
+ DCHECK(mount_point_name);
+
+ // Get mount point the path belongs to. It is the path whose value is smaller
+ // than normalized path, but also parents the normalized_path. Note that
+ // ExternalMountPoints are constrained so there cannot be a root path x for
+ // which the following holds: root_path(path) < x < path.
+ base::FilePath normalized_path = NormalizeFilePath(path);
+ std::map<base::FilePath, std::string>::const_reverse_iterator iter(
+ path_to_name_map_.upper_bound(normalized_path));
+ if (iter == path_to_name_map_.rend() ||
+ (iter->first != normalized_path &&
+ !iter->first.IsParent(normalized_path))) {
+ return false;
+ }
+
+ *mount_point_name = iter->second;
+ if (mount_point_root)
+ *mount_point_root = iter->first;
+ return true;
+}
+
ScopedExternalFileSystem::ScopedExternalFileSystem(
const std::string& mount_name,
FileSystemType type,

Powered by Google App Engine
This is Rietveld 408576698