Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(636)

Side by Side Diff: base/registry.cc

Issue 552004: Style cleanup in preparation for auto-linting base/. (Closed)
Patch Set: Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/rand_util.h ('k') | base/resource_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 // All Rights Reserved. 4 // All Rights Reserved.
5 5
6 #include "base/registry.h" 6 #include "base/registry.h"
7 7
8 #include <assert.h> 8 #include <assert.h>
9 #include <shlwapi.h> 9 #include <shlwapi.h>
10 #include <windows.h> 10 #include <windows.h>
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 RegistryValueIterator::~RegistryValueIterator() { 44 RegistryValueIterator::~RegistryValueIterator() {
45 if (key_) 45 if (key_)
46 ::RegCloseKey(key_); 46 ::RegCloseKey(key_);
47 } 47 }
48 48
49 bool RegistryValueIterator::Valid() const { 49 bool RegistryValueIterator::Valid() const {
50 // true while the iterator is valid 50 // true while the iterator is valid
51 return key_ != NULL && index_ >= 0; 51 return key_ != NULL && index_ >= 0;
52 } 52 }
53 53
54 void RegistryValueIterator::operator ++ () { 54 void RegistryValueIterator::operator++() {
55 // advance to the next entry in the folder 55 // advance to the next entry in the folder
56 --index_; 56 --index_;
57 Read(); 57 Read();
58 } 58 }
59 59
60 bool RegistryValueIterator::Read() { 60 bool RegistryValueIterator::Read() {
61 if (Valid()) { 61 if (Valid()) {
62 DWORD ncount = sizeof(name_)/sizeof(*name_); 62 DWORD ncount = sizeof(name_)/sizeof(*name_);
63 value_size_ = sizeof(value_); 63 value_size_ = sizeof(value_);
64 LRESULT r = ::RegEnumValue(key_, index_, name_, &ncount, NULL, &type_, 64 LRESULT r = ::RegEnumValue(key_, index_, name_, &ncount, NULL, &type_,
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 RegistryKeyIterator::~RegistryKeyIterator() { 113 RegistryKeyIterator::~RegistryKeyIterator() {
114 if (key_) 114 if (key_)
115 ::RegCloseKey(key_); 115 ::RegCloseKey(key_);
116 } 116 }
117 117
118 bool RegistryKeyIterator::Valid() const { 118 bool RegistryKeyIterator::Valid() const {
119 // true while the iterator is valid 119 // true while the iterator is valid
120 return key_ != NULL && index_ >= 0; 120 return key_ != NULL && index_ >= 0;
121 } 121 }
122 122
123 void RegistryKeyIterator::operator ++ () { 123 void RegistryKeyIterator::operator++() {
124 // advance to the next entry in the folder 124 // advance to the next entry in the folder
125 --index_; 125 --index_;
126 Read(); 126 Read();
127 } 127 }
128 128
129 bool RegistryKeyIterator::Read() { 129 bool RegistryKeyIterator::Read() {
130 if (Valid()) { 130 if (Valid()) {
131 DWORD ncount = sizeof(name_)/sizeof(*name_); 131 DWORD ncount = sizeof(name_)/sizeof(*name_);
132 FILETIME written; 132 FILETIME written;
133 LRESULT r = ::RegEnumKeyEx(key_, index_, name_, &ncount, NULL, NULL, 133 LRESULT r = ::RegEnumKeyEx(key_, index_, name_, &ncount, NULL, NULL,
(...skipping 22 matching lines...) Expand all
156 // RegKey 156 // RegKey
157 // 157 //
158 158
159 RegKey::RegKey(HKEY rootkey, const tchar* subkey, REGSAM access) 159 RegKey::RegKey(HKEY rootkey, const tchar* subkey, REGSAM access)
160 : key_(NULL), watch_event_(0) { 160 : key_(NULL), watch_event_(0) {
161 if (rootkey) { 161 if (rootkey) {
162 if (access & (KEY_SET_VALUE | KEY_CREATE_SUB_KEY | KEY_CREATE_LINK)) 162 if (access & (KEY_SET_VALUE | KEY_CREATE_SUB_KEY | KEY_CREATE_LINK))
163 this->Create(rootkey, subkey, access); 163 this->Create(rootkey, subkey, access);
164 else 164 else
165 this->Open(rootkey, subkey, access); 165 this->Open(rootkey, subkey, access);
166 } else {
167 assert(!subkey);
166 } 168 }
167 else assert(!subkey);
168 } 169 }
169 170
170 void RegKey::Close() { 171 void RegKey::Close() {
171 StopWatching(); 172 StopWatching();
172 if (key_) { 173 if (key_) {
173 ::RegCloseKey(key_); 174 ::RegCloseKey(key_);
174 key_ = NULL; 175 key_ = NULL;
175 } 176 }
176 } 177 }
177 178
(...skipping 13 matching lines...) Expand all
191 NULL, 192 NULL,
192 REG_OPTION_NON_VOLATILE, 193 REG_OPTION_NON_VOLATILE,
193 access, 194 access,
194 NULL, 195 NULL,
195 &key_, 196 &key_,
196 disposition ); 197 disposition );
197 if (result != ERROR_SUCCESS) { 198 if (result != ERROR_SUCCESS) {
198 key_ = NULL; 199 key_ = NULL;
199 return false; 200 return false;
200 } 201 }
201 else return true; 202
203 return true;
202 } 204 }
203 205
204 bool RegKey::Open(HKEY rootkey, const tchar* subkey, REGSAM access) { 206 bool RegKey::Open(HKEY rootkey, const tchar* subkey, REGSAM access) {
205 assert(rootkey && subkey && access); 207 assert(rootkey && subkey && access);
206 this->Close(); 208 this->Close();
207 209
208 LONG const result = RegOpenKeyEx(rootkey, subkey, 0, 210 LONG const result = RegOpenKeyEx(rootkey, subkey, 0,
209 access, &key_ ); 211 access, &key_ );
210 if (result != ERROR_SUCCESS) { 212 if (result != ERROR_SUCCESS) {
211 key_ = NULL; 213 key_ = NULL;
212 return false; 214 return false;
213 } 215 }
214 else return true; 216
217 return true;
215 } 218 }
216 219
217 bool RegKey::CreateKey(const tchar* name, REGSAM access) { 220 bool RegKey::CreateKey(const tchar* name, REGSAM access) {
218 assert(name && access); 221 assert(name && access);
219 222
220 HKEY subkey = NULL; 223 HKEY subkey = NULL;
221 LONG const result = RegCreateKeyEx(key_, name, 0, NULL, 224 LONG const result = RegCreateKeyEx(key_, name, 0, NULL,
222 REG_OPTION_NON_VOLATILE, 225 REG_OPTION_NON_VOLATILE,
223 access, NULL, &subkey, NULL); 226 access, NULL, &subkey, NULL);
224 this->Close(); 227 this->Close();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 // Fail: other, returns 0 293 // Fail: other, returns 0
291 if (size == 0 || size > kMaxStringLength) 294 if (size == 0 || size > kMaxStringLength)
292 return false; 295 return false;
293 *value = expanded; 296 *value = expanded;
294 } else { 297 } else {
295 // Not a string. Oops. 298 // Not a string. Oops.
296 return false; 299 return false;
297 } 300 }
298 return true; 301 return true;
299 } 302 }
300 else return false; 303
304 return false;
301 } 305 }
302 306
303 bool RegKey::ReadValueDW(const tchar* name, DWORD * value) { 307 bool RegKey::ReadValueDW(const tchar* name, DWORD * value) {
304 assert(value); 308 assert(value);
305 DWORD type = REG_DWORD, size = sizeof(DWORD), result = 0; 309 DWORD type = REG_DWORD, size = sizeof(DWORD), result = 0;
306 if (this->ReadValue(name, &result, &size, &type) 310 if (this->ReadValue(name, &result, &size, &type)
307 && (type == REG_DWORD || type == REG_BINARY) 311 && (type == REG_DWORD || type == REG_BINARY)
308 && size == sizeof(DWORD)) { 312 && size == sizeof(DWORD)) {
309 *value = result; 313 *value = result;
310 return true; 314 return true;
311 } 315 }
312 else return false; 316
317 return false;
313 } 318 }
314 319
315 bool RegKey::WriteValue(const tchar* name, 320 bool RegKey::WriteValue(const tchar* name,
316 const void * data, 321 const void * data,
317 DWORD dsize, 322 DWORD dsize,
318 DWORD dtype) { 323 DWORD dtype) {
319 assert(data); 324 assert(data);
320 if (!key_) return false; 325 if (!key_) return false;
321 HRESULT const result = RegSetValueEx( 326 HRESULT const result = RegSetValueEx(
322 key_, 327 key_,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 ::GetModuleFileName(module, module_path, MAX_PATH); 413 ::GetModuleFileName(module, module_path, MAX_PATH);
409 _tcslwr_s(module_path, MAX_PATH); 414 _tcslwr_s(module_path, MAX_PATH);
410 return RegisterCOMServer(guid, name, module_path); 415 return RegisterCOMServer(guid, name, module_path);
411 } 416 }
412 417
413 bool UnregisterCOMServer(const tchar* guid) { 418 bool UnregisterCOMServer(const tchar* guid) {
414 RegKey key(HKEY_CLASSES_ROOT, _T("CLSID"), KEY_WRITE); 419 RegKey key(HKEY_CLASSES_ROOT, _T("CLSID"), KEY_WRITE);
415 key.DeleteKey(guid); 420 key.DeleteKey(guid);
416 return true; 421 return true;
417 } 422 }
OLDNEW
« no previous file with comments | « base/rand_util.h ('k') | base/resource_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698