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 CHROME_BROWSER_POLICY_REGISTRY_DICT_WIN_H_
6 #define CHROME_BROWSER_POLICY_REGISTRY_DICT_WIN_H_
13 #include "base/basictypes.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/strings/string16.h"
18 class DictionaryValue;
24 // A case-insensitive string comparison functor.
25 struct CaseInsensitiveStringCompare {
26 bool operator()(const std::string& a, const std::string& b) const;
29 // In-memory representation of a registry subtree. Using a
30 // base::DictionaryValue directly seems tempting, but that doesn't handle the
31 // registry's case-insensitive-but-case-preserving semantics properly.
34 typedef std::map<std::string, RegistryDict*,
35 CaseInsensitiveStringCompare> KeyMap;
36 typedef std::map<std::string, base::Value*,
37 CaseInsensitiveStringCompare> ValueMap;
42 // Returns a pointer to an existing key, NULL if not present.
43 RegistryDict* GetKey(const std::string& name);
44 const RegistryDict* GetKey(const std::string& name) const;
45 // Sets a key. If |dict| is NULL, clears that key.
46 void SetKey(const std::string& name, scoped_ptr<RegistryDict> dict);
47 // Removes a key. If the key doesn't exist, NULL is returned.
48 scoped_ptr<RegistryDict> RemoveKey(const std::string& name);
52 // Returns a pointer to a value, NULL if not present.
53 base::Value* GetValue(const std::string& name);
54 const base::Value* GetValue(const std::string& name) const;
55 // Sets a value. If |value| is NULL, removes the value.
56 void SetValue(const std::string& name, scoped_ptr<base::Value> value);
57 // Removes a value. If the value doesn't exist, NULL is returned.
58 scoped_ptr<base::Value> RemoveValue(const std::string& name);
62 // Merge keys and values from |other|, giving precedence to |other|.
63 void Merge(const RegistryDict& other);
66 void Swap(RegistryDict* other);
68 // Read a Windows registry subtree into this registry dictionary object.
69 void ReadRegistry(HKEY hive, const string16& root);
71 // Converts the dictionary to base::Value representation. For key/value name
72 // collisions, the key wins. |schema| supplies an optional JSON schema that
73 // will be used to map types to base::Value types. The returned object is
74 // either a base::DictionaryValue or a base::ListValue.
75 scoped_ptr<base::Value> ConvertToJSON(
76 const base::DictionaryValue* schema) const;
78 const KeyMap& keys() const { return keys_; }
79 const ValueMap& values() const { return values_; }
85 DISALLOW_COPY_AND_ASSIGN(RegistryDict);
90 #endif // CHROME_BROWSER_POLICY_REGISTRY_DICT_WIN_H_