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 #include "chrome/browser/media_galleries/fileapi/native_media_file_util.h" | 5 #include "chrome/browser/media_galleries/fileapi/native_media_file_util.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "chrome/browser/media_galleries/fileapi/filtering_file_enumerator.h" | |
10 #include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_p rovider.h" | 9 #include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_p rovider.h" |
11 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" | 10 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" |
12 #include "googleurl/src/gurl.h" | 11 #include "googleurl/src/gurl.h" |
13 #include "net/base/mime_sniffer.h" | 12 #include "net/base/mime_sniffer.h" |
14 #include "webkit/browser/fileapi/file_system_context.h" | 13 #include "webkit/browser/fileapi/file_system_context.h" |
15 #include "webkit/browser/fileapi/file_system_operation_context.h" | 14 #include "webkit/browser/fileapi/file_system_operation_context.h" |
16 #include "webkit/browser/fileapi/file_system_task_runners.h" | 15 #include "webkit/browser/fileapi/file_system_task_runners.h" |
17 #include "webkit/browser/fileapi/native_file_util.h" | 16 #include "webkit/browser/fileapi/native_file_util.h" |
17 #include "webkit/common/blob/shareable_file_reference.h" | |
18 #include "webkit/common/fileapi/file_system_util.h" | |
18 | 19 |
19 using base::PlatformFile; | 20 using base::PlatformFile; |
20 using base::PlatformFileError; | 21 using base::PlatformFileError; |
21 using base::PlatformFileInfo; | 22 using base::PlatformFileInfo; |
22 using fileapi::FileSystemOperationContext; | 23 using fileapi::FileSystemOperationContext; |
23 using fileapi::FileSystemURL; | 24 using fileapi::FileSystemURL; |
24 using fileapi::NativeFileUtil; | 25 using fileapi::NativeFileUtil; |
25 | 26 |
26 namespace chrome { | 27 namespace chrome { |
27 | 28 |
28 namespace { | 29 namespace { |
29 | 30 |
30 // Modelled after ScopedFILEClose. | 31 // Modelled after ScopedFILEClose. |
31 struct ScopedPlatformFileClose { | 32 struct ScopedPlatformFileClose { |
32 void operator()(base::PlatformFile* file) { | 33 void operator()(base::PlatformFile* file) { |
33 if (file && *file != base::kInvalidPlatformFileValue) | 34 if (file && *file != base::kInvalidPlatformFileValue) |
34 base::ClosePlatformFile(*file); | 35 base::ClosePlatformFile(*file); |
35 } | 36 } |
36 }; | 37 }; |
37 | 38 |
38 typedef scoped_ptr<base::PlatformFile, ScopedPlatformFileClose> | 39 typedef scoped_ptr<base::PlatformFile, ScopedPlatformFileClose> |
39 ScopedPlatformFile; | 40 ScopedPlatformFile; |
40 | 41 |
42 // Used to skip the hidden folders and files. Returns true if the file specified | |
43 // by |path| should be skipped. | |
44 bool ShouldSkip(const base::FilePath& path) { | |
45 const base::FilePath::StringType base_name = path.BaseName().value(); | |
46 if (base_name.empty()) | |
47 return false; | |
48 | |
49 // Dot files (aka hidden files) | |
50 if (base_name[0] == '.') | |
51 return true; | |
52 | |
53 // Mac OS X file. | |
54 if (base_name == FILE_PATH_LITERAL("__MACOSX")) | |
55 return true; | |
56 | |
57 #if defined(OS_WIN) | |
58 DWORD file_attributes = ::GetFileAttributes(path.value().c_str()); | |
59 if ((file_attributes != INVALID_FILE_ATTRIBUTES) && | |
60 ((file_attributes & FILE_ATTRIBUTE_HIDDEN) != 0)) | |
61 return true; | |
62 #else | |
63 // Windows always creates a recycle bin folder in the attached device to store | |
64 // all the deleted contents. On non-windows operating systems, there is no way | |
65 // to get the hidden attribute of windows recycle bin folders that are present | |
66 // on the attached device. Therefore, compare the file path name to the | |
67 // recycle bin name and exclude those folders. For more details, please refer | |
68 // to http://support.microsoft.com/kb/171694. | |
69 const char win_98_recycle_bin_name[] = "RECYCLED"; | |
70 const char win_xp_recycle_bin_name[] = "RECYCLER"; | |
71 const char win_vista_recycle_bin_name[] = "$Recycle.bin"; | |
72 if ((base::strncasecmp(base_name.c_str(), | |
73 win_98_recycle_bin_name, | |
74 strlen(win_98_recycle_bin_name)) == 0) || | |
75 (base::strncasecmp(base_name.c_str(), | |
76 win_xp_recycle_bin_name, | |
77 strlen(win_xp_recycle_bin_name)) == 0) || | |
78 (base::strncasecmp(base_name.c_str(), | |
79 win_vista_recycle_bin_name, | |
80 strlen(win_vista_recycle_bin_name)) == 0)) | |
81 return true; | |
82 #endif | |
83 return false; | |
84 } | |
85 | |
41 // Returns true if the current thread is capable of doing IO. | 86 // Returns true if the current thread is capable of doing IO. |
42 bool IsOnTaskRunnerThread(fileapi::FileSystemOperationContext* context) { | 87 bool IsOnTaskRunnerThread(fileapi::FileSystemOperationContext* context) { |
43 return context->file_system_context()->task_runners()-> | 88 return context->file_system_context()->task_runners()-> |
44 media_task_runner()->RunsTasksOnCurrentThread(); | 89 media_task_runner()->RunsTasksOnCurrentThread(); |
45 } | 90 } |
46 | 91 |
47 MediaPathFilter* GetMediaPathFilter(FileSystemOperationContext* context) { | 92 MediaPathFilter* GetMediaPathFilter(FileSystemOperationContext* context) { |
48 return context->GetUserValue<MediaPathFilter*>( | 93 return context->GetUserValue<MediaPathFilter*>( |
49 MediaFileSystemMountPointProvider::kMediaPathFilterKey); | 94 MediaFileSystemMountPointProvider::kMediaPathFilterKey); |
50 } | 95 } |
51 | 96 |
52 } // namespace | 97 } // namespace |
53 | 98 |
54 NativeMediaFileUtil::NativeMediaFileUtil() { | 99 NativeMediaFileUtil::NativeMediaFileUtil() { |
55 } | 100 } |
56 | 101 |
57 PlatformFileError NativeMediaFileUtil::CreateOrOpen( | 102 bool NativeMediaFileUtil::CreateOrOpen( |
58 FileSystemOperationContext* context, | 103 FileSystemOperationContext* context, |
59 const FileSystemURL& url, | 104 const FileSystemURL& url, |
60 int file_flags, | 105 int file_flags, |
61 PlatformFile* file_handle, | 106 const CreateOrOpenCallback& callback) { |
62 bool* created) { | |
63 // Only called by NaCl, which should not have access to media file systems. | 107 // Only called by NaCl, which should not have access to media file systems. |
64 return base::PLATFORM_FILE_ERROR_SECURITY; | 108 base::PlatformFile invalid_file(base::kInvalidPlatformFileValue); |
109 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, | |
110 base::PassPlatformFile(&invalid_file), | |
111 false); | |
112 return true; | |
65 } | 113 } |
66 | 114 |
67 PlatformFileError NativeMediaFileUtil::EnsureFileExists( | 115 bool NativeMediaFileUtil::EnsureFileExists( |
68 FileSystemOperationContext* context, | 116 FileSystemOperationContext* context, |
69 const FileSystemURL& url, bool* created) { | 117 const FileSystemURL& url, |
70 base::FilePath file_path; | 118 const EnsureFileExistsCallback& callback) { |
71 PlatformFileError error = GetFilteredLocalFilePath(context, url, &file_path); | 119 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, false); |
72 if (error != base::PLATFORM_FILE_OK) | 120 return true; |
73 return error; | |
74 return NativeFileUtil::EnsureFileExists(file_path, created); | |
75 } | 121 } |
76 | 122 |
77 scoped_ptr<fileapi::FileSystemFileUtil::AbstractFileEnumerator> | 123 bool NativeMediaFileUtil::CreateDirectory( |
78 NativeMediaFileUtil::CreateFileEnumerator( | |
79 FileSystemOperationContext* context, | 124 FileSystemOperationContext* context, |
80 const FileSystemURL& root_url) { | 125 const FileSystemURL& url, |
81 DCHECK(context); | 126 bool exclusive, |
82 return make_scoped_ptr(new FilteringFileEnumerator( | 127 bool recursive, |
83 IsolatedFileUtil::CreateFileEnumerator(context, root_url), | 128 const StatusCallback& callback) { |
84 GetMediaPathFilter(context))) | 129 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
85 .PassAs<FileSystemFileUtil::AbstractFileEnumerator>(); | 130 return true; |
86 } | 131 } |
87 | 132 |
88 PlatformFileError NativeMediaFileUtil::Touch( | 133 bool NativeMediaFileUtil::GetFileInfo( |
134 FileSystemOperationContext* context, | |
135 const FileSystemURL& url, | |
136 const GetFileInfoCallback& callback) { | |
137 PlatformFileInfo file_info; | |
138 base::FilePath platform_path; | |
139 PlatformFileError error = | |
140 GetFileInfoSync(context, url, &file_info, &platform_path); | |
Lei Zhang
2013/05/30 21:27:17
This async file util doesn't seem very async??
tommycli
2013/05/30 21:52:32
Done.
| |
141 callback.Run(error, file_info, platform_path); | |
142 return true; | |
143 } | |
144 | |
145 bool NativeMediaFileUtil::ReadDirectory( | |
146 FileSystemOperationContext* context, | |
147 const FileSystemURL& url, | |
148 const ReadDirectoryCallback& callback) { | |
149 EntryList entry_list; | |
150 PlatformFileError error = ReadDirectorySync( | |
151 context, url, &entry_list); | |
152 callback.Run(error, entry_list, false /* has_more */); | |
153 return true; | |
154 } | |
155 | |
156 bool NativeMediaFileUtil::Touch( | |
89 FileSystemOperationContext* context, | 157 FileSystemOperationContext* context, |
90 const FileSystemURL& url, | 158 const FileSystemURL& url, |
91 const base::Time& last_access_time, | 159 const base::Time& last_access_time, |
92 const base::Time& last_modified_time) { | 160 const base::Time& last_modified_time, |
93 base::FilePath file_path; | 161 const StatusCallback& callback) { |
94 PlatformFileError error = GetFilteredLocalFilePathForExistingFileOrDirectory( | 162 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
95 context, | 163 return true; |
96 url, | |
97 // Touch fails for non-existent paths and filtered paths. | |
98 base::PLATFORM_FILE_ERROR_FAILED, | |
99 &file_path); | |
100 if (error != base::PLATFORM_FILE_OK) | |
101 return error; | |
102 return NativeFileUtil::Touch(file_path, last_access_time, last_modified_time); | |
103 } | 164 } |
104 | 165 |
105 PlatformFileError NativeMediaFileUtil::Truncate( | 166 bool NativeMediaFileUtil::Truncate( |
106 FileSystemOperationContext* context, | 167 FileSystemOperationContext* context, |
107 const FileSystemURL& url, | 168 const FileSystemURL& url, |
108 int64 length) { | 169 int64 length, |
109 base::FilePath file_path; | 170 const StatusCallback& callback) { |
110 PlatformFileError error = GetFilteredLocalFilePathForExistingFileOrDirectory( | 171 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
111 context, | 172 return true; |
112 url, | |
113 // Cannot truncate paths that do not exist, or are filtered. | |
114 base::PLATFORM_FILE_ERROR_NOT_FOUND, | |
115 &file_path); | |
116 if (error != base::PLATFORM_FILE_OK) | |
117 return error; | |
118 return NativeFileUtil::Truncate(file_path, length); | |
119 } | 173 } |
120 | 174 |
121 PlatformFileError NativeMediaFileUtil::CopyOrMoveFile( | 175 bool NativeMediaFileUtil::CopyFileLocal( |
122 FileSystemOperationContext* context, | 176 FileSystemOperationContext* context, |
123 const FileSystemURL& src_url, | 177 const FileSystemURL& src_url, |
124 const FileSystemURL& dest_url, | 178 const FileSystemURL& dest_url, |
125 bool copy) { | 179 const StatusCallback& callback) { |
126 base::FilePath src_file_path; | 180 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
127 PlatformFileError error = | 181 return true; |
128 GetFilteredLocalFilePathForExistingFileOrDirectory( | |
129 context, src_url, | |
130 base::PLATFORM_FILE_ERROR_NOT_FOUND, | |
131 &src_file_path); | |
132 if (error != base::PLATFORM_FILE_OK) | |
133 return error; | |
134 if (NativeFileUtil::DirectoryExists(src_file_path)) | |
135 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; | |
136 | |
137 base::FilePath dest_file_path; | |
138 error = GetLocalFilePath(context, dest_url, &dest_file_path); | |
139 if (error != base::PLATFORM_FILE_OK) | |
140 return error; | |
141 PlatformFileInfo file_info; | |
142 error = NativeFileUtil::GetFileInfo(dest_file_path, &file_info); | |
143 if (error != base::PLATFORM_FILE_OK && | |
144 error != base::PLATFORM_FILE_ERROR_NOT_FOUND) | |
145 return error; | |
146 if (error == base::PLATFORM_FILE_OK && file_info.is_directory) | |
147 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | |
148 if (!GetMediaPathFilter(context)->Match(dest_file_path)) | |
149 return base::PLATFORM_FILE_ERROR_SECURITY; | |
150 | |
151 return NativeFileUtil::CopyOrMoveFile(src_file_path, dest_file_path, copy); | |
152 } | 182 } |
153 | 183 |
154 PlatformFileError NativeMediaFileUtil::CopyInForeignFile( | 184 bool NativeMediaFileUtil::MoveFileLocal( |
185 FileSystemOperationContext* context, | |
186 const FileSystemURL& src_url, | |
187 const FileSystemURL& dest_url, | |
188 const StatusCallback& callback) { | |
189 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); | |
190 return true; | |
191 } | |
192 | |
193 bool NativeMediaFileUtil::CopyInForeignFile( | |
155 FileSystemOperationContext* context, | 194 FileSystemOperationContext* context, |
156 const base::FilePath& src_file_path, | 195 const base::FilePath& src_file_path, |
157 const FileSystemURL& dest_url) { | 196 const FileSystemURL& dest_url, |
158 if (src_file_path.empty()) | 197 const StatusCallback& callback) { |
159 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 198 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
160 | 199 return true; |
161 base::FilePath dest_file_path; | |
162 PlatformFileError error = | |
163 GetFilteredLocalFilePath(context, dest_url, &dest_file_path); | |
164 if (error != base::PLATFORM_FILE_OK) | |
165 return error; | |
166 return NativeFileUtil::CopyOrMoveFile(src_file_path, dest_file_path, true); | |
167 } | 200 } |
168 | 201 |
169 PlatformFileError NativeMediaFileUtil::DeleteFile( | 202 bool NativeMediaFileUtil::DeleteFile( |
170 FileSystemOperationContext* context, | 203 FileSystemOperationContext* context, |
171 const FileSystemURL& url) { | 204 const FileSystemURL& url, |
172 base::FilePath file_path; | 205 const StatusCallback& callback) { |
173 PlatformFileError error = GetLocalFilePath(context, url, &file_path); | 206 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); |
174 if (error != base::PLATFORM_FILE_OK) | 207 return true; |
175 return error; | |
176 PlatformFileInfo file_info; | |
177 error = NativeFileUtil::GetFileInfo(file_path, &file_info); | |
178 if (error != base::PLATFORM_FILE_OK) | |
179 return error; | |
180 if (file_info.is_directory) | |
181 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; | |
182 if (!GetMediaPathFilter(context)->Match(file_path)) | |
183 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
184 return NativeFileUtil::DeleteFile(file_path); | |
185 } | 208 } |
186 | 209 |
187 PlatformFileError NativeMediaFileUtil::GetFileInfo( | 210 bool NativeMediaFileUtil::DeleteDirectory( |
211 FileSystemOperationContext* context, | |
212 const FileSystemURL& url, | |
213 const StatusCallback& callback) { | |
214 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); | |
215 return true; | |
216 } | |
217 | |
218 bool NativeMediaFileUtil::CreateSnapshotFile( | |
219 FileSystemOperationContext* context, | |
220 const FileSystemURL& url, | |
221 const CreateSnapshotFileCallback& callback) { | |
222 // We're just returning the local file information. | |
223 PlatformFileInfo file_info; | |
224 base::FilePath platform_path; | |
225 PlatformFileError error = | |
226 GetFileInfoSync(context, url, &file_info, &platform_path); | |
227 if (error == base::PLATFORM_FILE_OK && file_info.is_directory) | |
228 error = base::PLATFORM_FILE_ERROR_NOT_A_FILE; | |
229 if (error == base::PLATFORM_FILE_OK) | |
230 error = IsMediaFile(platform_path); | |
231 | |
232 callback.Run(error, file_info, platform_path, | |
233 scoped_refptr<webkit_blob::ShareableFileReference>()); | |
234 return true; | |
235 } | |
236 | |
237 PlatformFileError NativeMediaFileUtil::GetFileInfoSync( | |
188 FileSystemOperationContext* context, | 238 FileSystemOperationContext* context, |
189 const FileSystemURL& url, | 239 const FileSystemURL& url, |
190 PlatformFileInfo* file_info, | 240 PlatformFileInfo* file_info, |
191 base::FilePath* platform_path) { | 241 base::FilePath* platform_path) { |
192 DCHECK(context); | 242 DCHECK(context); |
193 DCHECK(GetMediaPathFilter(context)); | |
194 DCHECK(file_info); | 243 DCHECK(file_info); |
195 DCHECK(platform_path); | 244 DCHECK(platform_path); |
245 DCHECK(GetMediaPathFilter(context)); | |
196 | 246 |
197 base::PlatformFileError error = | 247 base::FilePath file_path; |
198 IsolatedFileUtil::GetFileInfo(context, url, file_info, platform_path); | 248 PlatformFileError error = GetLocalFilePath(context, url, &file_path); |
249 if (error != base::PLATFORM_FILE_OK) | |
250 return error; | |
251 if (file_util::IsLink(file_path)) | |
252 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | |
253 error = NativeFileUtil::GetFileInfo(file_path, file_info); | |
199 if (error != base::PLATFORM_FILE_OK) | 254 if (error != base::PLATFORM_FILE_OK) |
200 return error; | 255 return error; |
201 | 256 |
257 *platform_path = file_path; | |
202 if (file_info->is_directory || | 258 if (file_info->is_directory || |
203 GetMediaPathFilter(context)->Match(*platform_path)) { | 259 GetMediaPathFilter(context)->Match(*platform_path)) { |
204 return base::PLATFORM_FILE_OK; | 260 return base::PLATFORM_FILE_OK; |
205 } | 261 } |
206 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 262 return base::PLATFORM_FILE_ERROR_NOT_FOUND; |
207 } | 263 } |
208 | 264 |
209 PlatformFileError NativeMediaFileUtil::GetFilteredLocalFilePath( | 265 PlatformFileError NativeMediaFileUtil::GetLocalFilePath( |
210 FileSystemOperationContext* context, | 266 FileSystemOperationContext* context, |
211 const FileSystemURL& file_system_url, | 267 const FileSystemURL& url, |
212 base::FilePath* local_file_path) { | 268 base::FilePath* local_file_path) { |
213 base::FilePath file_path; | 269 DCHECK(local_file_path); |
214 PlatformFileError error = | 270 DCHECK(url.is_valid()); |
215 IsolatedFileUtil::GetLocalFilePath(context, file_system_url, &file_path); | 271 if (url.path().empty()) { |
216 if (error != base::PLATFORM_FILE_OK) | 272 // Root direcory case, which should not be accessed. |
217 return error; | 273 return base::PLATFORM_FILE_ERROR_ACCESS_DENIED; |
218 if (!GetMediaPathFilter(context)->Match(file_path)) | 274 } |
219 return base::PLATFORM_FILE_ERROR_SECURITY; | 275 *local_file_path = url.path(); |
220 | |
221 *local_file_path = file_path; | |
222 return base::PLATFORM_FILE_OK; | 276 return base::PLATFORM_FILE_OK; |
223 } | 277 } |
224 | 278 |
225 PlatformFileError | 279 base::PlatformFileError NativeMediaFileUtil::ReadDirectorySync( |
226 NativeMediaFileUtil::GetFilteredLocalFilePathForExistingFileOrDirectory( | 280 FileSystemOperationContext* context, |
227 FileSystemOperationContext* context, | 281 const FileSystemURL& url, |
228 const FileSystemURL& file_system_url, | 282 EntryList* file_list) { |
229 PlatformFileError failure_error, | 283 DCHECK(file_list); |
230 base::FilePath* local_file_path) { | 284 DCHECK(file_list->empty()); |
231 base::FilePath file_path; | 285 base::PlatformFileInfo file_info; |
232 PlatformFileError error = | 286 base::FilePath platform_path; |
233 GetLocalFilePath(context, file_system_url, &file_path); | 287 PlatformFileError error = GetFileInfoSync(context, url, &file_info, |
288 &platform_path); | |
289 | |
290 if (error == base::PLATFORM_FILE_OK && !file_info.is_directory) | |
291 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; | |
292 | |
234 if (error != base::PLATFORM_FILE_OK) | 293 if (error != base::PLATFORM_FILE_OK) |
235 return error; | 294 return error; |
236 | 295 |
237 if (!file_util::PathExists(file_path)) | 296 file_util::FileEnumerator file_enum( |
238 return failure_error; | 297 platform_path, |
239 PlatformFileInfo file_info; | 298 false /* recursive */, |
240 if (!file_util::GetFileInfo(file_path, &file_info)) | 299 file_util::FileEnumerator::FILES | |
241 return base::PLATFORM_FILE_ERROR_FAILED; | 300 file_util::FileEnumerator::DIRECTORIES); |
301 file_util::FileEnumerator::FindInfo file_util_info; | |
302 #if defined(OS_WIN) | |
303 memset(&file_util_info, 0, sizeof(file_util_info)); | |
304 #endif // defined(OS_WIN) | |
242 | 305 |
243 if (!file_info.is_directory && | 306 for (base::FilePath platform_path = file_enum.Next(); |
244 !GetMediaPathFilter(context)->Match(file_path)) { | 307 !platform_path.empty(); |
245 return failure_error; | 308 platform_path = file_enum.Next()) { |
309 // Skip symlinks. | |
310 if (file_util::IsLink(platform_path)) | |
311 continue; | |
312 | |
313 file_enum.GetFindInfo(&file_util_info); | |
314 | |
315 // NativeMediaFileUtil skip criteria. | |
316 if (ShouldSkip(platform_path)) | |
317 continue; | |
318 if (!file_util::FileEnumerator::IsDirectory(file_util_info) && | |
319 !GetMediaPathFilter(context)->Match(platform_path)) | |
320 continue; | |
321 | |
322 fileapi::DirectoryEntry entry; | |
323 entry.is_directory = file_util::FileEnumerator::IsDirectory(file_util_info); | |
324 entry.name = platform_path.BaseName().value(); | |
325 entry.size = file_util::FileEnumerator::GetFilesize(file_util_info); | |
326 entry.last_modified_time = | |
327 file_util::FileEnumerator::GetLastModifiedTime(file_util_info); | |
328 | |
329 file_list->push_back(entry); | |
246 } | 330 } |
247 | 331 |
248 *local_file_path = file_path; | |
249 return base::PLATFORM_FILE_OK; | 332 return base::PLATFORM_FILE_OK; |
250 } | 333 } |
251 | 334 |
252 webkit_blob::ScopedFile NativeMediaFileUtil::CreateSnapshotFile( | |
253 fileapi::FileSystemOperationContext* context, | |
254 const fileapi::FileSystemURL& url, | |
255 base::PlatformFileError* error, | |
256 base::PlatformFileInfo* file_info, | |
257 base::FilePath* platform_path) { | |
258 DCHECK(IsOnTaskRunnerThread(context)); | |
259 webkit_blob::ScopedFile file; | |
260 file = IsolatedFileUtil::CreateSnapshotFile( | |
261 context, url, error, file_info, platform_path); | |
262 if (*error != base::PLATFORM_FILE_OK) | |
263 return file.Pass(); | |
264 *error = IsMediaFile(*platform_path); | |
265 if (*error == base::PLATFORM_FILE_OK) | |
266 return file.Pass(); | |
267 return webkit_blob::ScopedFile(); | |
268 } | |
269 | |
270 // static | 335 // static |
271 base::PlatformFileError NativeMediaFileUtil::IsMediaFile( | 336 base::PlatformFileError NativeMediaFileUtil::IsMediaFile( |
272 const base::FilePath& path) { | 337 const base::FilePath& path) { |
273 base::PlatformFile file_handle; | 338 base::PlatformFile file_handle; |
274 const int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ; | 339 const int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ; |
275 base::PlatformFileError error = | 340 base::PlatformFileError error = |
276 NativeFileUtil::CreateOrOpen(path, flags, &file_handle, NULL); | 341 NativeFileUtil::CreateOrOpen(path, flags, &file_handle, NULL); |
277 if (error != base::PLATFORM_FILE_OK) | 342 if (error != base::PLATFORM_FILE_OK) |
278 return error; | 343 return error; |
279 | 344 |
(...skipping 15 matching lines...) Expand all Loading... | |
295 if (StartsWithASCII(mime_type, "image/", true) || | 360 if (StartsWithASCII(mime_type, "image/", true) || |
296 StartsWithASCII(mime_type, "audio/", true) || | 361 StartsWithASCII(mime_type, "audio/", true) || |
297 StartsWithASCII(mime_type, "video/", true) || | 362 StartsWithASCII(mime_type, "video/", true) || |
298 mime_type == "application/x-shockwave-flash") { | 363 mime_type == "application/x-shockwave-flash") { |
299 return base::PLATFORM_FILE_OK; | 364 return base::PLATFORM_FILE_OK; |
300 } | 365 } |
301 return base::PLATFORM_FILE_ERROR_SECURITY; | 366 return base::PLATFORM_FILE_ERROR_SECURITY; |
302 } | 367 } |
303 | 368 |
304 } // namespace chrome | 369 } // namespace chrome |
OLD | NEW |