1 // Copyright 2014 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 CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_GCD_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_GCD_PRIVATE_API_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "chrome/browser/extensions/chrome_extension_function.h"
10 #include "chrome/browser/local_discovery/cloud_device_list_delegate.h"
11 #include "chrome/common/extensions/api/gcd_private.h"
12 #include "extensions/browser/browser_context_keyed_api_factory.h"
14 namespace local_discovery
{
18 namespace extensions
{
20 class GcdPrivateAPIImpl
;
22 class GcdPrivateAPI
: public BrowserContextKeyedAPI
{
24 class GCDApiFlowFactoryForTests
{
26 virtual ~GCDApiFlowFactoryForTests() {}
28 virtual scoped_ptr
<local_discovery::GCDApiFlow
> CreateGCDApiFlow() = 0;
31 explicit GcdPrivateAPI(content::BrowserContext
* context
);
32 ~GcdPrivateAPI() override
;
34 static void SetGCDApiFlowFactoryForTests(GCDApiFlowFactoryForTests
* factory
);
36 // BrowserContextKeyedAPI implementation.
37 static BrowserContextKeyedAPIFactory
<GcdPrivateAPI
>* GetFactoryInstance();
40 friend class BrowserContextKeyedAPIFactory
<GcdPrivateAPI
>;
41 friend class GcdPrivateAPIImpl
;
43 // BrowserContextKeyedAPI implementation.
44 static const char* service_name() { return "GcdPrivateAPI"; }
46 scoped_ptr
<GcdPrivateAPIImpl
> impl_
;
49 class GcdPrivateGetCloudDeviceListFunction
50 : public ChromeAsyncExtensionFunction
,
51 public local_discovery::CloudDeviceListDelegate
{
53 DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCloudDeviceList",
54 GCDPRIVATE_GETCLOUDDEVICELIST
)
56 GcdPrivateGetCloudDeviceListFunction();
59 ~GcdPrivateGetCloudDeviceListFunction() override
;
61 // AsyncExtensionFunction overrides.
62 bool RunAsync() override
;
65 // CloudDeviceListDelegate implementation
66 void OnDeviceListReady(const DeviceList
& devices
) override
;
67 void OnDeviceListUnavailable() override
;
69 void CheckListingDone();
71 int requests_succeeded_
;
75 scoped_ptr
<local_discovery::GCDApiFlow
> printer_list_
;
76 scoped_ptr
<local_discovery::GCDApiFlow
> device_list_
;
79 class GcdPrivateQueryForNewLocalDevicesFunction
80 : public ChromeSyncExtensionFunction
{
82 DECLARE_EXTENSION_FUNCTION("gcdPrivate.queryForNewLocalDevices",
83 GCDPRIVATE_QUERYFORNEWLOCALDEVICES
)
85 GcdPrivateQueryForNewLocalDevicesFunction();
88 ~GcdPrivateQueryForNewLocalDevicesFunction() override
;
90 // SyncExtensionFunction overrides.
91 bool RunSync() override
;
94 class GcdPrivatePrefetchWifiPasswordFunction
95 : public ChromeAsyncExtensionFunction
{
97 DECLARE_EXTENSION_FUNCTION("gcdPrivate.prefetchWifiPassword",
98 GCDPRIVATE_PREFETCHWIFIPASSWORD
)
100 GcdPrivatePrefetchWifiPasswordFunction();
103 ~GcdPrivatePrefetchWifiPasswordFunction() override
;
105 // AsyncExtensionFunction overrides.
106 bool RunAsync() override
;
108 void OnResponse(bool response
);
111 class GcdPrivateGetPrefetchedWifiNameListFunction
112 : public ChromeSyncExtensionFunction
{
114 DECLARE_EXTENSION_FUNCTION("gcdPrivate.getPrefetchedWifiNameList",
115 GCDPRIVATE_GETPREFETCHEDWIFINAMELIST
);
117 GcdPrivateGetPrefetchedWifiNameListFunction();
120 ~GcdPrivateGetPrefetchedWifiNameListFunction() override
;
122 // SyncExtensionFunction overrides.
123 bool RunSync() override
;
126 class GcdPrivateGetDeviceInfoFunction
: public ChromeAsyncExtensionFunction
{
128 DECLARE_EXTENSION_FUNCTION("gcdPrivate.getDeviceInfo",
129 GCDPRIVATE_GETDEVICEINFO
)
131 GcdPrivateGetDeviceInfoFunction();
134 ~GcdPrivateGetDeviceInfoFunction() override
;
136 // AsyncExtensionFunction overrides.
137 bool RunAsync() override
;
140 void OnSessionInitialized(
142 api::gcd_private::Status status
,
143 const base::DictionaryValue
& info
);
146 class GcdPrivateCreateSessionFunction
: public ChromeAsyncExtensionFunction
{
148 DECLARE_EXTENSION_FUNCTION("gcdPrivate.createSession",
149 GCDPRIVATE_ESTABLISHSESSION
)
151 GcdPrivateCreateSessionFunction();
154 ~GcdPrivateCreateSessionFunction() override
;
156 // AsyncExtensionFunction overrides.
157 bool RunAsync() override
;
160 void OnSessionInitialized(
162 api::gcd_private::Status status
,
163 const base::DictionaryValue
& info
);
166 class GcdPrivateStartPairingFunction
: public ChromeAsyncExtensionFunction
{
168 DECLARE_EXTENSION_FUNCTION("gcdPrivate.startPairing", GCDPRIVATE_STARTPAIRING
)
170 GcdPrivateStartPairingFunction();
173 ~GcdPrivateStartPairingFunction() override
;
175 // AsyncExtensionFunction overrides.
176 bool RunAsync() override
;
179 void OnPairingStarted(api::gcd_private::Status status
);
182 class GcdPrivateConfirmCodeFunction
: public ChromeAsyncExtensionFunction
{
184 DECLARE_EXTENSION_FUNCTION("gcdPrivate.confirmCode", GCDPRIVATE_CONFIRMCODE
)
186 GcdPrivateConfirmCodeFunction();
189 ~GcdPrivateConfirmCodeFunction() override
;
191 // AsyncExtensionFunction overrides.
192 bool RunAsync() override
;
195 void OnCodeConfirmed(api::gcd_private::Status status
);
198 class GcdPrivateSendMessageFunction
: public ChromeAsyncExtensionFunction
{
200 DECLARE_EXTENSION_FUNCTION("gcdPrivate.sendMessage", GCDPRIVATE_SENDMESSAGE
)
202 GcdPrivateSendMessageFunction();
205 ~GcdPrivateSendMessageFunction() override
;
207 // AsyncExtensionFunction overrides.
208 bool RunAsync() override
;
211 void OnMessageSentCallback(api::gcd_private::Status status
,
212 const base::DictionaryValue
& value
);
215 class GcdPrivateTerminateSessionFunction
: public ChromeAsyncExtensionFunction
{
217 DECLARE_EXTENSION_FUNCTION("gcdPrivate.terminateSession",
218 GCDPRIVATE_TERMINATESESSION
)
220 GcdPrivateTerminateSessionFunction();
223 ~GcdPrivateTerminateSessionFunction() override
;
225 // AsyncExtensionFunction overrides.
226 bool RunAsync() override
;
229 class GcdPrivateGetCommandDefinitionsFunction
230 : public ChromeAsyncExtensionFunction
{
232 DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCommandDefinitions",
233 GCDPRIVATE_GETCOMMANDDEFINITIONS
)
235 GcdPrivateGetCommandDefinitionsFunction();
238 ~GcdPrivateGetCommandDefinitionsFunction() override
;
240 // AsyncExtensionFunction overrides.
241 bool RunAsync() override
;
246 class GcdPrivateInsertCommandFunction
: public ChromeAsyncExtensionFunction
{
248 DECLARE_EXTENSION_FUNCTION("gcdPrivate.insertCommand",
249 GCDPRIVATE_INSERTCOMMAND
)
251 GcdPrivateInsertCommandFunction();
254 ~GcdPrivateInsertCommandFunction() override
;
256 // AsyncExtensionFunction overrides.
257 bool RunAsync() override
;
262 class GcdPrivateGetCommandFunction
: public ChromeAsyncExtensionFunction
{
264 DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCommand", GCDPRIVATE_GETCOMMAND
)
266 GcdPrivateGetCommandFunction();
269 ~GcdPrivateGetCommandFunction() override
;
271 // AsyncExtensionFunction overrides.
272 bool RunAsync() override
;
277 class GcdPrivateCancelCommandFunction
: public ChromeAsyncExtensionFunction
{
279 DECLARE_EXTENSION_FUNCTION("gcdPrivate.cancelCommand",
280 GCDPRIVATE_CANCELCOMMAND
)
282 GcdPrivateCancelCommandFunction();
285 ~GcdPrivateCancelCommandFunction() override
;
287 // AsyncExtensionFunction overrides.
288 bool RunAsync() override
;
293 class GcdPrivateGetCommandsListFunction
: public ChromeAsyncExtensionFunction
{
295 DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCommandsList",
296 GCDPRIVATE_GETCOMMANDSLIST
)
298 GcdPrivateGetCommandsListFunction();
301 ~GcdPrivateGetCommandsListFunction() override
;
303 // AsyncExtensionFunction overrides.
304 bool RunAsync() override
;
309 } // namespace extensions
311 #endif // CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_GCD_PRIVATE_API_H_