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

Side by Side Diff: chrome/browser/chromeos/network_settings/onc_validator.h

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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_
6 #define CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_
7
8 #include "base/memory/scoped_ptr.h"
9 #include "chrome/browser/chromeos/network_settings/onc_mapper.h"
10
11 namespace base {
12 class Value;
13 class DictionaryValue;
14 }
15
16 namespace chromeos {
17 namespace onc {
18
19 class OncValueSignature;
20
21 class Validator : public Mapper {
22 public:
23 // Creates a Validator with the following options:
24 // - It is an error if |error_on_unknown_field| is true and a field name is
25 // found that is not part of the signature.
26 // - It is an error if |error_on_wrong_recommended| is true and a kRecommended
27 // array contains a field name that is not part of the enclosing object's
28 // signature.
29 // - It is an error if |error_on_missing_field| is true and a required field
30 // is missing.
31 // - It is an error if |managed_onc| is false and a kRecommended field is set.
32 // Any error stops the validation. Only if no error occurs, a repaired object
33 // is created that contains all but the problematic fields and values.
34 Validator(bool error_on_unknown_field,
35 bool error_on_wrong_recommended,
36 bool error_on_missing_field,
37 bool managed_onc);
38
39 // Shortcut to create a strict validator: every error option is true.
40 static scoped_ptr<Validator> CreateStrictValidator(bool managed_onc);
41 // Shortcut to create a liberal validator: every error option is false.
42 static scoped_ptr<Validator> CreateLiberalValidator(bool managed_onc);
43
44 // Validate and repair the given |onc_object| according to
45 // |object_signature|. The |object_signature| has to be a pointer to one of
46 // the signatures in |onc_signature.h|. If repair is possible (no error
47 // encountered), returns the repaired object, otherwise returns NULL.
48 scoped_ptr<base::DictionaryValue> ValidateAndRepairObject(
49 const OncValueSignature* object_signature,
50 const base::DictionaryValue& onc_object);
51
52 private:
53 // Compare |onc_value|s type with |onc_type| and validate/repair according to
54 // |value_signature|. On error returns NULL.
55 virtual scoped_ptr<base::Value> MapValue(
56 const OncValueSignature& signature,
57 const base::Value& onc_value);
58
59 // Dispatch to the right validation function according to
60 // |signature|. Iterates over all fields and recursively validates/repairs
61 // these. All valid fields are added to the result dictionary. Returns the
62 // repaired dictionary. On error returns NULL.
63 virtual scoped_ptr<base::DictionaryValue> MapObject(
64 const OncValueSignature& signature,
65 const base::DictionaryValue& onc_object);
66
67 // This is the default validation of objects/dictionaries. Validates
68 // |onc_object| according to |object_signature|. |result| must point to a
69 // dictionary into which the repaired fields are written.
70 bool ValidateObjectDefault(
71 const OncValueSignature& object_signature,
72 const base::DictionaryValue& onc_object,
73 base::DictionaryValue* result);
74
75 // Validates/repairs the kRecommended array in |result| according to
76 // |object_signature| of the enclosing object.
77 bool ValidateRecommendedField(
78 const OncValueSignature& object_signature,
79 base::DictionaryValue* result);
80
81 bool ValidateNetworkConfiguration(
82 const base::DictionaryValue& onc_object,
83 base::DictionaryValue* result);
84
85 bool ValidateVpn(
86 const base::DictionaryValue& onc_object,
87 base::DictionaryValue* result);
88
89 bool ValidateIpsec(
90 const base::DictionaryValue& onc_object,
91 base::DictionaryValue* result);
92
93 const bool error_on_unknown_field_;
94 const bool error_on_wrong_recommended_;
95 const bool error_on_missing_field_;
96 const bool managed_onc_;
97
98 DISALLOW_COPY_AND_ASSIGN(Validator);
99 };
100
101 } // namespace onc
102 } // namespace chromeos
103
104 #endif // CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_VALIDATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698