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

Unified Diff: components/history/core/browser/thumbnail_database.cc

Issue 1005783003: Fix ThumbnailDatabase::RetainDataForPageUrls() to drop unretained page mappings (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « chrome/browser/history/thumbnail_database_unittest.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/history/core/browser/thumbnail_database.cc
diff --git a/components/history/core/browser/thumbnail_database.cc b/components/history/core/browser/thumbnail_database.cc
index c115c3cc8ca06ae560759357babc4462f6c51c85..e82888492a36db72869d5b2fc5544556922ceaa8 100644
--- a/components/history/core/browser/thumbnail_database.cc
+++ b/components/history/core/browser/thumbnail_database.cc
@@ -1024,6 +1024,24 @@ bool ThumbnailDatabase::RetainDataForPageUrls(
if (!transaction.Begin())
return false;
+ // Populate temp.retained_urls with |urls_to_keep|.
+ {
+ const char kCreateRetainedUrls[] =
+ "CREATE TEMP TABLE retained_urls (url LONGVARCHAR PRIMARY KEY)";
+ if (!db_.Execute(kCreateRetainedUrls))
+ return false;
+
+ const char kRetainedUrlSql[] =
+ "INSERT OR IGNORE INTO temp.retained_urls (url) VALUES (?)";
+ sql::Statement statement(db_.GetUniqueStatement(kRetainedUrlSql));
+ for (const GURL& url : urls_to_keep) {
+ statement.BindString(0, URLDatabase::GURLToDatabaseURL(url));
+ if (!statement.Run())
+ return false;
+ statement.Reset(true);
+ }
+ }
+
// temp.icon_id_mapping generates new icon ids as consecutive
// integers starting from 1, and maps them to the old icon ids.
{
@@ -1039,23 +1057,21 @@ bool ThumbnailDatabase::RetainDataForPageUrls(
// Insert the icon ids for retained urls, skipping duplicates.
const char kIconMappingSql[] =
"INSERT OR IGNORE INTO temp.icon_id_mapping (old_icon_id) "
- "SELECT icon_id FROM icon_mapping WHERE page_url = ?";
- sql::Statement statement(db_.GetUniqueStatement(kIconMappingSql));
- for (std::vector<GURL>::const_iterator
- i = urls_to_keep.begin(); i != urls_to_keep.end(); ++i) {
- statement.BindString(0, URLDatabase::GURLToDatabaseURL(*i));
- if (!statement.Run())
- return false;
- statement.Reset(true);
- }
+ "SELECT icon_id FROM icon_mapping "
+ "JOIN temp.retained_urls "
+ "ON (temp.retained_urls.url = icon_mapping.page_url)";
+ if (!db_.Execute(kIconMappingSql))
+ return false;
}
const char kRenameIconMappingTable[] =
"ALTER TABLE icon_mapping RENAME TO old_icon_mapping";
const char kCopyIconMapping[] =
"INSERT INTO icon_mapping (page_url, icon_id) "
- "SELECT old.page_url, mapping.new_icon_id "
- "FROM old_icon_mapping AS old "
+ "SELECT temp.retained_urls.url, mapping.new_icon_id "
+ "FROM temp.retained_urls "
+ "JOIN old_icon_mapping AS old "
+ "ON (temp.retained_urls.url = old.page_url) "
"JOIN temp.icon_id_mapping AS mapping "
"ON (old.icon_id = mapping.old_icon_id)";
const char kDropOldIconMappingTable[] = "DROP TABLE old_icon_mapping";
@@ -1117,7 +1133,8 @@ bool ThumbnailDatabase::RetainDataForPageUrls(
return false;
const char kIconMappingDrop[] = "DROP TABLE temp.icon_id_mapping";
- if (!db_.Execute(kIconMappingDrop))
+ const char kRetainedUrlsDrop[] = "DROP TABLE temp.retained_urls";
+ if (!db_.Execute(kIconMappingDrop) || !db_.Execute(kRetainedUrlsDrop))
return false;
return transaction.Commit();
« no previous file with comments | « chrome/browser/history/thumbnail_database_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698