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..86c1b002c1d99cec51870938319bc8e77e43caaf 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; |
| }; |
| +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.
|
| + 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: |
| + // 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
|
| + ::printing::CupsConnection cups_connection_; |
| + |
| + SEQUENCE_CHECKER(sequence_checker_); |
| +}; |
|
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
|
| + |
| 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,18 @@ class CupsPrintJobManagerImpl : public CupsPrintJobManager, |
| // Records the number of consecutive times the GetJobs query has failed. |
| int retry_count_ = 0; |
| - ::printing::CupsConnection cups_connection_; |
| + // Container for the cups connection to ensure that accesses are sequenced. |
| + CupsWrapper cups_wrapper_; |
| + 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.
|
| + |
| 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); |