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..d6e6d1b9e88d41aafeccadb6427ace7c8d48dc37 100644 |
--- a/components/previews/core/previews_opt_out_store_sql.cc |
+++ b/components/previews/core/previews_opt_out_store_sql.cc |
@@ -146,62 +146,68 @@ void MaybeEvictHostEntryFromDataBase(sql::Connection* db, |
} |
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[] = |
"SELECT host_name, time, opt_out" |
- " FROM " PREVIEWS_TABLE_NAME; |
+ " FROM " PREVIEWS_TABLE_NAME " ORDER BY host_name, time DESC"; |
tbansal1
2016/10/25 16:15:48
May be add a comment explaining why ordering is im
RyanSturm
2016/10/25 18:15:44
Done.
|
sql::Statement statement(db->GetUniqueStatement(kSql)); |
std::unique_ptr<BlackListItemMap> black_list_item_map(new BlackListItemMap()); |
+ std::unique_ptr<PreviewsBlackListItem> host_indifferent_black_list_item = |
+ PreviewsBlackList::CreateHostIndifferentBlackListItem(); |
int count = 0; |
// Add the host name, the visit time, and opt out history to |
// |black_list_item_map|. |
while (statement.Step()) { |
++count; |
std::string host_name = statement.ColumnString(0); |
PreviewsBlackListItem* black_list_item = |
- PreviewsBlackList::GetOrCreateBlackListItem(black_list_item_map.get(), |
- host_name); |
+ PreviewsBlackList::GetOrCreateBlackListItemForMap( |
+ black_list_item_map.get(), host_name); |
DCHECK_LE(black_list_item_map->size(), |
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))); |
+ host_indifferent_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) { |
// 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.Run(); |
} |
runner->PostTask(FROM_HERE, |
- base::Bind(callback, base::Passed(&black_list_item_map))); |
+ base::Bind(callback, base::Passed(&black_list_item_map), |
+ base::Passed(&host_indifferent_black_list_item))); |
} |
// 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, |
const base::FilePath& path, |
scoped_refptr<base::SingleThreadTaskRunner> runner, |
LoadBlackListCallback callback) { |
if (!db->is_open()) |
InitDatabase(db, path); |