[email protected] | e7e4673 | 2012-01-05 11:45:55 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 5 | #ifndef WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_BACKEND_H_ |
| 6 | #define WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_BACKEND_H_ |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 7 | |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
[email protected] | e7e4673 | 2012-01-05 11:45:55 | [diff] [blame] | 11 | #include "base/callback_forward.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 12 | #include "base/files/file_path.h" |
[email protected] | 98407ee | 2013-04-04 08:52:17 | [diff] [blame] | 13 | #include "base/memory/scoped_ptr.h" |
[email protected] | 07ecc2d | 2012-01-16 04:46:59 | [diff] [blame] | 14 | #include "base/platform_file.h" |
[email protected] | c6f9203a | 2013-05-28 02:08:07 | [diff] [blame] | 15 | #include "webkit/browser/fileapi/file_permission_policy.h" |
[email protected] | 22dea52c | 2013-05-29 07:44:40 | [diff] [blame] | 16 | #include "webkit/browser/fileapi/open_file_system_mode.h" |
[email protected] | e5bf2fd | 2013-06-13 02:59:18 | [diff] [blame] | 17 | #include "webkit/browser/webkit_storage_browser_export.h" |
[email protected] | 61d271f3 | 2013-05-28 04:59:23 | [diff] [blame] | 18 | #include "webkit/common/fileapi/file_system_types.h" |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 19 | |
[email protected] | 35456abfb | 2013-06-11 10:57:39 | [diff] [blame] | 20 | class GURL; |
| 21 | |
[email protected] | ad117b1 | 2012-04-19 05:40:19 | [diff] [blame] | 22 | namespace webkit_blob { |
[email protected] | c4ca3b45 | 2012-05-31 03:15:46 | [diff] [blame] | 23 | class FileStreamReader; |
[email protected] | ad117b1 | 2012-04-19 05:40:19 | [diff] [blame] | 24 | } |
| 25 | |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 26 | namespace fileapi { |
| 27 | |
[email protected] | 25b69799 | 2013-01-29 07:10:05 | [diff] [blame] | 28 | class AsyncFileUtil; |
[email protected] | 98407ee | 2013-04-04 08:52:17 | [diff] [blame] | 29 | class CopyOrMoveFileValidatorFactory; |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 30 | class FileSystemURL; |
[email protected] | 7e836a3d | 2012-05-31 05:14:59 | [diff] [blame] | 31 | class FileStreamWriter; |
[email protected] | 3eb080d | 2012-01-16 04:20:06 | [diff] [blame] | 32 | class FileSystemContext; |
[email protected] | e7e4673 | 2012-01-05 11:45:55 | [diff] [blame] | 33 | class FileSystemFileUtil; |
[email protected] | 8e3bc3e | 2012-08-24 13:12:53 | [diff] [blame] | 34 | class FileSystemOperation; |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 35 | class FileSystemQuotaUtil; |
[email protected] | e7e4673 | 2012-01-05 11:45:55 | [diff] [blame] | 36 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 37 | // An interface for defining a file system backend. |
[email protected] | c3d638b3 | 2013-04-22 02:18:49 | [diff] [blame] | 38 | // |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 39 | // NOTE: when you implement a new FileSystemBackend for your own |
[email protected] | c3d638b3 | 2013-04-22 02:18:49 | [diff] [blame] | 40 | // FileSystem module, please contact to [email protected]. |
| 41 | // |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 42 | class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemBackend { |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 43 | public: |
[email protected] | e7b9c97 | 2013-07-17 01:10:36 | [diff] [blame] | 44 | // Callback for InitializeFileSystem. |
[email protected] | a836883d | 2013-07-12 03:50:02 | [diff] [blame] | 45 | typedef base::Callback<void(const GURL& root_url, |
| 46 | const std::string& name, |
| 47 | base::PlatformFileError error)> |
[email protected] | 3fc17aed | 2013-07-24 10:01:50 | [diff] [blame] | 48 | OpenFileSystemCallback; |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 49 | virtual ~FileSystemBackend() {} |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 50 | |
[email protected] | 534173b5 | 2013-07-25 12:21:13 | [diff] [blame] | 51 | // Returns true if this filesystem backend can handle |type|. |
| 52 | // One filesystem backend may be able to handle multiple filesystem types. |
[email protected] | 420fb56 | 2013-04-18 01:46:34 | [diff] [blame] | 53 | virtual bool CanHandleType(FileSystemType type) const = 0; |
| 54 | |
[email protected] | 3fc17aed | 2013-07-24 10:01:50 | [diff] [blame] | 55 | // This method is called right after the backend is registered in the |
| 56 | // FileSystemContext and before any other methods are called. Each backend can |
| 57 | // do additional initialization which depends on FileSystemContext here. |
| 58 | virtual void Initialize(FileSystemContext* context) = 0; |
| 59 | |
| 60 | // Opens the filesystem for the given |origin_url| and |type|. |
[email protected] | 60f60f8 | 2012-01-11 10:26:10 | [diff] [blame] | 61 | // This verifies if it is allowed to request (or create) the filesystem |
[email protected] | 534173b5 | 2013-07-25 12:21:13 | [diff] [blame] | 62 | // and if it can access (or create) the root directory. |
[email protected] | 22dea52c | 2013-05-29 07:44:40 | [diff] [blame] | 63 | // If |mode| is CREATE_IF_NONEXISTENT calling this may also create |
| 64 | // the root directory (and/or related database entries etc) for |
[email protected] | 60f60f8 | 2012-01-11 10:26:10 | [diff] [blame] | 65 | // the filesystem if it doesn't exist. |
[email protected] | 3fc17aed | 2013-07-24 10:01:50 | [diff] [blame] | 66 | virtual void OpenFileSystem( |
[email protected] | 60f60f8 | 2012-01-11 10:26:10 | [diff] [blame] | 67 | const GURL& origin_url, |
| 68 | FileSystemType type, |
[email protected] | 22dea52c | 2013-05-29 07:44:40 | [diff] [blame] | 69 | OpenFileSystemMode mode, |
[email protected] | 3fc17aed | 2013-07-24 10:01:50 | [diff] [blame] | 70 | const OpenFileSystemCallback& callback) = 0; |
[email protected] | 60f60f8 | 2012-01-11 10:26:10 | [diff] [blame] | 71 | |
[email protected] | 534173b5 | 2013-07-25 12:21:13 | [diff] [blame] | 72 | // Returns the specialized AsyncFileUtil for this backend. |
[email protected] | 25b69799 | 2013-01-29 07:10:05 | [diff] [blame] | 73 | virtual AsyncFileUtil* GetAsyncFileUtil(FileSystemType type) = 0; |
| 74 | |
[email protected] | 534173b5 | 2013-07-25 12:21:13 | [diff] [blame] | 75 | // Returns the specialized CopyOrMoveFileValidatorFactory for this backend |
| 76 | // and |type|. If |error_code| is PLATFORM_FILE_OK and the result is NULL, |
| 77 | // then no validator is required. |
[email protected] | 98407ee | 2013-04-04 08:52:17 | [diff] [blame] | 78 | virtual CopyOrMoveFileValidatorFactory* GetCopyOrMoveFileValidatorFactory( |
| 79 | FileSystemType type, base::PlatformFileError* error_code) = 0; |
| 80 | |
[email protected] | 3eb080d | 2012-01-16 04:20:06 | [diff] [blame] | 81 | // Returns a new instance of the specialized FileSystemOperation for this |
[email protected] | 534173b5 | 2013-07-25 12:21:13 | [diff] [blame] | 82 | // backend based on the given triplet of |origin_url|, |file_system_type| |
[email protected] | d23a00cc | 2012-09-11 17:38:13 | [diff] [blame] | 83 | // and |virtual_path|. On failure to create a file system operation, set |
| 84 | // |error_code| correspondingly. |
[email protected] | 3eb080d | 2012-01-16 04:20:06 | [diff] [blame] | 85 | // This method is usually dispatched by |
| 86 | // FileSystemContext::CreateFileSystemOperation. |
[email protected] | 8e3bc3e | 2012-08-24 13:12:53 | [diff] [blame] | 87 | virtual FileSystemOperation* CreateFileSystemOperation( |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 88 | const FileSystemURL& url, |
[email protected] | d23a00cc | 2012-09-11 17:38:13 | [diff] [blame] | 89 | FileSystemContext* context, |
| 90 | base::PlatformFileError* error_code) const = 0; |
[email protected] | ad117b1 | 2012-04-19 05:40:19 | [diff] [blame] | 91 | |
[email protected] | c4ca3b45 | 2012-05-31 03:15:46 | [diff] [blame] | 92 | // Creates a new file stream reader for a given filesystem URL |url| with an |
[email protected] | a105783 | 2012-10-15 13:28:06 | [diff] [blame] | 93 | // offset |offset|. |expected_modification_time| specifies the expected last |
| 94 | // modification if the value is non-null, the reader will check the underlying |
| 95 | // file's actual modification time to see if the file has been modified, and |
| 96 | // if it does any succeeding read operations should fail with |
| 97 | // ERR_UPLOAD_FILE_CHANGED error. |
[email protected] | ad117b1 | 2012-04-19 05:40:19 | [diff] [blame] | 98 | // This method itself does *not* check if the given path exists and is a |
| 99 | // regular file. |
[email protected] | 3ee9eb0 | 2013-04-10 09:17:05 | [diff] [blame] | 100 | virtual scoped_ptr<webkit_blob::FileStreamReader> CreateFileStreamReader( |
[email protected] | 7ba1627 | 2013-10-07 09:43:16 | [diff] [blame] | 101 | const FileSystemURL& url, |
| 102 | int64 offset, |
| 103 | const base::Time& expected_modification_time, |
| 104 | FileSystemContext* context) const = 0; |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 105 | |
[email protected] | 7e836a3d | 2012-05-31 05:14:59 | [diff] [blame] | 106 | // Creates a new file stream writer for a given filesystem URL |url| with an |
| 107 | // offset |offset|. |
[email protected] | 7e84b91 | 2012-05-16 04:42:01 | [diff] [blame] | 108 | // This method itself does *not* check if the given path exists and is a |
| 109 | // regular file. |
[email protected] | 3ee9eb0 | 2013-04-10 09:17:05 | [diff] [blame] | 110 | virtual scoped_ptr<FileStreamWriter> CreateFileStreamWriter( |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 111 | const FileSystemURL& url, |
[email protected] | 7e836a3d | 2012-05-31 05:14:59 | [diff] [blame] | 112 | int64 offset, |
| 113 | FileSystemContext* context) const = 0; |
[email protected] | 7e84b91 | 2012-05-16 04:42:01 | [diff] [blame] | 114 | |
[email protected] | 534173b5 | 2013-07-25 12:21:13 | [diff] [blame] | 115 | // Returns the specialized FileSystemQuotaUtil for this backend. |
| 116 | // This could return NULL if this backend does not support quota. |
[email protected] | 6faad82 | 2012-05-11 12:58:29 | [diff] [blame] | 117 | virtual FileSystemQuotaUtil* GetQuotaUtil() = 0; |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | // An interface to control external file system access permissions. |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 121 | // TODO(satorux): Move this out of 'webkit/browser/fileapi'. crbug.com/257279 |
| 122 | class ExternalFileSystemBackend : public FileSystemBackend { |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 123 | public: |
[email protected] | 4d03859 | 2013-02-18 16:50:23 | [diff] [blame] | 124 | // Returns true if |url| is allowed to be accessed. |
| 125 | // This is supposed to perform ExternalFileSystem-specific security |
[email protected] | ce5cbed8 | 2013-07-01 11:52:31 | [diff] [blame] | 126 | // checks. |
[email protected] | 4d03859 | 2013-02-18 16:50:23 | [diff] [blame] | 127 | virtual bool IsAccessAllowed(const fileapi::FileSystemURL& url) const = 0; |
[email protected] | ce09761 | 2012-06-17 05:05:41 | [diff] [blame] | 128 | // Returns the list of top level directories that are exposed by this |
| 129 | // provider. This list is used to set appropriate child process file access |
| 130 | // permissions. |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 131 | virtual std::vector<base::FilePath> GetRootDirectories() const = 0; |
[email protected] | 9fb9294a | 2012-08-21 14:55:37 | [diff] [blame] | 132 | // Grants access to all external file system from extension identified with |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 133 | // |extension_id|. |
| 134 | virtual void GrantFullAccessToExtension(const std::string& extension_id) = 0; |
| 135 | // Grants access to |virtual_path| from |origin_url|. |
| 136 | virtual void GrantFileAccessToExtension( |
| 137 | const std::string& extension_id, |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 138 | const base::FilePath& virtual_path) = 0; |
[email protected] | 9fb9294a | 2012-08-21 14:55:37 | [diff] [blame] | 139 | // Revokes file access from extension identified with |extension_id|. |
[email protected] | b777b33 | 2011-04-16 04:01:08 | [diff] [blame] | 140 | virtual void RevokeAccessForExtension( |
| 141 | const std::string& extension_id) = 0; |
[email protected] | ce980204 | 2011-05-27 10:11:40 | [diff] [blame] | 142 | // Gets virtual path by known filesystem path. Returns false when filesystem |
| 143 | // path is not exposed by this provider. |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 144 | virtual bool GetVirtualPath(const base::FilePath& file_system_path, |
| 145 | base::FilePath* virtual_path) = 0; |
[email protected] | 073a04f | 2011-03-24 00:49:40 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | } // namespace fileapi |
| 149 | |
[email protected] | f19bbf6 | 2013-07-09 01:22:32 | [diff] [blame] | 150 | #endif // WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_BACKEND_H_ |