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

Side by Side Diff: components/policy/core/common/registry_dict_win.h

Issue 2481753002: Push preg_parser and registry_dict changes upstream (Closed)
Patch Set: Minor formatting fixes Created 4 years, 1 month 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 2013 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 COMPONENTS_POLICY_CORE_COMMON_REGISTRY_DICT_WIN_H_
6 #define COMPONENTS_POLICY_CORE_COMMON_REGISTRY_DICT_WIN_H_
7
8 #include <windows.h>
9
10 #include <map>
11 #include <memory>
12 #include <string>
13
14 #include "base/macros.h"
15 #include "base/strings/string16.h"
16 #include "components/policy/policy_export.h"
17
18 namespace base {
19 class Value;
20 }
21
22 namespace policy {
23
24 class Schema;
25
26 // A case-insensitive string comparison functor.
27 struct POLICY_EXPORT CaseInsensitiveStringCompare {
28 bool operator()(const std::string& a, const std::string& b) const;
29 };
30
31 // In-memory representation of a registry subtree. Using a
32 // base::DictionaryValue directly seems tempting, but that doesn't handle the
33 // registry's case-insensitive-but-case-preserving semantics properly.
34 class POLICY_EXPORT RegistryDict {
35 public:
36 using KeyMap = std::map<std::string,
37 std::unique_ptr<RegistryDict>,
38 CaseInsensitiveStringCompare>;
39 using ValueMap = std::map<std::string,
40 std::unique_ptr<base::Value>,
41 CaseInsensitiveStringCompare>;
42
43 RegistryDict();
44 ~RegistryDict();
45
46 // Returns a pointer to an existing key, NULL if not present.
47 RegistryDict* GetKey(const std::string& name);
48 const RegistryDict* GetKey(const std::string& name) const;
49 // Sets a key. If |dict| is NULL, clears that key.
50 void SetKey(const std::string& name, std::unique_ptr<RegistryDict> dict);
51 // Removes a key. If the key doesn't exist, NULL is returned.
52 std::unique_ptr<RegistryDict> RemoveKey(const std::string& name);
53 // Clears all keys.
54 void ClearKeys();
55
56 // Returns a pointer to a value, NULL if not present.
57 base::Value* GetValue(const std::string& name);
58 const base::Value* GetValue(const std::string& name) const;
59 // Sets a value. If |value| is NULL, removes the value.
60 void SetValue(const std::string& name, std::unique_ptr<base::Value> value);
61 // Removes a value. If the value doesn't exist, NULL is returned.
62 std::unique_ptr<base::Value> RemoveValue(const std::string& name);
63 // Clears all values.
64 void ClearValues();
65
66 // Merge keys and values from |other|, giving precedence to |other|.
67 void Merge(const RegistryDict& other);
68
69 // Swap with |other|.
70 void Swap(RegistryDict* other);
71
72 // Read a Windows registry subtree into this registry dictionary object.
73 void ReadRegistry(HKEY hive, const base::string16& root);
74
75 // Converts the dictionary to base::Value representation. For key/value name
76 // collisions, the key wins. |schema| is used to determine the expected type
77 // for each policy.
78 // The returned object is either a base::DictionaryValue or a base::ListValue.
79 std::unique_ptr<base::Value> ConvertToJSON(const Schema& schema) const;
80
81 const KeyMap& keys() const { return keys_; }
82 const ValueMap& values() const { return values_; }
83
84 private:
85 KeyMap keys_;
86 ValueMap values_;
87
88 DISALLOW_COPY_AND_ASSIGN(RegistryDict);
89 };
90
91 } // namespace policy
92
93 #endif // COMPONENTS_POLICY_CORE_COMMON_REGISTRY_DICT_WIN_H_
OLDNEW
« no previous file with comments | « components/policy/core/common/registry_dict_unittest.cc ('k') | components/policy/core/common/registry_dict_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698