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

Side by Side Diff: chrome/browser/webdata/web_database.cc

Issue 42258: Add way to remove entries from autocomplete (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/webdata/web_database.h ('k') | chrome/common/render_messages_internal.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
861 } 861 }
862 862
863 std::set<int64> ids; 863 std::set<int64> ids;
864 int result; 864 int result;
865 while ((result = s.step()) == SQLITE_ROW) 865 while ((result = s.step()) == SQLITE_ROW)
866 ids.insert(s.column_int64(0)); 866 ids.insert(s.column_int64(0));
867 867
868 bool success = true; 868 bool success = true;
869 for (std::set<int64>::const_iterator iter = ids.begin(); iter != ids.end(); 869 for (std::set<int64>::const_iterator iter = ids.begin(); iter != ids.end();
870 ++iter) { 870 ++iter) {
871 if (!RemoveFormElement(*iter)) 871 if (!RemoveFormElementForID(*iter))
872 success = false; 872 success = false;
873 } 873 }
874 874
875 return success; 875 return success;
876 } 876 }
877 877
878 bool WebDatabase::GetIDAndCountOfFormElement( 878 bool WebDatabase::GetIDAndCountOfFormElement(
879 const AutofillForm::Element& element, int64* pair_id, int* count) { 879 const AutofillForm::Element& element, int64* pair_id, int* count) {
880 SQLStatement s; 880 SQLStatement s;
881 881
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 s.bind_int64(2, delete_end.is_null() ? std::numeric_limits<int64>::max() : 1110 s.bind_int64(2, delete_end.is_null() ? std::numeric_limits<int64>::max() :
1111 delete_end.ToTimeT()); 1111 delete_end.ToTimeT());
1112 1112
1113 bool result = (s.step() == SQLITE_DONE); 1113 bool result = (s.step() == SQLITE_DONE);
1114 if (how_many) 1114 if (how_many)
1115 *how_many = sqlite3_changes(db_); 1115 *how_many = sqlite3_changes(db_);
1116 1116
1117 return result; 1117 return result;
1118 } 1118 }
1119 1119
1120 bool WebDatabase::RemoveFormElement(const std::wstring& name,
1121 const std::wstring& value) {
1122 // Find the id for that pair.
1123 SQLStatement s;
1124 if (s.prepare(db_,
1125 "SELECT pair_id FROM autofill WHERE name = ? AND value= ?") !=
1126 SQLITE_OK) {
1127 NOTREACHED() << "Statement 1 prepare failed";
1128 return false;
1129 }
1130 s.bind_wstring(0, name);
1131 s.bind_wstring(1, value);
1132
1133 int result = s.step();
1134 if (result != SQLITE_ROW)
1135 return false;
1136
1137 return RemoveFormElementForID(s.column_int64(0));
1138 }
1139
1120 bool WebDatabase::AddToCountOfFormElement(int64 pair_id, int delta) { 1140 bool WebDatabase::AddToCountOfFormElement(int64 pair_id, int delta) {
1121 int count = 0; 1141 int count = 0;
1122 1142
1123 if (!GetCountOfFormElement(pair_id, &count)) 1143 if (!GetCountOfFormElement(pair_id, &count))
1124 return false; 1144 return false;
1125 1145
1126 if (count + delta == 0) { 1146 if (count + delta == 0) {
1127 if (!RemoveFormElement(pair_id)) 1147 if (!RemoveFormElementForID(pair_id))
1128 return false; 1148 return false;
1129 } else { 1149 } else {
1130 if (!SetCountOfFormElement(pair_id, count + delta)) 1150 if (!SetCountOfFormElement(pair_id, count + delta))
1131 return false; 1151 return false;
1132 } 1152 }
1133 return true; 1153 return true;
1134 } 1154 }
1135 1155
1136 bool WebDatabase::RemoveFormElement(int64 pair_id) { 1156 bool WebDatabase::RemoveFormElementForID(int64 pair_id) {
1137 SQLStatement s; 1157 SQLStatement s;
1138 if (s.prepare(db_, 1158 if (s.prepare(db_,
1139 "DELETE FROM autofill WHERE pair_id = ?") != SQLITE_OK) { 1159 "DELETE FROM autofill WHERE pair_id = ?") != SQLITE_OK) {
1140 NOTREACHED() << "Statement prepare failed"; 1160 NOTREACHED() << "Statement prepare failed";
1141 return false; 1161 return false;
1142 } 1162 }
1143 s.bind_int64(0, pair_id); 1163 s.bind_int64(0, pair_id);
1144 if (s.step() != SQLITE_DONE) 1164 if (s.step() != SQLITE_DONE)
1145 return false; 1165 return false;
1146 1166
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 1206
1187 // Add successive versions here. Each should set the version number and 1207 // Add successive versions here. Each should set the version number and
1188 // compatible version number as appropriate, then fall through to the next 1208 // compatible version number as appropriate, then fall through to the next
1189 // case. 1209 // case.
1190 1210
1191 case kCurrentVersionNumber: 1211 case kCurrentVersionNumber:
1192 // No migration needed. 1212 // No migration needed.
1193 return; 1213 return;
1194 } 1214 }
1195 } 1215 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/web_database.h ('k') | chrome/common/render_messages_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698