| 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 <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/bind.h" | 11 #include "base/bind.h" |
| 12 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 13 #include "base/guid.h" | 13 #include "base/guid.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "base/macros.h" | 16 #include "base/macros.h" |
| 17 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 19 #include "base/stl_util.h" | |
| 20 #include "base/strings/string_number_conversions.h" | 19 #include "base/strings/string_number_conversions.h" |
| 21 #include "base/strings/string_util.h" | 20 #include "base/strings/string_util.h" |
| 22 #include "base/threading/thread_task_runner_handle.h" | 21 #include "base/threading/thread_task_runner_handle.h" |
| 23 #include "base/values.h" | 22 #include "base/values.h" |
| 24 #include "chromeos/dbus/shill_third_party_vpn_driver_client.h" | 23 #include "chromeos/dbus/shill_third_party_vpn_driver_client.h" |
| 25 #include "chromeos/dbus/shill_third_party_vpn_observer.h" | 24 #include "chromeos/dbus/shill_third_party_vpn_observer.h" |
| 26 #include "chromeos/network/network_configuration_handler.h" | 25 #include "chromeos/network/network_configuration_handler.h" |
| 27 #include "chromeos/network/network_profile.h" | 26 #include "chromeos/network/network_profile.h" |
| 28 #include "chromeos/network/network_profile_handler.h" | 27 #include "chromeos/network/network_profile_handler.h" |
| 29 #include "chromeos/network/network_state.h" | 28 #include "chromeos/network/network_state.h" |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 network_configuration_handler_->AddObserver(this); | 235 network_configuration_handler_->AddObserver(this); |
| 237 base::ThreadTaskRunnerHandle::Get()->PostTask( | 236 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 238 FROM_HERE, | 237 FROM_HERE, |
| 239 base::Bind(&VpnService::NetworkListChanged, weak_factory_.GetWeakPtr())); | 238 base::Bind(&VpnService::NetworkListChanged, weak_factory_.GetWeakPtr())); |
| 240 } | 239 } |
| 241 | 240 |
| 242 VpnService::~VpnService() { | 241 VpnService::~VpnService() { |
| 243 network_configuration_handler_->RemoveObserver(this); | 242 network_configuration_handler_->RemoveObserver(this); |
| 244 network_state_handler_->RemoveObserver(this, FROM_HERE); | 243 network_state_handler_->RemoveObserver(this, FROM_HERE); |
| 245 extension_registry_->RemoveObserver(this); | 244 extension_registry_->RemoveObserver(this); |
| 246 base::STLDeleteContainerPairSecondPointers(key_to_configuration_map_.begin(), | |
| 247 key_to_configuration_map_.end()); | |
| 248 } | 245 } |
| 249 | 246 |
| 250 void VpnService::SendShowAddDialogToExtension(const std::string& extension_id) { | 247 void VpnService::SendShowAddDialogToExtension(const std::string& extension_id) { |
| 251 SendSignalToExtension(extension_id, | 248 SendSignalToExtension(extension_id, |
| 252 extensions::events::VPN_PROVIDER_ON_UI_EVENT, | 249 extensions::events::VPN_PROVIDER_ON_UI_EVENT, |
| 253 api_vpn::OnUIEvent::kEventName, | 250 api_vpn::OnUIEvent::kEventName, |
| 254 api_vpn::OnUIEvent::Create( | 251 api_vpn::OnUIEvent::Create( |
| 255 api_vpn::UI_EVENT_SHOWADDDIALOG, std::string())); | 252 api_vpn::UI_EVENT_SHOWADDDIALOG, std::string())); |
| 256 } | 253 } |
| 257 | 254 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 const std::string& configuration_id, | 438 const std::string& configuration_id, |
| 442 const SuccessCallback& success, | 439 const SuccessCallback& success, |
| 443 const FailureCallback& failure) { | 440 const FailureCallback& failure) { |
| 444 // The ID is the configuration name for now. This may change in the future. | 441 // The ID is the configuration name for now. This may change in the future. |
| 445 const std::string key = GetKey(extension_id, configuration_id); | 442 const std::string key = GetKey(extension_id, configuration_id); |
| 446 if (!base::ContainsKey(key_to_configuration_map_, key)) { | 443 if (!base::ContainsKey(key_to_configuration_map_, key)) { |
| 447 failure.Run(std::string(), std::string("Unauthorized access.")); | 444 failure.Run(std::string(), std::string("Unauthorized access.")); |
| 448 return; | 445 return; |
| 449 } | 446 } |
| 450 | 447 |
| 451 VpnConfiguration* configuration = key_to_configuration_map_[key]; | 448 VpnConfiguration* configuration = key_to_configuration_map_[key].get(); |
| 452 const std::string service_path = configuration->service_path(); | 449 const std::string service_path = configuration->service_path(); |
| 453 if (service_path.empty()) { | 450 if (service_path.empty()) { |
| 454 failure.Run(std::string(), std::string("Pending create.")); | 451 failure.Run(std::string(), std::string("Pending create.")); |
| 455 return; | 452 return; |
| 456 } | 453 } |
| 457 if (active_configuration_ == configuration) { | 454 if (active_configuration_ == configuration) { |
| 458 configuration->OnPlatformMessage(api_vpn::PLATFORM_MESSAGE_DISCONNECTED); | 455 configuration->OnPlatformMessage(api_vpn::PLATFORM_MESSAGE_DISCONNECTED); |
| 459 } | 456 } |
| 460 DestroyConfigurationInternal(configuration); | 457 DestroyConfigurationInternal(configuration); |
| 461 | 458 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 bool VpnService::VerifyConfigIsConnectedForTesting( | 519 bool VpnService::VerifyConfigIsConnectedForTesting( |
| 523 const std::string& extension_id) { | 520 const std::string& extension_id) { |
| 524 return DoesActiveConfigurationExistAndIsAccessAuthorized(extension_id); | 521 return DoesActiveConfigurationExistAndIsAccessAuthorized(extension_id); |
| 525 } | 522 } |
| 526 | 523 |
| 527 void VpnService::DestroyConfigurationsForExtension( | 524 void VpnService::DestroyConfigurationsForExtension( |
| 528 const extensions::Extension* extension) { | 525 const extensions::Extension* extension) { |
| 529 std::vector<VpnConfiguration*> to_be_destroyed; | 526 std::vector<VpnConfiguration*> to_be_destroyed; |
| 530 for (const auto& iter : key_to_configuration_map_) { | 527 for (const auto& iter : key_to_configuration_map_) { |
| 531 if (iter.second->extension_id() == extension->id()) { | 528 if (iter.second->extension_id() == extension->id()) { |
| 532 to_be_destroyed.push_back(iter.second); | 529 to_be_destroyed.push_back(iter.second.get()); |
| 533 } | 530 } |
| 534 } | 531 } |
| 535 | 532 |
| 536 for (auto* iter : to_be_destroyed) { | 533 for (auto* iter : to_be_destroyed) { |
| 537 DestroyConfiguration(extension->id(), // Extension ID | 534 DestroyConfiguration(extension->id(), // Extension ID |
| 538 iter->configuration_name(), // Configuration name | 535 iter->configuration_name(), // Configuration name |
| 539 base::Bind(base::DoNothing), | 536 base::Bind(base::DoNothing), |
| 540 base::Bind(DoNothingFailureCallback)); | 537 base::Bind(DoNothingFailureCallback)); |
| 541 } | 538 } |
| 542 } | 539 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 623 VpnService::VpnConfiguration* configuration) { | 620 VpnService::VpnConfiguration* configuration) { |
| 624 active_configuration_ = configuration; | 621 active_configuration_ = configuration; |
| 625 } | 622 } |
| 626 | 623 |
| 627 VpnService::VpnConfiguration* VpnService::CreateConfigurationInternal( | 624 VpnService::VpnConfiguration* VpnService::CreateConfigurationInternal( |
| 628 const std::string& extension_id, | 625 const std::string& extension_id, |
| 629 const std::string& configuration_name, | 626 const std::string& configuration_name, |
| 630 const std::string& key) { | 627 const std::string& key) { |
| 631 VpnConfiguration* configuration = new VpnConfiguration( | 628 VpnConfiguration* configuration = new VpnConfiguration( |
| 632 extension_id, configuration_name, key, weak_factory_.GetWeakPtr()); | 629 extension_id, configuration_name, key, weak_factory_.GetWeakPtr()); |
| 633 // The object is owned by key_to_configuration_map_ henceforth. | 630 key_to_configuration_map_[key] = base::WrapUnique(configuration); |
| 634 key_to_configuration_map_[key] = configuration; | |
| 635 return configuration; | 631 return configuration; |
| 636 } | 632 } |
| 637 | 633 |
| 638 void VpnService::DestroyConfigurationInternal(VpnConfiguration* configuration) { | 634 void VpnService::DestroyConfigurationInternal(VpnConfiguration* configuration) { |
| 635 std::unique_ptr<VpnConfiguration> configuration_ptr = |
| 636 std::move(key_to_configuration_map_[configuration->key()]); |
| 639 key_to_configuration_map_.erase(configuration->key()); | 637 key_to_configuration_map_.erase(configuration->key()); |
| 640 if (active_configuration_ == configuration) { | 638 if (active_configuration_ == configuration) { |
| 641 active_configuration_ = nullptr; | 639 active_configuration_ = nullptr; |
| 642 } | 640 } |
| 643 if (!configuration->service_path().empty()) { | 641 if (!configuration->service_path().empty()) { |
| 644 shill_client_->RemoveShillThirdPartyVpnObserver( | 642 shill_client_->RemoveShillThirdPartyVpnObserver( |
| 645 configuration->object_path()); | 643 configuration->object_path()); |
| 646 service_path_to_configuration_map_.erase(configuration->service_path()); | 644 service_path_to_configuration_map_.erase(configuration->service_path()); |
| 647 } | 645 } |
| 648 delete configuration; | |
| 649 } | 646 } |
| 650 | 647 |
| 651 bool VpnService::DoesActiveConfigurationExistAndIsAccessAuthorized( | 648 bool VpnService::DoesActiveConfigurationExistAndIsAccessAuthorized( |
| 652 const std::string& extension_id) { | 649 const std::string& extension_id) { |
| 653 return active_configuration_ && | 650 return active_configuration_ && |
| 654 active_configuration_->extension_id() == extension_id; | 651 active_configuration_->extension_id() == extension_id; |
| 655 } | 652 } |
| 656 | 653 |
| 657 void VpnService::Bind( | 654 void VpnService::Bind( |
| 658 const std::string& extension_id, | 655 const std::string& extension_id, |
| 659 const std::string& configuration_id, | 656 const std::string& configuration_id, |
| 660 const std::string& configuration_name, | 657 const std::string& configuration_name, |
| 661 const SuccessCallback& success, | 658 const SuccessCallback& success, |
| 662 const FailureCallback& failure, | 659 const FailureCallback& failure, |
| 663 std::unique_ptr<content::PepperVpnProviderResourceHostProxy> | 660 std::unique_ptr<content::PepperVpnProviderResourceHostProxy> |
| 664 pepper_vpn_provider_proxy) { | 661 pepper_vpn_provider_proxy) { |
| 665 // The ID is the configuration name for now. This may change in the future. | 662 // The ID is the configuration name for now. This may change in the future. |
| 666 const std::string key = GetKey(extension_id, configuration_id); | 663 const std::string key = GetKey(extension_id, configuration_id); |
| 667 if (!base::ContainsKey(key_to_configuration_map_, key)) { | 664 if (!base::ContainsKey(key_to_configuration_map_, key)) { |
| 668 failure.Run(std::string(), | 665 failure.Run(std::string(), |
| 669 std::string("Unauthorized access. " | 666 std::string("Unauthorized access. " |
| 670 "The configuration does not exist.")); | 667 "The configuration does not exist.")); |
| 671 return; | 668 return; |
| 672 } | 669 } |
| 673 | 670 |
| 674 VpnConfiguration* configuration = key_to_configuration_map_[key]; | 671 VpnConfiguration* configuration = key_to_configuration_map_[key].get(); |
| 675 if (active_configuration_ != configuration) { | 672 if (active_configuration_ != configuration) { |
| 676 failure.Run(std::string(), std::string("Unauthorized access. " | 673 failure.Run(std::string(), std::string("Unauthorized access. " |
| 677 "The configuration is not active.")); | 674 "The configuration is not active.")); |
| 678 return; | 675 return; |
| 679 } | 676 } |
| 680 | 677 |
| 681 if (configuration->extension_id() != extension_id || | 678 if (configuration->extension_id() != extension_id || |
| 682 configuration->configuration_name() != configuration_name) { | 679 configuration->configuration_name() != configuration_name) { |
| 683 failure.Run(std::string(), | 680 failure.Run(std::string(), |
| 684 std::string("Unauthorized access. " | 681 std::string("Unauthorized access. " |
| (...skipping 11 matching lines...) Expand all Loading... |
| 696 configuration->set_pepper_proxy(std::move(pepper_vpn_provider_proxy)); | 693 configuration->set_pepper_proxy(std::move(pepper_vpn_provider_proxy)); |
| 697 | 694 |
| 698 success.Run(); | 695 success.Run(); |
| 699 } | 696 } |
| 700 | 697 |
| 701 std::unique_ptr<content::VpnServiceProxy> VpnService::GetVpnServiceProxy() { | 698 std::unique_ptr<content::VpnServiceProxy> VpnService::GetVpnServiceProxy() { |
| 702 return base::WrapUnique(new VpnServiceProxyImpl(weak_factory_.GetWeakPtr())); | 699 return base::WrapUnique(new VpnServiceProxyImpl(weak_factory_.GetWeakPtr())); |
| 703 } | 700 } |
| 704 | 701 |
| 705 } // namespace chromeos | 702 } // namespace chromeos |
| OLD | NEW |