Index: webkit/fileapi/isolated_context.h |
diff --git a/webkit/fileapi/isolated_context.h b/webkit/fileapi/isolated_context.h |
index 31ed9fcc03ec034db2596172b314ccac5b5d9685..08603b685d4f56a0823fc6f2e4b31aac043c7c5c 100644 |
--- a/webkit/fileapi/isolated_context.h |
+++ b/webkit/fileapi/isolated_context.h |
@@ -26,23 +26,44 @@ namespace fileapi { |
// Some methods of this class are virtual just for mocking. |
class FILEAPI_EXPORT IsolatedContext { |
public: |
+ struct FILEAPI_EXPORT FileInfo { |
+ FileInfo(); |
+ FileInfo(const std::string& name, const FilePath& path); |
+ |
+ // The name of the file. |
+ std::string name; |
benwells
2012/06/29 17:41:09
Nit - this comment, and maybe the field name, shou
kinuko
2012/07/02 13:51:54
Done.
|
+ // The path of the file. |
+ FilePath path; |
+ |
+ // For STL operation. |
+ bool operator<(const FileInfo& that) const { return name < that.name; } |
+ }; |
+ |
// The instance is lazily created per browser process. |
static IsolatedContext* GetInstance(); |
- // Registers a new file isolated filesystem with the given set of files |
+ // Get a convenient display name of the |path| which could be used as a key |
+ // in the toplevel_map_. Usually this simply returns path.BaseName() |
+ // unless the |path| is a root directory (e.g. a device root). |
+ // Note that this does not guarantee the uniqueness of the returned name. |
+ static std::string GetNameForPath(const FilePath& path); |
+ |
+ // Registers a new isolated filesystem with the given set of FileInfo |
// and returns the new filesystem_id. The files are registered with their |
- // basenames as their keys so that later we can resolve the full paths |
- // for the given file name in the isolated filesystem. We only expose the |
- // key and the ID for the newly created filesystem to the renderer for |
- // the sake of security. |
+ // name as their keys so that later we can resolve the full paths |
+ // for the given name. We only expose the name and the ID for the |
+ // newly created filesystem to the renderer for the sake of security. |
+ // |
+ // It is not valid to give duplicated entries with the same name in the |
+ // same file system. |
// |
// The renderer will be sending filesystem requests with a virtual path like |
- // '/<filesystem_id>/<relative_path_from_the_basename_of_dropped_path>' |
+ // '/<filesystem_id>/<relative_path_from_the_dropped_path>' |
// for which we could crack in the browser by calling CrackIsolatedPath to |
// get the full path. |
// |
- // For example: if a dropped file has a path like '/a/b/foo' we register |
- // the path with the key 'foo' in the newly created filesystem. |
+ // For example: if a dropped file has a path like '/a/b/foo' and we register |
+ // the path with the name 'foo' in the newly created filesystem. |
// Later if the context is asked to crack a virtual path like '/<fsid>/foo' |
// it can properly return the original path '/a/b/foo' by looking up the |
// internal mapping. Similarly if a dropped entry is a directory and its |
@@ -51,13 +72,17 @@ class FILEAPI_EXPORT IsolatedContext { |
// |
// Note that the path in |fileset| that contains '..' or is not an |
// absolute path is skipped and is not registerred. |
- std::string RegisterIsolatedFileSystem(const std::set<FilePath>& fileset); |
+ std::string RegisterFileSystem(const std::vector<FileInfo>& files); |
+ |
+ // Registers a new isolated filesystem for a given display name and file. |
+ std::string RegisterFileSystemForFile(const std::string& display_name, |
+ const FilePath& path); |
// Revokes filesystem specified by the given filesystem_id. |
// Note that this revokes the filesystem no matter how many references it has. |
// It is ok to call this on the filesystem that has been already deleted |
// (if its reference count had reached 0). |
- void RevokeIsolatedFileSystem(const std::string& filesystem_id); |
+ void RevokeFileSystem(const std::string& filesystem_id); |
// Adds a reference to a filesystem specified by the given filesystem_id. |
void AddReference(const std::string& filesystem_id); |
@@ -65,36 +90,33 @@ class FILEAPI_EXPORT IsolatedContext { |
// Removes a reference to a filesystem specified by the given filesystem_id. |
// If the reference count reaches 0 the isolated context gets destroyed. |
// It is ok to call this on the filesystem that has been already deleted |
- // (e.g. by RevokeIsolatedFileSystem). |
+ // (e.g. by RevokeFileSystem). |
void RemoveReference(const std::string& filesystem_id); |
// Cracks the given |virtual_path| (which should look like |
// "/<filesystem_id>/<relative_path>") and populates the |filesystem_id| |
// and |platform_path| if the embedded <filesystem_id> is registerred |
- // to this context. |root_path| is also populated to have the platform |
- // root (toplevel) path for the |virtual_path| |
- // (i.e. |platform_path| = |root_path| + <relative_path>). |
+ // to this context. |root_path| is also populated to have the registered |
+ // root (toplevel) file info for the |virtual_path|. |
// |
// Returns false if the given virtual_path or the cracked filesystem_id |
// is not valid. |
// |
- // Note that |root_path| and |platform_path| are set to empty paths if |
+ // Note that |root_info| and |platform_path| are set to empty paths if |
// |virtual_path| has no <relative_path> part (i.e. pointing to |
// the virtual root). |
bool CrackIsolatedPath(const FilePath& virtual_path, |
std::string* filesystem_id, |
- FilePath* root_path, |
+ FileInfo* root_info, |
FilePath* platform_path) const; |
- // Returns a vector of the full paths of the top-level entry paths |
- // registered for the |filesystem_id|. Returns false if the |
- // |filesystem_is| is not valid. |
- bool GetTopLevelPaths(const std::string& filesystem_id, |
- std::vector<FilePath>* paths) const; |
+ // Returns a set of FileInfo registered for the |filesystem_id|. |
+ // Returns false if the |filesystem_id| is not valid. |
+ bool GetRegisteredFileInfo(const std::string& filesystem_id, |
+ std::vector<FileInfo>* files) const; |
- // Returns the virtual path that looks like /<filesystem_id>/<relative_path>. |
- FilePath CreateVirtualPath(const std::string& filesystem_id, |
- const FilePath& relative_path) const; |
+ // Returns the virtual root path that looks like /<filesystem_id>. |
+ FilePath CreateVirtualRootPath(const std::string& filesystem_id) const; |
// Set the filesystem writable if |writable| is true, non-writable |
// if it is false. Returns false if the |filesystem_id| is not valid. |
@@ -107,8 +129,8 @@ class FILEAPI_EXPORT IsolatedContext { |
friend struct base::DefaultLazyInstanceTraits<IsolatedContext>; |
// Maps from filesystem id to a path conversion map for top-level entries. |
- typedef std::map<FilePath, FilePath> PathMap; |
- typedef std::map<std::string, PathMap> IDToPathMap; |
+ typedef std::set<FileInfo> FileSet; |
+ typedef std::map<std::string, FileSet> IDToFileSet; |
// Obtain an instance of this class via GetInstance(). |
IsolatedContext(); |
@@ -125,7 +147,7 @@ class FILEAPI_EXPORT IsolatedContext { |
mutable base::Lock lock_; |
// Maps the toplevel entries to the filesystem id. |
- IDToPathMap toplevel_map_; |
+ IDToFileSet toplevel_map_; |
// Holds a set of writable ids. |
// Isolated file systems are created read-only by default, and this set |