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 : SchemaValidatingPolicyHandler(policy_name, |
| 379 schema.GetKnownProperty(policy_name), |
| 380 strategy), |
| 381 pref_path_(pref_path), |
| 382 allow_recommended_(true), |
| 383 allow_mandatory_(true) { |
| 384 } |
| 385 |
| 386 SimpleSchemaValidatingPolicyHandler::SimpleSchemaValidatingPolicyHandler( |
| 387 const char* policy_name, |
| 388 const char* pref_path, |
| 389 Schema schema, |
| 390 SchemaOnErrorStrategy strategy, |
| 391 bool allow_recommended, |
| 392 bool allow_mandatory) |
| 393 : SchemaValidatingPolicyHandler(policy_name, |
| 394 schema.GetKnownProperty(policy_name), |
| 395 strategy), |
| 396 pref_path_(pref_path), |
| 397 allow_recommended_(allow_recommended), |
| 398 allow_mandatory_(allow_mandatory) { |
| 399 } |
| 400 |
| 401 SimpleSchemaValidatingPolicyHandler::~SimpleSchemaValidatingPolicyHandler() { |
| 402 } |
| 403 |
| 404 bool SimpleSchemaValidatingPolicyHandler::CheckPolicySettings( |
| 405 const PolicyMap& policies, |
| 406 PolicyErrorMap* errors) { |
| 407 const PolicyMap::Entry* policy_entry = policies.Get(policy_name()); |
| 408 if (!policy_entry) |
| 409 return true; |
| 410 if ((policy_entry->level == policy::POLICY_LEVEL_MANDATORY && |
| 411 !allow_mandatory_) || |
| 412 (policy_entry->level == policy::POLICY_LEVEL_RECOMMENDED && |
| 413 !allow_recommended_)) { |
| 414 if (errors) |
| 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 |