| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 | 143 |
| 144 } // namespace | 144 } // namespace |
| 145 | 145 |
| 146 VpnThreadExtensionFunction::~VpnThreadExtensionFunction() { | 146 VpnThreadExtensionFunction::~VpnThreadExtensionFunction() { |
| 147 } | 147 } |
| 148 | 148 |
| 149 void VpnThreadExtensionFunction::SignalCallCompletionSuccess() { | 149 void VpnThreadExtensionFunction::SignalCallCompletionSuccess() { |
| 150 Respond(NoArguments()); | 150 Respond(NoArguments()); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void VpnThreadExtensionFunction::SignalCallCompletionSuccessWithId( |
| 154 const std::string& configuration_id) { |
| 155 Respond(OneArgument(new base::StringValue(configuration_id))); |
| 156 } |
| 157 |
| 153 void VpnThreadExtensionFunction::SignalCallCompletionFailure( | 158 void VpnThreadExtensionFunction::SignalCallCompletionFailure( |
| 154 const std::string& error_name, | 159 const std::string& error_name, |
| 155 const std::string& error_message) { | 160 const std::string& error_message) { |
| 156 if (!error_name.empty() && !error_message.empty()) { | 161 if (!error_name.empty() && !error_message.empty()) { |
| 157 Respond(Error(error_name + ": " + error_message)); | 162 Respond(Error(error_name + ": " + error_message)); |
| 158 } else if (!error_name.empty()) { | 163 } else if (!error_name.empty()) { |
| 159 Respond(Error(error_name)); | 164 Respond(Error(error_name)); |
| 160 } else { | 165 } else { |
| 161 Respond(Error(error_message)); | 166 Respond(Error(error_message)); |
| 162 } | 167 } |
| 163 } | 168 } |
| 164 | 169 |
| 165 VpnProviderCreateConfigFunction::~VpnProviderCreateConfigFunction() { | 170 VpnProviderCreateConfigFunction::~VpnProviderCreateConfigFunction() { |
| 166 } | 171 } |
| 167 | 172 |
| 168 ExtensionFunction::ResponseAction VpnProviderCreateConfigFunction::Run() { | 173 ExtensionFunction::ResponseAction VpnProviderCreateConfigFunction::Run() { |
| 169 scoped_ptr<api_vpn::CreateConfig::Params> params( | 174 scoped_ptr<api_vpn::CreateConfig::Params> params( |
| 170 api_vpn::CreateConfig::Params::Create(*args_)); | 175 api_vpn::CreateConfig::Params::Create(*args_)); |
| 171 if (!params) { | 176 if (!params) { |
| 172 return RespondNow(Error("Invalid arguments.")); | 177 return RespondNow(Error("Invalid arguments.")); |
| 173 } | 178 } |
| 174 | 179 |
| 175 chromeos::VpnService* service = | 180 chromeos::VpnService* service = |
| 176 chromeos::VpnServiceFactory::GetForBrowserContext(browser_context()); | 181 chromeos::VpnServiceFactory::GetForBrowserContext(browser_context()); |
| 177 if (!service) { | 182 if (!service) { |
| 178 return RespondNow(Error("Invalid profile.")); | 183 return RespondNow(Error("Invalid profile.")); |
| 179 } | 184 } |
| 180 | 185 |
| 186 // Use the configuration name as ID. In the future, a different ID scheme may |
| 187 // be used, requiring a mapping between the two. |
| 181 service->CreateConfiguration( | 188 service->CreateConfiguration( |
| 182 extension_id(), extension()->name(), params->name, | 189 extension_id(), extension()->name(), params->name, |
| 183 base::Bind(&VpnProviderCreateConfigFunction::SignalCallCompletionSuccess, | 190 base::Bind( |
| 184 this), | 191 &VpnProviderCreateConfigFunction::SignalCallCompletionSuccessWithId, |
| 192 this, params->name), |
| 185 base::Bind(&VpnProviderNotifyConnectionStateChangedFunction:: | 193 base::Bind(&VpnProviderNotifyConnectionStateChangedFunction:: |
| 186 SignalCallCompletionFailure, | 194 SignalCallCompletionFailure, |
| 187 this)); | 195 this)); |
| 188 | 196 |
| 189 return RespondLater(); | 197 return RespondLater(); |
| 190 } | 198 } |
| 191 | 199 |
| 192 VpnProviderDestroyConfigFunction::~VpnProviderDestroyConfigFunction() { | 200 VpnProviderDestroyConfigFunction::~VpnProviderDestroyConfigFunction() { |
| 193 } | 201 } |
| 194 | 202 |
| 195 ExtensionFunction::ResponseAction VpnProviderDestroyConfigFunction::Run() { | 203 ExtensionFunction::ResponseAction VpnProviderDestroyConfigFunction::Run() { |
| 196 scoped_ptr<api_vpn::DestroyConfig::Params> params( | 204 scoped_ptr<api_vpn::DestroyConfig::Params> params( |
| 197 api_vpn::DestroyConfig::Params::Create(*args_)); | 205 api_vpn::DestroyConfig::Params::Create(*args_)); |
| 198 if (!params) { | 206 if (!params) { |
| 199 return RespondNow(Error("Invalid arguments.")); | 207 return RespondNow(Error("Invalid arguments.")); |
| 200 } | 208 } |
| 201 | 209 |
| 202 chromeos::VpnService* service = | 210 chromeos::VpnService* service = |
| 203 chromeos::VpnServiceFactory::GetForBrowserContext(browser_context()); | 211 chromeos::VpnServiceFactory::GetForBrowserContext(browser_context()); |
| 204 if (!service) { | 212 if (!service) { |
| 205 return RespondNow(Error("Invalid profile.")); | 213 return RespondNow(Error("Invalid profile.")); |
| 206 } | 214 } |
| 207 | 215 |
| 208 service->DestroyConfiguration( | 216 service->DestroyConfiguration( |
| 209 extension_id(), params->name, | 217 extension_id(), params->id, |
| 210 base::Bind(&VpnProviderDestroyConfigFunction::SignalCallCompletionSuccess, | 218 base::Bind(&VpnProviderDestroyConfigFunction::SignalCallCompletionSuccess, |
| 211 this), | 219 this), |
| 212 base::Bind(&VpnProviderNotifyConnectionStateChangedFunction:: | 220 base::Bind(&VpnProviderNotifyConnectionStateChangedFunction:: |
| 213 SignalCallCompletionFailure, | 221 SignalCallCompletionFailure, |
| 214 this)); | 222 this)); |
| 215 | 223 |
| 216 return RespondLater(); | 224 return RespondLater(); |
| 217 } | 225 } |
| 218 | 226 |
| 219 VpnProviderSetParametersFunction::~VpnProviderSetParametersFunction() { | 227 VpnProviderSetParametersFunction::~VpnProviderSetParametersFunction() { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 SignalCallCompletionSuccess, | 309 SignalCallCompletionSuccess, |
| 302 this), | 310 this), |
| 303 base::Bind(&VpnProviderNotifyConnectionStateChangedFunction:: | 311 base::Bind(&VpnProviderNotifyConnectionStateChangedFunction:: |
| 304 SignalCallCompletionFailure, | 312 SignalCallCompletionFailure, |
| 305 this)); | 313 this)); |
| 306 | 314 |
| 307 return RespondLater(); | 315 return RespondLater(); |
| 308 } | 316 } |
| 309 | 317 |
| 310 } // namespace extensions | 318 } // namespace extensions |
| OLD | NEW |