| 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_service.h" | 5 #include "extensions/browser/api/vpn_provider/vpn_service.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 335 const SuccessCallback& success, | 335 const SuccessCallback& success, |
| 336 const FailureCallback& failure) { | 336 const FailureCallback& failure) { |
| 337 const std::string key = GetKey(extension_id, configuration_name); | 337 const std::string key = GetKey(extension_id, configuration_name); |
| 338 if (!ContainsKey(key_to_configuration_map_, key)) { | 338 if (!ContainsKey(key_to_configuration_map_, key)) { |
| 339 failure.Run(std::string(), std::string("Unauthorized access.")); | 339 failure.Run(std::string(), std::string("Unauthorized access.")); |
| 340 return; | 340 return; |
| 341 } | 341 } |
| 342 | 342 |
| 343 VpnConfiguration* configuration = key_to_configuration_map_[key]; | 343 VpnConfiguration* configuration = key_to_configuration_map_[key]; |
| 344 const std::string service_path = configuration->service_path(); | 344 const std::string service_path = configuration->service_path(); |
| 345 if (active_configuration_ == configuration) { |
| 346 configuration->OnPlatformMessage(api_vpn::PLATFORM_MESSAGE_DISCONNECTED); |
| 347 } |
| 345 DestroyConfigurationInternal(configuration); | 348 DestroyConfigurationInternal(configuration); |
| 346 | 349 |
| 347 network_configuration_handler_->RemoveConfiguration( | 350 network_configuration_handler_->RemoveConfiguration( |
| 348 service_path, NetworkConfigurationObserver::SOURCE_EXTENSION_INSTALL, | 351 service_path, NetworkConfigurationObserver::SOURCE_EXTENSION_INSTALL, |
| 349 base::Bind(&VpnService::OnRemoveConfigurationSuccess, | 352 base::Bind(&VpnService::OnRemoveConfigurationSuccess, |
| 350 weak_factory_.GetWeakPtr(), success), | 353 weak_factory_.GetWeakPtr(), success), |
| 351 base::Bind(&VpnService::OnRemoveConfigurationFailure, | 354 base::Bind(&VpnService::OnRemoveConfigurationFailure, |
| 352 weak_factory_.GetWeakPtr(), failure)); | 355 weak_factory_.GetWeakPtr(), failure)); |
| 353 } | 356 } |
| 354 | 357 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 } | 417 } |
| 415 | 418 |
| 416 for (auto& iter : to_be_destroyed) { | 419 for (auto& iter : to_be_destroyed) { |
| 417 DestroyConfiguration(extension->id(), // Extension ID | 420 DestroyConfiguration(extension->id(), // Extension ID |
| 418 iter->configuration_name(), // Configuration name | 421 iter->configuration_name(), // Configuration name |
| 419 base::Bind(base::DoNothing), | 422 base::Bind(base::DoNothing), |
| 420 base::Bind(DoNothingFailureCallback)); | 423 base::Bind(DoNothingFailureCallback)); |
| 421 } | 424 } |
| 422 } | 425 } |
| 423 | 426 |
| 427 void VpnService::OnExtensionUnloaded( |
| 428 content::BrowserContext* browser_context, |
| 429 const extensions::Extension* extension, |
| 430 extensions::UnloadedExtensionInfo::Reason reason) { |
| 431 if (browser_context != browser_context_) { |
| 432 NOTREACHED(); |
| 433 return; |
| 434 } |
| 435 |
| 436 if (active_configuration_ && |
| 437 active_configuration_->extension_id() == extension->id()) { |
| 438 shill_client_->UpdateConnectionState( |
| 439 active_configuration_->object_path(), |
| 440 static_cast<uint32_t>(api_vpn::VPN_CONNECTION_STATE_FAILURE), |
| 441 base::Bind(base::DoNothing), base::Bind(DoNothingFailureCallback)); |
| 442 } |
| 443 } |
| 444 |
| 424 void VpnService::OnCreateConfigurationSuccess( | 445 void VpnService::OnCreateConfigurationSuccess( |
| 425 const VpnService::SuccessCallback& callback, | 446 const VpnService::SuccessCallback& callback, |
| 426 VpnConfiguration* configuration, | 447 VpnConfiguration* configuration, |
| 427 const std::string& service_path) { | 448 const std::string& service_path) { |
| 428 configuration->set_service_path(service_path); | 449 configuration->set_service_path(service_path); |
| 429 service_path_to_configuration_map_[service_path] = configuration; | 450 service_path_to_configuration_map_[service_path] = configuration; |
| 430 shill_client_->AddShillThirdPartyVpnObserver(configuration->object_path(), | 451 shill_client_->AddShillThirdPartyVpnObserver(configuration->object_path(), |
| 431 configuration); | 452 configuration); |
| 432 callback.Run(); | 453 callback.Run(); |
| 433 } | 454 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 delete configuration; | 512 delete configuration; |
| 492 } | 513 } |
| 493 | 514 |
| 494 bool VpnService::DoesActiveConfigurationExistAndIsAccessAuthorized( | 515 bool VpnService::DoesActiveConfigurationExistAndIsAccessAuthorized( |
| 495 const std::string& extension_id) { | 516 const std::string& extension_id) { |
| 496 return active_configuration_ && | 517 return active_configuration_ && |
| 497 active_configuration_->extension_id() == extension_id; | 518 active_configuration_->extension_id() == extension_id; |
| 498 } | 519 } |
| 499 | 520 |
| 500 } // namespace chromeos | 521 } // namespace chromeos |
| OLD | NEW |