OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #ifndef CHROME_BROWSER_CHROMEOS_PRINTING_CUPS_PRINT_JOB_MANAGER_IMPL_H_ | 5 #ifndef CHROME_BROWSER_CHROMEOS_PRINTING_CUPS_PRINT_JOB_MANAGER_IMPL_H_ |
6 #define CHROME_BROWSER_CHROMEOS_PRINTING_CUPS_PRINT_JOB_MANAGER_IMPL_H_ | 6 #define CHROME_BROWSER_CHROMEOS_PRINTING_CUPS_PRINT_JOB_MANAGER_IMPL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
11 #include <unordered_map> | 11 #include <unordered_map> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/memory/ref_counted.h" | |
14 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
16 #include "base/sequence_checker.h" | |
17 #include "base/sequenced_task_runner.h" | |
18 #include "base/single_thread_task_runner.h" | |
15 #include "chrome/browser/chromeos/printing/cups_print_job.h" | 19 #include "chrome/browser/chromeos/printing/cups_print_job.h" |
16 #include "chrome/browser/chromeos/printing/cups_print_job_manager.h" | 20 #include "chrome/browser/chromeos/printing/cups_print_job_manager.h" |
17 #include "chrome/browser/chromeos/printing/printers_manager.h" | 21 #include "chrome/browser/chromeos/printing/printers_manager.h" |
18 #include "content/public/browser/notification_observer.h" | 22 #include "content/public/browser/notification_observer.h" |
19 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
20 #include "printing/backend/cups_connection.h" | 24 #include "printing/backend/cups_connection.h" |
21 | 25 |
22 class Profile; | 26 class Profile; |
23 | 27 |
24 namespace chromeos { | 28 namespace chromeos { |
25 | 29 |
26 struct QueryResult { | 30 struct QueryResult { |
27 QueryResult(); | 31 QueryResult(); |
28 QueryResult(const QueryResult& other); | 32 QueryResult(const QueryResult& other); |
29 ~QueryResult(); | 33 ~QueryResult(); |
30 | 34 |
31 bool success; | 35 bool success; |
32 std::vector<::printing::QueueStatus> queues; | 36 std::vector<::printing::QueueStatus> queues; |
33 }; | 37 }; |
34 | 38 |
39 class CupsWrapper { | |
Carlson
2017/06/26 18:42:01
Class comment, esp why this class exists in the fi
skau
2017/06/26 23:15:16
Done.
| |
40 public: | |
41 CupsWrapper(); | |
42 ~CupsWrapper(); | |
43 | |
44 // Query CUPS for the current jobs for the given |printer_ids|. Writes result | |
45 // to |result|. | |
46 void QueryCups(const std::vector<std::string>& printer_ids, | |
47 QueryResult* result); | |
48 | |
49 // Cancel the print job on the blocking thread. | |
50 void CancelJobImpl(const std::string& printer_id, const int job_id); | |
51 | |
52 private: | |
53 // Access only on query_runner_. | |
Carlson
2017/06/26 18:42:01
It's not obvious here what query_runner_ you're ta
skau
2017/06/26 23:15:17
I think the presence of the sequence checker is su
| |
54 ::printing::CupsConnection cups_connection_; | |
55 | |
56 SEQUENCE_CHECKER(sequence_checker_); | |
57 }; | |
Carlson
2017/06/26 18:42:01
I think this is still unsafe to me, w.r.t destruct
skau
2017/06/26 23:15:16
That is correct. I'm digging through the document
| |
58 | |
35 class CupsPrintJobManagerImpl : public CupsPrintJobManager, | 59 class CupsPrintJobManagerImpl : public CupsPrintJobManager, |
36 public content::NotificationObserver { | 60 public content::NotificationObserver { |
37 public: | 61 public: |
38 explicit CupsPrintJobManagerImpl(Profile* profile); | 62 explicit CupsPrintJobManagerImpl(Profile* profile); |
39 ~CupsPrintJobManagerImpl() override; | 63 ~CupsPrintJobManagerImpl() override; |
40 | 64 |
41 // CupsPrintJobManager overrides: | 65 // CupsPrintJobManager overrides: |
42 void CancelPrintJob(CupsPrintJob* job) override; | 66 void CancelPrintJob(CupsPrintJob* job) override; |
43 bool SuspendPrintJob(CupsPrintJob* job) override; | 67 bool SuspendPrintJob(CupsPrintJob* job) override; |
44 bool ResumePrintJob(CupsPrintJob* job) override; | 68 bool ResumePrintJob(CupsPrintJob* job) override; |
(...skipping 13 matching lines...) Expand all Loading... | |
58 | 82 |
59 // Schedule a query of CUPS for print job status with the default delay. | 83 // Schedule a query of CUPS for print job status with the default delay. |
60 void ScheduleQuery(); | 84 void ScheduleQuery(); |
61 // Schedule a query of CUPS for print job status with a delay of |delay|. | 85 // Schedule a query of CUPS for print job status with a delay of |delay|. |
62 void ScheduleQuery(const base::TimeDelta& delay); | 86 void ScheduleQuery(const base::TimeDelta& delay); |
63 | 87 |
64 // Schedule the CUPS query off the UI thread. Posts results back to UI thread | 88 // Schedule the CUPS query off the UI thread. Posts results back to UI thread |
65 // to UpdateJobs. | 89 // to UpdateJobs. |
66 void PostQuery(); | 90 void PostQuery(); |
67 | 91 |
68 // Updates the state of a print job based on |printer_status| and |job|. | |
69 // Returns true if observers need to be notified of an update. | |
70 bool UpdatePrintJob(const ::printing::PrinterStatus& printer_status, | |
71 const ::printing::CupsJob& job, | |
72 CupsPrintJob* print_job); | |
73 | |
74 // Process jobs from CUPS and perform notifications. | 92 // Process jobs from CUPS and perform notifications. |
75 void UpdateJobs(const QueryResult& results); | 93 void UpdateJobs(std::unique_ptr<QueryResult> results); |
76 | 94 |
77 // Mark remaining jobs as errors and remove active jobs. | 95 // Mark remaining jobs as errors and remove active jobs. |
78 void PurgeJobs(); | 96 void PurgeJobs(); |
79 | 97 |
80 // Cancel the print job on the blocking thread. | |
81 void CancelJobImpl(const std::string& printer_id, const int job_id); | |
82 | |
83 // Notify observers that a state update has occured for |job|. | 98 // Notify observers that a state update has occured for |job|. |
84 void NotifyJobStateUpdate(CupsPrintJob* job); | 99 void NotifyJobStateUpdate(CupsPrintJob* job); |
85 | 100 |
86 // Ongoing print jobs. | 101 // Ongoing print jobs. |
87 std::map<std::string, std::unique_ptr<CupsPrintJob>> jobs_; | 102 std::map<std::string, std::unique_ptr<CupsPrintJob>> jobs_; |
88 | 103 |
89 // Prevents multiple queries from being scheduled simultaneously. | 104 // Prevents multiple queries from being scheduled simultaneously. |
90 bool in_query_ = false; | 105 bool in_query_ = false; |
91 | 106 |
92 // Records the number of consecutive times the GetJobs query has failed. | 107 // Records the number of consecutive times the GetJobs query has failed. |
93 int retry_count_ = 0; | 108 int retry_count_ = 0; |
94 | 109 |
95 ::printing::CupsConnection cups_connection_; | 110 // Container for the cups connection to ensure that accesses are sequenced. |
111 CupsWrapper cups_wrapper_; | |
112 base::WeakPtrFactory<CupsWrapper> cups_wrapper_ptr_factory_; | |
Carlson
2017/06/26 18:42:01
I don't understand why you aren't putting the weak
skau
2017/06/26 23:15:17
It's SupportsWeakPtr now.
| |
113 | |
96 content::NotificationRegistrar registrar_; | 114 content::NotificationRegistrar registrar_; |
115 | |
116 // Task runner for queries to CUPS. | |
117 scoped_refptr<base::SequencedTaskRunner> query_runner_; | |
118 | |
119 // Task runner to for the Browser UI thread. | |
120 scoped_refptr<base::SingleThreadTaskRunner> browser_thread_runner_; | |
121 | |
97 base::WeakPtrFactory<CupsPrintJobManagerImpl> weak_ptr_factory_; | 122 base::WeakPtrFactory<CupsPrintJobManagerImpl> weak_ptr_factory_; |
98 | 123 |
99 DISALLOW_COPY_AND_ASSIGN(CupsPrintJobManagerImpl); | 124 DISALLOW_COPY_AND_ASSIGN(CupsPrintJobManagerImpl); |
100 }; | 125 }; |
101 | 126 |
102 } // namespace chromeos | 127 } // namespace chromeos |
103 | 128 |
104 #endif // CHROME_BROWSER_CHROMEOS_PRINTING_CUPS_PRINT_JOB_MANAGER_IMPL_H_ | 129 #endif // CHROME_BROWSER_CHROMEOS_PRINTING_CUPS_PRINT_JOB_MANAGER_IMPL_H_ |
OLD | NEW |