Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(536)

Side by Side Diff: chrome/browser/chromeos/drive/job_queue.cc

Issue 1138883004: Revert of Revert of Drive: Let DriveUploader use batch request API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/browser/chromeos/drive/job_scheduler.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 bool processing_batch_request = false; 44 uint64 total_size = 0;
45 int64 total_size = 0; 45 bool batchable = true;
46 for (int priority = 0; priority <= accepted_priority; ++priority) { 46 for (int priority = 0; priority <= accepted_priority; ++priority) {
47 auto it = queue_[priority].begin(); 47 while (!queue_[priority].empty()) {
48 while (it != queue_[priority].end()) { 48 const auto& item = queue_[priority].front();
49 if (!processing_batch_request || 49 total_size += item.size;
50 (it->batchable && total_size + it->size <= max_batch_size_)) { 50 batchable = batchable && item.batchable && total_size <= max_batch_size_;
51 total_size += it->size; 51 if (!(jobs->empty() || batchable))
52 processing_batch_request = it->batchable; 52 return;
53 jobs->push_back(it->id); 53 jobs->push_back(item.id);
54 running_.insert(it->id); 54 running_.insert(item.id);
55 it = queue_[priority].erase(it); 55 queue_[priority].pop_front();
56 if (processing_batch_request)
57 continue;
58 }
59 return;
60 } 56 }
61 } 57 }
62 } 58 }
63 59
64 void JobQueue::GetQueuedJobs(int priority, std::vector<JobID>* jobs) const { 60 void JobQueue::GetQueuedJobs(int priority, std::vector<JobID>* jobs) const {
65 DCHECK_LT(priority, static_cast<int>(queue_.size())); 61 DCHECK_LT(priority, static_cast<int>(queue_.size()));
66 jobs->clear(); 62 jobs->clear();
67 for (const Item& item : queue_[priority]) { 63 for (const Item& item : queue_[priority]) {
68 jobs->push_back(item.id); 64 jobs->push_back(item.id);
69 } 65 }
(...skipping 30 matching lines...) Expand all
100 for (auto it = queue_[i].begin(); it != queue_[i].end(); ++it) { 96 for (auto it = queue_[i].begin(); it != queue_[i].end(); ++it) {
101 if (it->id == id) { 97 if (it->id == id) {
102 queue_[i].erase(it); 98 queue_[i].erase(it);
103 break; 99 break;
104 } 100 }
105 } 101 }
106 } 102 }
107 } 103 }
108 104
109 } // namespace drive 105 } // namespace drive
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/drive/job_scheduler.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698