Chromium Code Reviews| 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 // Most of this code is copied from various classes in | 5 // Most of this code is copied from various classes in |
| 6 // src/chrome/browser/policy. In particular, look at | 6 // src/chrome/browser/policy. In particular, look at |
| 7 // | 7 // |
| 8 // configuration_policy_provider_delegate_win.{h,cc} | 8 // configuration_policy_provider_delegate_win.{h,cc} |
| 9 // configuration_policy_loader_win.{h,cc} | 9 // configuration_policy_loader_win.{h,cc} |
| 10 // | 10 // |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 105 machine_policy_changed_event_.handle(), this)) { | 105 machine_policy_changed_event_.handle(), this)) { |
| 106 LOG(WARNING) << "Failed to start watch for machine policy change event"; | 106 LOG(WARNING) << "Failed to start watch for machine policy change event"; |
| 107 machine_policy_watcher_failed_ = true; | 107 machine_policy_watcher_failed_ = true; |
| 108 } | 108 } |
| 109 | 109 |
| 110 if (user_policy_watcher_failed_ || machine_policy_watcher_failed_) { | 110 if (user_policy_watcher_failed_ || machine_policy_watcher_failed_) { |
| 111 ScheduleFallbackReloadTask(); | 111 ScheduleFallbackReloadTask(); |
| 112 } | 112 } |
| 113 } | 113 } |
| 114 | 114 |
| 115 bool GetRegistryPolicyInteger(const string16& value_name, | 115 bool GetRegistryPolicyString(const std::string& value_name, |
| 116 std::string* result) const { | |
| 117 string16 value_name_wide = UTF8ToWide(value_name); | |
|
alexeypa (please no reviews)
2012/07/30 22:15:45
string16 -> std::wstring because you are convertin
simonmorris
2012/07/30 23:17:13
Done.
| |
| 118 std::wstring value; | |
| 119 RegKey policy_key(HKEY_LOCAL_MACHINE, kRegistrySubKey, KEY_READ); | |
| 120 if (policy_key.ReadValue(value_name_wide.c_str(), &value) == | |
| 121 ERROR_SUCCESS) { | |
| 122 *result = WideToUTF8(value); | |
| 123 return true; | |
| 124 } | |
| 125 | |
| 126 if (policy_key.Open(HKEY_CURRENT_USER, kRegistrySubKey, KEY_READ) == | |
| 127 ERROR_SUCCESS) { | |
| 128 if (policy_key.ReadValue(value_name_wide.c_str(), &value) == | |
| 129 ERROR_SUCCESS) { | |
| 130 *result = WideToUTF8(value); | |
| 131 return true; | |
| 132 } | |
| 133 } | |
| 134 return false; | |
| 135 } | |
| 136 | |
| 137 bool GetRegistryPolicyInteger(const std::string& value_name, | |
| 116 uint32* result) const { | 138 uint32* result) const { |
| 139 string16 value_name_wide = UTF8ToWide(value_name); | |
| 117 DWORD value = 0; | 140 DWORD value = 0; |
| 118 RegKey policy_key(HKEY_LOCAL_MACHINE, kRegistrySubKey, KEY_READ); | 141 RegKey policy_key(HKEY_LOCAL_MACHINE, kRegistrySubKey, KEY_READ); |
| 119 if (policy_key.ReadValueDW(value_name.c_str(), &value) == ERROR_SUCCESS) { | 142 if (policy_key.ReadValueDW(value_name_wide.c_str(), &value) == |
| 143 ERROR_SUCCESS) { | |
| 120 *result = value; | 144 *result = value; |
| 121 return true; | 145 return true; |
| 122 } | 146 } |
| 123 | 147 |
| 124 if (policy_key.Open(HKEY_CURRENT_USER, kRegistrySubKey, KEY_READ) == | 148 if (policy_key.Open(HKEY_CURRENT_USER, kRegistrySubKey, KEY_READ) == |
| 125 ERROR_SUCCESS) { | 149 ERROR_SUCCESS) { |
| 126 if (policy_key.ReadValueDW(value_name.c_str(), &value) == ERROR_SUCCESS) { | 150 if (policy_key.ReadValueDW(value_name_wide.c_str(), &value) == |
| 151 ERROR_SUCCESS) { | |
| 127 *result = value; | 152 *result = value; |
| 128 return true; | 153 return true; |
| 129 } | 154 } |
| 130 } | 155 } |
| 131 return false; | 156 return false; |
| 132 } | 157 } |
| 133 | 158 |
| 134 bool GetRegistryPolicyBoolean(const string16& value_name, | 159 bool GetRegistryPolicyBoolean(const std::string& value_name, |
| 135 bool* result) const { | 160 bool* result) const { |
| 136 uint32 local_result = 0; | 161 uint32 local_result = 0; |
| 137 bool ret = GetRegistryPolicyInteger(value_name, &local_result); | 162 bool ret = GetRegistryPolicyInteger(value_name, &local_result); |
| 138 if (ret) | 163 if (ret) |
| 139 *result = local_result != 0; | 164 *result = local_result != 0; |
| 140 return ret; | 165 return ret; |
| 141 } | 166 } |
| 142 | 167 |
| 143 base::DictionaryValue* Load() { | 168 base::DictionaryValue* Load() { |
| 144 base::DictionaryValue* policy = new base::DictionaryValue(); | 169 base::DictionaryValue* policy = new base::DictionaryValue(); |
| 145 | 170 |
| 146 for (int i = 0; i < kBooleanPolicyNamesNum; ++i) { | 171 for (int i = 0; i < kBooleanPolicyNamesNum; ++i) { |
| 147 const char* policy_name = kBooleanPolicyNames[i]; | 172 const char* policy_name = kBooleanPolicyNames[i]; |
| 148 bool bool_value; | 173 bool bool_value; |
| 149 const string16 name(ASCIIToUTF16(policy_name)); | 174 if (GetRegistryPolicyBoolean(policy_name, &bool_value)) { |
| 150 if (GetRegistryPolicyBoolean(name, &bool_value)) { | |
| 151 policy->SetBoolean(policy_name, bool_value); | 175 policy->SetBoolean(policy_name, bool_value); |
| 152 } | 176 } |
| 153 } | 177 } |
| 154 // TODO(simonmorris): Read policies whose names are in kStringPolicyNames. | 178 for (int i = 0; i < kStringPolicyNamesNum; ++i) { |
| 155 | 179 const char* policy_name = kStringPolicyNames[i]; |
| 180 std::string string_value; | |
| 181 if (GetRegistryPolicyString(policy_name, &string_value)) { | |
| 182 policy->SetString(policy_name, string_value); | |
| 183 } | |
| 184 } | |
| 156 return policy; | 185 return policy; |
| 157 } | 186 } |
| 158 | 187 |
| 159 // Post a reload notification and update the watch machinery. | 188 // Post a reload notification and update the watch machinery. |
| 160 void Reload() { | 189 void Reload() { |
| 161 DCHECK(OnPolicyWatcherThread()); | 190 DCHECK(OnPolicyWatcherThread()); |
| 162 SetupWatches(); | 191 SetupWatches(); |
| 163 scoped_ptr<DictionaryValue> new_policy(Load()); | 192 scoped_ptr<DictionaryValue> new_policy(Load()); |
| 164 UpdatePolicies(new_policy.get()); | 193 UpdatePolicies(new_policy.get()); |
| 165 } | 194 } |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 182 bool machine_policy_watcher_failed_; | 211 bool machine_policy_watcher_failed_; |
| 183 }; | 212 }; |
| 184 | 213 |
| 185 PolicyWatcher* PolicyWatcher::Create( | 214 PolicyWatcher* PolicyWatcher::Create( |
| 186 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { | 215 scoped_refptr<base::SingleThreadTaskRunner> task_runner) { |
| 187 return new PolicyWatcherWin(task_runner); | 216 return new PolicyWatcherWin(task_runner); |
| 188 } | 217 } |
| 189 | 218 |
| 190 } // namespace policy_hack | 219 } // namespace policy_hack |
| 191 } // namespace remoting | 220 } // namespace remoting |
| OLD | NEW |