Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / extensions / api / gcd_private / gcd_private_api.h
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.
4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_GCD_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_GCD_PRIVATE_API_H_
7
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"
13
14 namespace local_discovery {
15 class GCDApiFlow;
16 }
17
18 namespace extensions {
19
20 class GcdPrivateAPIImpl;
21
22 class GcdPrivateAPI : public BrowserContextKeyedAPI {
23  public:
24   class GCDApiFlowFactoryForTests {
25    public:
26     virtual ~GCDApiFlowFactoryForTests() {}
27
28     virtual scoped_ptr<local_discovery::GCDApiFlow> CreateGCDApiFlow() = 0;
29   };
30
31   explicit GcdPrivateAPI(content::BrowserContext* context);
32   ~GcdPrivateAPI() override;
33
34   static void SetGCDApiFlowFactoryForTests(GCDApiFlowFactoryForTests* factory);
35
36   // BrowserContextKeyedAPI implementation.
37   static BrowserContextKeyedAPIFactory<GcdPrivateAPI>* GetFactoryInstance();
38
39  private:
40   friend class BrowserContextKeyedAPIFactory<GcdPrivateAPI>;
41   friend class GcdPrivateAPIImpl;
42
43   // BrowserContextKeyedAPI implementation.
44   static const char* service_name() { return "GcdPrivateAPI"; }
45
46   scoped_ptr<GcdPrivateAPIImpl> impl_;
47 };
48
49 class GcdPrivateGetCloudDeviceListFunction
50     : public ChromeAsyncExtensionFunction,
51       public local_discovery::CloudDeviceListDelegate {
52  public:
53   DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCloudDeviceList",
54                              GCDPRIVATE_GETCLOUDDEVICELIST)
55
56   GcdPrivateGetCloudDeviceListFunction();
57
58  protected:
59   ~GcdPrivateGetCloudDeviceListFunction() override;
60
61   // AsyncExtensionFunction overrides.
62   bool RunAsync() override;
63
64  private:
65   // CloudDeviceListDelegate implementation
66   void OnDeviceListReady(const DeviceList& devices) override;
67   void OnDeviceListUnavailable() override;
68
69   void CheckListingDone();
70
71   int requests_succeeded_;
72   int requests_failed_;
73   DeviceList devices_;
74
75   scoped_ptr<local_discovery::GCDApiFlow> printer_list_;
76   scoped_ptr<local_discovery::GCDApiFlow> device_list_;
77 };
78
79 class GcdPrivateQueryForNewLocalDevicesFunction
80     : public ChromeSyncExtensionFunction {
81  public:
82   DECLARE_EXTENSION_FUNCTION("gcdPrivate.queryForNewLocalDevices",
83                              GCDPRIVATE_QUERYFORNEWLOCALDEVICES)
84
85   GcdPrivateQueryForNewLocalDevicesFunction();
86
87  protected:
88   ~GcdPrivateQueryForNewLocalDevicesFunction() override;
89
90   // SyncExtensionFunction overrides.
91   bool RunSync() override;
92 };
93
94 class GcdPrivatePrefetchWifiPasswordFunction
95     : public ChromeAsyncExtensionFunction {
96  public:
97   DECLARE_EXTENSION_FUNCTION("gcdPrivate.prefetchWifiPassword",
98                              GCDPRIVATE_PREFETCHWIFIPASSWORD)
99
100   GcdPrivatePrefetchWifiPasswordFunction();
101
102  protected:
103   ~GcdPrivatePrefetchWifiPasswordFunction() override;
104
105   // AsyncExtensionFunction overrides.
106   bool RunAsync() override;
107
108   void OnResponse(bool response);
109 };
110
111 class GcdPrivateGetPrefetchedWifiNameListFunction
112     : public ChromeSyncExtensionFunction {
113  public:
114   DECLARE_EXTENSION_FUNCTION("gcdPrivate.getPrefetchedWifiNameList",
115                              GCDPRIVATE_GETPREFETCHEDWIFINAMELIST);
116
117   GcdPrivateGetPrefetchedWifiNameListFunction();
118
119  protected:
120   ~GcdPrivateGetPrefetchedWifiNameListFunction() override;
121
122   // SyncExtensionFunction overrides.
123   bool RunSync() override;
124 };
125
126 class GcdPrivateEstablishSessionFunction : public ChromeAsyncExtensionFunction {
127  public:
128   DECLARE_EXTENSION_FUNCTION("gcdPrivate.establishSession",
129                              GCDPRIVATE_ESTABLISHSESSION)
130
131   GcdPrivateEstablishSessionFunction();
132
133  protected:
134   ~GcdPrivateEstablishSessionFunction() override;
135
136   // AsyncExtensionFunction overrides.
137   bool RunAsync() override;
138
139  private:
140   void OnSessionInitialized(
141       int session_id,
142       api::gcd_private::Status status,
143       const std::vector<api::gcd_private::PairingType>& pairing_types);
144 };
145
146 class GcdPrivateStartPairingFunction : public ChromeAsyncExtensionFunction {
147  public:
148   DECLARE_EXTENSION_FUNCTION("gcdPrivate.startPairing", GCDPRIVATE_STARTPAIRING)
149
150   GcdPrivateStartPairingFunction();
151
152  protected:
153   ~GcdPrivateStartPairingFunction() override;
154
155   // AsyncExtensionFunction overrides.
156   bool RunAsync() override;
157
158  private:
159   void OnPairingStarted(api::gcd_private::Status status);
160 };
161
162 class GcdPrivateConfirmCodeFunction : public ChromeAsyncExtensionFunction {
163  public:
164   DECLARE_EXTENSION_FUNCTION("gcdPrivate.confirmCode", GCDPRIVATE_CONFIRMCODE)
165
166   GcdPrivateConfirmCodeFunction();
167
168  protected:
169   ~GcdPrivateConfirmCodeFunction() override;
170
171   // AsyncExtensionFunction overrides.
172   bool RunAsync() override;
173
174  private:
175   void OnCodeConfirmed(api::gcd_private::Status status);
176 };
177
178 class GcdPrivateSendMessageFunction : public ChromeAsyncExtensionFunction {
179  public:
180   DECLARE_EXTENSION_FUNCTION("gcdPrivate.sendMessage", GCDPRIVATE_SENDMESSAGE)
181
182   GcdPrivateSendMessageFunction();
183
184  protected:
185   ~GcdPrivateSendMessageFunction() override;
186
187   // AsyncExtensionFunction overrides.
188   bool RunAsync() override;
189
190  private:
191   void OnMessageSentCallback(api::gcd_private::Status status,
192                              const base::DictionaryValue& value);
193 };
194
195 class GcdPrivateTerminateSessionFunction : public ChromeAsyncExtensionFunction {
196  public:
197   DECLARE_EXTENSION_FUNCTION("gcdPrivate.terminateSession",
198                              GCDPRIVATE_TERMINATESESSION)
199
200   GcdPrivateTerminateSessionFunction();
201
202  protected:
203   ~GcdPrivateTerminateSessionFunction() override;
204
205   // AsyncExtensionFunction overrides.
206   bool RunAsync() override;
207 };
208
209 class GcdPrivateGetCommandDefinitionsFunction
210     : public ChromeAsyncExtensionFunction {
211  public:
212   DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCommandDefinitions",
213                              GCDPRIVATE_GETCOMMANDDEFINITIONS)
214
215   GcdPrivateGetCommandDefinitionsFunction();
216
217  protected:
218   ~GcdPrivateGetCommandDefinitionsFunction() override;
219
220   // AsyncExtensionFunction overrides.
221   bool RunAsync() override;
222
223  private:
224 };
225
226 class GcdPrivateInsertCommandFunction : public ChromeAsyncExtensionFunction {
227  public:
228   DECLARE_EXTENSION_FUNCTION("gcdPrivate.insertCommand",
229                              GCDPRIVATE_INSERTCOMMAND)
230
231   GcdPrivateInsertCommandFunction();
232
233  protected:
234   ~GcdPrivateInsertCommandFunction() override;
235
236   // AsyncExtensionFunction overrides.
237   bool RunAsync() override;
238
239  private:
240 };
241
242 class GcdPrivateGetCommandFunction : public ChromeAsyncExtensionFunction {
243  public:
244   DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCommand", GCDPRIVATE_GETCOMMAND)
245
246   GcdPrivateGetCommandFunction();
247
248  protected:
249   ~GcdPrivateGetCommandFunction() override;
250
251   // AsyncExtensionFunction overrides.
252   bool RunAsync() override;
253
254  private:
255 };
256
257 class GcdPrivateCancelCommandFunction : public ChromeAsyncExtensionFunction {
258  public:
259   DECLARE_EXTENSION_FUNCTION("gcdPrivate.cancelCommand",
260                              GCDPRIVATE_CANCELCOMMAND)
261
262   GcdPrivateCancelCommandFunction();
263
264  protected:
265   ~GcdPrivateCancelCommandFunction() override;
266
267   // AsyncExtensionFunction overrides.
268   bool RunAsync() override;
269
270  private:
271 };
272
273 class GcdPrivateGetCommandsListFunction : public ChromeAsyncExtensionFunction {
274  public:
275   DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCommandsList",
276                              GCDPRIVATE_GETCOMMANDSLIST)
277
278   GcdPrivateGetCommandsListFunction();
279
280  protected:
281   ~GcdPrivateGetCommandsListFunction() override;
282
283   // AsyncExtensionFunction overrides.
284   bool RunAsync() override;
285
286  private:
287 };
288
289 }  // namespace extensions
290
291 #endif  // CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_GCD_PRIVATE_API_H_