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 <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 | 77 |
78 NativeMediaFileUtil::NativeMediaFileUtil(MediaPathFilter* media_path_filter) | 78 NativeMediaFileUtil::NativeMediaFileUtil(MediaPathFilter* media_path_filter) |
79 : media_path_filter_(media_path_filter), | 79 : media_path_filter_(media_path_filter), |
80 weak_factory_(this) { | 80 weak_factory_(this) { |
81 } | 81 } |
82 | 82 |
83 NativeMediaFileUtil::~NativeMediaFileUtil() { | 83 NativeMediaFileUtil::~NativeMediaFileUtil() { |
84 } | 84 } |
85 | 85 |
86 // static | 86 // static |
87 base::PlatformFileError NativeMediaFileUtil::IsMediaFile( | 87 base::File::Error NativeMediaFileUtil::IsMediaFile( |
88 const base::FilePath& path) { | 88 const base::FilePath& path) { |
89 base::PlatformFile file_handle; | 89 base::PlatformFile file_handle; |
90 const int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ; | 90 const int flags = base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ; |
91 base::PlatformFileError error = | 91 base::File::Error error = |
92 fileapi::NativeFileUtil::CreateOrOpen(path, flags, &file_handle, NULL); | 92 fileapi::NativeFileUtil::CreateOrOpen(path, flags, &file_handle, NULL); |
93 if (error != base::PLATFORM_FILE_OK) | 93 if (error != base::File::FILE_OK) |
94 return error; | 94 return error; |
95 | 95 |
96 base::ScopedPlatformFileCloser scoped_platform_file(&file_handle); | 96 base::ScopedPlatformFileCloser scoped_platform_file(&file_handle); |
97 char buffer[net::kMaxBytesToSniff]; | 97 char buffer[net::kMaxBytesToSniff]; |
98 | 98 |
99 // Read as much as net::SniffMimeTypeFromLocalData() will bother looking at. | 99 // Read as much as net::SniffMimeTypeFromLocalData() will bother looking at. |
100 int64 len = | 100 int64 len = |
101 base::ReadPlatformFile(file_handle, 0, buffer, net::kMaxBytesToSniff); | 101 base::ReadPlatformFile(file_handle, 0, buffer, net::kMaxBytesToSniff); |
102 if (len < 0) | 102 if (len < 0) |
103 return base::PLATFORM_FILE_ERROR_FAILED; | 103 return base::File::FILE_ERROR_FAILED; |
104 if (len == 0) | 104 if (len == 0) |
105 return base::PLATFORM_FILE_ERROR_SECURITY; | 105 return base::File::FILE_ERROR_SECURITY; |
106 | 106 |
107 std::string mime_type; | 107 std::string mime_type; |
108 if (!net::SniffMimeTypeFromLocalData(buffer, len, &mime_type)) | 108 if (!net::SniffMimeTypeFromLocalData(buffer, len, &mime_type)) |
109 return base::PLATFORM_FILE_ERROR_SECURITY; | 109 return base::File::FILE_ERROR_SECURITY; |
110 | 110 |
111 if (StartsWithASCII(mime_type, "image/", true) || | 111 if (StartsWithASCII(mime_type, "image/", true) || |
112 StartsWithASCII(mime_type, "audio/", true) || | 112 StartsWithASCII(mime_type, "audio/", true) || |
113 StartsWithASCII(mime_type, "video/", true) || | 113 StartsWithASCII(mime_type, "video/", true) || |
114 mime_type == "application/x-shockwave-flash") { | 114 mime_type == "application/x-shockwave-flash") { |
115 return base::PLATFORM_FILE_OK; | 115 return base::File::FILE_OK; |
116 } | 116 } |
117 return base::PLATFORM_FILE_ERROR_SECURITY; | 117 return base::File::FILE_ERROR_SECURITY; |
118 } | 118 } |
119 | 119 |
120 void NativeMediaFileUtil::CreateOrOpen( | 120 void NativeMediaFileUtil::CreateOrOpen( |
121 scoped_ptr<fileapi::FileSystemOperationContext> context, | 121 scoped_ptr<fileapi::FileSystemOperationContext> context, |
122 const fileapi::FileSystemURL& url, | 122 const fileapi::FileSystemURL& url, |
123 int file_flags, | 123 int file_flags, |
124 const CreateOrOpenCallback& callback) { | 124 const CreateOrOpenCallback& callback) { |
125 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 125 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
126 // Only called by NaCl, which should not have access to media file systems. | 126 // Only called by NaCl, which should not have access to media file systems. |
127 base::PlatformFile invalid_file(base::kInvalidPlatformFileValue); | 127 base::PlatformFile invalid_file(base::kInvalidPlatformFileValue); |
128 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, | 128 callback.Run(base::File::FILE_ERROR_SECURITY, |
129 base::PassPlatformFile(&invalid_file), | 129 base::PassPlatformFile(&invalid_file), |
130 base::Closure()); | 130 base::Closure()); |
131 } | 131 } |
132 | 132 |
133 void NativeMediaFileUtil::EnsureFileExists( | 133 void NativeMediaFileUtil::EnsureFileExists( |
134 scoped_ptr<fileapi::FileSystemOperationContext> context, | 134 scoped_ptr<fileapi::FileSystemOperationContext> context, |
135 const fileapi::FileSystemURL& url, | 135 const fileapi::FileSystemURL& url, |
136 const EnsureFileExistsCallback& callback) { | 136 const EnsureFileExistsCallback& callback) { |
137 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 137 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
138 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY, false); | 138 callback.Run(base::File::FILE_ERROR_SECURITY, false); |
139 } | 139 } |
140 | 140 |
141 void NativeMediaFileUtil::CreateDirectory( | 141 void NativeMediaFileUtil::CreateDirectory( |
142 scoped_ptr<fileapi::FileSystemOperationContext> context, | 142 scoped_ptr<fileapi::FileSystemOperationContext> context, |
143 const fileapi::FileSystemURL& url, | 143 const fileapi::FileSystemURL& url, |
144 bool exclusive, | 144 bool exclusive, |
145 bool recursive, | 145 bool recursive, |
146 const StatusCallback& callback) { | 146 const StatusCallback& callback) { |
147 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 147 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
148 fileapi::FileSystemOperationContext* context_ptr = context.get(); | 148 fileapi::FileSystemOperationContext* context_ptr = context.get(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
182 DCHECK(success); | 182 DCHECK(success); |
183 } | 183 } |
184 | 184 |
185 void NativeMediaFileUtil::Touch( | 185 void NativeMediaFileUtil::Touch( |
186 scoped_ptr<fileapi::FileSystemOperationContext> context, | 186 scoped_ptr<fileapi::FileSystemOperationContext> context, |
187 const fileapi::FileSystemURL& url, | 187 const fileapi::FileSystemURL& url, |
188 const base::Time& last_access_time, | 188 const base::Time& last_access_time, |
189 const base::Time& last_modified_time, | 189 const base::Time& last_modified_time, |
190 const StatusCallback& callback) { | 190 const StatusCallback& callback) { |
191 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 191 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
192 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); | 192 callback.Run(base::File::FILE_ERROR_SECURITY); |
193 } | 193 } |
194 | 194 |
195 void NativeMediaFileUtil::Truncate( | 195 void NativeMediaFileUtil::Truncate( |
196 scoped_ptr<fileapi::FileSystemOperationContext> context, | 196 scoped_ptr<fileapi::FileSystemOperationContext> context, |
197 const fileapi::FileSystemURL& url, | 197 const fileapi::FileSystemURL& url, |
198 int64 length, | 198 int64 length, |
199 const StatusCallback& callback) { | 199 const StatusCallback& callback) { |
200 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 200 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
201 callback.Run(base::PLATFORM_FILE_ERROR_SECURITY); | 201 callback.Run(base::File::FILE_ERROR_SECURITY); |
202 } | 202 } |
203 | 203 |
204 void NativeMediaFileUtil::CopyFileLocal( | 204 void NativeMediaFileUtil::CopyFileLocal( |
205 scoped_ptr<fileapi::FileSystemOperationContext> context, | 205 scoped_ptr<fileapi::FileSystemOperationContext> context, |
206 const fileapi::FileSystemURL& src_url, | 206 const fileapi::FileSystemURL& src_url, |
207 const fileapi::FileSystemURL& dest_url, | 207 const fileapi::FileSystemURL& dest_url, |
208 CopyOrMoveOption option, | 208 CopyOrMoveOption option, |
209 const CopyFileProgressCallback& progress_callback, | 209 const CopyFileProgressCallback& progress_callback, |
210 const StatusCallback& callback) { | 210 const StatusCallback& callback) { |
211 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 211 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 weak_factory_.GetWeakPtr(), base::Passed(&context), | 276 weak_factory_.GetWeakPtr(), base::Passed(&context), |
277 url, callback)); | 277 url, callback)); |
278 DCHECK(success); | 278 DCHECK(success); |
279 } | 279 } |
280 | 280 |
281 void NativeMediaFileUtil::DeleteRecursively( | 281 void NativeMediaFileUtil::DeleteRecursively( |
282 scoped_ptr<fileapi::FileSystemOperationContext> context, | 282 scoped_ptr<fileapi::FileSystemOperationContext> context, |
283 const fileapi::FileSystemURL& url, | 283 const fileapi::FileSystemURL& url, |
284 const StatusCallback& callback) { | 284 const StatusCallback& callback) { |
285 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 285 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
286 callback.Run(base::PLATFORM_FILE_ERROR_INVALID_OPERATION); | 286 callback.Run(base::File::FILE_ERROR_INVALID_OPERATION); |
287 } | 287 } |
288 | 288 |
289 void NativeMediaFileUtil::CreateSnapshotFile( | 289 void NativeMediaFileUtil::CreateSnapshotFile( |
290 scoped_ptr<fileapi::FileSystemOperationContext> context, | 290 scoped_ptr<fileapi::FileSystemOperationContext> context, |
291 const fileapi::FileSystemURL& url, | 291 const fileapi::FileSystemURL& url, |
292 const CreateSnapshotFileCallback& callback) { | 292 const CreateSnapshotFileCallback& callback) { |
293 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); | 293 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); |
294 fileapi::FileSystemOperationContext* context_ptr = context.get(); | 294 fileapi::FileSystemOperationContext* context_ptr = context.get(); |
295 const bool success = context_ptr->task_runner()->PostTask( | 295 const bool success = context_ptr->task_runner()->PostTask( |
296 FROM_HERE, | 296 FROM_HERE, |
297 base::Bind(&NativeMediaFileUtil::CreateSnapshotFileOnTaskRunnerThread, | 297 base::Bind(&NativeMediaFileUtil::CreateSnapshotFileOnTaskRunnerThread, |
298 weak_factory_.GetWeakPtr(), base::Passed(&context), | 298 weak_factory_.GetWeakPtr(), base::Passed(&context), |
299 url, callback)); | 299 url, callback)); |
300 DCHECK(success); | 300 DCHECK(success); |
301 } | 301 } |
302 | 302 |
303 void NativeMediaFileUtil::CreateDirectoryOnTaskRunnerThread( | 303 void NativeMediaFileUtil::CreateDirectoryOnTaskRunnerThread( |
304 scoped_ptr<fileapi::FileSystemOperationContext> context, | 304 scoped_ptr<fileapi::FileSystemOperationContext> context, |
305 const fileapi::FileSystemURL& url, | 305 const fileapi::FileSystemURL& url, |
306 bool exclusive, | 306 bool exclusive, |
307 bool recursive, | 307 bool recursive, |
308 const StatusCallback& callback) { | 308 const StatusCallback& callback) { |
309 DCHECK(IsOnTaskRunnerThread(context.get())); | 309 DCHECK(IsOnTaskRunnerThread(context.get())); |
310 base::PlatformFileError error = | 310 base::File::Error error = |
311 CreateDirectorySync(context.get(), url, exclusive, recursive); | 311 CreateDirectorySync(context.get(), url, exclusive, recursive); |
312 content::BrowserThread::PostTask( | 312 content::BrowserThread::PostTask( |
313 content::BrowserThread::IO, | 313 content::BrowserThread::IO, |
314 FROM_HERE, | 314 FROM_HERE, |
315 base::Bind(callback, error)); | 315 base::Bind(callback, error)); |
316 } | 316 } |
317 | 317 |
318 void NativeMediaFileUtil::GetFileInfoOnTaskRunnerThread( | 318 void NativeMediaFileUtil::GetFileInfoOnTaskRunnerThread( |
319 scoped_ptr<fileapi::FileSystemOperationContext> context, | 319 scoped_ptr<fileapi::FileSystemOperationContext> context, |
320 const fileapi::FileSystemURL& url, | 320 const fileapi::FileSystemURL& url, |
321 const GetFileInfoCallback& callback) { | 321 const GetFileInfoCallback& callback) { |
322 DCHECK(IsOnTaskRunnerThread(context.get())); | 322 DCHECK(IsOnTaskRunnerThread(context.get())); |
323 base::PlatformFileInfo file_info; | 323 base::File::Info file_info; |
324 base::PlatformFileError error = | 324 base::File::Error error = |
325 GetFileInfoSync(context.get(), url, &file_info, NULL); | 325 GetFileInfoSync(context.get(), url, &file_info, NULL); |
326 content::BrowserThread::PostTask( | 326 content::BrowserThread::PostTask( |
327 content::BrowserThread::IO, | 327 content::BrowserThread::IO, |
328 FROM_HERE, | 328 FROM_HERE, |
329 base::Bind(callback, error, file_info)); | 329 base::Bind(callback, error, file_info)); |
330 } | 330 } |
331 | 331 |
332 void NativeMediaFileUtil::ReadDirectoryOnTaskRunnerThread( | 332 void NativeMediaFileUtil::ReadDirectoryOnTaskRunnerThread( |
333 scoped_ptr<fileapi::FileSystemOperationContext> context, | 333 scoped_ptr<fileapi::FileSystemOperationContext> context, |
334 const fileapi::FileSystemURL& url, | 334 const fileapi::FileSystemURL& url, |
335 const ReadDirectoryCallback& callback) { | 335 const ReadDirectoryCallback& callback) { |
336 DCHECK(IsOnTaskRunnerThread(context.get())); | 336 DCHECK(IsOnTaskRunnerThread(context.get())); |
337 EntryList entry_list; | 337 EntryList entry_list; |
338 base::PlatformFileError error = | 338 base::File::Error error = |
339 ReadDirectorySync(context.get(), url, &entry_list); | 339 ReadDirectorySync(context.get(), url, &entry_list); |
340 content::BrowserThread::PostTask( | 340 content::BrowserThread::PostTask( |
341 content::BrowserThread::IO, | 341 content::BrowserThread::IO, |
342 FROM_HERE, | 342 FROM_HERE, |
343 base::Bind(callback, error, entry_list, false /* has_more */)); | 343 base::Bind(callback, error, entry_list, false /* has_more */)); |
344 } | 344 } |
345 | 345 |
346 void NativeMediaFileUtil::CopyOrMoveFileLocalOnTaskRunnerThread( | 346 void NativeMediaFileUtil::CopyOrMoveFileLocalOnTaskRunnerThread( |
347 scoped_ptr<fileapi::FileSystemOperationContext> context, | 347 scoped_ptr<fileapi::FileSystemOperationContext> context, |
348 const fileapi::FileSystemURL& src_url, | 348 const fileapi::FileSystemURL& src_url, |
349 const fileapi::FileSystemURL& dest_url, | 349 const fileapi::FileSystemURL& dest_url, |
350 CopyOrMoveOption option, | 350 CopyOrMoveOption option, |
351 bool copy, | 351 bool copy, |
352 const StatusCallback& callback) { | 352 const StatusCallback& callback) { |
353 DCHECK(IsOnTaskRunnerThread(context.get())); | 353 DCHECK(IsOnTaskRunnerThread(context.get())); |
354 base::PlatformFileError error = | 354 base::File::Error error = |
355 CopyOrMoveFileSync(context.get(), src_url, dest_url, option, copy); | 355 CopyOrMoveFileSync(context.get(), src_url, dest_url, option, copy); |
356 content::BrowserThread::PostTask( | 356 content::BrowserThread::PostTask( |
357 content::BrowserThread::IO, | 357 content::BrowserThread::IO, |
358 FROM_HERE, | 358 FROM_HERE, |
359 base::Bind(callback, error)); | 359 base::Bind(callback, error)); |
360 } | 360 } |
361 | 361 |
362 void NativeMediaFileUtil::CopyInForeignFileOnTaskRunnerThread( | 362 void NativeMediaFileUtil::CopyInForeignFileOnTaskRunnerThread( |
363 scoped_ptr<fileapi::FileSystemOperationContext> context, | 363 scoped_ptr<fileapi::FileSystemOperationContext> context, |
364 const base::FilePath& src_file_path, | 364 const base::FilePath& src_file_path, |
365 const fileapi::FileSystemURL& dest_url, | 365 const fileapi::FileSystemURL& dest_url, |
366 const StatusCallback& callback) { | 366 const StatusCallback& callback) { |
367 DCHECK(IsOnTaskRunnerThread(context.get())); | 367 DCHECK(IsOnTaskRunnerThread(context.get())); |
368 base::PlatformFileError error = | 368 base::File::Error error = |
369 CopyInForeignFileSync(context.get(), src_file_path, dest_url); | 369 CopyInForeignFileSync(context.get(), src_file_path, dest_url); |
370 content::BrowserThread::PostTask( | 370 content::BrowserThread::PostTask( |
371 content::BrowserThread::IO, | 371 content::BrowserThread::IO, |
372 FROM_HERE, | 372 FROM_HERE, |
373 base::Bind(callback, error)); | 373 base::Bind(callback, error)); |
374 } | 374 } |
375 | 375 |
376 void NativeMediaFileUtil::DeleteFileOnTaskRunnerThread( | 376 void NativeMediaFileUtil::DeleteFileOnTaskRunnerThread( |
377 scoped_ptr<fileapi::FileSystemOperationContext> context, | 377 scoped_ptr<fileapi::FileSystemOperationContext> context, |
378 const fileapi::FileSystemURL& url, | 378 const fileapi::FileSystemURL& url, |
379 const StatusCallback& callback) { | 379 const StatusCallback& callback) { |
380 DCHECK(IsOnTaskRunnerThread(context.get())); | 380 DCHECK(IsOnTaskRunnerThread(context.get())); |
381 base::PlatformFileError error = DeleteFileSync(context.get(), url); | 381 base::File::Error error = DeleteFileSync(context.get(), url); |
382 content::BrowserThread::PostTask( | 382 content::BrowserThread::PostTask( |
383 content::BrowserThread::IO, | 383 content::BrowserThread::IO, |
384 FROM_HERE, | 384 FROM_HERE, |
385 base::Bind(callback, error)); | 385 base::Bind(callback, error)); |
386 } | 386 } |
387 | 387 |
388 void NativeMediaFileUtil::DeleteDirectoryOnTaskRunnerThread( | 388 void NativeMediaFileUtil::DeleteDirectoryOnTaskRunnerThread( |
389 scoped_ptr<fileapi::FileSystemOperationContext> context, | 389 scoped_ptr<fileapi::FileSystemOperationContext> context, |
390 const fileapi::FileSystemURL& url, | 390 const fileapi::FileSystemURL& url, |
391 const StatusCallback& callback) { | 391 const StatusCallback& callback) { |
392 DCHECK(IsOnTaskRunnerThread(context.get())); | 392 DCHECK(IsOnTaskRunnerThread(context.get())); |
393 base::PlatformFileError error = DeleteDirectorySync(context.get(), url); | 393 base::File::Error error = DeleteDirectorySync(context.get(), url); |
394 content::BrowserThread::PostTask( | 394 content::BrowserThread::PostTask( |
395 content::BrowserThread::IO, | 395 content::BrowserThread::IO, |
396 FROM_HERE, | 396 FROM_HERE, |
397 base::Bind(callback, error)); | 397 base::Bind(callback, error)); |
398 } | 398 } |
399 | 399 |
400 void NativeMediaFileUtil::CreateSnapshotFileOnTaskRunnerThread( | 400 void NativeMediaFileUtil::CreateSnapshotFileOnTaskRunnerThread( |
401 scoped_ptr<fileapi::FileSystemOperationContext> context, | 401 scoped_ptr<fileapi::FileSystemOperationContext> context, |
402 const fileapi::FileSystemURL& url, | 402 const fileapi::FileSystemURL& url, |
403 const CreateSnapshotFileCallback& callback) { | 403 const CreateSnapshotFileCallback& callback) { |
404 DCHECK(IsOnTaskRunnerThread(context.get())); | 404 DCHECK(IsOnTaskRunnerThread(context.get())); |
405 base::PlatformFileInfo file_info; | 405 base::File::Info file_info; |
406 base::FilePath platform_path; | 406 base::FilePath platform_path; |
407 scoped_refptr<webkit_blob::ShareableFileReference> file_ref; | 407 scoped_refptr<webkit_blob::ShareableFileReference> file_ref; |
408 base::PlatformFileError error = | 408 base::File::Error error = |
409 CreateSnapshotFileSync(context.get(), url, &file_info, &platform_path, | 409 CreateSnapshotFileSync(context.get(), url, &file_info, &platform_path, |
410 &file_ref); | 410 &file_ref); |
411 content::BrowserThread::PostTask( | 411 content::BrowserThread::PostTask( |
412 content::BrowserThread::IO, | 412 content::BrowserThread::IO, |
413 FROM_HERE, | 413 FROM_HERE, |
414 base::Bind(callback, error, file_info, platform_path, file_ref)); | 414 base::Bind(callback, error, file_info, platform_path, file_ref)); |
415 } | 415 } |
416 | 416 |
417 base::PlatformFileError NativeMediaFileUtil::CreateDirectorySync( | 417 base::File::Error NativeMediaFileUtil::CreateDirectorySync( |
418 fileapi::FileSystemOperationContext* context, | 418 fileapi::FileSystemOperationContext* context, |
419 const fileapi::FileSystemURL& url, | 419 const fileapi::FileSystemURL& url, |
420 bool exclusive, | 420 bool exclusive, |
421 bool recursive) { | 421 bool recursive) { |
422 base::FilePath file_path; | 422 base::FilePath file_path; |
423 base::PlatformFileError error = GetLocalFilePath(context, url, &file_path); | 423 base::File::Error error = GetLocalFilePath(context, url, &file_path); |
424 if (error != base::PLATFORM_FILE_OK) | 424 if (error != base::File::FILE_OK) |
425 return error; | 425 return error; |
426 return fileapi::NativeFileUtil::CreateDirectory(file_path, exclusive, | 426 return fileapi::NativeFileUtil::CreateDirectory(file_path, exclusive, |
427 recursive); | 427 recursive); |
428 } | 428 } |
429 | 429 |
430 base::PlatformFileError NativeMediaFileUtil::CopyOrMoveFileSync( | 430 base::File::Error NativeMediaFileUtil::CopyOrMoveFileSync( |
431 fileapi::FileSystemOperationContext* context, | 431 fileapi::FileSystemOperationContext* context, |
432 const fileapi::FileSystemURL& src_url, | 432 const fileapi::FileSystemURL& src_url, |
433 const fileapi::FileSystemURL& dest_url, | 433 const fileapi::FileSystemURL& dest_url, |
434 CopyOrMoveOption option, | 434 CopyOrMoveOption option, |
435 bool copy) { | 435 bool copy) { |
436 DCHECK(IsOnTaskRunnerThread(context)); | 436 DCHECK(IsOnTaskRunnerThread(context)); |
437 base::FilePath src_file_path; | 437 base::FilePath src_file_path; |
438 base::PlatformFileError error = | 438 base::File::Error error = |
439 GetFilteredLocalFilePathForExistingFileOrDirectory( | 439 GetFilteredLocalFilePathForExistingFileOrDirectory( |
440 context, src_url, | 440 context, src_url, |
441 base::PLATFORM_FILE_ERROR_NOT_FOUND, | 441 base::File::FILE_ERROR_NOT_FOUND, |
442 &src_file_path); | 442 &src_file_path); |
443 if (error != base::PLATFORM_FILE_OK) | 443 if (error != base::File::FILE_OK) |
444 return error; | 444 return error; |
445 if (fileapi::NativeFileUtil::DirectoryExists(src_file_path)) | 445 if (fileapi::NativeFileUtil::DirectoryExists(src_file_path)) |
446 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; | 446 return base::File::FILE_ERROR_NOT_A_FILE; |
447 | 447 |
448 base::FilePath dest_file_path; | 448 base::FilePath dest_file_path; |
449 error = GetLocalFilePath(context, dest_url, &dest_file_path); | 449 error = GetLocalFilePath(context, dest_url, &dest_file_path); |
450 if (error != base::PLATFORM_FILE_OK) | 450 if (error != base::File::FILE_OK) |
451 return error; | 451 return error; |
452 base::PlatformFileInfo file_info; | 452 base::File::Info file_info; |
453 error = fileapi::NativeFileUtil::GetFileInfo(dest_file_path, &file_info); | 453 error = fileapi::NativeFileUtil::GetFileInfo(dest_file_path, &file_info); |
454 if (error != base::PLATFORM_FILE_OK && | 454 if (error != base::File::FILE_OK && |
455 error != base::PLATFORM_FILE_ERROR_NOT_FOUND) | 455 error != base::File::FILE_ERROR_NOT_FOUND) { |
456 return error; | 456 return error; |
457 if (error == base::PLATFORM_FILE_OK && file_info.is_directory) | 457 } |
458 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 458 if (error == base::File::FILE_OK && file_info.is_directory) |
| 459 return base::File::FILE_ERROR_INVALID_OPERATION; |
459 if (!media_path_filter_->Match(dest_file_path)) | 460 if (!media_path_filter_->Match(dest_file_path)) |
460 return base::PLATFORM_FILE_ERROR_SECURITY; | 461 return base::File::FILE_ERROR_SECURITY; |
461 | 462 |
462 return fileapi::NativeFileUtil::CopyOrMoveFile( | 463 return fileapi::NativeFileUtil::CopyOrMoveFile( |
463 src_file_path, dest_file_path, option, | 464 src_file_path, dest_file_path, option, |
464 fileapi::NativeFileUtil::CopyOrMoveModeForDestination(dest_url, copy)); | 465 fileapi::NativeFileUtil::CopyOrMoveModeForDestination(dest_url, copy)); |
465 } | 466 } |
466 | 467 |
467 base::PlatformFileError NativeMediaFileUtil::CopyInForeignFileSync( | 468 base::File::Error NativeMediaFileUtil::CopyInForeignFileSync( |
468 fileapi::FileSystemOperationContext* context, | 469 fileapi::FileSystemOperationContext* context, |
469 const base::FilePath& src_file_path, | 470 const base::FilePath& src_file_path, |
470 const fileapi::FileSystemURL& dest_url) { | 471 const fileapi::FileSystemURL& dest_url) { |
471 DCHECK(IsOnTaskRunnerThread(context)); | 472 DCHECK(IsOnTaskRunnerThread(context)); |
472 if (src_file_path.empty()) | 473 if (src_file_path.empty()) |
473 return base::PLATFORM_FILE_ERROR_INVALID_OPERATION; | 474 return base::File::FILE_ERROR_INVALID_OPERATION; |
474 | 475 |
475 base::FilePath dest_file_path; | 476 base::FilePath dest_file_path; |
476 base::PlatformFileError error = | 477 base::File::Error error = |
477 GetFilteredLocalFilePath(context, dest_url, &dest_file_path); | 478 GetFilteredLocalFilePath(context, dest_url, &dest_file_path); |
478 if (error != base::PLATFORM_FILE_OK) | 479 if (error != base::File::FILE_OK) |
479 return error; | 480 return error; |
480 return fileapi::NativeFileUtil::CopyOrMoveFile( | 481 return fileapi::NativeFileUtil::CopyOrMoveFile( |
481 src_file_path, dest_file_path, | 482 src_file_path, dest_file_path, |
482 fileapi::FileSystemOperation::OPTION_NONE, | 483 fileapi::FileSystemOperation::OPTION_NONE, |
483 fileapi::NativeFileUtil::CopyOrMoveModeForDestination(dest_url, | 484 fileapi::NativeFileUtil::CopyOrMoveModeForDestination(dest_url, |
484 true /* copy */)); | 485 true /* copy */)); |
485 } | 486 } |
486 | 487 |
487 base::PlatformFileError NativeMediaFileUtil::GetFileInfoSync( | 488 base::File::Error NativeMediaFileUtil::GetFileInfoSync( |
488 fileapi::FileSystemOperationContext* context, | 489 fileapi::FileSystemOperationContext* context, |
489 const fileapi::FileSystemURL& url, | 490 const fileapi::FileSystemURL& url, |
490 base::PlatformFileInfo* file_info, | 491 base::File::Info* file_info, |
491 base::FilePath* platform_path) { | 492 base::FilePath* platform_path) { |
492 DCHECK(context); | 493 DCHECK(context); |
493 DCHECK(IsOnTaskRunnerThread(context)); | 494 DCHECK(IsOnTaskRunnerThread(context)); |
494 DCHECK(file_info); | 495 DCHECK(file_info); |
495 | 496 |
496 base::FilePath file_path; | 497 base::FilePath file_path; |
497 base::PlatformFileError error = GetLocalFilePath(context, url, &file_path); | 498 base::File::Error error = GetLocalFilePath(context, url, &file_path); |
498 if (error != base::PLATFORM_FILE_OK) | 499 if (error != base::File::FILE_OK) |
499 return error; | 500 return error; |
500 if (base::IsLink(file_path)) | 501 if (base::IsLink(file_path)) |
501 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 502 return base::File::FILE_ERROR_NOT_FOUND; |
502 error = fileapi::NativeFileUtil::GetFileInfo(file_path, file_info); | 503 error = fileapi::NativeFileUtil::GetFileInfo(file_path, file_info); |
503 if (error != base::PLATFORM_FILE_OK) | 504 if (error != base::File::FILE_OK) |
504 return error; | 505 return error; |
505 | 506 |
506 if (platform_path) | 507 if (platform_path) |
507 *platform_path = file_path; | 508 *platform_path = file_path; |
508 if (file_info->is_directory || | 509 if (file_info->is_directory || |
509 media_path_filter_->Match(file_path)) { | 510 media_path_filter_->Match(file_path)) { |
510 return base::PLATFORM_FILE_OK; | 511 return base::File::FILE_OK; |
511 } | 512 } |
512 return base::PLATFORM_FILE_ERROR_NOT_FOUND; | 513 return base::File::FILE_ERROR_NOT_FOUND; |
513 } | 514 } |
514 | 515 |
515 base::PlatformFileError NativeMediaFileUtil::GetLocalFilePath( | 516 base::File::Error NativeMediaFileUtil::GetLocalFilePath( |
516 fileapi::FileSystemOperationContext* context, | 517 fileapi::FileSystemOperationContext* context, |
517 const fileapi::FileSystemURL& url, | 518 const fileapi::FileSystemURL& url, |
518 base::FilePath* local_file_path) { | 519 base::FilePath* local_file_path) { |
519 DCHECK(local_file_path); | 520 DCHECK(local_file_path); |
520 DCHECK(url.is_valid()); | 521 DCHECK(url.is_valid()); |
521 if (url.path().empty()) { | 522 if (url.path().empty()) { |
522 // Root direcory case, which should not be accessed. | 523 // Root direcory case, which should not be accessed. |
523 return base::PLATFORM_FILE_ERROR_ACCESS_DENIED; | 524 return base::File::FILE_ERROR_ACCESS_DENIED; |
524 } | 525 } |
525 *local_file_path = url.path(); | 526 *local_file_path = url.path(); |
526 return base::PLATFORM_FILE_OK; | 527 return base::File::FILE_OK; |
527 } | 528 } |
528 | 529 |
529 base::PlatformFileError NativeMediaFileUtil::ReadDirectorySync( | 530 base::File::Error NativeMediaFileUtil::ReadDirectorySync( |
530 fileapi::FileSystemOperationContext* context, | 531 fileapi::FileSystemOperationContext* context, |
531 const fileapi::FileSystemURL& url, | 532 const fileapi::FileSystemURL& url, |
532 EntryList* file_list) { | 533 EntryList* file_list) { |
533 DCHECK(IsOnTaskRunnerThread(context)); | 534 DCHECK(IsOnTaskRunnerThread(context)); |
534 DCHECK(file_list); | 535 DCHECK(file_list); |
535 DCHECK(file_list->empty()); | 536 DCHECK(file_list->empty()); |
536 base::PlatformFileInfo file_info; | 537 base::File::Info file_info; |
537 base::FilePath dir_path; | 538 base::FilePath dir_path; |
538 base::PlatformFileError error = | 539 base::File::Error error = |
539 GetFileInfoSync(context, url, &file_info, &dir_path); | 540 GetFileInfoSync(context, url, &file_info, &dir_path); |
540 | 541 |
541 if (error != base::PLATFORM_FILE_OK) | 542 if (error != base::File::FILE_OK) |
542 return error; | 543 return error; |
543 | 544 |
544 if (!file_info.is_directory) | 545 if (!file_info.is_directory) |
545 return base::PLATFORM_FILE_ERROR_NOT_A_DIRECTORY; | 546 return base::File::FILE_ERROR_NOT_A_DIRECTORY; |
546 | 547 |
547 base::FileEnumerator file_enum( | 548 base::FileEnumerator file_enum( |
548 dir_path, | 549 dir_path, |
549 false /* recursive */, | 550 false /* recursive */, |
550 base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES); | 551 base::FileEnumerator::FILES | base::FileEnumerator::DIRECTORIES); |
551 for (base::FilePath enum_path = file_enum.Next(); | 552 for (base::FilePath enum_path = file_enum.Next(); |
552 !enum_path.empty(); | 553 !enum_path.empty(); |
553 enum_path = file_enum.Next()) { | 554 enum_path = file_enum.Next()) { |
554 // Skip symlinks. | 555 // Skip symlinks. |
555 if (base::IsLink(enum_path)) | 556 if (base::IsLink(enum_path)) |
556 continue; | 557 continue; |
557 | 558 |
558 base::FileEnumerator::FileInfo info = file_enum.GetInfo(); | 559 base::FileEnumerator::FileInfo info = file_enum.GetInfo(); |
559 | 560 |
560 // NativeMediaFileUtil skip criteria. | 561 // NativeMediaFileUtil skip criteria. |
561 if (ShouldSkip(enum_path)) | 562 if (ShouldSkip(enum_path)) |
562 continue; | 563 continue; |
563 if (!info.IsDirectory() && !media_path_filter_->Match(enum_path)) | 564 if (!info.IsDirectory() && !media_path_filter_->Match(enum_path)) |
564 continue; | 565 continue; |
565 | 566 |
566 fileapi::DirectoryEntry entry; | 567 fileapi::DirectoryEntry entry; |
567 entry.is_directory = info.IsDirectory(); | 568 entry.is_directory = info.IsDirectory(); |
568 entry.name = enum_path.BaseName().value(); | 569 entry.name = enum_path.BaseName().value(); |
569 entry.size = info.GetSize(); | 570 entry.size = info.GetSize(); |
570 entry.last_modified_time = info.GetLastModifiedTime(); | 571 entry.last_modified_time = info.GetLastModifiedTime(); |
571 | 572 |
572 file_list->push_back(entry); | 573 file_list->push_back(entry); |
573 } | 574 } |
574 | 575 |
575 return base::PLATFORM_FILE_OK; | 576 return base::File::FILE_OK; |
576 } | 577 } |
577 | 578 |
578 base::PlatformFileError NativeMediaFileUtil::DeleteFileSync( | 579 base::File::Error NativeMediaFileUtil::DeleteFileSync( |
579 fileapi::FileSystemOperationContext* context, | 580 fileapi::FileSystemOperationContext* context, |
580 const fileapi::FileSystemURL& url) { | 581 const fileapi::FileSystemURL& url) { |
581 DCHECK(IsOnTaskRunnerThread(context)); | 582 DCHECK(IsOnTaskRunnerThread(context)); |
582 base::PlatformFileInfo file_info; | 583 base::File::Info file_info; |
583 base::FilePath file_path; | 584 base::FilePath file_path; |
584 base::PlatformFileError error = | 585 base::File::Error error = |
585 GetFileInfoSync(context, url, &file_info, &file_path); | 586 GetFileInfoSync(context, url, &file_info, &file_path); |
586 if (error != base::PLATFORM_FILE_OK) | 587 if (error != base::File::FILE_OK) |
587 return error; | 588 return error; |
588 if (file_info.is_directory) | 589 if (file_info.is_directory) |
589 return base::PLATFORM_FILE_ERROR_NOT_A_FILE; | 590 return base::File::FILE_ERROR_NOT_A_FILE; |
590 return fileapi::NativeFileUtil::DeleteFile(file_path); | 591 return fileapi::NativeFileUtil::DeleteFile(file_path); |
591 } | 592 } |
592 | 593 |
593 base::PlatformFileError NativeMediaFileUtil::DeleteDirectorySync( | 594 base::File::Error NativeMediaFileUtil::DeleteDirectorySync( |
594 fileapi::FileSystemOperationContext* context, | 595 fileapi::FileSystemOperationContext* context, |
595 const fileapi::FileSystemURL& url) { | 596 const fileapi::FileSystemURL& url) { |
596 DCHECK(IsOnTaskRunnerThread(context)); | 597 DCHECK(IsOnTaskRunnerThread(context)); |
597 base::FilePath file_path; | 598 base::FilePath file_path; |
598 base::PlatformFileError error = GetLocalFilePath(context, url, &file_path); | 599 base::File::Error error = GetLocalFilePath(context, url, &file_path); |
599 if (error != base::PLATFORM_FILE_OK) | 600 if (error != base::File::FILE_OK) |
600 return error; | 601 return error; |
601 return fileapi::NativeFileUtil::DeleteDirectory(file_path); | 602 return fileapi::NativeFileUtil::DeleteDirectory(file_path); |
602 } | 603 } |
603 | 604 |
604 base::PlatformFileError NativeMediaFileUtil::CreateSnapshotFileSync( | 605 base::File::Error NativeMediaFileUtil::CreateSnapshotFileSync( |
605 fileapi::FileSystemOperationContext* context, | 606 fileapi::FileSystemOperationContext* context, |
606 const fileapi::FileSystemURL& url, | 607 const fileapi::FileSystemURL& url, |
607 base::PlatformFileInfo* file_info, | 608 base::File::Info* file_info, |
608 base::FilePath* platform_path, | 609 base::FilePath* platform_path, |
609 scoped_refptr<webkit_blob::ShareableFileReference>* file_ref) { | 610 scoped_refptr<webkit_blob::ShareableFileReference>* file_ref) { |
610 DCHECK(IsOnTaskRunnerThread(context)); | 611 DCHECK(IsOnTaskRunnerThread(context)); |
611 base::PlatformFileError error = | 612 base::File::Error error = |
612 GetFileInfoSync(context, url, file_info, platform_path); | 613 GetFileInfoSync(context, url, file_info, platform_path); |
613 if (error == base::PLATFORM_FILE_OK && file_info->is_directory) | 614 if (error == base::File::FILE_OK && file_info->is_directory) |
614 error = base::PLATFORM_FILE_ERROR_NOT_A_FILE; | 615 error = base::File::FILE_ERROR_NOT_A_FILE; |
615 if (error == base::PLATFORM_FILE_OK) | 616 if (error == base::File::FILE_OK) |
616 error = NativeMediaFileUtil::IsMediaFile(*platform_path); | 617 error = NativeMediaFileUtil::IsMediaFile(*platform_path); |
617 | 618 |
618 // We're just returning the local file information. | 619 // We're just returning the local file information. |
619 *file_ref = scoped_refptr<webkit_blob::ShareableFileReference>(); | 620 *file_ref = scoped_refptr<webkit_blob::ShareableFileReference>(); |
620 | 621 |
621 return error; | 622 return error; |
622 } | 623 } |
623 | 624 |
624 base::PlatformFileError NativeMediaFileUtil::GetFilteredLocalFilePath( | 625 base::File::Error NativeMediaFileUtil::GetFilteredLocalFilePath( |
625 fileapi::FileSystemOperationContext* context, | 626 fileapi::FileSystemOperationContext* context, |
626 const fileapi::FileSystemURL& file_system_url, | 627 const fileapi::FileSystemURL& file_system_url, |
627 base::FilePath* local_file_path) { | 628 base::FilePath* local_file_path) { |
628 DCHECK(IsOnTaskRunnerThread(context)); | 629 DCHECK(IsOnTaskRunnerThread(context)); |
629 base::FilePath file_path; | 630 base::FilePath file_path; |
630 base::PlatformFileError error = | 631 base::File::Error error = |
631 GetLocalFilePath(context, file_system_url, &file_path); | 632 GetLocalFilePath(context, file_system_url, &file_path); |
632 if (error != base::PLATFORM_FILE_OK) | 633 if (error != base::File::FILE_OK) |
633 return error; | 634 return error; |
634 if (!media_path_filter_->Match(file_path)) | 635 if (!media_path_filter_->Match(file_path)) |
635 return base::PLATFORM_FILE_ERROR_SECURITY; | 636 return base::File::FILE_ERROR_SECURITY; |
636 | 637 |
637 *local_file_path = file_path; | 638 *local_file_path = file_path; |
638 return base::PLATFORM_FILE_OK; | 639 return base::File::FILE_OK; |
639 } | 640 } |
640 | 641 |
641 base::PlatformFileError | 642 base::File::Error |
642 NativeMediaFileUtil::GetFilteredLocalFilePathForExistingFileOrDirectory( | 643 NativeMediaFileUtil::GetFilteredLocalFilePathForExistingFileOrDirectory( |
643 fileapi::FileSystemOperationContext* context, | 644 fileapi::FileSystemOperationContext* context, |
644 const fileapi::FileSystemURL& file_system_url, | 645 const fileapi::FileSystemURL& file_system_url, |
645 base::PlatformFileError failure_error, | 646 base::File::Error failure_error, |
646 base::FilePath* local_file_path) { | 647 base::FilePath* local_file_path) { |
647 DCHECK(IsOnTaskRunnerThread(context)); | 648 DCHECK(IsOnTaskRunnerThread(context)); |
648 base::FilePath file_path; | 649 base::FilePath file_path; |
649 base::PlatformFileError error = | 650 base::File::Error error = |
650 GetLocalFilePath(context, file_system_url, &file_path); | 651 GetLocalFilePath(context, file_system_url, &file_path); |
651 if (error != base::PLATFORM_FILE_OK) | 652 if (error != base::File::FILE_OK) |
652 return error; | 653 return error; |
653 | 654 |
654 if (!base::PathExists(file_path)) | 655 if (!base::PathExists(file_path)) |
655 return failure_error; | 656 return failure_error; |
656 base::File::Info file_info; | 657 base::File::Info file_info; |
657 if (!base::GetFileInfo(file_path, &file_info)) | 658 if (!base::GetFileInfo(file_path, &file_info)) |
658 return base::PLATFORM_FILE_ERROR_FAILED; | 659 return base::File::FILE_ERROR_FAILED; |
659 | 660 |
660 if (!file_info.is_directory && | 661 if (!file_info.is_directory && |
661 !media_path_filter_->Match(file_path)) { | 662 !media_path_filter_->Match(file_path)) { |
662 return failure_error; | 663 return failure_error; |
663 } | 664 } |
664 | 665 |
665 *local_file_path = file_path; | 666 *local_file_path = file_path; |
666 return base::PLATFORM_FILE_OK; | 667 return base::File::FILE_OK; |
667 } | 668 } |
OLD | NEW |