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 GcdPrivateEstablishSessionFunction : public ChromeAsyncExtensionFunction {
128 DECLARE_EXTENSION_FUNCTION("gcdPrivate.establishSession",
129 GCDPRIVATE_ESTABLISHSESSION)
131 GcdPrivateEstablishSessionFunction();
134 ~GcdPrivateEstablishSessionFunction() override;
136 // AsyncExtensionFunction overrides.
137 bool RunAsync() override;
140 void OnSessionInitialized(
142 api::gcd_private::Status status,
143 const std::vector<api::gcd_private::PairingType>& pairing_types);
146 class GcdPrivateStartPairingFunction : public ChromeAsyncExtensionFunction {
148 DECLARE_EXTENSION_FUNCTION("gcdPrivate.startPairing", GCDPRIVATE_STARTPAIRING)
150 GcdPrivateStartPairingFunction();
153 ~GcdPrivateStartPairingFunction() override;
155 // AsyncExtensionFunction overrides.
156 bool RunAsync() override;
159 void OnPairingStarted(api::gcd_private::Status status);
162 class GcdPrivateConfirmCodeFunction : public ChromeAsyncExtensionFunction {
164 DECLARE_EXTENSION_FUNCTION("gcdPrivate.confirmCode", GCDPRIVATE_CONFIRMCODE)
166 GcdPrivateConfirmCodeFunction();
169 ~GcdPrivateConfirmCodeFunction() override;
171 // AsyncExtensionFunction overrides.
172 bool RunAsync() override;
175 void OnCodeConfirmed(api::gcd_private::Status status);
178 class GcdPrivateSendMessageFunction : public ChromeAsyncExtensionFunction {
180 DECLARE_EXTENSION_FUNCTION("gcdPrivate.sendMessage", GCDPRIVATE_SENDMESSAGE)
182 GcdPrivateSendMessageFunction();
185 ~GcdPrivateSendMessageFunction() override;
187 // AsyncExtensionFunction overrides.
188 bool RunAsync() override;
191 void OnMessageSentCallback(api::gcd_private::Status status,
192 const base::DictionaryValue& value);
195 class GcdPrivateTerminateSessionFunction : public ChromeAsyncExtensionFunction {
197 DECLARE_EXTENSION_FUNCTION("gcdPrivate.terminateSession",
198 GCDPRIVATE_TERMINATESESSION)
200 GcdPrivateTerminateSessionFunction();
203 ~GcdPrivateTerminateSessionFunction() override;
205 // AsyncExtensionFunction overrides.
206 bool RunAsync() override;
209 class GcdPrivateGetCommandDefinitionsFunction
210 : public ChromeAsyncExtensionFunction {
212 DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCommandDefinitions",
213 GCDPRIVATE_GETCOMMANDDEFINITIONS)
215 GcdPrivateGetCommandDefinitionsFunction();
218 ~GcdPrivateGetCommandDefinitionsFunction() override;
220 // AsyncExtensionFunction overrides.
221 bool RunAsync() override;
226 class GcdPrivateInsertCommandFunction : public ChromeAsyncExtensionFunction {
228 DECLARE_EXTENSION_FUNCTION("gcdPrivate.insertCommand",
229 GCDPRIVATE_INSERTCOMMAND)
231 GcdPrivateInsertCommandFunction();
234 ~GcdPrivateInsertCommandFunction() override;
236 // AsyncExtensionFunction overrides.
237 bool RunAsync() override;
242 class GcdPrivateGetCommandFunction : public ChromeAsyncExtensionFunction {
244 DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCommand", GCDPRIVATE_GETCOMMAND)
246 GcdPrivateGetCommandFunction();
249 ~GcdPrivateGetCommandFunction() override;
251 // AsyncExtensionFunction overrides.
252 bool RunAsync() override;
257 class GcdPrivateCancelCommandFunction : public ChromeAsyncExtensionFunction {
259 DECLARE_EXTENSION_FUNCTION("gcdPrivate.cancelCommand",
260 GCDPRIVATE_CANCELCOMMAND)
262 GcdPrivateCancelCommandFunction();
265 ~GcdPrivateCancelCommandFunction() override;
267 // AsyncExtensionFunction overrides.
268 bool RunAsync() override;
273 class GcdPrivateGetCommandsListFunction : public ChromeAsyncExtensionFunction {
275 DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCommandsList",
276 GCDPRIVATE_GETCOMMANDSLIST)
278 GcdPrivateGetCommandsListFunction();
281 ~GcdPrivateGetCommandsListFunction() override;
283 // AsyncExtensionFunction overrides.
284 bool RunAsync() override;
289 } // namespace extensions
291 #endif // CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_GCD_PRIVATE_API_H_