| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_queue.h" | 5 #include "chrome/browser/chromeos/drive/job_queue.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 | 34 |
| 35 void JobQueue::PopForRun(int accepted_priority, std::vector<JobID>* jobs) { | 35 void JobQueue::PopForRun(int accepted_priority, std::vector<JobID>* jobs) { |
| 36 DCHECK_LT(accepted_priority, static_cast<int>(queue_.size())); | 36 DCHECK_LT(accepted_priority, static_cast<int>(queue_.size())); |
| 37 jobs->clear(); | 37 jobs->clear(); |
| 38 | 38 |
| 39 // Too many jobs are running already. | 39 // Too many jobs are running already. |
| 40 if (running_.size() >= num_max_concurrent_jobs_) | 40 if (running_.size() >= num_max_concurrent_jobs_) |
| 41 return; | 41 return; |
| 42 | 42 |
| 43 // Looks up the queue in the order of priority upto |accepted_priority|. | 43 // Looks up the queue in the order of priority upto |accepted_priority|. |
| 44 uint64 total_size = 0; | 44 bool processing_batch_request = false; |
| 45 bool batchable = true; | 45 int64 total_size = 0; |
| 46 for (int priority = 0; priority <= accepted_priority; ++priority) { | 46 for (int priority = 0; priority <= accepted_priority; ++priority) { |
| 47 while (!queue_[priority].empty()) { | 47 auto it = queue_[priority].begin(); |
| 48 const auto& item = queue_[priority].front(); | 48 while (it != queue_[priority].end()) { |
| 49 total_size += item.size; | 49 if (!processing_batch_request || |
| 50 batchable = batchable && item.batchable && total_size <= max_batch_size_; | 50 (it->batchable && total_size + it->size <= max_batch_size_)) { |
| 51 if (!(jobs->empty() || batchable)) | 51 total_size += it->size; |
| 52 return; | 52 processing_batch_request = it->batchable; |
| 53 jobs->push_back(item.id); | 53 jobs->push_back(it->id); |
| 54 running_.insert(item.id); | 54 running_.insert(it->id); |
| 55 queue_[priority].pop_front(); | 55 it = queue_[priority].erase(it); |
| 56 if (processing_batch_request) |
| 57 continue; |
| 58 } |
| 59 return; |
| 56 } | 60 } |
| 57 } | 61 } |
| 58 } | 62 } |
| 59 | 63 |
| 60 void JobQueue::GetQueuedJobs(int priority, std::vector<JobID>* jobs) const { | 64 void JobQueue::GetQueuedJobs(int priority, std::vector<JobID>* jobs) const { |
| 61 DCHECK_LT(priority, static_cast<int>(queue_.size())); | 65 DCHECK_LT(priority, static_cast<int>(queue_.size())); |
| 62 jobs->clear(); | 66 jobs->clear(); |
| 63 for (const Item& item : queue_[priority]) { | 67 for (const Item& item : queue_[priority]) { |
| 64 jobs->push_back(item.id); | 68 jobs->push_back(item.id); |
| 65 } | 69 } |
| (...skipping 30 matching lines...) Expand all Loading... |
| 96 for (auto it = queue_[i].begin(); it != queue_[i].end(); ++it) { | 100 for (auto it = queue_[i].begin(); it != queue_[i].end(); ++it) { |
| 97 if (it->id == id) { | 101 if (it->id == id) { |
| 98 queue_[i].erase(it); | 102 queue_[i].erase(it); |
| 99 break; | 103 break; |
| 100 } | 104 } |
| 101 } | 105 } |
| 102 } | 106 } |
| 103 } | 107 } |
| 104 | 108 |
| 105 } // namespace drive | 109 } // namespace drive |
| OLD | NEW |