OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/webdata/web_database.h" | 5 #include "chrome/browser/webdata/web_database.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
(...skipping 1057 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1068 } | 1068 } |
1069 | 1069 |
1070 bool WebDatabase::AddFormFieldValues(const std::vector<FormField>& elements, | 1070 bool WebDatabase::AddFormFieldValues(const std::vector<FormField>& elements, |
1071 std::vector<AutofillChange>* changes) { | 1071 std::vector<AutofillChange>* changes) { |
1072 return AddFormFieldValuesTime(elements, changes, Time::Now()); | 1072 return AddFormFieldValuesTime(elements, changes, Time::Now()); |
1073 } | 1073 } |
1074 | 1074 |
1075 bool WebDatabase::AddFormFieldValuesTime(const std::vector<FormField>& elements, | 1075 bool WebDatabase::AddFormFieldValuesTime(const std::vector<FormField>& elements, |
1076 std::vector<AutofillChange>* changes, | 1076 std::vector<AutofillChange>* changes, |
1077 base::Time time) { | 1077 base::Time time) { |
| 1078 // Only add one new entry for each unique element name. Use |seen_names| to |
| 1079 // track this. Add up to |kMaximumUniqueNames| unique entries per form. |
| 1080 const size_t kMaximumUniqueNames = 256; |
| 1081 std::set<string16> seen_names; |
1078 bool result = true; | 1082 bool result = true; |
1079 for (std::vector<FormField>::const_iterator | 1083 for (std::vector<FormField>::const_iterator |
1080 itr = elements.begin(); | 1084 itr = elements.begin(); |
1081 itr != elements.end(); | 1085 itr != elements.end(); |
1082 itr++) { | 1086 itr++) { |
| 1087 if (seen_names.size() >= kMaximumUniqueNames) |
| 1088 break; |
| 1089 if (seen_names.find(itr->name()) != seen_names.end()) |
| 1090 continue; |
1083 result = result && AddFormFieldValueTime(*itr, changes, time); | 1091 result = result && AddFormFieldValueTime(*itr, changes, time); |
| 1092 seen_names.insert(itr->name()); |
1084 } | 1093 } |
1085 return result; | 1094 return result; |
1086 } | 1095 } |
1087 | 1096 |
1088 bool WebDatabase::ClearAutofillEmptyValueElements() { | 1097 bool WebDatabase::ClearAutofillEmptyValueElements() { |
1089 sql::Statement s(db_.GetUniqueStatement( | 1098 sql::Statement s(db_.GetUniqueStatement( |
1090 "SELECT pair_id FROM autofill WHERE TRIM(value)= \"\"")); | 1099 "SELECT pair_id FROM autofill WHERE TRIM(value)= \"\"")); |
1091 if (!s) { | 1100 if (!s) { |
1092 NOTREACHED() << "Statement prepare failed"; | 1101 NOTREACHED() << "Statement prepare failed"; |
1093 return false; | 1102 return false; |
(...skipping 799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1893 | 1902 |
1894 // Add successive versions here. Each should set the version number and | 1903 // Add successive versions here. Each should set the version number and |
1895 // compatible version number as appropriate, then fall through to the next | 1904 // compatible version number as appropriate, then fall through to the next |
1896 // case. | 1905 // case. |
1897 | 1906 |
1898 case kCurrentVersionNumber: | 1907 case kCurrentVersionNumber: |
1899 // No migration needed. | 1908 // No migration needed. |
1900 return; | 1909 return; |
1901 } | 1910 } |
1902 } | 1911 } |
OLD | NEW |