| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/common/schema.h" | 5 #include "components/policy/core/common/schema.h" |
| 6 | 6 |
| 7 #include <limits.h> | 7 #include <limits.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 601 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 *error = "Enum attribute must be non-empty"; | 612 *error = "Enum attribute must be non-empty"; |
| 613 return false; | 613 return false; |
| 614 } | 614 } |
| 615 int offset_begin; | 615 int offset_begin; |
| 616 int offset_end; | 616 int offset_end; |
| 617 if (type == base::Value::Type::INTEGER) { | 617 if (type == base::Value::Type::INTEGER) { |
| 618 offset_begin = static_cast<int>(int_enums_.size()); | 618 offset_begin = static_cast<int>(int_enums_.size()); |
| 619 int value; | 619 int value; |
| 620 for (base::ListValue::const_iterator it = possible_values->begin(); | 620 for (base::ListValue::const_iterator it = possible_values->begin(); |
| 621 it != possible_values->end(); ++it) { | 621 it != possible_values->end(); ++it) { |
| 622 if (!(*it)->GetAsInteger(&value)) { | 622 if (!it->GetAsInteger(&value)) { |
| 623 *error = "Invalid enumeration member type"; | 623 *error = "Invalid enumeration member type"; |
| 624 return false; | 624 return false; |
| 625 } | 625 } |
| 626 int_enums_.push_back(value); | 626 int_enums_.push_back(value); |
| 627 } | 627 } |
| 628 offset_end = static_cast<int>(int_enums_.size()); | 628 offset_end = static_cast<int>(int_enums_.size()); |
| 629 } else if (type == base::Value::Type::STRING) { | 629 } else if (type == base::Value::Type::STRING) { |
| 630 offset_begin = static_cast<int>(string_enums_.size()); | 630 offset_begin = static_cast<int>(string_enums_.size()); |
| 631 std::string value; | 631 std::string value; |
| 632 for (base::ListValue::const_iterator it = possible_values->begin(); | 632 for (base::ListValue::const_iterator it = possible_values->begin(); |
| 633 it != possible_values->end(); ++it) { | 633 it != possible_values->end(); ++it) { |
| 634 if (!(*it)->GetAsString(&value)) { | 634 if (!it->GetAsString(&value)) { |
| 635 *error = "Invalid enumeration member type"; | 635 *error = "Invalid enumeration member type"; |
| 636 return false; | 636 return false; |
| 637 } | 637 } |
| 638 strings_.push_back(value); | 638 strings_.push_back(value); |
| 639 string_enums_.push_back(strings_.back().c_str()); | 639 string_enums_.push_back(strings_.back().c_str()); |
| 640 } | 640 } |
| 641 offset_end = static_cast<int>(string_enums_.size()); | 641 offset_end = static_cast<int>(string_enums_.size()); |
| 642 } else { | 642 } else { |
| 643 *error = "Enumeration is only supported for integer and string."; | 643 *error = "Enumeration is only supported for integer and string."; |
| 644 return false; | 644 return false; |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 819 AddDictKeyPrefixToPath(it.key(), error_path); | 819 AddDictKeyPrefixToPath(it.key(), error_path); |
| 820 if (!StrategyAllowInvalidOnTopLevel(strategy)) | 820 if (!StrategyAllowInvalidOnTopLevel(strategy)) |
| 821 return false; | 821 return false; |
| 822 } | 822 } |
| 823 } | 823 } |
| 824 } | 824 } |
| 825 } | 825 } |
| 826 } else if (value.GetAsList(&list)) { | 826 } else if (value.GetAsList(&list)) { |
| 827 for (base::ListValue::const_iterator it = list->begin(); it != list->end(); | 827 for (base::ListValue::const_iterator it = list->begin(); it != list->end(); |
| 828 ++it) { | 828 ++it) { |
| 829 if (!*it || | 829 if (!GetItems().Validate(*it, StrategyForNextLevel(strategy), error_path, |
| 830 !GetItems().Validate(**it, | |
| 831 StrategyForNextLevel(strategy), | |
| 832 error_path, | |
| 833 error)) { | 830 error)) { |
| 834 // Invalid list item was detected. | 831 // Invalid list item was detected. |
| 835 AddListIndexPrefixToPath(it - list->begin(), error_path); | 832 AddListIndexPrefixToPath(it - list->begin(), error_path); |
| 836 if (!StrategyAllowInvalidOnTopLevel(strategy)) | 833 if (!StrategyAllowInvalidOnTopLevel(strategy)) |
| 837 return false; | 834 return false; |
| 838 } | 835 } |
| 839 } | 836 } |
| 840 } else if (value.GetAsInteger(&int_value)) { | 837 } else if (value.GetAsInteger(&int_value)) { |
| 841 if (node_->extra != kInvalid && | 838 if (node_->extra != kInvalid && |
| 842 !ValidateIntegerRestriction(node_->extra, int_value)) { | 839 !ValidateIntegerRestriction(node_->extra, int_value)) { |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1105 return false; | 1102 return false; |
| 1106 } else { | 1103 } else { |
| 1107 int index = rnode->string_pattern_restriction.pattern_index; | 1104 int index = rnode->string_pattern_restriction.pattern_index; |
| 1108 DCHECK(index == rnode->string_pattern_restriction.pattern_index_backup); | 1105 DCHECK(index == rnode->string_pattern_restriction.pattern_index_backup); |
| 1109 re2::RE2* regex = storage_->CompileRegex(*storage_->string_enums(index)); | 1106 re2::RE2* regex = storage_->CompileRegex(*storage_->string_enums(index)); |
| 1110 return re2::RE2::PartialMatch(str, *regex); | 1107 return re2::RE2::PartialMatch(str, *regex); |
| 1111 } | 1108 } |
| 1112 } | 1109 } |
| 1113 | 1110 |
| 1114 } // namespace policy | 1111 } // namespace policy |
| OLD | NEW |