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 "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/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 73 // width Pixel width of |image_data|. | 73 // width Pixel width of |image_data|. |
| 74 // height Pixel height of |image_data|. | 74 // height Pixel height of |image_data|. |
| 75 | 75 |
| 76 static void FillIconMapping(const sql::Statement& statement, | 76 static void FillIconMapping(const sql::Statement& statement, |
| 77 const GURL& page_url, | 77 const GURL& page_url, |
| 78 history::IconMapping* icon_mapping) { | 78 history::IconMapping* icon_mapping) { |
| 79 icon_mapping->mapping_id = statement.ColumnInt64(0); | 79 icon_mapping->mapping_id = statement.ColumnInt64(0); |
| 80 icon_mapping->icon_id = statement.ColumnInt64(1); | 80 icon_mapping->icon_id = statement.ColumnInt64(1); |
| 81 icon_mapping->icon_type = | 81 icon_mapping->icon_type = |
| 82 static_cast<history::IconType>(statement.ColumnInt(2)); | 82 static_cast<history::IconType>(statement.ColumnInt(2)); |
| 83 icon_mapping->icon_url = GURL(statement.ColumnString(3)); | |
| 83 icon_mapping->page_url = page_url; | 84 icon_mapping->page_url = page_url; |
| 84 } | 85 } |
| 85 | 86 |
| 86 namespace history { | 87 namespace history { |
| 87 | 88 |
| 88 // Version number of the database. | 89 // Version number of the database. |
| 89 static const int kCurrentVersionNumber = 6; | 90 static const int kCurrentVersionNumber = 6; |
| 90 static const int kCompatibleVersionNumber = 6; | 91 static const int kCompatibleVersionNumber = 6; |
| 91 | 92 |
| 92 // Use 90 quality (out of 100) which is pretty high, because we're very | 93 // Use 90 quality (out of 100) which is pretty high, because we're very |
| 93 // sensitive to artifacts for these small sized, highly detailed images. | 94 // sensitive to artifacts for these small sized, highly detailed images. |
| 94 static const int kImageQuality = 90; | 95 static const int kImageQuality = 90; |
| 95 | 96 |
| 96 ThumbnailDatabase::IconMappingEnumerator::IconMappingEnumerator() { | 97 ThumbnailDatabase::IconMappingEnumerator::IconMappingEnumerator() { |
| 97 } | 98 } |
| 98 | 99 |
| 99 ThumbnailDatabase::IconMappingEnumerator::~IconMappingEnumerator() { | 100 ThumbnailDatabase::IconMappingEnumerator::~IconMappingEnumerator() { |
| 100 } | 101 } |
| 101 | 102 |
| 102 bool ThumbnailDatabase::IconMappingEnumerator::GetNextIconMapping( | 103 bool ThumbnailDatabase::IconMappingEnumerator::GetNextIconMapping( |
| 103 IconMapping* icon_mapping) { | 104 IconMapping* icon_mapping) { |
| 104 if (!statement_.Step()) | 105 if (!statement_.Step()) |
| 105 return false; | 106 return false; |
| 106 FillIconMapping(statement_, GURL(statement_.ColumnString(3)), icon_mapping); | 107 FillIconMapping(statement_, GURL(statement_.ColumnString(4)), icon_mapping); |
| 107 return true; | 108 return true; |
| 108 } | 109 } |
| 109 | 110 |
| 110 ThumbnailDatabase::ThumbnailDatabase() | 111 ThumbnailDatabase::ThumbnailDatabase() |
| 111 : history_publisher_(NULL), | 112 : history_publisher_(NULL), |
| 112 use_top_sites_(false) { | 113 use_top_sites_(false) { |
| 113 } | 114 } |
| 114 | 115 |
| 115 sql::InitStatus ThumbnailDatabase::CantUpgradeToVersion(int cur_version) { | 116 sql::InitStatus ThumbnailDatabase::CantUpgradeToVersion(int cur_version) { |
| 116 LOG(WARNING) << "Unable to update to thumbnail database to version " << | 117 LOG(WARNING) << "Unable to update to thumbnail database to version " << |
| (...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 440 double current_boring_score = select_statement.ColumnDouble(0); | 441 double current_boring_score = select_statement.ColumnDouble(0); |
| 441 bool current_clipping = select_statement.ColumnBool(1); | 442 bool current_clipping = select_statement.ColumnBool(1); |
| 442 bool current_at_top = select_statement.ColumnBool(2); | 443 bool current_at_top = select_statement.ColumnBool(2); |
| 443 base::Time last_updated = | 444 base::Time last_updated = |
| 444 base::Time::FromTimeT(select_statement.ColumnInt64(3)); | 445 base::Time::FromTimeT(select_statement.ColumnInt64(3)); |
| 445 *score = ThumbnailScore(current_boring_score, current_clipping, | 446 *score = ThumbnailScore(current_boring_score, current_clipping, |
| 446 current_at_top, last_updated); | 447 current_at_top, last_updated); |
| 447 return true; | 448 return true; |
| 448 } | 449 } |
| 449 | 450 |
| 451 bool ThumbnailDatabase::GetFaviconBitmapIDSizes( | |
|
sky
2012/09/04 20:52:29
Is it possible to land the changes in this file ou
pkotwicz
2012/09/04 22:40:54
Sure. I will however wait for the HistoryBackend t
| |
| 452 FaviconID icon_id, | |
| 453 std::vector<FaviconBitmapIDSize>* bitmap_id_sizes) { | |
| 454 DCHECK(icon_id); | |
| 455 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | |
| 456 "SELECT id, width, height FROM favicon_bitmaps WHERE icon_id=?")); | |
| 457 statement.BindInt64(0, icon_id); | |
| 458 | |
| 459 bool result = false; | |
| 460 while (statement.Step()) { | |
| 461 result = true; | |
| 462 if (!bitmap_id_sizes) | |
| 463 return result; | |
| 464 | |
| 465 FaviconBitmapIDSize bitmap_id_size; | |
| 466 bitmap_id_size.bitmap_id = statement.ColumnInt(0); | |
| 467 bitmap_id_size.pixel_size = gfx::Size(statement.ColumnInt(1), | |
| 468 statement.ColumnInt(2)); | |
| 469 bitmap_id_sizes->push_back(bitmap_id_size); | |
| 470 } | |
| 471 return result; | |
| 472 } | |
| 473 | |
| 450 bool ThumbnailDatabase::GetFaviconBitmaps( | 474 bool ThumbnailDatabase::GetFaviconBitmaps( |
| 451 FaviconID icon_id, | 475 FaviconID icon_id, |
| 452 std::vector<FaviconBitmap>* favicon_bitmaps) { | 476 std::vector<FaviconBitmap>* favicon_bitmaps) { |
| 453 DCHECK(icon_id); | 477 DCHECK(icon_id); |
| 454 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 478 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| 455 "SELECT id, last_updated, image_data, width, height FROM favicon_bitmaps " | 479 "SELECT id, last_updated, image_data, width, height FROM favicon_bitmaps " |
| 456 "WHERE icon_id=?")); | 480 "WHERE icon_id=?")); |
| 457 statement.BindInt64(0, icon_id); | 481 statement.BindInt64(0, icon_id); |
| 458 | 482 |
| 459 bool result = false; | 483 bool result = false; |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 472 statement.ColumnBlobAsVector(2, &data->data()); | 496 statement.ColumnBlobAsVector(2, &data->data()); |
| 473 favicon_bitmap.bitmap_data = data; | 497 favicon_bitmap.bitmap_data = data; |
| 474 } | 498 } |
| 475 favicon_bitmap.pixel_size = gfx::Size(statement.ColumnInt(3), | 499 favicon_bitmap.pixel_size = gfx::Size(statement.ColumnInt(3), |
| 476 statement.ColumnInt(4)); | 500 statement.ColumnInt(4)); |
| 477 favicon_bitmaps->push_back(favicon_bitmap); | 501 favicon_bitmaps->push_back(favicon_bitmap); |
| 478 } | 502 } |
| 479 return result; | 503 return result; |
| 480 } | 504 } |
| 481 | 505 |
| 506 bool ThumbnailDatabase::GetFaviconBitmap( | |
| 507 FaviconBitmapID bitmap_id, | |
| 508 base::Time* last_updated, | |
| 509 scoped_refptr<base::RefCountedMemory>* png_icon_data, | |
| 510 gfx::Size* pixel_size) { | |
| 511 DCHECK(bitmap_id); | |
| 512 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | |
| 513 "SELECT last_updated, image_data, width, height FROM favicon_bitmaps " | |
| 514 "WHERE id=?")); | |
| 515 statement.BindInt64(0, bitmap_id); | |
| 516 | |
| 517 if (!statement.Step()) | |
| 518 return false; | |
| 519 | |
| 520 if (last_updated) | |
| 521 *last_updated = base::Time::FromTimeT(statement.ColumnInt64(0)); | |
| 522 | |
| 523 if (png_icon_data && statement.ColumnByteLength(1) > 0) { | |
| 524 scoped_refptr<base::RefCountedBytes> data(new base::RefCountedBytes()); | |
| 525 statement.ColumnBlobAsVector(1, &data->data()); | |
| 526 *png_icon_data = data; | |
| 527 } | |
| 528 | |
| 529 if (pixel_size) { | |
| 530 *pixel_size = gfx::Size(statement.ColumnInt(2), | |
| 531 statement.ColumnInt(3)); | |
| 532 } | |
| 533 return true; | |
| 534 } | |
| 535 | |
| 482 FaviconBitmapID ThumbnailDatabase::AddFaviconBitmap( | 536 FaviconBitmapID ThumbnailDatabase::AddFaviconBitmap( |
| 483 FaviconID icon_id, | 537 FaviconID icon_id, |
| 484 const scoped_refptr<base::RefCountedMemory>& icon_data, | 538 const scoped_refptr<base::RefCountedMemory>& icon_data, |
| 485 base::Time time, | 539 base::Time time, |
| 486 const gfx::Size& pixel_size) { | 540 const gfx::Size& pixel_size) { |
| 487 DCHECK(icon_id); | 541 DCHECK(icon_id); |
| 488 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 542 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| 489 "INSERT INTO favicon_bitmaps (icon_id, image_data, last_updated, width, " | 543 "INSERT INTO favicon_bitmaps (icon_id, image_data, last_updated, width, " |
| 490 "height) VALUES (?, ?, ?, ?, ?)")); | 544 "height) VALUES (?, ?, ?, ?, ?)")); |
| 491 statement.BindInt64(0, icon_id); | 545 statement.BindInt64(0, icon_id); |
| 492 if (icon_data.get() && icon_data->size()) { | 546 if (icon_data.get() && icon_data->size()) { |
| 493 statement.BindBlob(1, icon_data->front(), | 547 statement.BindBlob(1, icon_data->front(), |
| 494 static_cast<int>(icon_data->size())); | 548 static_cast<int>(icon_data->size())); |
| 495 } else { | 549 } else { |
| 496 statement.BindNull(1); | 550 statement.BindNull(1); |
| 497 } | 551 } |
| 498 statement.BindInt64(2, time.ToTimeT()); | 552 statement.BindInt64(2, time.ToTimeT()); |
| 499 statement.BindInt(3, pixel_size.width()); | 553 statement.BindInt(3, pixel_size.width()); |
| 500 statement.BindInt(4, pixel_size.height()); | 554 statement.BindInt(4, pixel_size.height()); |
| 501 | 555 |
| 502 if (!statement.Run()) | 556 if (!statement.Run()) |
| 503 return 0; | 557 return 0; |
| 504 return db_.GetLastInsertRowId(); | 558 return db_.GetLastInsertRowId(); |
| 505 } | 559 } |
| 506 | 560 |
| 507 bool ThumbnailDatabase::DeleteFaviconBitmapsForFavicon(FaviconID icon_id) { | 561 bool ThumbnailDatabase::SetFaviconBitmap( |
|
sky
2012/09/05 00:15:51
Make order match header.
| |
| 562 FaviconBitmapID bitmap_id, | |
| 563 scoped_refptr<base::RefCountedMemory> bitmap_data, | |
| 564 base::Time time) { | |
| 565 DCHECK(bitmap_id); | |
| 508 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 566 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| 509 "DELETE FROM favicon_bitmaps WHERE icon_id=?")); | 567 "UPDATE favicon_bitmaps SET image_data=?, last_updated=? WHERE id=?")); |
| 510 statement.BindInt64(0, icon_id); | 568 if (bitmap_data.get() && bitmap_data->size()) { |
| 569 statement.BindBlob(0, bitmap_data->front(), | |
| 570 static_cast<int>(bitmap_data->size())); | |
| 571 } else { | |
| 572 statement.BindNull(0); | |
| 573 } | |
| 574 statement.BindInt64(1, time.ToTimeT()); | |
|
sky
2012/09/05 00:15:51
Shouldn't this be ToInternalValue? Or are they all
pkotwicz
2012/09/05 22:39:26
Fixed this in separate CL.
| |
| 575 statement.BindInt64(2, bitmap_id); | |
| 576 | |
| 511 return statement.Run(); | 577 return statement.Run(); |
| 512 } | 578 } |
| 513 | 579 |
| 580 bool ThumbnailDatabase::DeleteFaviconBitmap(FaviconBitmapID bitmap_id) { | |
| 581 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | |
| 582 "DELETE FROM favicon_bitmaps WHERE id=?")); | |
| 583 statement.BindInt64(0, bitmap_id); | |
| 584 return statement.Run(); | |
| 585 } | |
| 586 | |
| 514 bool ThumbnailDatabase::SetFaviconSizes(FaviconID icon_id, | 587 bool ThumbnailDatabase::SetFaviconSizes(FaviconID icon_id, |
| 515 const FaviconSizes& favicon_sizes) { | 588 const FaviconSizes& favicon_sizes) { |
| 516 std::string favicon_sizes_as_string; | 589 std::string favicon_sizes_as_string; |
| 517 FaviconSizesToDatabaseString(favicon_sizes, &favicon_sizes_as_string); | 590 FaviconSizesToDatabaseString(favicon_sizes, &favicon_sizes_as_string); |
| 518 | 591 |
| 519 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 592 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| 520 "UPDATE favicons SET sizes=? WHERE id=?")); | 593 "UPDATE favicons SET sizes=? WHERE id=?")); |
| 521 statement.BindString(0, favicon_sizes_as_string); | 594 statement.BindString(0, favicon_sizes_as_string); |
| 522 statement.BindInt64(1, icon_id); | 595 statement.BindInt64(1, icon_id); |
| 523 | 596 |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 643 filtered_mapping_data->push_back(*m); | 716 filtered_mapping_data->push_back(*m); |
| 644 } | 717 } |
| 645 } | 718 } |
| 646 return result; | 719 return result; |
| 647 } | 720 } |
| 648 | 721 |
| 649 bool ThumbnailDatabase::GetIconMappingsForPageURL( | 722 bool ThumbnailDatabase::GetIconMappingsForPageURL( |
| 650 const GURL& page_url, | 723 const GURL& page_url, |
| 651 std::vector<IconMapping>* mapping_data) { | 724 std::vector<IconMapping>* mapping_data) { |
| 652 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 725 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| 653 "SELECT icon_mapping.id, icon_mapping.icon_id, favicons.icon_type " | 726 "SELECT icon_mapping.id, icon_mapping.icon_id, favicons.icon_type, " |
| 727 "favicons.url " | |
| 654 "FROM icon_mapping " | 728 "FROM icon_mapping " |
| 655 "INNER JOIN favicons " | 729 "INNER JOIN favicons " |
| 656 "ON icon_mapping.icon_id = favicons.id " | 730 "ON icon_mapping.icon_id = favicons.id " |
| 657 "WHERE icon_mapping.page_url=? " | 731 "WHERE icon_mapping.page_url=? " |
| 658 "ORDER BY favicons.icon_type DESC")); | 732 "ORDER BY favicons.icon_type DESC")); |
| 659 statement.BindString(0, URLDatabase::GURLToDatabaseURL(page_url)); | 733 statement.BindString(0, URLDatabase::GURLToDatabaseURL(page_url)); |
| 660 | 734 |
| 661 bool result = false; | 735 bool result = false; |
| 662 while (statement.Step()) { | 736 while (statement.Step()) { |
| 663 result = true; | 737 result = true; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 687 } | 761 } |
| 688 | 762 |
| 689 bool ThumbnailDatabase::DeleteIconMappings(const GURL& page_url) { | 763 bool ThumbnailDatabase::DeleteIconMappings(const GURL& page_url) { |
| 690 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 764 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| 691 "DELETE FROM icon_mapping WHERE page_url = ?")); | 765 "DELETE FROM icon_mapping WHERE page_url = ?")); |
| 692 statement.BindString(0, URLDatabase::GURLToDatabaseURL(page_url)); | 766 statement.BindString(0, URLDatabase::GURLToDatabaseURL(page_url)); |
| 693 | 767 |
| 694 return statement.Run(); | 768 return statement.Run(); |
| 695 } | 769 } |
| 696 | 770 |
| 771 bool ThumbnailDatabase::DeleteIconMapping(IconMappingID mapping_id) { | |
| 772 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | |
| 773 "DELETE FROM icon_mapping WHERE id=?")); | |
| 774 statement.BindInt64(0, mapping_id); | |
| 775 | |
| 776 return statement.Run(); | |
| 777 } | |
| 778 | |
| 697 bool ThumbnailDatabase::HasMappingFor(FaviconID id) { | 779 bool ThumbnailDatabase::HasMappingFor(FaviconID id) { |
| 698 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 780 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| 699 "SELECT id FROM icon_mapping " | 781 "SELECT id FROM icon_mapping " |
| 700 "WHERE icon_id=?")); | 782 "WHERE icon_id=?")); |
| 701 statement.BindInt64(0, id); | 783 statement.BindInt64(0, id); |
| 702 | 784 |
| 703 return statement.Step(); | 785 return statement.Step(); |
| 704 } | 786 } |
| 705 | 787 |
| 706 bool ThumbnailDatabase::CloneIconMappings(const GURL& old_page_url, | 788 bool ThumbnailDatabase::CloneIconMappings(const GURL& old_page_url, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 726 return statement.Run(); | 808 return statement.Run(); |
| 727 } | 809 } |
| 728 | 810 |
| 729 bool ThumbnailDatabase::InitIconMappingEnumerator( | 811 bool ThumbnailDatabase::InitIconMappingEnumerator( |
| 730 IconType type, | 812 IconType type, |
| 731 IconMappingEnumerator* enumerator) { | 813 IconMappingEnumerator* enumerator) { |
| 732 DCHECK(!enumerator->statement_.is_valid()); | 814 DCHECK(!enumerator->statement_.is_valid()); |
| 733 enumerator->statement_.Assign(db_.GetCachedStatement( | 815 enumerator->statement_.Assign(db_.GetCachedStatement( |
| 734 SQL_FROM_HERE, | 816 SQL_FROM_HERE, |
| 735 "SELECT icon_mapping.id, icon_mapping.icon_id, favicons.icon_type, " | 817 "SELECT icon_mapping.id, icon_mapping.icon_id, favicons.icon_type, " |
| 736 "icon_mapping.page_url " | 818 "favicons.url, icon_mapping.page_url " |
| 737 "FROM icon_mapping JOIN favicons ON (" | 819 "FROM icon_mapping JOIN favicons ON (" |
| 738 "icon_mapping.icon_id = favicons.id) " | 820 "icon_mapping.icon_id = favicons.id) " |
| 739 "WHERE favicons.icon_type = ?")); | 821 "WHERE favicons.icon_type = ?")); |
| 740 enumerator->statement_.BindInt(0, type); | 822 enumerator->statement_.BindInt(0, type); |
| 741 return enumerator->statement_.is_valid(); | 823 return enumerator->statement_.is_valid(); |
| 742 } | 824 } |
| 743 | 825 |
| 744 bool ThumbnailDatabase::MigrateIconMappingData(URLDatabase* url_db) { | 826 bool ThumbnailDatabase::MigrateIconMappingData(URLDatabase* url_db) { |
| 745 URLDatabase::IconMappingEnumerator e; | 827 URLDatabase::IconMappingEnumerator e; |
| 746 if (!url_db->InitIconMappingEnumeratorForEverything(&e)) | 828 if (!url_db->InitIconMappingEnumeratorForEverything(&e)) |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1036 } | 1118 } |
| 1037 parsing_errors |= !base::StringToInt(t.token(), &height); | 1119 parsing_errors |= !base::StringToInt(t.token(), &height); |
| 1038 favicon_sizes->push_back(gfx::Size(width, height)); | 1120 favicon_sizes->push_back(gfx::Size(width, height)); |
| 1039 } | 1121 } |
| 1040 | 1122 |
| 1041 if (parsing_errors) | 1123 if (parsing_errors) |
| 1042 favicon_sizes->clear(); | 1124 favicon_sizes->clear(); |
| 1043 } | 1125 } |
| 1044 | 1126 |
| 1045 } // namespace history | 1127 } // namespace history |
| OLD | NEW |