| 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 #include <vector> |
| 10 | 10 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 } | 43 } |
| 44 | 44 |
| 45 // Implementation of PrinterHandler interface backed by printerProvider | 45 // Implementation of PrinterHandler interface backed by printerProvider |
| 46 // extension API. | 46 // extension API. |
| 47 class ExtensionPrinterHandler : public PrinterHandler { | 47 class ExtensionPrinterHandler : public PrinterHandler { |
| 48 public: | 48 public: |
| 49 using GetUsbPrintersCallback = | 49 using GetUsbPrintersCallback = |
| 50 base::Callback<void(const base::ListValue& printers)>; | 50 base::Callback<void(const base::ListValue& printers)>; |
| 51 using PrintJobCallback = | 51 using PrintJobCallback = |
| 52 base::Callback<void(scoped_ptr<extensions::PrinterProviderPrintJob>)>; | 52 base::Callback<void(scoped_ptr<extensions::PrinterProviderPrintJob>)>; |
| 53 using GrantUsbPrinterAccessCallback = |
| 54 base::Callback<void(const base::DictionaryValue& printer_info)>; |
| 53 | 55 |
| 54 ExtensionPrinterHandler( | 56 ExtensionPrinterHandler( |
| 55 content::BrowserContext* browser_context, | 57 content::BrowserContext* browser_context, |
| 56 const scoped_refptr<base::TaskRunner>& slow_task_runner); | 58 const scoped_refptr<base::TaskRunner>& slow_task_runner); |
| 57 | 59 |
| 58 ~ExtensionPrinterHandler() override; | 60 ~ExtensionPrinterHandler() override; |
| 59 | 61 |
| 60 // PrinterHandler implementation: | 62 // PrinterHandler implementation: |
| 61 void Reset() override; | 63 void Reset() override; |
| 62 void StartGetPrinters( | 64 void StartGetPrinters( |
| 63 const PrinterHandler::GetPrintersCallback& callback) override; | 65 const PrinterHandler::GetPrintersCallback& callback) override; |
| 64 void StartGetUsbPrinters(const GetUsbPrintersCallback& callback); | 66 void StartGetUsbPrinters(const GetUsbPrintersCallback& callback); |
| 65 void StartGetCapability( | 67 void StartGetCapability( |
| 66 const std::string& destination_id, | 68 const std::string& destination_id, |
| 67 const PrinterHandler::GetCapabilityCallback& calback) override; | 69 const PrinterHandler::GetCapabilityCallback& calback) override; |
| 68 // TODO(tbarzic): It might make sense to have the strings in a single struct. | 70 // TODO(tbarzic): It might make sense to have the strings in a single struct. |
| 69 void StartPrint(const std::string& destination_id, | 71 void StartPrint(const std::string& destination_id, |
| 70 const std::string& capability, | 72 const std::string& capability, |
| 71 const base::string16& job_title, | 73 const base::string16& job_title, |
| 72 const std::string& ticket_json, | 74 const std::string& ticket_json, |
| 73 const gfx::Size& page_size, | 75 const gfx::Size& page_size, |
| 74 const scoped_refptr<base::RefCountedMemory>& print_data, | 76 const scoped_refptr<base::RefCountedMemory>& print_data, |
| 75 const PrinterHandler::PrintCallback& callback) override; | 77 const PrinterHandler::PrintCallback& callback) override; |
| 78 void StartGrantUsbPrinterAccess( |
| 79 const std::string& extension_id, |
| 80 int device_id, |
| 81 const GrantUsbPrinterAccessCallback& callback); |
| 76 | 82 |
| 77 private: | 83 private: |
| 78 friend class ExtensionPrinterHandlerTest; | 84 friend class ExtensionPrinterHandlerTest; |
| 79 | 85 |
| 80 void SetPwgRasterConverterForTesting( | 86 void SetPwgRasterConverterForTesting( |
| 81 scoped_ptr<local_discovery::PWGRasterConverter> pwg_raster_converter); | 87 scoped_ptr<local_discovery::PWGRasterConverter> pwg_raster_converter); |
| 82 | 88 |
| 83 // Converts |data| to PWG raster format (from PDF) for a printer described | 89 // Converts |data| to PWG raster format (from PDF) for a printer described |
| 84 // by |printer_description|. | 90 // by |printer_description|. |
| 85 // |callback| is called with the converted data. | 91 // |callback| is called with the converted data. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 103 const PrinterHandler::GetPrintersCallback& callback, | 109 const PrinterHandler::GetPrintersCallback& callback, |
| 104 const base::ListValue& printers, | 110 const base::ListValue& printers, |
| 105 bool done); | 111 bool done); |
| 106 void WrapGetCapabilityCallback( | 112 void WrapGetCapabilityCallback( |
| 107 const PrinterHandler::GetCapabilityCallback& callback, | 113 const PrinterHandler::GetCapabilityCallback& callback, |
| 108 const std::string& destination_id, | 114 const std::string& destination_id, |
| 109 const base::DictionaryValue& capability); | 115 const base::DictionaryValue& capability); |
| 110 void WrapPrintCallback(const PrinterHandler::PrintCallback& callback, | 116 void WrapPrintCallback(const PrinterHandler::PrintCallback& callback, |
| 111 bool success, | 117 bool success, |
| 112 const std::string& status); | 118 const std::string& status); |
| 119 void WrapGrantUsbPrinterAccessCallback( |
| 120 const GrantUsbPrinterAccessCallback& callback, |
| 121 const base::DictionaryValue& printer_info); |
| 122 |
| 113 void OnUsbDevicesEnumerated( | 123 void OnUsbDevicesEnumerated( |
| 114 const GetUsbPrintersCallback& callback, | 124 const GetUsbPrintersCallback& callback, |
| 115 const std::vector<scoped_refptr<device::UsbDevice>>& devices); | 125 const std::vector<scoped_refptr<device::UsbDevice>>& devices); |
| 116 | 126 |
| 117 content::BrowserContext* browser_context_; | 127 content::BrowserContext* browser_context_; |
| 118 | 128 |
| 119 scoped_ptr<local_discovery::PWGRasterConverter> pwg_raster_converter_; | 129 scoped_ptr<local_discovery::PWGRasterConverter> pwg_raster_converter_; |
| 120 | 130 |
| 121 scoped_refptr<base::TaskRunner> slow_task_runner_; | 131 scoped_refptr<base::TaskRunner> slow_task_runner_; |
| 122 | 132 |
| 123 base::WeakPtrFactory<ExtensionPrinterHandler> weak_ptr_factory_; | 133 base::WeakPtrFactory<ExtensionPrinterHandler> weak_ptr_factory_; |
| 124 | 134 |
| 125 DISALLOW_COPY_AND_ASSIGN(ExtensionPrinterHandler); | 135 DISALLOW_COPY_AND_ASSIGN(ExtensionPrinterHandler); |
| 126 }; | 136 }; |
| 127 | 137 |
| 128 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_ | 138 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_ |
| OLD | NEW |