| 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 "components/history/core/browser/thumbnail_database.h" | 5 #include "components/history/core/browser/thumbnail_database.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 577 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 577 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| 578 "UPDATE favicon_bitmaps SET last_updated=? WHERE icon_id=?")); | 578 "UPDATE favicon_bitmaps SET last_updated=? WHERE icon_id=?")); |
| 579 statement.BindInt64(0, 0); | 579 statement.BindInt64(0, 0); |
| 580 statement.BindInt64(1, icon_id); | 580 statement.BindInt64(1, icon_id); |
| 581 | 581 |
| 582 return statement.Run(); | 582 return statement.Run(); |
| 583 } | 583 } |
| 584 | 584 |
| 585 favicon_base::FaviconID ThumbnailDatabase::GetFaviconIDForFaviconURL( | 585 favicon_base::FaviconID ThumbnailDatabase::GetFaviconIDForFaviconURL( |
| 586 const GURL& icon_url, | 586 const GURL& icon_url, |
| 587 int required_icon_type, | 587 favicon_base::IconType icon_type) { |
| 588 favicon_base::IconType* icon_type) { | 588 sql::Statement statement(db_.GetCachedStatement( |
| 589 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 589 SQL_FROM_HERE, "SELECT id FROM favicons WHERE url=? AND icon_type=?")); |
| 590 "SELECT id, icon_type FROM favicons WHERE url=? AND (icon_type & ? > 0) " | |
| 591 "ORDER BY icon_type DESC")); | |
| 592 statement.BindString(0, URLDatabase::GURLToDatabaseURL(icon_url)); | 590 statement.BindString(0, URLDatabase::GURLToDatabaseURL(icon_url)); |
| 593 statement.BindInt(1, required_icon_type); | 591 statement.BindInt(1, icon_type); |
| 594 | 592 |
| 595 if (!statement.Step()) | 593 if (!statement.Step()) |
| 596 return 0; // not cached | 594 return 0; // not cached |
| 597 | 595 |
| 598 if (icon_type) | |
| 599 *icon_type = static_cast<favicon_base::IconType>(statement.ColumnInt(1)); | |
| 600 return statement.ColumnInt64(0); | 596 return statement.ColumnInt64(0); |
| 601 } | 597 } |
| 602 | 598 |
| 603 bool ThumbnailDatabase::GetFaviconHeader(favicon_base::FaviconID icon_id, | 599 bool ThumbnailDatabase::GetFaviconHeader(favicon_base::FaviconID icon_id, |
| 604 GURL* icon_url, | 600 GURL* icon_url, |
| 605 favicon_base::IconType* icon_type) { | 601 favicon_base::IconType* icon_type) { |
| 606 DCHECK(icon_id); | 602 DCHECK(icon_id); |
| 607 | 603 |
| 608 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 604 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, |
| 609 "SELECT url, icon_type FROM favicons WHERE id=?")); | 605 "SELECT url, icon_type FROM favicons WHERE id=?")); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 return false; | 666 return false; |
| 671 | 667 |
| 672 bool result = false; | 668 bool result = false; |
| 673 for (std::vector<IconMapping>::iterator m = mapping_data.begin(); | 669 for (std::vector<IconMapping>::iterator m = mapping_data.begin(); |
| 674 m != mapping_data.end(); ++m) { | 670 m != mapping_data.end(); ++m) { |
| 675 if (m->icon_type & required_icon_types) { | 671 if (m->icon_type & required_icon_types) { |
| 676 result = true; | 672 result = true; |
| 677 if (!filtered_mapping_data) | 673 if (!filtered_mapping_data) |
| 678 return result; | 674 return result; |
| 679 | 675 |
| 680 // Restrict icon type of subsequent matches to |m->icon_type|. | |
| 681 // |m->icon_type| is the largest IconType in |mapping_data| because | |
| 682 // |mapping_data| is sorted in descending order of IconType. | |
| 683 required_icon_types = m->icon_type; | |
| 684 | |
| 685 filtered_mapping_data->push_back(*m); | 676 filtered_mapping_data->push_back(*m); |
| 686 } | 677 } |
| 687 } | 678 } |
| 688 return result; | 679 return result; |
| 689 } | 680 } |
| 690 | 681 |
| 691 bool ThumbnailDatabase::GetIconMappingsForPageURL( | 682 bool ThumbnailDatabase::GetIconMappingsForPageURL( |
| 692 const GURL& page_url, | 683 const GURL& page_url, |
| 693 std::vector<IconMapping>* mapping_data) { | 684 std::vector<IconMapping>* mapping_data) { |
| 694 sql::Statement statement(db_.GetCachedStatement(SQL_FROM_HERE, | 685 sql::Statement statement(db_.GetCachedStatement( |
| 686 SQL_FROM_HERE, |
| 695 "SELECT icon_mapping.id, icon_mapping.icon_id, favicons.icon_type, " | 687 "SELECT icon_mapping.id, icon_mapping.icon_id, favicons.icon_type, " |
| 696 "favicons.url " | 688 "favicons.url " |
| 697 "FROM icon_mapping " | 689 "FROM icon_mapping " |
| 698 "INNER JOIN favicons " | 690 "INNER JOIN favicons " |
| 699 "ON icon_mapping.icon_id = favicons.id " | 691 "ON icon_mapping.icon_id = favicons.id " |
| 700 "WHERE icon_mapping.page_url=? " | 692 "WHERE icon_mapping.page_url=?")); |
| 701 "ORDER BY favicons.icon_type DESC")); | |
| 702 statement.BindString(0, URLDatabase::GURLToDatabaseURL(page_url)); | 693 statement.BindString(0, URLDatabase::GURLToDatabaseURL(page_url)); |
| 703 | 694 |
| 704 bool result = false; | 695 bool result = false; |
| 705 while (statement.Step()) { | 696 while (statement.Step()) { |
| 706 result = true; | 697 result = true; |
| 707 if (!mapping_data) | 698 if (!mapping_data) |
| 708 return result; | 699 return result; |
| 709 | 700 |
| 710 IconMapping icon_mapping; | 701 IconMapping icon_mapping; |
| 711 FillIconMapping(statement, page_url, &icon_mapping); | 702 FillIconMapping(statement, page_url, &icon_mapping); |
| (...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1067 meta_table_.SetVersionNumber(8); | 1058 meta_table_.SetVersionNumber(8); |
| 1068 meta_table_.SetCompatibleVersionNumber(std::min(8, kCompatibleVersionNumber)); | 1059 meta_table_.SetCompatibleVersionNumber(std::min(8, kCompatibleVersionNumber)); |
| 1069 return true; | 1060 return true; |
| 1070 } | 1061 } |
| 1071 | 1062 |
| 1072 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { | 1063 bool ThumbnailDatabase::IsFaviconDBStructureIncorrect() { |
| 1073 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); | 1064 return !db_.IsSQLValid("SELECT id, url, icon_type FROM favicons"); |
| 1074 } | 1065 } |
| 1075 | 1066 |
| 1076 } // namespace history | 1067 } // namespace history |
| OLD | NEW |