diff options
author | mtomasz@chromium.org <mtomasz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-26 04:56:40 +0000 |
---|---|---|
committer | mtomasz@chromium.org <mtomasz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-02-26 04:56:40 +0000 |
commit | 0fa422a0e4ee63132825a23a2f60f1a0c05aec79 (patch) | |
tree | 74b2cfb7115484e507cde71b18d1e9ea4e1a1c47 /chrome/browser/chromeos/file_manager/fileapi_util.h | |
parent | 7c89ff265392829fbc3510c047a555d290366408 (diff) | |
download | chromium_src-0fa422a0e4ee63132825a23a2f60f1a0c05aec79.zip chromium_src-0fa422a0e4ee63132825a23a2f60f1a0c05aec79.tar.gz chromium_src-0fa422a0e4ee63132825a23a2f60f1a0c05aec79.tar.bz2 |
Create file systems restricted to volumes.
Before, on Chrome OS, JS Entry objects were holding the same DOMFileSystem
object, and they were attached to the same big root. All of the mount points
were first-level directories. This looks like a Linux approach.
However, for better isolation a different approach has been suggested. To have
a separate DOMFileSystem object per every volume on Chrome OS. So, Downloads
and Drive files would be separate, and the filesystem's root would be one of
the mount points.
What is more, restricting DOMFileSystem objects to a mount point is not enough.
In case of `archive` and `removable`, we have two level mount points. The first
level is either `archive` or `removable`. Either of them contains mounted
volumes - archives or removable devices.
This patch restricts DOMFileSystem objects (and thereof Entry objects) to the
inner most mount point. For example: /Downloads, /drive, /archive/archive-1,
/archive/archive-2, /removable/disk-1, /removable/disk-2.
Having this solution it is impossible to access the grand root containing all
of the outer mount points, which was until now restricted in JavaScript. Also,
it doesn't allow to get an Entry for /archive and /removable, which was also
filtered out in JS layer.
Moreover, and what is the most important, this approach allows to map a C++
VolumeInfo to a DOMFileSystem object with 1:1 relationship.
To achieve that, the OpenFileSystem has been renamed to ResolveURL, since this
method has been always used to Resolving a file system URL. Opening the file
system was a side effect. This allowed to unify the code paths for sandboxed
and non-sandboxed file systems. Before, for non-sandboxed file systems, the
root url (and the name) were manually computed using a deprecated utility
function fileapi::GetFileSystemInfoForChromeOS(), which is removed in this
patch.
The drawback of this change was that the root_url and the fs name resolution
became asynchonous. The reason for that is that sandboxed file systems may
perform operations on different threads, therefore they have to be
asynchronous. To simplify migration a utility function has been introduced to
convert FileDefinition vectors to EntryDefinition vectors.
Finally, this change will allow simplifying Files app volumes logic
significantly. The JS VolumeInfo will match C++ VolumeInfo 1:1, as well as
either VolumeInfo will match a DOMFileSystem object 1:1. As a result, we will
be able to remove special cases for inner mount points (for archives and
removables). Another advantage is simple way to pass names of JS-provided file
systems.
The permission management is currently simplified, but the next step will be to
grant permissions per inner-most mount point, which will clean up security
policy comparing to the former implementation.
TBR=phajdan.jr@chromium.org
BUG=318021
TEST=Tested manually.
Review URL: https://codereview.chromium.org/162963003
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@253351 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/chromeos/file_manager/fileapi_util.h')
-rw-r--r-- | chrome/browser/chromeos/file_manager/fileapi_util.h | 59 |
1 files changed, 55 insertions, 4 deletions
diff --git a/chrome/browser/chromeos/file_manager/fileapi_util.h b/chrome/browser/chromeos/file_manager/fileapi_util.h index d935785..8adbd09 100644 --- a/chrome/browser/chromeos/file_manager/fileapi_util.h +++ b/chrome/browser/chromeos/file_manager/fileapi_util.h @@ -8,14 +8,14 @@ #define CHROME_BROWSER_CHROMEOS_FILE_MANAGER_FILEAPI_UTIL_H_ #include <string> + +#include "base/callback_forward.h" +#include "base/files/file.h" +#include "base/files/file_path.h" #include "url/gurl.h" class Profile; -namespace base { -class FilePath; -} - namespace content { class RenderViewHost; } @@ -27,6 +27,39 @@ class FileSystemContext; namespace file_manager { namespace util { +// Structure information necessary to create a EntryDefinition, and therefore +// an Entry object on the JavaScript side. +struct FileDefinition { + base::FilePath virtual_path; + base::FilePath absolute_path; + bool is_directory; +}; + +// Contains all information needed to create an Entry object in custom bindings. +struct EntryDefinition { + EntryDefinition(); + ~EntryDefinition(); + + std::string file_system_root_url; // Used to create DOMFileSystem. + std::string file_system_name; // Value of DOMFileSystem.name. + base::FilePath full_path; // Value of Entry.fullPath. + bool is_directory; // Whether to create FileEntry or DirectoryEntry. + base::File::Error error; +}; + +typedef std::vector<FileDefinition> FileDefinitionList; +typedef std::vector<EntryDefinition> EntryDefinitionList; + +// The callback used by ConvertFileDefinitionToEntryDefinition. Returns the +// result of the conversion. +typedef base::Callback<void(const EntryDefinition& entry_definition)> + EntryDefinitionCallback; + +// The callback used by ConvertFileDefinitionListToEntryDefinitionList. Returns +// the result of the conversion as a list. +typedef base::Callback<void(scoped_ptr< + EntryDefinitionList> entry_definition_list)> EntryDefinitionListCallback; + // Returns a file system context associated with the given profile and the // extension ID. fileapi::FileSystemContext* GetFileSystemContextForExtensionId( @@ -71,6 +104,24 @@ bool ConvertAbsoluteFilePathToRelativeFileSystemPath( const base::FilePath& absolute_path, base::FilePath* relative_path); +// Converts a file definition to a entry definition and returns the result +// via a callback. |profile| cannot be null. Must be called on UI thread. +void ConvertFileDefinitionToEntryDefinition( + Profile* profile, + const std::string& extension_id, + const FileDefinition& file_definition, + const EntryDefinitionCallback& callback); + +// Converts a list of file definitions into a list of entry definitions and +// returns it via |callback|. The method is safe, |file_definition_list| is +// copied internally. The output list has the same order of items and size as +// the input vector. |profile| cannot be null. Must be called on UI thread. +void ConvertFileDefinitionListToEntryDefinitionList( + Profile* profile, + const std::string& extension_id, + const FileDefinitionList& file_definition_list, + const EntryDefinitionListCallback& callback); + } // namespace util } // namespace file_manager |