| 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/history_backend.h" | 5 #include "chrome/browser/history/history_backend.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <list> | 9 #include <list> |
| 10 #include <map> | 10 #include <map> |
| (...skipping 1554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1565 } | 1565 } |
| 1566 UMA_HISTOGRAM_COUNTS("History.DeleteFTSIndexDatabases", | 1566 UMA_HISTOGRAM_COUNTS("History.DeleteFTSIndexDatabases", |
| 1567 num_databases_deleted); | 1567 num_databases_deleted); |
| 1568 } | 1568 } |
| 1569 | 1569 |
| 1570 void HistoryBackend::GetFavicons( | 1570 void HistoryBackend::GetFavicons( |
| 1571 const std::vector<GURL>& icon_urls, | 1571 const std::vector<GURL>& icon_urls, |
| 1572 int icon_types, | 1572 int icon_types, |
| 1573 int desired_size_in_dip, | 1573 int desired_size_in_dip, |
| 1574 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 1574 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
| 1575 std::vector<favicon_base::FaviconBitmapResult>* bitmap_results) { | 1575 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { |
| 1576 UpdateFaviconMappingsAndFetchImpl(NULL, icon_urls, icon_types, | 1576 UpdateFaviconMappingsAndFetchImpl(NULL, icon_urls, icon_types, |
| 1577 desired_size_in_dip, desired_scale_factors, | 1577 desired_size_in_dip, desired_scale_factors, |
| 1578 bitmap_results); | 1578 bitmap_results); |
| 1579 } | 1579 } |
| 1580 | 1580 |
| 1581 void HistoryBackend::GetLargestFaviconForURL( | 1581 void HistoryBackend::GetLargestFaviconForURL( |
| 1582 const GURL& page_url, | 1582 const GURL& page_url, |
| 1583 const std::vector<int>& icon_types, | 1583 const std::vector<int>& icon_types, |
| 1584 int minimum_size_in_pixels, | 1584 int minimum_size_in_pixels, |
| 1585 favicon_base::FaviconBitmapResult* favicon_bitmap_result) { | 1585 favicon_base::FaviconRawBitmapResult* favicon_bitmap_result) { |
| 1586 DCHECK(favicon_bitmap_result); | 1586 DCHECK(favicon_bitmap_result); |
| 1587 | 1587 |
| 1588 if (!db_ || !thumbnail_db_) | 1588 if (!db_ || !thumbnail_db_) |
| 1589 return; | 1589 return; |
| 1590 | 1590 |
| 1591 TimeTicks beginning_time = TimeTicks::Now(); | 1591 TimeTicks beginning_time = TimeTicks::Now(); |
| 1592 | 1592 |
| 1593 std::vector<IconMapping> icon_mappings; | 1593 std::vector<IconMapping> icon_mappings; |
| 1594 if (!thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings) || | 1594 if (!thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings) || |
| 1595 icon_mappings.empty()) | 1595 icon_mappings.empty()) |
| 1596 return; | 1596 return; |
| 1597 | 1597 |
| 1598 int required_icon_types = 0; | 1598 int required_icon_types = 0; |
| 1599 for (std::vector<int>::const_iterator i = icon_types.begin(); | 1599 for (std::vector<int>::const_iterator i = icon_types.begin(); |
| 1600 i != icon_types.end(); ++i) { | 1600 i != icon_types.end(); ++i) { |
| 1601 required_icon_types |= *i; | 1601 required_icon_types |= *i; |
| 1602 } | 1602 } |
| 1603 | 1603 |
| 1604 // Find the largest bitmap for each IconType placing in | 1604 // Find the largest bitmap for each IconType placing in |
| 1605 // |largest_favicon_bitmaps|. | 1605 // |largest_favicon_bitmaps|. |
| 1606 std::map<favicon_base::IconType, FaviconBitmap> largest_favicon_bitmaps; | 1606 std::map<favicon_base::IconType, FaviconRawBitmap> largest_favicon_bitmaps; |
| 1607 for (std::vector<IconMapping>::const_iterator i = icon_mappings.begin(); | 1607 for (std::vector<IconMapping>::const_iterator i = icon_mappings.begin(); |
| 1608 i != icon_mappings.end(); ++i) { | 1608 i != icon_mappings.end(); ++i) { |
| 1609 if (!(i->icon_type & required_icon_types)) | 1609 if (!(i->icon_type & required_icon_types)) |
| 1610 continue; | 1610 continue; |
| 1611 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; | 1611 std::vector<FaviconRawBitmapIDSize> bitmap_id_sizes; |
| 1612 thumbnail_db_->GetFaviconBitmapIDSizes(i->icon_id, &bitmap_id_sizes); | 1612 thumbnail_db_->GetFaviconRawBitmapIDSizes(i->icon_id, &bitmap_id_sizes); |
| 1613 FaviconBitmap& largest = largest_favicon_bitmaps[i->icon_type]; | 1613 FaviconRawBitmap& largest = largest_favicon_bitmaps[i->icon_type]; |
| 1614 for (std::vector<FaviconBitmapIDSize>::const_iterator j = | 1614 for (std::vector<FaviconRawBitmapIDSize>::const_iterator j = |
| 1615 bitmap_id_sizes.begin(); j != bitmap_id_sizes.end(); ++j) { | 1615 bitmap_id_sizes.begin(); |
| 1616 j != bitmap_id_sizes.end(); |
| 1617 ++j) { |
| 1616 if (largest.bitmap_id == 0 || | 1618 if (largest.bitmap_id == 0 || |
| 1617 (largest.pixel_size.width() < j->pixel_size.width() && | 1619 (largest.pixel_size.width() < j->pixel_size.width() && |
| 1618 largest.pixel_size.height() < j->pixel_size.height())) { | 1620 largest.pixel_size.height() < j->pixel_size.height())) { |
| 1619 largest.icon_id = i->icon_id; | 1621 largest.icon_id = i->icon_id; |
| 1620 largest.bitmap_id = j->bitmap_id; | 1622 largest.bitmap_id = j->bitmap_id; |
| 1621 largest.pixel_size = j->pixel_size; | 1623 largest.pixel_size = j->pixel_size; |
| 1622 } | 1624 } |
| 1623 } | 1625 } |
| 1624 } | 1626 } |
| 1625 if (largest_favicon_bitmaps.empty()) | 1627 if (largest_favicon_bitmaps.empty()) |
| 1626 return; | 1628 return; |
| 1627 | 1629 |
| 1628 // Find an icon which is larger than minimum_size_in_pixels in the order of | 1630 // Find an icon which is larger than minimum_size_in_pixels in the order of |
| 1629 // icon_types. | 1631 // icon_types. |
| 1630 FaviconBitmap largest_icon; | 1632 FaviconRawBitmap largest_icon; |
| 1631 for (std::vector<int>::const_iterator t = icon_types.begin(); | 1633 for (std::vector<int>::const_iterator t = icon_types.begin(); |
| 1632 t != icon_types.end(); ++t) { | 1634 t != icon_types.end(); ++t) { |
| 1633 for (std::map<favicon_base::IconType, FaviconBitmap>::const_iterator f = | 1635 for (std::map<favicon_base::IconType, FaviconRawBitmap>::const_iterator f = |
| 1634 largest_favicon_bitmaps.begin(); | 1636 largest_favicon_bitmaps.begin(); |
| 1635 f != largest_favicon_bitmaps.end(); | 1637 f != largest_favicon_bitmaps.end(); |
| 1636 ++f) { | 1638 ++f) { |
| 1637 if (f->first & *t && | 1639 if (f->first & *t && |
| 1638 (largest_icon.bitmap_id == 0 || | 1640 (largest_icon.bitmap_id == 0 || |
| 1639 (largest_icon.pixel_size.height() < f->second.pixel_size.height() && | 1641 (largest_icon.pixel_size.height() < f->second.pixel_size.height() && |
| 1640 largest_icon.pixel_size.width() < f->second.pixel_size.width()))) { | 1642 largest_icon.pixel_size.width() < f->second.pixel_size.width()))) { |
| 1641 largest_icon = f->second; | 1643 largest_icon = f->second; |
| 1642 } | 1644 } |
| 1643 } | 1645 } |
| 1644 if (largest_icon.pixel_size.width() > minimum_size_in_pixels && | 1646 if (largest_icon.pixel_size.width() > minimum_size_in_pixels && |
| 1645 largest_icon.pixel_size.height() > minimum_size_in_pixels) | 1647 largest_icon.pixel_size.height() > minimum_size_in_pixels) |
| 1646 break; | 1648 break; |
| 1647 } | 1649 } |
| 1648 | 1650 |
| 1649 GURL icon_url; | 1651 GURL icon_url; |
| 1650 favicon_base::IconType icon_type; | 1652 favicon_base::IconType icon_type; |
| 1651 if (!thumbnail_db_->GetFaviconHeader(largest_icon.icon_id, &icon_url, | 1653 if (!thumbnail_db_->GetFaviconHeader(largest_icon.icon_id, &icon_url, |
| 1652 &icon_type)) { | 1654 &icon_type)) { |
| 1653 return; | 1655 return; |
| 1654 } | 1656 } |
| 1655 | 1657 |
| 1656 base::Time last_updated; | 1658 base::Time last_updated; |
| 1657 favicon_base::FaviconBitmapResult bitmap_result; | 1659 favicon_base::FaviconRawBitmapResult bitmap_result; |
| 1658 bitmap_result.icon_url = icon_url; | 1660 bitmap_result.icon_url = icon_url; |
| 1659 bitmap_result.icon_type = icon_type; | 1661 bitmap_result.icon_type = icon_type; |
| 1660 if (!thumbnail_db_->GetFaviconBitmap(largest_icon.bitmap_id, | 1662 if (!thumbnail_db_->GetFaviconRawBitmap(largest_icon.bitmap_id, |
| 1661 &last_updated, | 1663 &last_updated, |
| 1662 &bitmap_result.bitmap_data, | 1664 &bitmap_result.bitmap_data, |
| 1663 &bitmap_result.pixel_size)) { | 1665 &bitmap_result.pixel_size)) { |
| 1664 return; | 1666 return; |
| 1665 } | 1667 } |
| 1666 | 1668 |
| 1667 bitmap_result.expired = (Time::Now() - last_updated) > | 1669 bitmap_result.expired = (Time::Now() - last_updated) > |
| 1668 TimeDelta::FromDays(kFaviconRefetchDays); | 1670 TimeDelta::FromDays(kFaviconRefetchDays); |
| 1669 if (bitmap_result.is_valid()) | 1671 if (bitmap_result.is_valid()) |
| 1670 *favicon_bitmap_result = bitmap_result; | 1672 *favicon_bitmap_result = bitmap_result; |
| 1671 | 1673 |
| 1672 HISTOGRAM_TIMES("History.GetLargestFaviconForURL", | 1674 HISTOGRAM_TIMES("History.GetLargestFaviconForURL", |
| 1673 TimeTicks::Now() - beginning_time); | 1675 TimeTicks::Now() - beginning_time); |
| 1674 } | 1676 } |
| 1675 | 1677 |
| 1676 void HistoryBackend::GetFaviconsForURL( | 1678 void HistoryBackend::GetFaviconsForURL( |
| 1677 const GURL& page_url, | 1679 const GURL& page_url, |
| 1678 int icon_types, | 1680 int icon_types, |
| 1679 int desired_size_in_dip, | 1681 int desired_size_in_dip, |
| 1680 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 1682 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
| 1681 std::vector<favicon_base::FaviconBitmapResult>* bitmap_results) { | 1683 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { |
| 1682 DCHECK(bitmap_results); | 1684 DCHECK(bitmap_results); |
| 1683 GetFaviconsFromDB(page_url, icon_types, desired_size_in_dip, | 1685 GetFaviconsFromDB(page_url, icon_types, desired_size_in_dip, |
| 1684 desired_scale_factors, bitmap_results); | 1686 desired_scale_factors, bitmap_results); |
| 1685 } | 1687 } |
| 1686 | 1688 |
| 1687 void HistoryBackend::GetFaviconForID( | 1689 void HistoryBackend::GetFaviconForID( |
| 1688 favicon_base::FaviconID favicon_id, | 1690 favicon_base::FaviconID favicon_id, |
| 1689 int desired_size_in_dip, | 1691 int desired_size_in_dip, |
| 1690 ui::ScaleFactor desired_scale_factor, | 1692 ui::ScaleFactor desired_scale_factor, |
| 1691 std::vector<favicon_base::FaviconBitmapResult>* bitmap_results) { | 1693 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { |
| 1692 std::vector<favicon_base::FaviconID> favicon_ids; | 1694 std::vector<favicon_base::FaviconID> favicon_ids; |
| 1693 favicon_ids.push_back(favicon_id); | 1695 favicon_ids.push_back(favicon_id); |
| 1694 std::vector<ui::ScaleFactor> desired_scale_factors; | 1696 std::vector<ui::ScaleFactor> desired_scale_factors; |
| 1695 desired_scale_factors.push_back(desired_scale_factor); | 1697 desired_scale_factors.push_back(desired_scale_factor); |
| 1696 | 1698 |
| 1697 // Get results from DB. | 1699 // Get results from DB. |
| 1698 GetFaviconBitmapResultsForBestMatch(favicon_ids, | 1700 GetFaviconRawBitmapResultsForBestMatch( |
| 1699 desired_size_in_dip, | 1701 favicon_ids, desired_size_in_dip, desired_scale_factors, bitmap_results); |
| 1700 desired_scale_factors, | |
| 1701 bitmap_results); | |
| 1702 } | 1702 } |
| 1703 | 1703 |
| 1704 void HistoryBackend::UpdateFaviconMappingsAndFetch( | 1704 void HistoryBackend::UpdateFaviconMappingsAndFetch( |
| 1705 const GURL& page_url, | 1705 const GURL& page_url, |
| 1706 const std::vector<GURL>& icon_urls, | 1706 const std::vector<GURL>& icon_urls, |
| 1707 int icon_types, | 1707 int icon_types, |
| 1708 int desired_size_in_dip, | 1708 int desired_size_in_dip, |
| 1709 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 1709 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
| 1710 std::vector<favicon_base::FaviconBitmapResult>* bitmap_results) { | 1710 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { |
| 1711 UpdateFaviconMappingsAndFetchImpl(&page_url, icon_urls, icon_types, | 1711 UpdateFaviconMappingsAndFetchImpl(&page_url, icon_urls, icon_types, |
| 1712 desired_size_in_dip, desired_scale_factors, | 1712 desired_size_in_dip, desired_scale_factors, |
| 1713 bitmap_results); | 1713 bitmap_results); |
| 1714 } | 1714 } |
| 1715 | 1715 |
| 1716 void HistoryBackend::MergeFavicon( | 1716 void HistoryBackend::MergeFavicon( |
| 1717 const GURL& page_url, | 1717 const GURL& page_url, |
| 1718 const GURL& icon_url, | 1718 const GURL& icon_url, |
| 1719 favicon_base::IconType icon_type, | 1719 favicon_base::IconType icon_type, |
| 1720 scoped_refptr<base::RefCountedMemory> bitmap_data, | 1720 scoped_refptr<base::RefCountedMemory> bitmap_data, |
| 1721 const gfx::Size& pixel_size) { | 1721 const gfx::Size& pixel_size) { |
| 1722 if (!thumbnail_db_ || !db_) | 1722 if (!thumbnail_db_ || !db_) |
| 1723 return; | 1723 return; |
| 1724 | 1724 |
| 1725 favicon_base::FaviconID favicon_id = | 1725 favicon_base::FaviconID favicon_id = |
| 1726 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type, NULL); | 1726 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type, NULL); |
| 1727 | 1727 |
| 1728 if (!favicon_id) { | 1728 if (!favicon_id) { |
| 1729 // There is no favicon at |icon_url|, create it. | 1729 // There is no favicon at |icon_url|, create it. |
| 1730 favicon_id = thumbnail_db_->AddFavicon(icon_url, icon_type); | 1730 favicon_id = thumbnail_db_->AddFavicon(icon_url, icon_type); |
| 1731 } | 1731 } |
| 1732 | 1732 |
| 1733 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; | 1733 std::vector<FaviconRawBitmapIDSize> bitmap_id_sizes; |
| 1734 thumbnail_db_->GetFaviconBitmapIDSizes(favicon_id, &bitmap_id_sizes); | 1734 thumbnail_db_->GetFaviconRawBitmapIDSizes(favicon_id, &bitmap_id_sizes); |
| 1735 | 1735 |
| 1736 // If there is already a favicon bitmap of |pixel_size| at |icon_url|, | 1736 // If there is already a favicon bitmap of |pixel_size| at |icon_url|, |
| 1737 // replace it. | 1737 // replace it. |
| 1738 bool bitmap_identical = false; | 1738 bool bitmap_identical = false; |
| 1739 bool replaced_bitmap = false; | 1739 bool replaced_bitmap = false; |
| 1740 for (size_t i = 0; i < bitmap_id_sizes.size(); ++i) { | 1740 for (size_t i = 0; i < bitmap_id_sizes.size(); ++i) { |
| 1741 if (bitmap_id_sizes[i].pixel_size == pixel_size) { | 1741 if (bitmap_id_sizes[i].pixel_size == pixel_size) { |
| 1742 if (IsFaviconBitmapDataEqual(bitmap_id_sizes[i].bitmap_id, bitmap_data)) { | 1742 if (IsFaviconRawBitmapDataEqual(bitmap_id_sizes[i].bitmap_id, |
| 1743 thumbnail_db_->SetFaviconBitmapLastUpdateTime( | 1743 bitmap_data)) { |
| 1744 thumbnail_db_->SetFaviconRawBitmapLastUpdateTime( |
| 1744 bitmap_id_sizes[i].bitmap_id, base::Time::Now()); | 1745 bitmap_id_sizes[i].bitmap_id, base::Time::Now()); |
| 1745 bitmap_identical = true; | 1746 bitmap_identical = true; |
| 1746 } else { | 1747 } else { |
| 1747 thumbnail_db_->SetFaviconBitmap(bitmap_id_sizes[i].bitmap_id, | 1748 thumbnail_db_->SetFaviconRawBitmap( |
| 1748 bitmap_data, base::Time::Now()); | 1749 bitmap_id_sizes[i].bitmap_id, bitmap_data, base::Time::Now()); |
| 1749 replaced_bitmap = true; | 1750 replaced_bitmap = true; |
| 1750 } | 1751 } |
| 1751 break; | 1752 break; |
| 1752 } | 1753 } |
| 1753 } | 1754 } |
| 1754 | 1755 |
| 1755 // Create a vector of the pixel sizes of the favicon bitmaps currently at | 1756 // Create a vector of the pixel sizes of the favicon bitmaps currently at |
| 1756 // |icon_url|. | 1757 // |icon_url|. |
| 1757 std::vector<gfx::Size> favicon_sizes; | 1758 std::vector<gfx::Size> favicon_sizes; |
| 1758 for (size_t i = 0; i < bitmap_id_sizes.size(); ++i) | 1759 for (size_t i = 0; i < bitmap_id_sizes.size(); ++i) |
| 1759 favicon_sizes.push_back(bitmap_id_sizes[i].pixel_size); | 1760 favicon_sizes.push_back(bitmap_id_sizes[i].pixel_size); |
| 1760 | 1761 |
| 1761 if (!replaced_bitmap && !bitmap_identical) { | 1762 if (!replaced_bitmap && !bitmap_identical) { |
| 1762 // Set the preexisting favicon bitmaps as expired as the preexisting favicon | 1763 // Set the preexisting favicon bitmaps as expired as the preexisting favicon |
| 1763 // bitmaps are not consistent with the merged in data. | 1764 // bitmaps are not consistent with the merged in data. |
| 1764 thumbnail_db_->SetFaviconOutOfDate(favicon_id); | 1765 thumbnail_db_->SetFaviconOutOfDate(favicon_id); |
| 1765 | 1766 |
| 1766 // Delete an arbitrary favicon bitmap to avoid going over the limit of | 1767 // Delete an arbitrary favicon bitmap to avoid going over the limit of |
| 1767 // |kMaxFaviconBitmapsPerIconURL|. | 1768 // |kMaxFaviconRawBitmapsPerIconURL|. |
| 1768 if (bitmap_id_sizes.size() >= kMaxFaviconBitmapsPerIconURL) { | 1769 if (bitmap_id_sizes.size() >= kMaxFaviconRawBitmapsPerIconURL) { |
| 1769 thumbnail_db_->DeleteFaviconBitmap(bitmap_id_sizes[0].bitmap_id); | 1770 thumbnail_db_->DeleteFaviconRawBitmap(bitmap_id_sizes[0].bitmap_id); |
| 1770 favicon_sizes.erase(favicon_sizes.begin()); | 1771 favicon_sizes.erase(favicon_sizes.begin()); |
| 1771 } | 1772 } |
| 1772 thumbnail_db_->AddFaviconBitmap(favicon_id, bitmap_data, base::Time::Now(), | 1773 thumbnail_db_->AddFaviconRawBitmap( |
| 1773 pixel_size); | 1774 favicon_id, bitmap_data, base::Time::Now(), pixel_size); |
| 1774 favicon_sizes.push_back(pixel_size); | 1775 favicon_sizes.push_back(pixel_size); |
| 1775 } | 1776 } |
| 1776 | 1777 |
| 1777 // A site may have changed the favicons that it uses for |page_url|. | 1778 // A site may have changed the favicons that it uses for |page_url|. |
| 1778 // Example Scenario: | 1779 // Example Scenario: |
| 1779 // page_url = news.google.com | 1780 // page_url = news.google.com |
| 1780 // Initial State: www.google.com/favicon.ico 16x16, 32x32 | 1781 // Initial State: www.google.com/favicon.ico 16x16, 32x32 |
| 1781 // MergeFavicon(news.google.com, news.google.com/news_specific.ico, ..., | 1782 // MergeFavicon(news.google.com, news.google.com/news_specific.ico, ..., |
| 1782 // ..., 16x16) | 1783 // ..., 16x16) |
| 1783 // | 1784 // |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1799 // / incorrect data. | 1800 // / incorrect data. |
| 1800 // Difficulty 1: All but news.google.com/news_specific.ico are unmapped from | 1801 // Difficulty 1: All but news.google.com/news_specific.ico are unmapped from |
| 1801 // news.google.com | 1802 // news.google.com |
| 1802 // Difficulty 2: The favicon bitmaps for www.google.com/favicon.ico are not | 1803 // Difficulty 2: The favicon bitmaps for www.google.com/favicon.ico are not |
| 1803 // modified. | 1804 // modified. |
| 1804 | 1805 |
| 1805 std::vector<IconMapping> icon_mappings; | 1806 std::vector<IconMapping> icon_mappings; |
| 1806 thumbnail_db_->GetIconMappingsForPageURL(page_url, icon_type, &icon_mappings); | 1807 thumbnail_db_->GetIconMappingsForPageURL(page_url, icon_type, &icon_mappings); |
| 1807 | 1808 |
| 1808 // Copy the favicon bitmaps mapped to |page_url| to the favicon at |icon_url| | 1809 // Copy the favicon bitmaps mapped to |page_url| to the favicon at |icon_url| |
| 1809 // till the limit of |kMaxFaviconBitmapsPerIconURL| is reached. | 1810 // till the limit of |kMaxFaviconRawBitmapsPerIconURL| is reached. |
| 1810 for (size_t i = 0; i < icon_mappings.size(); ++i) { | 1811 for (size_t i = 0; i < icon_mappings.size(); ++i) { |
| 1811 if (favicon_sizes.size() >= kMaxFaviconBitmapsPerIconURL) | 1812 if (favicon_sizes.size() >= kMaxFaviconRawBitmapsPerIconURL) |
| 1812 break; | 1813 break; |
| 1813 | 1814 |
| 1814 if (icon_mappings[i].icon_url == icon_url) | 1815 if (icon_mappings[i].icon_url == icon_url) |
| 1815 continue; | 1816 continue; |
| 1816 | 1817 |
| 1817 std::vector<FaviconBitmap> bitmaps_to_copy; | 1818 std::vector<FaviconRawBitmap> bitmaps_to_copy; |
| 1818 thumbnail_db_->GetFaviconBitmaps(icon_mappings[i].icon_id, | 1819 thumbnail_db_->GetFaviconRawBitmaps(icon_mappings[i].icon_id, |
| 1819 &bitmaps_to_copy); | 1820 &bitmaps_to_copy); |
| 1820 for (size_t j = 0; j < bitmaps_to_copy.size(); ++j) { | 1821 for (size_t j = 0; j < bitmaps_to_copy.size(); ++j) { |
| 1821 // Do not add a favicon bitmap at a pixel size for which there is already | 1822 // Do not add a favicon bitmap at a pixel size for which there is already |
| 1822 // a favicon bitmap mapped to |icon_url|. The one there is more correct | 1823 // a favicon bitmap mapped to |icon_url|. The one there is more correct |
| 1823 // and having multiple equally sized favicon bitmaps for |page_url| is | 1824 // and having multiple equally sized favicon bitmaps for |page_url| is |
| 1824 // ambiguous in terms of GetFaviconsForURL(). | 1825 // ambiguous in terms of GetFaviconsForURL(). |
| 1825 std::vector<gfx::Size>::iterator it = std::find(favicon_sizes.begin(), | 1826 std::vector<gfx::Size>::iterator it = std::find(favicon_sizes.begin(), |
| 1826 favicon_sizes.end(), bitmaps_to_copy[j].pixel_size); | 1827 favicon_sizes.end(), bitmaps_to_copy[j].pixel_size); |
| 1827 if (it != favicon_sizes.end()) | 1828 if (it != favicon_sizes.end()) |
| 1828 continue; | 1829 continue; |
| 1829 | 1830 |
| 1830 // Add the favicon bitmap as expired as it is not consistent with the | 1831 // Add the favicon bitmap as expired as it is not consistent with the |
| 1831 // merged in data. | 1832 // merged in data. |
| 1832 thumbnail_db_->AddFaviconBitmap(favicon_id, | 1833 thumbnail_db_->AddFaviconRawBitmap(favicon_id, |
| 1833 bitmaps_to_copy[j].bitmap_data, base::Time(), | 1834 bitmaps_to_copy[j].bitmap_data, |
| 1834 bitmaps_to_copy[j].pixel_size); | 1835 base::Time(), |
| 1836 bitmaps_to_copy[j].pixel_size); |
| 1835 favicon_sizes.push_back(bitmaps_to_copy[j].pixel_size); | 1837 favicon_sizes.push_back(bitmaps_to_copy[j].pixel_size); |
| 1836 | 1838 |
| 1837 if (favicon_sizes.size() >= kMaxFaviconBitmapsPerIconURL) | 1839 if (favicon_sizes.size() >= kMaxFaviconRawBitmapsPerIconURL) |
| 1838 break; | 1840 break; |
| 1839 } | 1841 } |
| 1840 } | 1842 } |
| 1841 | 1843 |
| 1842 // Update the favicon mappings such that only |icon_url| is mapped to | 1844 // Update the favicon mappings such that only |icon_url| is mapped to |
| 1843 // |page_url|. | 1845 // |page_url|. |
| 1844 bool mapping_changed = false; | 1846 bool mapping_changed = false; |
| 1845 if (icon_mappings.size() != 1 || icon_mappings[0].icon_url != icon_url) { | 1847 if (icon_mappings.size() != 1 || icon_mappings[0].icon_url != icon_url) { |
| 1846 std::vector<favicon_base::FaviconID> favicon_ids; | 1848 std::vector<favicon_base::FaviconID> favicon_ids; |
| 1847 favicon_ids.push_back(favicon_id); | 1849 favicon_ids.push_back(favicon_id); |
| 1848 SetFaviconMappingsForPageAndRedirects(page_url, icon_type, favicon_ids); | 1850 SetFaviconMappingsForPageAndRedirects(page_url, icon_type, favicon_ids); |
| 1849 mapping_changed = true; | 1851 mapping_changed = true; |
| 1850 } | 1852 } |
| 1851 | 1853 |
| 1852 if (mapping_changed || !bitmap_identical) | 1854 if (mapping_changed || !bitmap_identical) |
| 1853 SendFaviconChangedNotificationForPageAndRedirects(page_url); | 1855 SendFaviconChangedNotificationForPageAndRedirects(page_url); |
| 1854 ScheduleCommit(); | 1856 ScheduleCommit(); |
| 1855 } | 1857 } |
| 1856 | 1858 |
| 1857 void HistoryBackend::SetFavicons( | 1859 void HistoryBackend::SetFavicons( |
| 1858 const GURL& page_url, | 1860 const GURL& page_url, |
| 1859 favicon_base::IconType icon_type, | 1861 favicon_base::IconType icon_type, |
| 1860 const std::vector<favicon_base::FaviconBitmapData>& favicon_bitmap_data) { | 1862 const std::vector<favicon_base::FaviconRawBitmapData>& |
| 1863 favicon_bitmap_data) { |
| 1861 if (!thumbnail_db_ || !db_) | 1864 if (!thumbnail_db_ || !db_) |
| 1862 return; | 1865 return; |
| 1863 | 1866 |
| 1864 DCHECK(ValidateSetFaviconsParams(favicon_bitmap_data)); | 1867 DCHECK(ValidateSetFaviconsParams(favicon_bitmap_data)); |
| 1865 | 1868 |
| 1866 // Build map of FaviconBitmapData for each icon url. | 1869 // Build map of FaviconRawBitmapData for each icon url. |
| 1867 typedef std::map<GURL, std::vector<favicon_base::FaviconBitmapData> > | 1870 typedef std::map<GURL, std::vector<favicon_base::FaviconRawBitmapData> > |
| 1868 BitmapDataByIconURL; | 1871 BitmapDataByIconURL; |
| 1869 BitmapDataByIconURL grouped_by_icon_url; | 1872 BitmapDataByIconURL grouped_by_icon_url; |
| 1870 for (size_t i = 0; i < favicon_bitmap_data.size(); ++i) { | 1873 for (size_t i = 0; i < favicon_bitmap_data.size(); ++i) { |
| 1871 const GURL& icon_url = favicon_bitmap_data[i].icon_url; | 1874 const GURL& icon_url = favicon_bitmap_data[i].icon_url; |
| 1872 grouped_by_icon_url[icon_url].push_back(favicon_bitmap_data[i]); | 1875 grouped_by_icon_url[icon_url].push_back(favicon_bitmap_data[i]); |
| 1873 } | 1876 } |
| 1874 | 1877 |
| 1875 // Track whether the method modifies or creates any favicon bitmaps, favicons | 1878 // Track whether the method modifies or creates any favicon bitmaps, favicons |
| 1876 // or icon mappings. | 1879 // or icon mappings. |
| 1877 bool data_modified = false; | 1880 bool data_modified = false; |
| 1878 | 1881 |
| 1879 std::vector<favicon_base::FaviconID> icon_ids; | 1882 std::vector<favicon_base::FaviconID> icon_ids; |
| 1880 for (BitmapDataByIconURL::const_iterator it = grouped_by_icon_url.begin(); | 1883 for (BitmapDataByIconURL::const_iterator it = grouped_by_icon_url.begin(); |
| 1881 it != grouped_by_icon_url.end(); ++it) { | 1884 it != grouped_by_icon_url.end(); ++it) { |
| 1882 const GURL& icon_url = it->first; | 1885 const GURL& icon_url = it->first; |
| 1883 favicon_base::FaviconID icon_id = | 1886 favicon_base::FaviconID icon_id = |
| 1884 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type, NULL); | 1887 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type, NULL); |
| 1885 | 1888 |
| 1886 if (!icon_id) { | 1889 if (!icon_id) { |
| 1887 // TODO(pkotwicz): Remove the favicon sizes attribute from | 1890 // TODO(pkotwicz): Remove the favicon sizes attribute from |
| 1888 // ThumbnailDatabase::AddFavicon(). | 1891 // ThumbnailDatabase::AddFavicon(). |
| 1889 icon_id = thumbnail_db_->AddFavicon(icon_url, icon_type); | 1892 icon_id = thumbnail_db_->AddFavicon(icon_url, icon_type); |
| 1890 data_modified = true; | 1893 data_modified = true; |
| 1891 } | 1894 } |
| 1892 icon_ids.push_back(icon_id); | 1895 icon_ids.push_back(icon_id); |
| 1893 | 1896 |
| 1894 if (!data_modified) | 1897 if (!data_modified) |
| 1895 SetFaviconBitmaps(icon_id, it->second, &data_modified); | 1898 SetFaviconRawBitmaps(icon_id, it->second, &data_modified); |
| 1896 else | 1899 else |
| 1897 SetFaviconBitmaps(icon_id, it->second, NULL); | 1900 SetFaviconRawBitmaps(icon_id, it->second, NULL); |
| 1898 } | 1901 } |
| 1899 | 1902 |
| 1900 data_modified |= | 1903 data_modified |= |
| 1901 SetFaviconMappingsForPageAndRedirects(page_url, icon_type, icon_ids); | 1904 SetFaviconMappingsForPageAndRedirects(page_url, icon_type, icon_ids); |
| 1902 | 1905 |
| 1903 if (data_modified) { | 1906 if (data_modified) { |
| 1904 // Send notification to the UI as an icon mapping, favicon, or favicon | 1907 // Send notification to the UI as an icon mapping, favicon, or favicon |
| 1905 // bitmap was changed by this function. | 1908 // bitmap was changed by this function. |
| 1906 SendFaviconChangedNotificationForPageAndRedirects(page_url); | 1909 SendFaviconChangedNotificationForPageAndRedirects(page_url); |
| 1907 } | 1910 } |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2003 changed_details.PassAs<HistoryDetails>()); | 2006 changed_details.PassAs<HistoryDetails>()); |
| 2004 } | 2007 } |
| 2005 } | 2008 } |
| 2006 | 2009 |
| 2007 void HistoryBackend::UpdateFaviconMappingsAndFetchImpl( | 2010 void HistoryBackend::UpdateFaviconMappingsAndFetchImpl( |
| 2008 const GURL* page_url, | 2011 const GURL* page_url, |
| 2009 const std::vector<GURL>& icon_urls, | 2012 const std::vector<GURL>& icon_urls, |
| 2010 int icon_types, | 2013 int icon_types, |
| 2011 int desired_size_in_dip, | 2014 int desired_size_in_dip, |
| 2012 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 2015 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
| 2013 std::vector<favicon_base::FaviconBitmapResult>* bitmap_results) { | 2016 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { |
| 2014 // If |page_url| is specified, |icon_types| must be either a single icon | 2017 // If |page_url| is specified, |icon_types| must be either a single icon |
| 2015 // type or icon types which are equivalent. | 2018 // type or icon types which are equivalent. |
| 2016 DCHECK(!page_url || icon_types == favicon_base::FAVICON || | 2019 DCHECK(!page_url || icon_types == favicon_base::FAVICON || |
| 2017 icon_types == favicon_base::TOUCH_ICON || | 2020 icon_types == favicon_base::TOUCH_ICON || |
| 2018 icon_types == favicon_base::TOUCH_PRECOMPOSED_ICON || | 2021 icon_types == favicon_base::TOUCH_PRECOMPOSED_ICON || |
| 2019 icon_types == | 2022 icon_types == |
| 2020 (favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON)); | 2023 (favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON)); |
| 2021 bitmap_results->clear(); | 2024 bitmap_results->clear(); |
| 2022 | 2025 |
| 2023 if (!thumbnail_db_) { | 2026 if (!thumbnail_db_) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 2053 if (page_url && !favicon_ids.empty()) { | 2056 if (page_url && !favicon_ids.empty()) { |
| 2054 bool mappings_updated = | 2057 bool mappings_updated = |
| 2055 SetFaviconMappingsForPageAndRedirects(*page_url, selected_icon_type, | 2058 SetFaviconMappingsForPageAndRedirects(*page_url, selected_icon_type, |
| 2056 favicon_ids); | 2059 favicon_ids); |
| 2057 if (mappings_updated) { | 2060 if (mappings_updated) { |
| 2058 SendFaviconChangedNotificationForPageAndRedirects(*page_url); | 2061 SendFaviconChangedNotificationForPageAndRedirects(*page_url); |
| 2059 ScheduleCommit(); | 2062 ScheduleCommit(); |
| 2060 } | 2063 } |
| 2061 } | 2064 } |
| 2062 | 2065 |
| 2063 GetFaviconBitmapResultsForBestMatch(favicon_ids, desired_size_in_dip, | 2066 GetFaviconRawBitmapResultsForBestMatch( |
| 2064 desired_scale_factors, bitmap_results); | 2067 favicon_ids, desired_size_in_dip, desired_scale_factors, bitmap_results); |
| 2065 } | 2068 } |
| 2066 | 2069 |
| 2067 void HistoryBackend::SetFaviconBitmaps( | 2070 void HistoryBackend::SetFaviconRawBitmaps( |
| 2068 favicon_base::FaviconID icon_id, | 2071 favicon_base::FaviconID icon_id, |
| 2069 const std::vector<favicon_base::FaviconBitmapData>& favicon_bitmap_data, | 2072 const std::vector<favicon_base::FaviconRawBitmapData>& favicon_bitmap_data, |
| 2070 bool* favicon_bitmaps_changed) { | 2073 bool* favicon_bitmaps_changed) { |
| 2071 if (favicon_bitmaps_changed) | 2074 if (favicon_bitmaps_changed) |
| 2072 *favicon_bitmaps_changed = false; | 2075 *favicon_bitmaps_changed = false; |
| 2073 | 2076 |
| 2074 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; | 2077 std::vector<FaviconRawBitmapIDSize> bitmap_id_sizes; |
| 2075 thumbnail_db_->GetFaviconBitmapIDSizes(icon_id, &bitmap_id_sizes); | 2078 thumbnail_db_->GetFaviconRawBitmapIDSizes(icon_id, &bitmap_id_sizes); |
| 2076 | 2079 |
| 2077 std::vector<favicon_base::FaviconBitmapData> to_add = favicon_bitmap_data; | 2080 std::vector<favicon_base::FaviconRawBitmapData> to_add = favicon_bitmap_data; |
| 2078 | 2081 |
| 2079 for (size_t i = 0; i < bitmap_id_sizes.size(); ++i) { | 2082 for (size_t i = 0; i < bitmap_id_sizes.size(); ++i) { |
| 2080 const gfx::Size& pixel_size = bitmap_id_sizes[i].pixel_size; | 2083 const gfx::Size& pixel_size = bitmap_id_sizes[i].pixel_size; |
| 2081 std::vector<favicon_base::FaviconBitmapData>::iterator match_it = | 2084 std::vector<favicon_base::FaviconRawBitmapData>::iterator match_it = |
| 2082 to_add.end(); | 2085 to_add.end(); |
| 2083 for (std::vector<favicon_base::FaviconBitmapData>::iterator it = | 2086 for (std::vector<favicon_base::FaviconRawBitmapData>::iterator it = |
| 2084 to_add.begin(); | 2087 to_add.begin(); |
| 2085 it != to_add.end(); | 2088 it != to_add.end(); |
| 2086 ++it) { | 2089 ++it) { |
| 2087 if (it->pixel_size == pixel_size) { | 2090 if (it->pixel_size == pixel_size) { |
| 2088 match_it = it; | 2091 match_it = it; |
| 2089 break; | 2092 break; |
| 2090 } | 2093 } |
| 2091 } | 2094 } |
| 2092 | 2095 |
| 2093 FaviconBitmapID bitmap_id = bitmap_id_sizes[i].bitmap_id; | 2096 FaviconRawBitmapID bitmap_id = bitmap_id_sizes[i].bitmap_id; |
| 2094 if (match_it == to_add.end()) { | 2097 if (match_it == to_add.end()) { |
| 2095 thumbnail_db_->DeleteFaviconBitmap(bitmap_id); | 2098 thumbnail_db_->DeleteFaviconRawBitmap(bitmap_id); |
| 2096 | 2099 |
| 2097 if (favicon_bitmaps_changed) | 2100 if (favicon_bitmaps_changed) |
| 2098 *favicon_bitmaps_changed = true; | 2101 *favicon_bitmaps_changed = true; |
| 2099 } else { | 2102 } else { |
| 2100 if (favicon_bitmaps_changed && | 2103 if (favicon_bitmaps_changed && !*favicon_bitmaps_changed && |
| 2101 !*favicon_bitmaps_changed && | 2104 IsFaviconRawBitmapDataEqual(bitmap_id, match_it->bitmap_data)) { |
| 2102 IsFaviconBitmapDataEqual(bitmap_id, match_it->bitmap_data)) { | 2105 thumbnail_db_->SetFaviconRawBitmapLastUpdateTime(bitmap_id, |
| 2103 thumbnail_db_->SetFaviconBitmapLastUpdateTime( | 2106 base::Time::Now()); |
| 2104 bitmap_id, base::Time::Now()); | |
| 2105 } else { | 2107 } else { |
| 2106 thumbnail_db_->SetFaviconBitmap(bitmap_id, match_it->bitmap_data, | 2108 thumbnail_db_->SetFaviconRawBitmap( |
| 2107 base::Time::Now()); | 2109 bitmap_id, match_it->bitmap_data, base::Time::Now()); |
| 2108 | 2110 |
| 2109 if (favicon_bitmaps_changed) | 2111 if (favicon_bitmaps_changed) |
| 2110 *favicon_bitmaps_changed = true; | 2112 *favicon_bitmaps_changed = true; |
| 2111 } | 2113 } |
| 2112 to_add.erase(match_it); | 2114 to_add.erase(match_it); |
| 2113 } | 2115 } |
| 2114 } | 2116 } |
| 2115 | 2117 |
| 2116 for (size_t i = 0; i < to_add.size(); ++i) { | 2118 for (size_t i = 0; i < to_add.size(); ++i) { |
| 2117 thumbnail_db_->AddFaviconBitmap(icon_id, to_add[i].bitmap_data, | 2119 thumbnail_db_->AddFaviconRawBitmap(icon_id, |
| 2118 base::Time::Now(), to_add[i].pixel_size); | 2120 to_add[i].bitmap_data, |
| 2121 base::Time::Now(), |
| 2122 to_add[i].pixel_size); |
| 2119 | 2123 |
| 2120 if (favicon_bitmaps_changed) | 2124 if (favicon_bitmaps_changed) |
| 2121 *favicon_bitmaps_changed = true; | 2125 *favicon_bitmaps_changed = true; |
| 2122 } | 2126 } |
| 2123 } | 2127 } |
| 2124 | 2128 |
| 2125 bool HistoryBackend::ValidateSetFaviconsParams(const std::vector< | 2129 bool HistoryBackend::ValidateSetFaviconsParams(const std::vector< |
| 2126 favicon_base::FaviconBitmapData>& favicon_bitmap_data) const { | 2130 favicon_base::FaviconRawBitmapData>& favicon_bitmap_data) const { |
| 2127 typedef std::map<GURL, size_t> BitmapsPerIconURL; | 2131 typedef std::map<GURL, size_t> BitmapsPerIconURL; |
| 2128 BitmapsPerIconURL num_bitmaps_per_icon_url; | 2132 BitmapsPerIconURL num_bitmaps_per_icon_url; |
| 2129 for (size_t i = 0; i < favicon_bitmap_data.size(); ++i) { | 2133 for (size_t i = 0; i < favicon_bitmap_data.size(); ++i) { |
| 2130 if (!favicon_bitmap_data[i].bitmap_data.get()) | 2134 if (!favicon_bitmap_data[i].bitmap_data.get()) |
| 2131 return false; | 2135 return false; |
| 2132 | 2136 |
| 2133 const GURL& icon_url = favicon_bitmap_data[i].icon_url; | 2137 const GURL& icon_url = favicon_bitmap_data[i].icon_url; |
| 2134 if (!num_bitmaps_per_icon_url.count(icon_url)) | 2138 if (!num_bitmaps_per_icon_url.count(icon_url)) |
| 2135 num_bitmaps_per_icon_url[icon_url] = 1u; | 2139 num_bitmaps_per_icon_url[icon_url] = 1u; |
| 2136 else | 2140 else |
| 2137 ++num_bitmaps_per_icon_url[icon_url]; | 2141 ++num_bitmaps_per_icon_url[icon_url]; |
| 2138 } | 2142 } |
| 2139 | 2143 |
| 2140 if (num_bitmaps_per_icon_url.size() > kMaxFaviconsPerPage) | 2144 if (num_bitmaps_per_icon_url.size() > kMaxFaviconsPerPage) |
| 2141 return false; | 2145 return false; |
| 2142 | 2146 |
| 2143 for (BitmapsPerIconURL::const_iterator it = num_bitmaps_per_icon_url.begin(); | 2147 for (BitmapsPerIconURL::const_iterator it = num_bitmaps_per_icon_url.begin(); |
| 2144 it != num_bitmaps_per_icon_url.end(); ++it) { | 2148 it != num_bitmaps_per_icon_url.end(); ++it) { |
| 2145 if (it->second > kMaxFaviconBitmapsPerIconURL) | 2149 if (it->second > kMaxFaviconRawBitmapsPerIconURL) |
| 2146 return false; | 2150 return false; |
| 2147 } | 2151 } |
| 2148 return true; | 2152 return true; |
| 2149 } | 2153 } |
| 2150 | 2154 |
| 2151 bool HistoryBackend::IsFaviconBitmapDataEqual( | 2155 bool HistoryBackend::IsFaviconRawBitmapDataEqual( |
| 2152 FaviconBitmapID bitmap_id, | 2156 FaviconRawBitmapID bitmap_id, |
| 2153 const scoped_refptr<base::RefCountedMemory>& new_bitmap_data) { | 2157 const scoped_refptr<base::RefCountedMemory>& new_bitmap_data) { |
| 2154 if (!new_bitmap_data.get()) | 2158 if (!new_bitmap_data.get()) |
| 2155 return false; | 2159 return false; |
| 2156 | 2160 |
| 2157 scoped_refptr<base::RefCountedMemory> original_bitmap_data; | 2161 scoped_refptr<base::RefCountedMemory> original_bitmap_data; |
| 2158 thumbnail_db_->GetFaviconBitmap(bitmap_id, | 2162 thumbnail_db_->GetFaviconRawBitmap( |
| 2159 NULL, | 2163 bitmap_id, NULL, &original_bitmap_data, NULL); |
| 2160 &original_bitmap_data, | |
| 2161 NULL); | |
| 2162 return new_bitmap_data->Equals(original_bitmap_data); | 2164 return new_bitmap_data->Equals(original_bitmap_data); |
| 2163 } | 2165 } |
| 2164 | 2166 |
| 2165 bool HistoryBackend::GetFaviconsFromDB( | 2167 bool HistoryBackend::GetFaviconsFromDB( |
| 2166 const GURL& page_url, | 2168 const GURL& page_url, |
| 2167 int icon_types, | 2169 int icon_types, |
| 2168 int desired_size_in_dip, | 2170 int desired_size_in_dip, |
| 2169 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 2171 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
| 2170 std::vector<favicon_base::FaviconBitmapResult>* favicon_bitmap_results) { | 2172 std::vector<favicon_base::FaviconRawBitmapResult>* favicon_bitmap_results) { |
| 2171 DCHECK(favicon_bitmap_results); | 2173 DCHECK(favicon_bitmap_results); |
| 2172 favicon_bitmap_results->clear(); | 2174 favicon_bitmap_results->clear(); |
| 2173 | 2175 |
| 2174 if (!db_ || !thumbnail_db_) | 2176 if (!db_ || !thumbnail_db_) |
| 2175 return false; | 2177 return false; |
| 2176 | 2178 |
| 2177 // Time the query. | 2179 // Time the query. |
| 2178 TimeTicks beginning_time = TimeTicks::Now(); | 2180 TimeTicks beginning_time = TimeTicks::Now(); |
| 2179 | 2181 |
| 2180 // Get FaviconIDs for |page_url| and one of |icon_types|. | 2182 // Get FaviconIDs for |page_url| and one of |icon_types|. |
| 2181 std::vector<IconMapping> icon_mappings; | 2183 std::vector<IconMapping> icon_mappings; |
| 2182 thumbnail_db_->GetIconMappingsForPageURL(page_url, icon_types, | 2184 thumbnail_db_->GetIconMappingsForPageURL(page_url, icon_types, |
| 2183 &icon_mappings); | 2185 &icon_mappings); |
| 2184 std::vector<favicon_base::FaviconID> favicon_ids; | 2186 std::vector<favicon_base::FaviconID> favicon_ids; |
| 2185 for (size_t i = 0; i < icon_mappings.size(); ++i) | 2187 for (size_t i = 0; i < icon_mappings.size(); ++i) |
| 2186 favicon_ids.push_back(icon_mappings[i].icon_id); | 2188 favicon_ids.push_back(icon_mappings[i].icon_id); |
| 2187 | 2189 |
| 2188 // Populate |favicon_bitmap_results| and |icon_url_sizes|. | 2190 // Populate |favicon_bitmap_results| and |icon_url_sizes|. |
| 2189 bool success = GetFaviconBitmapResultsForBestMatch(favicon_ids, | 2191 bool success = GetFaviconRawBitmapResultsForBestMatch(favicon_ids, |
| 2190 desired_size_in_dip, desired_scale_factors, favicon_bitmap_results); | 2192 desired_size_in_dip, |
| 2193 desired_scale_factors, |
| 2194 favicon_bitmap_results); |
| 2191 UMA_HISTOGRAM_TIMES("History.GetFavIconFromDB", // historical name | 2195 UMA_HISTOGRAM_TIMES("History.GetFavIconFromDB", // historical name |
| 2192 TimeTicks::Now() - beginning_time); | 2196 TimeTicks::Now() - beginning_time); |
| 2193 return success && !favicon_bitmap_results->empty(); | 2197 return success && !favicon_bitmap_results->empty(); |
| 2194 } | 2198 } |
| 2195 | 2199 |
| 2196 bool HistoryBackend::GetFaviconBitmapResultsForBestMatch( | 2200 bool HistoryBackend::GetFaviconRawBitmapResultsForBestMatch( |
| 2197 const std::vector<favicon_base::FaviconID>& candidate_favicon_ids, | 2201 const std::vector<favicon_base::FaviconID>& candidate_favicon_ids, |
| 2198 int desired_size_in_dip, | 2202 int desired_size_in_dip, |
| 2199 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 2203 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
| 2200 std::vector<favicon_base::FaviconBitmapResult>* favicon_bitmap_results) { | 2204 std::vector<favicon_base::FaviconRawBitmapResult>* favicon_bitmap_results) { |
| 2201 favicon_bitmap_results->clear(); | 2205 favicon_bitmap_results->clear(); |
| 2202 | 2206 |
| 2203 if (candidate_favicon_ids.empty()) | 2207 if (candidate_favicon_ids.empty()) |
| 2204 return true; | 2208 return true; |
| 2205 | 2209 |
| 2206 // Find the FaviconID and the FaviconBitmapIDs which best match | 2210 // Find the FaviconID and the FaviconRawBitmapIDs which best match |
| 2207 // |desired_size_in_dip| and |desired_scale_factors|. | 2211 // |desired_size_in_dip| and |desired_scale_factors|. |
| 2208 // TODO(pkotwicz): Select bitmap results from multiple favicons once | 2212 // TODO(pkotwicz): Select bitmap results from multiple favicons once |
| 2209 // content::FaviconStatus supports multiple icon URLs. | 2213 // content::FaviconStatus supports multiple icon URLs. |
| 2210 favicon_base::FaviconID best_favicon_id = 0; | 2214 favicon_base::FaviconID best_favicon_id = 0; |
| 2211 std::vector<FaviconBitmapID> best_bitmap_ids; | 2215 std::vector<FaviconRawBitmapID> best_bitmap_ids; |
| 2212 float highest_score = kSelectFaviconFramesInvalidScore; | 2216 float highest_score = kSelectFaviconFramesInvalidScore; |
| 2213 for (size_t i = 0; i < candidate_favicon_ids.size(); ++i) { | 2217 for (size_t i = 0; i < candidate_favicon_ids.size(); ++i) { |
| 2214 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; | 2218 std::vector<FaviconRawBitmapIDSize> bitmap_id_sizes; |
| 2215 thumbnail_db_->GetFaviconBitmapIDSizes(candidate_favicon_ids[i], | 2219 thumbnail_db_->GetFaviconRawBitmapIDSizes(candidate_favicon_ids[i], |
| 2216 &bitmap_id_sizes); | 2220 &bitmap_id_sizes); |
| 2217 | 2221 |
| 2218 // Build vector of gfx::Size from |bitmap_id_sizes|. | 2222 // Build vector of gfx::Size from |bitmap_id_sizes|. |
| 2219 std::vector<gfx::Size> sizes; | 2223 std::vector<gfx::Size> sizes; |
| 2220 for (size_t j = 0; j < bitmap_id_sizes.size(); ++j) | 2224 for (size_t j = 0; j < bitmap_id_sizes.size(); ++j) |
| 2221 sizes.push_back(bitmap_id_sizes[j].pixel_size); | 2225 sizes.push_back(bitmap_id_sizes[j].pixel_size); |
| 2222 | 2226 |
| 2223 std::vector<size_t> candidate_bitmap_indices; | 2227 std::vector<size_t> candidate_bitmap_indices; |
| 2224 float score = 0; | 2228 float score = 0; |
| 2225 SelectFaviconFrameIndices(sizes, | 2229 SelectFaviconFrameIndices(sizes, |
| 2226 desired_scale_factors, | 2230 desired_scale_factors, |
| 2227 desired_size_in_dip, | 2231 desired_size_in_dip, |
| 2228 &candidate_bitmap_indices, | 2232 &candidate_bitmap_indices, |
| 2229 &score); | 2233 &score); |
| 2230 if (score > highest_score) { | 2234 if (score > highest_score) { |
| 2231 highest_score = score; | 2235 highest_score = score; |
| 2232 best_favicon_id = candidate_favicon_ids[i], | 2236 best_favicon_id = candidate_favicon_ids[i], |
| 2233 best_bitmap_ids.clear(); | 2237 best_bitmap_ids.clear(); |
| 2234 for (size_t j = 0; j < candidate_bitmap_indices.size(); ++j) { | 2238 for (size_t j = 0; j < candidate_bitmap_indices.size(); ++j) { |
| 2235 size_t candidate_index = candidate_bitmap_indices[j]; | 2239 size_t candidate_index = candidate_bitmap_indices[j]; |
| 2236 best_bitmap_ids.push_back( | 2240 best_bitmap_ids.push_back( |
| 2237 bitmap_id_sizes[candidate_index].bitmap_id); | 2241 bitmap_id_sizes[candidate_index].bitmap_id); |
| 2238 } | 2242 } |
| 2239 } | 2243 } |
| 2240 } | 2244 } |
| 2241 | 2245 |
| 2242 // Construct FaviconBitmapResults from |best_favicon_id| and | 2246 // Construct FaviconRawBitmapResults from |best_favicon_id| and |
| 2243 // |best_bitmap_ids|. | 2247 // |best_bitmap_ids|. |
| 2244 GURL icon_url; | 2248 GURL icon_url; |
| 2245 favicon_base::IconType icon_type; | 2249 favicon_base::IconType icon_type; |
| 2246 if (!thumbnail_db_->GetFaviconHeader(best_favicon_id, &icon_url, | 2250 if (!thumbnail_db_->GetFaviconHeader(best_favicon_id, &icon_url, |
| 2247 &icon_type)) { | 2251 &icon_type)) { |
| 2248 return false; | 2252 return false; |
| 2249 } | 2253 } |
| 2250 | 2254 |
| 2251 for (size_t i = 0; i < best_bitmap_ids.size(); ++i) { | 2255 for (size_t i = 0; i < best_bitmap_ids.size(); ++i) { |
| 2252 base::Time last_updated; | 2256 base::Time last_updated; |
| 2253 favicon_base::FaviconBitmapResult bitmap_result; | 2257 favicon_base::FaviconRawBitmapResult bitmap_result; |
| 2254 bitmap_result.icon_url = icon_url; | 2258 bitmap_result.icon_url = icon_url; |
| 2255 bitmap_result.icon_type = icon_type; | 2259 bitmap_result.icon_type = icon_type; |
| 2256 if (!thumbnail_db_->GetFaviconBitmap(best_bitmap_ids[i], | 2260 if (!thumbnail_db_->GetFaviconRawBitmap(best_bitmap_ids[i], |
| 2257 &last_updated, | 2261 &last_updated, |
| 2258 &bitmap_result.bitmap_data, | 2262 &bitmap_result.bitmap_data, |
| 2259 &bitmap_result.pixel_size)) { | 2263 &bitmap_result.pixel_size)) { |
| 2260 return false; | 2264 return false; |
| 2261 } | 2265 } |
| 2262 | 2266 |
| 2263 bitmap_result.expired = (Time::Now() - last_updated) > | 2267 bitmap_result.expired = (Time::Now() - last_updated) > |
| 2264 TimeDelta::FromDays(kFaviconRefetchDays); | 2268 TimeDelta::FromDays(kFaviconRefetchDays); |
| 2265 if (bitmap_result.is_valid()) | 2269 if (bitmap_result.is_valid()) |
| 2266 favicon_bitmap_results->push_back(bitmap_result); | 2270 favicon_bitmap_results->push_back(bitmap_result); |
| 2267 } | 2271 } |
| 2268 return true; | 2272 return true; |
| 2269 } | 2273 } |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2846 int rank = kPageVisitStatsMaxTopSites; | 2850 int rank = kPageVisitStatsMaxTopSites; |
| 2847 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url); | 2851 std::map<GURL, int>::const_iterator it = most_visited_urls_map_.find(url); |
| 2848 if (it != most_visited_urls_map_.end()) | 2852 if (it != most_visited_urls_map_.end()) |
| 2849 rank = (*it).second; | 2853 rank = (*it).second; |
| 2850 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", | 2854 UMA_HISTOGRAM_ENUMERATION("History.TopSitesVisitsByRank", |
| 2851 rank, kPageVisitStatsMaxTopSites + 1); | 2855 rank, kPageVisitStatsMaxTopSites + 1); |
| 2852 } | 2856 } |
| 2853 #endif | 2857 #endif |
| 2854 | 2858 |
| 2855 } // namespace history | 2859 } // namespace history |
| OLD | NEW |