Add entry to histograms.xml for OverlyLargeOriginLength.
[chromium-blink-merge.git] / webkit / browser / fileapi / file_system_file_util.h
blob5a4d730b5c8beee0c6c712b6adbee4fea19341b0
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
3 // found in the LICENSE file.
5 #ifndef WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_
6 #define WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_
8 #include "base/files/file_path.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "base/platform_file.h"
11 #include "webkit/browser/fileapi/file_system_operation.h"
12 #include "webkit/browser/webkit_storage_browser_export.h"
13 #include "webkit/common/blob/scoped_file.h"
15 namespace base {
16 class Time;
19 namespace fileapi {
21 class FileSystemOperationContext;
22 class FileSystemURL;
24 // A file utility interface that provides basic file utility methods for
25 // FileSystem API.
27 // Layering structure of the FileSystemFileUtil was split out.
28 // See http://crbug.com/128136 if you need it.
29 class WEBKIT_STORAGE_BROWSER_EXPORT FileSystemFileUtil {
30 public:
31 typedef FileSystemOperation::CopyOrMoveOption CopyOrMoveOption;
33 // It will be implemented by each subclass such as FileSystemFileEnumerator.
34 class WEBKIT_STORAGE_BROWSER_EXPORT AbstractFileEnumerator {
35 public:
36 virtual ~AbstractFileEnumerator() {}
38 // Returns an empty string if there are no more results.
39 virtual base::FilePath Next() = 0;
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.
45 virtual int64 Size() = 0;
46 virtual base::Time LastModifiedTime() = 0;
47 virtual bool IsDirectory() = 0;
50 class WEBKIT_STORAGE_BROWSER_EXPORT EmptyFileEnumerator
51 : public AbstractFileEnumerator {
52 virtual base::FilePath Next() OVERRIDE;
53 virtual int64 Size() OVERRIDE;
54 virtual base::Time LastModifiedTime() OVERRIDE;
55 virtual bool IsDirectory() OVERRIDE;
58 virtual ~FileSystemFileUtil() {}
60 // Creates or opens a file with the given flags.
61 // See header comments for AsyncFileUtil::CreateOrOpen() for more details.
62 // This is used only by Pepper/NaCl File API.
63 virtual base::PlatformFileError CreateOrOpen(
64 FileSystemOperationContext* context,
65 const FileSystemURL& url,
66 int file_flags,
67 base::PlatformFile* file_handle,
68 bool* created) = 0;
70 // Closes the given file handle.
71 // This is used only for Pepper/NaCl File API.
72 virtual base::PlatformFileError Close(
73 FileSystemOperationContext* context,
74 base::PlatformFile file) = 0;
76 // Ensures that the given |url| exist. This creates a empty new file
77 // at |url| if the |url| does not exist.
78 // See header comments for AsyncFileUtil::EnsureFileExists() for more details.
79 virtual base::PlatformFileError EnsureFileExists(
80 FileSystemOperationContext* context,
81 const FileSystemURL& url, bool* created) = 0;
83 // Creates directory at given url.
84 // See header comments for AsyncFileUtil::CreateDirectory() for more details.
85 virtual base::PlatformFileError CreateDirectory(
86 FileSystemOperationContext* context,
87 const FileSystemURL& url,
88 bool exclusive,
89 bool recursive) = 0;
91 // Retrieves the information about a file.
92 // See header comments for AsyncFileUtil::GetFileInfo() for more details.
93 virtual base::PlatformFileError GetFileInfo(
94 FileSystemOperationContext* context,
95 const FileSystemURL& url,
96 base::PlatformFileInfo* file_info,
97 base::FilePath* platform_path) = 0;
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.
104 // The supplied context must remain valid at least lifetime of the enumerator
105 // instance.
106 virtual scoped_ptr<AbstractFileEnumerator> CreateFileEnumerator(
107 FileSystemOperationContext* context,
108 const FileSystemURL& root_url) = 0;
110 // Maps |file_system_url| given |context| into |local_file_path|
111 // which represents physical file location on the host OS.
112 // This may not always make sense for all subclasses.
113 virtual base::PlatformFileError GetLocalFilePath(
114 FileSystemOperationContext* context,
115 const FileSystemURL& file_system_url,
116 base::FilePath* local_file_path) = 0;
118 // Updates the file metadata information.
119 // See header comments for AsyncFileUtil::Touch() for more details.
120 virtual base::PlatformFileError Touch(
121 FileSystemOperationContext* context,
122 const FileSystemURL& url,
123 const base::Time& last_access_time,
124 const base::Time& last_modified_time) = 0;
126 // Truncates a file to the given length.
127 // See header comments for AsyncFileUtil::Truncate() for more details.
128 virtual base::PlatformFileError Truncate(
129 FileSystemOperationContext* context,
130 const FileSystemURL& url,
131 int64 length) = 0;
133 // Copies or moves a single file from |src_url| to |dest_url|.
134 // The filesystem type of |src_url| and |dest_url| MUST be same.
135 // For |option|, please see file_system_operation.h
137 // This returns:
138 // - PLATFORM_FILE_ERROR_NOT_FOUND if |src_url|
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.
146 virtual base::PlatformFileError CopyOrMoveFile(
147 FileSystemOperationContext* context,
148 const FileSystemURL& src_url,
149 const FileSystemURL& dest_url,
150 CopyOrMoveOption option,
151 bool copy) = 0;
153 // Copies in a single file from a different filesystem.
154 // See header comments for AsyncFileUtil::CopyInForeignFile() for
155 // more details.
156 virtual base::PlatformFileError CopyInForeignFile(
157 FileSystemOperationContext* context,
158 const base::FilePath& src_file_path,
159 const FileSystemURL& dest_url) = 0;
161 // Deletes a single file.
162 // See header comments for AsyncFileUtil::DeleteFile() for more details.
163 virtual base::PlatformFileError DeleteFile(
164 FileSystemOperationContext* context,
165 const FileSystemURL& url) = 0;
167 // Deletes a single empty directory.
168 // See header comments for AsyncFileUtil::DeleteDirectory() for more details.
169 virtual base::PlatformFileError DeleteDirectory(
170 FileSystemOperationContext* context,
171 const FileSystemURL& url) = 0;
173 // Creates a local snapshot file for a given |url| and returns the
174 // metadata and platform path of the snapshot file via |callback|.
176 // See header comments for AsyncFileUtil::CreateSnapshotFile() for
177 // more details.
178 virtual webkit_blob::ScopedFile CreateSnapshotFile(
179 FileSystemOperationContext* context,
180 const FileSystemURL& url,
181 base::PlatformFileError* error,
182 base::PlatformFileInfo* file_info,
183 base::FilePath* platform_path) = 0;
185 protected:
186 FileSystemFileUtil() {}
188 private:
189 DISALLOW_COPY_AND_ASSIGN(FileSystemFileUtil);
192 } // namespace fileapi
194 #endif // WEBKIT_BROWSER_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_