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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 } | 93 } |
94 | 94 |
95 void VpnService::VpnConfiguration::OnPacketReceived( | 95 void VpnService::VpnConfiguration::OnPacketReceived( |
96 const std::vector<char>& data) { | 96 const std::vector<char>& data) { |
97 if (!vpn_service_) { | 97 if (!vpn_service_) { |
98 return; | 98 return; |
99 } | 99 } |
100 scoped_ptr<base::ListValue> event_args = | 100 scoped_ptr<base::ListValue> event_args = |
101 api_vpn::OnPacketReceived::Create(data); | 101 api_vpn::OnPacketReceived::Create(data); |
102 vpn_service_->SendSignalToExtension( | 102 vpn_service_->SendSignalToExtension( |
103 extension_id_, api_vpn::OnPacketReceived::kEventName, event_args.Pass()); | 103 extension_id_, extensions::events::VPN_PROVIDER_ON_PACKET_RECEIVED, |
| 104 api_vpn::OnPacketReceived::kEventName, event_args.Pass()); |
104 } | 105 } |
105 | 106 |
106 void VpnService::VpnConfiguration::OnPlatformMessage(uint32_t message) { | 107 void VpnService::VpnConfiguration::OnPlatformMessage(uint32_t message) { |
107 if (!vpn_service_) { | 108 if (!vpn_service_) { |
108 return; | 109 return; |
109 } | 110 } |
110 DCHECK_GE(api_vpn::PLATFORM_MESSAGE_LAST, message); | 111 DCHECK_GE(api_vpn::PLATFORM_MESSAGE_LAST, message); |
111 | 112 |
112 api_vpn::PlatformMessage platform_message = | 113 api_vpn::PlatformMessage platform_message = |
113 static_cast<api_vpn::PlatformMessage>(message); | 114 static_cast<api_vpn::PlatformMessage>(message); |
114 vpn_service_->SetActiveConfiguration( | 115 vpn_service_->SetActiveConfiguration( |
115 platform_message == api_vpn::PLATFORM_MESSAGE_CONNECTED ? this : nullptr); | 116 platform_message == api_vpn::PLATFORM_MESSAGE_CONNECTED ? this : nullptr); |
116 | 117 |
117 // TODO(kaliamoorthi): Update the lower layers to get the error message and | 118 // TODO(kaliamoorthi): Update the lower layers to get the error message and |
118 // pass in the error instead of std::string(). | 119 // pass in the error instead of std::string(). |
119 scoped_ptr<base::ListValue> event_args = api_vpn::OnPlatformMessage::Create( | 120 scoped_ptr<base::ListValue> event_args = api_vpn::OnPlatformMessage::Create( |
120 configuration_name_, platform_message, std::string()); | 121 configuration_name_, platform_message, std::string()); |
121 | 122 |
122 vpn_service_->SendSignalToExtension( | 123 vpn_service_->SendSignalToExtension( |
123 extension_id_, api_vpn::OnPlatformMessage::kEventName, event_args.Pass()); | 124 extension_id_, extensions::events::VPN_PROVIDER_ON_PLATFORM_MESSAGE, |
| 125 api_vpn::OnPlatformMessage::kEventName, event_args.Pass()); |
124 } | 126 } |
125 | 127 |
126 VpnService::VpnService( | 128 VpnService::VpnService( |
127 content::BrowserContext* browser_context, | 129 content::BrowserContext* browser_context, |
128 const std::string& userid_hash, | 130 const std::string& userid_hash, |
129 extensions::ExtensionRegistry* extension_registry, | 131 extensions::ExtensionRegistry* extension_registry, |
130 extensions::EventRouter* event_router, | 132 extensions::EventRouter* event_router, |
131 ShillThirdPartyVpnDriverClient* shill_client, | 133 ShillThirdPartyVpnDriverClient* shill_client, |
132 NetworkConfigurationHandler* network_configuration_handler, | 134 NetworkConfigurationHandler* network_configuration_handler, |
133 NetworkProfileHandler* network_profile_handler, | 135 NetworkProfileHandler* network_profile_handler, |
(...skipping 18 matching lines...) Expand all Loading... |
152 | 154 |
153 VpnService::~VpnService() { | 155 VpnService::~VpnService() { |
154 network_configuration_handler_->RemoveObserver(this); | 156 network_configuration_handler_->RemoveObserver(this); |
155 network_state_handler_->RemoveObserver(this, FROM_HERE); | 157 network_state_handler_->RemoveObserver(this, FROM_HERE); |
156 extension_registry_->RemoveObserver(this); | 158 extension_registry_->RemoveObserver(this); |
157 STLDeleteContainerPairSecondPointers(key_to_configuration_map_.begin(), | 159 STLDeleteContainerPairSecondPointers(key_to_configuration_map_.begin(), |
158 key_to_configuration_map_.end()); | 160 key_to_configuration_map_.end()); |
159 } | 161 } |
160 | 162 |
161 void VpnService::SendShowAddDialogToExtension(const std::string& extension_id) { | 163 void VpnService::SendShowAddDialogToExtension(const std::string& extension_id) { |
162 SendSignalToExtension(extension_id, api_vpn::OnUIEvent::kEventName, | 164 SendSignalToExtension(extension_id, |
| 165 extensions::events::VPN_PROVIDER_ON_UI_EVENT, |
| 166 api_vpn::OnUIEvent::kEventName, |
163 api_vpn::OnUIEvent::Create( | 167 api_vpn::OnUIEvent::Create( |
164 api_vpn::UI_EVENT_SHOWADDDIALOG, std::string())); | 168 api_vpn::UI_EVENT_SHOWADDDIALOG, std::string())); |
165 } | 169 } |
166 | 170 |
167 void VpnService::SendShowConfigureDialogToExtension( | 171 void VpnService::SendShowConfigureDialogToExtension( |
168 const std::string& extension_id, | 172 const std::string& extension_id, |
169 const std::string& configuration_id) { | 173 const std::string& configuration_id) { |
170 SendSignalToExtension( | 174 SendSignalToExtension( |
171 extension_id, api_vpn::OnUIEvent::kEventName, | 175 extension_id, extensions::events::VPN_PROVIDER_ON_UI_EVENT, |
| 176 api_vpn::OnUIEvent::kEventName, |
172 api_vpn::OnUIEvent::Create(api_vpn::UI_EVENT_SHOWCONFIGUREDIALOG, | 177 api_vpn::OnUIEvent::Create(api_vpn::UI_EVENT_SHOWCONFIGUREDIALOG, |
173 configuration_id)); | 178 configuration_id)); |
174 } | 179 } |
175 | 180 |
176 void VpnService::SendPlatformError(const std::string& extension_id, | 181 void VpnService::SendPlatformError(const std::string& extension_id, |
177 const std::string& configuration_id, | 182 const std::string& configuration_id, |
178 const std::string& error_message) { | 183 const std::string& error_message) { |
179 SendSignalToExtension( | 184 SendSignalToExtension( |
180 extension_id, api_vpn::OnPlatformMessage::kEventName, | 185 extension_id, extensions::events::VPN_PROVIDER_ON_PLATFORM_MESSAGE, |
| 186 api_vpn::OnPlatformMessage::kEventName, |
181 api_vpn::OnPlatformMessage::Create( | 187 api_vpn::OnPlatformMessage::Create( |
182 configuration_id, api_vpn::PLATFORM_MESSAGE_ERROR, error_message)); | 188 configuration_id, api_vpn::PLATFORM_MESSAGE_ERROR, error_message)); |
183 } | 189 } |
184 | 190 |
185 std::string VpnService::GetKey(const std::string& extension_id, | 191 std::string VpnService::GetKey(const std::string& extension_id, |
186 const std::string& name) { | 192 const std::string& name) { |
187 const std::string key = crypto::SHA256HashString(extension_id + name); | 193 const std::string key = crypto::SHA256HashString(extension_id + name); |
188 return base::HexEncode(key.data(), key.size()); | 194 return base::HexEncode(key.data(), key.size()); |
189 } | 195 } |
190 | 196 |
(...skipping 17 matching lines...) Expand all Loading... |
208 // Ignore removal of a configuration unknown to VPN service, which means the | 214 // Ignore removal of a configuration unknown to VPN service, which means the |
209 // configuration was created internally by the platform. | 215 // configuration was created internally by the platform. |
210 return; | 216 return; |
211 } | 217 } |
212 | 218 |
213 VpnConfiguration* configuration = | 219 VpnConfiguration* configuration = |
214 service_path_to_configuration_map_[service_path]; | 220 service_path_to_configuration_map_[service_path]; |
215 scoped_ptr<base::ListValue> event_args = | 221 scoped_ptr<base::ListValue> event_args = |
216 api_vpn::OnConfigRemoved::Create(configuration->configuration_name()); | 222 api_vpn::OnConfigRemoved::Create(configuration->configuration_name()); |
217 SendSignalToExtension(configuration->extension_id(), | 223 SendSignalToExtension(configuration->extension_id(), |
| 224 extensions::events::VPN_PROVIDER_ON_CONFIG_REMOVED, |
218 api_vpn::OnConfigRemoved::kEventName, | 225 api_vpn::OnConfigRemoved::kEventName, |
219 event_args.Pass()); | 226 event_args.Pass()); |
220 | 227 |
221 DestroyConfigurationInternal(configuration); | 228 DestroyConfigurationInternal(configuration); |
222 } | 229 } |
223 | 230 |
224 void VpnService::OnPropertiesSet(const std::string& service_path, | 231 void VpnService::OnPropertiesSet(const std::string& service_path, |
225 const std::string& guid, | 232 const std::string& guid, |
226 const base::DictionaryValue& set_properties, | 233 const base::DictionaryValue& set_properties, |
227 Source source) { | 234 Source source) { |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
507 callback.Run(); | 514 callback.Run(); |
508 } | 515 } |
509 | 516 |
510 void VpnService::OnRemoveConfigurationFailure( | 517 void VpnService::OnRemoveConfigurationFailure( |
511 const VpnService::FailureCallback& callback, | 518 const VpnService::FailureCallback& callback, |
512 const std::string& error_name, | 519 const std::string& error_name, |
513 scoped_ptr<base::DictionaryValue> error_data) { | 520 scoped_ptr<base::DictionaryValue> error_data) { |
514 callback.Run(error_name, std::string()); | 521 callback.Run(error_name, std::string()); |
515 } | 522 } |
516 | 523 |
517 void VpnService::SendSignalToExtension(const std::string& extension_id, | 524 void VpnService::SendSignalToExtension( |
518 const std::string& event_name, | 525 const std::string& extension_id, |
519 scoped_ptr<base::ListValue> event_args) { | 526 extensions::events::HistogramValue histogram_value, |
520 scoped_ptr<extensions::Event> event( | 527 const std::string& event_name, |
521 new extensions::Event(extensions::events::UNKNOWN, event_name, | 528 scoped_ptr<base::ListValue> event_args) { |
522 event_args.Pass(), browser_context_)); | 529 scoped_ptr<extensions::Event> event(new extensions::Event( |
| 530 histogram_value, event_name, event_args.Pass(), browser_context_)); |
523 | 531 |
524 event_router_->DispatchEventToExtension(extension_id, event.Pass()); | 532 event_router_->DispatchEventToExtension(extension_id, event.Pass()); |
525 } | 533 } |
526 | 534 |
527 void VpnService::SetActiveConfiguration( | 535 void VpnService::SetActiveConfiguration( |
528 VpnService::VpnConfiguration* configuration) { | 536 VpnService::VpnConfiguration* configuration) { |
529 active_configuration_ = configuration; | 537 active_configuration_ = configuration; |
530 } | 538 } |
531 | 539 |
532 VpnService::VpnConfiguration* VpnService::CreateConfigurationInternal( | 540 VpnService::VpnConfiguration* VpnService::CreateConfigurationInternal( |
(...skipping 20 matching lines...) Expand all Loading... |
553 delete configuration; | 561 delete configuration; |
554 } | 562 } |
555 | 563 |
556 bool VpnService::DoesActiveConfigurationExistAndIsAccessAuthorized( | 564 bool VpnService::DoesActiveConfigurationExistAndIsAccessAuthorized( |
557 const std::string& extension_id) { | 565 const std::string& extension_id) { |
558 return active_configuration_ && | 566 return active_configuration_ && |
559 active_configuration_->extension_id() == extension_id; | 567 active_configuration_->extension_id() == extension_id; |
560 } | 568 } |
561 | 569 |
562 } // namespace chromeos | 570 } // namespace chromeos |
OLD | NEW |