Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(351)

Side by Side Diff: webkit/fileapi/media/device_media_async_file_util.cc

Issue 14075016: Change some snapshot- or temporary-file related changes to use ScopedFile (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "webkit/fileapi/media/device_media_async_file_util.h" 5 #include "webkit/fileapi/media/device_media_async_file_util.h"
6 6
7 #include "base/callback.h" 7 #include "base/callback.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "webkit/blob/shareable_file_reference.h"
10 #include "webkit/fileapi/file_system_context.h" 11 #include "webkit/fileapi/file_system_context.h"
11 #include "webkit/fileapi/file_system_operation_context.h" 12 #include "webkit/fileapi/file_system_operation_context.h"
12 #include "webkit/fileapi/file_system_task_runners.h" 13 #include "webkit/fileapi/file_system_task_runners.h"
13 #include "webkit/fileapi/file_system_url.h" 14 #include "webkit/fileapi/file_system_url.h"
14 #include "webkit/fileapi/isolated_context.h" 15 #include "webkit/fileapi/isolated_context.h"
15 #include "webkit/fileapi/media/filtering_file_enumerator.h" 16 #include "webkit/fileapi/media/filtering_file_enumerator.h"
16 #include "webkit/fileapi/media/media_file_system_mount_point_provider.h" 17 #include "webkit/fileapi/media/media_file_system_mount_point_provider.h"
17 #include "webkit/fileapi/media/media_path_filter.h" 18 #include "webkit/fileapi/media/media_path_filter.h"
18 #include "webkit/fileapi/media/mtp_device_async_delegate.h" 19 #include "webkit/fileapi/media/mtp_device_async_delegate.h"
19 #include "webkit/fileapi/media/mtp_device_map_service.h" 20 #include "webkit/fileapi/media/mtp_device_map_service.h"
20 21
22 using webkit_blob::ShareableFileReference;
23
21 namespace fileapi { 24 namespace fileapi {
22 25
23 namespace { 26 namespace {
24 27
25 const base::FilePath::CharType kDeviceMediaAsyncFileUtilTempDir[] = 28 const base::FilePath::CharType kDeviceMediaAsyncFileUtilTempDir[] =
26 FILE_PATH_LITERAL("DeviceMediaFileSystem"); 29 FILE_PATH_LITERAL("DeviceMediaFileSystem");
27 30
28 // Returns true if the current thread is IO thread. 31 // Returns true if the current thread is IO thread.
29 bool IsOnIOThread(FileSystemOperationContext* context) { 32 bool IsOnIOThread(FileSystemOperationContext* context) {
30 return context->file_system_context()->task_runners()-> 33 return context->file_system_context()->task_runners()->
(...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 302
300 void DeviceMediaAsyncFileUtil::OnReadDirectoryError( 303 void DeviceMediaAsyncFileUtil::OnReadDirectoryError(
301 const AsyncFileUtil::ReadDirectoryCallback& callback, 304 const AsyncFileUtil::ReadDirectoryCallback& callback,
302 base::PlatformFileError error) { 305 base::PlatformFileError error) {
303 if (!callback.is_null()) 306 if (!callback.is_null())
304 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/); 307 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/);
305 } 308 }
306 309
307 void DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile( 310 void DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile(
308 const AsyncFileUtil::CreateSnapshotFileCallback& callback, 311 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
312 base::SequencedTaskRunner* media_task_runner,
309 const base::PlatformFileInfo& file_info, 313 const base::PlatformFileInfo& file_info,
310 const base::FilePath& platform_path) { 314 const base::FilePath& platform_path) {
311 if (!callback.is_null()) 315 if (callback.is_null())
312 callback.Run(base::PLATFORM_FILE_OK, file_info, platform_path, 316 return;
313 kSnapshotFileTemporary); 317 callback.Run(base::PLATFORM_FILE_OK, file_info, platform_path,
318 ShareableFileReference::GetOrCreate(
319 platform_path,
320 ShareableFileReference::DELETE_ON_FINAL_RELEASE,
321 media_task_runner));
314 } 322 }
315 323
316 void DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError( 324 void DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError(
317 const AsyncFileUtil::CreateSnapshotFileCallback& callback, 325 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
318 base::PlatformFileError error) { 326 base::PlatformFileError error) {
319 if (!callback.is_null()) 327 if (!callback.is_null())
320 callback.Run(error, base::PlatformFileInfo(), base::FilePath(), 328 callback.Run(error, base::PlatformFileInfo(), base::FilePath(),
321 kSnapshotFileTemporary); 329 scoped_refptr<ShareableFileReference>());
322 } 330 }
323 331
324 void DeviceMediaAsyncFileUtil::OnSnapshotFileCreatedRunTask( 332 void DeviceMediaAsyncFileUtil::OnSnapshotFileCreatedRunTask(
325 FileSystemOperationContext* context, 333 FileSystemOperationContext* context,
326 const AsyncFileUtil::CreateSnapshotFileCallback& callback, 334 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
327 const base::FilePath& device_file_path, 335 const base::FilePath& device_file_path,
328 base::FilePath* snapshot_file_path) { 336 base::FilePath* snapshot_file_path) {
329 DCHECK(IsOnIOThread(context)); 337 DCHECK(IsOnIOThread(context));
330 if (!snapshot_file_path || snapshot_file_path->empty()) { 338 if (!snapshot_file_path || snapshot_file_path->empty()) {
331 OnCreateSnapshotFileError(callback, base::PLATFORM_FILE_ERROR_FAILED); 339 OnCreateSnapshotFileError(callback, base::PLATFORM_FILE_ERROR_FAILED);
332 return; 340 return;
333 } 341 }
334 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(context); 342 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(context);
335 if (!delegate) { 343 if (!delegate) {
336 OnCreateSnapshotFileError(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); 344 OnCreateSnapshotFileError(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND);
337 return; 345 return;
338 } 346 }
339 delegate->CreateSnapshotFile( 347 delegate->CreateSnapshotFile(
340 device_file_path, 348 device_file_path,
341 *snapshot_file_path, 349 *snapshot_file_path,
342 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile, 350 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile,
343 weak_ptr_factory_.GetWeakPtr(), 351 weak_ptr_factory_.GetWeakPtr(),
344 callback), 352 callback,
353 make_scoped_refptr(context->task_runner())),
345 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError, 354 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError,
346 weak_ptr_factory_.GetWeakPtr(), 355 weak_ptr_factory_.GetWeakPtr(),
347 callback)); 356 callback));
348 } 357 }
349 358
350 } // namespace fileapi 359 } // namespace fileapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698