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

Unified Diff: chrome/browser/media_galleries/linux/mtp_device_delegate_impl_linux.cc

Issue 947943002: Implement CopyFileFromLocal of MTPDeviceAsyncDelegate. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix failed test case. Created 5 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/media_galleries/linux/mtp_device_delegate_impl_linux.cc
diff --git a/chrome/browser/media_galleries/linux/mtp_device_delegate_impl_linux.cc b/chrome/browser/media_galleries/linux/mtp_device_delegate_impl_linux.cc
index b1cd91c59e85b22ebcf1fb10cdbc323495c7d5be..f90e2b62c73b62b5bc1754c2986409d90be39c8c 100644
--- a/chrome/browser/media_galleries/linux/mtp_device_delegate_impl_linux.cc
+++ b/chrome/browser/media_galleries/linux/mtp_device_delegate_impl_linux.cc
@@ -4,6 +4,7 @@
#include "chrome/browser/media_galleries/linux/mtp_device_delegate_impl_linux.h"
+#include <fcntl.h>
#include <algorithm>
#include <vector>
@@ -169,6 +170,24 @@ void ReadBytesOnUIThread(
task_helper->ReadBytes(request);
}
+void CopyFileFromLocalOnUIThread(
+ const std::string& storage_name,
+ const uint32 source_file_descriptor,
+ const uint32 parent_id,
+ const std::string& file_name,
+ const MTPDeviceTaskHelper::CopyFileFromLocalSuccessCallback&
+ success_callback,
+ const MTPDeviceTaskHelper::ErrorCallback& error_callback) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
+ MTPDeviceTaskHelper* task_helper =
+ GetDeviceTaskHelperForStorage(storage_name);
+ if (!task_helper)
+ return;
+ task_helper->CopyFileFromLocal(storage_name, source_file_descriptor,
+ parent_id, file_name, success_callback,
+ error_callback);
+}
+
// Closes the device storage specified by the |storage_name| and destroys the
// MTPDeviceTaskHelper object associated with the device storage.
//
@@ -432,6 +451,23 @@ void MTPDeviceDelegateImplLinux::ReadBytes(
closure));
}
+void MTPDeviceDelegateImplLinux::CopyFileFromLocal(
+ const base::FilePath& source_file_path,
+ const base::FilePath& device_file_path,
+ const CopyFileFromLocalSuccessCallback& success_callback,
+ const ErrorCallback& error_callback) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
+ DCHECK(!source_file_path.empty());
+ DCHECK(!device_file_path.empty());
+ base::Closure closure =
+ base::Bind(&MTPDeviceDelegateImplLinux::CopyFileFromLocalInternal,
+ weak_ptr_factory_.GetWeakPtr(), source_file_path,
+ device_file_path, success_callback, error_callback);
+ EnsureInitAndRunTask(PendingTaskInfo(device_file_path.DirName(),
+ content::BrowserThread::IO, FROM_HERE,
+ closure));
+}
+
void MTPDeviceDelegateImplLinux::CancelPendingTasksAndDeleteDelegate() {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
// To cancel all the pending tasks, destroy the MTPDeviceTaskHelper object.
@@ -580,6 +616,40 @@ void MTPDeviceDelegateImplLinux::ReadBytesInternal(
PendingRequestDone();
}
+void MTPDeviceDelegateImplLinux::CopyFileFromLocalInternal(
+ const base::FilePath& source_file_path,
+ const base::FilePath& device_file_path,
+ const CopyFileFromLocalSuccessCallback& success_callback,
+ const ErrorCallback& error_callback) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
+
+ uint32 parent_id;
+ if (CachedPathToId(device_file_path.DirName(), &parent_id)) {
+ const uint32 source_file_descriptor =
+ open(source_file_path.value().c_str(), O_RDONLY);
Lei Zhang 2015/02/24 23:35:48 open() can fail.
yawano 2015/02/26 07:27:54 Done.
+
+ CopyFileFromLocalSuccessCallback success_callback_wrapper =
+ base::Bind(&MTPDeviceDelegateImplLinux::OnDidCopyFileFromLocal,
+ weak_ptr_factory_.GetWeakPtr(), success_callback,
+ source_file_descriptor);
+
+ ErrorCallback error_callback_wrapper = base::Bind(
+ &MTPDeviceDelegateImplLinux::HandleCopyFileFromLocalError,
+ weak_ptr_factory_.GetWeakPtr(), error_callback, source_file_descriptor);
+
+ base::Closure closure = base::Bind(base::Bind(
Lei Zhang 2015/02/24 23:35:48 I think you copied a typo from elsewhere in the fi
yawano 2015/02/26 07:27:54 Done.
+ &CopyFileFromLocalOnUIThread, storage_name_, source_file_descriptor,
+ parent_id, device_file_path.BaseName().value(),
+ success_callback_wrapper, error_callback_wrapper));
+ EnsureInitAndRunTask(PendingTaskInfo(
+ base::FilePath(), content::BrowserThread::UI, FROM_HERE, closure));
+ } else {
+ error_callback.Run(base::File::FILE_ERROR_INVALID_OPERATION);
+ }
+
+ PendingRequestDone();
+}
+
void MTPDeviceDelegateImplLinux::EnsureInitAndRunTask(
const PendingTaskInfo& task_info) {
DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
@@ -854,6 +924,27 @@ void MTPDeviceDelegateImplLinux::OnFillFileCacheFailed(
pending_tasks_.front().path.clear();
}
+void MTPDeviceDelegateImplLinux::OnDidCopyFileFromLocal(
+ const CopyFileFromLocalSuccessCallback& success_callback,
+ const uint32 source_file_descriptor) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
+
+ close(source_file_descriptor);
Lei Zhang 2015/02/24 23:35:48 Wrap this in IGNORE_EINTR()
yawano 2015/02/26 07:27:54 Done.
+ success_callback.Run();
+ PendingRequestDone();
+}
+
+void MTPDeviceDelegateImplLinux::HandleCopyFileFromLocalError(
+ const ErrorCallback& error_callback,
+ const uint32 source_file_descriptor,
+ base::File::Error error) {
+ DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
+
+ close(source_file_descriptor);
+ error_callback.Run(error);
+ PendingRequestDone();
+}
+
void MTPDeviceDelegateImplLinux::HandleDeviceFileError(
const ErrorCallback& error_callback,
uint32 file_id,

Powered by Google App Engine
This is Rietveld 408576698