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

Side by Side Diff: chrome/browser/policy/configuration_policy_provider_delegate_win.cc

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 | « chrome/browser/plugin_service.cc ('k') | chrome/browser/rlz/rlz_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Property Changes:
Added: svn:eol-style
+ LF
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 #include "chrome/browser/policy/configuration_policy_provider_delegate_win.h" 5 #include "chrome/browser/policy/configuration_policy_provider_delegate_win.h"
6 6
7 #include "base/string_number_conversions.h" 7 #include "base/string_number_conversions.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "base/win/registry.h" 9 #include "base/win/registry.h"
10 #include "chrome/common/policy_constants.h" 10 #include "chrome/common/policy_constants.h"
11 11
12 using base::win::RegKey; 12 using base::win::RegKey;
13 13
14 namespace { 14 namespace {
15 15
16 bool ReadRegistryStringValue(RegKey* key, const string16& name, 16 bool ReadRegistryStringValue(RegKey* key, const string16& name,
17 string16* result) { 17 string16* result) {
18 DWORD value_size = 0; 18 DWORD value_size = 0;
19 DWORD key_type = 0; 19 DWORD key_type = 0;
20 scoped_array<uint8> buffer; 20 scoped_array<uint8> buffer;
21 21
22 if (!key->ReadValue(name.c_str(), 0, &value_size, &key_type)) 22 if (key->ReadValue(name.c_str(), 0, &value_size, &key_type) != ERROR_SUCCESS)
23 return false; 23 return false;
24 if (key_type != REG_SZ) 24 if (key_type != REG_SZ)
25 return false; 25 return false;
26 26
27 // According to the Microsoft documentation, the string 27 // According to the Microsoft documentation, the string
28 // buffer may not be explicitly 0-terminated. Allocate a 28 // buffer may not be explicitly 0-terminated. Allocate a
29 // slightly larger buffer and pre-fill to zeros to guarantee 29 // slightly larger buffer and pre-fill to zeros to guarantee
30 // the 0-termination. 30 // the 0-termination.
31 buffer.reset(new uint8[value_size + 2]); 31 buffer.reset(new uint8[value_size + 2]);
32 memset(buffer.get(), 0, value_size + 2); 32 memset(buffer.get(), 0, value_size + 2);
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
82 } 82 }
83 default: 83 default:
84 NOTREACHED(); 84 NOTREACHED();
85 } 85 }
86 } 86 }
87 return result; 87 return result;
88 } 88 }
89 89
90 bool ConfigurationPolicyProviderDelegateWin::GetRegistryPolicyString( 90 bool ConfigurationPolicyProviderDelegateWin::GetRegistryPolicyString(
91 const string16& name, string16* result) const { 91 const string16& name, string16* result) const {
92 string16 path = string16(kRegistrySubKey); 92 RegKey policy_key(HKEY_LOCAL_MACHINE, kRegistrySubKey, KEY_READ);
93 RegKey policy_key;
94 // First try the global policy. 93 // First try the global policy.
95 if (policy_key.Open(HKEY_LOCAL_MACHINE, path.c_str(), KEY_READ)) { 94 if (ReadRegistryStringValue(&policy_key, name, result))
96 if (ReadRegistryStringValue(&policy_key, name, result)) 95 return true;
97 return true; 96
98 policy_key.Close();
99 }
100 // Fall back on user-specific policy. 97 // Fall back on user-specific policy.
101 if (!policy_key.Open(HKEY_CURRENT_USER, path.c_str(), KEY_READ)) 98 if (policy_key.Open(HKEY_CURRENT_USER, kRegistrySubKey,
99 KEY_READ) != ERROR_SUCCESS)
102 return false; 100 return false;
103 return ReadRegistryStringValue(&policy_key, name, result); 101 return ReadRegistryStringValue(&policy_key, name, result);
104 } 102 }
105 103
106 bool ConfigurationPolicyProviderDelegateWin::GetRegistryPolicyStringList( 104 bool ConfigurationPolicyProviderDelegateWin::GetRegistryPolicyStringList(
107 const string16& key, ListValue* result) const { 105 const string16& key, ListValue* result) const {
108 string16 path = string16(kRegistrySubKey); 106 string16 path = string16(kRegistrySubKey);
109 path += ASCIIToUTF16("\\") + key; 107 path += ASCIIToUTF16("\\") + key;
110 RegKey policy_key; 108 RegKey policy_key;
111 if (!policy_key.Open(HKEY_LOCAL_MACHINE, path.c_str(), KEY_READ)) { 109 if (policy_key.Open(HKEY_LOCAL_MACHINE, path.c_str(), KEY_READ) !=
112 policy_key.Close(); 110 ERROR_SUCCESS) {
113 // Fall back on user-specific policy. 111 // Fall back on user-specific policy.
114 if (!policy_key.Open(HKEY_CURRENT_USER, path.c_str(), KEY_READ)) 112 if (policy_key.Open(HKEY_CURRENT_USER, path.c_str(), KEY_READ) !=
113 ERROR_SUCCESS)
115 return false; 114 return false;
116 } 115 }
117 string16 policy_string; 116 string16 policy_string;
118 int index = 0; 117 int index = 0;
119 while (ReadRegistryStringValue(&policy_key, base::IntToString16(++index), 118 while (ReadRegistryStringValue(&policy_key, base::IntToString16(++index),
120 &policy_string)) { 119 &policy_string)) {
121 result->Append(Value::CreateStringValue(policy_string)); 120 result->Append(Value::CreateStringValue(policy_string));
122 } 121 }
123 return true; 122 return true;
124 } 123 }
125 124
126 bool ConfigurationPolicyProviderDelegateWin::GetRegistryPolicyBoolean( 125 bool ConfigurationPolicyProviderDelegateWin::GetRegistryPolicyBoolean(
127 const string16& value_name, bool* result) const { 126 const string16& value_name, bool* result) const {
128 DWORD value; 127 uint32 local_result = 0;
129 RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, kRegistrySubKey, KEY_READ); 128 bool ret = GetRegistryPolicyInteger(value_name, &local_result);
130 if (hkcu_policy_key.ReadValueDW(value_name.c_str(), &value)) { 129 if (ret)
131 *result = value != 0; 130 *result = local_result != 0;
132 return true; 131 return ret;
133 }
134
135 RegKey hklm_policy_key(HKEY_CURRENT_USER, kRegistrySubKey, KEY_READ);
136 if (hklm_policy_key.ReadValueDW(value_name.c_str(), &value)) {
137 *result = value != 0;
138 return true;
139 }
140 return false;
141 } 132 }
142 133
143 bool ConfigurationPolicyProviderDelegateWin::GetRegistryPolicyInteger( 134 bool ConfigurationPolicyProviderDelegateWin::GetRegistryPolicyInteger(
144 const string16& value_name, uint32* result) const { 135 const string16& value_name, uint32* result) const {
145 DWORD value; 136 DWORD value = 0;
146 RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, kRegistrySubKey, KEY_READ); 137 RegKey policy_key(HKEY_LOCAL_MACHINE, kRegistrySubKey, KEY_READ);
147 if (hkcu_policy_key.ReadValueDW(value_name.c_str(), &value)) { 138 if (policy_key.ReadValueDW(value_name.c_str(), &value) == ERROR_SUCCESS) {
148 *result = value; 139 *result = value;
149 return true; 140 return true;
150 } 141 }
151 142
152 RegKey hklm_policy_key(HKEY_CURRENT_USER, kRegistrySubKey, KEY_READ); 143 if (policy_key.Open(HKEY_CURRENT_USER, kRegistrySubKey, KEY_READ) ==
153 if (hklm_policy_key.ReadValueDW(value_name.c_str(), &value)) { 144 ERROR_SUCCESS) {
154 *result = value; 145 if (policy_key.ReadValueDW(value_name.c_str(), &value) == ERROR_SUCCESS) {
155 return true; 146 *result = value;
147 return true;
148 }
156 } 149 }
157 return false; 150 return false;
158 } 151 }
159 152
160 } // namespace policy 153 } // namespace policy
OLDNEW
« no previous file with comments | « chrome/browser/plugin_service.cc ('k') | chrome/browser/rlz/rlz_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698