| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 832 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 843 int64* pair_id, | 843 int64* pair_id, |
| 844 int* count) { | 844 int* count) { |
| 845 sql::Statement s(db_.GetUniqueStatement( | 845 sql::Statement s(db_.GetUniqueStatement( |
| 846 "SELECT pair_id, count FROM autofill " | 846 "SELECT pair_id, count FROM autofill " |
| 847 "WHERE name = ? AND value = ?")); | 847 "WHERE name = ? AND value = ?")); |
| 848 if (!s) { | 848 if (!s) { |
| 849 NOTREACHED() << "Statement prepare failed"; | 849 NOTREACHED() << "Statement prepare failed"; |
| 850 return false; | 850 return false; |
| 851 } | 851 } |
| 852 | 852 |
| 853 s.BindString(0, WideToUTF8(element.name)); | 853 s.BindString(0, UTF16ToUTF8(element.name)); |
| 854 s.BindString(1, WideToUTF8(element.value)); | 854 s.BindString(1, UTF16ToUTF8(element.value)); |
| 855 | 855 |
| 856 *count = 0; | 856 *count = 0; |
| 857 | 857 |
| 858 if (s.Step()) { | 858 if (s.Step()) { |
| 859 *pair_id = s.ColumnInt64(0); | 859 *pair_id = s.ColumnInt64(0); |
| 860 *count = s.ColumnInt(1); | 860 *count = s.ColumnInt(1); |
| 861 } | 861 } |
| 862 | 862 |
| 863 return true; | 863 return true; |
| 864 } | 864 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 882 | 882 |
| 883 bool WebDatabase::InsertFormElement(const AutofillForm::Element& element, | 883 bool WebDatabase::InsertFormElement(const AutofillForm::Element& element, |
| 884 int64* pair_id) { | 884 int64* pair_id) { |
| 885 sql::Statement s(db_.GetUniqueStatement( | 885 sql::Statement s(db_.GetUniqueStatement( |
| 886 "INSERT INTO autofill (name, value, value_lower) VALUES (?,?,?)")); | 886 "INSERT INTO autofill (name, value, value_lower) VALUES (?,?,?)")); |
| 887 if (!s) { | 887 if (!s) { |
| 888 NOTREACHED() << "Statement prepare failed"; | 888 NOTREACHED() << "Statement prepare failed"; |
| 889 return false; | 889 return false; |
| 890 } | 890 } |
| 891 | 891 |
| 892 s.BindString(0, WideToUTF8(element.name)); | 892 s.BindString(0, UTF16ToUTF8(element.name)); |
| 893 s.BindString(1, WideToUTF8(element.value)); | 893 s.BindString(1, UTF16ToUTF8(element.value)); |
| 894 s.BindString(2, UTF16ToUTF8( | 894 s.BindString(2, UTF16ToUTF8(l10n_util::ToLower(element.value))); |
| 895 l10n_util::ToLower(WideToUTF16Hack(element.value)))); | |
| 896 | 895 |
| 897 if (!s.Run()) { | 896 if (!s.Run()) { |
| 898 NOTREACHED(); | 897 NOTREACHED(); |
| 899 return false; | 898 return false; |
| 900 } | 899 } |
| 901 | 900 |
| 902 *pair_id = db_.GetLastInsertRowId(); | 901 *pair_id = db_.GetLastInsertRowId(); |
| 903 return true; | 902 return true; |
| 904 } | 903 } |
| 905 | 904 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 949 if (!GetIDAndCountOfFormElement(element, &pair_id, &count)) | 948 if (!GetIDAndCountOfFormElement(element, &pair_id, &count)) |
| 950 return false; | 949 return false; |
| 951 | 950 |
| 952 if (count == 0 && !InsertFormElement(element, &pair_id)) | 951 if (count == 0 && !InsertFormElement(element, &pair_id)) |
| 953 return false; | 952 return false; |
| 954 | 953 |
| 955 return SetCountOfFormElement(pair_id, count + 1) && | 954 return SetCountOfFormElement(pair_id, count + 1) && |
| 956 InsertPairIDAndDate(pair_id, Time::Now()); | 955 InsertPairIDAndDate(pair_id, Time::Now()); |
| 957 } | 956 } |
| 958 | 957 |
| 959 bool WebDatabase::GetFormValuesForElementName(const std::wstring& name, | 958 bool WebDatabase::GetFormValuesForElementName(const string16& name, |
| 960 const std::wstring& prefix, | 959 const string16& prefix, |
| 961 std::vector<std::wstring>* values, | 960 std::vector<string16>* values, |
| 962 int limit) { | 961 int limit) { |
| 963 DCHECK(values); | 962 DCHECK(values); |
| 964 sql::Statement s; | 963 sql::Statement s; |
| 965 | 964 |
| 966 if (prefix.empty()) { | 965 if (prefix.empty()) { |
| 967 s.Assign(db_.GetUniqueStatement( | 966 s.Assign(db_.GetUniqueStatement( |
| 968 "SELECT value FROM autofill " | 967 "SELECT value FROM autofill " |
| 969 "WHERE name = ? " | 968 "WHERE name = ? " |
| 970 "ORDER BY count DESC " | 969 "ORDER BY count DESC " |
| 971 "LIMIT ?")); | 970 "LIMIT ?")); |
| 972 if (!s) { | 971 if (!s) { |
| 973 NOTREACHED() << "Statement prepare failed"; | 972 NOTREACHED() << "Statement prepare failed"; |
| 974 return false; | 973 return false; |
| 975 } | 974 } |
| 976 | 975 |
| 977 s.BindString(0, WideToUTF8(name)); | 976 s.BindString(0, UTF16ToUTF8(name)); |
| 978 s.BindInt(1, limit); | 977 s.BindInt(1, limit); |
| 979 } else { | 978 } else { |
| 980 string16 prefix_lower = l10n_util::ToLower(WideToUTF16Hack(prefix)); | 979 string16 prefix_lower = l10n_util::ToLower(prefix); |
| 981 string16 next_prefix = prefix_lower; | 980 string16 next_prefix = prefix_lower; |
| 982 next_prefix[next_prefix.length() - 1]++; | 981 next_prefix[next_prefix.length() - 1]++; |
| 983 | 982 |
| 984 s.Assign(db_.GetUniqueStatement( | 983 s.Assign(db_.GetUniqueStatement( |
| 985 "SELECT value FROM autofill " | 984 "SELECT value FROM autofill " |
| 986 "WHERE name = ? AND " | 985 "WHERE name = ? AND " |
| 987 "value_lower >= ? AND " | 986 "value_lower >= ? AND " |
| 988 "value_lower < ? " | 987 "value_lower < ? " |
| 989 "ORDER BY count DESC " | 988 "ORDER BY count DESC " |
| 990 "LIMIT ?")); | 989 "LIMIT ?")); |
| 991 if (!s) { | 990 if (!s) { |
| 992 NOTREACHED() << "Statement prepare failed"; | 991 NOTREACHED() << "Statement prepare failed"; |
| 993 return false; | 992 return false; |
| 994 } | 993 } |
| 995 | 994 |
| 996 s.BindString(0, WideToUTF8(name)); | 995 s.BindString(0, UTF16ToUTF8(name)); |
| 997 s.BindString(1, UTF16ToUTF8(prefix_lower)); | 996 s.BindString(1, UTF16ToUTF8(prefix_lower)); |
| 998 s.BindString(2, UTF16ToUTF8(next_prefix)); | 997 s.BindString(2, UTF16ToUTF8(next_prefix)); |
| 999 s.BindInt(3, limit); | 998 s.BindInt(3, limit); |
| 1000 } | 999 } |
| 1001 | 1000 |
| 1002 values->clear(); | 1001 values->clear(); |
| 1003 while (s.Step()) | 1002 while (s.Step()) |
| 1004 values->push_back(UTF8ToWide(s.ColumnString(0))); | 1003 values->push_back(UTF8ToUTF16(s.ColumnString(0))); |
| 1005 return s.Succeeded(); | 1004 return s.Succeeded(); |
| 1006 } | 1005 } |
| 1007 | 1006 |
| 1008 bool WebDatabase::RemoveFormElementsAddedBetween(base::Time delete_begin, | 1007 bool WebDatabase::RemoveFormElementsAddedBetween(base::Time delete_begin, |
| 1009 base::Time delete_end) { | 1008 base::Time delete_end) { |
| 1010 sql::Statement s(db_.GetUniqueStatement( | 1009 sql::Statement s(db_.GetUniqueStatement( |
| 1011 "SELECT DISTINCT pair_id FROM autofill_dates " | 1010 "SELECT DISTINCT pair_id FROM autofill_dates " |
| 1012 "WHERE date_created >= ? AND date_created < ?")); | 1011 "WHERE date_created >= ? AND date_created < ?")); |
| 1013 if (!s) { | 1012 if (!s) { |
| 1014 NOTREACHED() << "Statement 1 prepare failed"; | 1013 NOTREACHED() << "Statement 1 prepare failed"; |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1060 s.BindInt64(2, delete_end.is_null() ? std::numeric_limits<int64>::max() : | 1059 s.BindInt64(2, delete_end.is_null() ? std::numeric_limits<int64>::max() : |
| 1061 delete_end.ToTimeT()); | 1060 delete_end.ToTimeT()); |
| 1062 | 1061 |
| 1063 bool result = s.Run(); | 1062 bool result = s.Run(); |
| 1064 if (how_many) | 1063 if (how_many) |
| 1065 *how_many = db_.GetLastChangeCount(); | 1064 *how_many = db_.GetLastChangeCount(); |
| 1066 | 1065 |
| 1067 return result; | 1066 return result; |
| 1068 } | 1067 } |
| 1069 | 1068 |
| 1070 bool WebDatabase::RemoveFormElement(const std::wstring& name, | 1069 bool WebDatabase::RemoveFormElement(const string16& name, |
| 1071 const std::wstring& value) { | 1070 const string16& value) { |
| 1072 // Find the id for that pair. | 1071 // Find the id for that pair. |
| 1073 sql::Statement s(db_.GetUniqueStatement( | 1072 sql::Statement s(db_.GetUniqueStatement( |
| 1074 "SELECT pair_id FROM autofill WHERE name = ? AND value= ?")); | 1073 "SELECT pair_id FROM autofill WHERE name = ? AND value= ?")); |
| 1075 if (!s) { | 1074 if (!s) { |
| 1076 NOTREACHED() << "Statement 1 prepare failed"; | 1075 NOTREACHED() << "Statement 1 prepare failed"; |
| 1077 return false; | 1076 return false; |
| 1078 } | 1077 } |
| 1079 s.BindString(0, WideToUTF8(name)); | 1078 s.BindString(0, UTF16ToUTF8(name)); |
| 1080 s.BindString(1, WideToUTF8(value)); | 1079 s.BindString(1, UTF16ToUTF8(value)); |
| 1081 | 1080 |
| 1082 if (s.Step()) | 1081 if (s.Step()) |
| 1083 return RemoveFormElementForID(s.ColumnInt64(0)); | 1082 return RemoveFormElementForID(s.ColumnInt64(0)); |
| 1084 return false; | 1083 return false; |
| 1085 } | 1084 } |
| 1086 | 1085 |
| 1087 bool WebDatabase::AddToCountOfFormElement(int64 pair_id, int delta) { | 1086 bool WebDatabase::AddToCountOfFormElement(int64 pair_id, int delta) { |
| 1088 int count = 0; | 1087 int count = 0; |
| 1089 | 1088 |
| 1090 if (!GetCountOfFormElement(pair_id, &count)) | 1089 if (!GetCountOfFormElement(pair_id, &count)) |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1153 | 1152 |
| 1154 // Add successive versions here. Each should set the version number and | 1153 // Add successive versions here. Each should set the version number and |
| 1155 // compatible version number as appropriate, then fall through to the next | 1154 // compatible version number as appropriate, then fall through to the next |
| 1156 // case. | 1155 // case. |
| 1157 | 1156 |
| 1158 case kCurrentVersionNumber: | 1157 case kCurrentVersionNumber: |
| 1159 // No migration needed. | 1158 // No migration needed. |
| 1160 return; | 1159 return; |
| 1161 } | 1160 } |
| 1162 } | 1161 } |
| OLD | NEW |