1 // Copyright (c) 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_SERVICE_CLOUD_PRINT_PRINTER_JOB_QUEUE_HANDLER_H_
6 #define CHROME_SERVICE_CLOUD_PRINT_PRINTER_JOB_QUEUE_HANDLER_H_
13 #include "base/files/file_path.h"
14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_ptr.h"
16 #include "base/memory/weak_ptr.h"
17 #include "base/time/time.h"
18 #include "chrome/common/cloud_print/cloud_print_constants.h"
21 class DictionaryValue
;
24 namespace cloud_print
{
30 static bool ordering(const JobDetails
& first
, const JobDetails
& second
);
33 std::string job_title_
;
34 std::string job_owner_
;
36 std::string print_ticket_url_
;
37 std::string print_data_url_
;
39 std::string print_ticket_
;
40 std::string print_ticket_mime_type_
;
41 base::FilePath print_data_file_path_
;
42 std::string print_data_mime_type_
;
44 std::vector
<std::string
> tags_
;
46 base::TimeDelta time_remaining_
;
49 // class containing logic for print job backoff
51 class PrinterJobQueueHandler
{
55 virtual base::Time
GetNow() = 0;
56 virtual ~TimeProvider() {}
59 // PrinterJobQueueHandler takes ownership of |time_provider| and is
60 // responsible for deleting it.
61 explicit PrinterJobQueueHandler(TimeProvider
* time_provider
);
62 PrinterJobQueueHandler();
63 ~PrinterJobQueueHandler();
65 // jobs will be filled with details of all jobs in the queue, sorted by time
66 // until they are ready to print, lowest to highest. Jobs that are ready to
67 // print will have a time_remaining_ of 0.
68 void GetJobsFromQueue(const base::DictionaryValue
* json_data
,
69 std::vector
<JobDetails
>* jobs
);
71 // Marks a job fetch as failed. Returns "true" if the job will be retried.
72 bool JobFetchFailed(const std::string
& job_id
);
74 void JobDone(const std::string
& job_id
);
77 scoped_ptr
<TimeProvider
> time_provider_
;
79 struct FailedJobMetadata
{
81 base::Time last_retry_
;
84 typedef std::map
<std::string
, FailedJobMetadata
> FailedJobMap
;
85 typedef std::pair
<std::string
, FailedJobMetadata
> FailedJobPair
;
87 FailedJobMap failed_job_map_
;
89 void ConstructJobDetailsFromJson(const base::DictionaryValue
* json_data
,
90 JobDetails
* details_obj
);
91 base::TimeDelta
ComputeBackoffTime(const std::string
& job_id
);
93 DISALLOW_COPY_AND_ASSIGN(PrinterJobQueueHandler
);
96 } // namespace cloud_print
98 #endif // CHROME_SERVICE_CLOUD_PRINT_PRINTER_JOB_QUEUE_HANDLER_H_