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 "storage/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 storage::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::File::Error IsMediaFile(const base::FilePath& path); | 29 static base::File::Error IsMediaFile(const base::FilePath& path); |
30 static base::File::Error BufferIsMediaHeader(net::IOBuffer* buf, | 30 static base::File::Error BufferIsMediaHeader(net::IOBuffer* buf, |
31 size_t length); | 31 size_t length); |
32 | 32 |
33 // Methods to support CreateOrOpen. Public so they can be shared with | 33 // Methods to support CreateOrOpen. Public so they can be shared with |
34 // DeviceMediaAsyncFileUtil. | 34 // DeviceMediaAsyncFileUtil. |
35 static void CreatedSnapshotFileForCreateOrOpen( | 35 static void CreatedSnapshotFileForCreateOrOpen( |
36 base::SequencedTaskRunner* media_task_runner, | 36 base::SequencedTaskRunner* media_task_runner, |
37 int file_flags, | 37 int file_flags, |
38 const fileapi::AsyncFileUtil::CreateOrOpenCallback& callback, | 38 const storage::AsyncFileUtil::CreateOrOpenCallback& callback, |
39 base::File::Error result, | 39 base::File::Error result, |
40 const base::File::Info& file_info, | 40 const base::File::Info& file_info, |
41 const base::FilePath& platform_path, | 41 const base::FilePath& platform_path, |
42 const scoped_refptr<webkit_blob::ShareableFileReference>& file_ref); | 42 const scoped_refptr<storage::ShareableFileReference>& file_ref); |
43 | 43 |
44 // AsyncFileUtil overrides. | 44 // AsyncFileUtil overrides. |
45 virtual void CreateOrOpen( | 45 virtual void CreateOrOpen( |
46 scoped_ptr<fileapi::FileSystemOperationContext> context, | 46 scoped_ptr<storage::FileSystemOperationContext> context, |
47 const fileapi::FileSystemURL& url, | 47 const storage::FileSystemURL& url, |
48 int file_flags, | 48 int file_flags, |
49 const CreateOrOpenCallback& callback) OVERRIDE; | 49 const CreateOrOpenCallback& callback) OVERRIDE; |
50 virtual void EnsureFileExists( | 50 virtual void EnsureFileExists( |
51 scoped_ptr<fileapi::FileSystemOperationContext> context, | 51 scoped_ptr<storage::FileSystemOperationContext> context, |
52 const fileapi::FileSystemURL& url, | 52 const storage::FileSystemURL& url, |
53 const EnsureFileExistsCallback& callback) OVERRIDE; | 53 const EnsureFileExistsCallback& callback) OVERRIDE; |
54 virtual void CreateDirectory( | 54 virtual void CreateDirectory( |
55 scoped_ptr<fileapi::FileSystemOperationContext> context, | 55 scoped_ptr<storage::FileSystemOperationContext> context, |
56 const fileapi::FileSystemURL& url, | 56 const storage::FileSystemURL& url, |
57 bool exclusive, | 57 bool exclusive, |
58 bool recursive, | 58 bool recursive, |
59 const StatusCallback& callback) OVERRIDE; | 59 const StatusCallback& callback) OVERRIDE; |
60 virtual void GetFileInfo( | 60 virtual void GetFileInfo( |
61 scoped_ptr<fileapi::FileSystemOperationContext> context, | 61 scoped_ptr<storage::FileSystemOperationContext> context, |
62 const fileapi::FileSystemURL& url, | 62 const storage::FileSystemURL& url, |
63 const GetFileInfoCallback& callback) OVERRIDE; | 63 const GetFileInfoCallback& callback) OVERRIDE; |
64 virtual void ReadDirectory( | 64 virtual void ReadDirectory( |
65 scoped_ptr<fileapi::FileSystemOperationContext> context, | 65 scoped_ptr<storage::FileSystemOperationContext> context, |
66 const fileapi::FileSystemURL& url, | 66 const storage::FileSystemURL& url, |
67 const ReadDirectoryCallback& callback) OVERRIDE; | 67 const ReadDirectoryCallback& callback) OVERRIDE; |
68 virtual void Touch( | 68 virtual void Touch(scoped_ptr<storage::FileSystemOperationContext> context, |
69 scoped_ptr<fileapi::FileSystemOperationContext> context, | 69 const storage::FileSystemURL& url, |
70 const fileapi::FileSystemURL& url, | 70 const base::Time& last_access_time, |
71 const base::Time& last_access_time, | 71 const base::Time& last_modified_time, |
72 const base::Time& last_modified_time, | 72 const StatusCallback& callback) OVERRIDE; |
73 const StatusCallback& callback) OVERRIDE; | 73 virtual void Truncate(scoped_ptr<storage::FileSystemOperationContext> context, |
74 virtual void Truncate( | 74 const storage::FileSystemURL& url, |
75 scoped_ptr<fileapi::FileSystemOperationContext> context, | 75 int64 length, |
76 const fileapi::FileSystemURL& url, | 76 const StatusCallback& callback) OVERRIDE; |
77 int64 length, | |
78 const StatusCallback& callback) OVERRIDE; | |
79 virtual void CopyFileLocal( | 77 virtual void CopyFileLocal( |
80 scoped_ptr<fileapi::FileSystemOperationContext> context, | 78 scoped_ptr<storage::FileSystemOperationContext> context, |
81 const fileapi::FileSystemURL& src_url, | 79 const storage::FileSystemURL& src_url, |
82 const fileapi::FileSystemURL& dest_url, | 80 const storage::FileSystemURL& dest_url, |
83 CopyOrMoveOption option, | 81 CopyOrMoveOption option, |
84 const CopyFileProgressCallback& progress_callback, | 82 const CopyFileProgressCallback& progress_callback, |
85 const StatusCallback& callback) OVERRIDE; | 83 const StatusCallback& callback) OVERRIDE; |
86 virtual void MoveFileLocal( | 84 virtual void MoveFileLocal( |
87 scoped_ptr<fileapi::FileSystemOperationContext> context, | 85 scoped_ptr<storage::FileSystemOperationContext> context, |
88 const fileapi::FileSystemURL& src_url, | 86 const storage::FileSystemURL& src_url, |
89 const fileapi::FileSystemURL& dest_url, | 87 const storage::FileSystemURL& dest_url, |
90 CopyOrMoveOption option, | 88 CopyOrMoveOption option, |
91 const StatusCallback& callback) OVERRIDE; | 89 const StatusCallback& callback) OVERRIDE; |
92 virtual void CopyInForeignFile( | 90 virtual void CopyInForeignFile( |
93 scoped_ptr<fileapi::FileSystemOperationContext> context, | 91 scoped_ptr<storage::FileSystemOperationContext> context, |
94 const base::FilePath& src_file_path, | 92 const base::FilePath& src_file_path, |
95 const fileapi::FileSystemURL& dest_url, | 93 const storage::FileSystemURL& dest_url, |
96 const StatusCallback& callback) OVERRIDE; | 94 const StatusCallback& callback) OVERRIDE; |
97 virtual void DeleteFile( | 95 virtual void DeleteFile( |
98 scoped_ptr<fileapi::FileSystemOperationContext> context, | 96 scoped_ptr<storage::FileSystemOperationContext> context, |
99 const fileapi::FileSystemURL& url, | 97 const storage::FileSystemURL& url, |
100 const StatusCallback& callback) OVERRIDE; | 98 const StatusCallback& callback) OVERRIDE; |
101 virtual void DeleteDirectory( | 99 virtual void DeleteDirectory( |
102 scoped_ptr<fileapi::FileSystemOperationContext> context, | 100 scoped_ptr<storage::FileSystemOperationContext> context, |
103 const fileapi::FileSystemURL& url, | 101 const storage::FileSystemURL& url, |
104 const StatusCallback& callback) OVERRIDE; | 102 const StatusCallback& callback) OVERRIDE; |
105 virtual void DeleteRecursively( | 103 virtual void DeleteRecursively( |
106 scoped_ptr<fileapi::FileSystemOperationContext> context, | 104 scoped_ptr<storage::FileSystemOperationContext> context, |
107 const fileapi::FileSystemURL& url, | 105 const storage::FileSystemURL& url, |
108 const StatusCallback& callback) OVERRIDE; | 106 const StatusCallback& callback) OVERRIDE; |
109 virtual void CreateSnapshotFile( | 107 virtual void CreateSnapshotFile( |
110 scoped_ptr<fileapi::FileSystemOperationContext> context, | 108 scoped_ptr<storage::FileSystemOperationContext> context, |
111 const fileapi::FileSystemURL& url, | 109 const storage::FileSystemURL& url, |
112 const CreateSnapshotFileCallback& callback) OVERRIDE; | 110 const CreateSnapshotFileCallback& callback) OVERRIDE; |
113 | 111 |
114 protected: | 112 protected: |
115 virtual void CreateDirectoryOnTaskRunnerThread( | 113 virtual void CreateDirectoryOnTaskRunnerThread( |
116 scoped_ptr<fileapi::FileSystemOperationContext> context, | 114 scoped_ptr<storage::FileSystemOperationContext> context, |
117 const fileapi::FileSystemURL& url, | 115 const storage::FileSystemURL& url, |
118 bool exclusive, | 116 bool exclusive, |
119 bool recursive, | 117 bool recursive, |
120 const StatusCallback& callback); | 118 const StatusCallback& callback); |
121 virtual void GetFileInfoOnTaskRunnerThread( | 119 virtual void GetFileInfoOnTaskRunnerThread( |
122 scoped_ptr<fileapi::FileSystemOperationContext> context, | 120 scoped_ptr<storage::FileSystemOperationContext> context, |
123 const fileapi::FileSystemURL& url, | 121 const storage::FileSystemURL& url, |
124 const GetFileInfoCallback& callback); | 122 const GetFileInfoCallback& callback); |
125 virtual void ReadDirectoryOnTaskRunnerThread( | 123 virtual void ReadDirectoryOnTaskRunnerThread( |
126 scoped_ptr<fileapi::FileSystemOperationContext> context, | 124 scoped_ptr<storage::FileSystemOperationContext> context, |
127 const fileapi::FileSystemURL& url, | 125 const storage::FileSystemURL& url, |
128 const ReadDirectoryCallback& callback); | 126 const ReadDirectoryCallback& callback); |
129 virtual void CopyOrMoveFileLocalOnTaskRunnerThread( | 127 virtual void CopyOrMoveFileLocalOnTaskRunnerThread( |
130 scoped_ptr<fileapi::FileSystemOperationContext> context, | 128 scoped_ptr<storage::FileSystemOperationContext> context, |
131 const fileapi::FileSystemURL& src_url, | 129 const storage::FileSystemURL& src_url, |
132 const fileapi::FileSystemURL& dest_url, | 130 const storage::FileSystemURL& dest_url, |
133 CopyOrMoveOption option, | 131 CopyOrMoveOption option, |
134 bool copy, | 132 bool copy, |
135 const StatusCallback& callback); | 133 const StatusCallback& callback); |
136 virtual void CopyInForeignFileOnTaskRunnerThread( | 134 virtual void CopyInForeignFileOnTaskRunnerThread( |
137 scoped_ptr<fileapi::FileSystemOperationContext> context, | 135 scoped_ptr<storage::FileSystemOperationContext> context, |
138 const base::FilePath& src_file_path, | 136 const base::FilePath& src_file_path, |
139 const fileapi::FileSystemURL& dest_url, | 137 const storage::FileSystemURL& dest_url, |
140 const StatusCallback& callback); | 138 const StatusCallback& callback); |
141 virtual void DeleteFileOnTaskRunnerThread( | 139 virtual void DeleteFileOnTaskRunnerThread( |
142 scoped_ptr<fileapi::FileSystemOperationContext> context, | 140 scoped_ptr<storage::FileSystemOperationContext> context, |
143 const fileapi::FileSystemURL& url, | 141 const storage::FileSystemURL& url, |
144 const StatusCallback& callback); | 142 const StatusCallback& callback); |
145 virtual void DeleteDirectoryOnTaskRunnerThread( | 143 virtual void DeleteDirectoryOnTaskRunnerThread( |
146 scoped_ptr<fileapi::FileSystemOperationContext> context, | 144 scoped_ptr<storage::FileSystemOperationContext> context, |
147 const fileapi::FileSystemURL& url, | 145 const storage::FileSystemURL& url, |
148 const StatusCallback& callback); | 146 const StatusCallback& callback); |
149 virtual void CreateSnapshotFileOnTaskRunnerThread( | 147 virtual void CreateSnapshotFileOnTaskRunnerThread( |
150 scoped_ptr<fileapi::FileSystemOperationContext> context, | 148 scoped_ptr<storage::FileSystemOperationContext> context, |
151 const fileapi::FileSystemURL& url, | 149 const storage::FileSystemURL& url, |
152 const CreateSnapshotFileCallback& callback); | 150 const CreateSnapshotFileCallback& callback); |
153 | 151 |
154 // The following methods should only be called on the task runner thread. | 152 // The following methods should only be called on the task runner thread. |
155 | 153 |
156 // Necessary for copy/move to succeed. | 154 // Necessary for copy/move to succeed. |
157 virtual base::File::Error CreateDirectorySync( | 155 virtual base::File::Error CreateDirectorySync( |
158 fileapi::FileSystemOperationContext* context, | 156 storage::FileSystemOperationContext* context, |
159 const fileapi::FileSystemURL& url, | 157 const storage::FileSystemURL& url, |
160 bool exclusive, | 158 bool exclusive, |
161 bool recursive); | 159 bool recursive); |
162 virtual base::File::Error CopyOrMoveFileSync( | 160 virtual base::File::Error CopyOrMoveFileSync( |
163 fileapi::FileSystemOperationContext* context, | 161 storage::FileSystemOperationContext* context, |
164 const fileapi::FileSystemURL& src_url, | 162 const storage::FileSystemURL& src_url, |
165 const fileapi::FileSystemURL& dest_url, | 163 const storage::FileSystemURL& dest_url, |
166 CopyOrMoveOption option, | 164 CopyOrMoveOption option, |
167 bool copy); | 165 bool copy); |
168 virtual base::File::Error CopyInForeignFileSync( | 166 virtual base::File::Error CopyInForeignFileSync( |
169 fileapi::FileSystemOperationContext* context, | 167 storage::FileSystemOperationContext* context, |
170 const base::FilePath& src_file_path, | 168 const base::FilePath& src_file_path, |
171 const fileapi::FileSystemURL& dest_url); | 169 const storage::FileSystemURL& dest_url); |
172 virtual base::File::Error GetFileInfoSync( | 170 virtual base::File::Error GetFileInfoSync( |
173 fileapi::FileSystemOperationContext* context, | 171 storage::FileSystemOperationContext* context, |
174 const fileapi::FileSystemURL& url, | 172 const storage::FileSystemURL& url, |
175 base::File::Info* file_info, | 173 base::File::Info* file_info, |
176 base::FilePath* platform_path); | 174 base::FilePath* platform_path); |
177 // Called by GetFileInfoSync. Meant to be overridden by subclasses that | 175 // Called by GetFileInfoSync. Meant to be overridden by subclasses that |
178 // have special mappings from URLs to platform paths (virtual filesystems). | 176 // have special mappings from URLs to platform paths (virtual filesystems). |
179 virtual base::File::Error GetLocalFilePath( | 177 virtual base::File::Error GetLocalFilePath( |
180 fileapi::FileSystemOperationContext* context, | 178 storage::FileSystemOperationContext* context, |
181 const fileapi::FileSystemURL& file_system_url, | 179 const storage::FileSystemURL& file_system_url, |
182 base::FilePath* local_file_path); | 180 base::FilePath* local_file_path); |
183 virtual base::File::Error ReadDirectorySync( | 181 virtual base::File::Error ReadDirectorySync( |
184 fileapi::FileSystemOperationContext* context, | 182 storage::FileSystemOperationContext* context, |
185 const fileapi::FileSystemURL& url, | 183 const storage::FileSystemURL& url, |
186 EntryList* file_list); | 184 EntryList* file_list); |
187 virtual base::File::Error DeleteFileSync( | 185 virtual base::File::Error DeleteFileSync( |
188 fileapi::FileSystemOperationContext* context, | 186 storage::FileSystemOperationContext* context, |
189 const fileapi::FileSystemURL& url); | 187 const storage::FileSystemURL& url); |
190 // Necessary for move to succeed. | 188 // Necessary for move to succeed. |
191 virtual base::File::Error DeleteDirectorySync( | 189 virtual base::File::Error DeleteDirectorySync( |
192 fileapi::FileSystemOperationContext* context, | 190 storage::FileSystemOperationContext* context, |
193 const fileapi::FileSystemURL& url); | 191 const storage::FileSystemURL& url); |
194 virtual base::File::Error CreateSnapshotFileSync( | 192 virtual base::File::Error CreateSnapshotFileSync( |
195 fileapi::FileSystemOperationContext* context, | 193 storage::FileSystemOperationContext* context, |
196 const fileapi::FileSystemURL& url, | 194 const storage::FileSystemURL& url, |
197 base::File::Info* file_info, | 195 base::File::Info* file_info, |
198 base::FilePath* platform_path, | 196 base::FilePath* platform_path, |
199 scoped_refptr<webkit_blob::ShareableFileReference>* file_ref); | 197 scoped_refptr<storage::ShareableFileReference>* file_ref); |
200 | 198 |
201 MediaPathFilter* media_path_filter() { | 199 MediaPathFilter* media_path_filter() { |
202 return media_path_filter_; | 200 return media_path_filter_; |
203 } | 201 } |
204 | 202 |
205 private: | 203 private: |
206 // Like GetLocalFilePath(), but always take media_path_filter() into | 204 // Like GetLocalFilePath(), but always take media_path_filter() into |
207 // consideration. If the media_path_filter() check fails, return | 205 // consideration. If the media_path_filter() check fails, return |
208 // Fila::FILE_ERROR_SECURITY. |local_file_path| does not have to exist. | 206 // Fila::FILE_ERROR_SECURITY. |local_file_path| does not have to exist. |
209 base::File::Error GetFilteredLocalFilePath( | 207 base::File::Error GetFilteredLocalFilePath( |
210 fileapi::FileSystemOperationContext* context, | 208 storage::FileSystemOperationContext* context, |
211 const fileapi::FileSystemURL& file_system_url, | 209 const storage::FileSystemURL& file_system_url, |
212 base::FilePath* local_file_path); | 210 base::FilePath* local_file_path); |
213 | 211 |
214 // Like GetLocalFilePath(), but if the file does not exist, then return | 212 // Like GetLocalFilePath(), but if the file does not exist, then return |
215 // |failure_error|. | 213 // |failure_error|. |
216 // If |local_file_path| is a file, then take media_path_filter() into | 214 // If |local_file_path| is a file, then take media_path_filter() into |
217 // consideration. | 215 // consideration. |
218 // If the media_path_filter() check fails, return |failure_error|. | 216 // If the media_path_filter() check fails, return |failure_error|. |
219 // If |local_file_path| is a directory, return File::FILE_OK. | 217 // If |local_file_path| is a directory, return File::FILE_OK. |
220 base::File::Error GetFilteredLocalFilePathForExistingFileOrDirectory( | 218 base::File::Error GetFilteredLocalFilePathForExistingFileOrDirectory( |
221 fileapi::FileSystemOperationContext* context, | 219 storage::FileSystemOperationContext* context, |
222 const fileapi::FileSystemURL& file_system_url, | 220 const storage::FileSystemURL& file_system_url, |
223 base::File::Error failure_error, | 221 base::File::Error failure_error, |
224 base::FilePath* local_file_path); | 222 base::FilePath* local_file_path); |
225 | 223 |
226 | |
227 // Not owned, owned by the backend which owns this. | 224 // Not owned, owned by the backend which owns this. |
228 MediaPathFilter* const media_path_filter_; | 225 MediaPathFilter* const media_path_filter_; |
229 | 226 |
230 base::WeakPtrFactory<NativeMediaFileUtil> weak_factory_; | 227 base::WeakPtrFactory<NativeMediaFileUtil> weak_factory_; |
231 | 228 |
232 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtil); | 229 DISALLOW_COPY_AND_ASSIGN(NativeMediaFileUtil); |
233 }; | 230 }; |
234 | 231 |
235 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ | 232 #endif // CHROME_BROWSER_MEDIA_GALLERIES_FILEAPI_NATIVE_MEDIA_FILE_UTIL_H_ |
OLD | NEW |