Chromium Code Reviews| Index: chrome/browser/extensions/api/gcd_private/gcd_private_api.h |
| diff --git a/chrome/browser/extensions/api/gcd_private/gcd_private_api.h b/chrome/browser/extensions/api/gcd_private/gcd_private_api.h |
| index 488b60810cf25d73099a75c74f0879945c9acfb3..fe2955647bb9bf8c79ddb962074392eb75cca81f 100644 |
| --- a/chrome/browser/extensions/api/gcd_private/gcd_private_api.h |
| +++ b/chrome/browser/extensions/api/gcd_private/gcd_private_api.h |
| @@ -11,6 +11,7 @@ |
| #include "chrome/browser/local_discovery/cloud_device_list_delegate.h" |
| #include "chrome/browser/local_discovery/gcd_api_flow.h" |
| #include "chrome/browser/local_discovery/privet_device_lister.h" |
| +#include "chrome/browser/local_discovery/privetv3_session.h" |
| #include "chrome/browser/local_discovery/service_discovery_shared_client.h" |
| #include "chrome/common/extensions/api/gcd_private.h" |
| #include "extensions/browser/browser_context_keyed_api_factory.h" |
| @@ -18,10 +19,25 @@ |
| namespace extensions { |
| +class GcdPrivateSessionHolder; |
| + |
| class GcdPrivateAPI : public BrowserContextKeyedAPI, |
| public EventRouter::Observer, |
| public local_discovery::PrivetDeviceLister::Delegate { |
| public: |
| + typedef base::Callback<void(int session_id, |
| + api::gcd_private::Status status, |
| + const std::string& code, |
| + api::gcd_private::ConfirmationType type)> |
| + ConfirmationCodeCallback; |
| + |
| + typedef base::Callback<void(api::gcd_private::Status status)> |
| + SessionEstablishedCallback; |
| + |
| + typedef base::Callback<void(api::gcd_private::Status status, |
| + const base::DictionaryValue& response)> |
| + MessageResponseCallback; |
| + |
| class GCDApiFlowFactoryForTests { |
| public: |
| virtual ~GCDApiFlowFactoryForTests() {} |
| @@ -39,12 +55,26 @@ class GcdPrivateAPI : public BrowserContextKeyedAPI, |
| bool QueryForDevices(); |
| + void EstablishSession(std::string ip_address, |
| + int port, |
| + ConfirmationCodeCallback callback); |
| + |
| + void ConfirmCode(int session_id, SessionEstablishedCallback callback); |
| + |
| + void SendMessage(int session_id, |
| + const std::string& api, |
| + const base::DictionaryValue& input, |
| + MessageResponseCallback callback); |
| + |
| private: |
| friend class BrowserContextKeyedAPIFactory<GcdPrivateAPI>; |
| typedef std::map<std::string /* id_string */, |
| linked_ptr<api::gcd_private::GCDDevice> > GCDDeviceMap; |
| + typedef std::map<int /*session_id*/, linked_ptr<GcdPrivateSessionHolder> > |
|
Vitaly Buka (NO REVIEWS)
2014/07/24 20:50:18
You don't need map, ScopedVector<> should be enoug
Noam Samuel
2014/07/24 21:11:22
Not sure what the benefit of using a vector over a
Noam Samuel
2014/07/24 21:55:45
Replaced std::vector< linked_ptr< >> with ScopedVe
|
| + GCDSessionMap; |
| + |
| // EventRouter::Observer implementation. |
| virtual void OnListenerAdded(const EventListenerInfo& details) OVERRIDE; |
| virtual void OnListenerRemoved(const EventListenerInfo& details) OVERRIDE; |
| @@ -66,9 +96,74 @@ class GcdPrivateAPI : public BrowserContextKeyedAPI, |
| scoped_ptr<local_discovery::PrivetDeviceLister> privet_device_lister_; |
| GCDDeviceMap known_devices_; |
| + GCDSessionMap sessions_; |
| + int last_session_id_; |
| + |
| content::BrowserContext* const browser_context_; |
| }; |
| +class GcdPrivateRequest : public local_discovery::PrivetV3Session::Request { |
|
Vitaly Buka (NO REVIEWS)
2014/07/24 20:50:18
this should be defined in cc file
Noam Samuel
2014/07/24 21:55:45
Done.
|
| + public: |
| + GcdPrivateRequest(const std::string& api, |
| + const base::DictionaryValue& input, |
| + const GcdPrivateAPI::MessageResponseCallback& callback, |
| + GcdPrivateSessionHolder* session_holder); |
| + virtual ~GcdPrivateRequest(); |
| + |
| + // local_discovery::PrivetV3Session::Request implementation. |
| + virtual std::string GetName() OVERRIDE; |
| + virtual const base::DictionaryValue& GetInput() OVERRIDE; |
| + virtual void OnError( |
| + local_discovery::PrivetURLFetcher::ErrorType error) OVERRIDE; |
| + virtual void OnParsedJson(const base::DictionaryValue& value, |
| + bool has_error) OVERRIDE; |
| + |
| + private: |
| + std::string api_; |
| + scoped_ptr<base::DictionaryValue> input_; |
| + GcdPrivateAPI::MessageResponseCallback callback_; |
| + GcdPrivateSessionHolder* session_holder_; |
| +}; |
| + |
| +class GcdPrivateSessionHolder |
|
Vitaly Buka (NO REVIEWS)
2014/07/24 20:50:19
GcdPrivateSessionHolder also could be hidden in CC
Noam Samuel
2014/07/24 21:55:45
Done.
|
| + : public local_discovery::PrivetV3Session::Delegate { |
| + public: |
| + typedef base::Callback<void(api::gcd_private::Status status, |
| + const std::string& code, |
| + api::gcd_private::ConfirmationType type)> |
| + ConfirmationCodeCallback; |
| + |
| + GcdPrivateSessionHolder(const std::string& ip_address, |
| + int port, |
| + net::URLRequestContextGetter* request_context); |
| + virtual ~GcdPrivateSessionHolder(); |
| + |
| + void Start(const ConfirmationCodeCallback& callback); |
| + |
| + void ConfirmCode(const GcdPrivateAPI::SessionEstablishedCallback& callback); |
| + |
| + void SendMessage(const std::string& api, |
| + const base::DictionaryValue& input, |
| + GcdPrivateAPI::MessageResponseCallback callback); |
| + |
| + void DeleteRequest(GcdPrivateRequest* request); |
| + |
| + private: |
| + // local_discovery::PrivetV3Session::Delegate implementation. |
| + virtual void OnSetupConfirmationNeeded( |
| + const std::string& confirmation_code) OVERRIDE; |
| + virtual void OnSessionEstablished() OVERRIDE; |
| + virtual void OnCannotEstablishSession() OVERRIDE; |
| + |
| + scoped_ptr<local_discovery::PrivetHTTPClient> http_client_; |
| + scoped_ptr<local_discovery::PrivetV3Session> privet_session_; |
| + typedef std::vector<linked_ptr<GcdPrivateRequest> > RequestVector; |
| + RequestVector requests_; |
| + |
| + ConfirmationCodeCallback confirm_callback_; |
| + GcdPrivateAPI::SessionEstablishedCallback session_established_callback_; |
| +}; |
| + |
| class GcdPrivateGetCloudDeviceListFunction |
| : public ChromeAsyncExtensionFunction, |
| public local_discovery::CloudDeviceListDelegate { |
| @@ -141,6 +236,13 @@ class GcdPrivateEstablishSessionFunction : public ChromeAsyncExtensionFunction { |
| // AsyncExtensionFunction overrides. |
| virtual bool RunAsync() OVERRIDE; |
| + |
| + private: |
| + void OnConfirmCodeCallback( |
| + int session_id, |
| + api::gcd_private::Status status, |
| + const std::string& confirm_code, |
| + api::gcd_private::ConfirmationType confirmation_type); |
| }; |
| class GcdPrivateConfirmCodeFunction : public ChromeAsyncExtensionFunction { |
| @@ -156,6 +258,7 @@ class GcdPrivateConfirmCodeFunction : public ChromeAsyncExtensionFunction { |
| virtual bool RunAsync() OVERRIDE; |
| private: |
| + void OnSessionEstablishedCallback(api::gcd_private::Status status); |
| }; |
| class GcdPrivateSendMessageFunction : public ChromeAsyncExtensionFunction { |
| @@ -171,6 +274,8 @@ class GcdPrivateSendMessageFunction : public ChromeAsyncExtensionFunction { |
| virtual bool RunAsync() OVERRIDE; |
| private: |
| + void OnMessageSentCallback(api::gcd_private::Status status, |
| + const base::DictionaryValue& value); |
| }; |
| class GcdPrivateTerminateSessionFunction : public ChromeAsyncExtensionFunction { |