| 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 "extensions/browser/api/vpn_provider/vpn_provider_api.h" | 5 #include "extensions/browser/api/vpn_provider/vpn_provider_api.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <vector> | 8 #include <vector> |
| 8 | 9 |
| 9 #include "base/bind.h" | 10 #include "base/bind.h" |
| 10 #include "base/logging.h" | 11 #include "base/logging.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 14 #include "base/values.h" | 14 #include "base/values.h" |
| 15 #include "extensions/browser/api/vpn_provider/vpn_service.h" | 15 #include "extensions/browser/api/vpn_provider/vpn_service.h" |
| 16 #include "extensions/browser/api/vpn_provider/vpn_service_factory.h" | 16 #include "extensions/browser/api/vpn_provider/vpn_service_factory.h" |
| 17 #include "extensions/common/api/vpn_provider.h" | 17 #include "extensions/common/api/vpn_provider.h" |
| 18 #include "third_party/cros_system_api/dbus/service_constants.h" | 18 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 19 | 19 |
| 20 namespace extensions { | 20 namespace extensions { |
| 21 | 21 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 Respond(Error(error_name)); | 182 Respond(Error(error_name)); |
| 183 } else { | 183 } else { |
| 184 Respond(Error(error_message)); | 184 Respond(Error(error_message)); |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 | 187 |
| 188 VpnProviderCreateConfigFunction::~VpnProviderCreateConfigFunction() { | 188 VpnProviderCreateConfigFunction::~VpnProviderCreateConfigFunction() { |
| 189 } | 189 } |
| 190 | 190 |
| 191 ExtensionFunction::ResponseAction VpnProviderCreateConfigFunction::Run() { | 191 ExtensionFunction::ResponseAction VpnProviderCreateConfigFunction::Run() { |
| 192 scoped_ptr<api_vpn::CreateConfig::Params> params( | 192 std::unique_ptr<api_vpn::CreateConfig::Params> params( |
| 193 api_vpn::CreateConfig::Params::Create(*args_)); | 193 api_vpn::CreateConfig::Params::Create(*args_)); |
| 194 if (!params) { | 194 if (!params) { |
| 195 return RespondNow(Error("Invalid arguments.")); | 195 return RespondNow(Error("Invalid arguments.")); |
| 196 } | 196 } |
| 197 | 197 |
| 198 chromeos::VpnService* service = | 198 chromeos::VpnService* service = |
| 199 chromeos::VpnServiceFactory::GetForBrowserContext(browser_context()); | 199 chromeos::VpnServiceFactory::GetForBrowserContext(browser_context()); |
| 200 if (!service) { | 200 if (!service) { |
| 201 return RespondNow(Error("Invalid profile.")); | 201 return RespondNow(Error("Invalid profile.")); |
| 202 } | 202 } |
| 203 | 203 |
| 204 // Use the configuration name as ID. In the future, a different ID scheme may | 204 // Use the configuration name as ID. In the future, a different ID scheme may |
| 205 // be used, requiring a mapping between the two. | 205 // be used, requiring a mapping between the two. |
| 206 service->CreateConfiguration( | 206 service->CreateConfiguration( |
| 207 extension_id(), extension()->name(), params->name, | 207 extension_id(), extension()->name(), params->name, |
| 208 base::Bind( | 208 base::Bind( |
| 209 &VpnProviderCreateConfigFunction::SignalCallCompletionSuccessWithId, | 209 &VpnProviderCreateConfigFunction::SignalCallCompletionSuccessWithId, |
| 210 this, params->name), | 210 this, params->name), |
| 211 base::Bind(&VpnProviderNotifyConnectionStateChangedFunction:: | 211 base::Bind(&VpnProviderNotifyConnectionStateChangedFunction:: |
| 212 SignalCallCompletionFailure, | 212 SignalCallCompletionFailure, |
| 213 this)); | 213 this)); |
| 214 | 214 |
| 215 return RespondLater(); | 215 return RespondLater(); |
| 216 } | 216 } |
| 217 | 217 |
| 218 VpnProviderDestroyConfigFunction::~VpnProviderDestroyConfigFunction() { | 218 VpnProviderDestroyConfigFunction::~VpnProviderDestroyConfigFunction() { |
| 219 } | 219 } |
| 220 | 220 |
| 221 ExtensionFunction::ResponseAction VpnProviderDestroyConfigFunction::Run() { | 221 ExtensionFunction::ResponseAction VpnProviderDestroyConfigFunction::Run() { |
| 222 scoped_ptr<api_vpn::DestroyConfig::Params> params( | 222 std::unique_ptr<api_vpn::DestroyConfig::Params> params( |
| 223 api_vpn::DestroyConfig::Params::Create(*args_)); | 223 api_vpn::DestroyConfig::Params::Create(*args_)); |
| 224 if (!params) { | 224 if (!params) { |
| 225 return RespondNow(Error("Invalid arguments.")); | 225 return RespondNow(Error("Invalid arguments.")); |
| 226 } | 226 } |
| 227 | 227 |
| 228 chromeos::VpnService* service = | 228 chromeos::VpnService* service = |
| 229 chromeos::VpnServiceFactory::GetForBrowserContext(browser_context()); | 229 chromeos::VpnServiceFactory::GetForBrowserContext(browser_context()); |
| 230 if (!service) { | 230 if (!service) { |
| 231 return RespondNow(Error("Invalid profile.")); | 231 return RespondNow(Error("Invalid profile.")); |
| 232 } | 232 } |
| 233 | 233 |
| 234 service->DestroyConfiguration( | 234 service->DestroyConfiguration( |
| 235 extension_id(), params->id, | 235 extension_id(), params->id, |
| 236 base::Bind(&VpnProviderDestroyConfigFunction::SignalCallCompletionSuccess, | 236 base::Bind(&VpnProviderDestroyConfigFunction::SignalCallCompletionSuccess, |
| 237 this), | 237 this), |
| 238 base::Bind(&VpnProviderNotifyConnectionStateChangedFunction:: | 238 base::Bind(&VpnProviderNotifyConnectionStateChangedFunction:: |
| 239 SignalCallCompletionFailure, | 239 SignalCallCompletionFailure, |
| 240 this)); | 240 this)); |
| 241 | 241 |
| 242 return RespondLater(); | 242 return RespondLater(); |
| 243 } | 243 } |
| 244 | 244 |
| 245 VpnProviderSetParametersFunction::~VpnProviderSetParametersFunction() { | 245 VpnProviderSetParametersFunction::~VpnProviderSetParametersFunction() { |
| 246 } | 246 } |
| 247 | 247 |
| 248 ExtensionFunction::ResponseAction VpnProviderSetParametersFunction::Run() { | 248 ExtensionFunction::ResponseAction VpnProviderSetParametersFunction::Run() { |
| 249 scoped_ptr<api_vpn::SetParameters::Params> params( | 249 std::unique_ptr<api_vpn::SetParameters::Params> params( |
| 250 api_vpn::SetParameters::Params::Create(*args_)); | 250 api_vpn::SetParameters::Params::Create(*args_)); |
| 251 if (!params) { | 251 if (!params) { |
| 252 return RespondNow(Error("Invalid arguments.")); | 252 return RespondNow(Error("Invalid arguments.")); |
| 253 } | 253 } |
| 254 | 254 |
| 255 chromeos::VpnService* service = | 255 chromeos::VpnService* service = |
| 256 chromeos::VpnServiceFactory::GetForBrowserContext(browser_context()); | 256 chromeos::VpnServiceFactory::GetForBrowserContext(browser_context()); |
| 257 if (!service) { | 257 if (!service) { |
| 258 return RespondNow(Error("Invalid profile.")); | 258 return RespondNow(Error("Invalid profile.")); |
| 259 } | 259 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 274 SignalCallCompletionFailure, | 274 SignalCallCompletionFailure, |
| 275 this)); | 275 this)); |
| 276 | 276 |
| 277 return RespondLater(); | 277 return RespondLater(); |
| 278 } | 278 } |
| 279 | 279 |
| 280 VpnProviderSendPacketFunction::~VpnProviderSendPacketFunction() { | 280 VpnProviderSendPacketFunction::~VpnProviderSendPacketFunction() { |
| 281 } | 281 } |
| 282 | 282 |
| 283 ExtensionFunction::ResponseAction VpnProviderSendPacketFunction::Run() { | 283 ExtensionFunction::ResponseAction VpnProviderSendPacketFunction::Run() { |
| 284 scoped_ptr<api_vpn::SendPacket::Params> params( | 284 std::unique_ptr<api_vpn::SendPacket::Params> params( |
| 285 api_vpn::SendPacket::Params::Create(*args_)); | 285 api_vpn::SendPacket::Params::Create(*args_)); |
| 286 if (!params) { | 286 if (!params) { |
| 287 return RespondNow(Error("Invalid arguments.")); | 287 return RespondNow(Error("Invalid arguments.")); |
| 288 } | 288 } |
| 289 | 289 |
| 290 chromeos::VpnService* service = | 290 chromeos::VpnService* service = |
| 291 chromeos::VpnServiceFactory::GetForBrowserContext(browser_context()); | 291 chromeos::VpnServiceFactory::GetForBrowserContext(browser_context()); |
| 292 if (!service) { | 292 if (!service) { |
| 293 return RespondNow(Error("Invalid profile.")); | 293 return RespondNow(Error("Invalid profile.")); |
| 294 } | 294 } |
| 295 | 295 |
| 296 service->SendPacket( | 296 service->SendPacket( |
| 297 extension_id(), params->data, | 297 extension_id(), params->data, |
| 298 base::Bind(&VpnProviderSendPacketFunction::SignalCallCompletionSuccess, | 298 base::Bind(&VpnProviderSendPacketFunction::SignalCallCompletionSuccess, |
| 299 this), | 299 this), |
| 300 base::Bind(&VpnProviderNotifyConnectionStateChangedFunction:: | 300 base::Bind(&VpnProviderNotifyConnectionStateChangedFunction:: |
| 301 SignalCallCompletionFailure, | 301 SignalCallCompletionFailure, |
| 302 this)); | 302 this)); |
| 303 | 303 |
| 304 return RespondLater(); | 304 return RespondLater(); |
| 305 } | 305 } |
| 306 | 306 |
| 307 VpnProviderNotifyConnectionStateChangedFunction:: | 307 VpnProviderNotifyConnectionStateChangedFunction:: |
| 308 ~VpnProviderNotifyConnectionStateChangedFunction() { | 308 ~VpnProviderNotifyConnectionStateChangedFunction() { |
| 309 } | 309 } |
| 310 | 310 |
| 311 ExtensionFunction::ResponseAction | 311 ExtensionFunction::ResponseAction |
| 312 VpnProviderNotifyConnectionStateChangedFunction::Run() { | 312 VpnProviderNotifyConnectionStateChangedFunction::Run() { |
| 313 scoped_ptr<api_vpn::NotifyConnectionStateChanged::Params> params( | 313 std::unique_ptr<api_vpn::NotifyConnectionStateChanged::Params> params( |
| 314 api_vpn::NotifyConnectionStateChanged::Params::Create(*args_)); | 314 api_vpn::NotifyConnectionStateChanged::Params::Create(*args_)); |
| 315 if (!params) { | 315 if (!params) { |
| 316 return RespondNow(Error("Invalid arguments.")); | 316 return RespondNow(Error("Invalid arguments.")); |
| 317 } | 317 } |
| 318 | 318 |
| 319 chromeos::VpnService* service = | 319 chromeos::VpnService* service = |
| 320 chromeos::VpnServiceFactory::GetForBrowserContext(browser_context()); | 320 chromeos::VpnServiceFactory::GetForBrowserContext(browser_context()); |
| 321 if (!service) { | 321 if (!service) { |
| 322 return RespondNow(Error("Invalid profile.")); | 322 return RespondNow(Error("Invalid profile.")); |
| 323 } | 323 } |
| 324 | 324 |
| 325 service->NotifyConnectionStateChanged( | 325 service->NotifyConnectionStateChanged( |
| 326 extension_id(), params->state, | 326 extension_id(), params->state, |
| 327 base::Bind(&VpnProviderNotifyConnectionStateChangedFunction:: | 327 base::Bind(&VpnProviderNotifyConnectionStateChangedFunction:: |
| 328 SignalCallCompletionSuccess, | 328 SignalCallCompletionSuccess, |
| 329 this), | 329 this), |
| 330 base::Bind(&VpnProviderNotifyConnectionStateChangedFunction:: | 330 base::Bind(&VpnProviderNotifyConnectionStateChangedFunction:: |
| 331 SignalCallCompletionFailure, | 331 SignalCallCompletionFailure, |
| 332 this)); | 332 this)); |
| 333 | 333 |
| 334 return RespondLater(); | 334 return RespondLater(); |
| 335 } | 335 } |
| 336 | 336 |
| 337 } // namespace extensions | 337 } // namespace extensions |
| OLD | NEW |