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 "base/macros.h"
9 #include "base/observer_list.h"
10 #include "extensions/browser/api/printer_provider_internal/printer_provider_internal_api_observer.h"
11 #include "extensions/browser/browser_context_keyed_api_factory.h"
12 #include "extensions/browser/extension_function.h"
13 #include "extensions/common/api/printer_provider_internal.h"
16 class DictionaryValue
;
24 namespace extensions
{
28 namespace extensions
{
30 // Internal API instance. Primarily used to enable observers to watch for when
31 // printerProviderInternal API functions are called.
32 class PrinterProviderInternalAPI
: public BrowserContextKeyedAPI
{
34 static BrowserContextKeyedAPIFactory
<PrinterProviderInternalAPI
>*
37 explicit PrinterProviderInternalAPI(content::BrowserContext
* browser_context
);
38 ~PrinterProviderInternalAPI() override
;
40 void AddObserver(PrinterProviderInternalAPIObserver
* observer
);
41 void RemoveObserver(PrinterProviderInternalAPIObserver
* observer
);
44 friend class BrowserContextKeyedAPIFactory
<PrinterProviderInternalAPI
>;
45 friend class PrinterProviderInternalReportPrintersFunction
;
46 friend class PrinterProviderInternalReportPrinterCapabilityFunction
;
47 friend class PrinterProviderInternalReportPrintResultFunction
;
49 // BrowserContextKeyedAPI implementation.
50 static const bool kServiceRedirectedInIncognito
= true;
51 static const char* service_name() { return "PrinterProviderInternal"; }
53 // Notifies observers that a printerProvider.onGetPrintersRequested callback
54 // has been called. Called from
55 // |PrinterProviderInternalReportPrintersFunction|.
56 void NotifyGetPrintersResult(
57 const Extension
* extension
,
59 const PrinterProviderInternalAPIObserver::PrinterInfoVector
& printers
);
61 // Notifies observers that a printerProvider.onGetCapabilityRequested callback
62 // has been called. Called from
63 // |PrinterProviderInternalReportPrinterCapabilityFunction|.
64 void NotifyGetCapabilityResult(const Extension
* extension
,
66 const base::DictionaryValue
& capability
);
68 // Notifies observers that a printerProvider.onPrintRequested callback has
69 // been called. Called from
70 // |PrinterProviderInternalReportPrintResultFunction|.
71 void NotifyPrintResult(const Extension
* extension
,
73 core_api::printer_provider_internal::PrintError error
);
75 ObserverList
<PrinterProviderInternalAPIObserver
> observers_
;
77 DISALLOW_COPY_AND_ASSIGN(PrinterProviderInternalAPI
);
80 class PrinterProviderInternalReportPrintResultFunction
81 : public UIThreadExtensionFunction
{
83 PrinterProviderInternalReportPrintResultFunction();
86 ~PrinterProviderInternalReportPrintResultFunction() override
;
88 ExtensionFunction::ResponseAction
Run() override
;
91 DECLARE_EXTENSION_FUNCTION("printerProviderInternal.reportPrintResult",
92 PRINTERPROVIDERINTERNAL_REPORTPRINTRESULT
)
94 DISALLOW_COPY_AND_ASSIGN(PrinterProviderInternalReportPrintResultFunction
);
97 class PrinterProviderInternalReportPrinterCapabilityFunction
98 : public UIThreadExtensionFunction
{
100 PrinterProviderInternalReportPrinterCapabilityFunction();
103 ~PrinterProviderInternalReportPrinterCapabilityFunction() override
;
105 ExtensionFunction::ResponseAction
Run() override
;
108 DECLARE_EXTENSION_FUNCTION("printerProviderInternal.reportPrinterCapability",
109 PRINTERPROVIDERINTERNAL_REPORTPRINTERCAPABILITY
)
111 DISALLOW_COPY_AND_ASSIGN(
112 PrinterProviderInternalReportPrinterCapabilityFunction
);
115 class PrinterProviderInternalReportPrintersFunction
116 : public UIThreadExtensionFunction
{
118 PrinterProviderInternalReportPrintersFunction();
121 ~PrinterProviderInternalReportPrintersFunction() override
;
122 ExtensionFunction::ResponseAction
Run() override
;
125 DECLARE_EXTENSION_FUNCTION("printerProviderInternal.reportPrinters",
126 PRINTERPROVIDERINTERNAL_REPORTPRINTERS
)
128 DISALLOW_COPY_AND_ASSIGN(PrinterProviderInternalReportPrintersFunction
);
131 } // namespace extensions
133 #endif // EXTENSIONS_BROWSER_API_PRINTER_PROVIDER_INTERNAL_PRINTER_PROVIDER_INTERNAL_API_H_