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

Side by Side Diff: chrome/browser/media_galleries/fileapi/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: rebased Created 7 years, 7 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 "chrome/browser/media_galleries/fileapi/device_media_async_file_util.h" 5 #include "chrome/browser/media_galleries/fileapi/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 "chrome/browser/media_galleries/fileapi/filtering_file_enumerator.h" 10 #include "chrome/browser/media_galleries/fileapi/filtering_file_enumerator.h"
11 #include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_p rovider.h" 11 #include "chrome/browser/media_galleries/fileapi/media_file_system_mount_point_p rovider.h"
12 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h" 12 #include "chrome/browser/media_galleries/fileapi/media_path_filter.h"
13 #include "chrome/browser/media_galleries/fileapi/mtp_device_async_delegate.h" 13 #include "chrome/browser/media_galleries/fileapi/mtp_device_async_delegate.h"
14 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h" 14 #include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h"
15 #include "webkit/blob/shareable_file_reference.h"
15 #include "webkit/fileapi/file_system_context.h" 16 #include "webkit/fileapi/file_system_context.h"
16 #include "webkit/fileapi/file_system_operation_context.h" 17 #include "webkit/fileapi/file_system_operation_context.h"
17 #include "webkit/fileapi/file_system_task_runners.h" 18 #include "webkit/fileapi/file_system_task_runners.h"
18 #include "webkit/fileapi/file_system_url.h" 19 #include "webkit/fileapi/file_system_url.h"
19 #include "webkit/fileapi/isolated_context.h" 20 #include "webkit/fileapi/isolated_context.h"
20 21
21 using fileapi::FileSystemOperationContext; 22 using fileapi::FileSystemOperationContext;
22 using fileapi::FileSystemURL; 23 using fileapi::FileSystemURL;
24 using webkit_blob::ShareableFileReference;
23 25
24 namespace chrome { 26 namespace chrome {
25 27
26 namespace { 28 namespace {
27 29
28 const base::FilePath::CharType kDeviceMediaAsyncFileUtilTempDir[] = 30 const base::FilePath::CharType kDeviceMediaAsyncFileUtilTempDir[] =
29 FILE_PATH_LITERAL("DeviceMediaFileSystem"); 31 FILE_PATH_LITERAL("DeviceMediaFileSystem");
30 32
31 // Returns true if the current thread is IO thread. 33 // Returns true if the current thread is IO thread.
32 bool IsOnIOThread(FileSystemOperationContext* context) { 34 bool IsOnIOThread(FileSystemOperationContext* context) {
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 304
303 void DeviceMediaAsyncFileUtil::OnReadDirectoryError( 305 void DeviceMediaAsyncFileUtil::OnReadDirectoryError(
304 const AsyncFileUtil::ReadDirectoryCallback& callback, 306 const AsyncFileUtil::ReadDirectoryCallback& callback,
305 base::PlatformFileError error) { 307 base::PlatformFileError error) {
306 if (!callback.is_null()) 308 if (!callback.is_null())
307 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/); 309 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/);
308 } 310 }
309 311
310 void DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile( 312 void DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile(
311 const AsyncFileUtil::CreateSnapshotFileCallback& callback, 313 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
314 base::SequencedTaskRunner* media_task_runner,
312 const base::PlatformFileInfo& file_info, 315 const base::PlatformFileInfo& file_info,
313 const base::FilePath& platform_path) { 316 const base::FilePath& platform_path) {
314 if (!callback.is_null()) 317 if (callback.is_null())
315 callback.Run(base::PLATFORM_FILE_OK, file_info, platform_path, 318 return;
316 fileapi::kSnapshotFileTemporary); 319 callback.Run(base::PLATFORM_FILE_OK, file_info, platform_path,
320 ShareableFileReference::GetOrCreate(
321 platform_path,
322 ShareableFileReference::DELETE_ON_FINAL_RELEASE,
323 media_task_runner));
317 } 324 }
318 325
319 void DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError( 326 void DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError(
320 const AsyncFileUtil::CreateSnapshotFileCallback& callback, 327 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
321 base::PlatformFileError error) { 328 base::PlatformFileError error) {
322 if (!callback.is_null()) 329 if (!callback.is_null())
323 callback.Run(error, base::PlatformFileInfo(), base::FilePath(), 330 callback.Run(error, base::PlatformFileInfo(), base::FilePath(),
324 fileapi::kSnapshotFileTemporary); 331 scoped_refptr<ShareableFileReference>());
325 } 332 }
326 333
327 void DeviceMediaAsyncFileUtil::OnSnapshotFileCreatedRunTask( 334 void DeviceMediaAsyncFileUtil::OnSnapshotFileCreatedRunTask(
328 FileSystemOperationContext* context, 335 FileSystemOperationContext* context,
329 const AsyncFileUtil::CreateSnapshotFileCallback& callback, 336 const AsyncFileUtil::CreateSnapshotFileCallback& callback,
330 const base::FilePath& device_file_path, 337 const base::FilePath& device_file_path,
331 base::FilePath* snapshot_file_path) { 338 base::FilePath* snapshot_file_path) {
332 DCHECK(IsOnIOThread(context)); 339 DCHECK(IsOnIOThread(context));
333 if (!snapshot_file_path || snapshot_file_path->empty()) { 340 if (!snapshot_file_path || snapshot_file_path->empty()) {
334 OnCreateSnapshotFileError(callback, base::PLATFORM_FILE_ERROR_FAILED); 341 OnCreateSnapshotFileError(callback, base::PLATFORM_FILE_ERROR_FAILED);
335 return; 342 return;
336 } 343 }
337 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(context); 344 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(context);
338 if (!delegate) { 345 if (!delegate) {
339 OnCreateSnapshotFileError(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND); 346 OnCreateSnapshotFileError(callback, base::PLATFORM_FILE_ERROR_NOT_FOUND);
340 return; 347 return;
341 } 348 }
342 delegate->CreateSnapshotFile( 349 delegate->CreateSnapshotFile(
343 device_file_path, 350 device_file_path,
344 *snapshot_file_path, 351 *snapshot_file_path,
345 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile, 352 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCreateSnapshotFile,
346 weak_ptr_factory_.GetWeakPtr(), 353 weak_ptr_factory_.GetWeakPtr(),
347 callback), 354 callback,
355 make_scoped_refptr(context->task_runner())),
348 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError, 356 base::Bind(&DeviceMediaAsyncFileUtil::OnCreateSnapshotFileError,
349 weak_ptr_factory_.GetWeakPtr(), 357 weak_ptr_factory_.GetWeakPtr(),
350 callback)); 358 callback));
351 } 359 }
352 360
353 } // namespace chrome 361 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698