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_POLICY_DEVICE_POLICY_DECODER_CHROMEOS_H_
6 #define CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_POLICY_DECODER_CHROMEOS_H_
7 
8 #include <string>
9 
10 #include "base/memory/weak_ptr.h"
11 #include "base/optional.h"
12 
13 namespace enterprise_management {
14 class ChromeDeviceSettingsProto;
15 }
16 
17 namespace base {
18 class Value;
19 }
20 
21 namespace policy {
22 
23 class ExternalDataManager;
24 class PolicyMap;
25 
26 // A pattern for validating hostnames. Used for the validation of
27 // DeviceLoginScreenDomainAutoComplete policy.
28 extern const char hostNameRegex[];
29 
30 // Decodes a JSON string to a base::Value and validates it against the schema
31 // defined in policy_templates.json for the policy named |policy_name|. Unknown
32 // properties are dropped. Returns nullptr if the input cannot be parsed as
33 // valid JSON string or doesn't comply with the declared schema (e.g. mismatched
34 // type, missing required field, etc.). Any warning or error messages from the
35 // decoding and schema validation process are stored in |error|.
36 base::Optional<base::Value> DecodeJsonStringAndNormalize(
37     const std::string& json_string,
38     const std::string& policy_name,
39     std::string* error);
40 
41 // Decodes device policy in ChromeDeviceSettingsProto representation into the a
42 // PolicyMap.
43 void DecodeDevicePolicy(
44     const enterprise_management::ChromeDeviceSettingsProto& policy,
45     base::WeakPtr<ExternalDataManager> external_data_manager,
46     PolicyMap* policies);
47 
48 }  // namespace policy
49 
50 #endif  // CHROME_BROWSER_CHROMEOS_POLICY_DEVICE_POLICY_DECODER_CHROMEOS_H_
51