Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 PRINTING_BACKEND_CUPS_CONNECTION_H_ | 5 #ifndef PRINTING_BACKEND_CUPS_CONNECTION_H_ |
| 6 #define PRINTING_BACKEND_CUPS_CONNECTION_H_ | 6 #define PRINTING_BACKEND_CUPS_CONNECTION_H_ |
| 7 | 7 |
| 8 #include <cups/cups.h> | 8 #include <cups/cups.h> |
| 9 | 9 |
| 10 #include <memory> | 10 #include <memory> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/macros.h" | 14 #include "base/macros.h" |
| 15 #include "base/memory/weak_ptr.h" | 15 #include "base/memory/weak_ptr.h" |
| 16 #include "printing/backend/cups_deleters.h" | 16 #include "printing/backend/cups_deleters.h" |
| 17 #include "printing/backend/cups_jobs.h" | |
| 17 #include "printing/backend/cups_printer.h" | 18 #include "printing/backend/cups_printer.h" |
| 18 #include "printing/printing_export.h" | 19 #include "printing/printing_export.h" |
| 19 #include "url/gurl.h" | 20 #include "url/gurl.h" |
| 20 | 21 |
| 21 namespace printing { | 22 namespace printing { |
| 22 | 23 |
| 23 // Represents a print job sent to the queue. | 24 // Represents the status of a printer queue. |
| 24 struct PRINTING_EXPORT CupsJob { | 25 struct PRINTING_EXPORT QueueStatus { |
| 25 enum JobState { | 26 QueueStatus(PrinterStatus status, std::vector<CupsJob> cups_jobs) |
|
Carlson
2017/02/24 00:02:08
I suspect the second argument here should be a con
skau
2017/02/28 00:59:58
I've removed the constructor and I'm populating th
| |
| 26 UNKNOWN, | 27 : printer_status(status), jobs(cups_jobs) {} |
| 27 PENDING, | |
| 28 HELD, | |
| 29 COMPLETED, | |
| 30 PROCESSING, | |
| 31 STOPPED, | |
| 32 CANCELED, | |
| 33 ABORTED | |
| 34 }; | |
| 35 | 28 |
| 36 int id; | 29 PrinterStatus printer_status; |
| 37 std::string title; | 30 std::vector<CupsJob> jobs; |
| 38 std::string printer_id; | |
| 39 JobState state; | |
| 40 }; | 31 }; |
| 41 | 32 |
| 42 // Represents a connection to a CUPS server. | 33 // Represents a connection to a CUPS server. |
| 43 class PRINTING_EXPORT CupsConnection { | 34 class PRINTING_EXPORT CupsConnection { |
| 44 public: | 35 public: |
| 45 CupsConnection(const GURL& print_server_url, | 36 CupsConnection(const GURL& print_server_url, |
| 46 http_encryption_t encryption, | 37 http_encryption_t encryption, |
| 47 bool blocking); | 38 bool blocking); |
| 48 | 39 |
| 49 CupsConnection(CupsConnection&& connection); | 40 CupsConnection(CupsConnection&& connection); |
| 50 | 41 |
| 51 ~CupsConnection(); | 42 ~CupsConnection(); |
| 52 | 43 |
| 53 // Returns a vector of all the printers configure on the CUPS server. | 44 // Returns a vector of all the printers configure on the CUPS server. |
| 54 std::vector<CupsPrinter> GetDests(); | 45 std::vector<CupsPrinter> GetDests(); |
| 55 | 46 |
| 56 // Returns a printer for |printer_name| from the connected server. | 47 // Returns a printer for |printer_name| from the connected server. |
| 57 std::unique_ptr<CupsPrinter> GetPrinter(const std::string& printer_name); | 48 std::unique_ptr<CupsPrinter> GetPrinter(const std::string& printer_name); |
| 58 | 49 |
| 59 // Returns a list of print jobs from all connected printers. | 50 // Queries CUPS for printer queue status for |printer_ids|. Populates |jobs| |
| 60 std::vector<CupsJob> GetJobs(); | 51 // with said information with one QueueStatus per printer_id. Returns true if |
| 52 // all the queries were successful. | |
|
Carlson
2017/02/24 00:02:08
What can we expect about |jobs| if not all the que
skau
2017/02/28 00:59:58
Done.
| |
| 53 bool GetJobs(const std::vector<std::string>& printer_ids, | |
| 54 std::vector<QueueStatus>* jobs); | |
| 61 | 55 |
| 62 std::string server_name() const; | 56 std::string server_name() const; |
| 63 | 57 |
| 64 int last_error() const; | 58 int last_error() const; |
| 65 | 59 |
| 66 private: | 60 private: |
| 67 // lazily initialize http connection | 61 // lazily initialize http connection |
| 68 bool Connect(); | 62 bool Connect(); |
| 69 | 63 |
| 70 GURL print_server_url_; | 64 GURL print_server_url_; |
| 71 http_encryption_t cups_encryption_; | 65 http_encryption_t cups_encryption_; |
| 72 bool blocking_; | 66 bool blocking_; |
| 73 | 67 |
| 74 std::unique_ptr<http_t, HttpDeleter> cups_http_; | 68 std::unique_ptr<http_t, HttpDeleter> cups_http_; |
| 75 | 69 |
| 76 DISALLOW_COPY_AND_ASSIGN(CupsConnection); | 70 DISALLOW_COPY_AND_ASSIGN(CupsConnection); |
| 77 }; | 71 }; |
| 78 | 72 |
| 79 } // namespace printing | 73 } // namespace printing |
| 80 | 74 |
| 81 #endif // PRINTING_BACKEND_CUPS_CONNECTION_H_ | 75 #endif // PRINTING_BACKEND_CUPS_CONNECTION_H_ |
| OLD | NEW |