Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / components / policy / core / common / registry_dict_win.h
blobda48c857da8b4262482b2ea280aff546c88939ed
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.
5 #ifndef COMPONENTS_POLICY_CORE_COMMON_REGISTRY_DICT_WIN_H_
6 #define COMPONENTS_POLICY_CORE_COMMON_REGISTRY_DICT_WIN_H_
8 #include <windows.h>
10 #include <map>
11 #include <string>
13 #include "base/basictypes.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/strings/string16.h"
16 #include "components/policy/policy_export.h"
18 namespace base {
19 class Value;
22 namespace policy {
24 class Schema;
26 // A case-insensitive string comparison functor.
27 struct POLICY_EXPORT CaseInsensitiveStringCompare {
28 bool operator()(const std::string& a, const std::string& b) const;
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 typedef std::map<std::string, RegistryDict*,
37 CaseInsensitiveStringCompare> KeyMap;
38 typedef std::map<std::string, base::Value*,
39 CaseInsensitiveStringCompare> ValueMap;
41 RegistryDict();
42 ~RegistryDict();
44 // Returns a pointer to an existing key, NULL if not present.
45 RegistryDict* GetKey(const std::string& name);
46 const RegistryDict* GetKey(const std::string& name) const;
47 // Sets a key. If |dict| is NULL, clears that key.
48 void SetKey(const std::string& name, scoped_ptr<RegistryDict> dict);
49 // Removes a key. If the key doesn't exist, NULL is returned.
50 scoped_ptr<RegistryDict> RemoveKey(const std::string& name);
51 // Clears all keys.
52 void ClearKeys();
54 // Returns a pointer to a value, NULL if not present.
55 base::Value* GetValue(const std::string& name);
56 const base::Value* GetValue(const std::string& name) const;
57 // Sets a value. If |value| is NULL, removes the value.
58 void SetValue(const std::string& name, scoped_ptr<base::Value> value);
59 // Removes a value. If the value doesn't exist, NULL is returned.
60 scoped_ptr<base::Value> RemoveValue(const std::string& name);
61 // Clears all values.
62 void ClearValues();
64 // Merge keys and values from |other|, giving precedence to |other|.
65 void Merge(const RegistryDict& other);
67 // Swap with |other|.
68 void Swap(RegistryDict* other);
70 // Read a Windows registry subtree into this registry dictionary object.
71 void ReadRegistry(HKEY hive, const base::string16& root);
73 // Converts the dictionary to base::Value representation. For key/value name
74 // collisions, the key wins. |schema| is used to determine the expected type
75 // for each policy.
76 // The returned object is either a base::DictionaryValue or a base::ListValue.
77 scoped_ptr<base::Value> ConvertToJSON(const Schema& schema) const;
79 const KeyMap& keys() const { return keys_; }
80 const ValueMap& values() const { return values_; }
82 private:
83 KeyMap keys_;
84 ValueMap values_;
86 DISALLOW_COPY_AND_ASSIGN(RegistryDict);
89 } // namespace policy
91 #endif // COMPONENTS_POLICY_CORE_COMMON_REGISTRY_DICT_WIN_H_