OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ | 5 #ifndef CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ |
6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ | 6 #define CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/memory/weak_ptr.h" | 9 #include "base/memory/weak_ptr.h" |
10 #include "webkit/browser/fileapi/async_file_util.h" | 10 #include "webkit/browser/fileapi/async_file_util.h" |
11 | 11 |
12 namespace net { | 12 namespace net { |
13 class IOBuffer; | 13 class IOBuffer; |
14 } | 14 } |
15 | 15 |
16 class MediaPathFilter; | 16 class MediaPathFilter; |
17 | 17 |
18 // This class handles native file system operations with media type filtering. | 18 // This class handles native file system operations with media type filtering. |
19 // To support virtual file systems it implements the AsyncFileUtil interface | 19 // To support virtual file systems it implements the AsyncFileUtil interface |
20 // from scratch and provides synchronous override points. | 20 // from scratch and provides synchronous override points. |
21 class NativeMediaFileUtil : public fileapi::AsyncFileUtil { | 21 class NativeMediaFileUtil : public fileapi::AsyncFileUtil { |
22 public: | 22 public: |
23 explicit NativeMediaFileUtil(MediaPathFilter* media_path_filter); | 23 explicit NativeMediaFileUtil(MediaPathFilter* media_path_filter); |
24 virtual ~NativeMediaFileUtil(); | 24 virtual ~NativeMediaFileUtil(); |
25 | 25 |
26 // Uses the MIME sniffer code, which actually looks into the file, | 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 | 27 // to determine if it is really a media file (to avoid exposing |
28 // non-media files with a media file extension.) | 28 // non-media files with a media file extension.) |
29 static base::PlatformFileError IsMediaFile(const base::FilePath& path); | 29 static base::File::Error IsMediaFile(const base::FilePath& path); |
30 static base::PlatformFileError BufferIsMediaHeader(net::IOBuffer* buf, | 30 static base::File::Error BufferIsMediaHeader(net::IOBuffer* buf, |
31 size_t length); | 31 size_t length); |
32 | 32 |
33 // AsyncFileUtil overrides. | 33 // AsyncFileUtil overrides. |
34 virtual void CreateOrOpen( | 34 virtual void CreateOrOpen( |
35 scoped_ptr<fileapi::FileSystemOperationContext> context, | 35 scoped_ptr<fileapi::FileSystemOperationContext> context, |
36 const fileapi::FileSystemURL& url, | 36 const fileapi::FileSystemURL& url, |
37 int file_flags, | 37 int file_flags, |
38 const CreateOrOpenCallback& callback) OVERRIDE; | 38 const CreateOrOpenCallback& callback) OVERRIDE; |
39 virtual void EnsureFileExists( | 39 virtual void EnsureFileExists( |
40 scoped_ptr<fileapi::FileSystemOperationContext> context, | 40 scoped_ptr<fileapi::FileSystemOperationContext> context, |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 const fileapi::FileSystemURL& url, | 136 const fileapi::FileSystemURL& url, |
137 const StatusCallback& callback); | 137 const StatusCallback& callback); |
138 virtual void CreateSnapshotFileOnTaskRunnerThread( | 138 virtual void CreateSnapshotFileOnTaskRunnerThread( |
139 scoped_ptr<fileapi::FileSystemOperationContext> context, | 139 scoped_ptr<fileapi::FileSystemOperationContext> context, |
140 const fileapi::FileSystemURL& url, | 140 const fileapi::FileSystemURL& url, |
141 const CreateSnapshotFileCallback& callback); | 141 const CreateSnapshotFileCallback& callback); |
142 | 142 |
143 // The following methods should only be called on the task runner thread. | 143 // The following methods should only be called on the task runner thread. |
144 | 144 |
145 // Necessary for copy/move to succeed. | 145 // Necessary for copy/move to succeed. |
146 virtual base::PlatformFileError CreateDirectorySync( | 146 virtual base::File::Error CreateDirectorySync( |
147 fileapi::FileSystemOperationContext* context, | 147 fileapi::FileSystemOperationContext* context, |
148 const fileapi::FileSystemURL& url, | 148 const fileapi::FileSystemURL& url, |
149 bool exclusive, | 149 bool exclusive, |
150 bool recursive); | 150 bool recursive); |
151 virtual base::PlatformFileError CopyOrMoveFileSync( | 151 virtual base::File::Error CopyOrMoveFileSync( |
152 fileapi::FileSystemOperationContext* context, | 152 fileapi::FileSystemOperationContext* context, |
153 const fileapi::FileSystemURL& src_url, | 153 const fileapi::FileSystemURL& src_url, |
154 const fileapi::FileSystemURL& dest_url, | 154 const fileapi::FileSystemURL& dest_url, |
155 CopyOrMoveOption option, | 155 CopyOrMoveOption option, |
156 bool copy); | 156 bool copy); |
157 virtual base::PlatformFileError CopyInForeignFileSync( | 157 virtual base::File::Error CopyInForeignFileSync( |
158 fileapi::FileSystemOperationContext* context, | 158 fileapi::FileSystemOperationContext* context, |
159 const base::FilePath& src_file_path, | 159 const base::FilePath& src_file_path, |
160 const fileapi::FileSystemURL& dest_url); | 160 const fileapi::FileSystemURL& dest_url); |
161 virtual base::PlatformFileError GetFileInfoSync( | 161 virtual base::File::Error GetFileInfoSync( |
162 fileapi::FileSystemOperationContext* context, | 162 fileapi::FileSystemOperationContext* context, |
163 const fileapi::FileSystemURL& url, | 163 const fileapi::FileSystemURL& url, |
164 base::PlatformFileInfo* file_info, | 164 base::File::Info* file_info, |
165 base::FilePath* platform_path); | 165 base::FilePath* platform_path); |
166 // Called by GetFileInfoSync. Meant to be overridden by subclasses that | 166 // Called by GetFileInfoSync. Meant to be overridden by subclasses that |
167 // have special mappings from URLs to platform paths (virtual filesystems). | 167 // have special mappings from URLs to platform paths (virtual filesystems). |
168 virtual base::PlatformFileError GetLocalFilePath( | 168 virtual base::File::Error GetLocalFilePath( |
169 fileapi::FileSystemOperationContext* context, | 169 fileapi::FileSystemOperationContext* context, |
170 const fileapi::FileSystemURL& file_system_url, | 170 const fileapi::FileSystemURL& file_system_url, |
171 base::FilePath* local_file_path); | 171 base::FilePath* local_file_path); |
172 virtual base::PlatformFileError ReadDirectorySync( | 172 virtual base::File::Error ReadDirectorySync( |
173 fileapi::FileSystemOperationContext* context, | 173 fileapi::FileSystemOperationContext* context, |
174 const fileapi::FileSystemURL& url, | 174 const fileapi::FileSystemURL& url, |
175 EntryList* file_list); | 175 EntryList* file_list); |
176 virtual base::PlatformFileError DeleteFileSync( | 176 virtual base::File::Error DeleteFileSync( |
177 fileapi::FileSystemOperationContext* context, | 177 fileapi::FileSystemOperationContext* context, |
178 const fileapi::FileSystemURL& url); | 178 const fileapi::FileSystemURL& url); |
179 // Necessary for move to succeed. | 179 // Necessary for move to succeed. |
180 virtual base::PlatformFileError DeleteDirectorySync( | 180 virtual base::File::Error DeleteDirectorySync( |
181 fileapi::FileSystemOperationContext* context, | 181 fileapi::FileSystemOperationContext* context, |
182 const fileapi::FileSystemURL& url); | 182 const fileapi::FileSystemURL& url); |
183 virtual base::PlatformFileError CreateSnapshotFileSync( | 183 virtual base::File::Error CreateSnapshotFileSync( |
184 fileapi::FileSystemOperationContext* context, | 184 fileapi::FileSystemOperationContext* context, |
185 const fileapi::FileSystemURL& url, | 185 const fileapi::FileSystemURL& url, |
186 base::PlatformFileInfo* file_info, | 186 base::File::Info* file_info, |
187 base::FilePath* platform_path, | 187 base::FilePath* platform_path, |
188 scoped_refptr<webkit_blob::ShareableFileReference>* file_ref); | 188 scoped_refptr<webkit_blob::ShareableFileReference>* file_ref); |
189 | 189 |
190 protected: | 190 protected: |
191 MediaPathFilter* media_path_filter() { | 191 MediaPathFilter* media_path_filter() { |
192 return media_path_filter_; | 192 return media_path_filter_; |
193 } | 193 } |
194 | 194 |
195 private: | 195 private: |
196 // Like GetLocalFilePath(), but always take media_path_filter() into | 196 // Like GetLocalFilePath(), but always take media_path_filter() into |
197 // consideration. If the media_path_filter() check fails, return | 197 // consideration. If the media_path_filter() check fails, return |
198 // PLATFORM_FILE_ERROR_SECURITY. |local_file_path| does not have to exist. | 198 // PLATFORM_FILE_ERROR_SECURITY. |local_file_path| does not have to exist. |
199 base::PlatformFileError GetFilteredLocalFilePath( | 199 base::File::Error GetFilteredLocalFilePath( |
200 fileapi::FileSystemOperationContext* context, | 200 fileapi::FileSystemOperationContext* context, |
201 const fileapi::FileSystemURL& file_system_url, | 201 const fileapi::FileSystemURL& file_system_url, |
202 base::FilePath* local_file_path); | 202 base::FilePath* local_file_path); |
203 | 203 |
204 // Like GetLocalFilePath(), but if the file does not exist, then return | 204 // Like GetLocalFilePath(), but if the file does not exist, then return |
205 // |failure_error|. | 205 // |failure_error|. |
206 // If |local_file_path| is a file, then take media_path_filter() into | 206 // If |local_file_path| is a file, then take media_path_filter() into |
207 // consideration. | 207 // consideration. |
208 // If the media_path_filter() check fails, return |failure_error|. | 208 // If the media_path_filter() check fails, return |failure_error|. |
209 // If |local_file_path| is a directory, return PLATFORM_FILE_OK. | 209 // If |local_file_path| is a directory, return PLATFORM_FILE_OK. |
210 base::PlatformFileError GetFilteredLocalFilePathForExistingFileOrDirectory( | 210 base::File::Error GetFilteredLocalFilePathForExistingFileOrDirectory( |
211 fileapi::FileSystemOperationContext* context, | 211 fileapi::FileSystemOperationContext* context, |
212 const fileapi::FileSystemURL& file_system_url, | 212 const fileapi::FileSystemURL& file_system_url, |
213 base::PlatformFileError failure_error, | 213 base::File::Error failure_error, |
214 base::FilePath* local_file_path); | 214 base::FilePath* local_file_path); |
215 | 215 |
216 | 216 |
217 // Not owned, owned by the backend which owns this. | 217 // Not owned, owned by the backend which owns this. |
218 MediaPathFilter* media_path_filter_; | 218 MediaPathFilter* media_path_filter_; |
219 | 219 |
220 base::WeakPtrFactory<NativeMediaFileUtil> weak_factory_; | 220 base::WeakPtrFactory<NativeMediaFileUtil> weak_factory_; |
221 | 221 |
222 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtil); | 222 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtil); |
223 }; | 223 }; |
224 | 224 |
225 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ | 225 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ |
OLD | NEW |