Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Side by Side Diff: chrome/browser/chromeos/printing/cups_print_job_manager_impl.h

Issue 2691093006: Implement IPP Get-Jobs and Get-Printer-Attributes requests. (Closed)
Patch Set: assign default values to id and state Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/weak_ptr.h" 14 #include "base/memory/weak_ptr.h"
15 #include "base/synchronization/lock.h"
15 #include "chrome/browser/chromeos/printing/cups_print_job.h" 16 #include "chrome/browser/chromeos/printing/cups_print_job.h"
16 #include "chrome/browser/chromeos/printing/cups_print_job_manager.h" 17 #include "chrome/browser/chromeos/printing/cups_print_job_manager.h"
17 #include "chrome/browser/chromeos/printing/printers_manager.h" 18 #include "chrome/browser/chromeos/printing/printers_manager.h"
18 #include "content/public/browser/notification_observer.h" 19 #include "content/public/browser/notification_observer.h"
19 #include "content/public/browser/notification_registrar.h" 20 #include "content/public/browser/notification_registrar.h"
20 #include "printing/backend/cups_connection.h" 21 #include "printing/backend/cups_connection.h"
21 22
22 class Profile; 23 class Profile;
23 24
24 namespace chromeos { 25 namespace chromeos {
25 26
27 struct QueryResult {
28 bool success;
29 std::vector<::printing::QueueStatus> queues;
30 };
31
26 class CupsPrintJobManagerImpl : public CupsPrintJobManager, 32 class CupsPrintJobManagerImpl : public CupsPrintJobManager,
27 public content::NotificationObserver { 33 public content::NotificationObserver {
28 public: 34 public:
29 explicit CupsPrintJobManagerImpl(Profile* profile); 35 explicit CupsPrintJobManagerImpl(Profile* profile);
30 ~CupsPrintJobManagerImpl() override; 36 ~CupsPrintJobManagerImpl() override;
31 37
32 // CupsPrintJobManager overrides: 38 // CupsPrintJobManager overrides:
33 bool CancelPrintJob(CupsPrintJob* job) override; 39 bool CancelPrintJob(CupsPrintJob* job) override;
34 bool SuspendPrintJob(CupsPrintJob* job) override; 40 bool SuspendPrintJob(CupsPrintJob* job) override;
35 bool ResumePrintJob(CupsPrintJob* job) override; 41 bool ResumePrintJob(CupsPrintJob* job) override;
36 42
37 // NotificationObserver overrides: 43 // NotificationObserver overrides:
38 void Observe(int type, 44 void Observe(int type,
39 const content::NotificationSource& source, 45 const content::NotificationSource& source,
40 const content::NotificationDetails& details) override; 46 const content::NotificationDetails& details) override;
41 47
42 private: 48 private:
43 // Begin monitoring a print job for a given |printer_name| with the given 49 // Begin monitoring a print job for a given |printer_name| with the given
44 // |title| with the pages |total_page_number|. 50 // |title| with the pages |total_page_number|.
45 bool CreatePrintJob(const std::string& printer_name, 51 bool CreatePrintJob(const std::string& printer_name,
46 const std::string& title, 52 const std::string& title,
47 int job_id, 53 int job_id,
48 int total_page_number); 54 int total_page_number);
49 55
50 // Schedule a query of CUPS for print job status with the default delay. 56 // Schedule a query of CUPS for print job status with the default delay.
51 void ScheduleQuery(); 57 void ScheduleQuery();
52 // Schedule a query of CUPS for print job status with a delay of |delay|. 58 // Schedule a query of CUPS for print job status with a delay of |delay|.
53 void ScheduleQuery(const base::TimeDelta& delay); 59 void ScheduleQuery(const base::TimeDelta& delay);
54 60
55 // Query CUPS for print job status. 61 // Schedule the CUPS query off the UI thread.
56 void QueryCups(); 62 void PostQuery();
57 63
58 // Process jobs from CUPS and perform notifications. 64 // Process jobs from CUPS and perform notifications.
59 void UpdateJobs(const std::vector<::printing::CupsJob>& jobs); 65 void UpdateJobs(const QueryResult& results);
66
67 // Mark remaining jobs as errors and remove active jobs.
68 void PurgeJobs();
60 69
61 // Updates the state and performs the appropriate notifications. 70 // Updates the state and performs the appropriate notifications.
62 void JobStateUpdated(CupsPrintJob* job, CupsPrintJob::State new_state); 71 void JobStateUpdated(CupsPrintJob* job, CupsPrintJob::State new_state);
63 72
64 // Ongoing print jobs. 73 // Ongoing print jobs.
65 std::map<std::string, std::unique_ptr<CupsPrintJob>> jobs_; 74 std::map<std::string, std::unique_ptr<CupsPrintJob>> jobs_;
66 75
67 // Prevents multiple queries from being scheduled simultaneously. 76 // Prevents multiple queries from being scheduled simultaneously.
68 bool in_query_ = false; 77 bool in_query_ = false;
69 78
79 // Records the number of consecutive times the GetJobs query has failed.
80 int retry_count = 0;
Carlson 2017/02/24 00:02:08 Missing trailing underscore?
skau 2017/02/28 00:59:58 Done.
81
70 ::printing::CupsConnection cups_connection_; 82 ::printing::CupsConnection cups_connection_;
71 content::NotificationRegistrar registrar_; 83 content::NotificationRegistrar registrar_;
72 base::WeakPtrFactory<CupsPrintJobManagerImpl> weak_ptr_factory_; 84 base::WeakPtrFactory<CupsPrintJobManagerImpl> weak_ptr_factory_;
73 85
74 DISALLOW_COPY_AND_ASSIGN(CupsPrintJobManagerImpl); 86 DISALLOW_COPY_AND_ASSIGN(CupsPrintJobManagerImpl);
75 }; 87 };
76 88
77 } // namespace chromeos 89 } // namespace chromeos
78 90
79 #endif // CHROME_BROWSER_CHROMEOS_PRINTING_CUPS_PRINT_JOB_MANAGER_IMPL_H_ 91 #endif // CHROME_BROWSER_CHROMEOS_PRINTING_CUPS_PRINT_JOB_MANAGER_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698