| 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 <memory> |
| 8 #include <string> | 9 #include <string> |
| 9 #include <vector> | 10 #include <vector> |
| 10 | 11 |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | |
| 13 #include "base/memory/weak_ptr.h" | 13 #include "base/memory/weak_ptr.h" |
| 14 #include "base/strings/string16.h" | 14 #include "base/strings/string16.h" |
| 15 #include "chrome/browser/ui/webui/print_preview/printer_handler.h" | 15 #include "chrome/browser/ui/webui/print_preview/printer_handler.h" |
| 16 #include "extensions/browser/api/printer_provider/printer_provider_api.h" | 16 #include "extensions/browser/api/printer_provider/printer_provider_api.h" |
| 17 | 17 |
| 18 namespace base { | 18 namespace base { |
| 19 class DictionaryValue; | 19 class DictionaryValue; |
| 20 class ListValue; | 20 class ListValue; |
| 21 class RefCountedMemory; | 21 class RefCountedMemory; |
| 22 class TaskRunner; | 22 class TaskRunner; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 39 } | 39 } |
| 40 | 40 |
| 41 namespace printing { | 41 namespace printing { |
| 42 class PWGRasterConverter; | 42 class PWGRasterConverter; |
| 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 PrintJobCallback = | 49 using PrintJobCallback = base::Callback<void( |
| 50 base::Callback<void(scoped_ptr<extensions::PrinterProviderPrintJob>)>; | 50 std::unique_ptr<extensions::PrinterProviderPrintJob>)>; |
| 51 | 51 |
| 52 ExtensionPrinterHandler( | 52 ExtensionPrinterHandler( |
| 53 content::BrowserContext* browser_context, | 53 content::BrowserContext* browser_context, |
| 54 const scoped_refptr<base::TaskRunner>& slow_task_runner); | 54 const scoped_refptr<base::TaskRunner>& slow_task_runner); |
| 55 | 55 |
| 56 ~ExtensionPrinterHandler() override; | 56 ~ExtensionPrinterHandler() override; |
| 57 | 57 |
| 58 // PrinterHandler implementation: | 58 // PrinterHandler implementation: |
| 59 void Reset() override; | 59 void Reset() override; |
| 60 void StartGetPrinters( | 60 void StartGetPrinters( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 71 const scoped_refptr<base::RefCountedMemory>& print_data, | 71 const scoped_refptr<base::RefCountedMemory>& print_data, |
| 72 const PrinterHandler::PrintCallback& callback) override; | 72 const PrinterHandler::PrintCallback& callback) override; |
| 73 void StartGrantPrinterAccess( | 73 void StartGrantPrinterAccess( |
| 74 const std::string& printer_id, | 74 const std::string& printer_id, |
| 75 const PrinterHandler::GetPrinterInfoCallback& callback) override; | 75 const PrinterHandler::GetPrinterInfoCallback& callback) override; |
| 76 | 76 |
| 77 private: | 77 private: |
| 78 friend class ExtensionPrinterHandlerTest; | 78 friend class ExtensionPrinterHandlerTest; |
| 79 | 79 |
| 80 void SetPWGRasterConverterForTesting( | 80 void SetPWGRasterConverterForTesting( |
| 81 scoped_ptr<printing::PWGRasterConverter> pwg_raster_converter); | 81 std::unique_ptr<printing::PWGRasterConverter> pwg_raster_converter); |
| 82 | 82 |
| 83 // Converts |data| to PWG raster format (from PDF) for a printer described | 83 // Converts |data| to PWG raster format (from PDF) for a printer described |
| 84 // by |printer_description|. | 84 // by |printer_description|. |
| 85 // |callback| is called with the converted data. | 85 // |callback| is called with the converted data. |
| 86 void ConvertToPWGRaster( | 86 void ConvertToPWGRaster( |
| 87 const scoped_refptr<base::RefCountedMemory>& data, | 87 const scoped_refptr<base::RefCountedMemory>& data, |
| 88 const cloud_devices::CloudDeviceDescription& printer_description, | 88 const cloud_devices::CloudDeviceDescription& printer_description, |
| 89 const cloud_devices::CloudDeviceDescription& ticket, | 89 const cloud_devices::CloudDeviceDescription& ticket, |
| 90 const gfx::Size& page_size, | 90 const gfx::Size& page_size, |
| 91 scoped_ptr<extensions::PrinterProviderPrintJob> job, | 91 std::unique_ptr<extensions::PrinterProviderPrintJob> job, |
| 92 const PrintJobCallback& callback); | 92 const PrintJobCallback& callback); |
| 93 | 93 |
| 94 // Sets print job document data and dispatches it using printerProvider API. | 94 // Sets print job document data and dispatches it using printerProvider API. |
| 95 void DispatchPrintJob( | 95 void DispatchPrintJob( |
| 96 const PrinterHandler::PrintCallback& callback, | 96 const PrinterHandler::PrintCallback& callback, |
| 97 scoped_ptr<extensions::PrinterProviderPrintJob> print_job); | 97 std::unique_ptr<extensions::PrinterProviderPrintJob> print_job); |
| 98 | 98 |
| 99 // Methods used as wrappers to callbacks for extensions::PrinterProviderAPI | 99 // Methods used as wrappers to callbacks for extensions::PrinterProviderAPI |
| 100 // 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. |
| 101 // They just propagate results to callbacks passed to them. | 101 // They just propagate results to callbacks passed to them. |
| 102 void WrapGetPrintersCallback( | 102 void WrapGetPrintersCallback( |
| 103 const PrinterHandler::GetPrintersCallback& callback, | 103 const PrinterHandler::GetPrintersCallback& callback, |
| 104 const base::ListValue& printers, | 104 const base::ListValue& printers, |
| 105 bool done); | 105 bool done); |
| 106 void WrapGetCapabilityCallback( | 106 void WrapGetCapabilityCallback( |
| 107 const PrinterHandler::GetCapabilityCallback& callback, | 107 const PrinterHandler::GetCapabilityCallback& callback, |
| 108 const std::string& destination_id, | 108 const std::string& destination_id, |
| 109 const base::DictionaryValue& capability); | 109 const base::DictionaryValue& capability); |
| 110 void WrapPrintCallback(const PrinterHandler::PrintCallback& callback, | 110 void WrapPrintCallback(const PrinterHandler::PrintCallback& callback, |
| 111 bool success, | 111 bool success, |
| 112 const std::string& status); | 112 const std::string& status); |
| 113 void WrapGetPrinterInfoCallback(const GetPrinterInfoCallback& callback, | 113 void WrapGetPrinterInfoCallback(const GetPrinterInfoCallback& callback, |
| 114 const base::DictionaryValue& printer_info); | 114 const base::DictionaryValue& printer_info); |
| 115 | 115 |
| 116 void OnUsbDevicesEnumerated( | 116 void OnUsbDevicesEnumerated( |
| 117 const PrinterHandler::GetPrintersCallback& callback, | 117 const PrinterHandler::GetPrintersCallback& callback, |
| 118 const std::vector<scoped_refptr<device::UsbDevice>>& devices); | 118 const std::vector<scoped_refptr<device::UsbDevice>>& devices); |
| 119 | 119 |
| 120 content::BrowserContext* browser_context_; | 120 content::BrowserContext* browser_context_; |
| 121 | 121 |
| 122 scoped_ptr<printing::PWGRasterConverter> pwg_raster_converter_; | 122 std::unique_ptr<printing::PWGRasterConverter> pwg_raster_converter_; |
| 123 int pending_enumeration_count_ = 0; | 123 int pending_enumeration_count_ = 0; |
| 124 | 124 |
| 125 scoped_refptr<base::TaskRunner> slow_task_runner_; | 125 scoped_refptr<base::TaskRunner> slow_task_runner_; |
| 126 | 126 |
| 127 base::WeakPtrFactory<ExtensionPrinterHandler> weak_ptr_factory_; | 127 base::WeakPtrFactory<ExtensionPrinterHandler> weak_ptr_factory_; |
| 128 | 128 |
| 129 DISALLOW_COPY_AND_ASSIGN(ExtensionPrinterHandler); | 129 DISALLOW_COPY_AND_ASSIGN(ExtensionPrinterHandler); |
| 130 }; | 130 }; |
| 131 | 131 |
| 132 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_ | 132 #endif // CHROME_BROWSER_UI_WEBUI_PRINT_PREVIEW_EXTENSION_PRINTER_HANDLER_H_ |
| OLD | NEW |