| 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 15d6c86a4e33ee9b15e67a8e359be71bf03bf053..e6d64700d6284a36fd4f45056265fc40ad24da8d 100644
|
| --- a/chrome/browser/extensions/activity_log/counting_policy.cc
|
| +++ b/chrome/browser/extensions/activity_log/counting_policy.cc
|
| @@ -442,9 +442,10 @@ 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 count DESC "
|
| + "page_title, arg_url, other, count FROM %s %s %s ORDER BY time DESC "
|
| "LIMIT 300",
|
| kReadViewName,
|
| + where_str.empty() ? "" : "WHERE",
|
| where_str.c_str());
|
| sql::Statement query(db->GetUniqueStatement(query_str.c_str()));
|
| int i = -1;
|
| @@ -640,6 +641,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,
|
| @@ -679,6 +725,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();
|
| }
|
|
|