| 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/configuration_policy_provider_win.h" | 5 #include "chrome/browser/configuration_policy_provider_win.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/registry.h" | 10 #include "base/registry.h" |
| 11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
| 12 #include "base/sys_string_conversions.h" | 12 #include "base/sys_string_conversions.h" |
| 13 #include "base/values.h" | 13 #include "base/values.h" |
| 14 | 14 |
| 15 const wchar_t WinConfigurationPolicyProvider::kHomepageRegistryValueName[] = | 15 const wchar_t ConfigurationPolicyProviderWin::kHomepageRegistryValueName[] = |
| 16 L"Homepage"; | 16 L"Homepage"; |
| 17 const wchar_t WinConfigurationPolicyProvider:: | 17 const wchar_t ConfigurationPolicyProviderWin:: |
| 18 kHomepageIsNewTabPageRegistryValueName[] = L"HomepageIsNewTabPage"; | 18 kHomepageIsNewTabPageRegistryValueName[] = L"HomepageIsNewTabPage"; |
| 19 const wchar_t WinConfigurationPolicyProvider::kCookiesModeRegistryValueName[] = | 19 const wchar_t ConfigurationPolicyProviderWin::kCookiesModeRegistryValueName[] = |
| 20 L"CookiesMode"; | 20 L"CookiesMode"; |
| 21 | 21 |
| 22 #if defined(GOOGLE_CHROME_BUILD) | 22 #if defined(GOOGLE_CHROME_BUILD) |
| 23 const wchar_t WinConfigurationPolicyProvider::kPolicyRegistrySubKey[] = | 23 const wchar_t ConfigurationPolicyProviderWin::kPolicyRegistrySubKey[] = |
| 24 L"SOFTWARE\\Policies\\Google\\Google Chrome"; | 24 L"SOFTWARE\\Policies\\Google\\Google Chrome"; |
| 25 #else | 25 #else |
| 26 const wchar_t WinConfigurationPolicyProvider::kPolicyRegistrySubKey[] = | 26 const wchar_t ConfigurationPolicyProviderWin::kPolicyRegistrySubKey[] = |
| 27 L"SOFTWARE\\Policies\\Chromium"; | 27 L"SOFTWARE\\Policies\\Chromium"; |
| 28 #endif | 28 #endif |
| 29 | 29 |
| 30 WinConfigurationPolicyProvider::WinConfigurationPolicyProvider() { | 30 ConfigurationPolicyProviderWin::ConfigurationPolicyProviderWin() { |
| 31 } | 31 } |
| 32 | 32 |
| 33 bool WinConfigurationPolicyProvider::GetRegistryPolicyString( | 33 bool ConfigurationPolicyProviderWin::GetRegistryPolicyString( |
| 34 const wchar_t* value_name, string16* result) { | 34 const wchar_t* value_name, string16* result) { |
| 35 DWORD value_size = 0; | 35 DWORD value_size = 0; |
| 36 DWORD key_type = 0; | 36 DWORD key_type = 0; |
| 37 scoped_array<uint8> buffer; | 37 scoped_array<uint8> buffer; |
| 38 RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, kPolicyRegistrySubKey); | 38 RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, kPolicyRegistrySubKey); |
| 39 if (hkcu_policy_key.ReadValue(value_name, 0, &value_size, &key_type)) { | 39 if (hkcu_policy_key.ReadValue(value_name, 0, &value_size, &key_type)) { |
| 40 if (key_type != REG_SZ) | 40 if (key_type != REG_SZ) |
| 41 return false; | 41 return false; |
| 42 // According to the Microsoft documentation, the string | 42 // According to the Microsoft documentation, the string |
| 43 // buffer may not be explicitly 0-terminated. Allocate a | 43 // buffer may not be explicitly 0-terminated. Allocate a |
| (...skipping 16 matching lines...) Expand all Loading... |
| 60 hklm_policy_key.ReadValue(value_name, buffer.get(), &value_size); | 60 hklm_policy_key.ReadValue(value_name, buffer.get(), &value_size); |
| 61 } else { | 61 } else { |
| 62 return false; | 62 return false; |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 result->assign(reinterpret_cast<const wchar_t*>(buffer.get())); | 66 result->assign(reinterpret_cast<const wchar_t*>(buffer.get())); |
| 67 return true; | 67 return true; |
| 68 } | 68 } |
| 69 | 69 |
| 70 bool WinConfigurationPolicyProvider::GetRegistryPolicyBoolean( | 70 bool ConfigurationPolicyProviderWin::GetRegistryPolicyBoolean( |
| 71 const wchar_t* value_name, bool* result) { | 71 const wchar_t* value_name, bool* result) { |
| 72 DWORD value; | 72 DWORD value; |
| 73 RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, kPolicyRegistrySubKey); | 73 RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, kPolicyRegistrySubKey); |
| 74 if (hkcu_policy_key.ReadValueDW(value_name, &value)) { | 74 if (hkcu_policy_key.ReadValueDW(value_name, &value)) { |
| 75 *result = value != 0; | 75 *result = value != 0; |
| 76 return true; | 76 return true; |
| 77 } | 77 } |
| 78 | 78 |
| 79 RegKey hklm_policy_key(HKEY_CURRENT_USER, kPolicyRegistrySubKey); | 79 RegKey hklm_policy_key(HKEY_CURRENT_USER, kPolicyRegistrySubKey); |
| 80 if (hklm_policy_key.ReadValueDW(value_name, &value)) { | 80 if (hklm_policy_key.ReadValueDW(value_name, &value)) { |
| 81 *result = value != 0; | 81 *result = value != 0; |
| 82 return true; | 82 return true; |
| 83 } | 83 } |
| 84 return false; | 84 return false; |
| 85 } | 85 } |
| 86 | 86 |
| 87 bool WinConfigurationPolicyProvider::GetRegistryPolicyInteger( | 87 bool ConfigurationPolicyProviderWin::GetRegistryPolicyInteger( |
| 88 const wchar_t* value_name, uint32* result) { | 88 const wchar_t* value_name, uint32* result) { |
| 89 DWORD value; | 89 DWORD value; |
| 90 RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, kPolicyRegistrySubKey); | 90 RegKey hkcu_policy_key(HKEY_LOCAL_MACHINE, kPolicyRegistrySubKey); |
| 91 if (hkcu_policy_key.ReadValueDW(value_name, &value)) { | 91 if (hkcu_policy_key.ReadValueDW(value_name, &value)) { |
| 92 *result = value; | 92 *result = value; |
| 93 return true; | 93 return true; |
| 94 } | 94 } |
| 95 | 95 |
| 96 RegKey hklm_policy_key(HKEY_CURRENT_USER, kPolicyRegistrySubKey); | 96 RegKey hklm_policy_key(HKEY_CURRENT_USER, kPolicyRegistrySubKey); |
| 97 if (hklm_policy_key.ReadValueDW(value_name, &value)) { | 97 if (hklm_policy_key.ReadValueDW(value_name, &value)) { |
| 98 *result = value; | 98 *result = value; |
| 99 return true; | 99 return true; |
| 100 } | 100 } |
| 101 return false; | 101 return false; |
| 102 } | 102 } |
| 103 | 103 |
| 104 const WinConfigurationPolicyProvider::RegistryPolicyMapEntry | 104 const ConfigurationPolicyProviderWin::RegistryPolicyMapEntry |
| 105 WinConfigurationPolicyProvider::registry_to_policy_map_[] = { | 105 ConfigurationPolicyProviderWin::registry_to_policy_map_[] = { |
| 106 { Value::TYPE_STRING, | 106 { Value::TYPE_STRING, |
| 107 ConfigurationPolicyStore::kPolicyHomePage, | 107 ConfigurationPolicyStore::kPolicyHomePage, |
| 108 kHomepageRegistryValueName }, | 108 kHomepageRegistryValueName }, |
| 109 { Value::TYPE_BOOLEAN, | 109 { Value::TYPE_BOOLEAN, |
| 110 ConfigurationPolicyStore::kPolicyHomepageIsNewTabPage, | 110 ConfigurationPolicyStore::kPolicyHomepageIsNewTabPage, |
| 111 kHomepageIsNewTabPageRegistryValueName }, | 111 kHomepageIsNewTabPageRegistryValueName }, |
| 112 { Value::TYPE_INTEGER, | 112 { Value::TYPE_INTEGER, |
| 113 ConfigurationPolicyStore::kPolicyCookiesMode, | 113 ConfigurationPolicyStore::kPolicyCookiesMode, |
| 114 kCookiesModeRegistryValueName }, | 114 kCookiesModeRegistryValueName }, |
| 115 }; | 115 }; |
| 116 | 116 |
| 117 bool WinConfigurationPolicyProvider::Provide( | 117 bool ConfigurationPolicyProviderWin::Provide( |
| 118 ConfigurationPolicyStore* store) { | 118 ConfigurationPolicyStore* store) { |
| 119 const RegistryPolicyMapEntry* current; | 119 const RegistryPolicyMapEntry* current; |
| 120 const RegistryPolicyMapEntry* end = registry_to_policy_map_ + | 120 const RegistryPolicyMapEntry* end = registry_to_policy_map_ + |
| 121 arraysize(registry_to_policy_map_); | 121 arraysize(registry_to_policy_map_); |
| 122 | 122 |
| 123 for (current = registry_to_policy_map_; current != end; ++current) { | 123 for (current = registry_to_policy_map_; current != end; ++current) { |
| 124 std::wstring string_value; | 124 std::wstring string_value; |
| 125 uint32 int_value; | 125 uint32 int_value; |
| 126 bool bool_value; | 126 bool bool_value; |
| 127 switch (current->value_type) { | 127 switch (current->value_type) { |
| (...skipping 21 matching lines...) Expand all Loading... |
| 149 break; | 149 break; |
| 150 default: | 150 default: |
| 151 NOTREACHED(); | 151 NOTREACHED(); |
| 152 return false; | 152 return false; |
| 153 } | 153 } |
| 154 } | 154 } |
| 155 | 155 |
| 156 return true; | 156 return true; |
| 157 } | 157 } |
| 158 | 158 |
| OLD | NEW |