Chromium Code Reviews| 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" |
| 11 #include "base/bind_helpers.h" | 11 #include "base/bind_helpers.h" |
| 12 #include "base/guid.h" | 12 #include "base/guid.h" |
| 13 #include "base/location.h" | 13 #include "base/location.h" |
| 14 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
| 17 #include "base/strings/string_util.h" | 17 #include "base/strings/string_util.h" |
| 18 #include "base/values.h" | 18 #include "base/values.h" |
| 19 #include "chromeos/dbus/shill_third_party_vpn_driver_client.h" | 19 #include "chromeos/dbus/shill_third_party_vpn_driver_client.h" |
| 20 #include "chromeos/dbus/shill_third_party_vpn_observer.h" | 20 #include "chromeos/dbus/shill_third_party_vpn_observer.h" |
| 21 #include "chromeos/network/network_configuration_handler.h" | 21 #include "chromeos/network/network_configuration_handler.h" |
| 22 #include "chromeos/network/network_profile.h" | 22 #include "chromeos/network/network_profile.h" |
| 23 #include "chromeos/network/network_profile_handler.h" | 23 #include "chromeos/network/network_profile_handler.h" |
| 24 #include "chromeos/network/network_state.h" | 24 #include "chromeos/network/network_state.h" |
| 25 #include "chromeos/network/network_state_handler.h" | 25 #include "chromeos/network/network_state_handler.h" |
| 26 #include "chromeos/network/network_type_pattern.h" | 26 #include "chromeos/network/network_type_pattern.h" |
| 27 #include "crypto/sha2.h" | 27 #include "crypto/sha2.h" |
| 28 #include "extensions/browser/app_window/app_window.h" | |
|
bartfab (slow)
2015/03/10 13:28:40
Nit: No longer needed.
| |
| 28 #include "extensions/browser/event_router.h" | 29 #include "extensions/browser/event_router.h" |
| 29 #include "extensions/browser/extension_registry.h" | 30 #include "extensions/browser/extension_registry.h" |
| 30 #include "third_party/cros_system_api/dbus/service_constants.h" | 31 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 31 | 32 |
| 32 namespace chromeos { | 33 namespace chromeos { |
| 33 | 34 |
| 34 namespace { | 35 namespace { |
| 35 | 36 |
| 36 namespace api_vpn = extensions::core_api::vpn_provider; | 37 namespace api_vpn = extensions::core_api::vpn_provider; |
| 37 | 38 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 130 scoped_ptr<base::ListValue> event_args = api_vpn::OnPlatformMessage::Create( | 131 scoped_ptr<base::ListValue> event_args = api_vpn::OnPlatformMessage::Create( |
| 131 configuration_name_, platform_message, std::string()); | 132 configuration_name_, platform_message, std::string()); |
| 132 | 133 |
| 133 vpn_service_->SendSignalToExtension( | 134 vpn_service_->SendSignalToExtension( |
| 134 extension_id_, api_vpn::OnPlatformMessage::kEventName, event_args.Pass()); | 135 extension_id_, api_vpn::OnPlatformMessage::kEventName, event_args.Pass()); |
| 135 } | 136 } |
| 136 | 137 |
| 137 VpnService::VpnService( | 138 VpnService::VpnService( |
| 138 content::BrowserContext* browser_context, | 139 content::BrowserContext* browser_context, |
| 139 const std::string& userid_hash, | 140 const std::string& userid_hash, |
| 141 extensions::AppWindowRegistry* app_window_registry, | |
|
bartfab (slow)
2015/03/10 13:28:40
Nit: No longer needed.
| |
| 140 extensions::ExtensionRegistry* extension_registry, | 142 extensions::ExtensionRegistry* extension_registry, |
| 141 extensions::EventRouter* event_router, | 143 extensions::EventRouter* event_router, |
| 142 ShillThirdPartyVpnDriverClient* shill_client, | 144 ShillThirdPartyVpnDriverClient* shill_client, |
| 143 NetworkConfigurationHandler* network_configuration_handler, | 145 NetworkConfigurationHandler* network_configuration_handler, |
| 144 NetworkProfileHandler* network_profile_handler, | 146 NetworkProfileHandler* network_profile_handler, |
| 145 NetworkStateHandler* network_state_handler) | 147 NetworkStateHandler* network_state_handler) |
| 146 : browser_context_(browser_context), | 148 : browser_context_(browser_context), |
| 147 userid_hash_(userid_hash), | 149 userid_hash_(userid_hash), |
| 150 app_window_registry_(app_window_registry), | |
|
bartfab (slow)
2015/03/10 13:28:40
Nit: No longer needed.
| |
| 148 extension_registry_(extension_registry), | 151 extension_registry_(extension_registry), |
| 149 event_router_(event_router), | 152 event_router_(event_router), |
| 150 shill_client_(shill_client), | 153 shill_client_(shill_client), |
| 151 network_configuration_handler_(network_configuration_handler), | 154 network_configuration_handler_(network_configuration_handler), |
| 152 network_profile_handler_(network_profile_handler), | 155 network_profile_handler_(network_profile_handler), |
| 153 network_state_handler_(network_state_handler), | 156 network_state_handler_(network_state_handler), |
| 154 active_configuration_(nullptr), | 157 active_configuration_(nullptr), |
| 155 weak_factory_(this) { | 158 weak_factory_(this) { |
| 159 app_window_registry_->AddObserver(this); | |
|
bartfab (slow)
2015/03/10 13:28:40
Nit: No longer needed.
| |
| 156 extension_registry_->AddObserver(this); | 160 extension_registry_->AddObserver(this); |
| 157 network_state_handler_->AddObserver(this, FROM_HERE); | 161 network_state_handler_->AddObserver(this, FROM_HERE); |
| 158 network_configuration_handler_->AddObserver(this); | 162 network_configuration_handler_->AddObserver(this); |
| 159 } | 163 } |
| 160 | 164 |
| 161 VpnService::~VpnService() { | 165 VpnService::~VpnService() { |
| 162 network_configuration_handler_->RemoveObserver(this); | 166 network_configuration_handler_->RemoveObserver(this); |
| 163 network_state_handler_->RemoveObserver(this, FROM_HERE); | 167 network_state_handler_->RemoveObserver(this, FROM_HERE); |
| 164 extension_registry_->RemoveObserver(this); | 168 extension_registry_->RemoveObserver(this); |
| 169 app_window_registry_->RemoveObserver(this); | |
|
bartfab (slow)
2015/03/10 13:28:40
Nit: No longer needed.
| |
| 165 STLDeleteContainerPairSecondPointers(key_to_configuration_map_.begin(), | 170 STLDeleteContainerPairSecondPointers(key_to_configuration_map_.begin(), |
| 166 key_to_configuration_map_.end()); | 171 key_to_configuration_map_.end()); |
| 167 } | 172 } |
| 168 | 173 |
| 169 void VpnService::OnConfigurationCreated(const std::string& service_path, | 174 void VpnService::OnConfigurationCreated(const std::string& service_path, |
| 170 const std::string& profile_path, | 175 const std::string& profile_path, |
| 171 const base::DictionaryValue& properties, | 176 const base::DictionaryValue& properties, |
| 172 Source source) { | 177 Source source) { |
| 173 } | 178 } |
| 174 | 179 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 const SuccessCallback& success, | 340 const SuccessCallback& success, |
| 336 const FailureCallback& failure) { | 341 const FailureCallback& failure) { |
| 337 const std::string key = GetKey(extension_id, configuration_name); | 342 const std::string key = GetKey(extension_id, configuration_name); |
| 338 if (!ContainsKey(key_to_configuration_map_, key)) { | 343 if (!ContainsKey(key_to_configuration_map_, key)) { |
| 339 failure.Run(std::string(), std::string("Unauthorized access.")); | 344 failure.Run(std::string(), std::string("Unauthorized access.")); |
| 340 return; | 345 return; |
| 341 } | 346 } |
| 342 | 347 |
| 343 VpnConfiguration* configuration = key_to_configuration_map_[key]; | 348 VpnConfiguration* configuration = key_to_configuration_map_[key]; |
| 344 const std::string service_path = configuration->service_path(); | 349 const std::string service_path = configuration->service_path(); |
| 350 if (active_configuration_ == configuration) { | |
| 351 configuration->OnPlatformMessage(api_vpn::PLATFORM_MESSAGE_DISCONNECTED); | |
| 352 } | |
| 345 DestroyConfigurationInternal(configuration); | 353 DestroyConfigurationInternal(configuration); |
| 346 | 354 |
| 347 network_configuration_handler_->RemoveConfiguration( | 355 network_configuration_handler_->RemoveConfiguration( |
| 348 service_path, NetworkConfigurationObserver::SOURCE_EXTENSION_INSTALL, | 356 service_path, NetworkConfigurationObserver::SOURCE_EXTENSION_INSTALL, |
| 349 base::Bind(&VpnService::OnRemoveConfigurationSuccess, | 357 base::Bind(&VpnService::OnRemoveConfigurationSuccess, |
| 350 weak_factory_.GetWeakPtr(), success), | 358 weak_factory_.GetWeakPtr(), success), |
| 351 base::Bind(&VpnService::OnRemoveConfigurationFailure, | 359 base::Bind(&VpnService::OnRemoveConfigurationFailure, |
| 352 weak_factory_.GetWeakPtr(), failure)); | 360 weak_factory_.GetWeakPtr(), failure)); |
| 353 } | 361 } |
| 354 | 362 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 414 } | 422 } |
| 415 | 423 |
| 416 for (auto& iter : to_be_destroyed) { | 424 for (auto& iter : to_be_destroyed) { |
| 417 DestroyConfiguration(extension->id(), // Extension ID | 425 DestroyConfiguration(extension->id(), // Extension ID |
| 418 iter->configuration_name(), // Configuration name | 426 iter->configuration_name(), // Configuration name |
| 419 base::Bind(base::DoNothing), | 427 base::Bind(base::DoNothing), |
| 420 base::Bind(DoNothingFailureCallback)); | 428 base::Bind(DoNothingFailureCallback)); |
| 421 } | 429 } |
| 422 } | 430 } |
| 423 | 431 |
| 432 void VpnService::OnExtensionUnloaded( | |
| 433 content::BrowserContext* browser_context, | |
| 434 const extensions::Extension* extension, | |
| 435 extensions::UnloadedExtensionInfo::Reason reason) { | |
| 436 if (browser_context != browser_context_) { | |
| 437 NOTREACHED(); | |
| 438 return; | |
| 439 } | |
| 440 | |
| 441 if (active_configuration_ && | |
| 442 active_configuration_->extension_id() == extension->id()) { | |
| 443 shill_client_->UpdateConnectionState( | |
| 444 active_configuration_->object_path(), | |
| 445 static_cast<uint32_t>(api_vpn::VPN_CONNECTION_STATE_FAILURE), | |
| 446 base::Bind(base::DoNothing), base::Bind(DoNothingFailureCallback)); | |
| 447 } | |
| 448 } | |
| 449 | |
| 450 void VpnService::OnAppWindowRemoved(extensions::AppWindow* app_window) { | |
|
bartfab (slow)
2015/03/10 13:28:40
Nit: As discussed offline, we do not need this.
| |
| 451 if (active_configuration_ && | |
| 452 active_configuration_->extension_id() == app_window->extension_id()) { | |
| 453 shill_client_->UpdateConnectionState( | |
| 454 active_configuration_->object_path(), | |
| 455 static_cast<uint32_t>(api_vpn::VPN_CONNECTION_STATE_FAILURE), | |
| 456 base::Bind(base::DoNothing), base::Bind(DoNothingFailureCallback)); | |
| 457 } | |
| 458 } | |
| 459 | |
| 424 void VpnService::OnCreateConfigurationSuccess( | 460 void VpnService::OnCreateConfigurationSuccess( |
| 425 const VpnService::SuccessCallback& callback, | 461 const VpnService::SuccessCallback& callback, |
| 426 VpnConfiguration* configuration, | 462 VpnConfiguration* configuration, |
| 427 const std::string& service_path) { | 463 const std::string& service_path) { |
| 428 configuration->set_service_path(service_path); | 464 configuration->set_service_path(service_path); |
| 429 service_path_to_configuration_map_[service_path] = configuration; | 465 service_path_to_configuration_map_[service_path] = configuration; |
| 430 shill_client_->AddShillThirdPartyVpnObserver(configuration->object_path(), | 466 shill_client_->AddShillThirdPartyVpnObserver(configuration->object_path(), |
| 431 configuration); | 467 configuration); |
| 432 callback.Run(); | 468 callback.Run(); |
| 433 } | 469 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 491 delete configuration; | 527 delete configuration; |
| 492 } | 528 } |
| 493 | 529 |
| 494 bool VpnService::DoesActiveConfigurationExistAndIsAccessAuthorized( | 530 bool VpnService::DoesActiveConfigurationExistAndIsAccessAuthorized( |
| 495 const std::string& extension_id) { | 531 const std::string& extension_id) { |
| 496 return active_configuration_ && | 532 return active_configuration_ && |
| 497 active_configuration_->extension_id() == extension_id; | 533 active_configuration_->extension_id() == extension_id; |
| 498 } | 534 } |
| 499 | 535 |
| 500 } // namespace chromeos | 536 } // namespace chromeos |
| OLD | NEW |