| 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/history_backend.h" | 5 #include "components/history/core/browser/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 1403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1414 int num_databases_deleted = 0; | 1414 int num_databases_deleted = 0; |
| 1415 base::FilePath current_file; | 1415 base::FilePath current_file; |
| 1416 while (!(current_file = enumerator.Next()).empty()) { | 1416 while (!(current_file = enumerator.Next()).empty()) { |
| 1417 if (sql::Connection::Delete(current_file)) | 1417 if (sql::Connection::Delete(current_file)) |
| 1418 num_databases_deleted++; | 1418 num_databases_deleted++; |
| 1419 } | 1419 } |
| 1420 UMA_HISTOGRAM_COUNTS("History.DeleteFTSIndexDatabases", | 1420 UMA_HISTOGRAM_COUNTS("History.DeleteFTSIndexDatabases", |
| 1421 num_databases_deleted); | 1421 num_databases_deleted); |
| 1422 } | 1422 } |
| 1423 | 1423 |
| 1424 void HistoryBackend::GetFavicons( | 1424 void HistoryBackend::GetFavicon( |
| 1425 const std::vector<GURL>& icon_urls, | 1425 const GURL& icon_url, |
| 1426 int icon_types, | 1426 favicon_base::IconType icon_type, |
| 1427 const std::vector<int>& desired_sizes, | 1427 const std::vector<int>& desired_sizes, |
| 1428 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { | 1428 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { |
| 1429 UpdateFaviconMappingsAndFetchImpl(nullptr, icon_urls, icon_types, | 1429 UpdateFaviconMappingsAndFetchImpl(nullptr, icon_url, icon_type, desired_sizes, |
| 1430 desired_sizes, bitmap_results); | 1430 bitmap_results); |
| 1431 } | 1431 } |
| 1432 | 1432 |
| 1433 void HistoryBackend::GetLargestFaviconForURL( | 1433 void HistoryBackend::GetLargestFaviconForURL( |
| 1434 const GURL& page_url, | 1434 const GURL& page_url, |
| 1435 const std::vector<int>& icon_types, | 1435 const std::vector<int>& icon_types, |
| 1436 int minimum_size_in_pixels, | 1436 int minimum_size_in_pixels, |
| 1437 favicon_base::FaviconRawBitmapResult* favicon_bitmap_result) { | 1437 favicon_base::FaviconRawBitmapResult* favicon_bitmap_result) { |
| 1438 DCHECK(favicon_bitmap_result); | 1438 DCHECK(favicon_bitmap_result); |
| 1439 | 1439 |
| 1440 if (!db_ || !thumbnail_db_) | 1440 if (!db_ || !thumbnail_db_) |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1552 // Get results from DB. | 1552 // Get results from DB. |
| 1553 GetFaviconBitmapResultsForBestMatch(favicon_ids, desired_sizes, | 1553 GetFaviconBitmapResultsForBestMatch(favicon_ids, desired_sizes, |
| 1554 bitmap_results); | 1554 bitmap_results); |
| 1555 | 1555 |
| 1556 bitmap_results->assign(1, favicon_base::ResizeFaviconBitmapResult( | 1556 bitmap_results->assign(1, favicon_base::ResizeFaviconBitmapResult( |
| 1557 *bitmap_results, desired_size)); | 1557 *bitmap_results, desired_size)); |
| 1558 } | 1558 } |
| 1559 | 1559 |
| 1560 void HistoryBackend::UpdateFaviconMappingsAndFetch( | 1560 void HistoryBackend::UpdateFaviconMappingsAndFetch( |
| 1561 const GURL& page_url, | 1561 const GURL& page_url, |
| 1562 const std::vector<GURL>& icon_urls, | 1562 const GURL& icon_url, |
| 1563 int icon_types, | 1563 favicon_base::IconType icon_type, |
| 1564 const std::vector<int>& desired_sizes, | 1564 const std::vector<int>& desired_sizes, |
| 1565 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { | 1565 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { |
| 1566 UpdateFaviconMappingsAndFetchImpl(&page_url, icon_urls, icon_types, | 1566 UpdateFaviconMappingsAndFetchImpl(&page_url, icon_url, icon_type, |
| 1567 desired_sizes, bitmap_results); | 1567 desired_sizes, bitmap_results); |
| 1568 } | 1568 } |
| 1569 | 1569 |
| 1570 void HistoryBackend::MergeFavicon( | 1570 void HistoryBackend::MergeFavicon( |
| 1571 const GURL& page_url, | 1571 const GURL& page_url, |
| 1572 const GURL& icon_url, | 1572 const GURL& icon_url, |
| 1573 favicon_base::IconType icon_type, | 1573 favicon_base::IconType icon_type, |
| 1574 scoped_refptr<base::RefCountedMemory> bitmap_data, | 1574 scoped_refptr<base::RefCountedMemory> bitmap_data, |
| 1575 const gfx::Size& pixel_size) { | 1575 const gfx::Size& pixel_size) { |
| 1576 if (!thumbnail_db_ || !db_) | 1576 if (!thumbnail_db_ || !db_) |
| 1577 return; | 1577 return; |
| 1578 | 1578 |
| 1579 favicon_base::FaviconID favicon_id = | 1579 favicon_base::FaviconID favicon_id = |
| 1580 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type, nullptr); | 1580 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type); |
| 1581 | 1581 |
| 1582 bool favicon_created = false; | 1582 bool favicon_created = false; |
| 1583 if (!favicon_id) { | 1583 if (!favicon_id) { |
| 1584 // There is no favicon at |icon_url|, create it. | 1584 // There is no favicon at |icon_url|, create it. |
| 1585 favicon_id = thumbnail_db_->AddFavicon(icon_url, icon_type); | 1585 favicon_id = thumbnail_db_->AddFavicon(icon_url, icon_type); |
| 1586 favicon_created = true; | 1586 favicon_created = true; |
| 1587 } | 1587 } |
| 1588 | 1588 |
| 1589 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; | 1589 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; |
| 1590 thumbnail_db_->GetFaviconBitmapIDSizes(favicon_id, &bitmap_id_sizes); | 1590 thumbnail_db_->GetFaviconBitmapIDSizes(favicon_id, &bitmap_id_sizes); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1770 if (!db_ || !thumbnail_db_) | 1770 if (!db_ || !thumbnail_db_) |
| 1771 return; | 1771 return; |
| 1772 | 1772 |
| 1773 Time now = Time::Now(); | 1773 Time now = Time::Now(); |
| 1774 | 1774 |
| 1775 // Track all URLs that had their favicons set or updated. | 1775 // Track all URLs that had their favicons set or updated. |
| 1776 std::set<GURL> favicons_changed; | 1776 std::set<GURL> favicons_changed; |
| 1777 | 1777 |
| 1778 for (size_t i = 0; i < favicon_usage.size(); i++) { | 1778 for (size_t i = 0; i < favicon_usage.size(); i++) { |
| 1779 favicon_base::FaviconID favicon_id = | 1779 favicon_base::FaviconID favicon_id = |
| 1780 thumbnail_db_->GetFaviconIDForFaviconURL( | 1780 thumbnail_db_->GetFaviconIDForFaviconURL(favicon_usage[i].favicon_url, |
| 1781 favicon_usage[i].favicon_url, favicon_base::FAVICON, nullptr); | 1781 favicon_base::FAVICON); |
| 1782 if (!favicon_id) { | 1782 if (!favicon_id) { |
| 1783 // This favicon doesn't exist yet, so we create it using the given data. | 1783 // This favicon doesn't exist yet, so we create it using the given data. |
| 1784 // TODO(pkotwicz): Pass in real pixel size. | 1784 // TODO(pkotwicz): Pass in real pixel size. |
| 1785 favicon_id = thumbnail_db_->AddFavicon( | 1785 favicon_id = thumbnail_db_->AddFavicon( |
| 1786 favicon_usage[i].favicon_url, favicon_base::FAVICON, | 1786 favicon_usage[i].favicon_url, favicon_base::FAVICON, |
| 1787 new base::RefCountedBytes(favicon_usage[i].png_data), now, | 1787 new base::RefCountedBytes(favicon_usage[i].png_data), now, |
| 1788 gfx::Size()); | 1788 gfx::Size()); |
| 1789 } | 1789 } |
| 1790 | 1790 |
| 1791 // Save the mapping from all the URLs to the favicon. | 1791 // Save the mapping from all the URLs to the favicon. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1830 favicon_base::IconType icon_type, | 1830 favicon_base::IconType icon_type, |
| 1831 const GURL& icon_url, | 1831 const GURL& icon_url, |
| 1832 const std::vector<SkBitmap>& bitmaps, | 1832 const std::vector<SkBitmap>& bitmaps, |
| 1833 bool bitmaps_are_expired) { | 1833 bool bitmaps_are_expired) { |
| 1834 if (!thumbnail_db_ || !db_) | 1834 if (!thumbnail_db_ || !db_) |
| 1835 return false; | 1835 return false; |
| 1836 | 1836 |
| 1837 DCHECK_GE(kMaxFaviconBitmapsPerIconURL, bitmaps.size()); | 1837 DCHECK_GE(kMaxFaviconBitmapsPerIconURL, bitmaps.size()); |
| 1838 | 1838 |
| 1839 favicon_base::FaviconID icon_id = | 1839 favicon_base::FaviconID icon_id = |
| 1840 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type, nullptr); | 1840 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type); |
| 1841 | 1841 |
| 1842 bool favicon_created = false; | 1842 bool favicon_created = false; |
| 1843 if (!icon_id) { | 1843 if (!icon_id) { |
| 1844 icon_id = thumbnail_db_->AddFavicon(icon_url, icon_type); | 1844 icon_id = thumbnail_db_->AddFavicon(icon_url, icon_type); |
| 1845 favicon_created = true; | 1845 favicon_created = true; |
| 1846 } | 1846 } |
| 1847 | 1847 |
| 1848 bool favicon_data_modified = false; | 1848 bool favicon_data_modified = false; |
| 1849 if (favicon_created || !bitmaps_are_expired) | 1849 if (favicon_created || !bitmaps_are_expired) |
| 1850 favicon_data_modified = SetFaviconBitmaps(icon_id, bitmaps); | 1850 favicon_data_modified = SetFaviconBitmaps(icon_id, bitmaps); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1866 // there may be page URLs which also use the favicon at |icon_url|. Notify | 1866 // there may be page URLs which also use the favicon at |icon_url|. Notify |
| 1867 // the UI that the favicon has changed for |icon_url|. | 1867 // the UI that the favicon has changed for |icon_url|. |
| 1868 SendFaviconChangedNotificationForIconURL(icon_url); | 1868 SendFaviconChangedNotificationForIconURL(icon_url); |
| 1869 } | 1869 } |
| 1870 ScheduleCommit(); | 1870 ScheduleCommit(); |
| 1871 return favicon_data_modified; | 1871 return favicon_data_modified; |
| 1872 } | 1872 } |
| 1873 | 1873 |
| 1874 void HistoryBackend::UpdateFaviconMappingsAndFetchImpl( | 1874 void HistoryBackend::UpdateFaviconMappingsAndFetchImpl( |
| 1875 const GURL* page_url, | 1875 const GURL* page_url, |
| 1876 const std::vector<GURL>& icon_urls, | 1876 const GURL& icon_url, |
| 1877 int icon_types, | 1877 favicon_base::IconType icon_type, |
| 1878 const std::vector<int>& desired_sizes, | 1878 const std::vector<int>& desired_sizes, |
| 1879 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { | 1879 std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { |
| 1880 // If |page_url| is specified, |icon_types| must be either a single icon | |
| 1881 // type or icon types which are equivalent. | |
| 1882 DCHECK(!page_url || icon_types == favicon_base::FAVICON || | |
| 1883 icon_types == favicon_base::TOUCH_ICON || | |
| 1884 icon_types == favicon_base::TOUCH_PRECOMPOSED_ICON || | |
| 1885 icon_types == | |
| 1886 (favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON)); | |
| 1887 bitmap_results->clear(); | 1880 bitmap_results->clear(); |
| 1888 | 1881 |
| 1889 if (!thumbnail_db_) { | 1882 if (!thumbnail_db_) { |
| 1890 return; | 1883 return; |
| 1891 } | 1884 } |
| 1892 | 1885 |
| 1893 std::vector<favicon_base::FaviconID> favicon_ids; | 1886 std::vector<favicon_base::FaviconID> favicon_ids; |
| 1894 | 1887 |
| 1895 // The icon type for which the mappings will the updated and data will be | 1888 const favicon_base::FaviconID favicon_id = |
| 1896 // returned. | 1889 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type); |
| 1897 favicon_base::IconType selected_icon_type = favicon_base::INVALID_ICON; | 1890 if (favicon_id) |
| 1898 | 1891 favicon_ids.push_back(favicon_id); |
| 1899 for (size_t i = 0; i < icon_urls.size(); ++i) { | |
| 1900 const GURL& icon_url = icon_urls[i]; | |
| 1901 favicon_base::IconType icon_type_out; | |
| 1902 const favicon_base::FaviconID favicon_id = | |
| 1903 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_types, | |
| 1904 &icon_type_out); | |
| 1905 | |
| 1906 if (favicon_id) { | |
| 1907 // Return and update icon mappings only for the largest icon type. As | |
| 1908 // |icon_urls| is not sorted in terms of icon type, clear |favicon_ids| | |
| 1909 // if an |icon_url| with a larger icon type is found. | |
| 1910 if (icon_type_out > selected_icon_type) { | |
| 1911 selected_icon_type = icon_type_out; | |
| 1912 favicon_ids.clear(); | |
| 1913 } | |
| 1914 if (icon_type_out == selected_icon_type) | |
| 1915 favicon_ids.push_back(favicon_id); | |
| 1916 } | |
| 1917 } | |
| 1918 | 1892 |
| 1919 if (page_url && !favicon_ids.empty()) { | 1893 if (page_url && !favicon_ids.empty()) { |
| 1920 bool mappings_updated = SetFaviconMappingsForPageAndRedirects( | 1894 bool mappings_updated = SetFaviconMappingsForPageAndRedirects( |
| 1921 *page_url, selected_icon_type, favicon_ids); | 1895 *page_url, icon_type, favicon_ids); |
| 1922 if (mappings_updated) { | 1896 if (mappings_updated) { |
| 1923 SendFaviconChangedNotificationForPageAndRedirects(*page_url); | 1897 SendFaviconChangedNotificationForPageAndRedirects(*page_url); |
| 1924 ScheduleCommit(); | 1898 ScheduleCommit(); |
| 1925 } | 1899 } |
| 1926 } | 1900 } |
| 1927 | 1901 |
| 1928 GetFaviconBitmapResultsForBestMatch(favicon_ids, desired_sizes, | 1902 GetFaviconBitmapResultsForBestMatch(favicon_ids, desired_sizes, |
| 1929 bitmap_results); | 1903 bitmap_results); |
| 1930 } | 1904 } |
| 1931 | 1905 |
| (...skipping 728 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2660 // transaction is currently open. | 2634 // transaction is currently open. |
| 2661 db_->CommitTransaction(); | 2635 db_->CommitTransaction(); |
| 2662 db_->Vacuum(); | 2636 db_->Vacuum(); |
| 2663 db_->BeginTransaction(); | 2637 db_->BeginTransaction(); |
| 2664 db_->GetStartDate(&first_recorded_time_); | 2638 db_->GetStartDate(&first_recorded_time_); |
| 2665 | 2639 |
| 2666 return true; | 2640 return true; |
| 2667 } | 2641 } |
| 2668 | 2642 |
| 2669 } // namespace history | 2643 } // namespace history |
| OLD | NEW |