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

Side by Side Diff: chrome/browser/media_galleries/fileapi/device_media_async_file_util.cc

Issue 947943002: Implement CopyFileFromLocal of MTPDeviceAsyncDelegate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix wrong function definition. Created 5 years, 9 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
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/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/single_thread_task_runner.h" 9 #include "base/single_thread_task_runner.h"
10 #include "base/task_runner_util.h" 10 #include "base/task_runner_util.h"
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 // Called when ReadDirectory method call failed to enumerate the directory 73 // Called when ReadDirectory method call failed to enumerate the directory
74 // objects. |callback| is invoked to notify the caller about the |error| 74 // objects. |callback| is invoked to notify the caller about the |error|
75 // that occured while reading the directory objects. 75 // that occured while reading the directory objects.
76 void OnReadDirectoryError(const AsyncFileUtil::ReadDirectoryCallback& callback, 76 void OnReadDirectoryError(const AsyncFileUtil::ReadDirectoryCallback& callback,
77 base::File::Error error) { 77 base::File::Error error) {
78 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 78 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
79 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/); 79 callback.Run(error, AsyncFileUtil::EntryList(), false /*no more*/);
80 } 80 }
81 81
82 // Called when CopyInForeignFile method call failed.
83 void OnCopyInForeignFileError(const AsyncFileUtil::StatusCallback& callback,
84 base::File::Error error) {
85 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
86 callback.Run(error);
87 }
88
82 // Called on a blocking pool thread to create a snapshot file to hold the 89 // Called on a blocking pool thread to create a snapshot file to hold the
83 // contents of |device_file_path|. The snapshot file is created in the 90 // contents of |device_file_path|. The snapshot file is created in the
84 // "profile_path/kDeviceMediaAsyncFileUtilTempDir" directory. Return the 91 // "profile_path/kDeviceMediaAsyncFileUtilTempDir" directory. Return the
85 // snapshot file path or an empty path on failure. 92 // snapshot file path or an empty path on failure.
86 base::FilePath CreateSnapshotFileOnBlockingPool( 93 base::FilePath CreateSnapshotFileOnBlockingPool(
87 const base::FilePath& device_file_path, 94 const base::FilePath& device_file_path,
88 const base::FilePath& profile_path) { 95 const base::FilePath& profile_path) {
89 base::FilePath snapshot_file_path; 96 base::FilePath snapshot_file_path;
90 base::FilePath media_file_system_dir_path = 97 base::FilePath media_file_system_dir_path =
91 profile_path.AppendASCII(kDeviceMediaAsyncFileUtilTempDir); 98 profile_path.AppendASCII(kDeviceMediaAsyncFileUtilTempDir);
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 void DeviceMediaAsyncFileUtil::ReadDirectory( 330 void DeviceMediaAsyncFileUtil::ReadDirectory(
324 scoped_ptr<FileSystemOperationContext> context, 331 scoped_ptr<FileSystemOperationContext> context,
325 const FileSystemURL& url, 332 const FileSystemURL& url,
326 const ReadDirectoryCallback& callback) { 333 const ReadDirectoryCallback& callback) {
327 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 334 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
328 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url); 335 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(url);
329 if (!delegate) { 336 if (!delegate) {
330 OnReadDirectoryError(callback, base::File::FILE_ERROR_NOT_FOUND); 337 OnReadDirectoryError(callback, base::File::FILE_ERROR_NOT_FOUND);
331 return; 338 return;
332 } 339 }
340
333 delegate->ReadDirectory( 341 delegate->ReadDirectory(
334 url.path(), 342 url.path(),
335 base::Bind(&DeviceMediaAsyncFileUtil::OnDidReadDirectory, 343 base::Bind(&DeviceMediaAsyncFileUtil::OnDidReadDirectory,
336 weak_ptr_factory_.GetWeakPtr(), 344 weak_ptr_factory_.GetWeakPtr(),
337 make_scoped_refptr(context->task_runner()), 345 make_scoped_refptr(context->task_runner()),
338 callback), 346 callback),
339 base::Bind(&OnReadDirectoryError, callback)); 347 base::Bind(&OnReadDirectoryError, callback));
340 } 348 }
341 349
342 void DeviceMediaAsyncFileUtil::Touch( 350 void DeviceMediaAsyncFileUtil::Touch(
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 NOTIMPLEMENTED(); 390 NOTIMPLEMENTED();
383 callback.Run(base::File::FILE_ERROR_SECURITY); 391 callback.Run(base::File::FILE_ERROR_SECURITY);
384 } 392 }
385 393
386 void DeviceMediaAsyncFileUtil::CopyInForeignFile( 394 void DeviceMediaAsyncFileUtil::CopyInForeignFile(
387 scoped_ptr<FileSystemOperationContext> context, 395 scoped_ptr<FileSystemOperationContext> context,
388 const base::FilePath& src_file_path, 396 const base::FilePath& src_file_path,
389 const FileSystemURL& dest_url, 397 const FileSystemURL& dest_url,
390 const StatusCallback& callback) { 398 const StatusCallback& callback) {
391 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 399 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
392 NOTIMPLEMENTED(); 400
393 callback.Run(base::File::FILE_ERROR_SECURITY); 401 MTPDeviceAsyncDelegate* delegate = GetMTPDeviceDelegate(dest_url);
402 if (!delegate) {
403 OnCopyInForeignFileError(callback, base::File::FILE_ERROR_NOT_FOUND);
404 return;
405 }
406 if (delegate->IsReadOnly()) {
407 OnCopyInForeignFileError(callback, base::File::FILE_ERROR_SECURITY);
408 return;
409 }
410
411 delegate->CopyFileFromLocal(
412 src_file_path, dest_url.path(),
413 base::Bind(&DeviceMediaAsyncFileUtil::OnDidCopyInForeignFile,
414 weak_ptr_factory_.GetWeakPtr(), callback),
415 base::Bind(&OnCopyInForeignFileError, callback));
394 } 416 }
395 417
396 void DeviceMediaAsyncFileUtil::DeleteFile( 418 void DeviceMediaAsyncFileUtil::DeleteFile(
397 scoped_ptr<FileSystemOperationContext> context, 419 scoped_ptr<FileSystemOperationContext> context,
398 const FileSystemURL& url, 420 const FileSystemURL& url,
399 const StatusCallback& callback) { 421 const StatusCallback& callback) {
400 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 422 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
401 NOTIMPLEMENTED(); 423 NOTIMPLEMENTED();
402 callback.Run(base::File::FILE_ERROR_SECURITY); 424 callback.Run(base::File::FILE_ERROR_SECURITY);
403 } 425 }
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 526
505 base::PostTaskAndReplyWithResult( 527 base::PostTaskAndReplyWithResult(
506 task_runner, 528 task_runner,
507 FROM_HERE, 529 FROM_HERE,
508 base::Bind(&MediaPathFilterWrapper::FilterMediaEntries, 530 base::Bind(&MediaPathFilterWrapper::FilterMediaEntries,
509 media_path_filter_wrapper_, 531 media_path_filter_wrapper_,
510 file_list), 532 file_list),
511 base::Bind(&OnDidCheckMediaForReadDirectory, callback, has_more)); 533 base::Bind(&OnDidCheckMediaForReadDirectory, callback, has_more));
512 } 534 }
513 535
536 void DeviceMediaAsyncFileUtil::OnDidCopyInForeignFile(
537 const StatusCallback& callback) {
538 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
539
540 callback.Run(base::File::FILE_OK);
541 }
542
514 bool DeviceMediaAsyncFileUtil::validate_media_files() const { 543 bool DeviceMediaAsyncFileUtil::validate_media_files() const {
515 return media_path_filter_wrapper_.get() != NULL; 544 return media_path_filter_wrapper_.get() != NULL;
516 } 545 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698