blob: ef9dac51ee6a048790dd44e7fb21175a5a0dcbc6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_SERVICE_CLOUD_PRINT_PRINTER_JOB_QUEUE_HANDLER_H_
#define CHROME_SERVICE_CLOUD_PRINT_PRINTER_JOB_QUEUE_HANDLER_H_
#include <map>
#include <string>
#include <utility>
#include <vector>
#include "base/files/file_path.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "chrome/common/cloud_print/cloud_print_constants.h"
namespace base {
class DictionaryValue;
}
namespace cloud_print {
struct JobDetails {
JobDetails();
~JobDetails();
void Clear();
static bool ordering(const JobDetails& first, const JobDetails& second);
std::string job_id_;
std::string job_title_;
std::string print_ticket_url_;
std::string print_data_url_;
std::string print_ticket_;
std::string print_ticket_mime_type_;
base::FilePath print_data_file_path_;
std::string print_data_mime_type_;
std::vector<std::string> tags_;
base::TimeDelta time_remaining_;
};
// class containing logic for print job backoff
class PrinterJobQueueHandler {
public:
class TimeProvider {
public:
virtual base::Time GetNow() = 0;
virtual ~TimeProvider() {}
};
// PrinterJobQueueHandler takes ownership of |time_provider| and is
// responsible for deleting it.
explicit PrinterJobQueueHandler(TimeProvider* time_provider);
PrinterJobQueueHandler();
~PrinterJobQueueHandler();
// jobs will be filled with details of all jobs in the queue, sorted by time
// until they are ready to print, lowest to highest. Jobs that are ready to
// print will have a time_remaining_ of 0.
void GetJobsFromQueue(const base::DictionaryValue* json_data,
std::vector<JobDetails>* jobs);
// Marks a job fetch as failed. Returns "true" if the job will be retried.
bool JobFetchFailed(const std::string& job_id);
void JobDone(const std::string& job_id);
private:
scoped_ptr<TimeProvider> time_provider_;
struct FailedJobMetadata {
int retries_;
base::Time last_retry_;
};
typedef std::map<std::string, FailedJobMetadata> FailedJobMap;
typedef std::pair<std::string, FailedJobMetadata> FailedJobPair;
FailedJobMap failed_job_map_;
void ConstructJobDetailsFromJson(const base::DictionaryValue* json_data,
JobDetails* details_obj);
base::TimeDelta ComputeBackoffTime(const std::string& job_id);
DISALLOW_COPY_AND_ASSIGN(PrinterJobQueueHandler);
};
} // namespace cloud_print
#endif // CHROME_SERVICE_CLOUD_PRINT_PRINTER_JOB_QUEUE_HANDLER_H_
|