blob: 5a4d730b5c8beee0c6c712b6adbee4fea19341b0 [file] [log] [blame]
[email protected]08f8feb2012-02-26 11:53:501// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]d5233ef42011-03-04 04:14:042// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]5a20d042013-05-22 12:54:185#ifndef WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_
6#define WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_
[email protected]d5233ef42011-03-04 04:14:047
[email protected]57999812013-02-24 05:40:528#include "base/files/file_path.h"
[email protected]d109fcb2012-11-07 19:44:339#include "base/memory/scoped_ptr.h"
[email protected]d5233ef42011-03-04 04:14:0410#include "base/platform_file.h"
[email protected]824d3892013-09-25 13:00:3011#include "webkit/browser/fileapi/file_system_operation.h"
[email protected]e5bf2fd2013-06-13 02:59:1812#include "webkit/browser/webkit_storage_browser_export.h"
[email protected]b76b556d2013-05-29 03:09:4313#include "webkit/common/blob/scoped_file.h"
[email protected]d5233ef42011-03-04 04:14:0414
15namespace base {
[email protected]d5233ef42011-03-04 04:14:0416class Time;
17}
18
19namespace fileapi {
20
[email protected]d5233ef42011-03-04 04:14:0421class FileSystemOperationContext;
[email protected]25b697992013-01-29 07:10:0522class FileSystemURL;
[email protected]d5233ef42011-03-04 04:14:0423
[email protected]3d7e97a2012-03-01 19:04:0624// A file utility interface that provides basic file utility methods for
25// FileSystem API.
[email protected]8eb140ed2011-04-28 08:01:5426//
[email protected]95af7372012-05-28 07:51:2027// Layering structure of the FileSystemFileUtil was split out.
28// See http://crbug.com/128136 if you need it.
[email protected]e5bf2fd2013-06-13 02:59:1829class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemFileUtil {
[email protected]d5233ef42011-03-04 04:14:0430 public:
[email protected]824d3892013-09-25 13:00:3031 typedef FileSystemOperation::CopyOrMoveOption CopyOrMoveOption;
32
[email protected]7878ece2011-09-05 11:41:4933 // It will be implemented by each subclass such as FileSystemFileEnumerator.
[email protected]e5bf2fd2013-06-13 02:59:1834 class WEBKIT_STORAGE_BROWSER_EXPORT AbstractFileEnumerator {
[email protected]7878ece2011-09-05 11:41:4935 public:
36 virtual ~AbstractFileEnumerator() {}
[email protected]d5233ef42011-03-04 04:14:0437
[email protected]7878ece2011-09-05 11:41:4938 // Returns an empty string if there are no more results.
[email protected]a3ef4832013-02-02 05:12:3339 virtual base::FilePath Next() = 0;
[email protected]d5233ef42011-03-04 04:14:0440
[email protected]488a09e72013-01-18 05:21:3941 // 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]7878ece2011-09-05 11:41:4945 virtual int64 Size() = 0;
[email protected]2c514f32012-03-14 05:58:1346 virtual base::Time LastModifiedTime() = 0;
[email protected]7878ece2011-09-05 11:41:4947 virtual bool IsDirectory() = 0;
48 };
[email protected]d5233ef42011-03-04 04:14:0449
[email protected]e5bf2fd2013-06-13 02:59:1850 class WEBKIT_STORAGE_BROWSER_EXPORT EmptyFileEnumerator
[email protected]3d1e89a2013-01-17 22:34:2051 : public AbstractFileEnumerator {
[email protected]a3ef4832013-02-02 05:12:3352 virtual base::FilePath Next() OVERRIDE;
[email protected]0034fcd2012-08-09 22:08:5653 virtual int64 Size() OVERRIDE;
54 virtual base::Time LastModifiedTime() OVERRIDE;
55 virtual bool IsDirectory() OVERRIDE;
[email protected]7878ece2011-09-05 11:41:4956 };
[email protected]d5233ef42011-03-04 04:14:0457
[email protected]95af7372012-05-28 07:51:2058 virtual ~FileSystemFileUtil() {}
[email protected]d5233ef42011-03-04 04:14:0459
[email protected]65c337e02012-02-29 04:31:1060 // Creates or opens a file with the given flags.
[email protected]25b697992013-01-29 07:10:0561 // See header comments for AsyncFileUtil::CreateOrOpen() for more details.
[email protected]077c5dfd2013-11-02 01:41:1162 // This is used only by Pepper/NaCl File API.
[email protected]403ada82013-01-08 07:51:3963 virtual base::PlatformFileError CreateOrOpen(
[email protected]7878ece2011-09-05 11:41:4964 FileSystemOperationContext* context,
[email protected]949f25a2012-06-27 01:53:0965 const FileSystemURL& url,
[email protected]7878ece2011-09-05 11:41:4966 int file_flags,
[email protected]403ada82013-01-08 07:51:3967 base::PlatformFile* file_handle,
[email protected]95af7372012-05-28 07:51:2068 bool* created) = 0;
[email protected]3a7f4392011-04-26 12:21:5169
[email protected]65c337e02012-02-29 04:31:1070 // Closes the given file handle.
[email protected]077c5dfd2013-11-02 01:41:1171 // This is used only for Pepper/NaCl File API.
[email protected]403ada82013-01-08 07:51:3972 virtual base::PlatformFileError Close(
[email protected]7878ece2011-09-05 11:41:4973 FileSystemOperationContext* context,
[email protected]403ada82013-01-08 07:51:3974 base::PlatformFile file) = 0;
[email protected]7878ece2011-09-05 11:41:4975
[email protected]949f25a2012-06-27 01:53:0976 // Ensures that the given |url| exist. This creates a empty new file
77 // at |url| if the |url| does not exist.
[email protected]25b697992013-01-29 07:10:0578 // See header comments for AsyncFileUtil::EnsureFileExists() for more details.
[email protected]403ada82013-01-08 07:51:3979 virtual base::PlatformFileError EnsureFileExists(
[email protected]7878ece2011-09-05 11:41:4980 FileSystemOperationContext* context,
[email protected]949f25a2012-06-27 01:53:0981 const FileSystemURL& url, bool* created) = 0;
[email protected]7878ece2011-09-05 11:41:4982
[email protected]25b697992013-01-29 07:10:0583 // Creates directory at given url.
84 // See header comments for AsyncFileUtil::CreateDirectory() for more details.
[email protected]403ada82013-01-08 07:51:3985 virtual base::PlatformFileError CreateDirectory(
[email protected]7878ece2011-09-05 11:41:4986 FileSystemOperationContext* context,
[email protected]949f25a2012-06-27 01:53:0987 const FileSystemURL& url,
[email protected]7878ece2011-09-05 11:41:4988 bool exclusive,
[email protected]95af7372012-05-28 07:51:2089 bool recursive) = 0;
[email protected]7878ece2011-09-05 11:41:4990
[email protected]65c337e02012-02-29 04:31:1091 // Retrieves the information about a file.
[email protected]25b697992013-01-29 07:10:0592 // See header comments for AsyncFileUtil::GetFileInfo() for more details.
[email protected]403ada82013-01-08 07:51:3993 virtual base::PlatformFileError GetFileInfo(
[email protected]7878ece2011-09-05 11:41:4994 FileSystemOperationContext* context,
[email protected]949f25a2012-06-27 01:53:0995 const FileSystemURL& url,
[email protected]7878ece2011-09-05 11:41:4996 base::PlatformFileInfo* file_info,
[email protected]a3ef4832013-02-02 05:12:3397 base::FilePath* platform_path) = 0;
[email protected]7878ece2011-09-05 11:41:4998
[email protected]7878ece2011-09-05 11:41:4999 // 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]3a7f4392011-04-26 12:21:51103 //
[email protected]7878ece2011-09-05 11:41:49104 // The supplied context must remain valid at least lifetime of the enumerator
105 // instance.
[email protected]d109fcb2012-11-07 19:44:33106 virtual scoped_ptr<AbstractFileEnumerator> CreateFileEnumerator(
[email protected]7878ece2011-09-05 11:41:49107 FileSystemOperationContext* context,
[email protected]5453ca052013-04-11 21:15:39108 const FileSystemURL& root_url) = 0;
[email protected]7878ece2011-09-05 11:41:49109
[email protected]949f25a2012-06-27 01:53:09110 // Maps |file_system_url| given |context| into |local_file_path|
111 // which represents physical file location on the host OS.
[email protected]08f8feb2012-02-26 11:53:50112 // This may not always make sense for all subclasses.
[email protected]403ada82013-01-08 07:51:39113 virtual base::PlatformFileError GetLocalFilePath(
[email protected]7878ece2011-09-05 11:41:49114 FileSystemOperationContext* context,
[email protected]949f25a2012-06-27 01:53:09115 const FileSystemURL& file_system_url,
[email protected]a3ef4832013-02-02 05:12:33116 base::FilePath* local_file_path) = 0;
[email protected]3a7f4392011-04-26 12:21:51117
[email protected]25b697992013-01-29 07:10:05118 // Updates the file metadata information.
119 // See header comments for AsyncFileUtil::Touch() for more details.
[email protected]403ada82013-01-08 07:51:39120 virtual base::PlatformFileError Touch(
[email protected]d5233ef42011-03-04 04:14:04121 FileSystemOperationContext* context,
[email protected]949f25a2012-06-27 01:53:09122 const FileSystemURL& url,
[email protected]d5233ef42011-03-04 04:14:04123 const base::Time& last_access_time,
[email protected]95af7372012-05-28 07:51:20124 const base::Time& last_modified_time) = 0;
[email protected]d5233ef42011-03-04 04:14:04125
[email protected]25b697992013-01-29 07:10:05126 // Truncates a file to the given length.
127 // See header comments for AsyncFileUtil::Truncate() for more details.
[email protected]403ada82013-01-08 07:51:39128 virtual base::PlatformFileError Truncate(
[email protected]d5233ef42011-03-04 04:14:04129 FileSystemOperationContext* context,
[email protected]949f25a2012-06-27 01:53:09130 const FileSystemURL& url,
[email protected]95af7372012-05-28 07:51:20131 int64 length) = 0;
[email protected]d5233ef42011-03-04 04:14:04132
[email protected]949f25a2012-06-27 01:53:09133 // Copies or moves a single file from |src_url| to |dest_url|.
[email protected]bab213be2013-01-23 15:13:08134 // The filesystem type of |src_url| and |dest_url| MUST be same.
[email protected]824d3892013-09-25 13:00:30135 // For |option|, please see file_system_operation.h
[email protected]bab213be2013-01-23 15:13:08136 //
137 // This returns:
[email protected]aeba9c12013-01-28 10:44:42138 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url|
[email protected]bab213be2013-01-23 15:13:08139 // 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]403ada82013-01-08 07:51:39146 virtual base::PlatformFileError CopyOrMoveFile(
[email protected]172205b2011-08-30 03:36:44147 FileSystemOperationContext* context,
[email protected]949f25a2012-06-27 01:53:09148 const FileSystemURL& src_url,
149 const FileSystemURL& dest_url,
[email protected]824d3892013-09-25 13:00:30150 CopyOrMoveOption option,
[email protected]95af7372012-05-28 07:51:20151 bool copy) = 0;
[email protected]7878ece2011-09-05 11:41:49152
[email protected]949f25a2012-06-27 01:53:09153 // Copies in a single file from a different filesystem.
[email protected]25b697992013-01-29 07:10:05154 // See header comments for AsyncFileUtil::CopyInForeignFile() for
155 // more details.
[email protected]403ada82013-01-08 07:51:39156 virtual base::PlatformFileError CopyInForeignFile(
[email protected]7878ece2011-09-05 11:41:49157 FileSystemOperationContext* context,
[email protected]a3ef4832013-02-02 05:12:33158 const base::FilePath& src_file_path,
[email protected]949f25a2012-06-27 01:53:09159 const FileSystemURL& dest_url) = 0;
[email protected]7878ece2011-09-05 11:41:49160
161 // Deletes a single file.
[email protected]25b697992013-01-29 07:10:05162 // See header comments for AsyncFileUtil::DeleteFile() for more details.
[email protected]403ada82013-01-08 07:51:39163 virtual base::PlatformFileError DeleteFile(
[email protected]7878ece2011-09-05 11:41:49164 FileSystemOperationContext* context,
[email protected]949f25a2012-06-27 01:53:09165 const FileSystemURL& url) = 0;
[email protected]7878ece2011-09-05 11:41:49166
167 // Deletes a single empty directory.
[email protected]25b697992013-01-29 07:10:05168 // See header comments for AsyncFileUtil::DeleteDirectory() for more details.
[email protected]bab213be2013-01-23 15:13:08169 virtual base::PlatformFileError DeleteDirectory(
[email protected]7878ece2011-09-05 11:41:49170 FileSystemOperationContext* context,
[email protected]949f25a2012-06-27 01:53:09171 const FileSystemURL& url) = 0;
[email protected]cdba46992011-06-07 11:51:39172
[email protected]d0a1f0372012-07-19 11:17:37173 // 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]d0a1f0372012-07-19 11:17:37175 //
[email protected]25b697992013-01-29 07:10:05176 // See header comments for AsyncFileUtil::CreateSnapshotFile() for
177 // more details.
[email protected]7ab45cfa82013-04-26 07:13:20178 virtual webkit_blob::ScopedFile CreateSnapshotFile(
[email protected]826df822012-08-04 01:23:56179 FileSystemOperationContext* context,
180 const FileSystemURL& url,
[email protected]7ab45cfa82013-04-26 07:13:20181 base::PlatformFileError* error,
[email protected]826df822012-08-04 01:23:56182 base::PlatformFileInfo* file_info,
[email protected]7ab45cfa82013-04-26 07:13:20183 base::FilePath* platform_path) = 0;
[email protected]d0a1f0372012-07-19 11:17:37184
[email protected]8eb140ed2011-04-28 08:01:54185 protected:
[email protected]95af7372012-05-28 07:51:20186 FileSystemFileUtil() {}
[email protected]7878ece2011-09-05 11:41:49187
188 private:
[email protected]d5233ef42011-03-04 04:14:04189 DISALLOW_COPY_AND_ASSIGN(FileSystemFileUtil);
190};
191
192} // namespace fileapi
193
[email protected]5a20d042013-05-22 12:54:18194#endif // WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_