OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 | 7 |
8 #include <windows.h> | 8 #include <windows.h> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 HKEY key_; // The registry key being iterated. | 150 HKEY key_; // The registry key being iterated. |
151 HANDLE watch_event_; | 151 HANDLE watch_event_; |
152 REGSAM wow64access_; | 152 REGSAM wow64access_; |
153 | 153 |
154 DISALLOW_COPY_AND_ASSIGN(RegKey); | 154 DISALLOW_COPY_AND_ASSIGN(RegKey); |
155 }; | 155 }; |
156 | 156 |
157 // Iterates the entries found in a particular folder on the registry. | 157 // Iterates the entries found in a particular folder on the registry. |
158 class BASE_EXPORT RegistryValueIterator { | 158 class BASE_EXPORT RegistryValueIterator { |
159 public: | 159 public: |
| 160 // Construct a Registry Value Iterator with default WOW64 access. |
160 RegistryValueIterator(HKEY root_key, const wchar_t* folder_key); | 161 RegistryValueIterator(HKEY root_key, const wchar_t* folder_key); |
161 | 162 |
| 163 // Construct a Registry Key Iterator with specific WOW64 access, one of |
| 164 // KEY_WOW64_32KEY or KEY_WOW64_64KEY, or 0. |
| 165 // Note: |wow64access| should be the same access used to open |root_key| |
| 166 // previously, or a predefined key (e.g. HKEY_LOCAL_MACHINE). |
| 167 // See http://msdn.microsoft.com/en-us/library/windows/desktop/aa384129.aspx. |
| 168 RegistryValueIterator(HKEY root_key, |
| 169 const wchar_t* folder_key, |
| 170 REGSAM wow64access); |
| 171 |
162 ~RegistryValueIterator(); | 172 ~RegistryValueIterator(); |
163 | 173 |
164 DWORD ValueCount() const; | 174 DWORD ValueCount() const; |
165 | 175 |
166 // True while the iterator is valid. | 176 // True while the iterator is valid. |
167 bool Valid() const; | 177 bool Valid() const; |
168 | 178 |
169 // Advances to the next registry entry. | 179 // Advances to the next registry entry. |
170 void operator++(); | 180 void operator++(); |
171 | 181 |
172 const wchar_t* Name() const { return name_.c_str(); } | 182 const wchar_t* Name() const { return name_.c_str(); } |
173 const wchar_t* Value() const { return vector_as_array(&value_); } | 183 const wchar_t* Value() const { return vector_as_array(&value_); } |
174 // ValueSize() is in bytes. | 184 // ValueSize() is in bytes. |
175 DWORD ValueSize() const { return value_size_; } | 185 DWORD ValueSize() const { return value_size_; } |
176 DWORD Type() const { return type_; } | 186 DWORD Type() const { return type_; } |
177 | 187 |
178 int Index() const { return index_; } | 188 int Index() const { return index_; } |
179 | 189 |
180 private: | 190 private: |
181 // Read in the current values. | 191 // Read in the current values. |
182 bool Read(); | 192 bool Read(); |
183 | 193 |
| 194 void Initialize(HKEY root_key, const wchar_t* folder_key, REGSAM wow64access); |
| 195 |
184 // The registry key being iterated. | 196 // The registry key being iterated. |
185 HKEY key_; | 197 HKEY key_; |
186 | 198 |
187 // Current index of the iteration. | 199 // Current index of the iteration. |
188 int index_; | 200 int index_; |
189 | 201 |
190 // Current values. | 202 // Current values. |
191 std::wstring name_; | 203 std::wstring name_; |
192 std::vector<wchar_t> value_; | 204 std::vector<wchar_t> value_; |
193 DWORD value_size_; | 205 DWORD value_size_; |
194 DWORD type_; | 206 DWORD type_; |
195 | 207 |
196 DISALLOW_COPY_AND_ASSIGN(RegistryValueIterator); | 208 DISALLOW_COPY_AND_ASSIGN(RegistryValueIterator); |
197 }; | 209 }; |
198 | 210 |
199 class BASE_EXPORT RegistryKeyIterator { | 211 class BASE_EXPORT RegistryKeyIterator { |
200 public: | 212 public: |
| 213 // Construct a Registry Key Iterator with default WOW64 access. |
201 RegistryKeyIterator(HKEY root_key, const wchar_t* folder_key); | 214 RegistryKeyIterator(HKEY root_key, const wchar_t* folder_key); |
202 | 215 |
| 216 // Construct a Registry Value Iterator with specific WOW64 access, one of |
| 217 // KEY_WOW64_32KEY or KEY_WOW64_64KEY, or 0. |
| 218 // Note: |wow64access| should be the same access used to open |root_key| |
| 219 // previously, or a predefined key (e.g. HKEY_LOCAL_MACHINE). |
| 220 // See http://msdn.microsoft.com/en-us/library/windows/desktop/aa384129.aspx. |
| 221 RegistryKeyIterator(HKEY root_key, |
| 222 const wchar_t* folder_key, |
| 223 REGSAM wow64access); |
| 224 |
203 ~RegistryKeyIterator(); | 225 ~RegistryKeyIterator(); |
204 | 226 |
205 DWORD SubkeyCount() const; | 227 DWORD SubkeyCount() const; |
206 | 228 |
207 // True while the iterator is valid. | 229 // True while the iterator is valid. |
208 bool Valid() const; | 230 bool Valid() const; |
209 | 231 |
210 // Advances to the next entry in the folder. | 232 // Advances to the next entry in the folder. |
211 void operator++(); | 233 void operator++(); |
212 | 234 |
213 const wchar_t* Name() const { return name_; } | 235 const wchar_t* Name() const { return name_; } |
214 | 236 |
215 int Index() const { return index_; } | 237 int Index() const { return index_; } |
216 | 238 |
217 private: | 239 private: |
218 // Read in the current values. | 240 // Read in the current values. |
219 bool Read(); | 241 bool Read(); |
220 | 242 |
| 243 void Initialize(HKEY root_key, const wchar_t* folder_key, REGSAM wow64access); |
| 244 |
221 // The registry key being iterated. | 245 // The registry key being iterated. |
222 HKEY key_; | 246 HKEY key_; |
223 | 247 |
224 // Current index of the iteration. | 248 // Current index of the iteration. |
225 int index_; | 249 int index_; |
226 | 250 |
227 wchar_t name_[MAX_PATH]; | 251 wchar_t name_[MAX_PATH]; |
228 | 252 |
229 DISALLOW_COPY_AND_ASSIGN(RegistryKeyIterator); | 253 DISALLOW_COPY_AND_ASSIGN(RegistryKeyIterator); |
230 }; | 254 }; |
231 | 255 |
232 } // namespace win | 256 } // namespace win |
233 } // namespace base | 257 } // namespace base |
234 | 258 |
235 #endif // BASE_WIN_REGISTRY_H_ | 259 #endif // BASE_WIN_REGISTRY_H_ |
OLD | NEW |