Commit 86e0bc2d authored by Jon Mann's avatar Jon Mann Committed by Commit Bot

Record metadata for networks which don't have a NetworkState.

When hidden networks are first configured, they don't have a matching
NetworkState for the newly generated guid, but we still need to record
which user is the owner.  When retrieving the prefs, now check the
default profile for metadata about the guid if none exists on the user
profile, there are a few reasons this could happen now.

Bug: 966270
Change-Id: Id6368fce766907384aa4f41c1f03d458a2113a51
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2211743
Commit-Queue: Jon Mann <jonmann@chromium.org>
Reviewed-by: default avatarAzeem Arshad <azeemarshad@chromium.org>
Cr-Commit-Position: refs/heads/master@{#771225}
parent e409ae5c
......@@ -259,10 +259,7 @@ void NetworkMetadataStore::SetPref(const std::string& network_guid,
const NetworkState* network =
network_state_handler_->GetNetworkStateFromGuid(network_guid);
if (!network)
return;
if (network->IsPrivate() && profile_pref_service_) {
if (network && network->IsPrivate() && profile_pref_service_) {
base::Value profile_dict =
profile_pref_service_->GetDictionary(kNetworkMetadataPref)->Clone();
profile_dict.SetPath(GetPath(network_guid, key), std::move(value));
......@@ -286,14 +283,13 @@ const base::Value* NetworkMetadataStore::GetPref(
const NetworkState* network =
network_state_handler_->GetNetworkStateFromGuid(network_guid);
if (!network) {
return nullptr;
}
if (network->IsPrivate() && profile_pref_service_) {
if (network && network->IsPrivate() && profile_pref_service_) {
const base::Value* profile_dict =
profile_pref_service_->GetDictionary(kNetworkMetadataPref);
return profile_dict->FindPath(GetPath(network_guid, key));
const base::Value* value =
profile_dict->FindPath(GetPath(network_guid, key));
if (value)
return value;
}
const base::Value* device_dict =
......
......@@ -193,6 +193,15 @@ TEST_F(NetworkMetadataStoreTest, ConfigurationCreated) {
ASSERT_TRUE(metadata_store()->GetIsCreatedByUser(kGuid));
}
TEST_F(NetworkMetadataStoreTest, ConfigurationCreated_HiddenNetwork) {
metadata_store()->OnConfigurationCreated("service_path", kGuid);
// Network only exists after the OnConfigurationCreated has been called.
std::string service_path = ConfigureService(kConfigWifi0Connectable);
base::RunLoop().RunUntilIdle();
ASSERT_TRUE(metadata_store()->GetIsCreatedByUser(kGuid));
}
TEST_F(NetworkMetadataStoreTest, ConfigurationUpdated) {
std::string service_path = ConfigureService(kConfigWifi0Connectable);
network_connection_handler()->ConnectToNetwork(
......
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