[email protected] | 08f8feb | 2012-02-26 11:53:50 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | d5233ef4 | 2011-03-04 04:14:04 | [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] | 5a20d04 | 2013-05-22 12:54:18 | [diff] [blame] | 5 | #ifndef WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ |
| 6 | #define WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ |
[email protected] | d5233ef4 | 2011-03-04 04:14:04 | [diff] [blame] | 7 | |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 8 | #include "base/files/file_path.h" |
[email protected] | d109fcb | 2012-11-07 19:44:33 | [diff] [blame] | 9 | #include "base/memory/scoped_ptr.h" |
[email protected] | d5233ef4 | 2011-03-04 04:14:04 | [diff] [blame] | 10 | #include "base/platform_file.h" |
[email protected] | 824d389 | 2013-09-25 13:00:30 | [diff] [blame] | 11 | #include "webkit/browser/fileapi/file_system_operation.h" |
[email protected] | e5bf2fd | 2013-06-13 02:59:18 | [diff] [blame] | 12 | #include "webkit/browser/webkit_storage_browser_export.h" |
[email protected] | b76b556d | 2013-05-29 03:09:43 | [diff] [blame] | 13 | #include "webkit/common/blob/scoped_file.h" |
[email protected] | d5233ef4 | 2011-03-04 04:14:04 | [diff] [blame] | 14 | |
| 15 | namespace base { |
[email protected] | d5233ef4 | 2011-03-04 04:14:04 | [diff] [blame] | 16 | class Time; |
| 17 | } |
| 18 | |
| 19 | namespace fileapi { |
| 20 | |
[email protected] | d5233ef4 | 2011-03-04 04:14:04 | [diff] [blame] | 21 | class FileSystemOperationContext; |
[email protected] | 25b69799 | 2013-01-29 07:10:05 | [diff] [blame] | 22 | class FileSystemURL; |
[email protected] | d5233ef4 | 2011-03-04 04:14:04 | [diff] [blame] | 23 | |
[email protected] | 3d7e97a | 2012-03-01 19:04:06 | [diff] [blame] | 24 | // A file utility interface that provides basic file utility methods for |
| 25 | // FileSystem API. |
[email protected] | 8eb140ed | 2011-04-28 08:01:54 | [diff] [blame] | 26 | // |
[email protected] | 95af737 | 2012-05-28 07:51:20 | [diff] [blame] | 27 | // Layering structure of the FileSystemFileUtil was split out. |
| 28 | // See http://crbug.com/128136 if you need it. |
[email protected] | e5bf2fd | 2013-06-13 02:59:18 | [diff] [blame] | 29 | class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemFileUtil { |
[email protected] | d5233ef4 | 2011-03-04 04:14:04 | [diff] [blame] | 30 | public: |
[email protected] | 824d389 | 2013-09-25 13:00:30 | [diff] [blame] | 31 | typedef FileSystemOperation::CopyOrMoveOption CopyOrMoveOption; |
| 32 | |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 33 | // It will be implemented by each subclass such as FileSystemFileEnumerator. |
[email protected] | e5bf2fd | 2013-06-13 02:59:18 | [diff] [blame] | 34 | class WEBKIT_STORAGE_BROWSER_EXPORT AbstractFileEnumerator { |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 35 | public: |
| 36 | virtual ~AbstractFileEnumerator() {} |
[email protected] | d5233ef4 | 2011-03-04 04:14:04 | [diff] [blame] | 37 | |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 38 | // Returns an empty string if there are no more results. |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 39 | virtual base::FilePath Next() = 0; |
[email protected] | d5233ef4 | 2011-03-04 04:14:04 | [diff] [blame] | 40 | |
[email protected] | 488a09e7 | 2013-01-18 05:21:39 | [diff] [blame] | 41 | // These methods return metadata for the file most recently returned by |
| 42 | // Next(). If Next() has never been called, or if Next() most recently |
| 43 | // returned an empty string, then return the default values of 0, |
| 44 | // "null time", and false, respectively. |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 45 | virtual int64 Size() = 0; |
[email protected] | 2c514f3 | 2012-03-14 05:58:13 | [diff] [blame] | 46 | virtual base::Time LastModifiedTime() = 0; |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 47 | virtual bool IsDirectory() = 0; |
| 48 | }; |
[email protected] | d5233ef4 | 2011-03-04 04:14:04 | [diff] [blame] | 49 | |
[email protected] | e5bf2fd | 2013-06-13 02:59:18 | [diff] [blame] | 50 | class WEBKIT_STORAGE_BROWSER_EXPORT EmptyFileEnumerator |
[email protected] | 3d1e89a | 2013-01-17 22:34:20 | [diff] [blame] | 51 | : public AbstractFileEnumerator { |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 52 | virtual base::FilePath Next() OVERRIDE; |
[email protected] | 0034fcd | 2012-08-09 22:08:56 | [diff] [blame] | 53 | virtual int64 Size() OVERRIDE; |
| 54 | virtual base::Time LastModifiedTime() OVERRIDE; |
| 55 | virtual bool IsDirectory() OVERRIDE; |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 56 | }; |
[email protected] | d5233ef4 | 2011-03-04 04:14:04 | [diff] [blame] | 57 | |
[email protected] | 95af737 | 2012-05-28 07:51:20 | [diff] [blame] | 58 | virtual ~FileSystemFileUtil() {} |
[email protected] | d5233ef4 | 2011-03-04 04:14:04 | [diff] [blame] | 59 | |
[email protected] | 65c337e0 | 2012-02-29 04:31:10 | [diff] [blame] | 60 | // Creates or opens a file with the given flags. |
[email protected] | 25b69799 | 2013-01-29 07:10:05 | [diff] [blame] | 61 | // See header comments for AsyncFileUtil::CreateOrOpen() for more details. |
[email protected] | 077c5dfd | 2013-11-02 01:41:11 | [diff] [blame] | 62 | // This is used only by Pepper/NaCl File API. |
[email protected] | 403ada8 | 2013-01-08 07:51:39 | [diff] [blame] | 63 | virtual base::PlatformFileError CreateOrOpen( |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 64 | FileSystemOperationContext* context, |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 65 | const FileSystemURL& url, |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 66 | int file_flags, |
[email protected] | 403ada8 | 2013-01-08 07:51:39 | [diff] [blame] | 67 | base::PlatformFile* file_handle, |
[email protected] | 95af737 | 2012-05-28 07:51:20 | [diff] [blame] | 68 | bool* created) = 0; |
[email protected] | 3a7f439 | 2011-04-26 12:21:51 | [diff] [blame] | 69 | |
[email protected] | 65c337e0 | 2012-02-29 04:31:10 | [diff] [blame] | 70 | // Closes the given file handle. |
[email protected] | 077c5dfd | 2013-11-02 01:41:11 | [diff] [blame] | 71 | // This is used only for Pepper/NaCl File API. |
[email protected] | 403ada8 | 2013-01-08 07:51:39 | [diff] [blame] | 72 | virtual base::PlatformFileError Close( |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 73 | FileSystemOperationContext* context, |
[email protected] | 403ada8 | 2013-01-08 07:51:39 | [diff] [blame] | 74 | base::PlatformFile file) = 0; |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 75 | |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 76 | // Ensures that the given |url| exist. This creates a empty new file |
| 77 | // at |url| if the |url| does not exist. |
[email protected] | 25b69799 | 2013-01-29 07:10:05 | [diff] [blame] | 78 | // See header comments for AsyncFileUtil::EnsureFileExists() for more details. |
[email protected] | 403ada8 | 2013-01-08 07:51:39 | [diff] [blame] | 79 | virtual base::PlatformFileError EnsureFileExists( |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 80 | FileSystemOperationContext* context, |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 81 | const FileSystemURL& url, bool* created) = 0; |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 82 | |
[email protected] | 25b69799 | 2013-01-29 07:10:05 | [diff] [blame] | 83 | // Creates directory at given url. |
| 84 | // See header comments for AsyncFileUtil::CreateDirectory() for more details. |
[email protected] | 403ada8 | 2013-01-08 07:51:39 | [diff] [blame] | 85 | virtual base::PlatformFileError CreateDirectory( |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 86 | FileSystemOperationContext* context, |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 87 | const FileSystemURL& url, |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 88 | bool exclusive, |
[email protected] | 95af737 | 2012-05-28 07:51:20 | [diff] [blame] | 89 | bool recursive) = 0; |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 90 | |
[email protected] | 65c337e0 | 2012-02-29 04:31:10 | [diff] [blame] | 91 | // Retrieves the information about a file. |
[email protected] | 25b69799 | 2013-01-29 07:10:05 | [diff] [blame] | 92 | // See header comments for AsyncFileUtil::GetFileInfo() for more details. |
[email protected] | 403ada8 | 2013-01-08 07:51:39 | [diff] [blame] | 93 | virtual base::PlatformFileError GetFileInfo( |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 94 | FileSystemOperationContext* context, |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 95 | const FileSystemURL& url, |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 96 | base::PlatformFileInfo* file_info, |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 97 | base::FilePath* platform_path) = 0; |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 98 | |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 99 | // Returns a pointer to a new instance of AbstractFileEnumerator which is |
| 100 | // implemented for each FileSystemFileUtil subclass. The instance needs to be |
| 101 | // freed by the caller, and its lifetime should not extend past when the |
| 102 | // current call returns to the main FILE message loop. |
[email protected] | 3a7f439 | 2011-04-26 12:21:51 | [diff] [blame] | 103 | // |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 104 | // The supplied context must remain valid at least lifetime of the enumerator |
| 105 | // instance. |
[email protected] | d109fcb | 2012-11-07 19:44:33 | [diff] [blame] | 106 | virtual scoped_ptr<AbstractFileEnumerator> CreateFileEnumerator( |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 107 | FileSystemOperationContext* context, |
[email protected] | 5453ca05 | 2013-04-11 21:15:39 | [diff] [blame] | 108 | const FileSystemURL& root_url) = 0; |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 109 | |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 110 | // Maps |file_system_url| given |context| into |local_file_path| |
| 111 | // which represents physical file location on the host OS. |
[email protected] | 08f8feb | 2012-02-26 11:53:50 | [diff] [blame] | 112 | // This may not always make sense for all subclasses. |
[email protected] | 403ada8 | 2013-01-08 07:51:39 | [diff] [blame] | 113 | virtual base::PlatformFileError GetLocalFilePath( |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 114 | FileSystemOperationContext* context, |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 115 | const FileSystemURL& file_system_url, |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 116 | base::FilePath* local_file_path) = 0; |
[email protected] | 3a7f439 | 2011-04-26 12:21:51 | [diff] [blame] | 117 | |
[email protected] | 25b69799 | 2013-01-29 07:10:05 | [diff] [blame] | 118 | // Updates the file metadata information. |
| 119 | // See header comments for AsyncFileUtil::Touch() for more details. |
[email protected] | 403ada8 | 2013-01-08 07:51:39 | [diff] [blame] | 120 | virtual base::PlatformFileError Touch( |
[email protected] | d5233ef4 | 2011-03-04 04:14:04 | [diff] [blame] | 121 | FileSystemOperationContext* context, |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 122 | const FileSystemURL& url, |
[email protected] | d5233ef4 | 2011-03-04 04:14:04 | [diff] [blame] | 123 | const base::Time& last_access_time, |
[email protected] | 95af737 | 2012-05-28 07:51:20 | [diff] [blame] | 124 | const base::Time& last_modified_time) = 0; |
[email protected] | d5233ef4 | 2011-03-04 04:14:04 | [diff] [blame] | 125 | |
[email protected] | 25b69799 | 2013-01-29 07:10:05 | [diff] [blame] | 126 | // Truncates a file to the given length. |
| 127 | // See header comments for AsyncFileUtil::Truncate() for more details. |
[email protected] | 403ada8 | 2013-01-08 07:51:39 | [diff] [blame] | 128 | virtual base::PlatformFileError Truncate( |
[email protected] | d5233ef4 | 2011-03-04 04:14:04 | [diff] [blame] | 129 | FileSystemOperationContext* context, |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 130 | const FileSystemURL& url, |
[email protected] | 95af737 | 2012-05-28 07:51:20 | [diff] [blame] | 131 | int64 length) = 0; |
[email protected] | d5233ef4 | 2011-03-04 04:14:04 | [diff] [blame] | 132 | |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 133 | // Copies or moves a single file from |src_url| to |dest_url|. |
[email protected] | bab213be | 2013-01-23 15:13:08 | [diff] [blame] | 134 | // The filesystem type of |src_url| and |dest_url| MUST be same. |
[email protected] | 824d389 | 2013-09-25 13:00:30 | [diff] [blame] | 135 | // For |option|, please see file_system_operation.h |
[email protected] | bab213be | 2013-01-23 15:13:08 | [diff] [blame] | 136 | // |
| 137 | // This returns: |
[email protected] | aeba9c1 | 2013-01-28 10:44:42 | [diff] [blame] | 138 | // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url| |
[email protected] | bab213be | 2013-01-23 15:13:08 | [diff] [blame] | 139 | // or the parent directory of |dest_url| does not exist. |
| 140 | // - PLATFORM_FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file. |
| 141 | // - PLATFORM_FILE_ERROR_INVALID_OPERATION if |dest_url| exists and |
| 142 | // is not a file. |
| 143 | // - PLATFORM_FILE_ERROR_FAILED if |dest_url| does not exist and |
| 144 | // its parent path is a file. |
| 145 | // |
[email protected] | 403ada8 | 2013-01-08 07:51:39 | [diff] [blame] | 146 | virtual base::PlatformFileError CopyOrMoveFile( |
[email protected] | 172205b | 2011-08-30 03:36:44 | [diff] [blame] | 147 | FileSystemOperationContext* context, |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 148 | const FileSystemURL& src_url, |
| 149 | const FileSystemURL& dest_url, |
[email protected] | 824d389 | 2013-09-25 13:00:30 | [diff] [blame] | 150 | CopyOrMoveOption option, |
[email protected] | 95af737 | 2012-05-28 07:51:20 | [diff] [blame] | 151 | bool copy) = 0; |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 152 | |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 153 | // Copies in a single file from a different filesystem. |
[email protected] | 25b69799 | 2013-01-29 07:10:05 | [diff] [blame] | 154 | // See header comments for AsyncFileUtil::CopyInForeignFile() for |
| 155 | // more details. |
[email protected] | 403ada8 | 2013-01-08 07:51:39 | [diff] [blame] | 156 | virtual base::PlatformFileError CopyInForeignFile( |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 157 | FileSystemOperationContext* context, |
[email protected] | a3ef483 | 2013-02-02 05:12:33 | [diff] [blame] | 158 | const base::FilePath& src_file_path, |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 159 | const FileSystemURL& dest_url) = 0; |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 160 | |
| 161 | // Deletes a single file. |
[email protected] | 25b69799 | 2013-01-29 07:10:05 | [diff] [blame] | 162 | // See header comments for AsyncFileUtil::DeleteFile() for more details. |
[email protected] | 403ada8 | 2013-01-08 07:51:39 | [diff] [blame] | 163 | virtual base::PlatformFileError DeleteFile( |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 164 | FileSystemOperationContext* context, |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 165 | const FileSystemURL& url) = 0; |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 166 | |
| 167 | // Deletes a single empty directory. |
[email protected] | 25b69799 | 2013-01-29 07:10:05 | [diff] [blame] | 168 | // See header comments for AsyncFileUtil::DeleteDirectory() for more details. |
[email protected] | bab213be | 2013-01-23 15:13:08 | [diff] [blame] | 169 | virtual base::PlatformFileError DeleteDirectory( |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 170 | FileSystemOperationContext* context, |
[email protected] | 949f25a | 2012-06-27 01:53:09 | [diff] [blame] | 171 | const FileSystemURL& url) = 0; |
[email protected] | cdba4699 | 2011-06-07 11:51:39 | [diff] [blame] | 172 | |
[email protected] | d0a1f037 | 2012-07-19 11:17:37 | [diff] [blame] | 173 | // Creates a local snapshot file for a given |url| and returns the |
| 174 | // metadata and platform path of the snapshot file via |callback|. |
[email protected] | d0a1f037 | 2012-07-19 11:17:37 | [diff] [blame] | 175 | // |
[email protected] | 25b69799 | 2013-01-29 07:10:05 | [diff] [blame] | 176 | // See header comments for AsyncFileUtil::CreateSnapshotFile() for |
| 177 | // more details. |
[email protected] | 7ab45cfa8 | 2013-04-26 07:13:20 | [diff] [blame] | 178 | virtual webkit_blob::ScopedFile CreateSnapshotFile( |
[email protected] | 826df82 | 2012-08-04 01:23:56 | [diff] [blame] | 179 | FileSystemOperationContext* context, |
| 180 | const FileSystemURL& url, |
[email protected] | 7ab45cfa8 | 2013-04-26 07:13:20 | [diff] [blame] | 181 | base::PlatformFileError* error, |
[email protected] | 826df82 | 2012-08-04 01:23:56 | [diff] [blame] | 182 | base::PlatformFileInfo* file_info, |
[email protected] | 7ab45cfa8 | 2013-04-26 07:13:20 | [diff] [blame] | 183 | base::FilePath* platform_path) = 0; |
[email protected] | d0a1f037 | 2012-07-19 11:17:37 | [diff] [blame] | 184 | |
[email protected] | 8eb140ed | 2011-04-28 08:01:54 | [diff] [blame] | 185 | protected: |
[email protected] | 95af737 | 2012-05-28 07:51:20 | [diff] [blame] | 186 | FileSystemFileUtil() {} |
[email protected] | 7878ece | 2011-09-05 11:41:49 | [diff] [blame] | 187 | |
| 188 | private: |
[email protected] | d5233ef4 | 2011-03-04 04:14:04 | [diff] [blame] | 189 | DISALLOW_COPY_AND_ASSIGN(FileSystemFileUtil); |
| 190 | }; |
| 191 | |
| 192 | } // namespace fileapi |
| 193 | |
[email protected] | 5a20d04 | 2013-05-22 12:54:18 | [diff] [blame] | 194 | #endif // WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_ |