Finish refactoring of DomCodeToUsLayoutKeyboardCode().
[chromium-blink-merge.git] / extensions / browser / api / printer_provider_internal / printer_provider_internal_api.h
blobbb62b333883e8c4897496dfb4311f1de697f1abc
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 EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_INTERNAL_PRINTER_PROVIDER_INTERNAL_API_H_
6 #define EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_INTERNAL_PRINTER_PROVIDER_INTERNAL_API_H_
8 #include <string>
10 #include "base/macros.h"
11 #include "base/observer_list.h"
12 #include "extensions/browser/api/printer_provider_internal/printer_provider_internal_api_observer.h"
13 #include "extensions/browser/browser_context_keyed_api_factory.h"
14 #include "extensions/browser/extension_function.h"
15 #include "extensions/common/api/printer_provider_internal.h"
17 namespace base {
18 class DictionaryValue;
19 class ListValue;
22 namespace content {
23 class BlobHandle;
24 class BrowserContext;
27 namespace extensions {
28 class Extension;
31 namespace extensions {
33 // Internal API instance. Primarily used to enable observers to watch for when
34 // printerProviderInternal API functions are called.
35 class PrinterProviderInternalAPI : public BrowserContextKeyedAPI {
36 public:
37 static BrowserContextKeyedAPIFactory<PrinterProviderInternalAPI>*
38 GetFactoryInstance();
40 explicit PrinterProviderInternalAPI(content::BrowserContext* browser_context);
41 ~PrinterProviderInternalAPI() override;
43 void AddObserver(PrinterProviderInternalAPIObserver* observer);
44 void RemoveObserver(PrinterProviderInternalAPIObserver* observer);
46 private:
47 friend class BrowserContextKeyedAPIFactory<PrinterProviderInternalAPI>;
48 friend class PrinterProviderInternalReportPrintersFunction;
49 friend class PrinterProviderInternalReportPrinterCapabilityFunction;
50 friend class PrinterProviderInternalReportPrintResultFunction;
51 friend class PrinterProviderInternalReportUsbPrinterInfoFunction;
53 // BrowserContextKeyedAPI implementation.
54 static const bool kServiceRedirectedInIncognito = true;
55 static const char* service_name() { return "PrinterProviderInternal"; }
57 // Notifies observers that a printerProvider.onGetPrintersRequested callback
58 // has been called. Called from
59 // |PrinterProviderInternalReportPrintersFunction|.
60 void NotifyGetPrintersResult(
61 const Extension* extension,
62 int request_id,
63 const PrinterProviderInternalAPIObserver::PrinterInfoVector& printers);
65 // Notifies observers that a printerProvider.onGetCapabilityRequested callback
66 // has been called. Called from
67 // |PrinterProviderInternalReportPrinterCapabilityFunction|.
68 void NotifyGetCapabilityResult(const Extension* extension,
69 int request_id,
70 const base::DictionaryValue& capability);
72 // Notifies observers that a printerProvider.onPrintRequested callback has
73 // been called. Called from
74 // |PrinterProviderInternalReportPrintResultFunction|.
75 void NotifyPrintResult(const Extension* extension,
76 int request_id,
77 core_api::printer_provider_internal::PrintError error);
79 // Notifies observers that a printerProvider.onGetUsbPrinterInfoRequested
80 // callback has been called. Called from
81 // |PrinterProviderInternalReportUsbPrinterInfoFunction|.
82 void NotifyGetUsbPrinterInfoResult(
83 const Extension* extension,
84 int request_id,
85 const core_api::printer_provider::PrinterInfo* printer_info);
87 base::ObserverList<PrinterProviderInternalAPIObserver> observers_;
89 DISALLOW_COPY_AND_ASSIGN(PrinterProviderInternalAPI);
92 class PrinterProviderInternalReportPrintResultFunction
93 : public UIThreadExtensionFunction {
94 public:
95 PrinterProviderInternalReportPrintResultFunction();
97 protected:
98 ~PrinterProviderInternalReportPrintResultFunction() override;
100 ExtensionFunction::ResponseAction Run() override;
102 private:
103 DECLARE_EXTENSION_FUNCTION("printerProviderInternal.reportPrintResult",
104 PRINTERPROVIDERINTERNAL_REPORTPRINTRESULT)
106 DISALLOW_COPY_AND_ASSIGN(PrinterProviderInternalReportPrintResultFunction);
109 class PrinterProviderInternalReportPrinterCapabilityFunction
110 : public UIThreadExtensionFunction {
111 public:
112 PrinterProviderInternalReportPrinterCapabilityFunction();
114 protected:
115 ~PrinterProviderInternalReportPrinterCapabilityFunction() override;
117 ExtensionFunction::ResponseAction Run() override;
119 private:
120 DECLARE_EXTENSION_FUNCTION("printerProviderInternal.reportPrinterCapability",
121 PRINTERPROVIDERINTERNAL_REPORTPRINTERCAPABILITY)
123 DISALLOW_COPY_AND_ASSIGN(
124 PrinterProviderInternalReportPrinterCapabilityFunction);
127 class PrinterProviderInternalReportPrintersFunction
128 : public UIThreadExtensionFunction {
129 public:
130 PrinterProviderInternalReportPrintersFunction();
132 protected:
133 ~PrinterProviderInternalReportPrintersFunction() override;
134 ExtensionFunction::ResponseAction Run() override;
136 private:
137 DECLARE_EXTENSION_FUNCTION("printerProviderInternal.reportPrinters",
138 PRINTERPROVIDERINTERNAL_REPORTPRINTERS)
140 DISALLOW_COPY_AND_ASSIGN(PrinterProviderInternalReportPrintersFunction);
143 class PrinterProviderInternalGetPrintDataFunction
144 : public UIThreadExtensionFunction {
145 public:
146 PrinterProviderInternalGetPrintDataFunction();
148 protected:
149 ~PrinterProviderInternalGetPrintDataFunction() override;
150 ExtensionFunction::ResponseAction Run() override;
152 private:
153 void OnBlob(const std::string& type,
154 int size,
155 const scoped_refptr<base::RefCountedMemory>& data,
156 scoped_ptr<content::BlobHandle> blob);
157 DECLARE_EXTENSION_FUNCTION("printerProviderInternal.getPrintData",
158 PRINTERPROVIDERINTERNAL_GETPRINTDATA)
160 DISALLOW_COPY_AND_ASSIGN(PrinterProviderInternalGetPrintDataFunction);
163 class PrinterProviderInternalReportUsbPrinterInfoFunction
164 : public UIThreadExtensionFunction {
165 public:
166 PrinterProviderInternalReportUsbPrinterInfoFunction();
168 protected:
169 ~PrinterProviderInternalReportUsbPrinterInfoFunction() override;
170 ExtensionFunction::ResponseAction Run() override;
172 private:
173 DECLARE_EXTENSION_FUNCTION("printerProviderInternal.reportUsbPrinterInfo",
174 PRINTERPROVIDERINTERNAL_REPORTUSBPRINTERINFO)
176 DISALLOW_COPY_AND_ASSIGN(PrinterProviderInternalReportUsbPrinterInfoFunction);
179 } // namespace extensions
181 #endif // EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_INTERNAL_PRINTER_PROVIDER_INTERNAL_API_H_