Chromium Code Reviews| Index: chrome/browser/chromeos/printing/cups_print_job_manager_impl.h |
| diff --git a/chrome/browser/chromeos/printing/cups_print_job_manager_impl.h b/chrome/browser/chromeos/printing/cups_print_job_manager_impl.h |
| index cdf723691dc5b914fc963c6fa435d7e120698592..101655a1aa1124edc0f5670865cfcd45658f17e2 100644 |
| --- a/chrome/browser/chromeos/printing/cups_print_job_manager_impl.h |
| +++ b/chrome/browser/chromeos/printing/cups_print_job_manager_impl.h |
| @@ -11,7 +11,11 @@ |
| #include <unordered_map> |
| #include <vector> |
| +#include "base/memory/ref_counted.h" |
| #include "base/memory/weak_ptr.h" |
| +#include "base/sequence_checker.h" |
| +#include "base/sequenced_task_runner.h" |
| +#include "base/single_thread_task_runner.h" |
| #include "chrome/browser/chromeos/printing/cups_print_job.h" |
| #include "chrome/browser/chromeos/printing/cups_print_job_manager.h" |
| #include "chrome/browser/chromeos/printing/printers_manager.h" |
| @@ -32,6 +36,26 @@ struct QueryResult { |
| std::vector<::printing::QueueStatus> queues; |
| }; |
| +// A wrapper around the CUPS connection to ensure that it's always accessed on |
| +// the same sequence. |
| +class CupsWrapper : public base::SupportsWeakPtr<CupsWrapper> { |
| + public: |
| + CupsWrapper(); |
| + ~CupsWrapper(); |
| + |
| + // Query CUPS for the current jobs for the given |printer_ids|. Writes result |
| + // to |result|. |
| + void QueryCups(const std::vector<std::string>& printer_ids, |
| + QueryResult* result); |
| + |
| + // Cancel the print job on the blocking thread. |
| + void CancelJobImpl(const std::string& printer_id, const int job_id); |
| + |
| + private: |
| + ::printing::CupsConnection cups_connection_; |
| + SEQUENCE_CHECKER(sequence_checker_); |
| +}; |
|
gab
2017/06/27 17:44:18
DISALLOW_COPY_AND_ASSIGN
skau
2017/06/27 20:25:41
Done.
|
| + |
| class CupsPrintJobManagerImpl : public CupsPrintJobManager, |
| public content::NotificationObserver { |
| public: |
| @@ -65,21 +89,12 @@ class CupsPrintJobManagerImpl : public CupsPrintJobManager, |
| // to UpdateJobs. |
| void PostQuery(); |
| - // Updates the state of a print job based on |printer_status| and |job|. |
| - // Returns true if observers need to be notified of an update. |
| - bool UpdatePrintJob(const ::printing::PrinterStatus& printer_status, |
| - const ::printing::CupsJob& job, |
| - CupsPrintJob* print_job); |
| - |
| // Process jobs from CUPS and perform notifications. |
| - void UpdateJobs(const QueryResult& results); |
| + void UpdateJobs(std::unique_ptr<QueryResult> results); |
| // Mark remaining jobs as errors and remove active jobs. |
| void PurgeJobs(); |
| - // Cancel the print job on the blocking thread. |
| - void CancelJobImpl(const std::string& printer_id, const int job_id); |
| - |
| // Notify observers that a state update has occured for |job|. |
| void NotifyJobStateUpdate(CupsPrintJob* job); |
| @@ -92,8 +107,12 @@ class CupsPrintJobManagerImpl : public CupsPrintJobManager, |
| // Records the number of consecutive times the GetJobs query has failed. |
| int retry_count_ = 0; |
| - ::printing::CupsConnection cups_connection_; |
| + CupsWrapper cups_wrapper_; |
|
gab
2017/06/27 17:44:18
To ensure this is deleted on its sequence you'll n
skau
2017/06/27 20:25:41
Thanks! I was looking for that.
|
| content::NotificationRegistrar registrar_; |
| + // Task runner for queries to CUPS. |
| + scoped_refptr<base::SequencedTaskRunner> query_runner_; |
| + // Task runner to for the Browser UI thread. |
| + scoped_refptr<base::SingleThreadTaskRunner> browser_thread_runner_; |
| base::WeakPtrFactory<CupsPrintJobManagerImpl> weak_ptr_factory_; |
| DISALLOW_COPY_AND_ASSIGN(CupsPrintJobManagerImpl); |