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

Side by Side Diff: chrome/browser/history/thumbnail_database.cc

Issue 330603004: Rename FaviconBitmapXxx to FaviconRawBitmapXxx (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 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 | Annotate | Revision Log
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 "chrome/browser/history/thumbnail_database.h" 5 #include "chrome/browser/history/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 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 "CREATE TABLE IF NOT EXISTS favicons" 293 "CREATE TABLE IF NOT EXISTS favicons"
294 "(" 294 "("
295 "id INTEGER PRIMARY KEY," 295 "id INTEGER PRIMARY KEY,"
296 "url LONGVARCHAR NOT NULL," 296 "url LONGVARCHAR NOT NULL,"
297 // default icon_type FAVICON to be consistent with past migration. 297 // default icon_type FAVICON to be consistent with past migration.
298 "icon_type INTEGER DEFAULT 1" 298 "icon_type INTEGER DEFAULT 1"
299 ")"; 299 ")";
300 if (!db->Execute(kFaviconsSql)) 300 if (!db->Execute(kFaviconsSql))
301 return false; 301 return false;
302 302
303 const char kFaviconBitmapsSql[] = 303 const char kFaviconRawBitmapsSql[] =
304 "CREATE TABLE IF NOT EXISTS favicon_bitmaps" 304 "CREATE TABLE IF NOT EXISTS favicon_bitmaps"
305 "(" 305 "("
306 "id INTEGER PRIMARY KEY," 306 "id INTEGER PRIMARY KEY,"
307 "icon_id INTEGER NOT NULL," 307 "icon_id INTEGER NOT NULL,"
308 "last_updated INTEGER DEFAULT 0," 308 "last_updated INTEGER DEFAULT 0,"
309 "image_data BLOB," 309 "image_data BLOB,"
310 "width INTEGER DEFAULT 0," 310 "width INTEGER DEFAULT 0,"
311 "height INTEGER DEFAULT 0" 311 "height INTEGER DEFAULT 0"
312 ")"; 312 ")";
313 if (!db->Execute(kFaviconBitmapsSql)) 313 if (!db->Execute(kFaviconRawBitmapsSql))
314 return false; 314 return false;
315 315
316 return true; 316 return true;
317 } 317 }
318 318
319 // NOTE(shess): Schema modifications must consider initial creation in 319 // NOTE(shess): Schema modifications must consider initial creation in
320 // |InitImpl()|, recovery in |RecoverDatabaseOrRaze()|, and history pruning in 320 // |InitImpl()|, recovery in |RecoverDatabaseOrRaze()|, and history pruning in
321 // |RetainDataForPageUrls()|. 321 // |RetainDataForPageUrls()|.
322 bool InitIndices(sql::Connection* db) { 322 bool InitIndices(sql::Connection* db) {
323 const char kIconMappingUrlIndexSql[] = 323 const char kIconMappingUrlIndexSql[] =
324 "CREATE INDEX IF NOT EXISTS icon_mapping_page_url_idx" 324 "CREATE INDEX IF NOT EXISTS icon_mapping_page_url_idx"
325 " ON icon_mapping(page_url)"; 325 " ON icon_mapping(page_url)";
326 const char kIconMappingIdIndexSql[] = 326 const char kIconMappingIdIndexSql[] =
327 "CREATE INDEX IF NOT EXISTS icon_mapping_icon_id_idx" 327 "CREATE INDEX IF NOT EXISTS icon_mapping_icon_id_idx"
328 " ON icon_mapping(icon_id)"; 328 " ON icon_mapping(icon_id)";
329 if (!db->Execute(kIconMappingUrlIndexSql) || 329 if (!db->Execute(kIconMappingUrlIndexSql) ||
330 !db->Execute(kIconMappingIdIndexSql)) { 330 !db->Execute(kIconMappingIdIndexSql)) {
331 return false; 331 return false;
332 } 332 }
333 333
334 const char kFaviconsIndexSql[] = 334 const char kFaviconsIndexSql[] =
335 "CREATE INDEX IF NOT EXISTS favicons_url ON favicons(url)"; 335 "CREATE INDEX IF NOT EXISTS favicons_url ON favicons(url)";
336 if (!db->Execute(kFaviconsIndexSql)) 336 if (!db->Execute(kFaviconsIndexSql))
337 return false; 337 return false;
338 338
339 const char kFaviconBitmapsIndexSql[] = 339 const char kFaviconRawBitmapsIndexSql[] =
340 "CREATE INDEX IF NOT EXISTS favicon_bitmaps_icon_id ON " 340 "CREATE INDEX IF NOT EXISTS favicon_bitmaps_icon_id ON "
341 "favicon_bitmaps(icon_id)"; 341 "favicon_bitmaps(icon_id)";
342 if (!db->Execute(kFaviconBitmapsIndexSql)) 342 if (!db->Execute(kFaviconRawBitmapsIndexSql))
343 return false; 343 return false;
344 344
345 return true; 345 return true;
346 } 346 }
347 347
348 enum RecoveryEventType { 348 enum RecoveryEventType {
349 RECOVERY_EVENT_RECOVERED = 0, 349 RECOVERY_EVENT_RECOVERED = 0,
350 RECOVERY_EVENT_FAILED_SCOPER, 350 RECOVERY_EVENT_FAILED_SCOPER,
351 RECOVERY_EVENT_FAILED_META_VERSION_ERROR, // obsolete 351 RECOVERY_EVENT_FAILED_META_VERSION_ERROR, // obsolete
352 RECOVERY_EVENT_FAILED_META_VERSION_NONE, // obsolete 352 RECOVERY_EVENT_FAILED_META_VERSION_NONE, // obsolete
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 int percentage = static_cast<int>(original_size * 100 / final_size); 524 int percentage = static_cast<int>(original_size * 100 / final_size);
525 UMA_HISTOGRAM_PERCENTAGE("History.FaviconsRecoveredPercentage", 525 UMA_HISTOGRAM_PERCENTAGE("History.FaviconsRecoveredPercentage",
526 std::max(100, percentage)); 526 std::max(100, percentage));
527 } 527 }
528 528
529 // Using 10,000 because these cases mostly care about "none 529 // Using 10,000 because these cases mostly care about "none
530 // recovered" and "lots recovered". More than 10,000 rows recovered 530 // recovered" and "lots recovered". More than 10,000 rows recovered
531 // probably means there's something wrong with the profile. 531 // probably means there's something wrong with the profile.
532 UMA_HISTOGRAM_COUNTS_10000("History.FaviconsRecoveredRowsFavicons", 532 UMA_HISTOGRAM_COUNTS_10000("History.FaviconsRecoveredRowsFavicons",
533 favicons_rows_recovered); 533 favicons_rows_recovered);
534 UMA_HISTOGRAM_COUNTS_10000("History.FaviconsRecoveredRowsFaviconBitmaps", 534 UMA_HISTOGRAM_COUNTS_10000("History.FaviconsRecoveredRowsFaviconRawBitmaps",
535 favicon_bitmaps_rows_recovered); 535 favicon_bitmaps_rows_recovered);
536 UMA_HISTOGRAM_COUNTS_10000("History.FaviconsRecoveredRowsIconMapping", 536 UMA_HISTOGRAM_COUNTS_10000("History.FaviconsRecoveredRowsIconMapping",
537 icon_mapping_rows_recovered); 537 icon_mapping_rows_recovered);
538 538
539 RecordRecoveryEvent(RECOVERY_EVENT_RECOVERED); 539 RecordRecoveryEvent(RECOVERY_EVENT_RECOVERED);
540 } 540 }
541 541
542 void DatabaseErrorCallback(sql::Connection* db, 542 void DatabaseErrorCallback(sql::Connection* db,
543 const base::FilePath& db_path, 543 const base::FilePath& db_path,
544 size_t startup_kb, 544 size_t startup_kb,
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 void ThumbnailDatabase::Vacuum() { 638 void ThumbnailDatabase::Vacuum() {
639 DCHECK(db_.transaction_nesting() == 0) << 639 DCHECK(db_.transaction_nesting() == 0) <<
640 "Can not have a transaction when vacuuming."; 640 "Can not have a transaction when vacuuming.";
641 ignore_result(db_.Execute("VACUUM")); 641 ignore_result(db_.Execute("VACUUM"));
642 } 642 }
643 643
644 void ThumbnailDatabase::TrimMemory(bool aggressively) { 644 void ThumbnailDatabase::TrimMemory(bool aggressively) {
645 db_.TrimMemory(aggressively); 645 db_.TrimMemory(aggressively);
646 } 646 }
647 647
648 bool ThumbnailDatabase::GetFaviconBitmapIDSizes( 648 bool ThumbnailDatabase::GetFaviconRawBitmapIDSizes(
649 favicon_base::FaviconID icon_id, 649 favicon_base::FaviconID icon_id,
650 std::vector<FaviconBitmapIDSize>* bitmap_id_sizes) { 650 std::vector<FaviconRawBitmapIDSize>* bitmap_id_sizes) {
651 DCHECK(icon_id); 651 DCHECK(icon_id);
652 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 652 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
653 "SELECT id, width, height FROM favicon_bitmaps WHERE icon_id=?")); 653 "SELECT id, width, height FROM favicon_bitmaps WHERE icon_id=?"));
654 statement.BindInt64(0, icon_id); 654 statement.BindInt64(0, icon_id);
655 655
656 bool result = false; 656 bool result = false;
657 while (statement.Step()) { 657 while (statement.Step()) {
658 result = true; 658 result = true;
659 if (!bitmap_id_sizes) 659 if (!bitmap_id_sizes)
660 return result; 660 return result;
661 661
662 FaviconBitmapIDSize bitmap_id_size; 662 FaviconRawBitmapIDSize bitmap_id_size;
663 bitmap_id_size.bitmap_id = statement.ColumnInt64(0); 663 bitmap_id_size.bitmap_id = statement.ColumnInt64(0);
664 bitmap_id_size.pixel_size = gfx::Size(statement.ColumnInt(1), 664 bitmap_id_size.pixel_size = gfx::Size(statement.ColumnInt(1),
665 statement.ColumnInt(2)); 665 statement.ColumnInt(2));
666 bitmap_id_sizes->push_back(bitmap_id_size); 666 bitmap_id_sizes->push_back(bitmap_id_size);
667 } 667 }
668 return result; 668 return result;
669 } 669 }
670 670
671 bool ThumbnailDatabase::GetFaviconBitmaps( 671 bool ThumbnailDatabase::GetFaviconRawBitmaps(
672 favicon_base::FaviconID icon_id, 672 favicon_base::FaviconID icon_id,
673 std::vector<FaviconBitmap>* favicon_bitmaps) { 673 std::vector<FaviconRawBitmap>* favicon_bitmaps) {
674 DCHECK(icon_id); 674 DCHECK(icon_id);
675 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 675 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
676 "SELECT id, last_updated, image_data, width, height FROM favicon_bitmaps " 676 "SELECT id, last_updated, image_data, width, height FROM favicon_bitmaps "
677 "WHERE icon_id=?")); 677 "WHERE icon_id=?"));
678 statement.BindInt64(0, icon_id); 678 statement.BindInt64(0, icon_id);
679 679
680 bool result = false; 680 bool result = false;
681 while (statement.Step()) { 681 while (statement.Step()) {
682 result = true; 682 result = true;
683 if (!favicon_bitmaps) 683 if (!favicon_bitmaps)
684 return result; 684 return result;
685 685
686 FaviconBitmap favicon_bitmap; 686 FaviconRawBitmap favicon_bitmap;
687 favicon_bitmap.bitmap_id = statement.ColumnInt64(0); 687 favicon_bitmap.bitmap_id = statement.ColumnInt64(0);
688 favicon_bitmap.icon_id = icon_id; 688 favicon_bitmap.icon_id = icon_id;
689 favicon_bitmap.last_updated = 689 favicon_bitmap.last_updated =
690 base::Time::FromInternalValue(statement.ColumnInt64(1)); 690 base::Time::FromInternalValue(statement.ColumnInt64(1));
691 if (statement.ColumnByteLength(2) > 0) { 691 if (statement.ColumnByteLength(2) > 0) {
692 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes()); 692 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes());
693 statement.ColumnBlobAsVector(2, &data->data()); 693 statement.ColumnBlobAsVector(2, &data->data());
694 favicon_bitmap.bitmap_data = data; 694 favicon_bitmap.bitmap_data = data;
695 } 695 }
696 favicon_bitmap.pixel_size = gfx::Size(statement.ColumnInt(3), 696 favicon_bitmap.pixel_size = gfx::Size(statement.ColumnInt(3),
697 statement.ColumnInt(4)); 697 statement.ColumnInt(4));
698 favicon_bitmaps->push_back(favicon_bitmap); 698 favicon_bitmaps->push_back(favicon_bitmap);
699 } 699 }
700 return result; 700 return result;
701 } 701 }
702 702
703 bool ThumbnailDatabase::GetFaviconBitmap( 703 bool ThumbnailDatabase::GetFaviconRawBitmap(
704 FaviconBitmapID bitmap_id, 704 FaviconRawBitmapID bitmap_id,
705 base::Time* last_updated, 705 base::Time* last_updated,
706 scoped_refptr<base::RefCountedMemory>* png_icon_data, 706 scoped_refptr<base::RefCountedMemory>* png_icon_data,
707 gfx::Size* pixel_size) { 707 gfx::Size* pixel_size) {
708 DCHECK(bitmap_id); 708 DCHECK(bitmap_id);
709 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 709 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
710 "SELECT last_updated, image_data, width, height FROM favicon_bitmaps " 710 "SELECT last_updated, image_data, width, height FROM favicon_bitmaps "
711 "WHERE id=?")); 711 "WHERE id=?"));
712 statement.BindInt64(0, bitmap_id); 712 statement.BindInt64(0, bitmap_id);
713 713
714 if (!statement.Step()) 714 if (!statement.Step())
715 return false; 715 return false;
716 716
717 if (last_updated) 717 if (last_updated)
718 *last_updated = base::Time::FromInternalValue(statement.ColumnInt64(0)); 718 *last_updated = base::Time::FromInternalValue(statement.ColumnInt64(0));
719 719
720 if (png_icon_data && statement.ColumnByteLength(1) > 0) { 720 if (png_icon_data && statement.ColumnByteLength(1) > 0) {
721 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes()); 721 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes());
722 statement.ColumnBlobAsVector(1, &data->data()); 722 statement.ColumnBlobAsVector(1, &data->data());
723 *png_icon_data = data; 723 *png_icon_data = data;
724 } 724 }
725 725
726 if (pixel_size) { 726 if (pixel_size) {
727 *pixel_size = gfx::Size(statement.ColumnInt(2), 727 *pixel_size = gfx::Size(statement.ColumnInt(2),
728 statement.ColumnInt(3)); 728 statement.ColumnInt(3));
729 } 729 }
730 return true; 730 return true;
731 } 731 }
732 732
733 FaviconBitmapID ThumbnailDatabase::AddFaviconBitmap( 733 FaviconRawBitmapID ThumbnailDatabase::AddFaviconRawBitmap(
734 favicon_base::FaviconID icon_id, 734 favicon_base::FaviconID icon_id,
735 const scoped_refptr<base::RefCountedMemory>& icon_data, 735 const scoped_refptr<base::RefCountedMemory>& icon_data,
736 base::Time time, 736 base::Time time,
737 const gfx::Size& pixel_size) { 737 const gfx::Size& pixel_size) {
738 DCHECK(icon_id); 738 DCHECK(icon_id);
739 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 739 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
740 "INSERT INTO favicon_bitmaps (icon_id, image_data, last_updated, width, " 740 "INSERT INTO favicon_bitmaps (icon_id, image_data, last_updated, width, "
741 "height) VALUES (?, ?, ?, ?, ?)")); 741 "height) VALUES (?, ?, ?, ?, ?)"));
742 statement.BindInt64(0, icon_id); 742 statement.BindInt64(0, icon_id);
743 if (icon_data.get() && icon_data->size()) { 743 if (icon_data.get() && icon_data->size()) {
744 statement.BindBlob(1, icon_data->front(), 744 statement.BindBlob(1, icon_data->front(),
745 static_cast<int>(icon_data->size())); 745 static_cast<int>(icon_data->size()));
746 } else { 746 } else {
747 statement.BindNull(1); 747 statement.BindNull(1);
748 } 748 }
749 statement.BindInt64(2, time.ToInternalValue()); 749 statement.BindInt64(2, time.ToInternalValue());
750 statement.BindInt(3, pixel_size.width()); 750 statement.BindInt(3, pixel_size.width());
751 statement.BindInt(4, pixel_size.height()); 751 statement.BindInt(4, pixel_size.height());
752 752
753 if (!statement.Run()) 753 if (!statement.Run())
754 return 0; 754 return 0;
755 return db_.GetLastInsertRowId(); 755 return db_.GetLastInsertRowId();
756 } 756 }
757 757
758 bool ThumbnailDatabase::SetFaviconBitmap( 758 bool ThumbnailDatabase::SetFaviconRawBitmap(
759 FaviconBitmapID bitmap_id, 759 FaviconRawBitmapID bitmap_id,
760 scoped_refptr<base::RefCountedMemory> bitmap_data, 760 scoped_refptr<base::RefCountedMemory> bitmap_data,
761 base::Time time) { 761 base::Time time) {
762 DCHECK(bitmap_id); 762 DCHECK(bitmap_id);
763 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 763 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
764 "UPDATE favicon_bitmaps SET image_data=?, last_updated=? WHERE id=?")); 764 "UPDATE favicon_bitmaps SET image_data=?, last_updated=? WHERE id=?"));
765 if (bitmap_data.get() && bitmap_data->size()) { 765 if (bitmap_data.get() && bitmap_data->size()) {
766 statement.BindBlob(0, bitmap_data->front(), 766 statement.BindBlob(0, bitmap_data->front(),
767 static_cast<int>(bitmap_data->size())); 767 static_cast<int>(bitmap_data->size()));
768 } else { 768 } else {
769 statement.BindNull(0); 769 statement.BindNull(0);
770 } 770 }
771 statement.BindInt64(1, time.ToInternalValue()); 771 statement.BindInt64(1, time.ToInternalValue());
772 statement.BindInt64(2, bitmap_id); 772 statement.BindInt64(2, bitmap_id);
773 773
774 return statement.Run(); 774 return statement.Run();
775 } 775 }
776 776
777 bool ThumbnailDatabase::SetFaviconBitmapLastUpdateTime( 777 bool ThumbnailDatabase::SetFaviconRawBitmapLastUpdateTime(
778 FaviconBitmapID bitmap_id, 778 FaviconRawBitmapID bitmap_id,
779 base::Time time) { 779 base::Time time) {
780 DCHECK(bitmap_id); 780 DCHECK(bitmap_id);
781 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 781 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
782 "UPDATE favicon_bitmaps SET last_updated=? WHERE id=?")); 782 "UPDATE favicon_bitmaps SET last_updated=? WHERE id=?"));
783 statement.BindInt64(0, time.ToInternalValue()); 783 statement.BindInt64(0, time.ToInternalValue());
784 statement.BindInt64(1, bitmap_id); 784 statement.BindInt64(1, bitmap_id);
785 return statement.Run(); 785 return statement.Run();
786 } 786 }
787 787
788 bool ThumbnailDatabase::DeleteFaviconBitmap(FaviconBitmapID bitmap_id) { 788 bool ThumbnailDatabase::DeleteFaviconRawBitmap(FaviconRawBitmapID bitmap_id) {
789 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 789 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
790 "DELETE FROM favicon_bitmaps WHERE id=?")); 790 "DELETE FROM favicon_bitmaps WHERE id=?"));
791 statement.BindInt64(0, bitmap_id); 791 statement.BindInt64(0, bitmap_id);
792 return statement.Run(); 792 return statement.Run();
793 } 793 }
794 794
795 bool ThumbnailDatabase::SetFaviconOutOfDate(favicon_base::FaviconID icon_id) { 795 bool ThumbnailDatabase::SetFaviconOutOfDate(favicon_base::FaviconID icon_id) {
796 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 796 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
797 "UPDATE favicon_bitmaps SET last_updated=? WHERE icon_id=?")); 797 "UPDATE favicon_bitmaps SET last_updated=? WHERE icon_id=?"));
798 statement.BindInt64(0, 0); 798 statement.BindInt64(0, 0);
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
853 return db_.GetLastInsertRowId(); 853 return db_.GetLastInsertRowId();
854 } 854 }
855 855
856 favicon_base::FaviconID ThumbnailDatabase::AddFavicon( 856 favicon_base::FaviconID ThumbnailDatabase::AddFavicon(
857 const GURL& icon_url, 857 const GURL& icon_url,
858 favicon_base::IconType icon_type, 858 favicon_base::IconType icon_type,
859 const scoped_refptr<base::RefCountedMemory>& icon_data, 859 const scoped_refptr<base::RefCountedMemory>& icon_data,
860 base::Time time, 860 base::Time time,
861 const gfx::Size& pixel_size) { 861 const gfx::Size& pixel_size) {
862 favicon_base::FaviconID icon_id = AddFavicon(icon_url, icon_type); 862 favicon_base::FaviconID icon_id = AddFavicon(icon_url, icon_type);
863 if (!icon_id || !AddFaviconBitmap(icon_id, icon_data, time, pixel_size)) 863 if (!icon_id || !AddFaviconRawBitmap(icon_id, icon_data, time, pixel_size))
864 return 0; 864 return 0;
865 865
866 return icon_id; 866 return icon_id;
867 } 867 }
868 868
869 bool ThumbnailDatabase::DeleteFavicon(favicon_base::FaviconID id) { 869 bool ThumbnailDatabase::DeleteFavicon(favicon_base::FaviconID id) {
870 sql::Statement statement; 870 sql::Statement statement;
871 statement.Assign(db_.GetCachedStatement(SQL_FROM_HERE, 871 statement.Assign(db_.GetCachedStatement(SQL_FROM_HERE,
872 "DELETE FROM favicons WHERE id = ?")); 872 "DELETE FROM favicons WHERE id = ?"));
873 statement.BindInt64(0, id); 873 statement.BindInt64(0, id);
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
1066 const char kRenameFaviconsTable[] = 1066 const char kRenameFaviconsTable[] =
1067 "ALTER TABLE favicons RENAME TO old_favicons"; 1067 "ALTER TABLE favicons RENAME TO old_favicons";
1068 const char kCopyFavicons[] = 1068 const char kCopyFavicons[] =
1069 "INSERT INTO favicons (id, url, icon_type) " 1069 "INSERT INTO favicons (id, url, icon_type) "
1070 "SELECT mapping.new_icon_id, old.url, old.icon_type " 1070 "SELECT mapping.new_icon_id, old.url, old.icon_type "
1071 "FROM old_favicons AS old " 1071 "FROM old_favicons AS old "
1072 "JOIN temp.icon_id_mapping AS mapping " 1072 "JOIN temp.icon_id_mapping AS mapping "
1073 "ON (old.id = mapping.old_icon_id)"; 1073 "ON (old.id = mapping.old_icon_id)";
1074 const char kDropOldFaviconsTable[] = "DROP TABLE old_favicons"; 1074 const char kDropOldFaviconsTable[] = "DROP TABLE old_favicons";
1075 1075
1076 const char kRenameFaviconBitmapsTable[] = 1076 const char kRenameFaviconRawBitmapsTable[] =
1077 "ALTER TABLE favicon_bitmaps RENAME TO old_favicon_bitmaps"; 1077 "ALTER TABLE favicon_bitmaps RENAME TO old_favicon_bitmaps";
1078 const char kCopyFaviconBitmaps[] = 1078 const char kCopyFaviconRawBitmaps[] =
1079 "INSERT INTO favicon_bitmaps " 1079 "INSERT INTO favicon_bitmaps "
1080 " (icon_id, last_updated, image_data, width, height) " 1080 " (icon_id, last_updated, image_data, width, height) "
1081 "SELECT mapping.new_icon_id, old.last_updated, " 1081 "SELECT mapping.new_icon_id, old.last_updated, "
1082 " old.image_data, old.width, old.height " 1082 " old.image_data, old.width, old.height "
1083 "FROM old_favicon_bitmaps AS old " 1083 "FROM old_favicon_bitmaps AS old "
1084 "JOIN temp.icon_id_mapping AS mapping " 1084 "JOIN temp.icon_id_mapping AS mapping "
1085 "ON (old.icon_id = mapping.old_icon_id)"; 1085 "ON (old.icon_id = mapping.old_icon_id)";
1086 const char kDropOldFaviconBitmapsTable[] = 1086 const char kDropOldFaviconRawBitmapsTable[] =
1087 "DROP TABLE old_favicon_bitmaps"; 1087 "DROP TABLE old_favicon_bitmaps";
1088 1088
1089 // Rename existing tables to new location. 1089 // Rename existing tables to new location.
1090 if (!db_.Execute(kRenameIconMappingTable) || 1090 if (!db_.Execute(kRenameIconMappingTable) ||
1091 !db_.Execute(kRenameFaviconsTable) || 1091 !db_.Execute(kRenameFaviconsTable) ||
1092 !db_.Execute(kRenameFaviconBitmapsTable)) { 1092 !db_.Execute(kRenameFaviconRawBitmapsTable)) {
1093 return false; 1093 return false;
1094 } 1094 }
1095 1095
1096 // Initialize the replacement tables. At this point the old indices 1096 // Initialize the replacement tables. At this point the old indices
1097 // still exist (pointing to the old_* tables), so do not initialize 1097 // still exist (pointing to the old_* tables), so do not initialize
1098 // the indices. 1098 // the indices.
1099 if (!InitTables(&db_)) 1099 if (!InitTables(&db_))
1100 return false; 1100 return false;
1101 1101
1102 // Copy all of the data over. 1102 // Copy all of the data over.
1103 if (!db_.Execute(kCopyIconMapping) || 1103 if (!db_.Execute(kCopyIconMapping) || !db_.Execute(kCopyFavicons) ||
1104 !db_.Execute(kCopyFavicons) || 1104 !db_.Execute(kCopyFaviconRawBitmaps)) {
1105 !db_.Execute(kCopyFaviconBitmaps)) {
1106 return false; 1105 return false;
1107 } 1106 }
1108 1107
1109 // Drop the old_* tables, which also drops the indices. 1108 // Drop the old_* tables, which also drops the indices.
1110 if (!db_.Execute(kDropOldIconMappingTable) || 1109 if (!db_.Execute(kDropOldIconMappingTable) ||
1111 !db_.Execute(kDropOldFaviconsTable) || 1110 !db_.Execute(kDropOldFaviconsTable) ||
1112 !db_.Execute(kDropOldFaviconBitmapsTable)) { 1111 !db_.Execute(kDropOldFaviconRawBitmapsTable)) {
1113 return false; 1112 return false;
1114 } 1113 }
1115 1114
1116 // Recreate the indices. 1115 // Recreate the indices.
1117 // TODO(shess): UNIQUE indices could fail due to duplication. This 1116 // TODO(shess): UNIQUE indices could fail due to duplication. This
1118 // could happen in case of corruption. 1117 // could happen in case of corruption.
1119 if (!InitIndices(&db_)) 1118 if (!InitIndices(&db_))
1120 return false; 1119 return false;
1121 1120
1122 const char kIconMappingDrop[] = "DROP TABLE temp.icon_id_mapping"; 1121 const char kIconMappingDrop[] = "DROP TABLE temp.icon_id_mapping";
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1316 meta_table_.SetVersionNumber(7); 1315 meta_table_.SetVersionNumber(7);
1317 meta_table_.SetCompatibleVersionNumber(std::min(7, kCompatibleVersionNumber)); 1316 meta_table_.SetCompatibleVersionNumber(std::min(7, kCompatibleVersionNumber));
1318 return true; 1317 return true;
1319 } 1318 }
1320 1319
1321 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { 1320 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() {
1322 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); 1321 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons");
1323 } 1322 }
1324 1323
1325 } // namespace history 1324 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698