Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_WIN_REGISTRY_H_ | 5 #ifndef BASE_WIN_REGISTRY_H_ |
| 6 #define BASE_WIN_REGISTRY_H_ | 6 #define BASE_WIN_REGISTRY_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 | 13 |
| 14 // Please ignore this part. This temporary hack exists | |
|
brettw
2011/01/10 20:42:28
What's the plan for removing this? Should it be a
amit
2011/01/12 04:11:23
Todo added.
This was to help catch all the usage
Sigurður Ásgeirsson
2011/01/12 14:04:19
Maybe not a bad idea to leave this in place for a
| |
| 15 // to detect if the return value is used as 'bool'. | |
| 16 struct CatchBoolChecks { | |
| 17 CatchBoolChecks(LONG l) : l_(l) {} | |
| 18 LONG l_; | |
| 19 operator LONG() { return l_; } | |
| 20 LONG value() const { return l_; } | |
| 21 bool operator == (LONG l) const { return l == l_; } | |
| 22 bool operator != (LONG l) const { return l != l_; } | |
| 23 private: | |
|
brettw
2011/01/10 20:42:28
Indent one more space.
amit
2011/01/12 04:11:23
Done.
| |
| 24 operator bool () {return false;} | |
|
robertshield
2011/01/10 21:34:37
If you intend this to be checked in, consider addi
amit
2011/01/12 04:11:23
Done.
| |
| 25 }; | |
| 26 | |
| 27 inline bool operator == (const LONG& l, const CatchBoolChecks& g) { | |
| 28 return g.value() == l; | |
| 29 } | |
| 30 | |
| 31 inline bool operator != (const LONG& l, const CatchBoolChecks& g) { | |
| 32 return g.value() != l; | |
| 33 } | |
| 34 | |
| 35 using std::ostream; | |
| 36 inline ostream& operator <<(ostream &os, const CatchBoolChecks& g) { | |
| 37 os << g.value(); | |
| 38 return os; | |
| 39 } | |
| 40 | |
| 41 typedef CatchBoolChecks GONG; | |
| 42 | |
| 14 namespace base { | 43 namespace base { |
| 15 namespace win { | 44 namespace win { |
| 16 | 45 |
| 17 // Utility class to read, write and manipulate the Windows Registry. | 46 // Utility class to read, write and manipulate the Windows Registry. |
| 18 // Registry vocabulary primer: a "key" is like a folder, in which there | 47 // Registry vocabulary primer: a "key" is like a folder, in which there |
| 19 // are "values", which are <name, data> pairs, with an associated data type. | 48 // are "values", which are <name, data> pairs, with an associated data type. |
| 20 class RegKey { | 49 class RegKey { |
| 21 public: | 50 public: |
| 22 RegKey(); | 51 RegKey(); |
| 23 RegKey(HKEY rootkey, const wchar_t* subkey, REGSAM access); | 52 RegKey(HKEY rootkey, const wchar_t* subkey, REGSAM access); |
| 24 ~RegKey(); | 53 ~RegKey(); |
| 25 | 54 |
| 26 bool Create(HKEY rootkey, const wchar_t* subkey, REGSAM access); | 55 GONG Create(HKEY rootkey, const wchar_t* subkey, REGSAM access); |
| 27 | 56 |
| 28 bool CreateWithDisposition(HKEY rootkey, const wchar_t* subkey, | 57 GONG CreateWithDisposition(HKEY rootkey, const wchar_t* subkey, |
| 29 DWORD* disposition, REGSAM access); | 58 DWORD* disposition, REGSAM access); |
| 30 | 59 |
| 31 bool Open(HKEY rootkey, const wchar_t* subkey, REGSAM access); | 60 GONG Open(HKEY rootkey, const wchar_t* subkey, REGSAM access); |
| 32 | 61 |
| 33 // Creates a subkey or open it if it already exists. | 62 // Creates a subkey or open it if it already exists. |
| 34 bool CreateKey(const wchar_t* name, REGSAM access); | 63 GONG CreateKey(const wchar_t* name, REGSAM access); |
| 35 | 64 |
| 36 // Opens a subkey | 65 // Opens a subkey |
| 37 bool OpenKey(const wchar_t* name, REGSAM access); | 66 GONG OpenKey(const wchar_t* name, REGSAM access); |
| 38 | 67 |
| 39 void Close(); | 68 void Close(); |
| 40 | 69 |
| 41 DWORD ValueCount() const; | 70 DWORD ValueCount() const; |
| 42 | 71 |
| 43 // Determine the nth value's name. | 72 // Determine the nth value's name. |
| 44 bool ReadName(int index, std::wstring* name) const; | 73 GONG ReadName(int index, std::wstring* name) const; |
| 45 | 74 |
| 46 // True while the key is valid. | 75 // True while the key is valid. |
| 47 bool Valid() const { return key_ != NULL; } | 76 bool Valid() const { return key_ != NULL; } |
| 48 | 77 |
| 49 // Kill a key and everything that live below it; please be careful when using | 78 // Kill a key and everything that live below it; please be careful when using |
| 50 // it. | 79 // it. |
| 51 bool DeleteKey(const wchar_t* name); | 80 GONG DeleteKey(const wchar_t* name); |
| 52 | 81 |
| 53 // Deletes a single value within the key. | 82 // Deletes a single value within the key. |
| 54 bool DeleteValue(const wchar_t* name); | 83 GONG DeleteValue(const wchar_t* name); |
| 55 | 84 |
| 56 bool ValueExists(const wchar_t* name); | 85 bool ValueExists(const wchar_t* name) const; |
| 57 | 86 |
| 58 bool ReadValue(const wchar_t* name, void* data, DWORD* dsize, | 87 GONG ReadValue(const wchar_t* name, void* data, DWORD* dsize, |
| 59 DWORD* dtype) const; | 88 DWORD* dtype) const; |
| 60 bool ReadValue(const wchar_t* name, std::wstring* value) const; | 89 GONG ReadValue(const wchar_t* name, std::wstring* value) const; |
| 61 bool ReadValueDW(const wchar_t* name, DWORD* value) const; | 90 GONG ReadValueDW(const wchar_t* name, DWORD* value) const; |
|
Sigurður Ásgeirsson
2011/01/10 21:02:43
The way you use this in ceee relies upon the fact
amit
2011/01/12 04:11:23
I think it's not proper for an API to return failu
Sigurður Ásgeirsson
2011/01/12 14:04:19
I couldn't agree more - SGTM!
| |
| 91 GONG ReadValueQW(const wchar_t* name, int64* value) const; | |
|
brettw
2011/01/10 20:42:28
What do you think about calling this ReadValue64 o
amit
2011/01/12 04:11:23
Yeah ReadInt64 is much more readable. Changed.
| |
| 62 | 92 |
| 63 bool WriteValue(const wchar_t* name, const void* data, DWORD dsize, | 93 GONG WriteValue(const wchar_t* name, const void* data, DWORD dsize, |
| 64 DWORD dtype); | 94 DWORD dtype); |
| 65 bool WriteValue(const wchar_t* name, const wchar_t* value); | 95 GONG WriteValue(const wchar_t* name, const wchar_t* value); |
| 66 bool WriteValue(const wchar_t* name, DWORD value); | 96 GONG WriteValue(const wchar_t* name, DWORD value); |
| 67 | 97 |
| 68 // Starts watching the key to see if any of its values have changed. | 98 // Starts watching the key to see if any of its values have changed. |
| 69 // The key must have been opened with the KEY_NOTIFY access privilege. | 99 // The key must have been opened with the KEY_NOTIFY access privilege. |
| 70 bool StartWatching(); | 100 GONG StartWatching(); |
| 71 | 101 |
| 72 // If StartWatching hasn't been called, always returns false. | 102 // If StartWatching hasn't been called, always returns false. |
| 73 // Otherwise, returns true if anything under the key has changed. | 103 // Otherwise, returns true if anything under the key has changed. |
| 74 // This can't be const because the |watch_event_| may be refreshed. | 104 // This can't be const because the |watch_event_| may be refreshed. |
| 75 bool HasChanged(); | 105 bool HasChanged(); |
| 76 | 106 |
| 77 // Will automatically be called by destructor if not manually called | 107 // Will automatically be called by destructor if not manually called |
| 78 // beforehand. Returns true if it was watching, false otherwise. | 108 // beforehand. Returns true if it was watching, false otherwise. |
| 79 bool StopWatching(); | 109 GONG StopWatching(); |
| 80 | 110 |
| 81 inline bool IsWatching() const { return watch_event_ != 0; } | 111 inline bool IsWatching() const { return watch_event_ != 0; } |
| 82 HANDLE watch_event() const { return watch_event_; } | 112 HANDLE watch_event() const { return watch_event_; } |
| 83 HKEY Handle() const { return key_; } | 113 HKEY Handle() const { return key_; } |
| 84 | 114 |
| 85 private: | 115 private: |
| 86 HKEY key_; // The registry key being iterated. | 116 HKEY key_; // The registry key being iterated. |
| 87 HANDLE watch_event_; | 117 HANDLE watch_event_; |
| 88 | 118 |
| 89 DISALLOW_COPY_AND_ASSIGN(RegKey); | 119 DISALLOW_COPY_AND_ASSIGN(RegKey); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 163 | 193 |
| 164 wchar_t name_[MAX_PATH]; | 194 wchar_t name_[MAX_PATH]; |
| 165 | 195 |
| 166 DISALLOW_COPY_AND_ASSIGN(RegistryKeyIterator); | 196 DISALLOW_COPY_AND_ASSIGN(RegistryKeyIterator); |
| 167 }; | 197 }; |
| 168 | 198 |
| 169 } // namespace win | 199 } // namespace win |
| 170 } // namespace base | 200 } // namespace base |
| 171 | 201 |
| 172 #endif // BASE_WIN_REGISTRY_H_ | 202 #endif // BASE_WIN_REGISTRY_H_ |
| OLD | NEW |