| 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/job_scheduler.h" | 5 #include "chrome/browser/chromeos/drive/job_scheduler.h" |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
| 10 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 CreateErrorRunCallback(const base::Callback<CallbackType>& callback) { | 67 CreateErrorRunCallback(const base::Callback<CallbackType>& callback) { |
| 68 return base::Bind(&CreateErrorRunCallbackHelper<CallbackType>::Run, callback); | 68 return base::Bind(&CreateErrorRunCallbackHelper<CallbackType>::Run, callback); |
| 69 } | 69 } |
| 70 | 70 |
| 71 // Parameter struct for RunUploadNewFile. | 71 // Parameter struct for RunUploadNewFile. |
| 72 struct UploadNewFileParams { | 72 struct UploadNewFileParams { |
| 73 std::string parent_resource_id; | 73 std::string parent_resource_id; |
| 74 base::FilePath local_file_path; | 74 base::FilePath local_file_path; |
| 75 std::string title; | 75 std::string title; |
| 76 std::string content_type; | 76 std::string content_type; |
| 77 DriveUploader::UploadNewFileOptions options; | 77 UploadNewFileOptions options; |
| 78 UploadCompletionCallback callback; | 78 UploadCompletionCallback callback; |
| 79 google_apis::ProgressCallback progress_callback; | 79 google_apis::ProgressCallback progress_callback; |
| 80 }; | 80 }; |
| 81 | 81 |
| 82 // Helper function to work around the arity limitation of base::Bind. | 82 // Helper function to work around the arity limitation of base::Bind. |
| 83 google_apis::CancelCallback RunUploadNewFile( | 83 google_apis::CancelCallback RunUploadNewFile( |
| 84 DriveUploaderInterface* uploader, | 84 DriveUploaderInterface* uploader, |
| 85 const UploadNewFileParams& params) { | 85 const UploadNewFileParams& params) { |
| 86 return uploader->UploadNewFile(params.parent_resource_id, | 86 return uploader->UploadNewFile(params.parent_resource_id, |
| 87 params.local_file_path, | 87 params.local_file_path, |
| 88 params.title, | 88 params.title, |
| 89 params.content_type, | 89 params.content_type, |
| 90 params.options, | 90 params.options, |
| 91 params.callback, | 91 params.callback, |
| 92 params.progress_callback); | 92 params.progress_callback); |
| 93 } | 93 } |
| 94 | 94 |
| 95 // Parameter struct for RunUploadExistingFile. | 95 // Parameter struct for RunUploadExistingFile. |
| 96 struct UploadExistingFileParams { | 96 struct UploadExistingFileParams { |
| 97 std::string resource_id; | 97 std::string resource_id; |
| 98 base::FilePath local_file_path; | 98 base::FilePath local_file_path; |
| 99 std::string content_type; | 99 std::string content_type; |
| 100 DriveUploader::UploadExistingFileOptions options; | 100 UploadExistingFileOptions options; |
| 101 std::string etag; | 101 std::string etag; |
| 102 UploadCompletionCallback callback; | 102 UploadCompletionCallback callback; |
| 103 google_apis::ProgressCallback progress_callback; | 103 google_apis::ProgressCallback progress_callback; |
| 104 }; | 104 }; |
| 105 | 105 |
| 106 // Helper function to work around the arity limitation of base::Bind. | 106 // Helper function to work around the arity limitation of base::Bind. |
| 107 google_apis::CancelCallback RunUploadExistingFile( | 107 google_apis::CancelCallback RunUploadExistingFile( |
| 108 DriveUploaderInterface* uploader, | 108 DriveUploaderInterface* uploader, |
| 109 const UploadExistingFileParams& params) { | 109 const UploadExistingFileParams& params) { |
| 110 return uploader->UploadExistingFile(params.resource_id, | 110 return uploader->UploadExistingFile(params.resource_id, |
| (...skipping 447 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 weak_ptr_factory_.GetWeakPtr(), | 558 weak_ptr_factory_.GetWeakPtr(), |
| 559 new_job->job_info.job_id, | 559 new_job->job_info.job_id, |
| 560 callback)); | 560 callback)); |
| 561 new_job->abort_callback = callback; | 561 new_job->abort_callback = callback; |
| 562 StartJob(new_job); | 562 StartJob(new_job); |
| 563 } | 563 } |
| 564 | 564 |
| 565 void JobScheduler::AddNewDirectory( | 565 void JobScheduler::AddNewDirectory( |
| 566 const std::string& parent_resource_id, | 566 const std::string& parent_resource_id, |
| 567 const std::string& directory_title, | 567 const std::string& directory_title, |
| 568 const DriveServiceInterface::AddNewDirectoryOptions& options, | 568 const AddNewDirectoryOptions& options, |
| 569 const ClientContext& context, | 569 const ClientContext& context, |
| 570 const google_apis::FileResourceCallback& callback) { | 570 const google_apis::FileResourceCallback& callback) { |
| 571 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 571 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 572 | 572 |
| 573 JobEntry* new_job = CreateNewJob(TYPE_ADD_NEW_DIRECTORY); | 573 JobEntry* new_job = CreateNewJob(TYPE_ADD_NEW_DIRECTORY); |
| 574 new_job->context = context; | 574 new_job->context = context; |
| 575 new_job->task = base::Bind( | 575 new_job->task = base::Bind( |
| 576 &DriveServiceInterface::AddNewDirectory, | 576 &DriveServiceInterface::AddNewDirectory, |
| 577 base::Unretained(drive_service_), | 577 base::Unretained(drive_service_), |
| 578 parent_resource_id, | 578 parent_resource_id, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 StartJob(new_job); | 621 StartJob(new_job); |
| 622 return new_job->job_info.job_id; | 622 return new_job->job_info.job_id; |
| 623 } | 623 } |
| 624 | 624 |
| 625 void JobScheduler::UploadNewFile( | 625 void JobScheduler::UploadNewFile( |
| 626 const std::string& parent_resource_id, | 626 const std::string& parent_resource_id, |
| 627 const base::FilePath& drive_file_path, | 627 const base::FilePath& drive_file_path, |
| 628 const base::FilePath& local_file_path, | 628 const base::FilePath& local_file_path, |
| 629 const std::string& title, | 629 const std::string& title, |
| 630 const std::string& content_type, | 630 const std::string& content_type, |
| 631 const DriveUploader::UploadNewFileOptions& options, | 631 const UploadNewFileOptions& options, |
| 632 const ClientContext& context, | 632 const ClientContext& context, |
| 633 const google_apis::FileResourceCallback& callback) { | 633 const google_apis::FileResourceCallback& callback) { |
| 634 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 634 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 635 | 635 |
| 636 JobEntry* new_job = CreateNewJob(TYPE_UPLOAD_NEW_FILE); | 636 JobEntry* new_job = CreateNewJob(TYPE_UPLOAD_NEW_FILE); |
| 637 new_job->job_info.file_path = drive_file_path; | 637 new_job->job_info.file_path = drive_file_path; |
| 638 new_job->context = context; | 638 new_job->context = context; |
| 639 | 639 |
| 640 GetFileSizeForJob( | 640 GetFileSizeForJob( |
| 641 blocking_task_runner_, local_file_path, | 641 blocking_task_runner_, local_file_path, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 665 new_job->task = base::Bind(&RunUploadNewFile, uploader_.get(), params); | 665 new_job->task = base::Bind(&RunUploadNewFile, uploader_.get(), params); |
| 666 new_job->abort_callback = CreateErrorRunCallback(callback); | 666 new_job->abort_callback = CreateErrorRunCallback(callback); |
| 667 StartJob(new_job); | 667 StartJob(new_job); |
| 668 } | 668 } |
| 669 | 669 |
| 670 void JobScheduler::UploadExistingFile( | 670 void JobScheduler::UploadExistingFile( |
| 671 const std::string& resource_id, | 671 const std::string& resource_id, |
| 672 const base::FilePath& drive_file_path, | 672 const base::FilePath& drive_file_path, |
| 673 const base::FilePath& local_file_path, | 673 const base::FilePath& local_file_path, |
| 674 const std::string& content_type, | 674 const std::string& content_type, |
| 675 const DriveUploader::UploadExistingFileOptions& options, | 675 const UploadExistingFileOptions& options, |
| 676 const ClientContext& context, | 676 const ClientContext& context, |
| 677 const google_apis::FileResourceCallback& callback) { | 677 const google_apis::FileResourceCallback& callback) { |
| 678 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 678 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 679 | 679 |
| 680 JobEntry* new_job = CreateNewJob(TYPE_UPLOAD_EXISTING_FILE); | 680 JobEntry* new_job = CreateNewJob(TYPE_UPLOAD_EXISTING_FILE); |
| 681 new_job->job_info.file_path = drive_file_path; | 681 new_job->job_info.file_path = drive_file_path; |
| 682 new_job->context = context; | 682 new_job->context = context; |
| 683 | 683 |
| 684 GetFileSizeForJob( | 684 GetFileSizeForJob( |
| 685 blocking_task_runner_, local_file_path, | 685 blocking_task_runner_, local_file_path, |
| (...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1203 case FILE_QUEUE: | 1203 case FILE_QUEUE: |
| 1204 return "FILE_QUEUE"; | 1204 return "FILE_QUEUE"; |
| 1205 case NUM_QUEUES: | 1205 case NUM_QUEUES: |
| 1206 break; // This value is just a sentinel. Should never be used. | 1206 break; // This value is just a sentinel. Should never be used. |
| 1207 } | 1207 } |
| 1208 NOTREACHED(); | 1208 NOTREACHED(); |
| 1209 return ""; | 1209 return ""; |
| 1210 } | 1210 } |
| 1211 | 1211 |
| 1212 } // namespace drive | 1212 } // namespace drive |
| OLD | NEW |