| OLD | NEW |
| 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 #include "chrome/browser/extensions/api/gcd_private/gcd_private_api.h" | 5 #include "chrome/browser/extensions/api/gcd_private/gcd_private_api.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 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 "base/memory/scoped_vector.h" | 10 #include "base/memory/scoped_vector.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 typedef std::map<std::string /* id_string */, | 143 typedef std::map<std::string /* id_string */, |
| 144 linked_ptr<api::gcd_private::GCDDevice> > GCDDeviceMap; | 144 linked_ptr<api::gcd_private::GCDDevice> > GCDDeviceMap; |
| 145 | 145 |
| 146 typedef std::map<int /* session id*/, linked_ptr<GcdPrivateSessionHolder> > | 146 typedef std::map<int /* session id*/, linked_ptr<GcdPrivateSessionHolder> > |
| 147 GCDSessionMap; | 147 GCDSessionMap; |
| 148 | 148 |
| 149 typedef std::map<std::string /* ssid */, std::string /* password */> | 149 typedef std::map<std::string /* ssid */, std::string /* password */> |
| 150 PasswordMap; | 150 PasswordMap; |
| 151 | 151 |
| 152 // EventRouter::Observer implementation. | 152 // EventRouter::Observer implementation. |
| 153 virtual void OnListenerAdded(const EventListenerInfo& details) override; | 153 void OnListenerAdded(const EventListenerInfo& details) override; |
| 154 virtual void OnListenerRemoved(const EventListenerInfo& details) override; | 154 void OnListenerRemoved(const EventListenerInfo& details) override; |
| 155 | 155 |
| 156 // local_discovery::PrivetDeviceLister implementation. | 156 // local_discovery::PrivetDeviceLister implementation. |
| 157 virtual void DeviceChanged( | 157 void DeviceChanged( |
| 158 bool added, | 158 bool added, |
| 159 const std::string& name, | 159 const std::string& name, |
| 160 const local_discovery::DeviceDescription& description) override; | 160 const local_discovery::DeviceDescription& description) override; |
| 161 virtual void DeviceRemoved(const std::string& name) override; | 161 void DeviceRemoved(const std::string& name) override; |
| 162 virtual void DeviceCacheFlushed() override; | 162 void DeviceCacheFlushed() override; |
| 163 | 163 |
| 164 void SendMessageInternal(int session_id, | 164 void SendMessageInternal(int session_id, |
| 165 const std::string& api, | 165 const std::string& api, |
| 166 const base::DictionaryValue& input, | 166 const base::DictionaryValue& input, |
| 167 const MessageResponseCallback& callback); | 167 const MessageResponseCallback& callback); |
| 168 | 168 |
| 169 #if defined(ENABLE_WIFI_BOOTSTRAPPING) | 169 #if defined(ENABLE_WIFI_BOOTSTRAPPING) |
| 170 void OnWifiPassword(const SuccessCallback& callback, | 170 void OnWifiPassword(const SuccessCallback& callback, |
| 171 bool success, | 171 bool success, |
| 172 const std::string& ssid, | 172 const std::string& ssid, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 190 #endif | 190 #endif |
| 191 PasswordMap wifi_passwords_; | 191 PasswordMap wifi_passwords_; |
| 192 }; | 192 }; |
| 193 | 193 |
| 194 class GcdPrivateRequest : public local_discovery::PrivetV3Session::Request { | 194 class GcdPrivateRequest : public local_discovery::PrivetV3Session::Request { |
| 195 public: | 195 public: |
| 196 GcdPrivateRequest(const std::string& api, | 196 GcdPrivateRequest(const std::string& api, |
| 197 const base::DictionaryValue& input, | 197 const base::DictionaryValue& input, |
| 198 const GcdPrivateAPIImpl::MessageResponseCallback& callback, | 198 const GcdPrivateAPIImpl::MessageResponseCallback& callback, |
| 199 GcdPrivateSessionHolder* session_holder); | 199 GcdPrivateSessionHolder* session_holder); |
| 200 virtual ~GcdPrivateRequest(); | 200 ~GcdPrivateRequest() override; |
| 201 | 201 |
| 202 // local_discovery::PrivetV3Session::Request implementation. | 202 // local_discovery::PrivetV3Session::Request implementation. |
| 203 virtual std::string GetName() override; | 203 std::string GetName() override; |
| 204 virtual const base::DictionaryValue& GetInput() override; | 204 const base::DictionaryValue& GetInput() override; |
| 205 virtual void OnError() override; | 205 void OnError() override; |
| 206 virtual void OnParsedJson(const base::DictionaryValue& value, | 206 void OnParsedJson(const base::DictionaryValue& value, |
| 207 bool has_error) override; | 207 bool has_error) override; |
| 208 | 208 |
| 209 void RunCallback(gcd_private::Status status, | 209 void RunCallback(gcd_private::Status status, |
| 210 const base::DictionaryValue& value); | 210 const base::DictionaryValue& value); |
| 211 | 211 |
| 212 private: | 212 private: |
| 213 std::string api_; | 213 std::string api_; |
| 214 scoped_ptr<base::DictionaryValue> input_; | 214 scoped_ptr<base::DictionaryValue> input_; |
| 215 GcdPrivateAPIImpl::MessageResponseCallback callback_; | 215 GcdPrivateAPIImpl::MessageResponseCallback callback_; |
| 216 GcdPrivateSessionHolder* session_holder_; | 216 GcdPrivateSessionHolder* session_holder_; |
| 217 }; | 217 }; |
| 218 | 218 |
| 219 class GcdPrivateSessionHolder | 219 class GcdPrivateSessionHolder |
| 220 : public local_discovery::PrivetV3Session::Delegate { | 220 : public local_discovery::PrivetV3Session::Delegate { |
| 221 public: | 221 public: |
| 222 typedef base::Callback<void(api::gcd_private::Status status, | 222 typedef base::Callback<void(api::gcd_private::Status status, |
| 223 const std::string& code, | 223 const std::string& code, |
| 224 api::gcd_private::ConfirmationType type)> | 224 api::gcd_private::ConfirmationType type)> |
| 225 ConfirmationCodeCallback; | 225 ConfirmationCodeCallback; |
| 226 | 226 |
| 227 GcdPrivateSessionHolder(const std::string& ip_address, | 227 GcdPrivateSessionHolder(const std::string& ip_address, |
| 228 int port, | 228 int port, |
| 229 net::URLRequestContextGetter* request_context); | 229 net::URLRequestContextGetter* request_context); |
| 230 virtual ~GcdPrivateSessionHolder(); | 230 ~GcdPrivateSessionHolder() override; |
| 231 | 231 |
| 232 void Start(const ConfirmationCodeCallback& callback); | 232 void Start(const ConfirmationCodeCallback& callback); |
| 233 | 233 |
| 234 void ConfirmCode( | 234 void ConfirmCode( |
| 235 const std::string& code, | 235 const std::string& code, |
| 236 const GcdPrivateAPIImpl::SessionEstablishedCallback& callback); | 236 const GcdPrivateAPIImpl::SessionEstablishedCallback& callback); |
| 237 | 237 |
| 238 void SendMessage(const std::string& api, | 238 void SendMessage(const std::string& api, |
| 239 const base::DictionaryValue& input, | 239 const base::DictionaryValue& input, |
| 240 GcdPrivateAPIImpl::MessageResponseCallback callback); | 240 GcdPrivateAPIImpl::MessageResponseCallback callback); |
| 241 | 241 |
| 242 void DeleteRequest(GcdPrivateRequest* request); | 242 void DeleteRequest(GcdPrivateRequest* request); |
| 243 | 243 |
| 244 private: | 244 private: |
| 245 // local_discovery::PrivetV3Session::Delegate implementation. | 245 // local_discovery::PrivetV3Session::Delegate implementation. |
| 246 virtual void OnSetupConfirmationNeeded( | 246 void OnSetupConfirmationNeeded( |
| 247 const std::string& confirmation_code, | 247 const std::string& confirmation_code, |
| 248 api::gcd_private::ConfirmationType confirmation_type) override; | 248 api::gcd_private::ConfirmationType confirmation_type) override; |
| 249 virtual void OnSessionStatus(api::gcd_private::Status status) override; | 249 void OnSessionStatus(api::gcd_private::Status status) override; |
| 250 | 250 |
| 251 scoped_ptr<local_discovery::PrivetHTTPClient> http_client_; | 251 scoped_ptr<local_discovery::PrivetHTTPClient> http_client_; |
| 252 scoped_ptr<local_discovery::PrivetV3Session> privet_session_; | 252 scoped_ptr<local_discovery::PrivetV3Session> privet_session_; |
| 253 typedef ScopedVector<GcdPrivateRequest> RequestVector; | 253 typedef ScopedVector<GcdPrivateRequest> RequestVector; |
| 254 RequestVector requests_; | 254 RequestVector requests_; |
| 255 | 255 |
| 256 ConfirmationCodeCallback confirm_callback_; | 256 ConfirmationCodeCallback confirm_callback_; |
| 257 GcdPrivateAPIImpl::SessionEstablishedCallback session_established_callback_; | 257 GcdPrivateAPIImpl::SessionEstablishedCallback session_established_callback_; |
| 258 }; | 258 }; |
| 259 | 259 |
| (...skipping 692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 952 } | 952 } |
| 953 | 953 |
| 954 GcdPrivateGetCommandsListFunction::~GcdPrivateGetCommandsListFunction() { | 954 GcdPrivateGetCommandsListFunction::~GcdPrivateGetCommandsListFunction() { |
| 955 } | 955 } |
| 956 | 956 |
| 957 bool GcdPrivateGetCommandsListFunction::RunAsync() { | 957 bool GcdPrivateGetCommandsListFunction::RunAsync() { |
| 958 return false; | 958 return false; |
| 959 } | 959 } |
| 960 | 960 |
| 961 } // namespace extensions | 961 } // namespace extensions |
| OLD | NEW |