Commit b92b69ac authored by kaliamoorthi's avatar kaliamoorthi Committed by Commit bot

Destroy configurations created by VPN extension on disable

The CL destroys VPN configurations created by an extension when
the extension is disabled.

BUG=468477

Review URL: https://codereview.chromium.org/1028213002

Cr-Commit-Position: refs/heads/master@{#321984}
parent 6c6edea6
...@@ -418,4 +418,55 @@ IN_PROC_BROWSER_TEST_F(VpnProviderApiTest, CreateUninstall) { ...@@ -418,4 +418,55 @@ IN_PROC_BROWSER_TEST_F(VpnProviderApiTest, CreateUninstall) {
->GetService(service_path, &profile_path, &properties)); ->GetService(service_path, &profile_path, &properties));
} }
IN_PROC_BROWSER_TEST_F(VpnProviderApiTest, CreateDisable) {
LoadVpnExtension();
AddNetworkProfileForUser();
EXPECT_TRUE(RunExtensionTest("createConfigSuccess"));
EXPECT_TRUE(DoesConfigExist(kTestConfig));
const std::string service_path = GetSingleServicePath();
std::string profile_path;
base::DictionaryValue properties;
EXPECT_TRUE(DBusThreadManager::Get()
->GetShillProfileClient()
->GetTestInterface()
->GetService(service_path, &profile_path, &properties));
ExtensionService* extension_service =
extensions::ExtensionSystem::Get(profile())->extension_service();
extension_service->DisableExtension(extension_id_,
extensions::Extension::DISABLE_NONE);
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(DoesConfigExist(kTestConfig));
EXPECT_FALSE(DBusThreadManager::Get()
->GetShillProfileClient()
->GetTestInterface()
->GetService(service_path, &profile_path, &properties));
}
IN_PROC_BROWSER_TEST_F(VpnProviderApiTest, CreateBlacklist) {
LoadVpnExtension();
AddNetworkProfileForUser();
EXPECT_TRUE(RunExtensionTest("createConfigSuccess"));
EXPECT_TRUE(DoesConfigExist(kTestConfig));
const std::string service_path = GetSingleServicePath();
std::string profile_path;
base::DictionaryValue properties;
EXPECT_TRUE(DBusThreadManager::Get()
->GetShillProfileClient()
->GetTestInterface()
->GetService(service_path, &profile_path, &properties));
ExtensionService* extension_service =
extensions::ExtensionSystem::Get(profile())->extension_service();
extension_service->BlacklistExtensionForTest(extension_id_);
content::RunAllPendingInMessageLoop();
EXPECT_FALSE(DoesConfigExist(kTestConfig));
EXPECT_FALSE(DBusThreadManager::Get()
->GetShillProfileClient()
->GetTestInterface()
->GetService(service_path, &profile_path, &properties));
}
} // namespace chromeos } // namespace chromeos
...@@ -431,15 +431,8 @@ bool VpnService::VerifyConfigIsConnectedForTesting( ...@@ -431,15 +431,8 @@ bool VpnService::VerifyConfigIsConnectedForTesting(
return DoesActiveConfigurationExistAndIsAccessAuthorized(extension_id); return DoesActiveConfigurationExistAndIsAccessAuthorized(extension_id);
} }
void VpnService::OnExtensionUninstalled( void VpnService::DestroyConfigurationsForExtension(
content::BrowserContext* browser_context, const extensions::Extension* extension) {
const extensions::Extension* extension,
extensions::UninstallReason reason) {
if (browser_context != browser_context_) {
NOTREACHED();
return;
}
std::vector<VpnConfiguration*> to_be_destroyed; std::vector<VpnConfiguration*> to_be_destroyed;
for (const auto& iter : key_to_configuration_map_) { for (const auto& iter : key_to_configuration_map_) {
if (iter.second->extension_id() == extension->id()) { if (iter.second->extension_id() == extension->id()) {
...@@ -455,6 +448,18 @@ void VpnService::OnExtensionUninstalled( ...@@ -455,6 +448,18 @@ void VpnService::OnExtensionUninstalled(
} }
} }
void VpnService::OnExtensionUninstalled(
content::BrowserContext* browser_context,
const extensions::Extension* extension,
extensions::UninstallReason reason) {
if (browser_context != browser_context_) {
NOTREACHED();
return;
}
DestroyConfigurationsForExtension(extension);
}
void VpnService::OnExtensionUnloaded( void VpnService::OnExtensionUnloaded(
content::BrowserContext* browser_context, content::BrowserContext* browser_context,
const extensions::Extension* extension, const extensions::Extension* extension,
...@@ -471,6 +476,10 @@ void VpnService::OnExtensionUnloaded( ...@@ -471,6 +476,10 @@ void VpnService::OnExtensionUnloaded(
static_cast<uint32_t>(api_vpn::VPN_CONNECTION_STATE_FAILURE), static_cast<uint32_t>(api_vpn::VPN_CONNECTION_STATE_FAILURE),
base::Bind(base::DoNothing), base::Bind(DoNothingFailureCallback)); base::Bind(base::DoNothing), base::Bind(DoNothingFailureCallback));
} }
if (reason == extensions::UnloadedExtensionInfo::REASON_DISABLE ||
reason == extensions::UnloadedExtensionInfo::REASON_BLACKLIST) {
DestroyConfigurationsForExtension(extension);
}
} }
void VpnService::OnCreateConfigurationSuccess( void VpnService::OnCreateConfigurationSuccess(
......
...@@ -215,6 +215,10 @@ class VpnService : public KeyedService, ...@@ -215,6 +215,10 @@ class VpnService : public KeyedService,
const std::string& event_name, const std::string& event_name,
scoped_ptr<base::ListValue> event_args); scoped_ptr<base::ListValue> event_args);
// Destroy configurations belonging to the extension.
void DestroyConfigurationsForExtension(
const extensions::Extension* extension);
// Set the active configuration. // Set the active configuration.
void SetActiveConfiguration(VpnConfiguration* configuration); void SetActiveConfiguration(VpnConfiguration* configuration);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment