| OLD | NEW |
| 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_win.h" | 5 #include "chrome/browser/policy/configuration_policy_provider_win.h" |
| 6 | 6 |
| 7 #include <userenv.h> | 7 #include <userenv.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 | 10 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 | 55 |
| 56 ConfigurationPolicyProviderWin::ConfigurationPolicyProviderWin() { | 56 ConfigurationPolicyProviderWin::ConfigurationPolicyProviderWin() { |
| 57 watcher_.reset(new GroupPolicyChangeWatcher(this)); | 57 watcher_.reset(new GroupPolicyChangeWatcher(this)); |
| 58 } | 58 } |
| 59 | 59 |
| 60 bool ConfigurationPolicyProviderWin::GetRegistryPolicyString( | 60 bool ConfigurationPolicyProviderWin::GetRegistryPolicyString( |
| 61 const string16& name, string16* result) { | 61 const string16& name, string16* result) { |
| 62 string16 path = string16(policy::kRegistrySubKey); | 62 string16 path = string16(policy::kRegistrySubKey); |
| 63 RegKey policy_key; | 63 RegKey policy_key; |
| 64 // First try the global policy. | 64 // First try the global policy. |
| 65 if (policy_key.Open(HKEY_LOCAL_MACHINE, path.c_str())) { | 65 if (policy_key.Open(HKEY_LOCAL_MACHINE, path.c_str(), KEY_READ)) { |
| 66 if (ReadRegistryStringValue(&policy_key, name, result)) | 66 if (ReadRegistryStringValue(&policy_key, name, result)) |
| 67 return true; | 67 return true; |
| 68 policy_key.Close(); | 68 policy_key.Close(); |
| 69 } | 69 } |
| 70 // Fall back on user-specific policy. | 70 // Fall back on user-specific policy. |
| 71 if (!policy_key.Open(HKEY_CURRENT_USER, path.c_str())) | 71 if (!policy_key.Open(HKEY_CURRENT_USER, path.c_str(), KEY_READ)) |
| 72 return false; | 72 return false; |
| 73 return ReadRegistryStringValue(&policy_key, name, result); | 73 return ReadRegistryStringValue(&policy_key, name, result); |
| 74 } | 74 } |
| 75 | 75 |
| 76 bool ConfigurationPolicyProviderWin::ReadRegistryStringValue( | 76 bool ConfigurationPolicyProviderWin::ReadRegistryStringValue( |
| 77 RegKey* key, const string16& name, string16* result) { | 77 RegKey* key, const string16& name, string16* result) { |
| 78 DWORD value_size = 0; | 78 DWORD value_size = 0; |
| 79 DWORD key_type = 0; | 79 DWORD key_type = 0; |
| 80 scoped_array<uint8> buffer; | 80 scoped_array<uint8> buffer; |
| 81 | 81 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 93 key->ReadValue(name.c_str(), buffer.get(), &value_size); | 93 key->ReadValue(name.c_str(), buffer.get(), &value_size); |
| 94 result->assign(reinterpret_cast<const wchar_t*>(buffer.get())); | 94 result->assign(reinterpret_cast<const wchar_t*>(buffer.get())); |
| 95 return true; | 95 return true; |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool ConfigurationPolicyProviderWin::GetRegistryPolicyStringList( | 98 bool ConfigurationPolicyProviderWin::GetRegistryPolicyStringList( |
| 99 const string16& key, ListValue* result) { | 99 const string16& key, ListValue* result) { |
| 100 string16 path = string16(policy::kRegistrySubKey); | 100 string16 path = string16(policy::kRegistrySubKey); |
| 101 path += ASCIIToUTF16("\\") + key; | 101 path += ASCIIToUTF16("\\") + key; |
| 102 RegKey policy_key; | 102 RegKey policy_key; |
| 103 if (!policy_key.Open(HKEY_LOCAL_MACHINE, path.c_str())) { | 103 if (!policy_key.Open(HKEY_LOCAL_MACHINE, path.c_str(), KEY_READ)) { |
| 104 policy_key.Close(); | 104 policy_key.Close(); |
| 105 // Fall back on user-specific policy. | 105 // Fall back on user-specific policy. |
| 106 if (!policy_key.Open(HKEY_CURRENT_USER, path.c_str())) | 106 if (!policy_key.Open(HKEY_CURRENT_USER, path.c_str(), KEY_READ)) |
| 107 return false; | 107 return false; |
| 108 } | 108 } |
| 109 string16 policy_string; | 109 string16 policy_string; |
| 110 int index = 0; | 110 int index = 0; |
| 111 while (ReadRegistryStringValue(&policy_key, base::IntToString16(++index), | 111 while (ReadRegistryStringValue(&policy_key, base::IntToString16(++index), |
| 112 &policy_string)) { | 112 &policy_string)) { |
| 113 result->Append(Value::CreateStringValue(policy_string)); | 113 result->Append(Value::CreateStringValue(policy_string)); |
| 114 } | 114 } |
| 115 return true; | 115 return true; |
| 116 } | 116 } |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 break; | 188 break; |
| 189 } | 189 } |
| 190 default: | 190 default: |
| 191 NOTREACHED(); | 191 NOTREACHED(); |
| 192 return false; | 192 return false; |
| 193 } | 193 } |
| 194 } | 194 } |
| 195 | 195 |
| 196 return true; | 196 return true; |
| 197 } | 197 } |
| OLD | NEW |