OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_ | 5 #ifndef CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_ |
6 #define CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_ | 6 #define CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
| 9 #include <vector> |
9 | 10 |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
13 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
14 #include "chrome/browser/ui/webui/print_preview/printer_handler.h" | 15 #include "chrome/browser/ui/webui/print_preview/printer_handler.h" |
15 #include "extensions/browser/api/printer_provider/printer_provider_api.h" | 16 #include "extensions/browser/api/printer_provider/printer_provider_api.h" |
16 | 17 |
17 namespace base { | 18 namespace base { |
18 class DictionaryValue; | 19 class DictionaryValue; |
19 class ListValue; | 20 class ListValue; |
20 class RefCountedMemory; | 21 class RefCountedMemory; |
21 class TaskRunner; | 22 class TaskRunner; |
22 } | 23 } |
23 | 24 |
24 namespace content { | 25 namespace content { |
25 class BrowserContext; | 26 class BrowserContext; |
26 } | 27 } |
27 | 28 |
28 namespace cloud_devices { | 29 namespace cloud_devices { |
29 class CloudDeviceDescription; | 30 class CloudDeviceDescription; |
30 } | 31 } |
31 | 32 |
| 33 namespace device { |
| 34 class UsbDevice; |
| 35 } |
| 36 |
32 namespace gfx { | 37 namespace gfx { |
33 class Size; | 38 class Size; |
34 } | 39 } |
35 | 40 |
36 namespace local_discovery { | 41 namespace local_discovery { |
37 class PWGRasterConverter; | 42 class PWGRasterConverter; |
38 } | 43 } |
39 | 44 |
40 // Implementation of PrinterHandler interface backed by printerProvider | 45 // Implementation of PrinterHandler interface backed by printerProvider |
41 // extension API. | 46 // extension API. |
42 class ExtensionPrinterHandler : public PrinterHandler { | 47 class ExtensionPrinterHandler : public PrinterHandler { |
43 public: | 48 public: |
| 49 using GetUsbPrintersCallback = |
| 50 base::Callback<void(const base::ListValue& printers)>; |
44 using PrintJobCallback = | 51 using PrintJobCallback = |
45 base::Callback<void(scoped_ptr<extensions::PrinterProviderPrintJob>)>; | 52 base::Callback<void(scoped_ptr<extensions::PrinterProviderPrintJob>)>; |
46 | 53 |
47 ExtensionPrinterHandler( | 54 ExtensionPrinterHandler( |
48 content::BrowserContext* browser_context, | 55 content::BrowserContext* browser_context, |
49 const scoped_refptr<base::TaskRunner>& slow_task_runner); | 56 const scoped_refptr<base::TaskRunner>& slow_task_runner); |
50 | 57 |
51 ~ExtensionPrinterHandler() override; | 58 ~ExtensionPrinterHandler() override; |
52 | 59 |
53 // PrinterHandler implementation: | 60 // PrinterHandler implementation: |
54 void Reset() override; | 61 void Reset() override; |
55 void StartGetPrinters( | 62 void StartGetPrinters( |
56 const PrinterHandler::GetPrintersCallback& callback) override; | 63 const PrinterHandler::GetPrintersCallback& callback) override; |
| 64 void StartGetUsbPrinters(const GetUsbPrintersCallback& callback); |
57 void StartGetCapability( | 65 void StartGetCapability( |
58 const std::string& destination_id, | 66 const std::string& destination_id, |
59 const PrinterHandler::GetCapabilityCallback& calback) override; | 67 const PrinterHandler::GetCapabilityCallback& calback) override; |
60 // TODO(tbarzic): It might make sense to have the strings in a single struct. | 68 // TODO(tbarzic): It might make sense to have the strings in a single struct. |
61 void StartPrint(const std::string& destination_id, | 69 void StartPrint(const std::string& destination_id, |
62 const std::string& capability, | 70 const std::string& capability, |
63 const base::string16& job_title, | 71 const base::string16& job_title, |
64 const std::string& ticket_json, | 72 const std::string& ticket_json, |
65 const gfx::Size& page_size, | 73 const gfx::Size& page_size, |
66 const scoped_refptr<base::RefCountedMemory>& print_data, | 74 const scoped_refptr<base::RefCountedMemory>& print_data, |
(...skipping 19 matching lines...) Expand all Loading... |
86 // Sets print job document data and dispatches it using printerProvider API. | 94 // Sets print job document data and dispatches it using printerProvider API. |
87 void DispatchPrintJob( | 95 void DispatchPrintJob( |
88 const PrinterHandler::PrintCallback& callback, | 96 const PrinterHandler::PrintCallback& callback, |
89 scoped_ptr<extensions::PrinterProviderPrintJob> print_job); | 97 scoped_ptr<extensions::PrinterProviderPrintJob> print_job); |
90 | 98 |
91 // Methods used as wrappers to callbacks for extensions::PrinterProviderAPI | 99 // Methods used as wrappers to callbacks for extensions::PrinterProviderAPI |
92 // methods, primarily so the callbacks can be bound to this class' weak ptr. | 100 // methods, primarily so the callbacks can be bound to this class' weak ptr. |
93 // They just propagate results to callbacks passed to them. | 101 // They just propagate results to callbacks passed to them. |
94 void WrapGetPrintersCallback( | 102 void WrapGetPrintersCallback( |
95 const PrinterHandler::GetPrintersCallback& callback, | 103 const PrinterHandler::GetPrintersCallback& callback, |
96 const base::ListValue& pritners, | 104 const base::ListValue& printers, |
97 bool done); | 105 bool done); |
98 void WrapGetCapabilityCallback( | 106 void WrapGetCapabilityCallback( |
99 const PrinterHandler::GetCapabilityCallback& callback, | 107 const PrinterHandler::GetCapabilityCallback& callback, |
100 const std::string& destination_id, | 108 const std::string& destination_id, |
101 const base::DictionaryValue& capability); | 109 const base::DictionaryValue& capability); |
102 void WrapPrintCallback(const PrinterHandler::PrintCallback& callback, | 110 void WrapPrintCallback(const PrinterHandler::PrintCallback& callback, |
103 bool success, | 111 bool success, |
104 const std::string& status); | 112 const std::string& status); |
| 113 void OnUsbDevicesEnumerated( |
| 114 const GetUsbPrintersCallback& callback, |
| 115 const std::vector<scoped_refptr<device::UsbDevice>>& devices); |
105 | 116 |
106 content::BrowserContext* browser_context_; | 117 content::BrowserContext* browser_context_; |
107 | 118 |
108 scoped_ptr<local_discovery::PWGRasterConverter> pwg_raster_converter_; | 119 scoped_ptr<local_discovery::PWGRasterConverter> pwg_raster_converter_; |
109 | 120 |
110 scoped_refptr<base::TaskRunner> slow_task_runner_; | 121 scoped_refptr<base::TaskRunner> slow_task_runner_; |
111 | 122 |
112 base::WeakPtrFactory<ExtensionPrinterHandler> weak_ptr_factory_; | 123 base::WeakPtrFactory<ExtensionPrinterHandler> weak_ptr_factory_; |
113 | 124 |
114 DISALLOW_COPY_AND_ASSIGN(ExtensionPrinterHandler); | 125 DISALLOW_COPY_AND_ASSIGN(ExtensionPrinterHandler); |
115 }; | 126 }; |
116 | 127 |
117 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_ | 128 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_ |
OLD | NEW |