- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / policy / registry_dict_win.h
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 CHROME_BROWSER_POLICY_REGISTRY_DICT_WIN_H_
6 #define CHROME_BROWSER_POLICY_REGISTRY_DICT_WIN_H_
7
8 #include <windows.h>
9
10 #include <map>
11 #include <string>
12
13 #include "base/basictypes.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/strings/string16.h"
16
17 namespace base {
18 class DictionaryValue;
19 class Value;
20 }
21
22 namespace policy {
23
24 // A case-insensitive string comparison functor.
25 struct CaseInsensitiveStringCompare {
26   bool operator()(const std::string& a, const std::string& b) const;
27 };
28
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.
32 class RegistryDict {
33  public:
34   typedef std::map<std::string, RegistryDict*,
35       CaseInsensitiveStringCompare> KeyMap;
36   typedef std::map<std::string, base::Value*,
37       CaseInsensitiveStringCompare> ValueMap;
38
39   RegistryDict();
40   ~RegistryDict();
41
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);
49   // Clears all keys.
50   void ClearKeys();
51
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);
59   // Clears all values.
60   void ClearValues();
61
62   // Merge keys and values from |other|, giving precedence to |other|.
63   void Merge(const RegistryDict& other);
64
65   // Swap with |other|.
66   void Swap(RegistryDict* other);
67
68   // Read a Windows registry subtree into this registry dictionary object.
69   void ReadRegistry(HKEY hive, const string16& root);
70
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;
77
78   const KeyMap& keys() const { return keys_; }
79   const ValueMap& values() const { return values_; }
80
81  private:
82   KeyMap keys_;
83   ValueMap values_;
84
85   DISALLOW_COPY_AND_ASSIGN(RegistryDict);
86 };
87
88 }  // namespace policy
89
90 #endif  // CHROME_BROWSER_POLICY_REGISTRY_DICT_WIN_H_