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/policy_loader_win.h" | 5 #include "chrome/browser/policy/policy_loader_win.h" |
6 | 6 |
7 #include <rpc.h> // For struct GUID | 7 #include <rpc.h> // For struct GUID |
8 #include <shlwapi.h> // For PathIsUNC() | 8 #include <shlwapi.h> // For PathIsUNC() |
9 #include <userenv.h> // For GPO functions | 9 #include <userenv.h> // For GPO functions |
10 #include <windows.h> | 10 #include <windows.h> |
(...skipping 15 matching lines...) Expand all Loading... |
26 #include "base/sequenced_task_runner.h" | 26 #include "base/sequenced_task_runner.h" |
27 #include "base/stl_util.h" | 27 #include "base/stl_util.h" |
28 #include "base/strings/string16.h" | 28 #include "base/strings/string16.h" |
29 #include "base/strings/string_util.h" | 29 #include "base/strings/string_util.h" |
30 #include "chrome/browser/policy/policy_bundle.h" | 30 #include "chrome/browser/policy/policy_bundle.h" |
31 #include "chrome/browser/policy/policy_load_status.h" | 31 #include "chrome/browser/policy/policy_load_status.h" |
32 #include "chrome/browser/policy/policy_map.h" | 32 #include "chrome/browser/policy/policy_map.h" |
33 #include "chrome/browser/policy/preg_parser_win.h" | 33 #include "chrome/browser/policy/preg_parser_win.h" |
34 #include "chrome/browser/policy/registry_dict_win.h" | 34 #include "chrome/browser/policy/registry_dict_win.h" |
35 #include "components/json_schema/json_schema_constants.h" | 35 #include "components/json_schema/json_schema_constants.h" |
| 36 #include "components/policy/core/common/policy_namespace.h" |
| 37 #include "components/policy/core/common/schema.h" |
36 #include "policy/policy_constants.h" | 38 #include "policy/policy_constants.h" |
37 | 39 |
38 namespace schema = json_schema_constants; | 40 namespace schema = json_schema_constants; |
39 | 41 |
40 namespace policy { | 42 namespace policy { |
41 | 43 |
42 namespace { | 44 namespace { |
43 | 45 |
44 const char kKeyMandatory[] = "policy"; | 46 const char kKeyMandatory[] = "policy"; |
45 const char kKeyRecommended[] = "recommended"; | 47 const char kKeyRecommended[] = "recommended"; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 policy->LoadFrom(policy_dict, level, scope); | 205 policy->LoadFrom(policy_dict, level, scope); |
204 } | 206 } |
205 | 207 |
206 } // namespace | 208 } // namespace |
207 | 209 |
208 const base::FilePath::CharType PolicyLoaderWin::kPRegFileName[] = | 210 const base::FilePath::CharType PolicyLoaderWin::kPRegFileName[] = |
209 FILE_PATH_LITERAL("Registry.pol"); | 211 FILE_PATH_LITERAL("Registry.pol"); |
210 | 212 |
211 PolicyLoaderWin::PolicyLoaderWin( | 213 PolicyLoaderWin::PolicyLoaderWin( |
212 scoped_refptr<base::SequencedTaskRunner> task_runner, | 214 scoped_refptr<base::SequencedTaskRunner> task_runner, |
213 const PolicyDefinitionList* policy_list, | |
214 const string16& chrome_policy_key, | 215 const string16& chrome_policy_key, |
215 AppliedGPOListProvider* gpo_provider) | 216 AppliedGPOListProvider* gpo_provider) |
216 : AsyncPolicyLoader(task_runner), | 217 : AsyncPolicyLoader(task_runner), |
217 is_initialized_(false), | 218 is_initialized_(false), |
218 policy_list_(policy_list), | |
219 chrome_policy_key_(chrome_policy_key), | 219 chrome_policy_key_(chrome_policy_key), |
220 gpo_provider_(gpo_provider), | 220 gpo_provider_(gpo_provider), |
221 user_policy_changed_event_(false, false), | 221 user_policy_changed_event_(false, false), |
222 machine_policy_changed_event_(false, false), | 222 machine_policy_changed_event_(false, false), |
223 user_policy_watcher_failed_(false), | 223 user_policy_watcher_failed_(false), |
224 machine_policy_watcher_failed_(false) { | 224 machine_policy_watcher_failed_(false) { |
225 if (!::RegisterGPNotification(user_policy_changed_event_.handle(), false)) { | 225 if (!::RegisterGPNotification(user_policy_changed_event_.handle(), false)) { |
226 DPLOG(WARNING) << "Failed to register user group policy notification"; | 226 DPLOG(WARNING) << "Failed to register user group policy notification"; |
227 user_policy_watcher_failed_ = true; | 227 user_policy_watcher_failed_ = true; |
228 } | 228 } |
229 if (!::RegisterGPNotification(machine_policy_changed_event_.handle(), true)) { | 229 if (!::RegisterGPNotification(machine_policy_changed_event_.handle(), true)) { |
230 DPLOG(WARNING) << "Failed to register machine group policy notification."; | 230 DPLOG(WARNING) << "Failed to register machine group policy notification."; |
231 machine_policy_watcher_failed_ = true; | 231 machine_policy_watcher_failed_ = true; |
232 } | 232 } |
233 } | 233 } |
234 | 234 |
235 PolicyLoaderWin::~PolicyLoaderWin() { | 235 PolicyLoaderWin::~PolicyLoaderWin() { |
236 if (!user_policy_watcher_failed_) { | 236 if (!user_policy_watcher_failed_) { |
237 ::UnregisterGPNotification(user_policy_changed_event_.handle()); | 237 ::UnregisterGPNotification(user_policy_changed_event_.handle()); |
238 user_policy_watcher_.StopWatching(); | 238 user_policy_watcher_.StopWatching(); |
239 } | 239 } |
240 if (!machine_policy_watcher_failed_) { | 240 if (!machine_policy_watcher_failed_) { |
241 ::UnregisterGPNotification(machine_policy_changed_event_.handle()); | 241 ::UnregisterGPNotification(machine_policy_changed_event_.handle()); |
242 machine_policy_watcher_.StopWatching(); | 242 machine_policy_watcher_.StopWatching(); |
243 } | 243 } |
244 } | 244 } |
245 | 245 |
246 // static | 246 // static |
247 scoped_ptr<PolicyLoaderWin> PolicyLoaderWin::Create( | 247 scoped_ptr<PolicyLoaderWin> PolicyLoaderWin::Create( |
248 scoped_refptr<base::SequencedTaskRunner> task_runner, | 248 scoped_refptr<base::SequencedTaskRunner> task_runner) { |
249 const PolicyDefinitionList* policy_list) { | |
250 return make_scoped_ptr( | 249 return make_scoped_ptr( |
251 new PolicyLoaderWin(task_runner, policy_list, kRegistryChromePolicyKey, | 250 new PolicyLoaderWin(task_runner, |
| 251 kRegistryChromePolicyKey, |
252 g_win_gpo_list_provider.Pointer())); | 252 g_win_gpo_list_provider.Pointer())); |
253 } | 253 } |
254 | 254 |
255 void PolicyLoaderWin::InitOnBackgroundThread() { | 255 void PolicyLoaderWin::InitOnBackgroundThread() { |
256 is_initialized_ = true; | 256 is_initialized_ = true; |
257 SetupWatches(); | 257 SetupWatches(); |
258 } | 258 } |
259 | 259 |
260 scoped_ptr<PolicyBundle> PolicyLoaderWin::Load() { | 260 scoped_ptr<PolicyBundle> PolicyLoaderWin::Load() { |
261 // Reset the watches BEFORE reading the individual policies to avoid | 261 // Reset the watches BEFORE reading the individual policies to avoid |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
320 | 320 |
321 // Load 3rd-party policy. | 321 // Load 3rd-party policy. |
322 if (third_party_dict) | 322 if (third_party_dict) |
323 Load3rdPartyPolicy(third_party_dict.get(), scope, bundle.get()); | 323 Load3rdPartyPolicy(third_party_dict.get(), scope, bundle.get()); |
324 } | 324 } |
325 | 325 |
326 return bundle.Pass(); | 326 return bundle.Pass(); |
327 } | 327 } |
328 | 328 |
329 void PolicyLoaderWin::BuildChromePolicySchema() { | 329 void PolicyLoaderWin::BuildChromePolicySchema() { |
| 330 // TODO(joaodasilva): use the Schema directly instead of building this |
| 331 // DictionaryValue. |
330 scoped_ptr<base::DictionaryValue> properties(new base::DictionaryValue()); | 332 scoped_ptr<base::DictionaryValue> properties(new base::DictionaryValue()); |
331 for (const PolicyDefinitionList::Entry* e = policy_list_->begin; | 333 const Schema* chrome_schema = |
332 e != policy_list_->end; ++e) { | 334 schema_map()->GetSchema(PolicyNamespace(POLICY_DOMAIN_CHROME, "")); |
333 const std::string schema_type = GetSchemaTypeForValueType(e->value_type); | 335 for (Schema::Iterator it = chrome_schema->GetPropertiesIterator(); |
| 336 !it.IsAtEnd(); it.Advance()) { |
| 337 const std::string schema_type = |
| 338 GetSchemaTypeForValueType(it.schema().type()); |
334 scoped_ptr<base::DictionaryValue> entry_schema(new base::DictionaryValue()); | 339 scoped_ptr<base::DictionaryValue> entry_schema(new base::DictionaryValue()); |
335 entry_schema->SetStringWithoutPathExpansion(json_schema_constants::kType, | 340 entry_schema->SetStringWithoutPathExpansion(json_schema_constants::kType, |
336 schema_type); | 341 schema_type); |
337 | 342 |
338 if (e->value_type == base::Value::TYPE_LIST) { | 343 if (it.schema().type() == base::Value::TYPE_LIST) { |
339 scoped_ptr<base::DictionaryValue> items_schema( | 344 scoped_ptr<base::DictionaryValue> items_schema( |
340 new base::DictionaryValue()); | 345 new base::DictionaryValue()); |
341 items_schema->SetStringWithoutPathExpansion( | 346 items_schema->SetStringWithoutPathExpansion( |
342 json_schema_constants::kType, json_schema_constants::kString); | 347 json_schema_constants::kType, json_schema_constants::kString); |
343 entry_schema->SetWithoutPathExpansion(json_schema_constants::kItems, | 348 entry_schema->SetWithoutPathExpansion(json_schema_constants::kItems, |
344 items_schema.release()); | 349 items_schema.release()); |
345 } | 350 } |
346 properties->SetWithoutPathExpansion(e->name, entry_schema.release()); | 351 properties->SetWithoutPathExpansion(it.key(), entry_schema.release()); |
347 } | 352 } |
348 chrome_policy_schema_.SetStringWithoutPathExpansion( | 353 chrome_policy_schema_.SetStringWithoutPathExpansion( |
349 json_schema_constants::kType, json_schema_constants::kObject); | 354 json_schema_constants::kType, json_schema_constants::kObject); |
350 chrome_policy_schema_.SetWithoutPathExpansion( | 355 chrome_policy_schema_.SetWithoutPathExpansion( |
351 json_schema_constants::kProperties, properties.release()); | 356 json_schema_constants::kProperties, properties.release()); |
352 } | 357 } |
353 | 358 |
354 bool PolicyLoaderWin::ReadPRegFile(const base::FilePath& preg_file, | 359 bool PolicyLoaderWin::ReadPRegFile(const base::FilePath& preg_file, |
355 RegistryDict* policy, | 360 RegistryDict* policy, |
356 PolicyLoadStatusSample* status) { | 361 PolicyLoadStatusSample* status) { |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
535 | 540 |
536 void PolicyLoaderWin::OnObjectSignaled(HANDLE object) { | 541 void PolicyLoaderWin::OnObjectSignaled(HANDLE object) { |
537 DCHECK(object == user_policy_changed_event_.handle() || | 542 DCHECK(object == user_policy_changed_event_.handle() || |
538 object == machine_policy_changed_event_.handle()) | 543 object == machine_policy_changed_event_.handle()) |
539 << "unexpected object signaled policy reload, obj = " | 544 << "unexpected object signaled policy reload, obj = " |
540 << std::showbase << std::hex << object; | 545 << std::showbase << std::hex << object; |
541 Reload(false); | 546 Reload(false); |
542 } | 547 } |
543 | 548 |
544 } // namespace policy | 549 } // namespace policy |
OLD | NEW |