Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / chrome / browser / media_galleries / fileapi / native_media_file_util.h
blob778b72dd30d4d427079510322e870e68914513c1
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 CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_
6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/weak_ptr.h"
10 #include "storage/browser/fileapi/async_file_util.h"
12 namespace net {
13 class IOBuffer;
16 class MediaPathFilter;
18 // This class handles native file system operations with media type filtering.
19 // To support virtual file systems it implements the AsyncFileUtil interface
20 // from scratch and provides synchronous override points.
21 class NativeMediaFileUtil : public storage::AsyncFileUtil {
22 public:
23 explicit NativeMediaFileUtil(MediaPathFilter* media_path_filter);
24 ~NativeMediaFileUtil() override;
26 // Uses the MIME sniffer code, which actually looks into the file,
27 // to determine if it is really a media file (to avoid exposing
28 // non-media files with a media file extension.)
29 static base::File::Error IsMediaFile(const base::FilePath& path);
30 static base::File::Error BufferIsMediaHeader(net::IOBuffer* buf,
31 size_t length);
33 // Methods to support CreateOrOpen. Public so they can be shared with
34 // DeviceMediaAsyncFileUtil.
35 static void CreatedSnapshotFileForCreateOrOpen(
36 base::SequencedTaskRunner* media_task_runner,
37 int file_flags,
38 const storage::AsyncFileUtil::CreateOrOpenCallback& callback,
39 base::File::Error result,
40 const base::File::Info& file_info,
41 const base::FilePath& platform_path,
42 const scoped_refptr<storage::ShareableFileReference>& file_ref);
44 // AsyncFileUtil overrides.
45 void CreateOrOpen(scoped_ptr<storage::FileSystemOperationContext> context,
46 const storage::FileSystemURL& url,
47 int file_flags,
48 const CreateOrOpenCallback& callback) override;
49 void EnsureFileExists(scoped_ptr<storage::FileSystemOperationContext> context,
50 const storage::FileSystemURL& url,
51 const EnsureFileExistsCallback& callback) override;
52 void CreateDirectory(scoped_ptr<storage::FileSystemOperationContext> context,
53 const storage::FileSystemURL& url,
54 bool exclusive,
55 bool recursive,
56 const StatusCallback& callback) override;
57 void GetFileInfo(scoped_ptr<storage::FileSystemOperationContext> context,
58 const storage::FileSystemURL& url,
59 const GetFileInfoCallback& callback) override;
60 void ReadDirectory(scoped_ptr<storage::FileSystemOperationContext> context,
61 const storage::FileSystemURL& url,
62 const ReadDirectoryCallback& callback) override;
63 void Touch(scoped_ptr<storage::FileSystemOperationContext> context,
64 const storage::FileSystemURL& url,
65 const base::Time& last_access_time,
66 const base::Time& last_modified_time,
67 const StatusCallback& callback) override;
68 void Truncate(scoped_ptr<storage::FileSystemOperationContext> context,
69 const storage::FileSystemURL& url,
70 int64 length,
71 const StatusCallback& callback) override;
72 void CopyFileLocal(scoped_ptr<storage::FileSystemOperationContext> context,
73 const storage::FileSystemURL& src_url,
74 const storage::FileSystemURL& dest_url,
75 CopyOrMoveOption option,
76 const CopyFileProgressCallback& progress_callback,
77 const StatusCallback& callback) override;
78 void MoveFileLocal(scoped_ptr<storage::FileSystemOperationContext> context,
79 const storage::FileSystemURL& src_url,
80 const storage::FileSystemURL& dest_url,
81 CopyOrMoveOption option,
82 const StatusCallback& callback) override;
83 void CopyInForeignFile(
84 scoped_ptr<storage::FileSystemOperationContext> context,
85 const base::FilePath& src_file_path,
86 const storage::FileSystemURL& dest_url,
87 const StatusCallback& callback) override;
88 void DeleteFile(scoped_ptr<storage::FileSystemOperationContext> context,
89 const storage::FileSystemURL& url,
90 const StatusCallback& callback) override;
91 void DeleteDirectory(scoped_ptr<storage::FileSystemOperationContext> context,
92 const storage::FileSystemURL& url,
93 const StatusCallback& callback) override;
94 void DeleteRecursively(
95 scoped_ptr<storage::FileSystemOperationContext> context,
96 const storage::FileSystemURL& url,
97 const StatusCallback& callback) override;
98 void CreateSnapshotFile(
99 scoped_ptr<storage::FileSystemOperationContext> context,
100 const storage::FileSystemURL& url,
101 const CreateSnapshotFileCallback& callback) override;
103 protected:
104 virtual void CreateDirectoryOnTaskRunnerThread(
105 scoped_ptr<storage::FileSystemOperationContext> context,
106 const storage::FileSystemURL& url,
107 bool exclusive,
108 bool recursive,
109 const StatusCallback& callback);
110 virtual void GetFileInfoOnTaskRunnerThread(
111 scoped_ptr<storage::FileSystemOperationContext> context,
112 const storage::FileSystemURL& url,
113 const GetFileInfoCallback& callback);
114 virtual void ReadDirectoryOnTaskRunnerThread(
115 scoped_ptr<storage::FileSystemOperationContext> context,
116 const storage::FileSystemURL& url,
117 const ReadDirectoryCallback& callback);
118 virtual void CopyOrMoveFileLocalOnTaskRunnerThread(
119 scoped_ptr<storage::FileSystemOperationContext> context,
120 const storage::FileSystemURL& src_url,
121 const storage::FileSystemURL& dest_url,
122 CopyOrMoveOption option,
123 bool copy,
124 const StatusCallback& callback);
125 virtual void CopyInForeignFileOnTaskRunnerThread(
126 scoped_ptr<storage::FileSystemOperationContext> context,
127 const base::FilePath& src_file_path,
128 const storage::FileSystemURL& dest_url,
129 const StatusCallback& callback);
130 virtual void DeleteFileOnTaskRunnerThread(
131 scoped_ptr<storage::FileSystemOperationContext> context,
132 const storage::FileSystemURL& url,
133 const StatusCallback& callback);
134 virtual void DeleteDirectoryOnTaskRunnerThread(
135 scoped_ptr<storage::FileSystemOperationContext> context,
136 const storage::FileSystemURL& url,
137 const StatusCallback& callback);
138 virtual void CreateSnapshotFileOnTaskRunnerThread(
139 scoped_ptr<storage::FileSystemOperationContext> context,
140 const storage::FileSystemURL& url,
141 const CreateSnapshotFileCallback& callback);
143 // The following methods should only be called on the task runner thread.
145 // Necessary for copy/move to succeed.
146 virtual base::File::Error CreateDirectorySync(
147 storage::FileSystemOperationContext* context,
148 const storage::FileSystemURL& url,
149 bool exclusive,
150 bool recursive);
151 virtual base::File::Error CopyOrMoveFileSync(
152 storage::FileSystemOperationContext* context,
153 const storage::FileSystemURL& src_url,
154 const storage::FileSystemURL& dest_url,
155 CopyOrMoveOption option,
156 bool copy);
157 virtual base::File::Error CopyInForeignFileSync(
158 storage::FileSystemOperationContext* context,
159 const base::FilePath& src_file_path,
160 const storage::FileSystemURL& dest_url);
161 virtual base::File::Error GetFileInfoSync(
162 storage::FileSystemOperationContext* context,
163 const storage::FileSystemURL& url,
164 base::File::Info* file_info,
165 base::FilePath* platform_path);
166 // Called by GetFileInfoSync. Meant to be overridden by subclasses that
167 // have special mappings from URLs to platform paths (virtual filesystems).
168 virtual base::File::Error GetLocalFilePath(
169 storage::FileSystemOperationContext* context,
170 const storage::FileSystemURL& file_system_url,
171 base::FilePath* local_file_path);
172 virtual base::File::Error ReadDirectorySync(
173 storage::FileSystemOperationContext* context,
174 const storage::FileSystemURL& url,
175 EntryList* file_list);
176 virtual base::File::Error DeleteFileSync(
177 storage::FileSystemOperationContext* context,
178 const storage::FileSystemURL& url);
179 // Necessary for move to succeed.
180 virtual base::File::Error DeleteDirectorySync(
181 storage::FileSystemOperationContext* context,
182 const storage::FileSystemURL& url);
183 virtual base::File::Error CreateSnapshotFileSync(
184 storage::FileSystemOperationContext* context,
185 const storage::FileSystemURL& url,
186 base::File::Info* file_info,
187 base::FilePath* platform_path,
188 scoped_refptr<storage::ShareableFileReference>* file_ref);
190 MediaPathFilter* media_path_filter() {
191 return media_path_filter_;
194 private:
195 // Like GetLocalFilePath(), but always take media_path_filter() into
196 // consideration. If the media_path_filter() check fails, return
197 // Fila::FILE_ERROR_SECURITY. |local_file_path| does not have to exist.
198 base::File::Error GetFilteredLocalFilePath(
199 storage::FileSystemOperationContext* context,
200 const storage::FileSystemURL& file_system_url,
201 base::FilePath* local_file_path);
203 // Like GetLocalFilePath(), but if the file does not exist, then return
204 // |failure_error|.
205 // If |local_file_path| is a file, then take media_path_filter() into
206 // consideration.
207 // If the media_path_filter() check fails, return |failure_error|.
208 // If |local_file_path| is a directory, return File::FILE_OK.
209 base::File::Error GetFilteredLocalFilePathForExistingFileOrDirectory(
210 storage::FileSystemOperationContext* context,
211 const storage::FileSystemURL& file_system_url,
212 base::File::Error failure_error,
213 base::FilePath* local_file_path);
215 // Not owned, owned by the backend which owns this.
216 MediaPathFilter* const media_path_filter_;
218 base::WeakPtrFactory<NativeMediaFileUtil> weak_factory_;
220 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtil);
223 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_