Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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) |
| 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 Loading... | |
| 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 Loading... | |
| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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. |
| 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 Loading... | |
| 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); | |
|
pkotwicz
2015/03/20 19:51:55
Can you explain why you are adding this UMA stat?
Roger McFarlane (Chromium)
2015/03/27 14:40:19
This change was moved to https://codereview.chromi
| |
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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). | |
|
pkotwicz
2015/03/20 19:51:55
We should copy the last_requested field over. Havi
Roger McFarlane (Chromium)
2015/03/27 14:40:18
Done.
| |
| 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 Loading... | |
| 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 detritus. |
| 1197 // detrious. | |
| 1198 ignore_result(db_.Execute("DROP TABLE IF EXISTS thumbnails")); | 1245 ignore_result(db_.Execute("DROP TABLE IF EXISTS thumbnails")); |
| 1199 | 1246 |
| 1200 // At some point, operations involving temporary tables weren't done | 1247 // At some point, operations involving temporary tables weren't done |
| 1201 // atomically and users have been stranded. Drop those tables and | 1248 // atomically and users have been stranded. Drop those tables and |
| 1202 // move on. | 1249 // move on. |
| 1203 // TODO(shess): Prove it? Audit all cases and see if it's possible | 1250 // 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 | 1251 // that this implies non-atomic update, and should thus be handled |
| 1205 // via the corruption handler. | 1252 // via the corruption handler. |
| 1206 ignore_result(db_.Execute("DROP TABLE IF EXISTS temp_favicons")); | 1253 ignore_result(db_.Execute("DROP TABLE IF EXISTS temp_favicons")); |
| 1207 ignore_result(db_.Execute("DROP TABLE IF EXISTS temp_favicon_bitmaps")); | 1254 ignore_result(db_.Execute("DROP TABLE IF EXISTS temp_favicon_bitmaps")); |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1233 } | 1280 } |
| 1234 | 1281 |
| 1235 if (cur_version < 7 && !db_.DoesColumnExist("favicons", "sizes")) { | 1282 if (cur_version < 7 && !db_.DoesColumnExist("favicons", "sizes")) { |
| 1236 LOG(ERROR) << "Raze because of missing favicon.sizes"; | 1283 LOG(ERROR) << "Raze because of missing favicon.sizes"; |
| 1237 RecordInvalidStructure(STRUCTURE_EVENT_VERSION5); | 1284 RecordInvalidStructure(STRUCTURE_EVENT_VERSION5); |
| 1238 | 1285 |
| 1239 db_.RazeAndClose(); | 1286 db_.RazeAndClose(); |
| 1240 return sql::INIT_FAILURE; | 1287 return sql::INIT_FAILURE; |
| 1241 } | 1288 } |
| 1242 | 1289 |
| 1243 if (cur_version == 5) { | 1290 if (cur_version == 5) { |
|
pkotwicz
2015/03/20 19:51:55
Given that version 5 is now deprecated shouldn't t
Roger McFarlane (Chromium)
2015/03/27 14:40:18
Done.
See: https://codereview.chromium.org/101097
| |
| 1244 ++cur_version; | 1291 ++cur_version; |
| 1245 if (!UpgradeToVersion6()) | 1292 if (!UpgradeToVersion6()) |
| 1246 return CantUpgradeToVersion(cur_version); | 1293 return CantUpgradeToVersion(cur_version); |
| 1247 } | 1294 } |
| 1248 | 1295 |
| 1249 if (cur_version == 6) { | 1296 if (cur_version == 6) { |
| 1250 ++cur_version; | 1297 ++cur_version; |
| 1251 if (!UpgradeToVersion7()) | 1298 if (!UpgradeToVersion7()) |
| 1252 return CantUpgradeToVersion(cur_version); | 1299 return CantUpgradeToVersion(cur_version); |
| 1253 } | 1300 } |
| 1254 | 1301 |
| 1302 if (cur_version == 7) { | |
| 1303 ++cur_version; | |
| 1304 if (!UpgradeToVersion8()) | |
| 1305 return CantUpgradeToVersion(cur_version); | |
| 1306 } | |
| 1307 | |
| 1255 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) << | 1308 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) << |
| 1256 "Thumbnail database version " << cur_version << " is too old to handle."; | 1309 "Thumbnail database version " << cur_version << " is too old to handle."; |
| 1257 | 1310 |
| 1258 // Initialization is complete. | 1311 // Initialization is complete. |
| 1259 if (!transaction.Commit()) | 1312 if (!transaction.Commit()) |
| 1260 return sql::INIT_FAILURE; | 1313 return sql::INIT_FAILURE; |
| 1261 | 1314 |
| 1262 // Raze the database if the structure of the favicons database is not what | 1315 // 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 | 1316 // 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 | 1317 // the error code for running SQL statements against a database with missing |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1325 db_.Execute("CREATE INDEX IF NOT EXISTS favicons_url ON favicons(url)"); | 1378 db_.Execute("CREATE INDEX IF NOT EXISTS favicons_url ON favicons(url)"); |
| 1326 | 1379 |
| 1327 if (!success) | 1380 if (!success) |
| 1328 return false; | 1381 return false; |
| 1329 | 1382 |
| 1330 meta_table_.SetVersionNumber(7); | 1383 meta_table_.SetVersionNumber(7); |
| 1331 meta_table_.SetCompatibleVersionNumber(std::min(7, kCompatibleVersionNumber)); | 1384 meta_table_.SetCompatibleVersionNumber(std::min(7, kCompatibleVersionNumber)); |
| 1332 return true; | 1385 return true; |
| 1333 } | 1386 } |
| 1334 | 1387 |
| 1388 bool ThumbnailDatabase::UpgradeToVersion8() { | |
| 1389 // Add the last_requested column to the favicon_bitmaps table. | |
| 1390 const char kFaviconBitmapsAddLastRequestedSql[] = | |
| 1391 "ALTER TABLE favicon_bitmaps ADD COLUMN last_requested INTEGER DEFAULT 0"; | |
| 1392 if (!db_.Execute(kFaviconBitmapsAddLastRequestedSql)) | |
| 1393 return false; | |
|
pkotwicz
2015/03/20 19:51:55
I wonder whether adding an extra index would be us
Roger McFarlane (Chromium)
2015/03/27 14:40:18
Yes, that's something I wanted to discuss more as
Scott Hess - ex-Googler
2015/03/27 17:59:33
The CL doesn't contain any information about which
| |
| 1394 | |
| 1395 meta_table_.SetVersionNumber(8); | |
| 1396 meta_table_.SetCompatibleVersionNumber(std::min(8, kCompatibleVersionNumber)); | |
| 1397 return true; | |
| 1398 } | |
| 1399 | |
| 1335 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { | 1400 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { |
| 1336 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); | 1401 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); |
| 1337 } | 1402 } |
| 1338 | 1403 |
| 1339 } // namespace history | 1404 } // namespace history |
| OLD | NEW |