Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Unified Diff: chromeos/network/policy_util.cc

Issue 2810703005: Fix policy_util iterator and re-enable networking tests (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/network/managed_network_configuration_handler_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromeos/network/policy_util.cc
diff --git a/chromeos/network/policy_util.cc b/chromeos/network/policy_util.cc
index b28f30bee2834a4a3856427405438044b4dd9cdb..ebea93e02b28221da0e237f715118fb0890355af 100644
--- a/chromeos/network/policy_util.cc
+++ b/chromeos/network/policy_util.cc
@@ -35,18 +35,17 @@ const char kFakeCredential[] = "FAKE_CREDENTIAL_VPaJDV9x";
void RemoveFakeCredentials(
const onc::OncValueSignature& signature,
base::DictionaryValue* onc_object) {
- base::DictionaryValue::Iterator it(*onc_object);
- while (!it.IsAtEnd()) {
- base::Value* value = NULL;
+ std::vector<std::string> entries_to_remove;
+ for (base::DictionaryValue::Iterator it(*onc_object); !it.IsAtEnd();
+ it.Advance()) {
+ base::Value* value = nullptr;
std::string field_name = it.key();
// We need the non-const entry to remove nested values but DictionaryValue
// has no non-const iterator.
onc_object->GetWithoutPathExpansion(field_name, &value);
- // Advance before delete.
- it.Advance();
// If |value| is a dictionary, recurse.
- base::DictionaryValue* nested_object = NULL;
+ base::DictionaryValue* nested_object = nullptr;
if (value->GetAsDictionary(&nested_object)) {
const onc::OncFieldSignature* field_signature =
onc::GetFieldSignature(signature, field_name);
@@ -64,12 +63,14 @@ void RemoveFakeCredentials(
if (string_value == kFakeCredential) {
// The value wasn't modified by the UI, thus we remove the field to keep
// the existing value that is stored in Shill.
- onc_object->RemoveWithoutPathExpansion(field_name, NULL);
+ entries_to_remove.push_back(field_name);
}
// Otherwise, the value is set and modified by the UI, thus we keep that
// value to overwrite whatever is stored in Shill.
}
}
+ for (auto field_name : entries_to_remove)
+ onc_object->RemoveWithoutPathExpansion(field_name, nullptr);
}
// Returns true if |policy| matches |actual_network|, which must be part of a
« no previous file with comments | « chromeos/network/managed_network_configuration_handler_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698