Index: webkit/fileapi/isolated_context.h |
diff --git a/webkit/fileapi/isolated_context.h b/webkit/fileapi/isolated_context.h |
index 31ed9fcc03ec034db2596172b314ccac5b5d9685..9bf75ac39f1451cbf75ebb69f1717d3ea80ddb5c 100644 |
--- a/webkit/fileapi/isolated_context.h |
+++ b/webkit/fileapi/isolated_context.h |
@@ -26,23 +26,39 @@ 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; |
+ // The path of the file. |
+ FilePath path; |
+ }; |
+ |
// 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). |
+ // Not 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 |
+ // display_name as their names 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 |
+ // name and the ID for the newly created filesystem to the renderer for |
// the sake of security. |
// |
// 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 +67,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); |
benwells
2012/06/28 20:07:39
Is there a way to make this change that doesn't ne
kinuko
2012/06/29 10:11:32
The new API is trying to let the caller pick a nam
|
+ |
+ // 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 +85,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 vector 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 +124,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::map<std::string, FileInfo> FileMap; |
tzik
2012/06/29 02:56:35
Can we use std::set instead?
kinuko
2012/06/29 08:31:22
Done.
|
+ typedef std::map<std::string, FileMap> IDToFileMap; |
// Obtain an instance of this class via GetInstance(). |
IsolatedContext(); |
@@ -125,7 +142,7 @@ class FILEAPI_EXPORT IsolatedContext { |
mutable base::Lock lock_; |
// Maps the toplevel entries to the filesystem id. |
- IDToPathMap toplevel_map_; |
+ IDToFileMap toplevel_map_; |
// Holds a set of writable ids. |
// Isolated file systems are created read-only by default, and this set |