| 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 <vector> | 9 #include <vector> |
| 9 | 10 |
| 10 #include "base/bind.h" | 11 #include "base/bind.h" |
| 11 #include "base/bind_helpers.h" | 12 #include "base/bind_helpers.h" |
| 12 #include "base/guid.h" | 13 #include "base/guid.h" |
| 13 #include "base/location.h" | 14 #include "base/location.h" |
| 14 #include "base/logging.h" | 15 #include "base/logging.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "base/message_loop/message_loop.h" | 17 #include "base/message_loop/message_loop.h" |
| 17 #include "base/stl_util.h" | 18 #include "base/stl_util.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 96 |
| 96 void VpnService::VpnConfiguration::OnPacketReceived( | 97 void VpnService::VpnConfiguration::OnPacketReceived( |
| 97 const std::vector<char>& data) { | 98 const std::vector<char>& data) { |
| 98 if (!vpn_service_) { | 99 if (!vpn_service_) { |
| 99 return; | 100 return; |
| 100 } | 101 } |
| 101 scoped_ptr<base::ListValue> event_args = | 102 scoped_ptr<base::ListValue> event_args = |
| 102 api_vpn::OnPacketReceived::Create(data); | 103 api_vpn::OnPacketReceived::Create(data); |
| 103 vpn_service_->SendSignalToExtension( | 104 vpn_service_->SendSignalToExtension( |
| 104 extension_id_, extensions::events::VPN_PROVIDER_ON_PACKET_RECEIVED, | 105 extension_id_, extensions::events::VPN_PROVIDER_ON_PACKET_RECEIVED, |
| 105 api_vpn::OnPacketReceived::kEventName, event_args.Pass()); | 106 api_vpn::OnPacketReceived::kEventName, std::move(event_args)); |
| 106 } | 107 } |
| 107 | 108 |
| 108 void VpnService::VpnConfiguration::OnPlatformMessage(uint32_t message) { | 109 void VpnService::VpnConfiguration::OnPlatformMessage(uint32_t message) { |
| 109 if (!vpn_service_) { | 110 if (!vpn_service_) { |
| 110 return; | 111 return; |
| 111 } | 112 } |
| 112 DCHECK_GE(api_vpn::PLATFORM_MESSAGE_LAST, message); | 113 DCHECK_GE(api_vpn::PLATFORM_MESSAGE_LAST, message); |
| 113 | 114 |
| 114 api_vpn::PlatformMessage platform_message = | 115 api_vpn::PlatformMessage platform_message = |
| 115 static_cast<api_vpn::PlatformMessage>(message); | 116 static_cast<api_vpn::PlatformMessage>(message); |
| 116 vpn_service_->SetActiveConfiguration( | 117 vpn_service_->SetActiveConfiguration( |
| 117 platform_message == api_vpn::PLATFORM_MESSAGE_CONNECTED ? this : nullptr); | 118 platform_message == api_vpn::PLATFORM_MESSAGE_CONNECTED ? this : nullptr); |
| 118 | 119 |
| 119 // TODO(kaliamoorthi): Update the lower layers to get the error message and | 120 // TODO(kaliamoorthi): Update the lower layers to get the error message and |
| 120 // pass in the error instead of std::string(). | 121 // pass in the error instead of std::string(). |
| 121 scoped_ptr<base::ListValue> event_args = api_vpn::OnPlatformMessage::Create( | 122 scoped_ptr<base::ListValue> event_args = api_vpn::OnPlatformMessage::Create( |
| 122 configuration_name_, platform_message, std::string()); | 123 configuration_name_, platform_message, std::string()); |
| 123 | 124 |
| 124 vpn_service_->SendSignalToExtension( | 125 vpn_service_->SendSignalToExtension( |
| 125 extension_id_, extensions::events::VPN_PROVIDER_ON_PLATFORM_MESSAGE, | 126 extension_id_, extensions::events::VPN_PROVIDER_ON_PLATFORM_MESSAGE, |
| 126 api_vpn::OnPlatformMessage::kEventName, event_args.Pass()); | 127 api_vpn::OnPlatformMessage::kEventName, std::move(event_args)); |
| 127 } | 128 } |
| 128 | 129 |
| 129 VpnService::VpnService( | 130 VpnService::VpnService( |
| 130 content::BrowserContext* browser_context, | 131 content::BrowserContext* browser_context, |
| 131 const std::string& userid_hash, | 132 const std::string& userid_hash, |
| 132 extensions::ExtensionRegistry* extension_registry, | 133 extensions::ExtensionRegistry* extension_registry, |
| 133 extensions::EventRouter* event_router, | 134 extensions::EventRouter* event_router, |
| 134 ShillThirdPartyVpnDriverClient* shill_client, | 135 ShillThirdPartyVpnDriverClient* shill_client, |
| 135 NetworkConfigurationHandler* network_configuration_handler, | 136 NetworkConfigurationHandler* network_configuration_handler, |
| 136 NetworkProfileHandler* network_profile_handler, | 137 NetworkProfileHandler* network_profile_handler, |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 return; | 218 return; |
| 218 } | 219 } |
| 219 | 220 |
| 220 VpnConfiguration* configuration = | 221 VpnConfiguration* configuration = |
| 221 service_path_to_configuration_map_[service_path]; | 222 service_path_to_configuration_map_[service_path]; |
| 222 scoped_ptr<base::ListValue> event_args = | 223 scoped_ptr<base::ListValue> event_args = |
| 223 api_vpn::OnConfigRemoved::Create(configuration->configuration_name()); | 224 api_vpn::OnConfigRemoved::Create(configuration->configuration_name()); |
| 224 SendSignalToExtension(configuration->extension_id(), | 225 SendSignalToExtension(configuration->extension_id(), |
| 225 extensions::events::VPN_PROVIDER_ON_CONFIG_REMOVED, | 226 extensions::events::VPN_PROVIDER_ON_CONFIG_REMOVED, |
| 226 api_vpn::OnConfigRemoved::kEventName, | 227 api_vpn::OnConfigRemoved::kEventName, |
| 227 event_args.Pass()); | 228 std::move(event_args)); |
| 228 | 229 |
| 229 DestroyConfigurationInternal(configuration); | 230 DestroyConfigurationInternal(configuration); |
| 230 } | 231 } |
| 231 | 232 |
| 232 void VpnService::OnPropertiesSet(const std::string& service_path, | 233 void VpnService::OnPropertiesSet(const std::string& service_path, |
| 233 const std::string& guid, | 234 const std::string& guid, |
| 234 const base::DictionaryValue& set_properties, | 235 const base::DictionaryValue& set_properties, |
| 235 Source source) { | 236 Source source) { |
| 236 } | 237 } |
| 237 | 238 |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 scoped_ptr<base::DictionaryValue> error_data) { | 522 scoped_ptr<base::DictionaryValue> error_data) { |
| 522 callback.Run(error_name, std::string()); | 523 callback.Run(error_name, std::string()); |
| 523 } | 524 } |
| 524 | 525 |
| 525 void VpnService::SendSignalToExtension( | 526 void VpnService::SendSignalToExtension( |
| 526 const std::string& extension_id, | 527 const std::string& extension_id, |
| 527 extensions::events::HistogramValue histogram_value, | 528 extensions::events::HistogramValue histogram_value, |
| 528 const std::string& event_name, | 529 const std::string& event_name, |
| 529 scoped_ptr<base::ListValue> event_args) { | 530 scoped_ptr<base::ListValue> event_args) { |
| 530 scoped_ptr<extensions::Event> event(new extensions::Event( | 531 scoped_ptr<extensions::Event> event(new extensions::Event( |
| 531 histogram_value, event_name, event_args.Pass(), browser_context_)); | 532 histogram_value, event_name, std::move(event_args), browser_context_)); |
| 532 | 533 |
| 533 event_router_->DispatchEventToExtension(extension_id, event.Pass()); | 534 event_router_->DispatchEventToExtension(extension_id, std::move(event)); |
| 534 } | 535 } |
| 535 | 536 |
| 536 void VpnService::SetActiveConfiguration( | 537 void VpnService::SetActiveConfiguration( |
| 537 VpnService::VpnConfiguration* configuration) { | 538 VpnService::VpnConfiguration* configuration) { |
| 538 active_configuration_ = configuration; | 539 active_configuration_ = configuration; |
| 539 } | 540 } |
| 540 | 541 |
| 541 VpnService::VpnConfiguration* VpnService::CreateConfigurationInternal( | 542 VpnService::VpnConfiguration* VpnService::CreateConfigurationInternal( |
| 542 const std::string& extension_id, | 543 const std::string& extension_id, |
| 543 const std::string& configuration_name, | 544 const std::string& configuration_name, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 562 delete configuration; | 563 delete configuration; |
| 563 } | 564 } |
| 564 | 565 |
| 565 bool VpnService::DoesActiveConfigurationExistAndIsAccessAuthorized( | 566 bool VpnService::DoesActiveConfigurationExistAndIsAccessAuthorized( |
| 566 const std::string& extension_id) { | 567 const std::string& extension_id) { |
| 567 return active_configuration_ && | 568 return active_configuration_ && |
| 568 active_configuration_->extension_id() == extension_id; | 569 active_configuration_->extension_id() == extension_id; |
| 569 } | 570 } |
| 570 | 571 |
| 571 } // namespace chromeos | 572 } // namespace chromeos |
| OLD | NEW |