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 <algorithm> | |
8 | |
9 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
10 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
11 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
12 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
13 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
14 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/stringprintf.h" | 13 #include "base/strings/stringprintf.h" |
16 #include "chrome/browser/drive/event_logger.h" | 14 #include "chrome/browser/drive/event_logger.h" |
17 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
18 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
(...skipping 718 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
737 } | 735 } |
738 | 736 |
739 void JobScheduler::QueueJob(JobID job_id) { | 737 void JobScheduler::QueueJob(JobID job_id) { |
740 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 738 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
741 | 739 |
742 JobEntry* job_entry = job_map_.Lookup(job_id); | 740 JobEntry* job_entry = job_map_.Lookup(job_id); |
743 DCHECK(job_entry); | 741 DCHECK(job_entry); |
744 const JobInfo& job_info = job_entry->job_info; | 742 const JobInfo& job_info = job_entry->job_info; |
745 | 743 |
746 const QueueType queue_type = GetJobQueueType(job_info.job_type); | 744 const QueueType queue_type = GetJobQueueType(job_info.job_type); |
747 const bool batchable = job_info.job_type == TYPE_UPLOAD_EXISTING_FILE || | 745 queue_[queue_type]->Push(job_id, job_entry->context.type, false, |
748 job_info.job_type == TYPE_UPLOAD_NEW_FILE; | |
749 queue_[queue_type]->Push(job_id, job_entry->context.type, batchable, | |
750 job_info.num_total_bytes); | 746 job_info.num_total_bytes); |
751 | 747 |
752 // Temporary histogram for crbug.com/229650. | 748 // Temporary histogram for crbug.com/229650. |
753 if (job_info.job_type == TYPE_DOWNLOAD_FILE || | 749 if (job_info.job_type == TYPE_DOWNLOAD_FILE || |
754 job_info.job_type == TYPE_UPLOAD_EXISTING_FILE || | 750 job_info.job_type == TYPE_UPLOAD_EXISTING_FILE || |
755 job_info.job_type == TYPE_UPLOAD_NEW_FILE) { | 751 job_info.job_type == TYPE_UPLOAD_NEW_FILE) { |
756 std::vector<JobID> jobs_with_the_same_priority; | 752 std::vector<JobID> jobs_with_the_same_priority; |
757 queue_[queue_type]->GetQueuedJobs(job_entry->context.type, | 753 queue_[queue_type]->GetQueuedJobs(job_entry->context.type, |
758 &jobs_with_the_same_priority); | 754 &jobs_with_the_same_priority); |
759 DCHECK(!jobs_with_the_same_priority.empty()); | 755 DCHECK(!jobs_with_the_same_priority.empty()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 wait_until_ - now); | 795 wait_until_ - now); |
800 return; | 796 return; |
801 } | 797 } |
802 | 798 |
803 // Run the job with the highest priority in the queue. | 799 // Run the job with the highest priority in the queue. |
804 std::vector<JobID> job_ids; | 800 std::vector<JobID> job_ids; |
805 queue_[queue_type]->PopForRun(accepted_priority, &job_ids); | 801 queue_[queue_type]->PopForRun(accepted_priority, &job_ids); |
806 if (job_ids.empty()) | 802 if (job_ids.empty()) |
807 return; | 803 return; |
808 | 804 |
809 if (job_ids.size() > 1) | 805 // TODO(hirono): Currently all requests are not batchable. So the queue always |
810 uploader_->StartBatchProcessing(); | 806 // return just 1 job. |
| 807 DCHECK_EQ(1u, job_ids.size()); |
| 808 JobEntry* entry = job_map_.Lookup(job_ids.front()); |
| 809 DCHECK(entry); |
811 | 810 |
812 for (JobID job_id : job_ids) { | 811 JobInfo* job_info = &entry->job_info; |
813 JobEntry* entry = job_map_.Lookup(job_id); | 812 job_info->state = STATE_RUNNING; |
814 DCHECK(entry); | 813 job_info->start_time = now; |
| 814 NotifyJobUpdated(*job_info); |
815 | 815 |
816 JobInfo* job_info = &entry->job_info; | 816 entry->cancel_callback = entry->task.Run(); |
817 job_info->state = STATE_RUNNING; | |
818 job_info->start_time = now; | |
819 NotifyJobUpdated(*job_info); | |
820 | |
821 entry->cancel_callback = entry->task.Run(); | |
822 logger_->Log(logging::LOG_INFO, "Job started: %s - %s", | |
823 job_info->ToString().c_str(), | |
824 GetQueueInfo(queue_type).c_str()); | |
825 } | |
826 | |
827 if (job_ids.size() > 1) | |
828 uploader_->StopBatchProcessing(); | |
829 | 817 |
830 UpdateWait(); | 818 UpdateWait(); |
| 819 |
| 820 logger_->Log(logging::LOG_INFO, |
| 821 "Job started: %s - %s", |
| 822 job_info->ToString().c_str(), |
| 823 GetQueueInfo(queue_type).c_str()); |
831 } | 824 } |
832 | 825 |
833 int JobScheduler::GetCurrentAcceptedPriority(QueueType queue_type) { | 826 int JobScheduler::GetCurrentAcceptedPriority(QueueType queue_type) { |
834 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 827 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
835 | 828 |
836 const int kNoJobShouldRun = -1; | 829 const int kNoJobShouldRun = -1; |
837 | 830 |
838 // Should stop if Drive was disabled while running the fetch loop. | 831 // Should stop if Drive was disabled while running the fetch loop. |
839 if (pref_service_->GetBoolean(prefs::kDisableDrive)) | 832 if (pref_service_->GetBoolean(prefs::kDisableDrive)) |
840 return kNoJobShouldRun; | 833 return kNoJobShouldRun; |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1185 case FILE_QUEUE: | 1178 case FILE_QUEUE: |
1186 return "FILE_QUEUE"; | 1179 return "FILE_QUEUE"; |
1187 case NUM_QUEUES: | 1180 case NUM_QUEUES: |
1188 break; // This value is just a sentinel. Should never be used. | 1181 break; // This value is just a sentinel. Should never be used. |
1189 } | 1182 } |
1190 NOTREACHED(); | 1183 NOTREACHED(); |
1191 return ""; | 1184 return ""; |
1192 } | 1185 } |
1193 | 1186 |
1194 } // namespace drive | 1187 } // namespace drive |
OLD | NEW |