OLD | NEW |
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/chromeos/drive/file_system/copy_operation.h" | 5 #include "chrome/browser/chromeos/drive/file_system/copy_operation.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/json/json_file_value_serializer.h" | 10 #include "base/json/json_file_value_serializer.h" |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 remote_file_path(in_remote_file_path), | 68 remote_file_path(in_remote_file_path), |
69 callback(in_callback) {} | 69 callback(in_callback) {} |
70 | 70 |
71 const base::FilePath local_file_path; | 71 const base::FilePath local_file_path; |
72 const base::FilePath remote_file_path; | 72 const base::FilePath remote_file_path; |
73 const FileOperationCallback callback; | 73 const FileOperationCallback callback; |
74 }; | 74 }; |
75 | 75 |
76 CopyOperation::CopyOperation( | 76 CopyOperation::CopyOperation( |
77 JobScheduler* job_scheduler, | 77 JobScheduler* job_scheduler, |
78 DriveFileSystemInterface* drive_file_system, | 78 DriveFileSystemInterface* file_system, |
79 internal::ResourceMetadata* metadata, | 79 internal::ResourceMetadata* metadata, |
80 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, | 80 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, |
81 OperationObserver* observer) | 81 OperationObserver* observer) |
82 : job_scheduler_(job_scheduler), | 82 : job_scheduler_(job_scheduler), |
83 drive_file_system_(drive_file_system), | 83 file_system_(file_system), |
84 metadata_(metadata), | 84 metadata_(metadata), |
85 blocking_task_runner_(blocking_task_runner), | 85 blocking_task_runner_(blocking_task_runner), |
86 observer_(observer), | 86 observer_(observer), |
87 move_operation_(new MoveOperation(job_scheduler, | 87 move_operation_(new MoveOperation(job_scheduler, |
88 metadata, | 88 metadata, |
89 observer)), | 89 observer)), |
90 weak_ptr_factory_(this) { | 90 weak_ptr_factory_(this) { |
91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 91 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
92 } | 92 } |
93 | 93 |
(...skipping 16 matching lines...) Expand all Loading... |
110 callback)); | 110 callback)); |
111 } | 111 } |
112 | 112 |
113 void CopyOperation::TransferFileFromRemoteToLocal( | 113 void CopyOperation::TransferFileFromRemoteToLocal( |
114 const base::FilePath& remote_src_file_path, | 114 const base::FilePath& remote_src_file_path, |
115 const base::FilePath& local_dest_file_path, | 115 const base::FilePath& local_dest_file_path, |
116 const FileOperationCallback& callback) { | 116 const FileOperationCallback& callback) { |
117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 117 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
118 DCHECK(!callback.is_null()); | 118 DCHECK(!callback.is_null()); |
119 | 119 |
120 drive_file_system_->GetFileByPath( | 120 file_system_->GetFileByPath( |
121 remote_src_file_path, | 121 remote_src_file_path, |
122 base::Bind(&CopyOperation::OnGetFileCompleteForTransferFile, | 122 base::Bind(&CopyOperation::OnGetFileCompleteForTransferFile, |
123 weak_ptr_factory_.GetWeakPtr(), | 123 weak_ptr_factory_.GetWeakPtr(), |
124 local_dest_file_path, | 124 local_dest_file_path, |
125 callback)); | 125 callback)); |
126 } | 126 } |
127 | 127 |
128 void CopyOperation::OnGetFileCompleteForTransferFile( | 128 void CopyOperation::OnGetFileCompleteForTransferFile( |
129 const base::FilePath& local_dest_file_path, | 129 const base::FilePath& local_dest_file_path, |
130 const FileOperationCallback& callback, | 130 const FileOperationCallback& callback, |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 src_file_proto->resource_id(), | 291 src_file_proto->resource_id(), |
292 // Drop the document extension, which should not be in the title. | 292 // Drop the document extension, which should not be in the title. |
293 dest_file_path.BaseName().RemoveExtension().value(), | 293 dest_file_path.BaseName().RemoveExtension().value(), |
294 callback); | 294 callback); |
295 return; | 295 return; |
296 } | 296 } |
297 | 297 |
298 // TODO(kochi): Reimplement this once the server API supports | 298 // TODO(kochi): Reimplement this once the server API supports |
299 // copying of regular files directly on the server side. crbug.com/138273 | 299 // copying of regular files directly on the server side. crbug.com/138273 |
300 const base::FilePath& src_file_path = result->first.path; | 300 const base::FilePath& src_file_path = result->first.path; |
301 drive_file_system_->GetFileByPath( | 301 file_system_->GetFileByPath( |
302 src_file_path, | 302 src_file_path, |
303 base::Bind(&CopyOperation::OnGetFileCompleteForCopy, | 303 base::Bind(&CopyOperation::OnGetFileCompleteForCopy, |
304 weak_ptr_factory_.GetWeakPtr(), | 304 weak_ptr_factory_.GetWeakPtr(), |
305 dest_file_path, | 305 dest_file_path, |
306 callback)); | 306 callback)); |
307 } | 307 } |
308 | 308 |
309 void CopyOperation::OnGetFileCompleteForCopy( | 309 void CopyOperation::OnGetFileCompleteForCopy( |
310 const base::FilePath& remote_dest_file_path, | 310 const base::FilePath& remote_dest_file_path, |
311 const FileOperationCallback& callback, | 311 const FileOperationCallback& callback, |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 void CopyOperation::OnTransferCompleted( | 373 void CopyOperation::OnTransferCompleted( |
374 const FileOperationCallback& callback, | 374 const FileOperationCallback& callback, |
375 google_apis::GDataErrorCode error, | 375 google_apis::GDataErrorCode error, |
376 const base::FilePath& drive_path, | 376 const base::FilePath& drive_path, |
377 const base::FilePath& file_path, | 377 const base::FilePath& file_path, |
378 scoped_ptr<ResourceEntry> resource_entry) { | 378 scoped_ptr<ResourceEntry> resource_entry) { |
379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 379 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
380 DCHECK(!callback.is_null()); | 380 DCHECK(!callback.is_null()); |
381 | 381 |
382 if (error == google_apis::HTTP_SUCCESS && resource_entry.get()) { | 382 if (error == google_apis::HTTP_SUCCESS && resource_entry.get()) { |
383 drive_file_system_->AddUploadedFile(resource_entry.Pass(), | 383 file_system_->AddUploadedFile(resource_entry.Pass(), |
384 file_path, | 384 file_path, |
385 callback); | 385 callback); |
386 } else { | 386 } else { |
387 callback.Run(util::GDataToFileError(error)); | 387 callback.Run(util::GDataToFileError(error)); |
388 } | 388 } |
389 } | 389 } |
390 | 390 |
391 void CopyOperation::TransferFileFromLocalToRemoteAfterGetEntryInfo( | 391 void CopyOperation::TransferFileFromLocalToRemoteAfterGetEntryInfo( |
392 const base::FilePath& local_src_file_path, | 392 const base::FilePath& local_src_file_path, |
393 const base::FilePath& remote_dest_file_path, | 393 const base::FilePath& remote_dest_file_path, |
394 const FileOperationCallback& callback, | 394 const FileOperationCallback& callback, |
395 FileError error, | 395 FileError error, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
440 remote_dest_file_path.DirName(), | 440 remote_dest_file_path.DirName(), |
441 resource_id, | 441 resource_id, |
442 // Drop the document extension, which should not be | 442 // Drop the document extension, which should not be |
443 // in the document title. | 443 // in the document title. |
444 remote_dest_file_path.BaseName().RemoveExtension().value(), | 444 remote_dest_file_path.BaseName().RemoveExtension().value(), |
445 callback); | 445 callback); |
446 } | 446 } |
447 | 447 |
448 } // namespace file_system | 448 } // namespace file_system |
449 } // namespace drive | 449 } // namespace drive |
OLD | NEW |