| 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 EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_PRINTER_PROVIDER_API_H_ | 5 #ifndef EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_PRINTER_PROVIDER_API_H_ |
| 6 #define EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_PRINTER_PROVIDER_API_H_ | 6 #define EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_PRINTER_PROVIDER_API_H_ |
| 7 | 7 |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback_forward.h" |
| 11 #include "base/memory/ref_counted.h" |
| 11 #include "components/keyed_service/core/keyed_service.h" | 12 #include "components/keyed_service/core/keyed_service.h" |
| 12 | 13 |
| 13 namespace base { | 14 namespace base { |
| 14 class DictionaryValue; | 15 class DictionaryValue; |
| 15 class ListValue; | 16 class ListValue; |
| 16 } | 17 } |
| 17 | 18 |
| 18 namespace content { | 19 namespace content { |
| 19 class BrowserContext; | 20 class BrowserContext; |
| 20 } | 21 } |
| 21 | 22 |
| 23 namespace device { |
| 24 class UsbDevice; |
| 25 } |
| 26 |
| 22 namespace extensions { | 27 namespace extensions { |
| 23 class Extension; | 28 class Extension; |
| 24 struct PrinterProviderPrintJob; | 29 struct PrinterProviderPrintJob; |
| 25 } | 30 } |
| 26 | 31 |
| 27 namespace extensions { | 32 namespace extensions { |
| 28 | 33 |
| 29 // Implements chrome.printerProvider API events. | 34 // Implements chrome.printerProvider API events. |
| 30 class PrinterProviderAPI : public KeyedService { | 35 class PrinterProviderAPI : public KeyedService { |
| 31 public: | 36 public: |
| 32 using GetPrintersCallback = | 37 using GetPrintersCallback = |
| 33 base::Callback<void(const base::ListValue& printers, bool done)>; | 38 base::Callback<void(const base::ListValue& printers, bool done)>; |
| 34 using GetCapabilityCallback = | 39 using GetCapabilityCallback = |
| 35 base::Callback<void(const base::DictionaryValue& capability)>; | 40 base::Callback<void(const base::DictionaryValue& capability)>; |
| 36 using PrintCallback = | 41 using PrintCallback = |
| 37 base::Callback<void(bool success, const std::string& error)>; | 42 base::Callback<void(bool success, const std::string& error)>; |
| 43 using GetPrinterInfoCallback = |
| 44 base::Callback<void(const base::DictionaryValue& printer_info)>; |
| 38 | 45 |
| 39 static PrinterProviderAPI* Create(content::BrowserContext* context); | 46 static PrinterProviderAPI* Create(content::BrowserContext* context); |
| 40 | 47 |
| 41 // Returns generic error string for print request. | 48 // Returns generic error string for print request. |
| 42 static std::string GetDefaultPrintError(); | 49 static std::string GetDefaultPrintError(); |
| 43 | 50 |
| 44 ~PrinterProviderAPI() override {} | 51 ~PrinterProviderAPI() override {} |
| 45 | 52 |
| 46 // Requests list of supported printers from extensions implementing | 53 // Requests list of supported printers from extensions implementing |
| 47 // chrome.printerProvider API. It dispatches | 54 // chrome.printerProvider API. It dispatches |
| (...skipping 27 matching lines...) Expand all Loading... |
| 75 // |callback| is passed the print status returned by the extension, and it | 82 // |callback| is passed the print status returned by the extension, and it |
| 76 // must not be null. | 83 // must not be null. |
| 77 virtual void DispatchPrintRequested(const PrinterProviderPrintJob& job, | 84 virtual void DispatchPrintRequested(const PrinterProviderPrintJob& job, |
| 78 const PrintCallback& callback) = 0; | 85 const PrintCallback& callback) = 0; |
| 79 | 86 |
| 80 // Returns print job associated with the print request with id |request_id| | 87 // Returns print job associated with the print request with id |request_id| |
| 81 // for extension |extension|. | 88 // for extension |extension|. |
| 82 // It should return NULL if the job for the request does not exist. | 89 // It should return NULL if the job for the request does not exist. |
| 83 virtual const PrinterProviderPrintJob* GetPrintJob(const Extension* extension, | 90 virtual const PrinterProviderPrintJob* GetPrintJob(const Extension* extension, |
| 84 int request_id) const = 0; | 91 int request_id) const = 0; |
| 92 |
| 93 // Dispatches a chrome.printerProvider.getUsbPrinterInfo event requesting |
| 94 // information about |device_id|. The event is only dispatched to the |
| 95 // extension identified by |extension_id|. |
| 96 virtual void DispatchGetUsbPrinterInfoRequested( |
| 97 const std::string& extension_id, |
| 98 scoped_refptr<device::UsbDevice> device, |
| 99 const PrinterProviderAPI::GetPrinterInfoCallback& callback) = 0; |
| 85 }; | 100 }; |
| 86 | 101 |
| 87 } // namespace extensions | 102 } // namespace extensions |
| 88 | 103 |
| 89 #endif // EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_PRINTER_PROVIDER_API_H_ | 104 #endif // EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_PRINTER_PROVIDER_API_H_ |
| OLD | NEW |