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

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
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;}
Sigurður Ásgeirsson 2011/01/12 14:04:19 nit: ws around {}
amit 2011/01/14 05:23:33 Done.
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
14 namespace base { 47 namespace base {
15 namespace win { 48 namespace win {
16 49
17 // Utility class to read, write and manipulate the Windows Registry. 50 // Utility class to read, write and manipulate the Windows Registry.
18 // Registry vocabulary primer: a "key" is like a folder, in which there 51 // 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. 52 // are "values", which are <name, data> pairs, with an associated data type.
20 class RegKey { 53 class RegKey {
21 public: 54 public:
22 RegKey(); 55 RegKey();
23 RegKey(HKEY rootkey, const wchar_t* subkey, REGSAM access); 56 RegKey(HKEY rootkey, const wchar_t* subkey, REGSAM access);
24 ~RegKey(); 57 ~RegKey();
25 58
26 bool Create(HKEY rootkey, const wchar_t* subkey, REGSAM access); 59 GONG Create(HKEY rootkey, const wchar_t* subkey, REGSAM access);
27 60
28 bool CreateWithDisposition(HKEY rootkey, const wchar_t* subkey, 61 GONG CreateWithDisposition(HKEY rootkey, const wchar_t* subkey,
29 DWORD* disposition, REGSAM access); 62 DWORD* disposition, REGSAM access);
30 63
31 bool Open(HKEY rootkey, const wchar_t* subkey, REGSAM access); 64 GONG Open(HKEY rootkey, const wchar_t* subkey, REGSAM access);
32 65
33 // Creates a subkey or open it if it already exists. 66 // Creates a subkey or open it if it already exists.
34 bool CreateKey(const wchar_t* name, REGSAM access); 67 GONG CreateKey(const wchar_t* name, REGSAM access);
35 68
36 // Opens a subkey 69 // Opens a subkey
37 bool OpenKey(const wchar_t* name, REGSAM access); 70 GONG OpenKey(const wchar_t* name, REGSAM access);
38 71
39 void Close(); 72 void Close();
40 73
41 DWORD ValueCount() const; 74 DWORD ValueCount() const;
42 75
43 // Determine the nth value's name. 76 // Determine the nth value's name.
44 bool ReadName(int index, std::wstring* name) const; 77 GONG ReadName(int index, std::wstring* name) const;
45 78
46 // True while the key is valid. 79 // True while the key is valid.
47 bool Valid() const { return key_ != NULL; } 80 bool Valid() const { return key_ != NULL; }
48 81
49 // Kill a key and everything that live below it; please be careful when using 82 // Kill a key and everything that live below it; please be careful when using
50 // it. 83 // it.
51 bool DeleteKey(const wchar_t* name); 84 GONG DeleteKey(const wchar_t* name);
52 85
53 // Deletes a single value within the key. 86 // Deletes a single value within the key.
54 bool DeleteValue(const wchar_t* name); 87 GONG DeleteValue(const wchar_t* name);
55 88
56 bool ValueExists(const wchar_t* name); 89 bool ValueExists(const wchar_t* name) const;
57 90
58 bool ReadValue(const wchar_t* name, void* data, DWORD* dsize, 91 GONG ReadValue(const wchar_t* name, void* data, DWORD* dsize,
59 DWORD* dtype) const; 92 DWORD* dtype) const;
60 bool ReadValue(const wchar_t* name, std::wstring* value) const; 93 GONG ReadValue(const wchar_t* name, std::wstring* value) const;
61 bool ReadValueDW(const wchar_t* name, DWORD* value) const; 94 GONG ReadValueDW(const wchar_t* name, DWORD* value) const;
95 GONG ReadInt64(const wchar_t* name, int64* value) const;
62 96
63 bool WriteValue(const wchar_t* name, const void* data, DWORD dsize, 97 GONG WriteValue(const wchar_t* name, const void* data, DWORD dsize,
64 DWORD dtype); 98 DWORD dtype);
65 bool WriteValue(const wchar_t* name, const wchar_t* value); 99 GONG WriteValue(const wchar_t* name, const wchar_t* value);
66 bool WriteValue(const wchar_t* name, DWORD value); 100 GONG WriteValue(const wchar_t* name, DWORD value);
67 101
68 // Starts watching the key to see if any of its values have changed. 102 // 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. 103 // The key must have been opened with the KEY_NOTIFY access privilege.
70 bool StartWatching(); 104 GONG StartWatching();
71 105
72 // If StartWatching hasn't been called, always returns false. 106 // If StartWatching hasn't been called, always returns false.
73 // Otherwise, returns true if anything under the key has changed. 107 // Otherwise, returns true if anything under the key has changed.
74 // This can't be const because the |watch_event_| may be refreshed. 108 // This can't be const because the |watch_event_| may be refreshed.
75 bool HasChanged(); 109 bool HasChanged();
76 110
77 // Will automatically be called by destructor if not manually called 111 // Will automatically be called by destructor if not manually called
78 // beforehand. Returns true if it was watching, false otherwise. 112 // beforehand. Returns true if it was watching, false otherwise.
79 bool StopWatching(); 113 GONG StopWatching();
80 114
81 inline bool IsWatching() const { return watch_event_ != 0; } 115 inline bool IsWatching() const { return watch_event_ != 0; }
82 HANDLE watch_event() const { return watch_event_; } 116 HANDLE watch_event() const { return watch_event_; }
83 HKEY Handle() const { return key_; } 117 HKEY Handle() const { return key_; }
84 118
85 private: 119 private:
86 HKEY key_; // The registry key being iterated. 120 HKEY key_; // The registry key being iterated.
87 HANDLE watch_event_; 121 HANDLE watch_event_;
88 122
89 DISALLOW_COPY_AND_ASSIGN(RegKey); 123 DISALLOW_COPY_AND_ASSIGN(RegKey);
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 197
164 wchar_t name_[MAX_PATH]; 198 wchar_t name_[MAX_PATH];
165 199
166 DISALLOW_COPY_AND_ASSIGN(RegistryKeyIterator); 200 DISALLOW_COPY_AND_ASSIGN(RegistryKeyIterator);
167 }; 201 };
168 202
169 } // namespace win 203 } // namespace win
170 } // namespace base 204 } // namespace base
171 205
172 #endif // BASE_WIN_REGISTRY_H_ 206 #endif // BASE_WIN_REGISTRY_H_
OLDNEW
« no previous file with comments | « no previous file | base/win/registry.cc » ('j') | chrome/browser/policy/configuration_policy_provider_delegate_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698