Commit ee260006 authored by Jon Mann's avatar Jon Mann Committed by Commit Bot

Add OnBeforeConfigurationRemoved to NetworkConfigurationObserver.

Wi-Fi sync needs to know the ssid and security type of a network
in order to remove it from sync.  Once a network has been removed
this information is no longer available.  This observer method
allows us to cache the required metadata for use once we know
that the removal was successful.

Bug: 966270
Change-Id: Ic850ae8fc75fe600ce70ca2a161bb4281be4119e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2110392
Commit-Queue: Jon Mann <jonmann@chromium.org>
Reviewed-by: default avatarAzeem Arshad <azeemarshad@chromium.org>
Reviewed-by: default avatarJames Vecore <vecore@google.com>
Cr-Commit-Position: refs/heads/master@{#753777}
parent 3ca8400c
......@@ -422,6 +422,8 @@ void NetworkConfigurationHandler::RemoveConfigurationFromProfile(
NET_LOG(USER) << "Remove Configuration: " << NetworkPathId(service_path)
<< " from profiles: "
<< (!profile_path.empty() ? profile_path : "all");
for (auto& observer : observers_)
observer.OnBeforeConfigurationRemoved(service_path, guid);
ProfileEntryDeleter* deleter = new ProfileEntryDeleter(
this, service_path, guid, callback, error_callback);
if (!profile_path.empty())
......
......@@ -95,6 +95,13 @@ class TestNetworkConfigurationObserver : public NetworkConfigurationObserver {
TestNetworkConfigurationObserver() = default;
// NetworkConfigurationObserver
void OnBeforeConfigurationRemoved(const std::string& service_path,
const std::string& guid) override {
ASSERT_EQ(before_remove_configurations_.end(),
before_remove_configurations_.find(service_path));
before_remove_configurations_[service_path] = guid;
}
void OnConfigurationRemoved(const std::string& service_path,
const std::string& guid) override {
ASSERT_EQ(removed_configurations_.end(),
......@@ -108,6 +115,11 @@ class TestNetworkConfigurationObserver : public NetworkConfigurationObserver {
updated_configurations_[service_path] = guid;
}
bool HasCalledBeforeRemoveConfiguration(const std::string& service_path) {
return before_remove_configurations_.find(service_path) !=
before_remove_configurations_.end();
}
bool HasRemovedConfiguration(const std::string& service_path) {
return removed_configurations_.find(service_path) !=
removed_configurations_.end();
......@@ -119,6 +131,7 @@ class TestNetworkConfigurationObserver : public NetworkConfigurationObserver {
}
private:
std::map<std::string, std::string> before_remove_configurations_;
std::map<std::string, std::string> removed_configurations_;
std::map<std::string, std::string> updated_configurations_;
......@@ -669,6 +682,9 @@ TEST_F(NetworkConfigurationHandlerTest, NetworkConfigurationObserver_Removed) {
EXPECT_FALSE(
network_configuration_observer->HasRemovedConfiguration(service_path));
EXPECT_FALSE(
network_configuration_observer->HasCalledBeforeRemoveConfiguration(
service_path));
network_configuration_handler_->RemoveConfiguration(
service_path, base::DoNothing(), base::Bind(&ErrorCallback));
......@@ -676,6 +692,9 @@ TEST_F(NetworkConfigurationHandlerTest, NetworkConfigurationObserver_Removed) {
EXPECT_TRUE(
network_configuration_observer->HasRemovedConfiguration(service_path));
EXPECT_TRUE(
network_configuration_observer->HasCalledBeforeRemoveConfiguration(
service_path));
network_configuration_handler_->RemoveObserver(
network_configuration_observer.get());
......
......@@ -15,6 +15,10 @@ void NetworkConfigurationObserver::OnConfigurationModified(
const std::string& guid,
base::DictionaryValue* set_properties) {}
void NetworkConfigurationObserver::OnBeforeConfigurationRemoved(
const std::string& service_path,
const std::string& guid) {}
void NetworkConfigurationObserver::OnConfigurationRemoved(
const std::string& service_path,
const std::string& guid) {}
......
......@@ -24,6 +24,10 @@ class COMPONENT_EXPORT(CHROMEOS_NETWORK) NetworkConfigurationObserver {
const std::string& guid,
base::DictionaryValue* set_properties);
// Called before a delete is attempted.
virtual void OnBeforeConfigurationRemoved(const std::string& service_path,
const std::string& guid);
// Called whenever a network configuration is removed. |service_path|
// provides the Shill current identifier for the network. |guid| will be set
// to the corresponding GUID for the network if known at the time of removal,
......
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