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 "components/policy/core/browser/configuration_policy_handler.h" | 5 #include "components/policy/core/browser/configuration_policy_handler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
361 | 361 |
362 if (errors && !error.empty()) { | 362 if (errors && !error.empty()) { |
363 if (error_path.empty()) | 363 if (error_path.empty()) |
364 error_path = "(ROOT)"; | 364 error_path = "(ROOT)"; |
365 errors->AddError(policy_name_, error_path, error); | 365 errors->AddError(policy_name_, error_path, error); |
366 } | 366 } |
367 | 367 |
368 return result; | 368 return result; |
369 } | 369 } |
370 | 370 |
371 // SimpleSchemaValidatingPolicyHandler implementation -------------------------- | |
372 | |
373 SimpleSchemaValidatingPolicyHandler::SimpleSchemaValidatingPolicyHandler( | |
374 const char* policy_name, | |
375 const char* pref_path, | |
376 Schema schema, | |
377 SchemaOnErrorStrategy strategy, | |
378 bool recommended, | |
379 bool mandatory) | |
380 : SchemaValidatingPolicyHandler(policy_name, | |
381 schema.GetKnownProperty(policy_name), | |
382 strategy), | |
383 pref_path_(pref_path), | |
384 recommended_(recommended), | |
385 mandatory_(mandatory) { | |
386 } | |
387 | |
388 SimpleSchemaValidatingPolicyHandler::SimpleSchemaValidatingPolicyHandler( | |
bartfab (slow)
2014/06/03 11:58:21
Nit: Reorder these constructors so that the implem
kaliamoorthi
2014/06/04 18:01:58
Done.
| |
389 const char* policy_name, | |
390 const char* pref_path, | |
391 Schema schema, | |
392 SchemaOnErrorStrategy strategy) | |
393 : SchemaValidatingPolicyHandler(policy_name, | |
394 schema.GetKnownProperty(policy_name), | |
395 strategy), | |
396 pref_path_(pref_path), | |
397 recommended_(true), | |
398 mandatory_(true) { | |
399 } | |
400 | |
401 SimpleSchemaValidatingPolicyHandler::~SimpleSchemaValidatingPolicyHandler() { | |
402 } | |
403 | |
404 bool SimpleSchemaValidatingPolicyHandler::CheckPolicySettings( | |
405 const PolicyMap& policies, | |
406 PolicyErrorMap* errors) { | |
407 const PolicyMap::Entry* policy_entry = | |
408 policies.Get(SchemaValidatingPolicyHandler::policy_name()); | |
bartfab (slow)
2014/06/03 11:58:21
Nit: No need for the SchemaValidatingPolicyHandler
kaliamoorthi
2014/06/04 18:01:58
Done.
| |
409 if (!policy_entry) | |
410 return false; | |
bartfab (slow)
2014/06/03 11:58:21
SchemaValidatingPolicyHandler returns |true| if th
kaliamoorthi
2014/06/04 18:01:58
Done.
| |
411 if ((policy_entry->level == policy::POLICY_LEVEL_MANDATORY && !mandatory_) || | |
412 (policy_entry->level == policy::POLICY_LEVEL_RECOMMENDED && | |
413 !recommended_)) { | |
414 if (errors != NULL) | |
bartfab (slow)
2014/06/03 11:58:21
Nit: "if (errors)" is sufficient
kaliamoorthi
2014/06/04 18:01:58
Done.
| |
415 errors->AddError(policy_name(), IDS_POLICY_LEVEL_ERROR); | |
416 return false; | |
417 } | |
418 | |
419 return SchemaValidatingPolicyHandler::CheckPolicySettings(policies, errors); | |
420 } | |
421 | |
422 void SimpleSchemaValidatingPolicyHandler::ApplyPolicySettings( | |
423 const PolicyMap& policies, | |
424 PrefValueMap* prefs) { | |
425 if (!pref_path_) | |
426 return; | |
427 const base::Value* value = policies.GetValue(policy_name()); | |
428 if (value) | |
429 prefs->SetValue(pref_path_, value->DeepCopy()); | |
430 } | |
431 | |
371 // LegacyPoliciesDeprecatingPolicyHandler implementation ----------------------- | 432 // LegacyPoliciesDeprecatingPolicyHandler implementation ----------------------- |
372 | 433 |
373 // TODO(binjin): Add a new common base class for SchemaValidatingPolicyHandler | 434 // TODO(binjin): Add a new common base class for SchemaValidatingPolicyHandler |
374 // and TypeCheckingPolicyHandler representing policy handlers for a single | 435 // and TypeCheckingPolicyHandler representing policy handlers for a single |
375 // policy, and use it as the type of |new_policy_handler|. | 436 // policy, and use it as the type of |new_policy_handler|. |
376 // http://crbug.com/345299 | 437 // http://crbug.com/345299 |
377 LegacyPoliciesDeprecatingPolicyHandler::LegacyPoliciesDeprecatingPolicyHandler( | 438 LegacyPoliciesDeprecatingPolicyHandler::LegacyPoliciesDeprecatingPolicyHandler( |
378 ScopedVector<ConfigurationPolicyHandler> legacy_policy_handlers, | 439 ScopedVector<ConfigurationPolicyHandler> legacy_policy_handlers, |
379 scoped_ptr<SchemaValidatingPolicyHandler> new_policy_handler) | 440 scoped_ptr<SchemaValidatingPolicyHandler> new_policy_handler) |
380 : legacy_policy_handlers_(legacy_policy_handlers.Pass()), | 441 : legacy_policy_handlers_(legacy_policy_handlers.Pass()), |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
416 for (handler = legacy_policy_handlers_.begin(); | 477 for (handler = legacy_policy_handlers_.begin(); |
417 handler != legacy_policy_handlers_.end(); | 478 handler != legacy_policy_handlers_.end(); |
418 ++handler) { | 479 ++handler) { |
419 if ((*handler)->CheckPolicySettings(policies, &scoped_errors)) | 480 if ((*handler)->CheckPolicySettings(policies, &scoped_errors)) |
420 (*handler)->ApplyPolicySettings(policies, prefs); | 481 (*handler)->ApplyPolicySettings(policies, prefs); |
421 } | 482 } |
422 } | 483 } |
423 } | 484 } |
424 | 485 |
425 } // namespace policy | 486 } // namespace policy |
OLD | NEW |