| 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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 void CollectCopyHistogramSample(const std::string& histogram_name, int64 size) { | 140 void CollectCopyHistogramSample(const std::string& histogram_name, int64 size) { |
| 141 base::HistogramBase* const counter = | 141 base::HistogramBase* const counter = |
| 142 base::Histogram::FactoryGet(histogram_name, | 142 base::Histogram::FactoryGet(histogram_name, |
| 143 1, | 143 1, |
| 144 1024 * 1024 /* 1 GB */, | 144 1024 * 1024 /* 1 GB */, |
| 145 50, | 145 50, |
| 146 base::Histogram::kUmaTargetedHistogramFlag); | 146 base::Histogram::kUmaTargetedHistogramFlag); |
| 147 counter->Add(size / 1024); | 147 counter->Add(size / 1024); |
| 148 } | 148 } |
| 149 | 149 |
| 150 // Callback for GetSizeAndCollectCopyHistogramSample(). | 150 // Obtains file size to be uploaded for setting total bytes of JobInfo. |
| 151 void OnGotSizeForCollectCopyHistogramSample(const std::string& histogram_name, | 151 void GetFileSizeForJob(base::SequencedTaskRunner* blocking_task_runner, |
| 152 int64* size) { | 152 const base::FilePath& local_file_path, |
| 153 if (*size != -1) | 153 const base::Callback<void(int64* size)>& callback) { |
| 154 CollectCopyHistogramSample(histogram_name, *size); | |
| 155 } | |
| 156 | |
| 157 // Collects information about sizes of files copied or moved from or to Drive | |
| 158 // Otherwise does nothing. Temporary for crbug.com/229650. | |
| 159 void GetSizeAndCollectCopyHistogramSample( | |
| 160 base::SequencedTaskRunner* blocking_task_runner, | |
| 161 const base::FilePath& local_file_path, | |
| 162 const std::string& histogram_name) { | |
| 163 int64* const size = new int64; | 154 int64* const size = new int64; |
| 164 *size = -1; | 155 *size = -1; |
| 165 blocking_task_runner->PostTaskAndReply( | 156 blocking_task_runner->PostTaskAndReply( |
| 166 FROM_HERE, | 157 FROM_HERE, base::Bind(base::IgnoreResult(&base::GetFileSize), |
| 167 base::Bind(base::IgnoreResult(&base::GetFileSize), | 158 local_file_path, base::Unretained(size)), |
| 168 local_file_path, | 159 base::Bind(callback, base::Owned(size))); |
| 169 base::Unretained(size)), | |
| 170 base::Bind(&OnGotSizeForCollectCopyHistogramSample, | |
| 171 histogram_name, | |
| 172 base::Owned(size))); | |
| 173 } | 160 } |
| 174 | 161 |
| 175 } // namespace | 162 } // namespace |
| 176 | 163 |
| 177 // Metadata jobs are cheap, so we run them concurrently. File jobs run serially. | 164 // Metadata jobs are cheap, so we run them concurrently. File jobs run serially. |
| 178 const int JobScheduler::kMaxJobCount[] = { | 165 const int JobScheduler::kMaxJobCount[] = { |
| 179 5, // METADATA_QUEUE | 166 5, // METADATA_QUEUE |
| 180 1, // FILE_QUEUE | 167 1, // FILE_QUEUE |
| 181 }; | 168 }; |
| 182 | 169 |
| (...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 const std::string& parent_resource_id, | 626 const std::string& parent_resource_id, |
| 640 const base::FilePath& drive_file_path, | 627 const base::FilePath& drive_file_path, |
| 641 const base::FilePath& local_file_path, | 628 const base::FilePath& local_file_path, |
| 642 const std::string& title, | 629 const std::string& title, |
| 643 const std::string& content_type, | 630 const std::string& content_type, |
| 644 const DriveUploader::UploadNewFileOptions& options, | 631 const DriveUploader::UploadNewFileOptions& options, |
| 645 const ClientContext& context, | 632 const ClientContext& context, |
| 646 const google_apis::FileResourceCallback& callback) { | 633 const google_apis::FileResourceCallback& callback) { |
| 647 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 634 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 648 | 635 |
| 649 // Temporary histogram for crbug.com/229650. | |
| 650 GetSizeAndCollectCopyHistogramSample( | |
| 651 blocking_task_runner_, local_file_path, "Drive.UploadToDriveFileSize"); | |
| 652 | |
| 653 JobEntry* new_job = CreateNewJob(TYPE_UPLOAD_NEW_FILE); | 636 JobEntry* new_job = CreateNewJob(TYPE_UPLOAD_NEW_FILE); |
| 654 new_job->job_info.file_path = drive_file_path; | 637 new_job->job_info.file_path = drive_file_path; |
| 655 new_job->context = context; | 638 new_job->context = context; |
| 656 | 639 |
| 640 GetFileSizeForJob( |
| 641 blocking_task_runner_, local_file_path, |
| 642 base::Bind(&JobScheduler::OnGotFileSizeForJob, |
| 643 weak_ptr_factory_.GetWeakPtr(), new_job->job_info.job_id, |
| 644 "Drive.UploadToDriveFileSize")); |
| 645 |
| 657 UploadNewFileParams params; | 646 UploadNewFileParams params; |
| 658 params.parent_resource_id = parent_resource_id; | 647 params.parent_resource_id = parent_resource_id; |
| 659 params.local_file_path = local_file_path; | 648 params.local_file_path = local_file_path; |
| 660 params.title = title; | 649 params.title = title; |
| 661 params.content_type = content_type; | 650 params.content_type = content_type; |
| 662 params.options = options; | 651 params.options = options; |
| 663 | 652 |
| 664 ResumeUploadParams resume_params; | 653 ResumeUploadParams resume_params; |
| 665 resume_params.local_file_path = params.local_file_path; | 654 resume_params.local_file_path = params.local_file_path; |
| 666 resume_params.content_type = params.content_type; | 655 resume_params.content_type = params.content_type; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 681 void JobScheduler::UploadExistingFile( | 670 void JobScheduler::UploadExistingFile( |
| 682 const std::string& resource_id, | 671 const std::string& resource_id, |
| 683 const base::FilePath& drive_file_path, | 672 const base::FilePath& drive_file_path, |
| 684 const base::FilePath& local_file_path, | 673 const base::FilePath& local_file_path, |
| 685 const std::string& content_type, | 674 const std::string& content_type, |
| 686 const DriveUploader::UploadExistingFileOptions& options, | 675 const DriveUploader::UploadExistingFileOptions& options, |
| 687 const ClientContext& context, | 676 const ClientContext& context, |
| 688 const google_apis::FileResourceCallback& callback) { | 677 const google_apis::FileResourceCallback& callback) { |
| 689 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 678 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 690 | 679 |
| 691 // Temporary histogram for crbug.com/229650. | |
| 692 GetSizeAndCollectCopyHistogramSample( | |
| 693 blocking_task_runner_, local_file_path, "Drive.UploadToDriveFileSize"); | |
| 694 | |
| 695 JobEntry* new_job = CreateNewJob(TYPE_UPLOAD_EXISTING_FILE); | 680 JobEntry* new_job = CreateNewJob(TYPE_UPLOAD_EXISTING_FILE); |
| 696 new_job->job_info.file_path = drive_file_path; | 681 new_job->job_info.file_path = drive_file_path; |
| 697 new_job->context = context; | 682 new_job->context = context; |
| 698 | 683 |
| 684 GetFileSizeForJob( |
| 685 blocking_task_runner_, local_file_path, |
| 686 base::Bind(&JobScheduler::OnGotFileSizeForJob, |
| 687 weak_ptr_factory_.GetWeakPtr(), new_job->job_info.job_id, |
| 688 "Drive.UploadToDriveFileSize")); |
| 689 |
| 699 UploadExistingFileParams params; | 690 UploadExistingFileParams params; |
| 700 params.resource_id = resource_id; | 691 params.resource_id = resource_id; |
| 701 params.local_file_path = local_file_path; | 692 params.local_file_path = local_file_path; |
| 702 params.content_type = content_type; | 693 params.content_type = content_type; |
| 703 params.options = options; | 694 params.options = options; |
| 704 | 695 |
| 705 ResumeUploadParams resume_params; | 696 ResumeUploadParams resume_params; |
| 706 resume_params.local_file_path = params.local_file_path; | 697 resume_params.local_file_path = params.local_file_path; |
| 707 resume_params.content_type = params.content_type; | 698 resume_params.content_type = params.content_type; |
| 708 | 699 |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1106 net::NetworkChangeNotifier::ConnectionType type) { | 1097 net::NetworkChangeNotifier::ConnectionType type) { |
| 1107 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 1098 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1108 | 1099 |
| 1109 // Resume the job loop. | 1100 // Resume the job loop. |
| 1110 // Note that we don't need to check the network connection status as it will | 1101 // Note that we don't need to check the network connection status as it will |
| 1111 // be checked in GetCurrentAcceptedPriority(). | 1102 // be checked in GetCurrentAcceptedPriority(). |
| 1112 for (int i = METADATA_QUEUE; i < NUM_QUEUES; ++i) | 1103 for (int i = METADATA_QUEUE; i < NUM_QUEUES; ++i) |
| 1113 DoJobLoop(static_cast<QueueType>(i)); | 1104 DoJobLoop(static_cast<QueueType>(i)); |
| 1114 } | 1105 } |
| 1115 | 1106 |
| 1107 void JobScheduler::OnGotFileSizeForJob(JobID job_id, |
| 1108 const std::string& histogram_name, |
| 1109 int64* size) { |
| 1110 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 1111 if (*size == -1) |
| 1112 return; |
| 1113 |
| 1114 // Temporary histogram for crbug.com/229650. |
| 1115 CollectCopyHistogramSample(histogram_name, *size); |
| 1116 |
| 1117 JobEntry* const job_entry = job_map_.Lookup(job_id); |
| 1118 if (!job_entry) |
| 1119 return; |
| 1120 |
| 1121 job_entry->job_info.num_total_bytes = *size; |
| 1122 NotifyJobUpdated(job_entry->job_info); |
| 1123 } |
| 1124 |
| 1116 JobScheduler::QueueType JobScheduler::GetJobQueueType(JobType type) { | 1125 JobScheduler::QueueType JobScheduler::GetJobQueueType(JobType type) { |
| 1117 switch (type) { | 1126 switch (type) { |
| 1118 case TYPE_GET_ABOUT_RESOURCE: | 1127 case TYPE_GET_ABOUT_RESOURCE: |
| 1119 case TYPE_GET_APP_LIST: | 1128 case TYPE_GET_APP_LIST: |
| 1120 case TYPE_GET_ALL_RESOURCE_LIST: | 1129 case TYPE_GET_ALL_RESOURCE_LIST: |
| 1121 case TYPE_GET_RESOURCE_LIST_IN_DIRECTORY: | 1130 case TYPE_GET_RESOURCE_LIST_IN_DIRECTORY: |
| 1122 case TYPE_SEARCH: | 1131 case TYPE_SEARCH: |
| 1123 case TYPE_GET_CHANGE_LIST: | 1132 case TYPE_GET_CHANGE_LIST: |
| 1124 case TYPE_GET_REMAINING_CHANGE_LIST: | 1133 case TYPE_GET_REMAINING_CHANGE_LIST: |
| 1125 case TYPE_GET_REMAINING_FILE_LIST: | 1134 case TYPE_GET_REMAINING_FILE_LIST: |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1194 case FILE_QUEUE: | 1203 case FILE_QUEUE: |
| 1195 return "FILE_QUEUE"; | 1204 return "FILE_QUEUE"; |
| 1196 case NUM_QUEUES: | 1205 case NUM_QUEUES: |
| 1197 break; // This value is just a sentinel. Should never be used. | 1206 break; // This value is just a sentinel. Should never be used. |
| 1198 } | 1207 } |
| 1199 NOTREACHED(); | 1208 NOTREACHED(); |
| 1200 return ""; | 1209 return ""; |
| 1201 } | 1210 } |
| 1202 | 1211 |
| 1203 } // namespace drive | 1212 } // namespace drive |
| OLD | NEW |