Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / chrome / browser / ui / webui / print_preview / extension_printer_handler.h
blob5f3d1bb2efa8e3850f7a671551fce147987c02b4
1 // Copyright 2015 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.
5 #ifndef CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_
6 #define CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_
8 #include <string>
9 #include <vector>
11 #include "base/macros.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/weak_ptr.h"
14 #include "base/strings/string16.h"
15 #include "chrome/browser/ui/webui/print_preview/printer_handler.h"
16 #include "extensions/browser/api/printer_provider/printer_provider_api.h"
18 namespace base {
19 class DictionaryValue;
20 class ListValue;
21 class RefCountedMemory;
22 class TaskRunner;
25 namespace content {
26 class BrowserContext;
29 namespace cloud_devices {
30 class CloudDeviceDescription;
33 namespace device {
34 class UsbDevice;
37 namespace gfx {
38 class Size;
41 namespace local_discovery {
42 class PWGRasterConverter;
45 // Implementation of PrinterHandler interface backed by printerProvider
46 // extension API.
47 class ExtensionPrinterHandler : public PrinterHandler {
48 public:
49 using PrintJobCallback =
50 base::Callback<void(scoped_ptr<extensions::PrinterProviderPrintJob>)>;
52 ExtensionPrinterHandler(
53 content::BrowserContext* browser_context,
54 const scoped_refptr<base::TaskRunner>& slow_task_runner);
56 ~ExtensionPrinterHandler() override;
58 // PrinterHandler implementation:
59 void Reset() override;
60 void StartGetPrinters(
61 const PrinterHandler::GetPrintersCallback& callback) override;
62 void StartGetCapability(
63 const std::string& destination_id,
64 const PrinterHandler::GetCapabilityCallback& calback) override;
65 // TODO(tbarzic): It might make sense to have the strings in a single struct.
66 void StartPrint(const std::string& destination_id,
67 const std::string& capability,
68 const base::string16& job_title,
69 const std::string& ticket_json,
70 const gfx::Size& page_size,
71 const scoped_refptr<base::RefCountedMemory>& print_data,
72 const PrinterHandler::PrintCallback& callback) override;
74 private:
75 friend class ExtensionPrinterHandlerTest;
77 void SetPwgRasterConverterForTesting(
78 scoped_ptr<local_discovery::PWGRasterConverter> pwg_raster_converter);
80 // Converts |data| to PWG raster format (from PDF) for a printer described
81 // by |printer_description|.
82 // |callback| is called with the converted data.
83 void ConvertToPWGRaster(
84 const scoped_refptr<base::RefCountedMemory>& data,
85 const cloud_devices::CloudDeviceDescription& printer_description,
86 const cloud_devices::CloudDeviceDescription& ticket,
87 const gfx::Size& page_size,
88 scoped_ptr<extensions::PrinterProviderPrintJob> job,
89 const PrintJobCallback& callback);
91 // Sets print job document data and dispatches it using printerProvider API.
92 void DispatchPrintJob(
93 const PrinterHandler::PrintCallback& callback,
94 scoped_ptr<extensions::PrinterProviderPrintJob> print_job);
96 // Methods used as wrappers to callbacks for extensions::PrinterProviderAPI
97 // methods, primarily so the callbacks can be bound to this class' weak ptr.
98 // They just propagate results to callbacks passed to them.
99 void WrapGetPrintersCallback(
100 const PrinterHandler::GetPrintersCallback& callback,
101 const base::ListValue& printers,
102 bool done);
103 void WrapGetCapabilityCallback(
104 const PrinterHandler::GetCapabilityCallback& callback,
105 const std::string& destination_id,
106 const base::DictionaryValue& capability);
107 void WrapPrintCallback(const PrinterHandler::PrintCallback& callback,
108 bool success,
109 const std::string& status);
110 void OnUsbDevicesEnumerated(
111 const PrinterHandler::GetPrintersCallback& callback,
112 const std::vector<scoped_refptr<device::UsbDevice>>& devices);
114 content::BrowserContext* browser_context_;
116 scoped_ptr<local_discovery::PWGRasterConverter> pwg_raster_converter_;
117 int pending_enumeration_count_ = 0;
119 scoped_refptr<base::TaskRunner> slow_task_runner_;
121 base::WeakPtrFactory<ExtensionPrinterHandler> weak_ptr_factory_;
123 DISALLOW_COPY_AND_ASSIGN(ExtensionPrinterHandler);
126 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_