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

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: Merge GetFaviconBitmapLastRequestedtime into GetFaviconBitmap. Created 5 years, 8 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
« no previous file with comments | « components/history/core/browser/thumbnail_database.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 // image_data PNG encoded data of the favicon.
67 // width Pixel width of |image_data|. 67 // width Pixel width of |image_data|.
68 // height Pixel height of |image_data|. 68 // height Pixel height of |image_data|.
69 // last_requested The time at which this bitmap was last requested. This is
70 // used to determine the priority with which the bitmap
71 // should be retained on cleanup.
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 (deprecated) 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 = 5; // 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));
(...skipping 202 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
441 // NOTE(shess,rogerm): v6 is not currently deprecated in the normal Init() 448 // NOTE(shess,rogerm): v6 is not currently deprecated in the normal Init()
442 // path, but is deprecated in the recovery path in the interest of keeping 449 // path, but is 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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 bitmap_id_sizes->push_back(bitmap_id_size); 669 bitmap_id_sizes->push_back(bitmap_id_size);
664 } 670 }
665 return result; 671 return result;
666 } 672 }
667 673
668 bool ThumbnailDatabase::GetFaviconBitmaps( 674 bool ThumbnailDatabase::GetFaviconBitmaps(
669 favicon_base::FaviconID icon_id, 675 favicon_base::FaviconID icon_id,
670 std::vector<FaviconBitmap>* favicon_bitmaps) { 676 std::vector<FaviconBitmap>* favicon_bitmaps) {
671 DCHECK(icon_id); 677 DCHECK(icon_id);
672 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 678 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
673 "SELECT id, last_updated, image_data, width, height FROM favicon_bitmaps " 679 "SELECT id, last_updated, image_data, width, height, last_requested "
674 "WHERE icon_id=?")); 680 "FROM favicon_bitmaps WHERE icon_id=?"));
675 statement.BindInt64(0, icon_id); 681 statement.BindInt64(0, icon_id);
676 682
677 bool result = false; 683 bool result = false;
678 while (statement.Step()) { 684 while (statement.Step()) {
679 result = true; 685 result = true;
680 if (!favicon_bitmaps) 686 if (!favicon_bitmaps)
681 return result; 687 return result;
682 688
683 FaviconBitmap favicon_bitmap; 689 FaviconBitmap favicon_bitmap;
684 favicon_bitmap.bitmap_id = statement.ColumnInt64(0); 690 favicon_bitmap.bitmap_id = statement.ColumnInt64(0);
685 favicon_bitmap.icon_id = icon_id; 691 favicon_bitmap.icon_id = icon_id;
686 favicon_bitmap.last_updated = 692 favicon_bitmap.last_updated =
687 base::Time::FromInternalValue(statement.ColumnInt64(1)); 693 base::Time::FromInternalValue(statement.ColumnInt64(1));
688 if (statement.ColumnByteLength(2) > 0) { 694 if (statement.ColumnByteLength(2) > 0) {
689 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes()); 695 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes());
690 statement.ColumnBlobAsVector(2, &data->data()); 696 statement.ColumnBlobAsVector(2, &data->data());
691 favicon_bitmap.bitmap_data = data; 697 favicon_bitmap.bitmap_data = data;
692 } 698 }
693 favicon_bitmap.pixel_size = gfx::Size(statement.ColumnInt(3), 699 favicon_bitmap.pixel_size = gfx::Size(statement.ColumnInt(3),
694 statement.ColumnInt(4)); 700 statement.ColumnInt(4));
701 favicon_bitmap.last_requested =
702 base::Time::FromInternalValue(statement.ColumnInt64(5));
695 favicon_bitmaps->push_back(favicon_bitmap); 703 favicon_bitmaps->push_back(favicon_bitmap);
696 } 704 }
697 return result; 705 return result;
698 } 706 }
699 707
700 bool ThumbnailDatabase::GetFaviconBitmap( 708 bool ThumbnailDatabase::GetFaviconBitmap(
701 FaviconBitmapID bitmap_id, 709 FaviconBitmapID bitmap_id,
702 base::Time* last_updated, 710 base::Time* last_updated,
711 base::Time* last_requested,
703 scoped_refptr<base::RefCountedMemory>* png_icon_data, 712 scoped_refptr<base::RefCountedMemory>* png_icon_data,
704 gfx::Size* pixel_size) { 713 gfx::Size* pixel_size) {
705 DCHECK(bitmap_id); 714 DCHECK(bitmap_id);
706 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 715 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
707 "SELECT last_updated, image_data, width, height FROM favicon_bitmaps " 716 "SELECT last_updated, image_data, width, height, last_requested "
708 "WHERE id=?")); 717 "FROM favicon_bitmaps WHERE id=?"));
709 statement.BindInt64(0, bitmap_id); 718 statement.BindInt64(0, bitmap_id);
710 719
711 if (!statement.Step()) 720 if (!statement.Step())
712 return false; 721 return false;
713 722
714 if (last_updated) 723 if (last_updated)
715 *last_updated = base::Time::FromInternalValue(statement.ColumnInt64(0)); 724 *last_updated = base::Time::FromInternalValue(statement.ColumnInt64(0));
716 725
717 if (png_icon_data && statement.ColumnByteLength(1) > 0) { 726 if (png_icon_data && statement.ColumnByteLength(1) > 0) {
718 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes()); 727 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes());
719 statement.ColumnBlobAsVector(1, &data->data()); 728 statement.ColumnBlobAsVector(1, &data->data());
720 *png_icon_data = data; 729 *png_icon_data = data;
721 } 730 }
722 731
723 if (pixel_size) { 732 if (pixel_size) {
724 *pixel_size = gfx::Size(statement.ColumnInt(2), 733 *pixel_size = gfx::Size(statement.ColumnInt(2),
725 statement.ColumnInt(3)); 734 statement.ColumnInt(3));
726 } 735 }
736
737 if (last_requested)
738 *last_requested = base::Time::FromInternalValue(statement.ColumnInt64(4));
739
727 return true; 740 return true;
728 } 741 }
729 742
730 FaviconBitmapID ThumbnailDatabase::AddFaviconBitmap( 743 FaviconBitmapID ThumbnailDatabase::AddFaviconBitmap(
731 favicon_base::FaviconID icon_id, 744 favicon_base::FaviconID icon_id,
732 const scoped_refptr<base::RefCountedMemory>& icon_data, 745 const scoped_refptr<base::RefCountedMemory>& icon_data,
733 base::Time time, 746 base::Time time,
734 const gfx::Size& pixel_size) { 747 const gfx::Size& pixel_size) {
735 DCHECK(icon_id); 748 DCHECK(icon_id);
736 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 749 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 FaviconBitmapID bitmap_id, 788 FaviconBitmapID bitmap_id,
776 base::Time time) { 789 base::Time time) {
777 DCHECK(bitmap_id); 790 DCHECK(bitmap_id);
778 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 791 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
779 "UPDATE favicon_bitmaps SET last_updated=? WHERE id=?")); 792 "UPDATE favicon_bitmaps SET last_updated=? WHERE id=?"));
780 statement.BindInt64(0, time.ToInternalValue()); 793 statement.BindInt64(0, time.ToInternalValue());
781 statement.BindInt64(1, bitmap_id); 794 statement.BindInt64(1, bitmap_id);
782 return statement.Run(); 795 return statement.Run();
783 } 796 }
784 797
798 bool ThumbnailDatabase::SetFaviconBitmapLastRequestedTime(
799 FaviconBitmapID bitmap_id,
800 base::Time time) {
801 DCHECK(bitmap_id);
802 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
803 "UPDATE favicon_bitmaps SET last_requested=? WHERE id=?"));
804 statement.BindInt64(0, time.ToInternalValue());
805 statement.BindInt64(1, bitmap_id);
806 return statement.Run();
807 }
808
785 bool ThumbnailDatabase::DeleteFaviconBitmap(FaviconBitmapID bitmap_id) { 809 bool ThumbnailDatabase::DeleteFaviconBitmap(FaviconBitmapID bitmap_id) {
786 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 810 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
787 "DELETE FROM favicon_bitmaps WHERE id=?")); 811 "DELETE FROM favicon_bitmaps WHERE id=?"));
788 statement.BindInt64(0, bitmap_id); 812 statement.BindInt64(0, bitmap_id);
789 return statement.Run(); 813 return statement.Run();
790 } 814 }
791 815
792 bool ThumbnailDatabase::SetFaviconOutOfDate(favicon_base::FaviconID icon_id) { 816 bool ThumbnailDatabase::SetFaviconOutOfDate(favicon_base::FaviconID icon_id) {
793 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 817 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
794 "UPDATE favicon_bitmaps SET last_updated=? WHERE icon_id=?")); 818 "UPDATE favicon_bitmaps SET last_updated=? WHERE icon_id=?"));
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 "SELECT mapping.new_icon_id, old.url, old.icon_type " 1107 "SELECT mapping.new_icon_id, old.url, old.icon_type "
1084 "FROM old_favicons AS old " 1108 "FROM old_favicons AS old "
1085 "JOIN temp.icon_id_mapping AS mapping " 1109 "JOIN temp.icon_id_mapping AS mapping "
1086 "ON (old.id = mapping.old_icon_id)"; 1110 "ON (old.id = mapping.old_icon_id)";
1087 const char kDropOldFaviconsTable[] = "DROP TABLE old_favicons"; 1111 const char kDropOldFaviconsTable[] = "DROP TABLE old_favicons";
1088 1112
1089 const char kRenameFaviconBitmapsTable[] = 1113 const char kRenameFaviconBitmapsTable[] =
1090 "ALTER TABLE favicon_bitmaps RENAME TO old_favicon_bitmaps"; 1114 "ALTER TABLE favicon_bitmaps RENAME TO old_favicon_bitmaps";
1091 const char kCopyFaviconBitmaps[] = 1115 const char kCopyFaviconBitmaps[] =
1092 "INSERT INTO favicon_bitmaps " 1116 "INSERT INTO favicon_bitmaps "
1093 " (icon_id, last_updated, image_data, width, height) " 1117 " (icon_id, last_updated, image_data, width, height, last_requested) "
1094 "SELECT mapping.new_icon_id, old.last_updated, " 1118 "SELECT mapping.new_icon_id, old.last_updated, "
1095 " old.image_data, old.width, old.height " 1119 " old.image_data, old.width, old.height, old.last_requested "
1096 "FROM old_favicon_bitmaps AS old " 1120 "FROM old_favicon_bitmaps AS old "
1097 "JOIN temp.icon_id_mapping AS mapping " 1121 "JOIN temp.icon_id_mapping AS mapping "
1098 "ON (old.icon_id = mapping.old_icon_id)"; 1122 "ON (old.icon_id = mapping.old_icon_id)";
1099 const char kDropOldFaviconBitmapsTable[] = 1123 const char kDropOldFaviconBitmapsTable[] =
1100 "DROP TABLE old_favicon_bitmaps"; 1124 "DROP TABLE old_favicon_bitmaps";
1101 1125
1102 // Rename existing tables to new location. 1126 // Rename existing tables to new location.
1103 if (!db_.Execute(kRenameIconMappingTable) || 1127 if (!db_.Execute(kRenameIconMappingTable) ||
1104 !db_.Execute(kRenameFaviconsTable) || 1128 !db_.Execute(kRenameFaviconsTable) ||
1105 !db_.Execute(kRenameFaviconBitmapsTable)) { 1129 !db_.Execute(kRenameFaviconBitmapsTable)) {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 return sql::INIT_FAILURE; 1210 return sql::INIT_FAILURE;
1187 1211
1188 // TODO(shess): Failing Begin() implies that something serious is 1212 // TODO(shess): Failing Begin() implies that something serious is
1189 // wrong with the database. Raze() may be in order. 1213 // wrong with the database. Raze() may be in order.
1190 1214
1191 #if defined(OS_MACOSX) && !defined(OS_IOS) 1215 #if defined(OS_MACOSX) && !defined(OS_IOS)
1192 // Exclude the thumbnails file from backups. 1216 // Exclude the thumbnails file from backups.
1193 base::mac::SetFileBackupExclusion(db_name); 1217 base::mac::SetFileBackupExclusion(db_name);
1194 #endif 1218 #endif
1195 1219
1196 // thumbnails table has been obsolete for a long time, remove any 1220 // thumbnails table has been obsolete for a long time, remove any detritus.
1197 // detrious.
1198 ignore_result(db_.Execute("DROP TABLE IF EXISTS thumbnails")); 1221 ignore_result(db_.Execute("DROP TABLE IF EXISTS thumbnails"));
1199 1222
1200 // At some point, operations involving temporary tables weren't done 1223 // At some point, operations involving temporary tables weren't done
1201 // atomically and users have been stranded. Drop those tables and 1224 // atomically and users have been stranded. Drop those tables and
1202 // move on. 1225 // move on.
1203 // TODO(shess): Prove it? Audit all cases and see if it's possible 1226 // 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 1227 // that this implies non-atomic update, and should thus be handled
1205 // via the corruption handler. 1228 // via the corruption handler.
1206 ignore_result(db_.Execute("DROP TABLE IF EXISTS temp_favicons")); 1229 ignore_result(db_.Execute("DROP TABLE IF EXISTS temp_favicons"));
1207 ignore_result(db_.Execute("DROP TABLE IF EXISTS temp_favicon_bitmaps")); 1230 ignore_result(db_.Execute("DROP TABLE IF EXISTS temp_favicon_bitmaps"));
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1239 db_.RazeAndClose(); 1262 db_.RazeAndClose();
1240 return sql::INIT_FAILURE; 1263 return sql::INIT_FAILURE;
1241 } 1264 }
1242 1265
1243 if (cur_version == 6) { 1266 if (cur_version == 6) {
1244 ++cur_version; 1267 ++cur_version;
1245 if (!UpgradeToVersion7()) 1268 if (!UpgradeToVersion7())
1246 return CantUpgradeToVersion(cur_version); 1269 return CantUpgradeToVersion(cur_version);
1247 } 1270 }
1248 1271
1272 if (cur_version == 7) {
1273 ++cur_version;
1274 if (!UpgradeToVersion8())
1275 return CantUpgradeToVersion(cur_version);
1276 }
1277
1249 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) << 1278 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) <<
1250 "Thumbnail database version " << cur_version << " is too old to handle."; 1279 "Thumbnail database version " << cur_version << " is too old to handle.";
1251 1280
1252 // Initialization is complete. 1281 // Initialization is complete.
1253 if (!transaction.Commit()) 1282 if (!transaction.Commit())
1254 return sql::INIT_FAILURE; 1283 return sql::INIT_FAILURE;
1255 1284
1256 // Raze the database if the structure of the favicons database is not what 1285 // Raze the database if the structure of the favicons database is not what
1257 // it should be. This error cannot be detected via the SQL error code because 1286 // it should be. This error cannot be detected via the SQL error code because
1258 // the error code for running SQL statements against a database with missing 1287 // the error code for running SQL statements against a database with missing
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1293 db_.Execute("CREATE INDEX IF NOT EXISTS favicons_url ON favicons(url)"); 1322 db_.Execute("CREATE INDEX IF NOT EXISTS favicons_url ON favicons(url)");
1294 1323
1295 if (!success) 1324 if (!success)
1296 return false; 1325 return false;
1297 1326
1298 meta_table_.SetVersionNumber(7); 1327 meta_table_.SetVersionNumber(7);
1299 meta_table_.SetCompatibleVersionNumber(std::min(7, kCompatibleVersionNumber)); 1328 meta_table_.SetCompatibleVersionNumber(std::min(7, kCompatibleVersionNumber));
1300 return true; 1329 return true;
1301 } 1330 }
1302 1331
1332 bool ThumbnailDatabase::UpgradeToVersion8() {
1333 // Add the last_requested column to the favicon_bitmaps table.
1334 const char kFaviconBitmapsAddLastRequestedSql[] =
1335 "ALTER TABLE favicon_bitmaps ADD COLUMN last_requested INTEGER DEFAULT 0";
1336 if (!db_.Execute(kFaviconBitmapsAddLastRequestedSql))
1337 return false;
1338
1339 meta_table_.SetVersionNumber(8);
1340 meta_table_.SetCompatibleVersionNumber(std::min(8, kCompatibleVersionNumber));
1341 return true;
1342 }
1343
1303 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { 1344 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() {
1304 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); 1345 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons");
1305 } 1346 }
1306 1347
1307 } // namespace history 1348 } // namespace history
OLDNEW
« no previous file with comments | « components/history/core/browser/thumbnail_database.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698