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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_CHROMEOS_DRIVE_JOB_QUEUE_H_
6 #define CHROME_BROWSER_CHROMEOS_DRIVE_JOB_QUEUE_H_
12 #include "chrome/browser/chromeos/drive/job_list.h"
16 // Priority queue for managing jobs in JobScheduler.
19 // Creates a queue that allows |num_max_concurrent_jobs| concurrent job
20 // execution and has |num_priority_levels| levels of priority.
21 JobQueue(size_t num_max_concurrent_jobs
, size_t num_priority_levels
);
24 // Pushes a job |id| of |priority|. The job with the smallest priority value
25 // is popped first (lower values are higher priority). In the same priority,
26 // the queue is "first-in first-out".
27 void Push(JobID id
, int priority
);
29 // Pops the first job which meets |accepted_priority| (i.e. the first job in
30 // the queue with equal or higher priority (lower value)), and the limit of
31 // concurrent job count is satisfied.
33 // For instance, if |accepted_priority| is 1, the first job with priority 0
34 // (higher priority) in the queue is picked even if a job with priority 1 was
35 // pushed earlier. If there is no job with priority 0, the first job with
36 // priority 1 in the queue is picked.
37 bool PopForRun(int accepted_priority
, JobID
* id
);
39 // Gets queued jobs with the given priority.
40 void GetQueuedJobs(int priority
, std::vector
<JobID
>* jobs
) const;
42 // Marks a running job |id| as finished running. This decreases the count
43 // of running parallel jobs and makes room for other jobs to be popped.
44 void MarkFinished(JobID id
);
46 // Generates a string representing the internal state for logging.
47 std::string
ToString() const;
49 // Gets the total number of jobs in the queue.
50 size_t GetNumberOfJobs() const;
52 // Removes the job from the queue.
53 void Remove(JobID id
);
56 size_t num_max_concurrent_jobs_
;
57 std::vector
<std::deque
<JobID
> > queue_
;
58 std::set
<JobID
> running_
;
60 DISALLOW_COPY_AND_ASSIGN(JobQueue
);
65 #endif // CHROME_BROWSER_CHROMEOS_DRIVE_JOB_QUEUE_H_