| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> |
| 8 |
| 7 #include <string.h> | 9 #include <string.h> |
| 8 | 10 |
| 9 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
| 10 #include "base/json/json_reader.h" | 12 #include "base/json/json_reader.h" |
| 11 #include "base/logging.h" | 13 #include "base/logging.h" |
| 12 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/string_number_conversions.h" | 15 #include "base/string_number_conversions.h" |
| 14 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 15 #include "base/values.h" | 17 #include "base/values.h" |
| 16 #include "base/win/registry.h" | 18 #include "base/win/registry.h" |
| 19 #include "chrome/browser/policy/policy_bundle.h" |
| 20 #include "chrome/browser/policy/policy_map.h" |
| 17 #include "policy/policy_constants.h" | 21 #include "policy/policy_constants.h" |
| 18 | 22 |
| 19 using base::win::RegKey; | 23 using base::win::RegKey; |
| 20 | 24 |
| 21 namespace { | 25 namespace { |
| 22 | 26 |
| 23 bool ReadRegistryStringValue(RegKey* key, const string16& name, | 27 bool ReadRegistryStringValue(RegKey* key, const string16& name, |
| 24 string16* result) { | 28 string16* result) { |
| 25 DWORD value_size = 0; | 29 DWORD value_size = 0; |
| 26 DWORD key_type = 0; | 30 DWORD key_type = 0; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 47 namespace policy { | 51 namespace policy { |
| 48 | 52 |
| 49 ConfigurationPolicyProviderDelegateWin::ConfigurationPolicyProviderDelegateWin( | 53 ConfigurationPolicyProviderDelegateWin::ConfigurationPolicyProviderDelegateWin( |
| 50 const PolicyDefinitionList* policy_definition_list, | 54 const PolicyDefinitionList* policy_definition_list, |
| 51 const string16& registry_key, | 55 const string16& registry_key, |
| 52 PolicyLevel level) | 56 PolicyLevel level) |
| 53 : policy_definition_list_(policy_definition_list), | 57 : policy_definition_list_(policy_definition_list), |
| 54 registry_key_(registry_key), | 58 registry_key_(registry_key), |
| 55 level_(level) {} | 59 level_(level) {} |
| 56 | 60 |
| 57 PolicyMap* ConfigurationPolicyProviderDelegateWin::Load() { | 61 scoped_ptr<PolicyBundle> ConfigurationPolicyProviderDelegateWin::Load() { |
| 58 PolicyMap* result = new PolicyMap(); | 62 scoped_ptr<PolicyBundle> bundle(new PolicyBundle()); |
| 63 PolicyMap& chrome_policy = bundle->Get(POLICY_DOMAIN_CHROME, std::string()); |
| 59 const PolicyDefinitionList::Entry* current; | 64 const PolicyDefinitionList::Entry* current; |
| 60 for (current = policy_definition_list_->begin; | 65 for (current = policy_definition_list_->begin; |
| 61 current != policy_definition_list_->end; | 66 current != policy_definition_list_->end; |
| 62 ++current) { | 67 ++current) { |
| 63 const string16 name(ASCIIToUTF16(current->name)); | 68 const string16 name(ASCIIToUTF16(current->name)); |
| 64 PolicyScope scope = POLICY_SCOPE_MACHINE; | 69 PolicyScope scope = POLICY_SCOPE_MACHINE; |
| 65 Value* value = NULL; | 70 Value* value = NULL; |
| 66 switch (current->value_type) { | 71 switch (current->value_type) { |
| 67 case Value::TYPE_STRING: { | 72 case Value::TYPE_STRING: { |
| 68 string16 string_value; | 73 string16 string_value; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 // support dictionaries. | 109 // support dictionaries. |
| 105 string16 string_value; | 110 string16 string_value; |
| 106 if (GetRegistryPolicyString(name, &string_value, &scope)) | 111 if (GetRegistryPolicyString(name, &string_value, &scope)) |
| 107 value = base::JSONReader::Read(UTF16ToUTF8(string_value)); | 112 value = base::JSONReader::Read(UTF16ToUTF8(string_value)); |
| 108 break; | 113 break; |
| 109 } | 114 } |
| 110 default: | 115 default: |
| 111 NOTREACHED(); | 116 NOTREACHED(); |
| 112 } | 117 } |
| 113 if (value) | 118 if (value) |
| 114 result->Set(current->name, level_, scope, value); | 119 chrome_policy.Set(current->name, level_, scope, value); |
| 115 } | 120 } |
| 116 return result; | 121 return bundle.Pass(); |
| 117 } | 122 } |
| 118 | 123 |
| 119 bool ConfigurationPolicyProviderDelegateWin::GetRegistryPolicyString( | 124 bool ConfigurationPolicyProviderDelegateWin::GetRegistryPolicyString( |
| 120 const string16& name, string16* result, PolicyScope* scope) const { | 125 const string16& name, string16* result, PolicyScope* scope) const { |
| 121 RegKey policy_key(HKEY_LOCAL_MACHINE, registry_key_.c_str(), KEY_READ); | 126 RegKey policy_key(HKEY_LOCAL_MACHINE, registry_key_.c_str(), KEY_READ); |
| 122 // First try the global policy. | 127 // First try the global policy. |
| 123 if (ReadRegistryStringValue(&policy_key, name, result)) { | 128 if (ReadRegistryStringValue(&policy_key, name, result)) { |
| 124 *scope = POLICY_SCOPE_MACHINE; | 129 *scope = POLICY_SCOPE_MACHINE; |
| 125 return true; | 130 return true; |
| 126 } | 131 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 if (policy_key.ReadValueDW(value_name.c_str(), &value) == ERROR_SUCCESS) { | 186 if (policy_key.ReadValueDW(value_name.c_str(), &value) == ERROR_SUCCESS) { |
| 182 *scope = POLICY_SCOPE_USER; | 187 *scope = POLICY_SCOPE_USER; |
| 183 *result = value; | 188 *result = value; |
| 184 return true; | 189 return true; |
| 185 } | 190 } |
| 186 } | 191 } |
| 187 return false; | 192 return false; |
| 188 } | 193 } |
| 189 | 194 |
| 190 } // namespace policy | 195 } // namespace policy |
| OLD | NEW |