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