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

Unified Diff: chrome/browser/extensions/activity_log/counting_policy.cc

Issue 23629015: Add deletion to the activityLogPrivate API (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleaned up CountingPolicy::DoDeleteDatabase Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/extensions/activity_log/counting_policy.cc
diff --git a/chrome/browser/extensions/activity_log/counting_policy.cc b/chrome/browser/extensions/activity_log/counting_policy.cc
index 9188b48ad8bd2b69543ae0f190ed5e9a7c60b324..4b9f94e147f9645aebeba41f1b8bf22e442dd372 100644
--- a/chrome/browser/extensions/activity_log/counting_policy.cc
+++ b/chrome/browser/extensions/activity_log/counting_policy.cc
@@ -442,8 +442,9 @@ scoped_ptr<Action::ActionVector> CountingPolicy::DoReadFilteredData(
where_str += where_next + "arg_url LIKE ?";
std::string query_str = base::StringPrintf(
"SELECT extension_id,time, action_type, api_name, args, page_url,"
- "page_title, arg_url, other, count FROM %s WHERE %s ORDER BY time DESC",
+ "page_title, arg_url, other, count FROM %s %s %s ORDER BY time DESC",
kReadViewName,
+ where_str.empty() ? "" : "WHERE",
where_str.c_str());
sql::Statement query(db->GetUniqueStatement(query_str.c_str()));
int i = -1;
@@ -639,6 +640,51 @@ void CountingPolicy::DoRemoveURLs(const std::vector<GURL>& restrict_urls) {
CleanStringTables(db);
}
+void CountingPolicy::DoDeleteDatabase() {
+ sql::Connection* db = GetDatabaseConnection();
+ if (!db) {
+ LOG(ERROR) << "Unable to connect to database";
+ return;
+ }
+
+ queued_actions_.clear();
+
+ // Not wrapped in a transaction because a late failure shouldn't undo a
+ // previous deletion.
+ std::string sql_str = base::StringPrintf("DELETE FROM %s", kTableName);
+ sql::Statement statement(db->GetCachedStatement(
+ sql::StatementID(SQL_FROM_HERE),
+ sql_str.c_str()));
+ if (!statement.Run()) {
+ LOG(ERROR) << "Deleting the database failed: "
+ << statement.GetSQLStatement();
+ return;
+ }
+ statement.Clear();
+ statement.Assign(db->GetCachedStatement(sql::StatementID(SQL_FROM_HERE),
+ "DELETE FROM string_ids"));
+ if (!statement.Run()) {
+ LOG(ERROR) << "Deleting the database failed: "
+ << statement.GetSQLStatement();
+ return;
+ }
+ statement.Clear();
+ statement.Assign(db->GetCachedStatement(sql::StatementID(SQL_FROM_HERE),
+ "DELETE FROM url_ids"));
+ if (!statement.Run()) {
+ LOG(ERROR) << "Deleting the database failed: "
+ << statement.GetSQLStatement();
+ return;
+ }
+ statement.Clear();
+ statement.Assign(db->GetCachedStatement(sql::StatementID(SQL_FROM_HERE),
+ "VACUUM"));
+ if (!statement.Run()) {
+ LOG(ERROR) << "Vacuuming the database failed: "
+ << statement.GetSQLStatement();
+ }
+}
+
void CountingPolicy::ReadData(
const std::string& extension_id,
const int day,
@@ -678,6 +724,10 @@ void CountingPolicy::RemoveURLs(const std::vector<GURL>& restrict_urls) {
ScheduleAndForget(this, &CountingPolicy::DoRemoveURLs, restrict_urls);
}
+void CountingPolicy::DeleteDatabase() {
+ ScheduleAndForget(this, &CountingPolicy::DoDeleteDatabase);
+}
+
void CountingPolicy::OnDatabaseFailure() {
queued_actions_.clear();
}

Powered by Google App Engine
This is Rietveld 408576698