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

Side by Side Diff: base/win/registry.h

Issue 6090006: Regkey functions return error code instead of bool (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | base/win/registry.cc » ('j') | chrome/installer/util/delete_reg_value_work_item.h » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
15 // to detect if the return value is used as 'bool'.
16 // Todo(amit): remove this before (or soon after) checkin.
17 struct CatchBoolChecks {
18 CatchBoolChecks(LONG l) : l_(l) {}
19 LONG l_;
20 operator LONG() { return l_; }
21 LONG value() const { return l_; }
22 bool operator == (LONG l) const { return l == l_; }
23 bool operator != (LONG l) const { return l != l_; }
24 private:
25 // If you hit a compile error here, you most likely attempting to use the
26 // return value of a RegKey helper as a bool. Please note that RegKey
27 // methods return LONG now instead of bool.
28 operator bool () { return false; }
29 };
30
31 inline bool operator == (const LONG& l, const CatchBoolChecks& g) {
32 return g.value() == l;
33 }
34
35 inline bool operator != (const LONG& l, const CatchBoolChecks& g) {
36 return g.value() != l;
37 }
38
39 using std::ostream;
40 inline ostream& operator <<(ostream &os, const CatchBoolChecks& g) {
41 os << g.value();
42 return os;
43 }
44
45 typedef CatchBoolChecks GONG;
46
47 #ifndef REG_SUCCESS
48 #define REG_SUCCESS(r) ((r) == ERROR_SUCCESS)
49 #endif // REG_SUCCESS
50
14 namespace base { 51 namespace base {
15 namespace win { 52 namespace win {
16 53
17 // Utility class to read, write and manipulate the Windows Registry. 54 // Utility class to read, write and manipulate the Windows Registry.
18 // Registry vocabulary primer: a "key" is like a folder, in which there 55 // 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. 56 // are "values", which are <name, data> pairs, with an associated data type.
57 //
58 // Note:
59 // ReadValue family of functions guarantee that the return arguments
60 // are not touched in case of failure.
20 class RegKey { 61 class RegKey {
21 public: 62 public:
22 RegKey(); 63 RegKey();
23 RegKey(HKEY rootkey, const wchar_t* subkey, REGSAM access); 64 RegKey(HKEY rootkey, const wchar_t* subkey, REGSAM access);
24 ~RegKey(); 65 ~RegKey();
25 66
26 bool Create(HKEY rootkey, const wchar_t* subkey, REGSAM access); 67 GONG Create(HKEY rootkey, const wchar_t* subkey, REGSAM access);
27 68
28 bool CreateWithDisposition(HKEY rootkey, const wchar_t* subkey, 69 GONG CreateWithDisposition(HKEY rootkey, const wchar_t* subkey,
29 DWORD* disposition, REGSAM access); 70 DWORD* disposition, REGSAM access);
30 71
31 bool Open(HKEY rootkey, const wchar_t* subkey, REGSAM access); 72 GONG Open(HKEY rootkey, const wchar_t* subkey, REGSAM access);
32 73
33 // Creates a subkey or open it if it already exists. 74 // Creates a subkey or open it if it already exists.
34 bool CreateKey(const wchar_t* name, REGSAM access); 75 GONG CreateKey(const wchar_t* name, REGSAM access);
35 76
36 // Opens a subkey 77 // Opens a subkey
37 bool OpenKey(const wchar_t* name, REGSAM access); 78 GONG OpenKey(const wchar_t* name, REGSAM access);
38 79
39 void Close(); 80 void Close();
40 81
41 DWORD ValueCount() const; 82 DWORD ValueCount() const;
42 83
43 // Determine the nth value's name. 84 // Determine the nth value's name.
44 bool ReadName(int index, std::wstring* name) const; 85 GONG ReadName(int index, std::wstring* name) const;
45 86
46 // True while the key is valid. 87 // True while the key is valid.
47 bool Valid() const { return key_ != NULL; } 88 bool Valid() const { return key_ != NULL; }
48 89
49 // Kill a key and everything that live below it; please be careful when using 90 // Kill a key and everything that live below it; please be careful when using
50 // it. 91 // it.
51 bool DeleteKey(const wchar_t* name); 92 GONG DeleteKey(const wchar_t* name);
52 93
53 // Deletes a single value within the key. 94 // Deletes a single value within the key.
54 bool DeleteValue(const wchar_t* name); 95 GONG DeleteValue(const wchar_t* name);
55 96
56 bool ValueExists(const wchar_t* name); 97 bool ValueExists(const wchar_t* name) const;
57 98
58 bool ReadValue(const wchar_t* name, void* data, DWORD* dsize, 99 GONG ReadValue(const wchar_t* name, void* data, DWORD* dsize,
59 DWORD* dtype) const; 100 DWORD* dtype) const;
60 bool ReadValue(const wchar_t* name, std::wstring* value) const; 101 GONG ReadValue(const wchar_t* name, std::wstring* value) const;
61 bool ReadValueDW(const wchar_t* name, DWORD* value) const; 102 GONG ReadValueDW(const wchar_t* name, DWORD* value) const;
103 GONG ReadInt64(const wchar_t* name, int64* value) const;
62 104
63 bool WriteValue(const wchar_t* name, const void* data, DWORD dsize, 105 GONG WriteValue(const wchar_t* name, const void* data, DWORD dsize,
64 DWORD dtype); 106 DWORD dtype);
65 bool WriteValue(const wchar_t* name, const wchar_t* value); 107 GONG WriteValue(const wchar_t* name, const wchar_t* value);
66 bool WriteValue(const wchar_t* name, DWORD value); 108 GONG WriteValue(const wchar_t* name, DWORD value);
67 109
68 // Starts watching the key to see if any of its values have changed. 110 // 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. 111 // The key must have been opened with the KEY_NOTIFY access privilege.
70 bool StartWatching(); 112 GONG StartWatching();
71 113
72 // If StartWatching hasn't been called, always returns false. 114 // If StartWatching hasn't been called, always returns false.
73 // Otherwise, returns true if anything under the key has changed. 115 // Otherwise, returns true if anything under the key has changed.
74 // This can't be const because the |watch_event_| may be refreshed. 116 // This can't be const because the |watch_event_| may be refreshed.
75 bool HasChanged(); 117 bool HasChanged();
76 118
77 // Will automatically be called by destructor if not manually called 119 // Will automatically be called by destructor if not manually called
78 // beforehand. Returns true if it was watching, false otherwise. 120 // beforehand. Returns true if it was watching, false otherwise.
79 bool StopWatching(); 121 GONG StopWatching();
80 122
81 inline bool IsWatching() const { return watch_event_ != 0; } 123 inline bool IsWatching() const { return watch_event_ != 0; }
82 HANDLE watch_event() const { return watch_event_; } 124 HANDLE watch_event() const { return watch_event_; }
83 HKEY Handle() const { return key_; } 125 HKEY Handle() const { return key_; }
84 126
85 private: 127 private:
86 HKEY key_; // The registry key being iterated. 128 HKEY key_; // The registry key being iterated.
87 HANDLE watch_event_; 129 HANDLE watch_event_;
88 130
89 DISALLOW_COPY_AND_ASSIGN(RegKey); 131 DISALLOW_COPY_AND_ASSIGN(RegKey);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 205
164 wchar_t name_[MAX_PATH]; 206 wchar_t name_[MAX_PATH];
165 207
166 DISALLOW_COPY_AND_ASSIGN(RegistryKeyIterator); 208 DISALLOW_COPY_AND_ASSIGN(RegistryKeyIterator);
167 }; 209 };
168 210
169 } // namespace win 211 } // namespace win
170 } // namespace base 212 } // namespace base
171 213
172 #endif // BASE_WIN_REGISTRY_H_ 214 #endif // BASE_WIN_REGISTRY_H_
OLDNEW
« no previous file with comments | « no previous file | base/win/registry.cc » ('j') | chrome/installer/util/delete_reg_value_work_item.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698