| 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
|
| index cee5d07e4a242356c681ab19e96253e27375dc90..c2a20742277c0efce8b0711868b188e4834b847e 100644
|
| --- a/chrome/browser/chromeos/network_settings/onc_validator.h
|
| +++ b/chrome/browser/chromeos/network_settings/onc_validator.h
|
| @@ -5,6 +5,8 @@
|
| #ifndef CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_
|
| #define CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_
|
|
|
| +#include <vector>
|
| +
|
| #include "base/memory/scoped_ptr.h"
|
| #include "chrome/browser/chromeos/network_settings/onc_mapper.h"
|
|
|
| @@ -20,6 +22,12 @@ struct OncValueSignature;
|
|
|
| class Validator : public Mapper {
|
| public:
|
| + enum Result {
|
| + VALID,
|
| + VALID_WITH_WARNINGS,
|
| + INVALID
|
| + };
|
| +
|
| // Creates a Validator that searches for the following invalid cases:
|
| // - a field name is found that is not part of the signature
|
| // (controlled by |error_on_unknown_field|)
|
| @@ -34,11 +42,18 @@ class Validator : public Mapper {
|
| // - a required field is missing (controlled by |error_on_missing_field|)
|
| //
|
| // If one of these invalid cases occurs and the controlling flag is true, then
|
| - // it is an error and the validation stops. The function
|
| - // ValidateAndRepairObject returns NULL.
|
| + // it is an error. The function ValidateAndRepairObject sets |result| to
|
| + // INVALID and returns NULL.
|
| + //
|
| + // Otherwise, a DeepCopy of the validated object is created, which contains
|
| + // all but the invalid fields and values.
|
| //
|
| - // If no error occurred, then a DeepCopy of the validated object is created,
|
| - // which contains all but the invalid fields and values.
|
| + // If one of the invalid cases occurs and the controlling flag is false, then
|
| + // it is a warning. The function ValidateAndRepairObject sets |result| to
|
| + // VALID_WITH_WARNINGS and returns the repaired copy.
|
| + //
|
| + // If no error occurred, |result| is set to VALID and an exact DeepCopy is
|
| + // returned.
|
| Validator(bool error_on_unknown_field,
|
| bool error_on_wrong_recommended,
|
| bool error_on_missing_field,
|
| @@ -51,22 +66,25 @@ class Validator : public Mapper {
|
| // |onc_signature.h|. If an error is found, the function returns NULL. If
|
| // possible (no error encountered) a DeepCopy is created that contains all but
|
| // the invalid fields and values and returns this "repaired" object.
|
| - // That means, if not handled as an error, then the following are ignored:
|
| + // That means, if not handled as an error, then the following are dropped from
|
| + // the copy:
|
| // - unknown fields
|
| // - invalid field names in kRecommended arrays
|
| // - kRecommended fields in an unmanaged ONC
|
| // For details, see the comment at the Constructor.
|
| scoped_ptr<base::DictionaryValue> ValidateAndRepairObject(
|
| const OncValueSignature* object_signature,
|
| - const base::DictionaryValue& onc_object);
|
| + const base::DictionaryValue& onc_object,
|
| + Result* result);
|
|
|
| private:
|
| - // Overriden from Mapper:
|
| + // Overridden from Mapper:
|
| // Compare |onc_value|s type with |onc_type| and validate/repair according to
|
| // |signature|. On error returns NULL.
|
| virtual scoped_ptr<base::Value> MapValue(
|
| const OncValueSignature& signature,
|
| - const base::Value& onc_value) OVERRIDE;
|
| + const base::Value& onc_value,
|
| + bool* error) OVERRIDE;
|
|
|
| // Dispatch to the right validation function according to
|
| // |signature|. Iterates over all fields and recursively validates/repairs
|
| @@ -74,7 +92,23 @@ class Validator : public Mapper {
|
| // repaired dictionary. On error returns NULL.
|
| virtual scoped_ptr<base::DictionaryValue> MapObject(
|
| const OncValueSignature& signature,
|
| - const base::DictionaryValue& onc_object) OVERRIDE;
|
| + const base::DictionaryValue& onc_object,
|
| + bool* error) OVERRIDE;
|
| +
|
| + // Pushes/pops the |field_name| to |path_|, otherwise like |Mapper::MapField|.
|
| + virtual scoped_ptr<base::Value> MapField(
|
| + const std::string& field_name,
|
| + const OncValueSignature& object_signature,
|
| + const base::Value& onc_value,
|
| + bool* found_unknown_field,
|
| + bool* error) OVERRIDE;
|
| +
|
| + // Pushes/pops the index to |path_|, otherwise like |Mapper::MapEntry|.
|
| + virtual scoped_ptr<base::Value> MapEntry(
|
| + int index,
|
| + const OncValueSignature& signature,
|
| + const base::Value& onc_value,
|
| + bool* error) OVERRIDE;
|
|
|
| // This is the default validation of objects/dictionaries. Validates
|
| // |onc_object| according to |object_signature|. |result| must point to a
|
| @@ -90,6 +124,10 @@ class Validator : public Mapper {
|
| const OncValueSignature& object_signature,
|
| base::DictionaryValue* result);
|
|
|
| + bool ValidateToplevelConfiguration(
|
| + const base::DictionaryValue& onc_object,
|
| + base::DictionaryValue* result);
|
| +
|
| bool ValidateNetworkConfiguration(
|
| const base::DictionaryValue& onc_object,
|
| base::DictionaryValue* result);
|
| @@ -138,11 +176,34 @@ class Validator : public Mapper {
|
| const base::DictionaryValue& onc_object,
|
| base::DictionaryValue* result);
|
|
|
| + bool FieldExistsAndHasNoValueOf(const base::DictionaryValue& object,
|
| + const std::string &field_name,
|
| + const char** valid_values);
|
| +
|
| + bool FieldExistsAndIsNotInRange(const base::DictionaryValue& object,
|
| + const std::string &field_name,
|
| + int lower_bound,
|
| + int upper_bound);
|
| +
|
| + bool RequireField(const base::DictionaryValue& dict, const std::string& key);
|
| +
|
| + std::string WarningHeader();
|
| + std::string ErrorHeader();
|
| + std::string MessageHeader(bool is_error);
|
| +
|
| const bool error_on_unknown_field_;
|
| const bool error_on_wrong_recommended_;
|
| const bool error_on_missing_field_;
|
| const bool managed_onc_;
|
|
|
| + // The path of field names and indices to the current value. Indices
|
| + // are stored as strings in decimal notation.
|
| + std::vector<std::string> path_;
|
| +
|
| + // Tracks if an error or warning occurred within validation initiated by
|
| + // function ValidateAndRepairObject.
|
| + bool error_or_warning_found_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(Validator);
|
| };
|
|
|
|
|