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

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: Initial CL for review. 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: ????????/r?????? by rogerm@chromium on 2015-??-??
Scott Hess - ex-Googler 2015/03/17 22:07:45 Don't worry too much about filling this in, usuall
Roger McFarlane (Chromium) 2015/03/19 17:55:51 Fair enough.
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
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 = 7;
91 const int kDeprecatedVersionNumber = 4; // and earlier. 95 const int kDeprecatedVersionNumber = 4; // 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));
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 ")"; 305 ")";
302 if (!db->Execute(kFaviconsSql)) 306 if (!db->Execute(kFaviconsSql))
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,"
315 "last_requested INTEGER DEFAULT 0,"
Scott Hess - ex-Googler 2015/03/17 22:07:45 Prefer to put the added column at the end, since t
Roger McFarlane (Chromium) 2015/03/19 17:55:51 Done.
311 "image_data BLOB," 316 "image_data BLOB,"
312 "width INTEGER DEFAULT 0," 317 "width INTEGER DEFAULT 0,"
313 "height INTEGER DEFAULT 0" 318 "height INTEGER DEFAULT 0"
314 ")"; 319 ")";
315 if (!db->Execute(kFaviconBitmapsSql)) 320 if (!db->Execute(kFaviconBitmapsSql))
316 return false; 321 return false;
317 322
323 // If we're updating to version 8, the favicon_bitmaps table already exists,
324 // so the above create was a NOP and we're still missing the last_requested
325 // column.
Scott Hess - ex-Googler 2015/03/17 22:07:46 Pull this out to UpgradeToVersion8() like the othe
Roger McFarlane (Chromium) 2015/03/19 17:55:51 I've clobbered the index over favicon_bitmaps(last
Scott Hess - ex-Googler 2015/03/19 21:32:22 Grr. I really hate our system. I want to have it
326 const char kFaviconBitmapsAddLastRequestedSql[] =
327 "ALTER TABLE favicon_bitmaps ADD COLUMN last_requested INTEGER DEFAULT 0";
328 if (!db->DoesColumnExist("favicon_bitmaps", "last_requested") &&
329 !db->Execute(kFaviconBitmapsAddLastRequestedSql)) {
330 return false;
331 }
332
318 return true; 333 return true;
319 } 334 }
320 335
321 // NOTE(shess): Schema modifications must consider initial creation in 336 // NOTE(shess): Schema modifications must consider initial creation in
322 // |InitImpl()|, recovery in |RecoverDatabaseOrRaze()|, and history pruning in 337 // |InitImpl()|, recovery in |RecoverDatabaseOrRaze()|, and history pruning in
323 // |RetainDataForPageUrls()|. 338 // |RetainDataForPageUrls()|.
324 bool InitIndices(sql::Connection* db) { 339 bool InitIndices(sql::Connection* db) {
325 const char kIconMappingUrlIndexSql[] = 340 const char kIconMappingUrlIndexSql[] =
326 "CREATE INDEX IF NOT EXISTS icon_mapping_page_url_idx" 341 "CREATE INDEX IF NOT EXISTS icon_mapping_page_url_idx"
327 " ON icon_mapping(page_url)"; 342 " ON icon_mapping(page_url)";
328 const char kIconMappingIdIndexSql[] = 343 const char kIconMappingIdIndexSql[] =
329 "CREATE INDEX IF NOT EXISTS icon_mapping_icon_id_idx" 344 "CREATE INDEX IF NOT EXISTS icon_mapping_icon_id_idx"
330 " ON icon_mapping(icon_id)"; 345 " ON icon_mapping(icon_id)";
331 if (!db->Execute(kIconMappingUrlIndexSql) || 346 if (!db->Execute(kIconMappingUrlIndexSql) ||
332 !db->Execute(kIconMappingIdIndexSql)) { 347 !db->Execute(kIconMappingIdIndexSql)) {
333 return false; 348 return false;
334 } 349 }
335 350
336 const char kFaviconsIndexSql[] = 351 const char kFaviconsIndexSql[] =
337 "CREATE INDEX IF NOT EXISTS favicons_url ON favicons(url)"; 352 "CREATE INDEX IF NOT EXISTS favicons_url ON favicons(url)";
338 if (!db->Execute(kFaviconsIndexSql)) 353 if (!db->Execute(kFaviconsIndexSql))
339 return false; 354 return false;
340 355
341 const char kFaviconBitmapsIndexSql[] = 356 const char kFaviconBitmapsIndexSql[] =
342 "CREATE INDEX IF NOT EXISTS favicon_bitmaps_icon_id ON " 357 "CREATE INDEX IF NOT EXISTS favicon_bitmaps_icon_id ON "
343 "favicon_bitmaps(icon_id)"; 358 "favicon_bitmaps(icon_id)";
344 if (!db->Execute(kFaviconBitmapsIndexSql)) 359 if (!db->Execute(kFaviconBitmapsIndexSql))
345 return false; 360 return false;
346 361
362 const char kFaviconBitmapsLastRequestedIndexSql[] =
363 "CREATE INDEX IF NOT EXISTS favicon_bitmaps_last_requested ON "
364 "favicon_bitmaps(last_requested)";
365 if (!db->Execute(kFaviconBitmapsLastRequestedIndexSql))
366 return false;
Scott Hess - ex-Googler 2015/03/17 22:07:46 My earlier statement means this will have to be du
Roger McFarlane (Chromium) 2015/03/19 17:55:51 I ended up removing this index entirely. I was goi
367
347 return true; 368 return true;
348 } 369 }
349 370
350 enum RecoveryEventType { 371 enum RecoveryEventType {
351 RECOVERY_EVENT_RECOVERED = 0, 372 RECOVERY_EVENT_RECOVERED = 0,
352 RECOVERY_EVENT_FAILED_SCOPER, 373 RECOVERY_EVENT_FAILED_SCOPER,
353 RECOVERY_EVENT_FAILED_META_VERSION_ERROR, // obsolete 374 RECOVERY_EVENT_FAILED_META_VERSION_ERROR, // obsolete
354 RECOVERY_EVENT_FAILED_META_VERSION_NONE, // obsolete 375 RECOVERY_EVENT_FAILED_META_VERSION_NONE, // obsolete
355 RECOVERY_EVENT_FAILED_META_WRONG_VERSION6, // obsolete 376 RECOVERY_EVENT_FAILED_META_WRONG_VERSION6, // obsolete
356 RECOVERY_EVENT_FAILED_META_WRONG_VERSION5, // obsolete 377 RECOVERY_EVENT_FAILED_META_WRONG_VERSION5, // obsolete
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
389 // Recover the database to the extent possible, razing it if recovery 410 // Recover the database to the extent possible, razing it if recovery
390 // is not possible. 411 // is not possible.
391 // TODO(shess): This is mostly just a safe proof of concept. In the 412 // TODO(shess): This is mostly just a safe proof of concept. In the
392 // real world, this database is probably not worthwhile recovering, as 413 // real world, this database is probably not worthwhile recovering, as
393 // opposed to just razing it and starting over whenever corruption is 414 // opposed to just razing it and starting over whenever corruption is
394 // detected. So this database is a good test subject. 415 // detected. So this database is a good test subject.
395 void RecoverDatabaseOrRaze(sql::Connection* db, const base::FilePath& db_path) { 416 void RecoverDatabaseOrRaze(sql::Connection* db, const base::FilePath& db_path) {
396 // NOTE(shess): This code is currently specific to the version 417 // NOTE(shess): This code is currently specific to the version
397 // number. I am working on simplifying things to loosen the 418 // number. I am working on simplifying things to loosen the
398 // dependency, meanwhile contact me if you need to bump the version. 419 // dependency, meanwhile contact me if you need to bump the version.
399 DCHECK_EQ(7, kCurrentVersionNumber); 420 DCHECK_EQ(8, kCurrentVersionNumber);
400 421
401 // TODO(shess): Reset back after? 422 // TODO(shess): Reset back after?
402 db->reset_error_callback(); 423 db->reset_error_callback();
403 424
404 // For histogram purposes. 425 // For histogram purposes.
405 size_t favicons_rows_recovered = 0; 426 size_t favicons_rows_recovered = 0;
406 size_t favicon_bitmaps_rows_recovered = 0; 427 size_t favicon_bitmaps_rows_recovered = 0;
407 size_t icon_mapping_rows_recovered = 0; 428 size_t icon_mapping_rows_recovered = 0;
408 int64 original_size = 0; 429 int64 original_size = 0;
409 base::GetFileSize(db_path, &original_size); 430 base::GetFileSize(db_path, &original_size);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 // the code simple. http://crbug.com/327485 for numbers. 464 // the code simple. http://crbug.com/327485 for numbers.
444 DCHECK_LE(kDeprecatedVersionNumber, 6); 465 DCHECK_LE(kDeprecatedVersionNumber, 6);
445 if (version <= 6) { 466 if (version <= 6) {
446 sql::Recovery::Unrecoverable(recovery.Pass()); 467 sql::Recovery::Unrecoverable(recovery.Pass());
447 RecordRecoveryEvent(RECOVERY_EVENT_DEPRECATED); 468 RecordRecoveryEvent(RECOVERY_EVENT_DEPRECATED);
448 return; 469 return;
449 } 470 }
450 471
451 // Earlier versions have been handled or deprecated, later versions should be 472 // Earlier versions have been handled or deprecated, later versions should be
452 // impossible. 473 // impossible.
453 if (version != 7) { 474 if (version != 8) {
Scott Hess - ex-Googler 2015/03/17 22:07:45 This should be < 7, in case someone's database was
Roger McFarlane (Chromium) 2015/03/19 17:55:51 Ah, quite right.
454 sql::Recovery::Unrecoverable(recovery.Pass()); 475 sql::Recovery::Unrecoverable(recovery.Pass());
455 RecordRecoveryEvent(RECOVERY_EVENT_FAILED_META_WRONG_VERSION); 476 RecordRecoveryEvent(RECOVERY_EVENT_FAILED_META_WRONG_VERSION);
456 return; 477 return;
457 } 478 }
458 479
459 // Recover to current schema version. 480 // Recover to current schema version.
460 sql::MetaTable recover_meta_table; 481 sql::MetaTable recover_meta_table;
461 if (!recover_meta_table.Init(recovery->db(), kCurrentVersionNumber, 482 if (!recover_meta_table.Init(recovery->db(), kCurrentVersionNumber,
462 kCompatibleVersionNumber)) { 483 kCompatibleVersionNumber)) {
463 sql::Recovery::Rollback(recovery.Pass()); 484 sql::Recovery::Rollback(recovery.Pass());
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 if (status == sql::INIT_OK) 627 if (status == sql::INIT_OK)
607 return status; 628 return status;
608 629
609 meta_table_.Reset(); 630 meta_table_.Reset();
610 db_.Close(); 631 db_.Close();
611 } 632 }
612 return status; 633 return status;
613 } 634 }
614 635
615 void ThumbnailDatabase::ComputeDatabaseMetrics() { 636 void ThumbnailDatabase::ComputeDatabaseMetrics() {
616 sql::Statement favicon_count( 637 // Count all icon files referenced by the DB.
638 sql::Statement count_statement(
617 db_.GetCachedStatement(SQL_FROM_HERE, "SELECT COUNT(*) FROM favicons")); 639 db_.GetCachedStatement(SQL_FROM_HERE, "SELECT COUNT(*) FROM favicons"));
618 UMA_HISTOGRAM_COUNTS_10000( 640 UMA_HISTOGRAM_COUNTS_10000(
619 "History.NumFaviconsInDB", 641 "History.NumFaviconsInDB",
620 favicon_count.Step() ? favicon_count.ColumnInt(0) : 0); 642 count_statement.Step() ? count_statement.ColumnInt(0) : 0);
643
644 // Count the subset of "large" icon files referenced by the DB.
645 count_statement.Assign(
646 db_.GetCachedStatement(
647 SQL_FROM_HERE, "SELECT COUNT(*) FROM favicons WHERE icon_type > ?"));
Scott Hess - ex-Googler 2015/03/17 22:07:46 Is there any reason to re-use the same sql::Statem
Roger McFarlane (Chromium) 2015/03/19 17:55:51 Done.
648 count_statement.BindInt64(0, favicon_base::FAVICON);
649 UMA_HISTOGRAM_COUNTS_10000(
650 "History.NumLargeFaviconsInDB",
651 count_statement.Step() ? count_statement.ColumnInt(0) : 0);
Scott Hess - ex-Googler 2015/03/17 22:07:45 These new histograms don't seem directly related t
Roger McFarlane (Chromium) 2015/03/19 17:55:51 I'll pull out the large favicon histograms to a fo
652
653 // Count all bitmap resources cached in the DB.
654 count_statement.Assign(
655 db_.GetCachedStatement(
656 SQL_FROM_HERE, "SELECT COUNT(*) FROM favicon_bitmaps"));
657 UMA_HISTOGRAM_COUNTS_10000(
658 "History.NumBitmapsInDB",
659 count_statement.Step() ? count_statement.ColumnInt(0) : 0);
660
661 // Count the subset of "large" bitmap resources cached in the DB.
662 count_statement.Assign(
663 db_.GetCachedStatement(
664 SQL_FROM_HERE,
665 "SELECT COUNT(*) FROM favicon_bitmaps "
666 "WHERE id IN (SELECT id FROM favicons WHERE icon_type > ?)"));
667 count_statement.BindInt64(0, favicon_base::FAVICON);
668 UMA_HISTOGRAM_COUNTS_10000(
669 "History.NumLargeBitmapsInDB",
670 count_statement.Step() ? count_statement.ColumnInt(0) : 0);
621 } 671 }
622 672
623 void ThumbnailDatabase::BeginTransaction() { 673 void ThumbnailDatabase::BeginTransaction() {
624 db_.BeginTransaction(); 674 db_.BeginTransaction();
625 } 675 }
626 676
627 void ThumbnailDatabase::CommitTransaction() { 677 void ThumbnailDatabase::CommitTransaction() {
628 db_.CommitTransaction(); 678 db_.CommitTransaction();
629 } 679 }
630 680
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 *png_icon_data = data; 770 *png_icon_data = data;
721 } 771 }
722 772
723 if (pixel_size) { 773 if (pixel_size) {
724 *pixel_size = gfx::Size(statement.ColumnInt(2), 774 *pixel_size = gfx::Size(statement.ColumnInt(2),
725 statement.ColumnInt(3)); 775 statement.ColumnInt(3));
726 } 776 }
727 return true; 777 return true;
728 } 778 }
729 779
780 bool ThumbnailDatabase::GetFaviconBitmapLastRequestedTime(
781 FaviconBitmapID bitmap_id,
782 base::Time* last_requested) {
783 DCHECK(bitmap_id);
784 DCHECK(last_requested);
785 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
786 "SELECT last_requested FROM favicon_bitmaps WHERE id=?"));
787 statement.BindInt64(0, bitmap_id);
788
789 if (!statement.Step())
790 return false;
791
792 *last_requested = base::Time::FromInternalValue(statement.ColumnInt64(0));
793 return true;
794 }
795
730 FaviconBitmapID ThumbnailDatabase::AddFaviconBitmap( 796 FaviconBitmapID ThumbnailDatabase::AddFaviconBitmap(
731 favicon_base::FaviconID icon_id, 797 favicon_base::FaviconID icon_id,
732 const scoped_refptr<base::RefCountedMemory>& icon_data, 798 const scoped_refptr<base::RefCountedMemory>& icon_data,
733 base::Time time, 799 base::Time time,
734 const gfx::Size& pixel_size) { 800 const gfx::Size& pixel_size) {
735 DCHECK(icon_id); 801 DCHECK(icon_id);
736 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 802 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
737 "INSERT INTO favicon_bitmaps (icon_id, image_data, last_updated, width, " 803 "INSERT INTO favicon_bitmaps (icon_id, image_data, last_updated, width, "
738 "height) VALUES (?, ?, ?, ?, ?)")); 804 "height) VALUES (?, ?, ?, ?, ?)"));
739 statement.BindInt64(0, icon_id); 805 statement.BindInt64(0, icon_id);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
775 FaviconBitmapID bitmap_id, 841 FaviconBitmapID bitmap_id,
776 base::Time time) { 842 base::Time time) {
777 DCHECK(bitmap_id); 843 DCHECK(bitmap_id);
778 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 844 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
779 "UPDATE favicon_bitmaps SET last_updated=? WHERE id=?")); 845 "UPDATE favicon_bitmaps SET last_updated=? WHERE id=?"));
780 statement.BindInt64(0, time.ToInternalValue()); 846 statement.BindInt64(0, time.ToInternalValue());
781 statement.BindInt64(1, bitmap_id); 847 statement.BindInt64(1, bitmap_id);
782 return statement.Run(); 848 return statement.Run();
783 } 849 }
784 850
851 bool ThumbnailDatabase::SetFaviconBitmapLastRequestedTime(
852 FaviconBitmapID bitmap_id,
853 base::Time time) {
854 DCHECK(bitmap_id);
855 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
856 "UPDATE favicon_bitmaps SET last_requested=? WHERE id=?"));
857 statement.BindInt64(0, time.ToInternalValue());
858 statement.BindInt64(1, bitmap_id);
859 return statement.Run();
860 }
861
785 bool ThumbnailDatabase::DeleteFaviconBitmap(FaviconBitmapID bitmap_id) { 862 bool ThumbnailDatabase::DeleteFaviconBitmap(FaviconBitmapID bitmap_id) {
786 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 863 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
787 "DELETE FROM favicon_bitmaps WHERE id=?")); 864 "DELETE FROM favicon_bitmaps WHERE id=?"));
788 statement.BindInt64(0, bitmap_id); 865 statement.BindInt64(0, bitmap_id);
789 return statement.Run(); 866 return statement.Run();
790 } 867 }
791 868
792 bool ThumbnailDatabase::SetFaviconOutOfDate(favicon_base::FaviconID icon_id) { 869 bool ThumbnailDatabase::SetFaviconOutOfDate(favicon_base::FaviconID icon_id) {
793 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, 870 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE,
794 "UPDATE favicon_bitmaps SET last_updated=? WHERE icon_id=?")); 871 "UPDATE favicon_bitmaps SET last_updated=? WHERE icon_id=?"));
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
859 favicon_base::FaviconID icon_id = AddFavicon(icon_url, icon_type); 936 favicon_base::FaviconID icon_id = AddFavicon(icon_url, icon_type);
860 if (!icon_id || !AddFaviconBitmap(icon_id, icon_data, time, pixel_size)) 937 if (!icon_id || !AddFaviconBitmap(icon_id, icon_data, time, pixel_size))
861 return 0; 938 return 0;
862 939
863 return icon_id; 940 return icon_id;
864 } 941 }
865 942
866 bool ThumbnailDatabase::DeleteFavicon(favicon_base::FaviconID id) { 943 bool ThumbnailDatabase::DeleteFavicon(favicon_base::FaviconID id) {
867 sql::Statement statement; 944 sql::Statement statement;
868 statement.Assign(db_.GetCachedStatement(SQL_FROM_HERE, 945 statement.Assign(db_.GetCachedStatement(SQL_FROM_HERE,
869 "DELETE FROM favicons WHERE id = ?")); 946 "DELETE FROM favicons WHERE id=?"));
Scott Hess - ex-Googler 2015/03/17 22:07:45 Egregious whitespace change is egregious.
Roger McFarlane (Chromium) 2015/03/19 17:55:51 Done.
870 statement.BindInt64(0, id); 947 statement.BindInt64(0, id);
871 if (!statement.Run()) 948 if (!statement.Run())
872 return false; 949 return false;
873 950
874 statement.Assign(db_.GetCachedStatement(SQL_FROM_HERE, 951 statement.Assign(db_.GetCachedStatement(SQL_FROM_HERE,
875 "DELETE FROM favicon_bitmaps WHERE icon_id = ?")); 952 "DELETE FROM favicon_bitmaps WHERE icon_id=?"));
Scott Hess - ex-Googler 2015/03/17 22:07:44 Also here.
Roger McFarlane (Chromium) 2015/03/19 17:55:51 Done.
876 statement.BindInt64(0, id); 953 statement.BindInt64(0, id);
877 return statement.Run(); 954 return statement.Run();
878 } 955 }
879 956
880 bool ThumbnailDatabase::GetIconMappingsForPageURL( 957 bool ThumbnailDatabase::GetIconMappingsForPageURL(
881 const GURL& page_url, 958 const GURL& page_url,
882 int required_icon_types, 959 int required_icon_types,
883 std::vector<IconMapping>* filtered_mapping_data) { 960 std::vector<IconMapping>* filtered_mapping_data) {
884 std::vector<IconMapping> mapping_data; 961 std::vector<IconMapping> mapping_data;
885 if (!GetIconMappingsForPageURL(page_url, &mapping_data)) 962 if (!GetIconMappingsForPageURL(page_url, &mapping_data))
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
1063 const char kRenameFaviconsTable[] = 1140 const char kRenameFaviconsTable[] =
1064 "ALTER TABLE favicons RENAME TO old_favicons"; 1141 "ALTER TABLE favicons RENAME TO old_favicons";
1065 const char kCopyFavicons[] = 1142 const char kCopyFavicons[] =
1066 "INSERT INTO favicons (id, url, icon_type) " 1143 "INSERT INTO favicons (id, url, icon_type) "
1067 "SELECT mapping.new_icon_id, old.url, old.icon_type " 1144 "SELECT mapping.new_icon_id, old.url, old.icon_type "
1068 "FROM old_favicons AS old " 1145 "FROM old_favicons AS old "
1069 "JOIN temp.icon_id_mapping AS mapping " 1146 "JOIN temp.icon_id_mapping AS mapping "
1070 "ON (old.id = mapping.old_icon_id)"; 1147 "ON (old.id = mapping.old_icon_id)";
1071 const char kDropOldFaviconsTable[] = "DROP TABLE old_favicons"; 1148 const char kDropOldFaviconsTable[] = "DROP TABLE old_favicons";
1072 1149
1150 // Note that we allow the last_requested field to be reset to the default
1151 // value (0).
1073 const char kRenameFaviconBitmapsTable[] = 1152 const char kRenameFaviconBitmapsTable[] =
1074 "ALTER TABLE favicon_bitmaps RENAME TO old_favicon_bitmaps"; 1153 "ALTER TABLE favicon_bitmaps RENAME TO old_favicon_bitmaps";
1075 const char kCopyFaviconBitmaps[] = 1154 const char kCopyFaviconBitmaps[] =
1076 "INSERT INTO favicon_bitmaps " 1155 "INSERT INTO favicon_bitmaps "
1077 " (icon_id, last_updated, image_data, width, height) " 1156 " (icon_id, last_updated, image_data, width, height) "
1078 "SELECT mapping.new_icon_id, old.last_updated, " 1157 "SELECT mapping.new_icon_id, old.last_updated, "
1079 " old.image_data, old.width, old.height " 1158 " old.image_data, old.width, old.height "
1080 "FROM old_favicon_bitmaps AS old " 1159 "FROM old_favicon_bitmaps AS old "
1081 "JOIN temp.icon_id_mapping AS mapping " 1160 "JOIN temp.icon_id_mapping AS mapping "
1082 "ON (old.icon_id = mapping.old_icon_id)"; 1161 "ON (old.icon_id = mapping.old_icon_id)";
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1170 1249
1171 // TODO(shess): Failing Begin() implies that something serious is 1250 // TODO(shess): Failing Begin() implies that something serious is
1172 // wrong with the database. Raze() may be in order. 1251 // wrong with the database. Raze() may be in order.
1173 1252
1174 #if defined(OS_MACOSX) && !defined(OS_IOS) 1253 #if defined(OS_MACOSX) && !defined(OS_IOS)
1175 // Exclude the thumbnails file from backups. 1254 // Exclude the thumbnails file from backups.
1176 base::mac::SetFileBackupExclusion(db_name); 1255 base::mac::SetFileBackupExclusion(db_name);
1177 #endif 1256 #endif
1178 1257
1179 // thumbnails table has been obsolete for a long time, remove any 1258 // thumbnails table has been obsolete for a long time, remove any
1180 // detrious. 1259 // detritus.
Scott Hess - ex-Googler 2015/03/17 22:07:46 That's just embarrassing!
Roger McFarlane (Chromium) 2015/03/19 17:55:51 :)
1181 ignore_result(db_.Execute("DROP TABLE IF EXISTS thumbnails")); 1260 ignore_result(db_.Execute("DROP TABLE IF EXISTS thumbnails"));
1182 1261
1183 // At some point, operations involving temporary tables weren't done 1262 // At some point, operations involving temporary tables weren't done
1184 // atomically and users have been stranded. Drop those tables and 1263 // atomically and users have been stranded. Drop those tables and
1185 // move on. 1264 // move on.
1186 // TODO(shess): Prove it? Audit all cases and see if it's possible 1265 // TODO(shess): Prove it? Audit all cases and see if it's possible
1187 // that this implies non-atomic update, and should thus be handled 1266 // that this implies non-atomic update, and should thus be handled
1188 // via the corruption handler. 1267 // via the corruption handler.
1189 ignore_result(db_.Execute("DROP TABLE IF EXISTS temp_favicons")); 1268 ignore_result(db_.Execute("DROP TABLE IF EXISTS temp_favicons"));
1190 ignore_result(db_.Execute("DROP TABLE IF EXISTS temp_favicon_bitmaps")); 1269 ignore_result(db_.Execute("DROP TABLE IF EXISTS temp_favicon_bitmaps"));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1228 if (!UpgradeToVersion6()) 1307 if (!UpgradeToVersion6())
1229 return CantUpgradeToVersion(cur_version); 1308 return CantUpgradeToVersion(cur_version);
1230 } 1309 }
1231 1310
1232 if (cur_version == 6) { 1311 if (cur_version == 6) {
1233 ++cur_version; 1312 ++cur_version;
1234 if (!UpgradeToVersion7()) 1313 if (!UpgradeToVersion7())
1235 return CantUpgradeToVersion(cur_version); 1314 return CantUpgradeToVersion(cur_version);
1236 } 1315 }
1237 1316
1317 if (cur_version == 7) {
1318 ++cur_version;
1319 if (!UpgradeToVersion8())
1320 return CantUpgradeToVersion(cur_version);
1321 }
1322
1238 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) << 1323 LOG_IF(WARNING, cur_version < kCurrentVersionNumber) <<
1239 "Thumbnail database version " << cur_version << " is too old to handle."; 1324 "Thumbnail database version " << cur_version << " is too old to handle.";
1240 1325
1241 // Initialization is complete. 1326 // Initialization is complete.
1242 if (!transaction.Commit()) 1327 if (!transaction.Commit())
1243 return sql::INIT_FAILURE; 1328 return sql::INIT_FAILURE;
1244 1329
1245 // Raze the database if the structure of the favicons database is not what 1330 // Raze the database if the structure of the favicons database is not what
1246 // it should be. This error cannot be detected via the SQL error code because 1331 // it should be. This error cannot be detected via the SQL error code because
1247 // the error code for running SQL statements against a database with missing 1332 // the error code for running SQL statements against a database with missing
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
1308 db_.Execute("CREATE INDEX IF NOT EXISTS favicons_url ON favicons(url)"); 1393 db_.Execute("CREATE INDEX IF NOT EXISTS favicons_url ON favicons(url)");
1309 1394
1310 if (!success) 1395 if (!success)
1311 return false; 1396 return false;
1312 1397
1313 meta_table_.SetVersionNumber(7); 1398 meta_table_.SetVersionNumber(7);
1314 meta_table_.SetCompatibleVersionNumber(std::min(7, kCompatibleVersionNumber)); 1399 meta_table_.SetCompatibleVersionNumber(std::min(7, kCompatibleVersionNumber));
1315 return true; 1400 return true;
1316 } 1401 }
1317 1402
1403 bool ThumbnailDatabase::UpgradeToVersion8() {
Scott Hess - ex-Googler 2015/03/17 22:07:44 This should include the schema to do the upgrade.
Roger McFarlane (Chromium) 2015/03/19 17:55:51 Done.
1404 meta_table_.SetVersionNumber(8);
1405 meta_table_.SetCompatibleVersionNumber(std::min(8, kCompatibleVersionNumber));
1406 return true;
1407 }
1408
1318 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { 1409 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() {
1319 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); 1410 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons");
1320 } 1411 }
1321 1412
1322 } // namespace history 1413 } // namespace history
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698