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