Don't preload rarely seen large images
[chromium-blink-merge.git] / storage / browser / fileapi / file_system_file_util.h
blob48a127a6a0029fff21c54baeea38ae3bfdf3ac6c
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 STORAGE_BROWSER_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_
6 #define STORAGE_BROWSER_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_
8 #include "base/files/file.h"
9 #include "base/files/file_path.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "storage/browser/blob/scoped_file.h"
12 #include "storage/browser/fileapi/file_system_operation.h"
13 #include "storage/browser/storage_browser_export.h"
15 namespace base {
16 class Time;
19 namespace storage {
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 STORAGE_EXPORT FileSystemFileUtil {
30 public:
31 typedef FileSystemOperation::CopyOrMoveOption CopyOrMoveOption;
33 // It will be implemented by each subclass such as FileSystemFileEnumerator.
34 class STORAGE_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 STORAGE_EXPORT EmptyFileEnumerator
51 : public AbstractFileEnumerator {
52 base::FilePath Next() override;
53 int64 Size() override;
54 base::Time LastModifiedTime() override;
55 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::File CreateOrOpen(
64 FileSystemOperationContext* context,
65 const FileSystemURL& url,
66 int file_flags) = 0;
68 // Ensures that the given |url| exist. This creates a empty new file
69 // at |url| if the |url| does not exist.
70 // See header comments for AsyncFileUtil::EnsureFileExists() for more details.
71 virtual base::File::Error EnsureFileExists(
72 FileSystemOperationContext* context,
73 const FileSystemURL& url, bool* created) = 0;
75 // Creates directory at given url.
76 // See header comments for AsyncFileUtil::CreateDirectory() for more details.
77 virtual base::File::Error CreateDirectory(
78 FileSystemOperationContext* context,
79 const FileSystemURL& url,
80 bool exclusive,
81 bool recursive) = 0;
83 // Retrieves the information about a file.
84 // See header comments for AsyncFileUtil::GetFileInfo() for more details.
85 virtual base::File::Error GetFileInfo(
86 FileSystemOperationContext* context,
87 const FileSystemURL& url,
88 base::File::Info* file_info,
89 base::FilePath* platform_path) = 0;
91 // Returns a pointer to a new instance of AbstractFileEnumerator which is
92 // implemented for each FileSystemFileUtil subclass. The instance needs to be
93 // freed by the caller, and its lifetime should not extend past when the
94 // current call returns to the main FILE message loop.
96 // The supplied context must remain valid at least lifetime of the enumerator
97 // instance.
98 virtual scoped_ptr<AbstractFileEnumerator> CreateFileEnumerator(
99 FileSystemOperationContext* context,
100 const FileSystemURL& root_url) = 0;
102 // Maps |file_system_url| given |context| into |local_file_path|
103 // which represents physical file location on the host OS.
104 // This may not always make sense for all subclasses.
105 virtual base::File::Error GetLocalFilePath(
106 FileSystemOperationContext* context,
107 const FileSystemURL& file_system_url,
108 base::FilePath* local_file_path) = 0;
110 // Updates the file metadata information.
111 // See header comments for AsyncFileUtil::Touch() for more details.
112 virtual base::File::Error Touch(
113 FileSystemOperationContext* context,
114 const FileSystemURL& url,
115 const base::Time& last_access_time,
116 const base::Time& last_modified_time) = 0;
118 // Truncates a file to the given length.
119 // See header comments for AsyncFileUtil::Truncate() for more details.
120 virtual base::File::Error Truncate(
121 FileSystemOperationContext* context,
122 const FileSystemURL& url,
123 int64 length) = 0;
125 // Copies or moves a single file from |src_url| to |dest_url|.
126 // The filesystem type of |src_url| and |dest_url| MUST be same.
127 // For |option|, please see file_system_operation.h
129 // This returns:
130 // - File::FILE_ERROR_NOT_FOUND if |src_url|
131 // or the parent directory of |dest_url| does not exist.
132 // - File::FILE_ERROR_NOT_A_FILE if |src_url| exists but is not a file.
133 // - File::FILE_ERROR_INVALID_OPERATION if |dest_url| exists and
134 // is not a file.
135 // - File::FILE_ERROR_FAILED if |dest_url| does not exist and
136 // its parent path is a file.
138 virtual base::File::Error CopyOrMoveFile(
139 FileSystemOperationContext* context,
140 const FileSystemURL& src_url,
141 const FileSystemURL& dest_url,
142 CopyOrMoveOption option,
143 bool copy) = 0;
145 // Copies in a single file from a different filesystem.
146 // See header comments for AsyncFileUtil::CopyInForeignFile() for
147 // more details.
148 virtual base::File::Error CopyInForeignFile(
149 FileSystemOperationContext* context,
150 const base::FilePath& src_file_path,
151 const FileSystemURL& dest_url) = 0;
153 // Deletes a single file.
154 // See header comments for AsyncFileUtil::DeleteFile() for more details.
155 virtual base::File::Error DeleteFile(
156 FileSystemOperationContext* context,
157 const FileSystemURL& url) = 0;
159 // Deletes a single empty directory.
160 // See header comments for AsyncFileUtil::DeleteDirectory() for more details.
161 virtual base::File::Error DeleteDirectory(
162 FileSystemOperationContext* context,
163 const FileSystemURL& url) = 0;
165 // Creates a local snapshot file for a given |url| and returns the
166 // metadata and platform path of the snapshot file via |callback|.
168 // See header comments for AsyncFileUtil::CreateSnapshotFile() for
169 // more details.
170 virtual storage::ScopedFile CreateSnapshotFile(
171 FileSystemOperationContext* context,
172 const FileSystemURL& url,
173 base::File::Error* error,
174 base::File::Info* file_info,
175 base::FilePath* platform_path) = 0;
177 protected:
178 FileSystemFileUtil() {}
180 private:
181 DISALLOW_COPY_AND_ASSIGN(FileSystemFileUtil);
184 } // namespace storage
186 #endif // STORAGE_BROWSER_FILEAPI_FILE_SYSTEM_FILE_UTIL_H_