| Index: chrome/browser/chromeos/network_settings/onc_validator.h
|
| diff --git a/chrome/browser/chromeos/network_settings/onc_validator.h b/chrome/browser/chromeos/network_settings/onc_validator.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..b80dfa2a2ad420cc7e50362fa0ff808531ecb7bf
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/network_settings/onc_validator.h
|
| @@ -0,0 +1,104 @@
|
| +// 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.
|
| +
|
| +#ifndef CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_
|
| +#define CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_
|
| +
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "chrome/browser/chromeos/network_settings/onc_mapper.h"
|
| +
|
| +namespace base {
|
| +class Value;
|
| +class DictionaryValue;
|
| +}
|
| +
|
| +namespace chromeos {
|
| +namespace onc {
|
| +
|
| +class OncValueSignature;
|
| +
|
| +class Validator : public Mapper {
|
| + public:
|
| + // Creates a Validator with the following options:
|
| + // - It is an error if |error_on_unknown_field| is true and a field name is
|
| + // found that is not part of the signature.
|
| + // - It is an error if |error_on_wrong_recommended| is true and a kRecommended
|
| + // array contains a field name that is not part of the enclosing object's
|
| + // signature.
|
| + // - It is an error if |error_on_missing_field| is true and a required field
|
| + // is missing.
|
| + // - It is an error if |managed_onc| is false and a kRecommended field is set.
|
| + // Any error stops the validation. Only if no error occurs, a repaired object
|
| + // is created that contains all but the problematic fields and values.
|
| + Validator(bool error_on_unknown_field,
|
| + bool error_on_wrong_recommended,
|
| + bool error_on_missing_field,
|
| + bool managed_onc);
|
| +
|
| + // Shortcut to create a strict validator: every error option is true.
|
| + static scoped_ptr<Validator> CreateStrictValidator(bool managed_onc);
|
| + // Shortcut to create a liberal validator: every error option is false.
|
| + static scoped_ptr<Validator> CreateLiberalValidator(bool managed_onc);
|
| +
|
| + // Validate and repair the given |onc_object| according to
|
| + // |object_signature|. The |object_signature| has to be a pointer to one of
|
| + // the signatures in |onc_signature.h|. If repair is possible (no error
|
| + // encountered), returns the repaired object, otherwise returns NULL.
|
| + scoped_ptr<base::DictionaryValue> ValidateAndRepairObject(
|
| + const OncValueSignature* object_signature,
|
| + const base::DictionaryValue& onc_object);
|
| +
|
| + private:
|
| + // Compare |onc_value|s type with |onc_type| and validate/repair according to
|
| + // |value_signature|. On error returns NULL.
|
| + virtual scoped_ptr<base::Value> MapValue(
|
| + const OncValueSignature& signature,
|
| + const base::Value& onc_value);
|
| +
|
| + // Dispatch to the right validation function according to
|
| + // |signature|. Iterates over all fields and recursively validates/repairs
|
| + // these. All valid fields are added to the result dictionary. Returns the
|
| + // repaired dictionary. On error returns NULL.
|
| + virtual scoped_ptr<base::DictionaryValue> MapObject(
|
| + const OncValueSignature& signature,
|
| + const base::DictionaryValue& onc_object);
|
| +
|
| + // This is the default validation of objects/dictionaries. Validates
|
| + // |onc_object| according to |object_signature|. |result| must point to a
|
| + // dictionary into which the repaired fields are written.
|
| + bool ValidateObjectDefault(
|
| + const OncValueSignature& object_signature,
|
| + const base::DictionaryValue& onc_object,
|
| + base::DictionaryValue* result);
|
| +
|
| + // Validates/repairs the kRecommended array in |result| according to
|
| + // |object_signature| of the enclosing object.
|
| + bool ValidateRecommendedField(
|
| + const OncValueSignature& object_signature,
|
| + base::DictionaryValue* result);
|
| +
|
| + bool ValidateNetworkConfiguration(
|
| + const base::DictionaryValue& onc_object,
|
| + base::DictionaryValue* result);
|
| +
|
| + bool ValidateVpn(
|
| + const base::DictionaryValue& onc_object,
|
| + base::DictionaryValue* result);
|
| +
|
| + bool ValidateIpsec(
|
| + const base::DictionaryValue& onc_object,
|
| + base::DictionaryValue* result);
|
| +
|
| + const bool error_on_unknown_field_;
|
| + const bool error_on_wrong_recommended_;
|
| + const bool error_on_missing_field_;
|
| + const bool managed_onc_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(Validator);
|
| +};
|
| +
|
| +} // namespace onc
|
| +} // namespace chromeos
|
| +
|
| +#endif // CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_
|
|
|