| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "app/gfx/codec/png_codec.h" | 9 #include "app/gfx/codec/png_codec.h" |
| 10 #include "app/l10n_util.h" | 10 #include "app/l10n_util.h" |
| (...skipping 786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 797 | 797 |
| 798 while (s.Step()) { | 798 while (s.Step()) { |
| 799 PasswordForm* new_form = new PasswordForm(); | 799 PasswordForm* new_form = new PasswordForm(); |
| 800 InitPasswordFormFromStatement(new_form, &s); | 800 InitPasswordFormFromStatement(new_form, &s); |
| 801 | 801 |
| 802 forms->push_back(new_form); | 802 forms->push_back(new_form); |
| 803 } | 803 } |
| 804 return s.Succeeded(); | 804 return s.Succeeded(); |
| 805 } | 805 } |
| 806 | 806 |
| 807 bool WebDatabase::AddFormFieldValues(const std::vector<FormField>& elements) { | 807 bool WebDatabase::AddFormFieldValues(const std::vector<FormField>& elements, |
| 808 return AddFormFieldValuesTime(elements, Time::Now()); | 808 std::vector<AutofillChange>* changes) { |
| 809 return AddFormFieldValuesTime(elements, changes, Time::Now()); |
| 809 } | 810 } |
| 810 | 811 |
| 811 bool WebDatabase::AddFormFieldValuesTime(const std::vector<FormField>& elements, | 812 bool WebDatabase::AddFormFieldValuesTime(const std::vector<FormField>& elements, |
| 813 std::vector<AutofillChange>* changes, |
| 812 base::Time time) { | 814 base::Time time) { |
| 813 bool result = true; | 815 bool result = true; |
| 814 for (std::vector<FormField>::const_iterator | 816 for (std::vector<FormField>::const_iterator |
| 815 itr = elements.begin(); | 817 itr = elements.begin(); |
| 816 itr != elements.end(); | 818 itr != elements.end(); |
| 817 itr++) { | 819 itr++) { |
| 818 result = result && AddFormFieldValueTime(*itr, time); | 820 result = result && AddFormFieldValueTime(*itr, changes, time); |
| 819 } | 821 } |
| 820 return result; | 822 return result; |
| 821 } | 823 } |
| 822 | 824 |
| 823 bool WebDatabase::ClearAutofillEmptyValueElements() { | 825 bool WebDatabase::ClearAutofillEmptyValueElements() { |
| 824 sql::Statement s(db_.GetUniqueStatement( | 826 sql::Statement s(db_.GetUniqueStatement( |
| 825 "SELECT pair_id FROM autofill WHERE TRIM(value)= \"\"")); | 827 "SELECT pair_id FROM autofill WHERE TRIM(value)= \"\"")); |
| 826 if (!s) { | 828 if (!s) { |
| 827 NOTREACHED() << "Statement prepare failed"; | 829 NOTREACHED() << "Statement prepare failed"; |
| 828 return false; | 830 return false; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 938 s.BindInt(0, count); | 940 s.BindInt(0, count); |
| 939 s.BindInt64(1, pair_id); | 941 s.BindInt64(1, pair_id); |
| 940 if (!s.Run()) { | 942 if (!s.Run()) { |
| 941 NOTREACHED(); | 943 NOTREACHED(); |
| 942 return false; | 944 return false; |
| 943 } | 945 } |
| 944 | 946 |
| 945 return true; | 947 return true; |
| 946 } | 948 } |
| 947 | 949 |
| 948 bool WebDatabase::AddFormFieldValue(const FormField& element) { | 950 bool WebDatabase::AddFormFieldValue(const FormField& element, |
| 949 return AddFormFieldValueTime(element, base::Time::Now()); | 951 std::vector<AutofillChange>* changes) { |
| 952 return AddFormFieldValueTime(element, changes, base::Time::Now()); |
| 950 } | 953 } |
| 951 | 954 |
| 952 bool WebDatabase::AddFormFieldValueTime(const FormField& element, | 955 bool WebDatabase::AddFormFieldValueTime(const FormField& element, |
| 956 std::vector<AutofillChange>* changes, |
| 953 base::Time time) { | 957 base::Time time) { |
| 954 int count = 0; | 958 int count = 0; |
| 955 int64 pair_id; | 959 int64 pair_id; |
| 956 | 960 |
| 957 if (!GetIDAndCountOfFormElement(element, &pair_id, &count)) | 961 if (!GetIDAndCountOfFormElement(element, &pair_id, &count)) |
| 958 return false; | 962 return false; |
| 959 | 963 |
| 960 if (count == 0 && !InsertFormElement(element, &pair_id)) | 964 if (count == 0 && !InsertFormElement(element, &pair_id)) |
| 961 return false; | 965 return false; |
| 962 | 966 |
| 963 return SetCountOfFormElement(pair_id, count + 1) && | 967 if (!SetCountOfFormElement(pair_id, count + 1)) |
| 964 InsertPairIDAndDate(pair_id, time); | 968 return false; |
| 969 |
| 970 if (!InsertPairIDAndDate(pair_id, time)) |
| 971 return false; |
| 972 |
| 973 AutofillChange::Type change_type = |
| 974 count == 0 ? AutofillChange::ADD : AutofillChange::UPDATE; |
| 975 changes->push_back( |
| 976 AutofillChange(change_type, |
| 977 AutofillKey(element.name(), element.value()))); |
| 978 return true; |
| 965 } | 979 } |
| 966 | 980 |
| 967 bool WebDatabase::GetFormValuesForElementName(const string16& name, | 981 bool WebDatabase::GetFormValuesForElementName(const string16& name, |
| 968 const string16& prefix, | 982 const string16& prefix, |
| 969 std::vector<string16>* values, | 983 std::vector<string16>* values, |
| 970 int limit) { | 984 int limit) { |
| 971 DCHECK(values); | 985 DCHECK(values); |
| 972 sql::Statement s; | 986 sql::Statement s; |
| 973 | 987 |
| 974 if (prefix.empty()) { | 988 if (prefix.empty()) { |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1179 | 1193 |
| 1180 // Add successive versions here. Each should set the version number and | 1194 // Add successive versions here. Each should set the version number and |
| 1181 // compatible version number as appropriate, then fall through to the next | 1195 // compatible version number as appropriate, then fall through to the next |
| 1182 // case. | 1196 // case. |
| 1183 | 1197 |
| 1184 case kCurrentVersionNumber: | 1198 case kCurrentVersionNumber: |
| 1185 // No migration needed. | 1199 // No migration needed. |
| 1186 return; | 1200 return; |
| 1187 } | 1201 } |
| 1188 } | 1202 } |
| OLD | NEW |