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

Unified Diff: chrome/browser/chromeos/network_settings/onc_normalizer.cc

Issue 10944009: Implementation of ONC signature, validator and normalizer. (Closed) Base URL: http://git.chromium.org/chromium/src.git@gperffix
Patch Set: Addressed comments (formatting, sorting). Minor change in policy.onc. Created 8 years, 2 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
Index: chrome/browser/chromeos/network_settings/onc_normalizer.cc
diff --git a/chrome/browser/chromeos/network_settings/onc_normalizer.cc b/chrome/browser/chromeos/network_settings/onc_normalizer.cc
new file mode 100644
index 0000000000000000000000000000000000000000..5557aa899edbcd67341f0094485aec84d298fcc5
--- /dev/null
+++ b/chrome/browser/chromeos/network_settings/onc_normalizer.cc
@@ -0,0 +1,106 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/network_settings/onc_normalizer.h"
+
+#include <string>
+
+#include "base/logging.h"
+#include "base/values.h"
+#include "chrome/browser/chromeos/cros/onc_constants.h"
+#include "chrome/browser/chromeos/network_settings/onc_signature.h"
+
+namespace chromeos {
+namespace onc {
+
+Normalizer::Normalizer(bool remove_recommended_fields)
+ : remove_recommended_fields_(remove_recommended_fields) {
+}
+
+scoped_ptr<base::DictionaryValue> Normalizer::NormalizeObject(
+ const OncValueSignature* object_signature,
+ const base::DictionaryValue& onc_object) {
+ CHECK(object_signature != NULL);
+ scoped_ptr<base::Value> result_value =
+ MapValue(*object_signature, onc_object);
+ base::DictionaryValue* result_dict = NULL;
+ if (result_value.get()) {
+ result_value.release()->GetAsDictionary(&result_dict);
+ CHECK(result_dict != NULL);
+ }
+ return make_scoped_ptr(result_dict);
+}
+
+scoped_ptr<base::DictionaryValue> Normalizer::MapObject(
+ const OncValueSignature& signature,
+ const base::DictionaryValue& onc_object) {
+ scoped_ptr<base::DictionaryValue> normalized =
+ Mapper::MapObject(signature, onc_object);
+
+ if (!normalized.get())
+ return scoped_ptr<base::DictionaryValue>();
+
+ if (remove_recommended_fields_)
+ normalized->RemoveWithoutPathExpansion(kRecommended, NULL);
+
+ if (&signature == &network_configuration_signature)
+ NormalizeNetworkConfiguration(normalized.get());
+ else if (&signature == &vpn_signature)
+ NormalizeVPN(normalized.get());
+ else if (&signature == &ipsec_signature)
+ NormalizeIPsec(normalized.get());
+
+ return normalized.Pass();
+}
+
+namespace {
+void RemoveEntryUnless(base::DictionaryValue* dict,
+ const std::string path,
+ bool condition) {
+ if (!condition)
+ dict->RemoveWithoutPathExpansion(path, NULL);
+}
+} // namespace
+
+void NormalizeIPsec(base::DictionaryValue* ipsec) {
+ using namespace vpn;
+
+ std::string auth_type = "";
stevenjb 2012/10/11 19:54:00 nit: = "" is unnecessary here and elsewhere
pneubeck (no reviews) 2012/10/15 13:57:44 Done.
+ ipsec->GetStringWithoutPathExpansion(kAuthenticationType, &auth_type);
+ RemoveEntryUnless(ipsec, kClientCertType, auth_type == "Cert");
stevenjb 2012/10/11 19:54:00 "Cert" and other strings should be consts declared
pneubeck (no reviews) 2012/10/15 13:57:44 I added constants for the possible field values to
+ RemoveEntryUnless(ipsec, kServerCARef, auth_type == "Cert");
+ RemoveEntryUnless(ipsec, kPSK, auth_type == "PSK");
+ RemoveEntryUnless(ipsec, kSaveCredentials, auth_type == "PSK");
+
+ std::string clientcert_type = "";
+ ipsec->GetStringWithoutPathExpansion(kClientCertType, &clientcert_type);
+ RemoveEntryUnless(ipsec, kClientCertPattern, clientcert_type == "Pattern");
+ RemoveEntryUnless(ipsec, kClientCertRef, clientcert_type == "Ref");
+
+ int ike_version = -1;
+ ipsec->GetIntegerWithoutPathExpansion(kIKEVersion, &ike_version);
+ RemoveEntryUnless(ipsec, kEAP, ike_version == 2);
+ RemoveEntryUnless(ipsec, kGroup, ike_version == 1);
+ RemoveEntryUnless(ipsec, kXAUTH, ike_version == 1);
+}
+
+void NormalizeVPN(base::DictionaryValue* vpn) {
+ using namespace vpn;
+ std::string type = "";
+ vpn->GetStringWithoutPathExpansion(vpn::kType, &type);
+ RemoveEntryUnless(vpn, kOpenVPN, type == kOpenVPN);
+ RemoveEntryUnless(vpn, kIPsec, type == kIPsec || type == "L2TP-IPsec");
+ RemoveEntryUnless(vpn, kL2TP, type == "L2TP-IPSec");
+}
+
+void NormalizeNetworkConfiguration(base::DictionaryValue* network) {
+ std::string type = "";
+ network->GetStringWithoutPathExpansion(kType, &type);
+ RemoveEntryUnless(network, kEthernet, type == kEthernet);
+ RemoveEntryUnless(network, kVPN, type == kVPN);
+ RemoveEntryUnless(network, kWiFi, type == kWiFi);
+}
+
+} // namespace onc
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698