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

Unified Diff: components/password_manager/core/browser/statistics_table.cc

Issue 2320763002: Support origin-based deletion for password store statistics (Closed)
Patch Set: Mac-specific code Created 4 years, 3 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: components/password_manager/core/browser/statistics_table.cc
diff --git a/components/password_manager/core/browser/statistics_table.cc b/components/password_manager/core/browser/statistics_table.cc
index bc174f021f3326f5b19afcc29805eb32cca5064a..0b6cc2cc0c4b7a8fe1bf9c779d5e088414bebe7e 100644
--- a/components/password_manager/core/browser/statistics_table.cc
+++ b/components/password_manager/core/browser/statistics_table.cc
@@ -8,6 +8,7 @@
#include <algorithm>
#include <limits>
+#include <set>
#include "base/memory/ptr_util.h"
#include "sql/connection.h"
@@ -126,15 +127,54 @@ std::vector<std::unique_ptr<InteractionsStats>> StatisticsTable::GetRows(
return result;
}
-bool StatisticsTable::RemoveStatsBetween(base::Time delete_begin,
- base::Time delete_end) {
- sql::Statement s(db_->GetCachedStatement(
- SQL_FROM_HERE,
- "DELETE FROM stats WHERE update_time >= ? AND update_time < ?"));
- s.BindInt64(0, delete_begin.ToInternalValue());
- s.BindInt64(1, delete_end.is_null() ? std::numeric_limits<int64_t>::max()
- : delete_end.ToInternalValue());
- return s.Run();
+bool StatisticsTable::RemoveStatsByOriginAndTime(
+ const base::Callback<bool(const GURL&)>& origin_filter,
+ base::Time delete_begin,
+ base::Time delete_end) {
+ if (delete_end.is_null())
+ delete_end = base::Time::Max();
+
+ // All origins.
+ if (origin_filter.is_null()) {
+ sql::Statement delete_statement(db_->GetCachedStatement(
+ SQL_FROM_HERE,
+ "DELETE FROM stats WHERE update_time >= ? AND update_time < ?"));
+ delete_statement.BindInt64(0, delete_begin.ToInternalValue());
+ delete_statement.BindInt64(1, delete_end.ToInternalValue());
+
+ return delete_statement.Run();
+ }
+
+ // Origin filtering.
+ sql::Statement select_statement(
+ db_->GetCachedStatement(SQL_FROM_HERE,
+ "SELECT origin_domain FROM stats "
+ "WHERE update_time >= ? AND update_time < ?"));
+ select_statement.BindInt64(0, delete_begin.ToInternalValue());
+ select_statement.BindInt64(1, delete_end.ToInternalValue());
+
+ std::set<std::string> origins;
+ while (select_statement.Step()) {
+ if (!origin_filter.Run(GURL(select_statement.ColumnString(0))))
+ continue;
+
+ origins.insert(select_statement.ColumnString(0));
+ }
+
+ bool success = true;
+
+ for (const std::string& origin : origins) {
+ sql::Statement origin_delete_statement(db_->GetCachedStatement(
+ SQL_FROM_HERE,
+ "DELETE FROM stats "
+ "WHERE origin_domain = ? AND update_time >= ? AND update_time < ?"));
+ origin_delete_statement.BindString(0, origin);
+ origin_delete_statement.BindInt64(1, delete_begin.ToInternalValue());
+ origin_delete_statement.BindInt64(2, delete_end.ToInternalValue());
+ success = success && origin_delete_statement.Run();
+ }
+
+ return success;
}
} // namespace password_manager

Powered by Google App Engine
This is Rietveld 408576698