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/schema.h" | |
36 #include "policy/policy_constants.h" | 37 #include "policy/policy_constants.h" |
bartfab (slow)
2013/11/05 18:18:33
Nit 1: Is this still needed?
Nit 2: policy/policy
Joao da Silva
2013/11/07 20:27:27
It's not used, removed
| |
37 | 38 |
38 namespace schema = json_schema_constants; | 39 namespace schema = json_schema_constants; |
39 | 40 |
40 namespace policy { | 41 namespace policy { |
41 | 42 |
42 namespace { | 43 namespace { |
43 | 44 |
44 const char kKeyMandatory[] = "policy"; | 45 const char kKeyMandatory[] = "policy"; |
45 const char kKeyRecommended[] = "recommended"; | 46 const char kKeyRecommended[] = "recommended"; |
46 const char kKeySchema[] = "schema"; | 47 const char kKeySchema[] = "schema"; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
203 policy->LoadFrom(policy_dict, level, scope); | 204 policy->LoadFrom(policy_dict, level, scope); |
204 } | 205 } |
205 | 206 |
206 } // namespace | 207 } // namespace |
207 | 208 |
208 const base::FilePath::CharType PolicyLoaderWin::kPRegFileName[] = | 209 const base::FilePath::CharType PolicyLoaderWin::kPRegFileName[] = |
209 FILE_PATH_LITERAL("Registry.pol"); | 210 FILE_PATH_LITERAL("Registry.pol"); |
210 | 211 |
211 PolicyLoaderWin::PolicyLoaderWin( | 212 PolicyLoaderWin::PolicyLoaderWin( |
212 scoped_refptr<base::SequencedTaskRunner> task_runner, | 213 scoped_refptr<base::SequencedTaskRunner> task_runner, |
213 const PolicyDefinitionList* policy_list, | |
214 const string16& chrome_policy_key, | 214 const string16& chrome_policy_key, |
215 AppliedGPOListProvider* gpo_provider) | 215 AppliedGPOListProvider* gpo_provider) |
216 : AsyncPolicyLoader(task_runner), | 216 : AsyncPolicyLoader(task_runner), |
217 is_initialized_(false), | 217 is_initialized_(false), |
218 policy_list_(policy_list), | |
219 chrome_policy_key_(chrome_policy_key), | 218 chrome_policy_key_(chrome_policy_key), |
220 gpo_provider_(gpo_provider), | 219 gpo_provider_(gpo_provider), |
221 user_policy_changed_event_(false, false), | 220 user_policy_changed_event_(false, false), |
222 machine_policy_changed_event_(false, false), | 221 machine_policy_changed_event_(false, false), |
223 user_policy_watcher_failed_(false), | 222 user_policy_watcher_failed_(false), |
224 machine_policy_watcher_failed_(false) { | 223 machine_policy_watcher_failed_(false) { |
225 if (!RegisterGPNotification(user_policy_changed_event_.handle(), false)) { | 224 if (!RegisterGPNotification(user_policy_changed_event_.handle(), false)) { |
226 DPLOG(WARNING) << "Failed to register user group policy notification"; | 225 DPLOG(WARNING) << "Failed to register user group policy notification"; |
227 user_policy_watcher_failed_ = true; | 226 user_policy_watcher_failed_ = true; |
228 } | 227 } |
229 if (!RegisterGPNotification(machine_policy_changed_event_.handle(), true)) { | 228 if (!RegisterGPNotification(machine_policy_changed_event_.handle(), true)) { |
230 DPLOG(WARNING) << "Failed to register machine group policy notification."; | 229 DPLOG(WARNING) << "Failed to register machine group policy notification."; |
231 machine_policy_watcher_failed_ = true; | 230 machine_policy_watcher_failed_ = true; |
232 } | 231 } |
233 } | 232 } |
234 | 233 |
235 PolicyLoaderWin::~PolicyLoaderWin() { | 234 PolicyLoaderWin::~PolicyLoaderWin() { |
236 user_policy_watcher_.StopWatching(); | 235 user_policy_watcher_.StopWatching(); |
237 machine_policy_watcher_.StopWatching(); | 236 machine_policy_watcher_.StopWatching(); |
238 } | 237 } |
239 | 238 |
240 // static | 239 // static |
241 scoped_ptr<PolicyLoaderWin> PolicyLoaderWin::Create( | 240 scoped_ptr<PolicyLoaderWin> PolicyLoaderWin::Create( |
242 scoped_refptr<base::SequencedTaskRunner> task_runner, | 241 scoped_refptr<base::SequencedTaskRunner> task_runner) { |
243 const PolicyDefinitionList* policy_list) { | |
244 return make_scoped_ptr( | 242 return make_scoped_ptr( |
245 new PolicyLoaderWin(task_runner, policy_list, kRegistryChromePolicyKey, | 243 new PolicyLoaderWin(task_runner, |
244 kRegistryChromePolicyKey, | |
246 g_win_gpo_list_provider.Pointer())); | 245 g_win_gpo_list_provider.Pointer())); |
247 } | 246 } |
248 | 247 |
249 void PolicyLoaderWin::InitOnBackgroundThread() { | 248 void PolicyLoaderWin::InitOnBackgroundThread() { |
250 is_initialized_ = true; | 249 is_initialized_ = true; |
251 SetupWatches(); | 250 SetupWatches(); |
252 } | 251 } |
253 | 252 |
254 scoped_ptr<PolicyBundle> PolicyLoaderWin::Load() { | 253 scoped_ptr<PolicyBundle> PolicyLoaderWin::Load() { |
255 // Reset the watches BEFORE reading the individual policies to avoid | 254 // Reset the watches BEFORE reading the individual policies to avoid |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
314 | 313 |
315 // Load 3rd-party policy. | 314 // Load 3rd-party policy. |
316 if (third_party_dict) | 315 if (third_party_dict) |
317 Load3rdPartyPolicy(third_party_dict.get(), scope, bundle.get()); | 316 Load3rdPartyPolicy(third_party_dict.get(), scope, bundle.get()); |
318 } | 317 } |
319 | 318 |
320 return bundle.Pass(); | 319 return bundle.Pass(); |
321 } | 320 } |
322 | 321 |
323 void PolicyLoaderWin::BuildChromePolicySchema() { | 322 void PolicyLoaderWin::BuildChromePolicySchema() { |
323 // TODO(joaodasilva): use the Schema directly instead of building this | |
324 // DictionaryValue. | |
324 scoped_ptr<base::DictionaryValue> properties(new base::DictionaryValue()); | 325 scoped_ptr<base::DictionaryValue> properties(new base::DictionaryValue()); |
325 for (const PolicyDefinitionList::Entry* e = policy_list_->begin; | 326 const Schema* chrome_schema = |
326 e != policy_list_->end; ++e) { | 327 schema_map()->GetSchema(PolicyNamespace(POLICY_DOMAIN_CHROME, "")); |
bartfab (slow)
2013/11/05 18:18:33
#include "components/policy/core/common/policy_nam
Joao da Silva
2013/11/07 20:27:27
Done.
| |
327 const std::string schema_type = GetSchemaTypeForValueType(e->value_type); | 328 for (Schema::Iterator it = chrome_schema->GetPropertiesIterator(); |
329 !it.IsAtEnd(); it.Advance()) { | |
330 const std::string schema_type = | |
331 GetSchemaTypeForValueType(it.schema().type()); | |
328 scoped_ptr<base::DictionaryValue> entry_schema(new base::DictionaryValue()); | 332 scoped_ptr<base::DictionaryValue> entry_schema(new base::DictionaryValue()); |
329 entry_schema->SetStringWithoutPathExpansion(json_schema_constants::kType, | 333 entry_schema->SetStringWithoutPathExpansion(json_schema_constants::kType, |
330 schema_type); | 334 schema_type); |
331 | 335 |
332 if (e->value_type == base::Value::TYPE_LIST) { | 336 if (it.schema().type() == base::Value::TYPE_LIST) { |
333 scoped_ptr<base::DictionaryValue> items_schema( | 337 scoped_ptr<base::DictionaryValue> items_schema( |
334 new base::DictionaryValue()); | 338 new base::DictionaryValue()); |
335 items_schema->SetStringWithoutPathExpansion( | 339 items_schema->SetStringWithoutPathExpansion( |
336 json_schema_constants::kType, json_schema_constants::kString); | 340 json_schema_constants::kType, json_schema_constants::kString); |
337 entry_schema->SetWithoutPathExpansion(json_schema_constants::kItems, | 341 entry_schema->SetWithoutPathExpansion(json_schema_constants::kItems, |
338 items_schema.release()); | 342 items_schema.release()); |
339 } | 343 } |
340 properties->SetWithoutPathExpansion(e->name, entry_schema.release()); | 344 properties->SetWithoutPathExpansion(it.key(), entry_schema.release()); |
341 } | 345 } |
342 chrome_policy_schema_.SetStringWithoutPathExpansion( | 346 chrome_policy_schema_.SetStringWithoutPathExpansion( |
343 json_schema_constants::kType, json_schema_constants::kObject); | 347 json_schema_constants::kType, json_schema_constants::kObject); |
344 chrome_policy_schema_.SetWithoutPathExpansion( | 348 chrome_policy_schema_.SetWithoutPathExpansion( |
345 json_schema_constants::kProperties, properties.release()); | 349 json_schema_constants::kProperties, properties.release()); |
346 } | 350 } |
347 | 351 |
348 bool PolicyLoaderWin::ReadPRegFile(const base::FilePath& preg_file, | 352 bool PolicyLoaderWin::ReadPRegFile(const base::FilePath& preg_file, |
349 RegistryDict* policy, | 353 RegistryDict* policy, |
350 PolicyLoadStatusSample* status) { | 354 PolicyLoadStatusSample* status) { |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
529 | 533 |
530 void PolicyLoaderWin::OnObjectSignaled(HANDLE object) { | 534 void PolicyLoaderWin::OnObjectSignaled(HANDLE object) { |
531 DCHECK(object == user_policy_changed_event_.handle() || | 535 DCHECK(object == user_policy_changed_event_.handle() || |
532 object == machine_policy_changed_event_.handle()) | 536 object == machine_policy_changed_event_.handle()) |
533 << "unexpected object signaled policy reload, obj = " | 537 << "unexpected object signaled policy reload, obj = " |
534 << std::showbase << std::hex << object; | 538 << std::showbase << std::hex << object; |
535 Reload(false); | 539 Reload(false); |
536 } | 540 } |
537 | 541 |
538 } // namespace policy | 542 } // namespace policy |
OLD | NEW |