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

Side by Side Diff: base/registry.cc

Issue 249363004: Revert of Style cleanup in preparation for auto-linting base/. (Closed)
Patch Set: Created 6 years, 8 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);
168 } 166 }
167 else assert(!subkey);
169 } 168 }
170 169
171 void RegKey::Close() { 170 void RegKey::Close() {
172 StopWatching(); 171 StopWatching();
173 if (key_) { 172 if (key_) {
174 ::RegCloseKey(key_); 173 ::RegCloseKey(key_);
175 key_ = NULL; 174 key_ = NULL;
176 } 175 }
177 } 176 }
178 177
(...skipping 13 matching lines...) Expand all
192 NULL, 191 NULL,
193 REG_OPTION_NON_VOLATILE, 192 REG_OPTION_NON_VOLATILE,
194 access, 193 access,
195 NULL, 194 NULL,
196 &key_, 195 &key_,
197 disposition ); 196 disposition );
198 if (result != ERROR_SUCCESS) { 197 if (result != ERROR_SUCCESS) {
199 key_ = NULL; 198 key_ = NULL;
200 return false; 199 return false;
201 } 200 }
202 201 else return true;
203 return true;
204 } 202 }
205 203
206 bool RegKey::Open(HKEY rootkey, const tchar* subkey, REGSAM access) { 204 bool RegKey::Open(HKEY rootkey, const tchar* subkey, REGSAM access) {
207 assert(rootkey && subkey && access); 205 assert(rootkey && subkey && access);
208 this->Close(); 206 this->Close();
209 207
210 LONG const result = RegOpenKeyEx(rootkey, subkey, 0, 208 LONG const result = RegOpenKeyEx(rootkey, subkey, 0,
211 access, &key_ ); 209 access, &key_ );
212 if (result != ERROR_SUCCESS) { 210 if (result != ERROR_SUCCESS) {
213 key_ = NULL; 211 key_ = NULL;
214 return false; 212 return false;
215 } 213 }
216 214 else return true;
217 return true;
218 } 215 }
219 216
220 bool RegKey::CreateKey(const tchar* name, REGSAM access) { 217 bool RegKey::CreateKey(const tchar* name, REGSAM access) {
221 assert(name && access); 218 assert(name && access);
222 219
223 HKEY subkey = NULL; 220 HKEY subkey = NULL;
224 LONG const result = RegCreateKeyEx(key_, name, 0, NULL, 221 LONG const result = RegCreateKeyEx(key_, name, 0, NULL,
225 REG_OPTION_NON_VOLATILE, 222 REG_OPTION_NON_VOLATILE,
226 access, NULL, &subkey, NULL); 223 access, NULL, &subkey, NULL);
227 this->Close(); 224 this->Close();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 // Fail: other, returns 0 290 // Fail: other, returns 0
294 if (size == 0 || size > kMaxStringLength) 291 if (size == 0 || size > kMaxStringLength)
295 return false; 292 return false;
296 *value = expanded; 293 *value = expanded;
297 } else { 294 } else {
298 // Not a string. Oops. 295 // Not a string. Oops.
299 return false; 296 return false;
300 } 297 }
301 return true; 298 return true;
302 } 299 }
303 300 else return false;
304 return false;
305 } 301 }
306 302
307 bool RegKey::ReadValueDW(const tchar* name, DWORD * value) { 303 bool RegKey::ReadValueDW(const tchar* name, DWORD * value) {
308 assert(value); 304 assert(value);
309 DWORD type = REG_DWORD, size = sizeof(DWORD), result = 0; 305 DWORD type = REG_DWORD, size = sizeof(DWORD), result = 0;
310 if (this->ReadValue(name, &result, &size, &type) 306 if (this->ReadValue(name, &result, &size, &type)
311 && (type == REG_DWORD || type == REG_BINARY) 307 && (type == REG_DWORD || type == REG_BINARY)
312 && size == sizeof(DWORD)) { 308 && size == sizeof(DWORD)) {
313 *value = result; 309 *value = result;
314 return true; 310 return true;
315 } 311 }
316 312 else return false;
317 return false;
318 } 313 }
319 314
320 bool RegKey::WriteValue(const tchar* name, 315 bool RegKey::WriteValue(const tchar* name,
321 const void * data, 316 const void * data,
322 DWORD dsize, 317 DWORD dsize,
323 DWORD dtype) { 318 DWORD dtype) {
324 assert(data); 319 assert(data);
325 if (!key_) return false; 320 if (!key_) return false;
326 HRESULT const result = RegSetValueEx( 321 HRESULT const result = RegSetValueEx(
327 key_, 322 key_,
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 ::GetModuleFileName(module, module_path, MAX_PATH); 408 ::GetModuleFileName(module, module_path, MAX_PATH);
414 _tcslwr_s(module_path, MAX_PATH); 409 _tcslwr_s(module_path, MAX_PATH);
415 return RegisterCOMServer(guid, name, module_path); 410 return RegisterCOMServer(guid, name, module_path);
416 } 411 }
417 412
418 bool UnregisterCOMServer(const tchar* guid) { 413 bool UnregisterCOMServer(const tchar* guid) {
419 RegKey key(HKEY_CLASSES_ROOT, _T("CLSID"), KEY_WRITE); 414 RegKey key(HKEY_CLASSES_ROOT, _T("CLSID"), KEY_WRITE);
420 key.DeleteKey(guid); 415 key.DeleteKey(guid);
421 return true; 416 return true;
422 } 417 }
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