Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(133)

Side by Side Diff: chrome/browser/extensions/api/gcd_private/gcd_private_api.h

Issue 411783002: Initial implementation of session APIs, sans WiFi component (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_GCD_PRIVATE_API_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_GCD_PRIVATE_API_H_
6 #define CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_GCD_PRIVATE_API_H_ 6 #define CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_GCD_PRIVATE_API_H_
7 7
8 #include "base/memory/linked_ptr.h" 8 #include "base/memory/linked_ptr.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "chrome/browser/extensions/chrome_extension_function.h" 10 #include "chrome/browser/extensions/chrome_extension_function.h"
11 #include "chrome/browser/local_discovery/cloud_device_list_delegate.h" 11 #include "chrome/browser/local_discovery/cloud_device_list_delegate.h"
12 #include "chrome/browser/local_discovery/gcd_api_flow.h" 12 #include "chrome/browser/local_discovery/gcd_api_flow.h"
13 #include "chrome/browser/local_discovery/privet_device_lister.h" 13 #include "chrome/browser/local_discovery/privet_device_lister.h"
14 #include "chrome/browser/local_discovery/privetv3_session.h"
14 #include "chrome/browser/local_discovery/service_discovery_shared_client.h" 15 #include "chrome/browser/local_discovery/service_discovery_shared_client.h"
15 #include "chrome/common/extensions/api/gcd_private.h" 16 #include "chrome/common/extensions/api/gcd_private.h"
16 #include "extensions/browser/browser_context_keyed_api_factory.h" 17 #include "extensions/browser/browser_context_keyed_api_factory.h"
17 #include "extensions/browser/event_router.h" 18 #include "extensions/browser/event_router.h"
18 19
19 namespace extensions { 20 namespace extensions {
20 21
22 class GcdPrivateSessionHolder;
23
21 class GcdPrivateAPI : public BrowserContextKeyedAPI, 24 class GcdPrivateAPI : public BrowserContextKeyedAPI,
22 public EventRouter::Observer, 25 public EventRouter::Observer,
23 public local_discovery::PrivetDeviceLister::Delegate { 26 public local_discovery::PrivetDeviceLister::Delegate {
24 public: 27 public:
28 typedef base::Callback<void(int session_id,
29 api::gcd_private::Status status,
30 const std::string& code,
31 api::gcd_private::ConfirmationType type)>
32 ConfirmationCodeCallback;
33
34 typedef base::Callback<void(api::gcd_private::Status status)>
35 SessionEstablishedCallback;
36
37 typedef base::Callback<void(api::gcd_private::Status status,
38 const base::DictionaryValue& response)>
39 MessageResponseCallback;
40
25 class GCDApiFlowFactoryForTests { 41 class GCDApiFlowFactoryForTests {
26 public: 42 public:
27 virtual ~GCDApiFlowFactoryForTests() {} 43 virtual ~GCDApiFlowFactoryForTests() {}
28 44
29 virtual scoped_ptr<local_discovery::GCDApiFlow> CreateGCDApiFlow() = 0; 45 virtual scoped_ptr<local_discovery::GCDApiFlow> CreateGCDApiFlow() = 0;
30 }; 46 };
31 47
32 explicit GcdPrivateAPI(content::BrowserContext* context); 48 explicit GcdPrivateAPI(content::BrowserContext* context);
33 virtual ~GcdPrivateAPI(); 49 virtual ~GcdPrivateAPI();
34 50
35 static void SetGCDApiFlowFactoryForTests(GCDApiFlowFactoryForTests* factory); 51 static void SetGCDApiFlowFactoryForTests(GCDApiFlowFactoryForTests* factory);
36 52
37 // BrowserContextKeyedAPI implementation. 53 // BrowserContextKeyedAPI implementation.
38 static BrowserContextKeyedAPIFactory<GcdPrivateAPI>* GetFactoryInstance(); 54 static BrowserContextKeyedAPIFactory<GcdPrivateAPI>* GetFactoryInstance();
39 55
40 bool QueryForDevices(); 56 bool QueryForDevices();
41 57
58 void EstablishSession(std::string ip_address,
asargent_no_longer_on_chrome 2014/07/25 20:50:10 nit: should this be "const std::string&" ?
Noam Samuel 2014/07/25 21:15:56 Done.
59 int port,
60 ConfirmationCodeCallback callback);
61
62 void ConfirmCode(int session_id, SessionEstablishedCallback callback);
63
64 void SendMessage(int session_id,
65 const std::string& api,
66 const base::DictionaryValue& input,
67 MessageResponseCallback callback);
68
69 void RemoveSession(int session_id);
70
42 private: 71 private:
43 friend class BrowserContextKeyedAPIFactory<GcdPrivateAPI>; 72 friend class BrowserContextKeyedAPIFactory<GcdPrivateAPI>;
44 73
45 typedef std::map<std::string /* id_string */, 74 typedef std::map<std::string /* id_string */,
46 linked_ptr<api::gcd_private::GCDDevice> > GCDDeviceMap; 75 linked_ptr<api::gcd_private::GCDDevice> > GCDDeviceMap;
47 76
77 typedef std::map<int /* session id*/, linked_ptr<GcdPrivateSessionHolder> >
78 GCDSessionMap;
79
48 // EventRouter::Observer implementation. 80 // EventRouter::Observer implementation.
49 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; 81 virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE;
50 virtual void OnListenerRemoved(const EventListenerInfo& details) OVERRIDE; 82 virtual void OnListenerRemoved(const EventListenerInfo& details) OVERRIDE;
51 83
52 // BrowserContextKeyedAPI implementation. 84 // BrowserContextKeyedAPI implementation.
53 static const char* service_name() { return "GcdPrivateAPI"; } 85 static const char* service_name() { return "GcdPrivateAPI"; }
54 86
55 // local_discovery::PrivetDeviceLister implementation. 87 // local_discovery::PrivetDeviceLister implementation.
56 virtual void DeviceChanged( 88 virtual void DeviceChanged(
57 bool added, 89 bool added,
58 const std::string& name, 90 const std::string& name,
59 const local_discovery::DeviceDescription& description) OVERRIDE; 91 const local_discovery::DeviceDescription& description) OVERRIDE;
60 virtual void DeviceRemoved(const std::string& name) OVERRIDE; 92 virtual void DeviceRemoved(const std::string& name) OVERRIDE;
61 virtual void DeviceCacheFlushed() OVERRIDE; 93 virtual void DeviceCacheFlushed() OVERRIDE;
62 94
63 int num_device_listeners_; 95 int num_device_listeners_;
64 scoped_refptr<local_discovery::ServiceDiscoverySharedClient> 96 scoped_refptr<local_discovery::ServiceDiscoverySharedClient>
65 service_discovery_client_; 97 service_discovery_client_;
66 scoped_ptr<local_discovery::PrivetDeviceLister> privet_device_lister_; 98 scoped_ptr<local_discovery::PrivetDeviceLister> privet_device_lister_;
67 GCDDeviceMap known_devices_; 99 GCDDeviceMap known_devices_;
68 100
101 GCDSessionMap sessions_;
102 int last_session_id_;
103
69 content::BrowserContext* const browser_context_; 104 content::BrowserContext* const browser_context_;
70 }; 105 };
71 106
72 class GcdPrivateGetCloudDeviceListFunction 107 class GcdPrivateGetCloudDeviceListFunction
73 : public ChromeAsyncExtensionFunction, 108 : public ChromeAsyncExtensionFunction,
74 public local_discovery::CloudDeviceListDelegate { 109 public local_discovery::CloudDeviceListDelegate {
75 public: 110 public:
76 DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCloudDeviceList", 111 DECLARE_EXTENSION_FUNCTION("gcdPrivate.getCloudDeviceList",
77 GCDPRIVATE_GETCLOUDDEVICELIST) 112 GCDPRIVATE_GETCLOUDDEVICELIST)
78 113
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 DECLARE_EXTENSION_FUNCTION("gcdPrivate.establishSession", 169 DECLARE_EXTENSION_FUNCTION("gcdPrivate.establishSession",
135 GCDPRIVATE_ESTABLISHSESSION) 170 GCDPRIVATE_ESTABLISHSESSION)
136 171
137 GcdPrivateEstablishSessionFunction(); 172 GcdPrivateEstablishSessionFunction();
138 173
139 protected: 174 protected:
140 virtual ~GcdPrivateEstablishSessionFunction(); 175 virtual ~GcdPrivateEstablishSessionFunction();
141 176
142 // AsyncExtensionFunction overrides. 177 // AsyncExtensionFunction overrides.
143 virtual bool RunAsync() OVERRIDE; 178 virtual bool RunAsync() OVERRIDE;
179
180 private:
181 void OnConfirmCodeCallback(
182 int session_id,
183 api::gcd_private::Status status,
184 const std::string& confirm_code,
185 api::gcd_private::ConfirmationType confirmation_type);
144 }; 186 };
145 187
146 class GcdPrivateConfirmCodeFunction : public ChromeAsyncExtensionFunction { 188 class GcdPrivateConfirmCodeFunction : public ChromeAsyncExtensionFunction {
147 public: 189 public:
148 DECLARE_EXTENSION_FUNCTION("gcdPrivate.confirmCode", GCDPRIVATE_CONFIRMCODE) 190 DECLARE_EXTENSION_FUNCTION("gcdPrivate.confirmCode", GCDPRIVATE_CONFIRMCODE)
149 191
150 GcdPrivateConfirmCodeFunction(); 192 GcdPrivateConfirmCodeFunction();
151 193
152 protected: 194 protected:
153 virtual ~GcdPrivateConfirmCodeFunction(); 195 virtual ~GcdPrivateConfirmCodeFunction();
154 196
155 // AsyncExtensionFunction overrides. 197 // AsyncExtensionFunction overrides.
156 virtual bool RunAsync() OVERRIDE; 198 virtual bool RunAsync() OVERRIDE;
157 199
158 private: 200 private:
201 void OnSessionEstablishedCallback(api::gcd_private::Status status);
159 }; 202 };
160 203
161 class GcdPrivateSendMessageFunction : public ChromeAsyncExtensionFunction { 204 class GcdPrivateSendMessageFunction : public ChromeAsyncExtensionFunction {
162 public: 205 public:
163 DECLARE_EXTENSION_FUNCTION("gcdPrivate.sendMessage", GCDPRIVATE_SENDMESSAGE) 206 DECLARE_EXTENSION_FUNCTION("gcdPrivate.sendMessage", GCDPRIVATE_SENDMESSAGE)
164 207
165 GcdPrivateSendMessageFunction(); 208 GcdPrivateSendMessageFunction();
166 209
167 protected: 210 protected:
168 virtual ~GcdPrivateSendMessageFunction(); 211 virtual ~GcdPrivateSendMessageFunction();
169 212
170 // AsyncExtensionFunction overrides. 213 // AsyncExtensionFunction overrides.
171 virtual bool RunAsync() OVERRIDE; 214 virtual bool RunAsync() OVERRIDE;
172 215
173 private: 216 private:
217 void OnMessageSentCallback(api::gcd_private::Status status,
218 const base::DictionaryValue& value);
174 }; 219 };
175 220
176 class GcdPrivateTerminateSessionFunction : public ChromeAsyncExtensionFunction { 221 class GcdPrivateTerminateSessionFunction : public ChromeAsyncExtensionFunction {
177 public: 222 public:
178 DECLARE_EXTENSION_FUNCTION("gcdPrivate.terminateSession", 223 DECLARE_EXTENSION_FUNCTION("gcdPrivate.terminateSession",
179 GCDPRIVATE_TERMINATESESSION) 224 GCDPRIVATE_TERMINATESESSION)
180 225
181 GcdPrivateTerminateSessionFunction(); 226 GcdPrivateTerminateSessionFunction();
182 227
183 protected: 228 protected:
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
263 308
264 // AsyncExtensionFunction overrides. 309 // AsyncExtensionFunction overrides.
265 virtual bool RunAsync() OVERRIDE; 310 virtual bool RunAsync() OVERRIDE;
266 311
267 private: 312 private:
268 }; 313 };
269 314
270 } // namespace extensions 315 } // namespace extensions
271 316
272 #endif // CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_GCD_PRIVATE_API_H_ 317 #endif // CHROME_BROWSER_EXTENSIONS_API_GCD_PRIVATE_GCD_PRIVATE_API_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698