printing_context_chromeos.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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
  3. // found in the LICENSE file.
  4. #ifndef PRINTING_PRINTING_CONTEXT_CHROMEOS_H_
  5. #define PRINTING_PRINTING_CONTEXT_CHROMEOS_H_
  6. #include <memory>
  7. #include <string>
  8. #include <vector>
  9. #include "printing/backend/cups_connection.h"
  10. #include "printing/backend/cups_deleters.h"
  11. #include "printing/backend/cups_printer.h"
  12. #include "printing/mojom/print.mojom.h"
  13. #include "printing/printing_context.h"
  14. namespace printing {
  15. class COMPONENT_EXPORT(PRINTING) PrintingContextChromeos
  16. : public PrintingContext {
  17. public:
  18. static std::unique_ptr<PrintingContextChromeos> CreateForTesting(
  19. Delegate* delegate,
  20. std::unique_ptr<CupsConnection> connection);
  21. explicit PrintingContextChromeos(Delegate* delegate);
  22. PrintingContextChromeos(const PrintingContextChromeos&) = delete;
  23. PrintingContextChromeos& operator=(const PrintingContextChromeos&) = delete;
  24. ~PrintingContextChromeos() override;
  25. // PrintingContext implementation.
  26. void AskUserForSettings(int max_pages,
  27. bool has_selection,
  28. bool is_scripted,
  29. PrintSettingsCallback callback) override;
  30. mojom::ResultCode UseDefaultSettings() override;
  31. gfx::Size GetPdfPaperSizeDeviceUnits() override;
  32. mojom::ResultCode UpdatePrinterSettings(
  33. const PrinterSettings& printer_settings) override;
  34. mojom::ResultCode NewDocument(const std::u16string& document_name) override;
  35. mojom::ResultCode PrintDocument(const MetafilePlayer& metafile,
  36. const PrintSettings& settings,
  37. uint32_t num_pages) override;
  38. mojom::ResultCode DocumentDone() override;
  39. void Cancel() override;
  40. void ReleaseContext() override;
  41. printing::NativeDrawingContext context() const override;
  42. mojom::ResultCode StreamData(const std::vector<char>& buffer);
  43. private:
  44. // For testing. Use CreateForTesting() to create.
  45. PrintingContextChromeos(Delegate* delegate,
  46. std::unique_ptr<CupsConnection> connection);
  47. // Lazily initializes `printer_`.
  48. mojom::ResultCode InitializeDevice(const std::string& device);
  49. const std::unique_ptr<CupsConnection> connection_;
  50. std::unique_ptr<CupsPrinter> printer_;
  51. std::vector<ScopedCupsOption> cups_options_;
  52. bool send_user_info_ = false;
  53. std::string username_;
  54. };
  55. // This has the side effect of recording UMA for advanced attributes usage,
  56. // so only call once per job.
  57. COMPONENT_EXPORT(PRINTING)
  58. std::vector<ScopedCupsOption> SettingsToCupsOptions(
  59. const PrintSettings& settings);
  60. } // namespace printing
  61. #endif // PRINTING_PRINTING_CONTEXT_CHROMEOS_H_