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" |
11 #include "chrome/browser/chromeos/drive/drive.pb.h" | 11 #include "chrome/browser/chromeos/drive/drive.pb.h" |
12 #include "chrome/browser/chromeos/drive/drive_cache.h" | 12 #include "chrome/browser/chromeos/drive/drive_cache.h" |
13 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h" | 13 #include "chrome/browser/chromeos/drive/drive_file_system_interface.h" |
14 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" | 14 #include "chrome/browser/chromeos/drive/drive_file_system_util.h" |
15 #include "chrome/browser/chromeos/drive/drive_scheduler.h" | 15 #include "chrome/browser/chromeos/drive/drive_scheduler.h" |
16 #include "chrome/browser/chromeos/drive/file_system/move_operation.h" | 16 #include "chrome/browser/chromeos/drive/file_system/move_operation.h" |
17 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" | 17 #include "chrome/browser/chromeos/drive/file_system/operation_observer.h" |
18 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" | 18 #include "chrome/browser/chromeos/drive/resource_entry_conversion.h" |
19 #include "chrome/browser/google_apis/drive_upload_error.h" | 19 #include "chrome/browser/google_apis/drive_upload_error.h" |
20 #include "chrome/browser/google_apis/drive_uploader.h" | |
21 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
22 #include "net/base/mime_util.h" | 21 #include "net/base/mime_util.h" |
23 | 22 |
24 using content::BrowserThread; | 23 using content::BrowserThread; |
25 using google_apis::ResourceEntry; | 24 using google_apis::ResourceEntry; |
26 using google_apis::GDataErrorCode; | 25 using google_apis::GDataErrorCode; |
27 | 26 |
28 namespace drive { | 27 namespace drive { |
29 namespace file_system { | 28 namespace file_system { |
30 | 29 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 | 71 |
73 const base::FilePath local_file_path; | 72 const base::FilePath local_file_path; |
74 const base::FilePath remote_file_path; | 73 const base::FilePath remote_file_path; |
75 const FileOperationCallback callback; | 74 const FileOperationCallback callback; |
76 }; | 75 }; |
77 | 76 |
78 CopyOperation::CopyOperation( | 77 CopyOperation::CopyOperation( |
79 DriveScheduler* drive_scheduler, | 78 DriveScheduler* drive_scheduler, |
80 DriveFileSystemInterface* drive_file_system, | 79 DriveFileSystemInterface* drive_file_system, |
81 DriveResourceMetadata* metadata, | 80 DriveResourceMetadata* metadata, |
82 google_apis::DriveUploaderInterface* uploader, | |
83 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, | 81 scoped_refptr<base::SequencedTaskRunner> blocking_task_runner, |
84 OperationObserver* observer) | 82 OperationObserver* observer) |
85 : drive_scheduler_(drive_scheduler), | 83 : drive_scheduler_(drive_scheduler), |
86 drive_file_system_(drive_file_system), | 84 drive_file_system_(drive_file_system), |
87 metadata_(metadata), | 85 metadata_(metadata), |
88 uploader_(uploader), | |
89 blocking_task_runner_(blocking_task_runner), | 86 blocking_task_runner_(blocking_task_runner), |
90 observer_(observer), | 87 observer_(observer), |
91 move_operation_(new MoveOperation(drive_scheduler, | 88 move_operation_(new MoveOperation(drive_scheduler, |
92 metadata, | 89 metadata, |
93 observer)), | 90 observer)), |
94 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 91 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
95 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 92 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
96 } | 93 } |
97 | 94 |
98 CopyOperation::~CopyOperation() { | 95 CopyOperation::~CopyOperation() { |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
355 | 352 |
356 if (entry_proto.get() && !entry_proto->file_info().is_directory()) | 353 if (entry_proto.get() && !entry_proto->file_info().is_directory()) |
357 error = DRIVE_FILE_ERROR_NOT_A_DIRECTORY; | 354 error = DRIVE_FILE_ERROR_NOT_A_DIRECTORY; |
358 | 355 |
359 if (error != DRIVE_FILE_OK) { | 356 if (error != DRIVE_FILE_OK) { |
360 params.callback.Run(error); | 357 params.callback.Run(error); |
361 return; | 358 return; |
362 } | 359 } |
363 DCHECK(entry_proto.get()); | 360 DCHECK(entry_proto.get()); |
364 | 361 |
365 uploader_->UploadNewFile(entry_proto->resource_id(), | 362 drive_scheduler_->UploadNewFile( |
366 params.remote_file_path, | 363 entry_proto->resource_id(), |
367 params.local_file_path, | 364 params.remote_file_path, |
368 params.remote_file_path.BaseName().value(), | 365 params.local_file_path, |
369 content_type, | 366 params.remote_file_path.BaseName().value(), |
370 base::Bind(&CopyOperation::OnTransferCompleted, | 367 content_type, |
371 weak_ptr_factory_.GetWeakPtr(), | 368 DriveClientContext(USER_INITIATED), |
372 params.callback)); | 369 base::Bind(&CopyOperation::OnTransferCompleted, |
| 370 weak_ptr_factory_.GetWeakPtr(), |
| 371 params.callback)); |
373 } | 372 } |
374 | 373 |
375 void CopyOperation::OnTransferCompleted( | 374 void CopyOperation::OnTransferCompleted( |
376 const FileOperationCallback& callback, | 375 const FileOperationCallback& callback, |
377 google_apis::DriveUploadError error, | 376 google_apis::DriveUploadError error, |
378 const base::FilePath& drive_path, | 377 const base::FilePath& drive_path, |
379 const base::FilePath& file_path, | 378 const base::FilePath& file_path, |
380 scoped_ptr<ResourceEntry> resource_entry) { | 379 scoped_ptr<ResourceEntry> resource_entry) { |
381 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 380 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
382 DCHECK(!callback.is_null()); | 381 DCHECK(!callback.is_null()); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 remote_dest_file_path.DirName(), | 441 remote_dest_file_path.DirName(), |
443 resource_id, | 442 resource_id, |
444 // Drop the document extension, which should not be | 443 // Drop the document extension, which should not be |
445 // in the document title. | 444 // in the document title. |
446 remote_dest_file_path.BaseName().RemoveExtension().value(), | 445 remote_dest_file_path.BaseName().RemoveExtension().value(), |
447 callback); | 446 callback); |
448 } | 447 } |
449 | 448 |
450 } // namespace file_system | 449 } // namespace file_system |
451 } // namespace drive | 450 } // namespace drive |
OLD | NEW |