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

Side by Side Diff: chrome/browser/media_galleries/linux/mtp_device_delegate_impl_linux.cc

Issue 1007173003: Implement MoveFileLocal (with rename operation). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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) 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/linux/mtp_device_delegate_impl_linux.h" 5 #include "chrome/browser/media_galleries/linux/mtp_device_delegate_impl_linux.h"
6 6
7 #include <fcntl.h> 7 #include <fcntl.h>
8 #include <algorithm> 8 #include <algorithm>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 const bool read_only, 182 const bool read_only,
183 const MTPDeviceAsyncDelegate::ReadBytesRequest& request) { 183 const MTPDeviceAsyncDelegate::ReadBytesRequest& request) {
184 DCHECK_CURRENTLY_ON(content::BrowserThread::UI); 184 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
185 MTPDeviceTaskHelper* task_helper = 185 MTPDeviceTaskHelper* task_helper =
186 GetDeviceTaskHelperForStorage(storage_name, read_only); 186 GetDeviceTaskHelperForStorage(storage_name, read_only);
187 if (!task_helper) 187 if (!task_helper)
188 return; 188 return;
189 task_helper->ReadBytes(request); 189 task_helper->ReadBytes(request);
190 } 190 }
191 191
192 // Renames |object_id| to |new_name|.
193 //
194 // |storage_name| specifies the name of the storage device.
195 // |read_only| specifies the mode of the storage device.
196 // |object_id| is an id of object to be renamed.
197 // |new_name| is new name of the object.
198 // |success_callback| is called when the object is renamed successfully.
199 // |error_callback| is called when it fails to rename the object.
200 // |success_callback| and |error_callback| runs on the IO thread.
201 void RenameObjectOnUIThread(
202 const std::string& storage_name,
203 const bool read_only,
204 const uint32 object_id,
205 const std::string& new_name,
206 const MTPDeviceTaskHelper::RenameObjectSuccessCallback& success_callback,
207 const MTPDeviceTaskHelper::ErrorCallback& error_callback) {
208 DCHECK_CURRENTLY_ON(content::BrowserThread::UI);
209 MTPDeviceTaskHelper* task_helper =
210 GetDeviceTaskHelperForStorage(storage_name, read_only);
211 if (!task_helper)
212 return;
213 task_helper->RenameObject(object_id, new_name, success_callback,
214 error_callback);
215 }
216
192 // Copies the file |source_file_descriptor| to |file_name| in |parent_id|. 217 // Copies the file |source_file_descriptor| to |file_name| in |parent_id|.
193 // 218 //
194 // |storage_name| specifies the name of the storage device. 219 // |storage_name| specifies the name of the storage device.
195 // |read_only| specifies the mode of the storage device. 220 // |read_only| specifies the mode of the storage device.
196 // |source_file_descriptor| file descriptor of source file. 221 // |source_file_descriptor| file descriptor of source file.
197 // |parent_id| object id of a target directory. 222 // |parent_id| object id of a target directory.
198 // |file_name| file name of a target file. 223 // |file_name| file name of a target file.
199 // |success_callback| is called when the file is copied successfully. 224 // |success_callback| is called when the file is copied successfully.
200 // |error_callback| is called when it fails to copy file. 225 // |error_callback| is called when it fails to copy file.
201 // Since this method does not close the file descriptor, callbacks are 226 // Since this method does not close the file descriptor, callbacks are
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 840 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
816 841
817 if (source_file_info.is_directory) { 842 if (source_file_info.is_directory) {
818 error_callback.Run(base::File::FILE_ERROR_NOT_A_FILE); 843 error_callback.Run(base::File::FILE_ERROR_NOT_A_FILE);
819 PendingRequestDone(); 844 PendingRequestDone();
820 return; 845 return;
821 } 846 }
822 847
823 if (source_file_path.DirName() == device_file_path.DirName()) { 848 if (source_file_path.DirName() == device_file_path.DirName()) {
824 // If a file is moved in a same directory, rename the file. 849 // If a file is moved in a same directory, rename the file.
825 // TODO(yawano) Implement rename operation. 850 uint32 file_id;
826 error_callback.Run(base::File::FILE_ERROR_SECURITY); 851 if (CachedPathToId(source_file_path, &file_id)) {
852 const MTPDeviceTaskHelper::RenameObjectSuccessCallback
853 success_callback_wrapper = base::Bind(
854 &MTPDeviceDelegateImplLinux::OnDidMoveFileLocalWithRename,
855 weak_ptr_factory_.GetWeakPtr(), success_callback, file_id);
856 const MTPDeviceTaskHelper::ErrorCallback error_callback_wrapper =
857 base::Bind(&MTPDeviceDelegateImplLinux::HandleDeviceFileError,
858 weak_ptr_factory_.GetWeakPtr(), error_callback, file_id);
859 const base::Closure closure =
860 base::Bind(&RenameObjectOnUIThread, storage_name_, read_only_,
861 file_id, device_file_path.BaseName().value(),
862 success_callback_wrapper, error_callback_wrapper);
863 EnsureInitAndRunTask(PendingTaskInfo(
864 base::FilePath(), content::BrowserThread::UI, FROM_HERE, closure));
865 } else {
866 error_callback.Run(base::File::FILE_ERROR_NOT_FOUND);
867 }
827 } else { 868 } else {
828 // If a file is moved to a different directory, create a copy to the 869 // If a file is moved to a different directory, create a copy to the
829 // destination path, and remove source file. 870 // destination path, and remove source file.
830 const CopyFileLocalSuccessCallback& success_callback_wrapper = 871 const CopyFileLocalSuccessCallback& success_callback_wrapper =
831 base::Bind(&MTPDeviceDelegateImplLinux::DeleteFileInternal, 872 base::Bind(&MTPDeviceDelegateImplLinux::DeleteFileInternal,
832 weak_ptr_factory_.GetWeakPtr(), source_file_path, 873 weak_ptr_factory_.GetWeakPtr(), source_file_path,
833 success_callback, error_callback, source_file_info); 874 success_callback, error_callback, source_file_info);
834 CopyFileLocal(source_file_path, device_file_path, 875 CopyFileLocal(source_file_path, device_file_path,
835 create_temporary_file_callback, 876 create_temporary_file_callback,
836 base::Bind(&FakeCopyFileProgressCallback), 877 base::Bind(&FakeCopyFileProgressCallback),
(...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 1348
1308 void MTPDeviceDelegateImplLinux::OnDidCopyFileFromLocalOfCopyFileLocal( 1349 void MTPDeviceDelegateImplLinux::OnDidCopyFileFromLocalOfCopyFileLocal(
1309 const CopyFileFromLocalSuccessCallback success_callback, 1350 const CopyFileFromLocalSuccessCallback success_callback,
1310 const base::FilePath& temporary_file_path) { 1351 const base::FilePath& temporary_file_path) {
1311 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 1352 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
1312 1353
1313 DeleteTemporaryFile(temporary_file_path); 1354 DeleteTemporaryFile(temporary_file_path);
1314 success_callback.Run(); 1355 success_callback.Run();
1315 } 1356 }
1316 1357
1358 void MTPDeviceDelegateImplLinux::OnDidMoveFileLocalWithRename(
1359 const MoveFileLocalSuccessCallback& success_callback,
1360 const uint32 file_id) {
1361 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
1362
1363 EvictCachedPathToId(file_id);
1364 success_callback.Run();
1365 PendingRequestDone();
1366 }
1367
1317 void MTPDeviceDelegateImplLinux::OnDidCopyFileFromLocal( 1368 void MTPDeviceDelegateImplLinux::OnDidCopyFileFromLocal(
1318 const CopyFileFromLocalSuccessCallback& success_callback, 1369 const CopyFileFromLocalSuccessCallback& success_callback,
1319 const int source_file_descriptor) { 1370 const int source_file_descriptor) {
1320 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 1371 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
1321 1372
1322 const base::Closure closure = base::Bind(&CloseFileDescriptor, 1373 const base::Closure closure = base::Bind(&CloseFileDescriptor,
1323 source_file_descriptor); 1374 source_file_descriptor);
1324 1375
1325 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE, 1376 content::BrowserThread::PostTask(content::BrowserThread::FILE, FROM_HERE,
1326 closure); 1377 closure);
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1466 } 1517 }
1467 } 1518 }
1468 1519
1469 void CreateMTPDeviceAsyncDelegate( 1520 void CreateMTPDeviceAsyncDelegate(
1470 const std::string& device_location, 1521 const std::string& device_location,
1471 const bool read_only, 1522 const bool read_only,
1472 const CreateMTPDeviceAsyncDelegateCallback& callback) { 1523 const CreateMTPDeviceAsyncDelegateCallback& callback) {
1473 DCHECK_CURRENTLY_ON(content::BrowserThread::IO); 1524 DCHECK_CURRENTLY_ON(content::BrowserThread::IO);
1474 callback.Run(new MTPDeviceDelegateImplLinux(device_location, read_only)); 1525 callback.Run(new MTPDeviceDelegateImplLinux(device_location, read_only));
1475 } 1526 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698