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

Side by Side Diff: components/history/core/browser/thumbnail_database.cc

Issue 1004373002: Add last_requested field to the favicon_bitmaps table of the favicons database. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address review comments 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "components/history/core/browser/thumbnail_database.h" 5 #include "components/history/core/browser/thumbnail_database.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 // the link tag. The FAVICON type is used for the default 51 // the link tag. The FAVICON type is used for the default
52 // favicon.ico favicon. 52 // favicon.ico favicon.
53 // 53 //
54 // favicon_bitmaps This table contains the PNG encoded bitmap data of the 54 // favicon_bitmaps This table contains the PNG encoded bitmap data of the
55 // favicons. There is a separate row for every size in a 55 // favicons. There is a separate row for every size in a
56 // multi resolution bitmap. The bitmap data is associated 56 // multi resolution bitmap. The bitmap data is associated
57 // to the favicon via the |icon_id| field which matches 57 // to the favicon via the |icon_id| field which matches
58 // the |id| field in the appropriate row in the |favicons| 58 // the |id| field in the appropriate row in the |favicons|
59 // table. 59 // table.
60 // 60 //
61 // id Unique ID. 61 // id Unique ID.
62 // icon_id The ID of the favicon that the bitmap is associated to. 62 // icon_id The ID of the favicon that the bitmap is associated to.
63 // last_updated The time at which this favicon was inserted into the 63 // last_updated The time at which this favicon was inserted into the
64 // table. This is used to determine if it needs to be 64 // table. This is used to determine if it needs to be
65 // redownloaded from the web. 65 // redownloaded from the web.
66 // image_data PNG encoded data of the favicon. 66 // last_requested The time at which this bitmap was last requested. This is
67 // width Pixel width of |image_data|. 67 // used to determine the priority with which the bitmap
68 // height Pixel height of |image_data|. 68 // should be retained on cleanup.
69 // image_data PNG encoded data of the favicon.
70 // width Pixel width of |image_data|.
71 // height Pixel height of |image_data|.
69 72
70 namespace { 73 namespace {
71 74
72 // For this database, schema migrations are deprecated after two 75 // For this database, schema migrations are deprecated after two
73 // years. This means that the oldest non-deprecated version should be 76 // years. This means that the oldest non-deprecated version should be
74 // two years old or greater (thus the migrations to get there are 77 // two years old or greater (thus the migrations to get there are
75 // older). Databases containing deprecated versions will be cleared 78 // older). Databases containing deprecated versions will be cleared
76 // at startup. Since this database is a cache, losing old data is not 79 // at startup. Since this database is a cache, losing old data is not
77 // fatal (in fact, very old data may be expired immediately at startup 80 // fatal (in fact, very old data may be expired immediately at startup
78 // anyhow). 81 // anyhow).
79 82
83 // Version 8: ???????? by rogerm@chromium.org on 2015-??-??
80 // Version 7: 911a634d/r209424 by qsr@chromium.org on 2013-07-01 84 // Version 7: 911a634d/r209424 by qsr@chromium.org on 2013-07-01
81 // Version 6: 610f923b/r152367 by pkotwicz@chromium.org on 2012-08-20 85 // Version 6: 610f923b/r152367 by pkotwicz@chromium.org on 2012-08-20
82 // Version 5: e2ee8ae9/r105004 by groby@chromium.org on 2011-10-12 86 // Version 5: e2ee8ae9/r105004 by groby@chromium.org on 2011-10-12 (deprecated)
Scott Hess - ex-Googler 2015/03/19 21:32:22 Cool beans. I was going to suggest that earlier,
Roger McFarlane (Chromium) 2015/03/20 14:40:59 With they way recovery/upgrade is done, it was mes
83 // Version 4: 5f104d76/r77288 by sky@chromium.org on 2011-03-08 (deprecated) 87 // Version 4: 5f104d76/r77288 by sky@chromium.org on 2011-03-08 (deprecated)
84 // Version 3: 09911bf3/r15 by initial.commit on 2008-07-26 (deprecated) 88 // Version 3: 09911bf3/r15 by initial.commit on 2008-07-26 (deprecated)
85 89
86 // Version number of the database. 90 // Version number of the database.
87 // NOTE(shess): When changing the version, add a new golden file for 91 // NOTE(shess): When changing the version, add a new golden file for
88 // the new version and a test to verify that Init() works with it. 92 // the new version and a test to verify that Init() works with it.
89 const int kCurrentVersionNumber = 7; 93 const int kCurrentVersionNumber = 8;
90 const int kCompatibleVersionNumber = 7; 94 const int kCompatibleVersionNumber = 8;
91 const int kDeprecatedVersionNumber = 4; // and earlier. 95 const int kDeprecatedVersionNumber = 5; // and earlier.
92 96
93 void FillIconMapping(const sql::Statement& statement, 97 void FillIconMapping(const sql::Statement& statement,
94 const GURL& page_url, 98 const GURL& page_url,
95 IconMapping* icon_mapping) { 99 IconMapping* icon_mapping) {
96 icon_mapping->mapping_id = statement.ColumnInt64(0); 100 icon_mapping->mapping_id = statement.ColumnInt64(0);
97 icon_mapping->icon_id = statement.ColumnInt64(1); 101 icon_mapping->icon_id = statement.ColumnInt64(1);
98 icon_mapping->icon_type = 102 icon_mapping->icon_type =
99 static_cast<favicon_base::IconType>(statement.ColumnInt(2)); 103 static_cast<favicon_base::IconType>(statement.ColumnInt(2));
100 icon_mapping->icon_url = GURL(statement.ColumnString(3)); 104 icon_mapping->icon_url = GURL(statement.ColumnString(3));
101 icon_mapping->page_url = page_url; 105 icon_mapping->page_url = page_url;
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 return false; 307 return false;
304 308
305 const char kFaviconBitmapsSql[] = 309 const char kFaviconBitmapsSql[] =
306 "CREATE TABLE IF NOT EXISTS favicon_bitmaps" 310 "CREATE TABLE IF NOT EXISTS favicon_bitmaps"
307 "(" 311 "("
308 "id INTEGER PRIMARY KEY," 312 "id INTEGER PRIMARY KEY,"
309 "icon_id INTEGER NOT NULL," 313 "icon_id INTEGER NOT NULL,"
310 "last_updated INTEGER DEFAULT 0," 314 "last_updated INTEGER DEFAULT 0,"
311 "image_data BLOB," 315 "image_data BLOB,"
312 "width INTEGER DEFAULT 0," 316 "width INTEGER DEFAULT 0,"
313 "height INTEGER DEFAULT 0" 317 "height INTEGER DEFAULT 0,"
318 // This field is at the end so that fresh tables and migrated tables have
319 // the same layout.
320 "last_requested INTEGER DEFAULT 0"
314 ")"; 321 ")";
315 if (!db->Execute(kFaviconBitmapsSql)) 322 if (!db->Execute(kFaviconBitmapsSql))
316 return false; 323 return false;
317 324
318 return true; 325 return true;
319 } 326 }
320 327
321 // NOTE(shess): Schema modifications must consider initial creation in 328 // NOTE(shess): Schema modifications must consider initial creation in
322 // |InitImpl()|, recovery in |RecoverDatabaseOrRaze()|, and history pruning in 329 // |InitImpl()|, recovery in |RecoverDatabaseOrRaze()|, and history pruning in
323 // |RetainDataForPageUrls()|. 330 // |RetainDataForPageUrls()|.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 // Recover the database to the extent possible, razing it if recovery 396 // Recover the database to the extent possible, razing it if recovery
390 // is not possible. 397 // is not possible.
391 // TODO(shess): This is mostly just a safe proof of concept. In the 398 // TODO(shess): This is mostly just a safe proof of concept. In the
392 // real world, this database is probably not worthwhile recovering, as 399 // real world, this database is probably not worthwhile recovering, as
393 // opposed to just razing it and starting over whenever corruption is 400 // opposed to just razing it and starting over whenever corruption is
394 // detected. So this database is a good test subject. 401 // detected. So this database is a good test subject.
395 void RecoverDatabaseOrRaze(sql::Connection* db, const base::FilePath& db_path) { 402 void RecoverDatabaseOrRaze(sql::Connection* db, const base::FilePath& db_path) {
396 // NOTE(shess): This code is currently specific to the version 403 // NOTE(shess): This code is currently specific to the version
397 // number. I am working on simplifying things to loosen the 404 // number. I am working on simplifying things to loosen the
398 // dependency, meanwhile contact me if you need to bump the version. 405 // dependency, meanwhile contact me if you need to bump the version.
399 DCHECK_EQ(7, kCurrentVersionNumber); 406 DCHECK_EQ(8, kCurrentVersionNumber);
400 407
401 // TODO(shess): Reset back after? 408 // TODO(shess): Reset back after?
402 db->reset_error_callback(); 409 db->reset_error_callback();
403 410
404 // For histogram purposes. 411 // For histogram purposes.
405 size_t favicons_rows_recovered = 0; 412 size_t favicons_rows_recovered = 0;
406 size_t favicon_bitmaps_rows_recovered = 0; 413 size_t favicon_bitmaps_rows_recovered = 0;
407 size_t icon_mapping_rows_recovered = 0; 414 size_t icon_mapping_rows_recovered = 0;
408 int64 original_size = 0; 415 int64 original_size = 0;
409 base::GetFileSize(db_path, &original_size); 416 base::GetFileSize(db_path, &original_size);
(...skipping 23 matching lines...) Expand all
433 // way, unclear how to resolve. 440 // way, unclear how to resolve.
434 sql::Recovery::Rollback(recovery.Pass()); 441 sql::Recovery::Rollback(recovery.Pass());
435 RecordRecoveryEvent(RECOVERY_EVENT_FAILED_META_VERSION); 442 RecordRecoveryEvent(RECOVERY_EVENT_FAILED_META_VERSION);
436 return; 443 return;
437 } 444 }
438 445
439 // This code may be able to fetch version information that the regular 446 // This code may be able to fetch version information that the regular
440 // deprecation path cannot. 447 // deprecation path cannot.
441 // NOTE(shess): v5 and v6 are currently not deprecated in the normal Init() 448 // NOTE(shess): v5 and v6 are currently not deprecated in the normal Init()
442 // path, but are deprecated in the recovery path in the interest of keeping 449 // path, but are deprecated in the recovery path in the interest of keeping
443 // the code simple. http://crbug.com/327485 for numbers. 450 // the code simple. http://crbug.com/327485 for numbers.
pkotwicz 2015/03/20 19:51:55 Nit: Can you please update the comment?
Roger McFarlane (Chromium) 2015/03/27 14:40:18 See: https://codereview.chromium.org/1010973011
444 DCHECK_LE(kDeprecatedVersionNumber, 6); 451 DCHECK_LE(kDeprecatedVersionNumber, 6);
445 if (version <= 6) { 452 if (version <= 6) {
446 sql::Recovery::Unrecoverable(recovery.Pass()); 453 sql::Recovery::Unrecoverable(recovery.Pass());
447 RecordRecoveryEvent(RECOVERY_EVENT_DEPRECATED); 454 RecordRecoveryEvent(RECOVERY_EVENT_DEPRECATED);
448 return; 455 return;
449 } 456 }
450 457
451 // Earlier versions have been handled or deprecated, later versions should be 458 // Earlier versions have been handled or deprecated.
452 // impossible. 459 if (version < 7) {
453 if (version != 7) {
454 sql::Recovery::Unrecoverable(recovery.Pass()); 460 sql::Recovery::Unrecoverable(recovery.Pass());
455 RecordRecoveryEvent(RECOVERY_EVENT_FAILED_META_WRONG_VERSION); 461 RecordRecoveryEvent(RECOVERY_EVENT_FAILED_META_WRONG_VERSION);
456 return; 462 return;
457 } 463 }
458 464
459 // Recover to current schema version. 465 // Recover to current schema version.
460 sql::MetaTable recover_meta_table; 466 sql::MetaTable recover_meta_table;
461 if (!recover_meta_table.Init(recovery->db(), kCurrentVersionNumber, 467 if (!recover_meta_table.Init(recovery->db(), kCurrentVersionNumber,
462 kCompatibleVersionNumber)) { 468 kCompatibleVersionNumber)) {
463 sql::Recovery::Rollback(recovery.Pass()); 469 sql::Recovery::Rollback(recovery.Pass());
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 if (status == sql::INIT_OK) 612 if (status == sql::INIT_OK)
607 return status; 613 return status;
608 614
609 meta_table_.Reset(); 615 meta_table_.Reset();
610 db_.Close(); 616 db_.Close();
611 } 617 }
612 return status; 618 return status;
613 } 619 }
614 620
615 void ThumbnailDatabase::ComputeDatabaseMetrics() { 621 void ThumbnailDatabase::ComputeDatabaseMetrics() {
616 sql::Statement favicon_count( 622 // Count all icon files referenced by the DB.
617 db_.GetCachedStatement(SQL_FROM_HERE, "SELECT COUNT(*) FROM favicons")); 623 {
618 UMA_HISTOGRAM_COUNTS_10000( 624 sql::Statement favicon_count(
619 "History.NumFaviconsInDB", 625 db_.GetCachedStatement(SQL_FROM_HERE, "SELECT COUNT(*) FROM favicons"));
620 favicon_count.Step() ? favicon_count.ColumnInt(0) : 0); 626 UMA_HISTOGRAM_COUNTS_10000(
627 "History.NumFaviconsInDB",
628 favicon_count.Step() ? favicon_count.ColumnInt(0) : 0);
629 }
630
631 // Count all bitmap resources cached in the DB.
632 {
633 sql::Statement bitmap_count(
634 db_.GetCachedStatement(
635 SQL_FROM_HERE, "SELECT COUNT(*) FROM favicon_bitmaps"));
636 UMA_HISTOGRAM_COUNTS_10000(
637 "History.NumBitmapsInDB",
638 bitmap_count.Step() ? bitmap_count.ColumnInt(0) : 0);
639 }
621 } 640 }
622 641
623 void ThumbnailDatabase::BeginTransaction() { 642 void ThumbnailDatabase::BeginTransaction() {
624 db_.BeginTransaction(); 643 db_.BeginTransaction();
625 } 644 }
626 645
627 void ThumbnailDatabase::CommitTransaction() { 646 void ThumbnailDatabase::CommitTransaction() {
628 db_.CommitTransaction(); 647 db_.CommitTransaction();
629 } 648 }
630 649
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 *png_icon_data = data; 739 *png_icon_data = data;
721 } 740 }
722 741
723 if (pixel_size) { 742 if (pixel_size) {
724 *pixel_size = gfx::Size(statement.ColumnInt(2), 743 *pixel_size = gfx::Size(statement.ColumnInt(2),
725 statement.ColumnInt(3)); 744 statement.ColumnInt(3));
726 } 745 }
727 return true; 746 return true;
728 } 747 }
729 748
749 bool ThumbnailDatabase::GetFaviconBitmapLastRequestedTime(
750 FaviconBitmapID bitmap_id,
751 base::Time* last_requested) {
752 DCHECK(bitmap_id);
753 DCHECK(last_requested);
754 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
755 "SELECT last_requested FROM favicon_bitmaps WHERE id=?"));
756 statement.BindInt64(0, bitmap_id);
757
758 if (!statement.Step())
759 return false;
760
761 *last_requested = base::Time::FromInternalValue(statement.ColumnInt64(0));
762 return true;
763 }
764
730 FaviconBitmapID ThumbnailDatabase::AddFaviconBitmap( 765 FaviconBitmapID ThumbnailDatabase::AddFaviconBitmap(
731 favicon_base::FaviconID icon_id, 766 favicon_base::FaviconID icon_id,
732 const scoped_refptr<base::RefCountedMemory>& icon_data, 767 const scoped_refptr<base::RefCountedMemory>& icon_data,
733 base::Time time, 768 base::Time time,
734 const gfx::Size& pixel_size) { 769 const gfx::Size& pixel_size) {
735 DCHECK(icon_id); 770 DCHECK(icon_id);
736 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 771 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
737 "INSERT INTO favicon_bitmaps (icon_id, image_data, last_updated, width, " 772 "INSERT INTO favicon_bitmaps (icon_id, image_data, last_updated, width, "
738 "height) VALUES (?, ?, ?, ?, ?)")); 773 "height) VALUES (?, ?, ?, ?, ?)"));
739 statement.BindInt64(0, icon_id); 774 statement.BindInt64(0, icon_id);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 FaviconBitmapID bitmap_id, 810 FaviconBitmapID bitmap_id,
776 base::Time time) { 811 base::Time time) {
777 DCHECK(bitmap_id); 812 DCHECK(bitmap_id);
778 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 813 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
779 "UPDATE favicon_bitmaps SET last_updated=? WHERE id=?")); 814 "UPDATE favicon_bitmaps SET last_updated=? WHERE id=?"));
780 statement.BindInt64(0, time.ToInternalValue()); 815 statement.BindInt64(0, time.ToInternalValue());
781 statement.BindInt64(1, bitmap_id); 816 statement.BindInt64(1, bitmap_id);
782 return statement.Run(); 817 return statement.Run();
783 } 818 }
784 819
820 bool ThumbnailDatabase::SetFaviconBitmapLastRequestedTime(
821 FaviconBitmapID bitmap_id,
822 base::Time time) {
823 DCHECK(bitmap_id);
824 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
825 "UPDATE favicon_bitmaps SET last_requested=? WHERE id=?"));
826 statement.BindInt64(0, time.ToInternalValue());
827 statement.BindInt64(1, bitmap_id);
828 return statement.Run();
829 }
830
785 bool ThumbnailDatabase::DeleteFaviconBitmap(FaviconBitmapID bitmap_id) { 831 bool ThumbnailDatabase::DeleteFaviconBitmap(FaviconBitmapID bitmap_id) {
786 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 832 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
787 "DELETE FROM favicon_bitmaps WHERE id=?")); 833 "DELETE FROM favicon_bitmaps WHERE id=?"));
788 statement.BindInt64(0, bitmap_id); 834 statement.BindInt64(0, bitmap_id);
789 return statement.Run(); 835 return statement.Run();
790 } 836 }
791 837
792 bool ThumbnailDatabase::SetFaviconOutOfDate(favicon_base::FaviconID icon_id) { 838 bool ThumbnailDatabase::SetFaviconOutOfDate(favicon_base::FaviconID icon_id) {
793 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 839 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
794 "UPDATE favicon_bitmaps SET last_updated=? WHERE icon_id=?")); 840 "UPDATE favicon_bitmaps SET last_updated=? WHERE icon_id=?"));
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
1079 const char kRenameFaviconsTable[] = 1125 const char kRenameFaviconsTable[] =
1080 "ALTER TABLE favicons RENAME TO old_favicons"; 1126 "ALTER TABLE favicons RENAME TO old_favicons";
1081 const char kCopyFavicons[] = 1127 const char kCopyFavicons[] =
1082 "INSERT INTO favicons (id, url, icon_type) " 1128 "INSERT INTO favicons (id, url, icon_type) "
1083 "SELECT mapping.new_icon_id, old.url, old.icon_type " 1129 "SELECT mapping.new_icon_id, old.url, old.icon_type "
1084 "FROM old_favicons AS old " 1130 "FROM old_favicons AS old "
1085 "JOIN temp.icon_id_mapping AS mapping " 1131 "JOIN temp.icon_id_mapping AS mapping "
1086 "ON (old.id = mapping.old_icon_id)"; 1132 "ON (old.id = mapping.old_icon_id)";
1087 const char kDropOldFaviconsTable[] = "DROP TABLE old_favicons"; 1133 const char kDropOldFaviconsTable[] = "DROP TABLE old_favicons";
1088 1134
1135 // Note that we allow the last_requested field to be reset to the default
1136 // value (0).
1089 const char kRenameFaviconBitmapsTable[] = 1137 const char kRenameFaviconBitmapsTable[] =
1090 "ALTER TABLE favicon_bitmaps RENAME TO old_favicon_bitmaps"; 1138 "ALTER TABLE favicon_bitmaps RENAME TO old_favicon_bitmaps";
1091 const char kCopyFaviconBitmaps[] = 1139 const char kCopyFaviconBitmaps[] =
1092 "INSERT INTO favicon_bitmaps " 1140 "INSERT INTO favicon_bitmaps "
1093 " (icon_id, last_updated, image_data, width, height) " 1141 " (icon_id, last_updated, image_data, width, height) "
1094 "SELECT mapping.new_icon_id, old.last_updated, " 1142 "SELECT mapping.new_icon_id, old.last_updated, "
1095 " old.image_data, old.width, old.height " 1143 " old.image_data, old.width, old.height "
1096 "FROM old_favicon_bitmaps AS old " 1144 "FROM old_favicon_bitmaps AS old "
1097 "JOIN temp.icon_id_mapping AS mapping " 1145 "JOIN temp.icon_id_mapping AS mapping "
1098 "ON (old.icon_id = mapping.old_icon_id)"; 1146 "ON (old.icon_id = mapping.old_icon_id)";
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 return sql::INIT_FAILURE; 1234 return sql::INIT_FAILURE;
1187 1235
1188 // TODO(shess): Failing Begin() implies that something serious is 1236 // TODO(shess): Failing Begin() implies that something serious is
1189 // wrong with the database. Raze() may be in order. 1237 // wrong with the database. Raze() may be in order.
1190 1238
1191 #if defined(OS_MACOSX) && !defined(OS_IOS) 1239 #if defined(OS_MACOSX) && !defined(OS_IOS)
1192 // Exclude the thumbnails file from backups. 1240 // Exclude the thumbnails file from backups.
1193 base::mac::SetFileBackupExclusion(db_name); 1241 base::mac::SetFileBackupExclusion(db_name);
1194 #endif 1242 #endif
1195 1243
1196 // thumbnails table has been obsolete for a long time, remove any 1244 // thumbnails table has been obsolete for a long time, remove any
huangs 2015/03/19 19:14:11 NIT: unwrap?
beaudoin 2015/03/19 21:36:54 I'm fine leaving it wrapped, 90% of the multi-line
Roger McFarlane (Chromium) 2015/03/20 14:41:00 Acknowledged.
Roger McFarlane (Chromium) 2015/03/20 14:41:00 Done.
1197 // detrious. 1245 // detritus.
1198 ignore_result(db_.Execute("DROP TABLE IF EXISTS thumbnails")); 1246 ignore_result(db_.Execute("DROP TABLE IF EXISTS thumbnails"));
1199 1247
1200 // At some point, operations involving temporary tables weren't done 1248 // At some point, operations involving temporary tables weren't done
1201 // atomically and users have been stranded. Drop those tables and 1249 // atomically and users have been stranded. Drop those tables and
1202 // move on. 1250 // move on.
1203 // TODO(shess): Prove it? Audit all cases and see if it's possible 1251 // TODO(shess): Prove it? Audit all cases and see if it's possible
1204 // that this implies non-atomic update, and should thus be handled 1252 // that this implies non-atomic update, and should thus be handled
1205 // via the corruption handler. 1253 // via the corruption handler.
1206 ignore_result(db_.Execute("DROP TABLE IF EXISTS temp_favicons")); 1254 ignore_result(db_.Execute("DROP TABLE IF EXISTS temp_favicons"));
1207 ignore_result(db_.Execute("DROP TABLE IF EXISTS temp_favicon_bitmaps")); 1255 ignore_result(db_.Execute("DROP TABLE IF EXISTS temp_favicon_bitmaps"));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 if (!UpgradeToVersion6()) 1293 if (!UpgradeToVersion6())
1246 return CantUpgradeToVersion(cur_version); 1294 return CantUpgradeToVersion(cur_version);
1247 } 1295 }
1248 1296
1249 if (cur_version == 6) { 1297 if (cur_version == 6) {
1250 ++cur_version; 1298 ++cur_version;
1251 if (!UpgradeToVersion7()) 1299 if (!UpgradeToVersion7())
1252 return CantUpgradeToVersion(cur_version); 1300 return CantUpgradeToVersion(cur_version);
1253 } 1301 }
1254 1302
1303 if (cur_version == 7) {
1304 ++cur_version;
1305 if (!UpgradeToVersion8())
1306 return CantUpgradeToVersion(cur_version);
1307 }
1308
1255 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) << 1309 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) <<
1256 "Thumbnail database version " << cur_version << " is too old to handle."; 1310 "Thumbnail database version " << cur_version << " is too old to handle.";
1257 1311
1258 // Initialization is complete. 1312 // Initialization is complete.
1259 if (!transaction.Commit()) 1313 if (!transaction.Commit())
1260 return sql::INIT_FAILURE; 1314 return sql::INIT_FAILURE;
1261 1315
1262 // Raze the database if the structure of the favicons database is not what 1316 // Raze the database if the structure of the favicons database is not what
1263 // it should be. This error cannot be detected via the SQL error code because 1317 // it should be. This error cannot be detected via the SQL error code because
1264 // the error code for running SQL statements against a database with missing 1318 // the error code for running SQL statements against a database with missing
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1325 db_.Execute("CREATE INDEX IF NOT EXISTS favicons_url ON favicons(url)"); 1379 db_.Execute("CREATE INDEX IF NOT EXISTS favicons_url ON favicons(url)");
1326 1380
1327 if (!success) 1381 if (!success)
1328 return false; 1382 return false;
1329 1383
1330 meta_table_.SetVersionNumber(7); 1384 meta_table_.SetVersionNumber(7);
1331 meta_table_.SetCompatibleVersionNumber(std::min(7, kCompatibleVersionNumber)); 1385 meta_table_.SetCompatibleVersionNumber(std::min(7, kCompatibleVersionNumber));
1332 return true; 1386 return true;
1333 } 1387 }
1334 1388
1389 bool ThumbnailDatabase::UpgradeToVersion8() {
1390 // Add the last_requested column to the favicon_bitmaps table.
1391 const char kFaviconBitmapsAddLastRequestedSql[] =
1392 "ALTER TABLE favicon_bitmaps ADD COLUMN last_requested INTEGER DEFAULT 0";
1393 if (!db_.Execute(kFaviconBitmapsAddLastRequestedSql))
1394 return false;
1395
1396
huangs 2015/03/19 19:14:11 NIT: extra space. I recently learned about "git c
Roger McFarlane (Chromium) 2015/03/20 14:41:00 Done.
1397 meta_table_.SetVersionNumber(8);
1398 meta_table_.SetCompatibleVersionNumber(std::min(8, kCompatibleVersionNumber));
1399 return true;
1400 }
1401
1335 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { 1402 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() {
1336 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); 1403 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons");
1337 } 1404 }
1338 1405
1339 } // namespace history 1406 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698