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::FromInternalValue(select_statement.ColumnInt64(3)); | 445 base::Time::FromInternalValue(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( |
| 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.ColumnInt64(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::FromInternalValue(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.ToInternalValue()); | 552 statement.BindInt64(2, time.ToInternalValue()); |
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 |
| 561 bool ThumbnailDatabase::SetFaviconBitmap( |
| 562 FaviconBitmapID bitmap_id, |
| 563 scoped_refptr<base::RefCountedMemory> bitmap_data, |
| 564 base::Time time) { |
| 565 DCHECK(bitmap_id); |
| 566 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| 567 "UPDATE favicon_bitmaps SET image_data=?, last_updated=? WHERE 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.ToInternalValue()); |
| 575 statement.BindInt64(2, bitmap_id); |
| 576 |
| 577 return statement.Run(); |
| 578 } |
| 579 |
507 bool ThumbnailDatabase::DeleteFaviconBitmapsForFavicon(FaviconID icon_id) { | 580 bool ThumbnailDatabase::DeleteFaviconBitmapsForFavicon(FaviconID icon_id) { |
508 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 581 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
509 "DELETE FROM favicon_bitmaps WHERE icon_id=?")); | 582 "DELETE FROM favicon_bitmaps WHERE icon_id=?")); |
510 statement.BindInt64(0, icon_id); | 583 statement.BindInt64(0, icon_id); |
511 return statement.Run(); | 584 return statement.Run(); |
512 } | 585 } |
513 | 586 |
| 587 bool ThumbnailDatabase::DeleteFaviconBitmap(FaviconBitmapID bitmap_id) { |
| 588 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| 589 "DELETE FROM favicon_bitmaps WHERE id=?")); |
| 590 statement.BindInt64(0, bitmap_id); |
| 591 return statement.Run(); |
| 592 } |
| 593 |
514 bool ThumbnailDatabase::SetFaviconSizes(FaviconID icon_id, | 594 bool ThumbnailDatabase::SetFaviconSizes(FaviconID icon_id, |
515 const FaviconSizes& favicon_sizes) { | 595 const FaviconSizes& favicon_sizes) { |
516 std::string favicon_sizes_as_string; | 596 std::string favicon_sizes_as_string; |
517 FaviconSizesToDatabaseString(favicon_sizes, &favicon_sizes_as_string); | 597 FaviconSizesToDatabaseString(favicon_sizes, &favicon_sizes_as_string); |
518 | 598 |
519 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 599 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
520 "UPDATE favicons SET sizes=? WHERE id=?")); | 600 "UPDATE favicons SET sizes=? WHERE id=?")); |
521 statement.BindString(0, favicon_sizes_as_string); | 601 statement.BindString(0, favicon_sizes_as_string); |
522 statement.BindInt64(1, icon_id); | 602 statement.BindInt64(1, icon_id); |
523 | 603 |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 filtered_mapping_data->push_back(*m); | 723 filtered_mapping_data->push_back(*m); |
644 } | 724 } |
645 } | 725 } |
646 return result; | 726 return result; |
647 } | 727 } |
648 | 728 |
649 bool ThumbnailDatabase::GetIconMappingsForPageURL( | 729 bool ThumbnailDatabase::GetIconMappingsForPageURL( |
650 const GURL& page_url, | 730 const GURL& page_url, |
651 std::vector<IconMapping>* mapping_data) { | 731 std::vector<IconMapping>* mapping_data) { |
652 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 732 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
653 "SELECT icon_mapping.id, icon_mapping.icon_id, favicons.icon_type " | 733 "SELECT icon_mapping.id, icon_mapping.icon_id, favicons.icon_type, " |
| 734 "favicons.url " |
654 "FROM icon_mapping " | 735 "FROM icon_mapping " |
655 "INNER JOIN favicons " | 736 "INNER JOIN favicons " |
656 "ON icon_mapping.icon_id = favicons.id " | 737 "ON icon_mapping.icon_id = favicons.id " |
657 "WHERE icon_mapping.page_url=? " | 738 "WHERE icon_mapping.page_url=? " |
658 "ORDER BY favicons.icon_type DESC")); | 739 "ORDER BY favicons.icon_type DESC")); |
659 statement.BindString(0, URLDatabase::GURLToDatabaseURL(page_url)); | 740 statement.BindString(0, URLDatabase::GURLToDatabaseURL(page_url)); |
660 | 741 |
661 bool result = false; | 742 bool result = false; |
662 while (statement.Step()) { | 743 while (statement.Step()) { |
663 result = true; | 744 result = true; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 return statement.Run(); | 815 return statement.Run(); |
735 } | 816 } |
736 | 817 |
737 bool ThumbnailDatabase::InitIconMappingEnumerator( | 818 bool ThumbnailDatabase::InitIconMappingEnumerator( |
738 IconType type, | 819 IconType type, |
739 IconMappingEnumerator* enumerator) { | 820 IconMappingEnumerator* enumerator) { |
740 DCHECK(!enumerator->statement_.is_valid()); | 821 DCHECK(!enumerator->statement_.is_valid()); |
741 enumerator->statement_.Assign(db_.GetCachedStatement( | 822 enumerator->statement_.Assign(db_.GetCachedStatement( |
742 SQL_FROM_HERE, | 823 SQL_FROM_HERE, |
743 "SELECT icon_mapping.id, icon_mapping.icon_id, favicons.icon_type, " | 824 "SELECT icon_mapping.id, icon_mapping.icon_id, favicons.icon_type, " |
744 "icon_mapping.page_url " | 825 "favicons.url, icon_mapping.page_url " |
745 "FROM icon_mapping JOIN favicons ON (" | 826 "FROM icon_mapping JOIN favicons ON (" |
746 "icon_mapping.icon_id = favicons.id) " | 827 "icon_mapping.icon_id = favicons.id) " |
747 "WHERE favicons.icon_type = ?")); | 828 "WHERE favicons.icon_type = ?")); |
748 enumerator->statement_.BindInt(0, type); | 829 enumerator->statement_.BindInt(0, type); |
749 return enumerator->statement_.is_valid(); | 830 return enumerator->statement_.is_valid(); |
750 } | 831 } |
751 | 832 |
752 bool ThumbnailDatabase::MigrateIconMappingData(URLDatabase* url_db) { | 833 bool ThumbnailDatabase::MigrateIconMappingData(URLDatabase* url_db) { |
753 URLDatabase::IconMappingEnumerator e; | 834 URLDatabase::IconMappingEnumerator e; |
754 if (!url_db->InitIconMappingEnumeratorForEverything(&e)) | 835 if (!url_db->InitIconMappingEnumeratorForEverything(&e)) |
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1044 } | 1125 } |
1045 parsing_errors |= !base::StringToInt(t.token(), &height); | 1126 parsing_errors |= !base::StringToInt(t.token(), &height); |
1046 favicon_sizes->push_back(gfx::Size(width, height)); | 1127 favicon_sizes->push_back(gfx::Size(width, height)); |
1047 } | 1128 } |
1048 | 1129 |
1049 if (parsing_errors) | 1130 if (parsing_errors) |
1050 favicon_sizes->clear(); | 1131 favicon_sizes->clear(); |
1051 } | 1132 } |
1052 | 1133 |
1053 } // namespace history | 1134 } // namespace history |
OLD | NEW |