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

Side by Side Diff: chrome/browser/chromeos/network_settings/onc_mapper.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_MAPPER_H_
6 #define CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_MAPPER_H_
7
8 #include <string>
9
10 #include "base/memory/scoped_ptr.h"
11
12 namespace base {
13 class Value;
14 class DictionaryValue;
15 class ListValue;
16 }
17
18 namespace chromeos {
19 namespace onc {
20
21 class OncValueSignature;
22
23 // Iterate over both a hierarchical onc signature and an onc value. By comparing
24 // the address of a signature object to the list of signatures in
25 // "onc_signature.h", accurate signature-specific functions can be applied. It
26 // is expected that the hierarchy of the signature is complete.
27 class Mapper {
28 public:
29 Mapper();
30
31 protected:
32 // Calls |MapObject|, |MapArray| and |MapPrimitive| according to |onc_value|'s
33 // type. By default aborts on nested errors in arrays. Result of the mapping
34 // is returned. On error returns NULL.
35 virtual scoped_ptr<base::Value> MapValue(
36 const OncValueSignature& signature,
37 const base::Value& onc_value);
38
39 // Maps objects/dictionaries. By default calls |MapFields|, which recurses
40 // into each field of |onc_object|, and aborts on unknown fields. Result of
41 // the mapping is returned. On error returns NULL.
42 virtual scoped_ptr<base::DictionaryValue> MapObject(
43 const OncValueSignature& signature,
44 const base::DictionaryValue& onc_object);
45
46 // Maps primitive values like BinaryValue, StringValue, IntegerValue... (all
47 // but dictionaries and lists). By default copies |onc_primitive|. Result of
48 // the mapping is returned. On error returns NULL.
49 virtual scoped_ptr<base::Value> MapPrimitive(
50 const OncValueSignature& signature,
51 const base::Value& onc_primitive);
52
53 // Maps each field of the given |onc_object| according to
54 // |object_signature|. Adds the mapping of each field to |result| using
55 // |MapField|, which drops unknown fields by default. Sets
56 // |found_unknown_fieldname| to true if this dictionary contains any unknown
57 // fields. Returns false if nested errors occured.
58 virtual bool MapFields(
59 const OncValueSignature& object_signature,
60 const base::DictionaryValue& onc_object,
61 bool* found_unknown_fieldname,
62 base::DictionaryValue* result);
stevenjb 2012/10/11 19:54:00 Returning a bool here is inconsistent and confusin
pneubeck (no reviews) 2012/10/15 13:57:44 I opted for a second bool argument. This keeps the
63
64 // Maps the value |onc_value| of field |field_name| according to its field
65 // signature in |object_signature| using |MapValue|. Sets
66 // |found_unknown_fieldname| to true if |field_name| cannot be found in
67 // |object_signature|, which by default is an error. Result of the mapping is
68 // returned. On error returns NULL.
69 virtual scoped_ptr<base::Value> MapField(
70 const std::string& field_name,
71 const OncValueSignature& object_signature,
72 const base::Value& onc_value,
73 bool* found_unknown_fieldname);
74
75 // Maps the array |onc_array| according to |array_signature|, which defines
76 // the type of the entries. Maps each entry by calling |MapValue|. If any of
77 // the nested mappings failed, the flag |nested_error_occured| is set to true
78 // and the entry is dropped from the result. The resulting array is
79 // returned. On error returns NULL (doesn't happen in the default
80 // implementation).
81 virtual scoped_ptr<base::ListValue> MapArray(
82 const OncValueSignature& array_signature,
83 const base::ListValue& onc_array,
84 bool* nested_error_occured);
85
86 DISALLOW_COPY_AND_ASSIGN(Mapper);
87 };
88
89 } // namespace onc
90 } // namespace chromeos
91
92 #endif // CHROME_BROWSER_CHROMEOS_NETWORK_SETTINGS_ONC_MAPPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698