Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(212)

Side by Side Diff: components/policy/core/common/schema.cc

Issue 171403004: Add touch flag to output of Schema::Normalize() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@split-1
Patch Set: rebase Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 <algorithm> 7 #include <algorithm>
8 #include <climits> 8 #include <climits>
9 #include <map> 9 #include <map>
10 #include <utility> 10 #include <utility>
(...skipping 719 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 return false; 730 return false;
731 } 731 }
732 } 732 }
733 733
734 return true; 734 return true;
735 } 735 }
736 736
737 bool Schema::Normalize(base::Value* value, 737 bool Schema::Normalize(base::Value* value,
738 SchemaOnErrorStrategy strategy, 738 SchemaOnErrorStrategy strategy,
739 std::string* error_path, 739 std::string* error_path,
740 std::string* error) const { 740 std::string* error,
741 bool* changed) const {
741 if (!valid()) { 742 if (!valid()) {
742 SchemaErrorFound(error_path, error, "The schema is invalid."); 743 SchemaErrorFound(error_path, error, "The schema is invalid.");
743 return false; 744 return false;
744 } 745 }
745 746
746 if (!value->IsType(type())) { 747 if (!value->IsType(type())) {
747 // Allow the integer to double promotion. Note that range restriction on 748 // Allow the integer to double promotion. Note that range restriction on
748 // double is not supported now. 749 // double is not supported now.
749 if (value->IsType(base::Value::TYPE_INTEGER) && 750 if (value->IsType(base::Value::TYPE_INTEGER) &&
750 type() == base::Value::TYPE_DOUBLE) { 751 type() == base::Value::TYPE_DOUBLE) {
(...skipping 18 matching lines...) Expand all
769 if (StrategyAllowUnknownOnTopLevel(strategy)) 770 if (StrategyAllowUnknownOnTopLevel(strategy))
770 drop_list.push_back(it.key()); 771 drop_list.push_back(it.key());
771 else 772 else
772 return false; 773 return false;
773 } else { 774 } else {
774 base::Value* sub_value = NULL; 775 base::Value* sub_value = NULL;
775 dict->GetWithoutPathExpansion(it.key(), &sub_value); 776 dict->GetWithoutPathExpansion(it.key(), &sub_value);
776 if (!subschema.Normalize(sub_value, 777 if (!subschema.Normalize(sub_value,
777 StrategyForNextLevel(strategy), 778 StrategyForNextLevel(strategy),
778 error_path, 779 error_path,
779 error)) { 780 error,
781 changed)) {
780 // Invalid property was detected. 782 // Invalid property was detected.
781 AddDictKeyPrefixToPath(it.key(), error_path); 783 AddDictKeyPrefixToPath(it.key(), error_path);
782 if (StrategyAllowInvalidOnTopLevel(strategy)) 784 if (StrategyAllowInvalidOnTopLevel(strategy))
783 drop_list.push_back(it.key()); 785 drop_list.push_back(it.key());
784 else 786 else
785 return false; 787 return false;
786 } 788 }
787 } 789 }
788 } 790 }
791 if (changed && !drop_list.empty())
792 *changed = true;
789 for (std::vector<std::string>::const_iterator it = drop_list.begin(); 793 for (std::vector<std::string>::const_iterator it = drop_list.begin();
790 it != drop_list.end(); 794 it != drop_list.end();
791 ++it) { 795 ++it) {
792 dict->RemoveWithoutPathExpansion(*it, NULL); 796 dict->RemoveWithoutPathExpansion(*it, NULL);
793 } 797 }
794 return true; 798 return true;
795 } else if (value->GetAsList(&list)) { 799 } else if (value->GetAsList(&list)) {
796 std::vector<size_t> drop_list; // Contains the indexes to drop. 800 std::vector<size_t> drop_list; // Contains the indexes to drop.
797 for (size_t index = 0; index < list->GetSize(); index++) { 801 for (size_t index = 0; index < list->GetSize(); index++) {
798 base::Value* sub_value = NULL; 802 base::Value* sub_value = NULL;
799 list->Get(index, &sub_value); 803 list->Get(index, &sub_value);
800 if (!sub_value || 804 if (!sub_value || !GetItems().Normalize(sub_value,
801 !GetItems().Normalize(sub_value, 805 StrategyForNextLevel(strategy),
802 StrategyForNextLevel(strategy), 806 error_path,
803 error_path, 807 error,
804 error)) { 808 changed)) {
805 // Invalid list item was detected. 809 // Invalid list item was detected.
806 AddListIndexPrefixToPath(index, error_path); 810 AddListIndexPrefixToPath(index, error_path);
807 if (StrategyAllowInvalidOnTopLevel(strategy)) 811 if (StrategyAllowInvalidOnTopLevel(strategy))
808 drop_list.push_back(index); 812 drop_list.push_back(index);
809 else 813 else
810 return false; 814 return false;
811 } 815 }
812 } 816 }
817 if (changed && !drop_list.empty())
818 *changed = true;
813 for (std::vector<size_t>::reverse_iterator it = drop_list.rbegin(); 819 for (std::vector<size_t>::reverse_iterator it = drop_list.rbegin();
814 it != drop_list.rend(); ++it) { 820 it != drop_list.rend(); ++it) {
815 list->Remove(*it, NULL); 821 list->Remove(*it, NULL);
816 } 822 }
817 return true; 823 return true;
818 } 824 }
819 825
820 return Validate(*value, strategy, error_path, error); 826 return Validate(*value, strategy, error_path, error);
821 } 827 }
822 828
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
926 const RestrictionNode* rnode = storage_->restriction(index); 932 const RestrictionNode* rnode = storage_->restriction(index);
927 for (int i = rnode->enumeration_restriction.offset_begin; 933 for (int i = rnode->enumeration_restriction.offset_begin;
928 i < rnode->enumeration_restriction.offset_end; i++) { 934 i < rnode->enumeration_restriction.offset_end; i++) {
929 if (strcmp(*storage_->string_enums(i), str) == 0) 935 if (strcmp(*storage_->string_enums(i), str) == 0)
930 return true; 936 return true;
931 } 937 }
932 return false; 938 return false;
933 } 939 }
934 940
935 } // namespace policy 941 } // namespace policy
OLDNEW
« no previous file with comments | « components/policy/core/common/schema.h ('k') | components/policy/core/common/schema_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698