| Index: components/previews/core/previews_opt_out_store_sql.cc
|
| diff --git a/components/previews/core/previews_opt_out_store_sql.cc b/components/previews/core/previews_opt_out_store_sql.cc
|
| index d4e6a59eac658be2f87160b297f2300a116749e2..14b5eaa08f2fbc5f88203a1bb776e3aec3de9e6d 100644
|
| --- a/components/previews/core/previews_opt_out_store_sql.cc
|
| +++ b/components/previews/core/previews_opt_out_store_sql.cc
|
| @@ -21,28 +21,20 @@
|
| #include "sql/transaction.h"
|
|
|
| namespace previews {
|
|
|
| namespace {
|
|
|
| // This is a macro instead of a const, so it can be used inline in other SQL
|
| // statements below.
|
| #define PREVIEWS_TABLE_NAME "previews_v1"
|
|
|
| -// The maximum number of entries allowed per host. Entries are evicted based on
|
| -// entry time.
|
| -const int kMaxRowsPerHost = 32;
|
| -
|
| -// The maximum number of entries allowed in the data base. Entries are evicted
|
| -// based on entry time.
|
| -const int kMaxRowsInDB = 3200;
|
| -
|
| void CreateSchema(sql::Connection* db) {
|
| const char kSql[] = "CREATE TABLE IF NOT EXISTS " PREVIEWS_TABLE_NAME
|
| " (host_name VARCHAR NOT NULL,"
|
| " time INTEGER NOT NULL,"
|
| " opt_out INTEGER NOT NULL,"
|
| " type INTEGER NOT NULL,"
|
| " PRIMARY KEY(host_name, time DESC, opt_out, type))";
|
| if (!db->Execute(kSql))
|
| return;
|
| }
|
| @@ -121,34 +113,34 @@ void AddPreviewNavigationToDataBase(sql::Connection* db,
|
| statement_insert.BindInt64(1, now.ToInternalValue());
|
| statement_insert.BindBool(2, opt_out);
|
| statement_insert.BindInt(3, static_cast<int>(type));
|
| statement_insert.Run();
|
| }
|
|
|
| // Removes entries for |host_name| if the per-host row limit is exceeded.
|
| // Removes entries if per data base row limit is exceeded.
|
| void MaybeEvictHostEntryFromDataBase(sql::Connection* db,
|
| const std::string& host_name) {
|
| - // Delete the oldest entries if there are more than |kMaxRowsPerHost| for
|
| - // |host_name|.
|
| + // Delete the oldest entries if there are more than |MaxRowsPerHostInOptOutDB|
|
| + // for |host_name|.
|
| // DELETE ... LIMIT -1 OFFSET x means delete all but the first x entries.
|
| const char kSqlDeleteByHost[] = "DELETE FROM " PREVIEWS_TABLE_NAME
|
| " WHERE ROWID IN"
|
| " (SELECT ROWID from " PREVIEWS_TABLE_NAME
|
| " WHERE host_name == ?"
|
| " ORDER BY time DESC"
|
| " LIMIT -1 OFFSET ?)";
|
|
|
| sql::Statement statement_delete_by_host(
|
| db->GetCachedStatement(SQL_FROM_HERE, kSqlDeleteByHost));
|
| statement_delete_by_host.BindString(0, host_name);
|
| - statement_delete_by_host.BindInt(1, kMaxRowsPerHost);
|
| + statement_delete_by_host.BindInt(1, MaxRowsPerHostInOptOutDB());
|
| statement_delete_by_host.Run();
|
| }
|
|
|
| void LoadBlackListFromDataBase(
|
| sql::Connection* db,
|
| scoped_refptr<base::SingleThreadTaskRunner> runner,
|
| LoadBlackListCallback callback) {
|
| // Gets the table sorted by host and time. Limits the number of hosts using
|
| // most recent opt_out time as the limiting function.
|
| const char kSql[] =
|
| @@ -171,32 +163,32 @@ void LoadBlackListFromDataBase(
|
| params::MaxInMemoryHostsInBlackList());
|
| // Allows the internal logic of PreviewsBlackListItem to determine how to
|
| // evict entries when there are more than
|
| // |StoredHistoryLengthForBlackList()| for the host.
|
| black_list_item->AddPreviewNavigation(
|
| statement.ColumnBool(2),
|
| base::Time::FromInternalValue(statement.ColumnInt64(1)));
|
| }
|
|
|
| // TODO(ryansturm): Add UMA to log |count|. crbug.com/656739
|
| - if (count > kMaxRowsInDB) {
|
| + if (count > MaxRowsInOptOutDB()) {
|
| // Delete the oldest entries if there are more than |kMaxEntriesInDB|.
|
| // DELETE ... LIMIT -1 OFFSET x means delete all but the first x entries.
|
| const char kSqlDeleteByDBSize[] = "DELETE FROM " PREVIEWS_TABLE_NAME
|
| " WHERE ROWID IN"
|
| " (SELECT ROWID from " PREVIEWS_TABLE_NAME
|
| " ORDER BY time DESC"
|
| " LIMIT -1 OFFSET ?)";
|
|
|
| sql::Statement statement_delete(
|
| db->GetCachedStatement(SQL_FROM_HERE, kSqlDeleteByDBSize));
|
| - statement_delete.BindInt(0, kMaxRowsInDB);
|
| + statement_delete.BindInt(0, MaxRowsInOptOutDB());
|
| statement_delete.Run();
|
| }
|
|
|
| runner->PostTask(FROM_HERE,
|
| base::Bind(callback, base::Passed(&black_list_item_map)));
|
| }
|
|
|
| // Synchronous implementations, these are run on the background thread
|
| // and actually do the work to access the SQL data base.
|
| void LoadBlackListSync(sql::Connection* db,
|
|
|