Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / api / gcd_private / gcd_private_api.h
blob856133a81d38de1b31fc8bf28cb510bf9fd97d1f
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 {
15 class GCDApiFlow;
18 namespace extensions {
20 class GcdPrivateAPIImpl;
22 class GcdPrivateAPI : public BrowserContextKeyedAPI {
23 public:
24 class GCDApiFlowFactoryForTests {
25 public:
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();
39 private:
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 {
52 public:
53 DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCloudDeviceList",
54 GCDPRIVATE_GETCLOUDDEVICELIST)
56 GcdPrivateGetCloudDeviceListFunction();
58 protected:
59 ~GcdPrivateGetCloudDeviceListFunction() override;
61 // AsyncExtensionFunction overrides.
62 bool RunAsync() override;
64 private:
65 // CloudDeviceListDelegate implementation
66 void OnDeviceListReady(const DeviceList& devices) override;
67 void OnDeviceListUnavailable() override;
69 void CheckListingDone();
71 int requests_succeeded_;
72 int requests_failed_;
73 DeviceList devices_;
75 scoped_ptr<local_discovery::GCDApiFlow> printer_list_;
76 scoped_ptr<local_discovery::GCDApiFlow> device_list_;
79 class GcdPrivateQueryForNewLocalDevicesFunction
80 : public ChromeSyncExtensionFunction {
81 public:
82 DECLARE_EXTENSION_FUNCTION("gcdPrivate.queryForNewLocalDevices",
83 GCDPRIVATE_QUERYFORNEWLOCALDEVICES)
85 GcdPrivateQueryForNewLocalDevicesFunction();
87 protected:
88 ~GcdPrivateQueryForNewLocalDevicesFunction() override;
90 // SyncExtensionFunction overrides.
91 bool RunSync() override;
94 class GcdPrivatePrefetchWifiPasswordFunction
95 : public ChromeAsyncExtensionFunction {
96 public:
97 DECLARE_EXTENSION_FUNCTION("gcdPrivate.prefetchWifiPassword",
98 GCDPRIVATE_PREFETCHWIFIPASSWORD)
100 GcdPrivatePrefetchWifiPasswordFunction();
102 protected:
103 ~GcdPrivatePrefetchWifiPasswordFunction() override;
105 // AsyncExtensionFunction overrides.
106 bool RunAsync() override;
108 void OnResponse(bool response);
111 class GcdPrivateGetPrefetchedWifiNameListFunction
112 : public ChromeSyncExtensionFunction {
113 public:
114 DECLARE_EXTENSION_FUNCTION("gcdPrivate.getPrefetchedWifiNameList",
115 GCDPRIVATE_GETPREFETCHEDWIFINAMELIST);
117 GcdPrivateGetPrefetchedWifiNameListFunction();
119 protected:
120 ~GcdPrivateGetPrefetchedWifiNameListFunction() override;
122 // SyncExtensionFunction overrides.
123 bool RunSync() override;
126 class GcdPrivateGetDeviceInfoFunction : public ChromeAsyncExtensionFunction {
127 public:
128 DECLARE_EXTENSION_FUNCTION("gcdPrivate.getDeviceInfo",
129 GCDPRIVATE_GETDEVICEINFO)
131 GcdPrivateGetDeviceInfoFunction();
133 protected:
134 ~GcdPrivateGetDeviceInfoFunction() override;
136 // AsyncExtensionFunction overrides.
137 bool RunAsync() override;
139 private:
140 void OnSessionInitialized(
141 int session_id,
142 api::gcd_private::Status status,
143 const base::DictionaryValue& info);
146 class GcdPrivateCreateSessionFunction : public ChromeAsyncExtensionFunction {
147 public:
148 DECLARE_EXTENSION_FUNCTION("gcdPrivate.createSession",
149 GCDPRIVATE_ESTABLISHSESSION)
151 GcdPrivateCreateSessionFunction();
153 protected:
154 ~GcdPrivateCreateSessionFunction() override;
156 // AsyncExtensionFunction overrides.
157 bool RunAsync() override;
159 private:
160 void OnSessionInitialized(
161 int session_id,
162 api::gcd_private::Status status,
163 const base::DictionaryValue& info);
166 class GcdPrivateStartPairingFunction : public ChromeAsyncExtensionFunction {
167 public:
168 DECLARE_EXTENSION_FUNCTION("gcdPrivate.startPairing", GCDPRIVATE_STARTPAIRING)
170 GcdPrivateStartPairingFunction();
172 protected:
173 ~GcdPrivateStartPairingFunction() override;
175 // AsyncExtensionFunction overrides.
176 bool RunAsync() override;
178 private:
179 void OnPairingStarted(api::gcd_private::Status status);
182 class GcdPrivateConfirmCodeFunction : public ChromeAsyncExtensionFunction {
183 public:
184 DECLARE_EXTENSION_FUNCTION("gcdPrivate.confirmCode", GCDPRIVATE_CONFIRMCODE)
186 GcdPrivateConfirmCodeFunction();
188 protected:
189 ~GcdPrivateConfirmCodeFunction() override;
191 // AsyncExtensionFunction overrides.
192 bool RunAsync() override;
194 private:
195 void OnCodeConfirmed(api::gcd_private::Status status);
198 class GcdPrivateSendMessageFunction : public ChromeAsyncExtensionFunction {
199 public:
200 DECLARE_EXTENSION_FUNCTION("gcdPrivate.sendMessage", GCDPRIVATE_SENDMESSAGE)
202 GcdPrivateSendMessageFunction();
204 protected:
205 ~GcdPrivateSendMessageFunction() override;
207 // AsyncExtensionFunction overrides.
208 bool RunAsync() override;
210 private:
211 void OnMessageSentCallback(api::gcd_private::Status status,
212 const base::DictionaryValue& value);
215 class GcdPrivateTerminateSessionFunction : public ChromeAsyncExtensionFunction {
216 public:
217 DECLARE_EXTENSION_FUNCTION("gcdPrivate.terminateSession",
218 GCDPRIVATE_TERMINATESESSION)
220 GcdPrivateTerminateSessionFunction();
222 protected:
223 ~GcdPrivateTerminateSessionFunction() override;
225 // AsyncExtensionFunction overrides.
226 bool RunAsync() override;
229 class GcdPrivateGetCommandDefinitionsFunction
230 : public ChromeAsyncExtensionFunction {
231 public:
232 DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCommandDefinitions",
233 GCDPRIVATE_GETCOMMANDDEFINITIONS)
235 GcdPrivateGetCommandDefinitionsFunction();
237 protected:
238 ~GcdPrivateGetCommandDefinitionsFunction() override;
240 // AsyncExtensionFunction overrides.
241 bool RunAsync() override;
243 private:
246 class GcdPrivateInsertCommandFunction : public ChromeAsyncExtensionFunction {
247 public:
248 DECLARE_EXTENSION_FUNCTION("gcdPrivate.insertCommand",
249 GCDPRIVATE_INSERTCOMMAND)
251 GcdPrivateInsertCommandFunction();
253 protected:
254 ~GcdPrivateInsertCommandFunction() override;
256 // AsyncExtensionFunction overrides.
257 bool RunAsync() override;
259 private:
262 class GcdPrivateGetCommandFunction : public ChromeAsyncExtensionFunction {
263 public:
264 DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCommand", GCDPRIVATE_GETCOMMAND)
266 GcdPrivateGetCommandFunction();
268 protected:
269 ~GcdPrivateGetCommandFunction() override;
271 // AsyncExtensionFunction overrides.
272 bool RunAsync() override;
274 private:
277 class GcdPrivateCancelCommandFunction : public ChromeAsyncExtensionFunction {
278 public:
279 DECLARE_EXTENSION_FUNCTION("gcdPrivate.cancelCommand",
280 GCDPRIVATE_CANCELCOMMAND)
282 GcdPrivateCancelCommandFunction();
284 protected:
285 ~GcdPrivateCancelCommandFunction() override;
287 // AsyncExtensionFunction overrides.
288 bool RunAsync() override;
290 private:
293 class GcdPrivateGetCommandsListFunction : public ChromeAsyncExtensionFunction {
294 public:
295 DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCommandsList",
296 GCDPRIVATE_GETCOMMANDSLIST)
298 GcdPrivateGetCommandsListFunction();
300 protected:
301 ~GcdPrivateGetCommandsListFunction() override;
303 // AsyncExtensionFunction overrides.
304 bool RunAsync() override;
306 private:
309 } // namespace extensions
311 #endif // CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_GCD_PRIVATE_API_H_