| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef WEBKIT_FILEAPI_FILE_SYSTEM_MOUNT_POINT_PROVIDER_H_ | |
| 6 #define WEBKIT_FILEAPI_FILE_SYSTEM_MOUNT_POINT_PROVIDER_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/callback_forward.h" | |
| 12 #include "base/files/file_path.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/platform_file.h" | |
| 15 #include "webkit/fileapi/file_permission_policy.h" | |
| 16 #include "webkit/fileapi/file_system_types.h" | |
| 17 #include "webkit/storage/webkit_storage_export.h" | |
| 18 | |
| 19 namespace webkit_blob { | |
| 20 class FileStreamReader; | |
| 21 } | |
| 22 | |
| 23 namespace fileapi { | |
| 24 | |
| 25 class AsyncFileUtil; | |
| 26 class CopyOrMoveFileValidatorFactory; | |
| 27 class FileSystemURL; | |
| 28 class FileStreamWriter; | |
| 29 class FileSystemContext; | |
| 30 class FileSystemFileUtil; | |
| 31 class FileSystemOperation; | |
| 32 class FileSystemQuotaUtil; | |
| 33 class RemoteFileSystemProxyInterface; | |
| 34 | |
| 35 // An interface to provide mount-point-specific path-related utilities | |
| 36 // and specialized FileSystemFileUtil instance. | |
| 37 // | |
| 38 // NOTE: when you implement a new MountPointProvider for your own | |
| 39 // FileSystem module, please contact to kinuko@chromium.org. | |
| 40 // | |
| 41 class WEBKIT_STORAGE_EXPORT FileSystemMountPointProvider { | |
| 42 public: | |
| 43 // Callback for ValidateFileSystemRoot. | |
| 44 typedef base::Callback<void(base::PlatformFileError error)> | |
| 45 ValidateFileSystemCallback; | |
| 46 typedef base::Callback<void(base::PlatformFileError error)> | |
| 47 DeleteFileSystemCallback; | |
| 48 virtual ~FileSystemMountPointProvider() {} | |
| 49 | |
| 50 // Returns true if this mount point provider can handle |type|. | |
| 51 // One mount point provider may be able to handle multiple filesystem types. | |
| 52 virtual bool CanHandleType(FileSystemType type) const = 0; | |
| 53 | |
| 54 // Validates the filesystem for the given |origin_url| and |type|. | |
| 55 // This verifies if it is allowed to request (or create) the filesystem | |
| 56 // and if it can access (or create) the root directory of the mount point. | |
| 57 // If |create| is true this may also create the root directory for | |
| 58 // the filesystem if it doesn't exist. | |
| 59 virtual void ValidateFileSystemRoot( | |
| 60 const GURL& origin_url, | |
| 61 FileSystemType type, | |
| 62 bool create, | |
| 63 const ValidateFileSystemCallback& callback) = 0; | |
| 64 | |
| 65 // Retrieves the root path of the filesystem specified by the given | |
| 66 // file system url on the file thread. | |
| 67 // If |create| is true this may also create the root directory for | |
| 68 // the filesystem if it doesn't exist. | |
| 69 virtual base::FilePath GetFileSystemRootPathOnFileThread( | |
| 70 const FileSystemURL& url, | |
| 71 bool create) = 0; | |
| 72 | |
| 73 // Returns the specialized FileSystemFileUtil for this mount point. | |
| 74 // It is ok to return NULL if the filesystem doesn't support synchronous | |
| 75 // version of FileUtil. | |
| 76 virtual FileSystemFileUtil* GetFileUtil(FileSystemType type) = 0; | |
| 77 | |
| 78 // Returns the specialized AsyncFileUtil for this mount point. | |
| 79 virtual AsyncFileUtil* GetAsyncFileUtil(FileSystemType type) = 0; | |
| 80 | |
| 81 // Returns the specialized CopyOrMoveFileValidatorFactory for this mount | |
| 82 // point and |type|. If |error_code| is PLATFORM_FILE_OK and the result | |
| 83 // is NULL, then no validator is required. | |
| 84 virtual CopyOrMoveFileValidatorFactory* GetCopyOrMoveFileValidatorFactory( | |
| 85 FileSystemType type, base::PlatformFileError* error_code) = 0; | |
| 86 | |
| 87 // Initialize the CopyOrMoveFileValidatorFactory. Invalid to call more than | |
| 88 // once. | |
| 89 virtual void InitializeCopyOrMoveFileValidatorFactory( | |
| 90 FileSystemType type, | |
| 91 scoped_ptr<CopyOrMoveFileValidatorFactory> factory) = 0; | |
| 92 | |
| 93 // Returns file permission policy we should apply for the given |url|. | |
| 94 virtual FilePermissionPolicy GetPermissionPolicy( | |
| 95 const FileSystemURL& url, | |
| 96 int permissions) const = 0; | |
| 97 | |
| 98 // Returns a new instance of the specialized FileSystemOperation for this | |
| 99 // mount point based on the given triplet of |origin_url|, |file_system_type| | |
| 100 // and |virtual_path|. On failure to create a file system operation, set | |
| 101 // |error_code| correspondingly. | |
| 102 // This method is usually dispatched by | |
| 103 // FileSystemContext::CreateFileSystemOperation. | |
| 104 virtual FileSystemOperation* CreateFileSystemOperation( | |
| 105 const FileSystemURL& url, | |
| 106 FileSystemContext* context, | |
| 107 base::PlatformFileError* error_code) const = 0; | |
| 108 | |
| 109 // Creates a new file stream reader for a given filesystem URL |url| with an | |
| 110 // offset |offset|. |expected_modification_time| specifies the expected last | |
| 111 // modification if the value is non-null, the reader will check the underlying | |
| 112 // file's actual modification time to see if the file has been modified, and | |
| 113 // if it does any succeeding read operations should fail with | |
| 114 // ERR_UPLOAD_FILE_CHANGED error. | |
| 115 // This method itself does *not* check if the given path exists and is a | |
| 116 // regular file. | |
| 117 virtual scoped_ptr<webkit_blob::FileStreamReader> CreateFileStreamReader( | |
| 118 const FileSystemURL& url, | |
| 119 int64 offset, | |
| 120 const base::Time& expected_modification_time, | |
| 121 FileSystemContext* context) const = 0; | |
| 122 | |
| 123 // Creates a new file stream writer for a given filesystem URL |url| with an | |
| 124 // offset |offset|. | |
| 125 // This method itself does *not* check if the given path exists and is a | |
| 126 // regular file. | |
| 127 virtual scoped_ptr<FileStreamWriter> CreateFileStreamWriter( | |
| 128 const FileSystemURL& url, | |
| 129 int64 offset, | |
| 130 FileSystemContext* context) const = 0; | |
| 131 | |
| 132 // Returns the specialized FileSystemQuotaUtil for this mount point. | |
| 133 // This could return NULL if this mount point does not support quota. | |
| 134 virtual FileSystemQuotaUtil* GetQuotaUtil() = 0; | |
| 135 | |
| 136 // Deletes the filesystem for the given |origin_url| and |type|. | |
| 137 virtual void DeleteFileSystem( | |
| 138 const GURL& origin_url, | |
| 139 FileSystemType type, | |
| 140 FileSystemContext* context, | |
| 141 const DeleteFileSystemCallback& callback) = 0; | |
| 142 }; | |
| 143 | |
| 144 // An interface to control external file system access permissions. | |
| 145 class ExternalFileSystemMountPointProvider | |
| 146 : public FileSystemMountPointProvider { | |
| 147 public: | |
| 148 // Returns true if |url| is allowed to be accessed. | |
| 149 // This is supposed to perform ExternalFileSystem-specific security | |
| 150 // checks. This method is also likely to be called by | |
| 151 // FileSystemMountPointProvider::GetPermissionPolicy as | |
| 152 // GetPermissionPolicy is supposed to perform fileapi-generic security | |
| 153 // checks (which likely need to include ExternalFileSystem-specific checks). | |
| 154 virtual bool IsAccessAllowed(const fileapi::FileSystemURL& url) const = 0; | |
| 155 // Returns the list of top level directories that are exposed by this | |
| 156 // provider. This list is used to set appropriate child process file access | |
| 157 // permissions. | |
| 158 virtual std::vector<base::FilePath> GetRootDirectories() const = 0; | |
| 159 // Grants access to all external file system from extension identified with | |
| 160 // |extension_id|. | |
| 161 virtual void GrantFullAccessToExtension(const std::string& extension_id) = 0; | |
| 162 // Grants access to |virtual_path| from |origin_url|. | |
| 163 virtual void GrantFileAccessToExtension( | |
| 164 const std::string& extension_id, | |
| 165 const base::FilePath& virtual_path) = 0; | |
| 166 // Revokes file access from extension identified with |extension_id|. | |
| 167 virtual void RevokeAccessForExtension( | |
| 168 const std::string& extension_id) = 0; | |
| 169 // Gets virtual path by known filesystem path. Returns false when filesystem | |
| 170 // path is not exposed by this provider. | |
| 171 virtual bool GetVirtualPath(const base::FilePath& file_system_path, | |
| 172 base::FilePath* virtual_path) = 0; | |
| 173 }; | |
| 174 | |
| 175 } // namespace fileapi | |
| 176 | |
| 177 #endif // WEBKIT_FILEAPI_FILE_SYSTEM_MOUNT_POINT_PROVIDER_H_ | |
| OLD | NEW |