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 1825 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1836 URLID url_id; | 1836 URLID url_id; |
1837 if ((url_id = db_->GetRowForURL(redirects.back(), NULL))) | 1837 if ((url_id = db_->GetRowForURL(redirects.back(), NULL))) |
1838 success = thumbnail_db_->GetPageThumbnail(url_id, data); | 1838 success = thumbnail_db_->GetPageThumbnail(url_id, data); |
1839 } | 1839 } |
1840 } | 1840 } |
1841 } | 1841 } |
1842 | 1842 |
1843 return success; | 1843 return success; |
1844 } | 1844 } |
1845 | 1845 |
1846 HistoryBackend::FaviconResults::FaviconResults() {} | |
1847 HistoryBackend::FaviconResults::~FaviconResults() {} | |
1848 | |
1849 void HistoryBackend::FaviconResults::Clear() { | |
1850 bitmap_results.clear(); | |
1851 size_map.clear(); | |
1852 } | |
1853 | |
1854 void HistoryBackend::GetFavicons( | 1846 void HistoryBackend::GetFavicons( |
1855 const std::vector<GURL>& icon_urls, | 1847 const std::vector<GURL>& icon_urls, |
1856 int icon_types, | 1848 int icon_types, |
1857 int desired_size_in_dip, | 1849 int desired_size_in_dip, |
1858 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 1850 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
1859 FaviconResults* results) { | 1851 std::vector<FaviconBitmapResult>* bitmap_results) { |
1860 UpdateFaviconMappingsAndFetchImpl(NULL, icon_urls, icon_types, | 1852 UpdateFaviconMappingsAndFetchImpl(NULL, icon_urls, icon_types, |
1861 desired_size_in_dip, desired_scale_factors, | 1853 desired_size_in_dip, desired_scale_factors, |
1862 results); | 1854 bitmap_results); |
1863 } | 1855 } |
1864 | 1856 |
1865 void HistoryBackend::GetFaviconsForURL( | 1857 void HistoryBackend::GetFaviconsForURL( |
1866 const GURL& page_url, | 1858 const GURL& page_url, |
1867 int icon_types, | 1859 int icon_types, |
1868 int desired_size_in_dip, | 1860 int desired_size_in_dip, |
1869 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 1861 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
1870 FaviconResults* results) { | 1862 std::vector<FaviconBitmapResult>* bitmap_results) { |
1871 DCHECK(results); | 1863 DCHECK(bitmap_results); |
1872 GetFaviconsFromDB(page_url, icon_types, desired_size_in_dip, | 1864 GetFaviconsFromDB(page_url, icon_types, desired_size_in_dip, |
1873 desired_scale_factors, &results->bitmap_results, | 1865 desired_scale_factors, bitmap_results); |
1874 &results->size_map); | |
1875 } | 1866 } |
1876 | 1867 |
1877 void HistoryBackend::GetFaviconForID( | 1868 void HistoryBackend::GetFaviconForID( |
1878 FaviconID favicon_id, | 1869 FaviconID favicon_id, |
1879 int desired_size_in_dip, | 1870 int desired_size_in_dip, |
1880 ui::ScaleFactor desired_scale_factor, | 1871 ui::ScaleFactor desired_scale_factor, |
1881 FaviconResults* results) { | 1872 std::vector<FaviconBitmapResult>* bitmap_results) { |
1882 std::vector<FaviconID> favicon_ids; | 1873 std::vector<FaviconID> favicon_ids; |
1883 favicon_ids.push_back(favicon_id); | 1874 favicon_ids.push_back(favicon_id); |
1884 std::vector<ui::ScaleFactor> desired_scale_factors; | 1875 std::vector<ui::ScaleFactor> desired_scale_factors; |
1885 desired_scale_factors.push_back(desired_scale_factor); | 1876 desired_scale_factors.push_back(desired_scale_factor); |
1886 | 1877 |
1887 // Get results from DB. | 1878 // Get results from DB. |
1888 GetFaviconBitmapResultsForBestMatch(favicon_ids, | 1879 GetFaviconBitmapResultsForBestMatch(favicon_ids, |
1889 desired_size_in_dip, | 1880 desired_size_in_dip, |
1890 desired_scale_factors, | 1881 desired_scale_factors, |
1891 &results->bitmap_results); | 1882 bitmap_results); |
1892 BuildIconURLSizesMap(favicon_ids, &results->size_map); | |
1893 } | 1883 } |
1894 | 1884 |
1895 void HistoryBackend::UpdateFaviconMappingsAndFetch( | 1885 void HistoryBackend::UpdateFaviconMappingsAndFetch( |
1896 const GURL& page_url, | 1886 const GURL& page_url, |
1897 const std::vector<GURL>& icon_urls, | 1887 const std::vector<GURL>& icon_urls, |
1898 int icon_types, | 1888 int icon_types, |
1899 int desired_size_in_dip, | 1889 int desired_size_in_dip, |
1900 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 1890 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
1901 FaviconResults* results) { | 1891 std::vector<FaviconBitmapResult>* bitmap_results) { |
1902 UpdateFaviconMappingsAndFetchImpl(&page_url, icon_urls, icon_types, | 1892 UpdateFaviconMappingsAndFetchImpl(&page_url, icon_urls, icon_types, |
1903 desired_size_in_dip, desired_scale_factors, | 1893 desired_size_in_dip, desired_scale_factors, |
1904 results); | 1894 bitmap_results); |
1905 } | 1895 } |
1906 | 1896 |
1907 void HistoryBackend::MergeFavicon( | 1897 void HistoryBackend::MergeFavicon( |
1908 const GURL& page_url, | 1898 const GURL& page_url, |
1909 const GURL& icon_url, | 1899 const GURL& icon_url, |
1910 history::IconType icon_type, | 1900 history::IconType icon_type, |
1911 scoped_refptr<base::RefCountedMemory> bitmap_data, | 1901 scoped_refptr<base::RefCountedMemory> bitmap_data, |
1912 const gfx::Size& pixel_size) { | 1902 const gfx::Size& pixel_size) { |
1913 if (!thumbnail_db_.get() || !db_.get()) | 1903 if (!thumbnail_db_.get() || !db_.get()) |
1914 return; | 1904 return; |
(...skipping 29 matching lines...) Expand all Loading... |
1944 } | 1934 } |
1945 } | 1935 } |
1946 | 1936 |
1947 // Create a vector of the pixel sizes of the favicon bitmaps currently at | 1937 // Create a vector of the pixel sizes of the favicon bitmaps currently at |
1948 // |icon_url|. | 1938 // |icon_url|. |
1949 std::vector<gfx::Size> favicon_sizes; | 1939 std::vector<gfx::Size> favicon_sizes; |
1950 for (size_t i = 0; i < bitmap_id_sizes.size(); ++i) | 1940 for (size_t i = 0; i < bitmap_id_sizes.size(); ++i) |
1951 favicon_sizes.push_back(bitmap_id_sizes[i].pixel_size); | 1941 favicon_sizes.push_back(bitmap_id_sizes[i].pixel_size); |
1952 | 1942 |
1953 if (!replaced_bitmap) { | 1943 if (!replaced_bitmap) { |
| 1944 // Set the preexisting favicon bitmaps as expired as the preexisting favicon |
| 1945 // bitmaps are not consistent with the merged in data. |
| 1946 thumbnail_db_->SetFaviconOutOfDate(favicon_id); |
| 1947 |
1954 // Delete an arbitrary favicon bitmap to avoid going over the limit of | 1948 // Delete an arbitrary favicon bitmap to avoid going over the limit of |
1955 // |kMaxFaviconBitmapsPerIconURL|. | 1949 // |kMaxFaviconBitmapsPerIconURL|. |
1956 if (bitmap_id_sizes.size() >= kMaxFaviconBitmapsPerIconURL) { | 1950 if (bitmap_id_sizes.size() >= kMaxFaviconBitmapsPerIconURL) { |
1957 thumbnail_db_->DeleteFaviconBitmap(bitmap_id_sizes[0].bitmap_id); | 1951 thumbnail_db_->DeleteFaviconBitmap(bitmap_id_sizes[0].bitmap_id); |
1958 favicon_sizes.erase(favicon_sizes.begin()); | 1952 favicon_sizes.erase(favicon_sizes.begin()); |
1959 } | 1953 } |
1960 thumbnail_db_->AddFaviconBitmap(favicon_id, bitmap_data, base::Time::Now(), | 1954 thumbnail_db_->AddFaviconBitmap(favicon_id, bitmap_data, base::Time::Now(), |
1961 pixel_size); | 1955 pixel_size); |
1962 favicon_sizes.push_back(pixel_size); | 1956 favicon_sizes.push_back(pixel_size); |
1963 } | 1957 } |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2010 // Do not add a favicon bitmap at a pixel size for which there is already | 2004 // Do not add a favicon bitmap at a pixel size for which there is already |
2011 // a favicon bitmap mapped to |icon_url|. The one there is more correct | 2005 // a favicon bitmap mapped to |icon_url|. The one there is more correct |
2012 // and having multiple equally sized favicon bitmaps for |page_url| is | 2006 // and having multiple equally sized favicon bitmaps for |page_url| is |
2013 // ambiguous in terms of GetFaviconsForURL(). | 2007 // ambiguous in terms of GetFaviconsForURL(). |
2014 std::vector<gfx::Size>::iterator it = std::find(favicon_sizes.begin(), | 2008 std::vector<gfx::Size>::iterator it = std::find(favicon_sizes.begin(), |
2015 favicon_sizes.end(), bitmaps_to_copy[j].pixel_size); | 2009 favicon_sizes.end(), bitmaps_to_copy[j].pixel_size); |
2016 if (it != favicon_sizes.end()) | 2010 if (it != favicon_sizes.end()) |
2017 continue; | 2011 continue; |
2018 | 2012 |
2019 migrated_bitmaps = true; | 2013 migrated_bitmaps = true; |
| 2014 |
| 2015 // Add the favicon bitmap as expired as it is not consistent with the |
| 2016 // merged in data. |
2020 thumbnail_db_->AddFaviconBitmap(favicon_id, | 2017 thumbnail_db_->AddFaviconBitmap(favicon_id, |
2021 bitmaps_to_copy[j].bitmap_data, base::Time::Now(), | 2018 bitmaps_to_copy[j].bitmap_data, base::Time(), |
2022 bitmaps_to_copy[j].pixel_size); | 2019 bitmaps_to_copy[j].pixel_size); |
2023 favicon_sizes.push_back(bitmaps_to_copy[j].pixel_size); | 2020 favicon_sizes.push_back(bitmaps_to_copy[j].pixel_size); |
2024 | 2021 |
2025 if (favicon_sizes.size() >= kMaxFaviconBitmapsPerIconURL) | 2022 if (favicon_sizes.size() >= kMaxFaviconBitmapsPerIconURL) |
2026 break; | 2023 break; |
2027 } | 2024 } |
2028 } | 2025 } |
2029 | 2026 |
2030 if (migrated_bitmaps || !replaced_bitmap) { | |
2031 // Set the favicon sizes to default to indicate that at least some of the | |
2032 // favicon bitmaps for the favicon at |icon_url| are missing or stale. | |
2033 thumbnail_db_->SetFaviconSizes(favicon_id, GetDefaultFaviconSizes()); | |
2034 } | |
2035 | |
2036 // Update the favicon mappings such that only |icon_url| is mapped to | 2027 // Update the favicon mappings such that only |icon_url| is mapped to |
2037 // |page_url|. | 2028 // |page_url|. |
2038 if (icon_mappings.size() != 1 || icon_mappings[0].icon_url != icon_url) { | 2029 if (icon_mappings.size() != 1 || icon_mappings[0].icon_url != icon_url) { |
2039 std::vector<FaviconID> favicon_ids; | 2030 std::vector<FaviconID> favicon_ids; |
2040 favicon_ids.push_back(favicon_id); | 2031 favicon_ids.push_back(favicon_id); |
2041 SetFaviconMappingsForPageAndRedirects(page_url, icon_type, favicon_ids); | 2032 SetFaviconMappingsForPageAndRedirects(page_url, icon_type, favicon_ids); |
2042 } | 2033 } |
2043 | 2034 |
2044 // Sync currently does not properly deal with notifications as a result of | 2035 // Sync currently does not properly deal with notifications as a result of |
2045 // replacing a favicon bitmap. For M25, do not send any notifications if a | 2036 // replacing a favicon bitmap. For M25, do not send any notifications if a |
2046 // bitmap was replaced and no bitmaps were added or deleted. This is a | 2037 // bitmap was replaced and no bitmaps were added or deleted. This is a |
2047 // temporary fix for http://crbug.com/169460. | 2038 // temporary fix for http://crbug.com/169460. |
2048 if (migrated_bitmaps || !replaced_bitmap) | 2039 if (migrated_bitmaps || !replaced_bitmap) |
2049 SendFaviconChangedNotificationForPageAndRedirects(page_url); | 2040 SendFaviconChangedNotificationForPageAndRedirects(page_url); |
2050 | 2041 |
2051 ScheduleCommit(); | 2042 ScheduleCommit(); |
2052 } | 2043 } |
2053 | 2044 |
2054 void HistoryBackend::SetFavicons( | 2045 void HistoryBackend::SetFavicons( |
2055 const GURL& page_url, | 2046 const GURL& page_url, |
2056 IconType icon_type, | 2047 IconType icon_type, |
2057 const std::vector<FaviconBitmapData>& favicon_bitmap_data, | 2048 const std::vector<FaviconBitmapData>& favicon_bitmap_data) { |
2058 const IconURLSizesMap& icon_url_sizes) { | |
2059 if (!thumbnail_db_.get() || !db_.get()) | 2049 if (!thumbnail_db_.get() || !db_.get()) |
2060 return; | 2050 return; |
2061 | 2051 |
2062 DCHECK(ValidateSetFaviconsParams(favicon_bitmap_data, icon_url_sizes)); | 2052 DCHECK(ValidateSetFaviconsParams(favicon_bitmap_data)); |
2063 | 2053 |
2064 // Build map of FaviconBitmapData for each icon url. | 2054 // Build map of FaviconBitmapData for each icon url. |
2065 typedef std::map<GURL, std::vector<FaviconBitmapData> > | 2055 typedef std::map<GURL, std::vector<FaviconBitmapData> > |
2066 BitmapDataByIconURL; | 2056 BitmapDataByIconURL; |
2067 BitmapDataByIconURL grouped_by_icon_url; | 2057 BitmapDataByIconURL grouped_by_icon_url; |
2068 for (size_t i = 0; i < favicon_bitmap_data.size(); ++i) { | 2058 for (size_t i = 0; i < favicon_bitmap_data.size(); ++i) { |
2069 const GURL& icon_url = favicon_bitmap_data[i].icon_url; | 2059 const GURL& icon_url = favicon_bitmap_data[i].icon_url; |
2070 grouped_by_icon_url[icon_url].push_back(favicon_bitmap_data[i]); | 2060 grouped_by_icon_url[icon_url].push_back(favicon_bitmap_data[i]); |
2071 } | 2061 } |
2072 | 2062 |
2073 // Track whether the method modifies or creates any favicon bitmaps, favicons | 2063 // Track whether the method modifies or creates any favicon bitmaps, favicons |
2074 // or icon mappings. | 2064 // or icon mappings. |
2075 bool data_modified = false; | 2065 bool data_modified = false; |
2076 | 2066 |
2077 std::vector<FaviconID> icon_ids; | 2067 std::vector<FaviconID> icon_ids; |
2078 for (IconURLSizesMap::const_iterator it = icon_url_sizes.begin(); | 2068 for (BitmapDataByIconURL::const_iterator it = grouped_by_icon_url.begin(); |
2079 it != icon_url_sizes.end(); ++it) { | 2069 it != grouped_by_icon_url.end(); ++it) { |
2080 const GURL& icon_url = it->first; | 2070 const GURL& icon_url = it->first; |
2081 FaviconID icon_id = | 2071 FaviconID icon_id = |
2082 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type, NULL); | 2072 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type, NULL); |
2083 if (icon_id) { | 2073 |
2084 bool favicon_bitmaps_deleted = false; | 2074 if (!icon_id) { |
2085 SetFaviconSizes(icon_id, it->second, &favicon_bitmaps_deleted); | 2075 // TODO(pkotwicz): Remove the favicon sizes attribute from |
2086 data_modified |= favicon_bitmaps_deleted; | 2076 // ThumbnailDatabase::AddFavicon(). |
2087 } else { | 2077 icon_id = thumbnail_db_->AddFavicon(icon_url, icon_type, |
2088 icon_id = thumbnail_db_->AddFavicon(icon_url, icon_type, it->second); | 2078 GetDefaultFaviconSizes()); |
2089 data_modified = true; | 2079 data_modified = true; |
2090 } | 2080 } |
2091 icon_ids.push_back(icon_id); | 2081 icon_ids.push_back(icon_id); |
2092 | 2082 |
2093 BitmapDataByIconURL::iterator grouped_by_icon_url_it = | 2083 if (!data_modified) |
2094 grouped_by_icon_url.find(icon_url); | 2084 SetFaviconBitmaps(icon_id, it->second, &data_modified); |
2095 if (grouped_by_icon_url_it != grouped_by_icon_url.end()) { | 2085 else |
2096 if (!data_modified) { | 2086 SetFaviconBitmaps(icon_id, it->second, NULL); |
2097 bool favicon_bitmaps_changed = false; | |
2098 SetFaviconBitmaps(icon_id, | |
2099 grouped_by_icon_url_it->second, | |
2100 &favicon_bitmaps_changed); | |
2101 data_modified |= favicon_bitmaps_changed; | |
2102 } else { | |
2103 SetFaviconBitmaps(icon_id, | |
2104 grouped_by_icon_url_it->second, | |
2105 NULL); | |
2106 } | |
2107 } | |
2108 } | 2087 } |
2109 | 2088 |
2110 data_modified |= | 2089 data_modified |= |
2111 SetFaviconMappingsForPageAndRedirects(page_url, icon_type, icon_ids); | 2090 SetFaviconMappingsForPageAndRedirects(page_url, icon_type, icon_ids); |
2112 | 2091 |
2113 if (data_modified) { | 2092 if (data_modified) { |
2114 // Send notification to the UI as an icon mapping, favicon, or favicon | 2093 // Send notification to the UI as an icon mapping, favicon, or favicon |
2115 // bitmap was changed by this function. | 2094 // bitmap was changed by this function. |
2116 SendFaviconChangedNotificationForPageAndRedirects(page_url); | 2095 SendFaviconChangedNotificationForPageAndRedirects(page_url); |
2117 } | 2096 } |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2211 changed_details); | 2190 changed_details); |
2212 } | 2191 } |
2213 } | 2192 } |
2214 | 2193 |
2215 void HistoryBackend::UpdateFaviconMappingsAndFetchImpl( | 2194 void HistoryBackend::UpdateFaviconMappingsAndFetchImpl( |
2216 const GURL* page_url, | 2195 const GURL* page_url, |
2217 const std::vector<GURL>& icon_urls, | 2196 const std::vector<GURL>& icon_urls, |
2218 int icon_types, | 2197 int icon_types, |
2219 int desired_size_in_dip, | 2198 int desired_size_in_dip, |
2220 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 2199 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
2221 FaviconResults* results) { | 2200 std::vector<FaviconBitmapResult>* bitmap_results) { |
2222 // If |page_url| is specified, |icon_types| must be either a single icon | 2201 // If |page_url| is specified, |icon_types| must be either a single icon |
2223 // type or icon types which are equivalent. | 2202 // type or icon types which are equivalent. |
2224 DCHECK(!page_url || | 2203 DCHECK(!page_url || |
2225 icon_types == FAVICON || | 2204 icon_types == FAVICON || |
2226 icon_types == TOUCH_ICON || | 2205 icon_types == TOUCH_ICON || |
2227 icon_types == TOUCH_PRECOMPOSED_ICON || | 2206 icon_types == TOUCH_PRECOMPOSED_ICON || |
2228 icon_types == (TOUCH_ICON | TOUCH_PRECOMPOSED_ICON)); | 2207 icon_types == (TOUCH_ICON | TOUCH_PRECOMPOSED_ICON)); |
2229 results->Clear(); | 2208 bitmap_results->clear(); |
2230 | 2209 |
2231 if (!thumbnail_db_.get()) { | 2210 if (!thumbnail_db_.get()) { |
2232 return; | 2211 return; |
2233 } | 2212 } |
2234 | 2213 |
2235 std::vector<FaviconID> favicon_ids; | 2214 std::vector<FaviconID> favicon_ids; |
2236 | 2215 |
2237 // The icon type for which the mappings will the updated and data will be | 2216 // The icon type for which the mappings will the updated and data will be |
2238 // returned. | 2217 // returned. |
2239 IconType selected_icon_type = INVALID_ICON; | 2218 IconType selected_icon_type = INVALID_ICON; |
(...skipping 21 matching lines...) Expand all Loading... |
2261 bool mappings_updated = | 2240 bool mappings_updated = |
2262 SetFaviconMappingsForPageAndRedirects(*page_url, selected_icon_type, | 2241 SetFaviconMappingsForPageAndRedirects(*page_url, selected_icon_type, |
2263 favicon_ids); | 2242 favicon_ids); |
2264 if (mappings_updated) { | 2243 if (mappings_updated) { |
2265 SendFaviconChangedNotificationForPageAndRedirects(*page_url); | 2244 SendFaviconChangedNotificationForPageAndRedirects(*page_url); |
2266 ScheduleCommit(); | 2245 ScheduleCommit(); |
2267 } | 2246 } |
2268 } | 2247 } |
2269 | 2248 |
2270 GetFaviconBitmapResultsForBestMatch(favicon_ids, desired_size_in_dip, | 2249 GetFaviconBitmapResultsForBestMatch(favicon_ids, desired_size_in_dip, |
2271 desired_scale_factors, &results->bitmap_results); | 2250 desired_scale_factors, bitmap_results); |
2272 BuildIconURLSizesMap(favicon_ids, &results->size_map); | |
2273 } | 2251 } |
2274 | 2252 |
2275 void HistoryBackend::SetFaviconBitmaps( | 2253 void HistoryBackend::SetFaviconBitmaps( |
2276 FaviconID icon_id, | 2254 FaviconID icon_id, |
2277 const std::vector<FaviconBitmapData>& favicon_bitmap_data, | 2255 const std::vector<FaviconBitmapData>& favicon_bitmap_data, |
2278 bool* favicon_bitmaps_changed) { | 2256 bool* favicon_bitmaps_changed) { |
2279 if (favicon_bitmaps_changed) | 2257 if (favicon_bitmaps_changed) |
2280 *favicon_bitmaps_changed = false; | 2258 *favicon_bitmaps_changed = false; |
2281 | 2259 |
2282 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; | 2260 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; |
2283 thumbnail_db_->GetFaviconBitmapIDSizes(icon_id, &bitmap_id_sizes); | 2261 thumbnail_db_->GetFaviconBitmapIDSizes(icon_id, &bitmap_id_sizes); |
2284 | 2262 |
2285 // A nested loop is ok because in practice neither |favicon_bitmap_data| nor | 2263 std::vector<FaviconBitmapData> to_add = favicon_bitmap_data; |
2286 // |bitmap_id_sizes| will have many elements. | 2264 |
2287 for (size_t i = 0; i < favicon_bitmap_data.size(); ++i) { | 2265 for (size_t i = 0; i < bitmap_id_sizes.size(); ++i) { |
2288 const FaviconBitmapData& bitmap_data_element = favicon_bitmap_data[i]; | 2266 const gfx::Size& pixel_size = bitmap_id_sizes[i].pixel_size; |
2289 FaviconBitmapID bitmap_id = 0; | 2267 std::vector<FaviconBitmapData>::iterator match_it = to_add.end(); |
2290 for (size_t j = 0; j < bitmap_id_sizes.size(); ++j) { | 2268 for (std::vector<FaviconBitmapData>::iterator it = to_add.begin(); |
2291 if (bitmap_id_sizes[j].pixel_size == bitmap_data_element.pixel_size) { | 2269 it != to_add.end(); ++it) { |
2292 bitmap_id = bitmap_id_sizes[j].bitmap_id; | 2270 if (it->pixel_size == pixel_size) { |
| 2271 match_it = it; |
2293 break; | 2272 break; |
2294 } | 2273 } |
2295 } | 2274 } |
2296 if (bitmap_id) { | 2275 |
| 2276 FaviconBitmapID bitmap_id = bitmap_id_sizes[i].bitmap_id; |
| 2277 if (match_it == to_add.end()) { |
| 2278 thumbnail_db_->DeleteFaviconBitmap(bitmap_id); |
| 2279 |
| 2280 if (favicon_bitmaps_changed) |
| 2281 *favicon_bitmaps_changed = true; |
| 2282 } else { |
2297 if (favicon_bitmaps_changed && | 2283 if (favicon_bitmaps_changed && |
2298 !*favicon_bitmaps_changed && | 2284 !*favicon_bitmaps_changed && |
2299 IsFaviconBitmapDataEqual(bitmap_id, | 2285 IsFaviconBitmapDataEqual(bitmap_id, match_it->bitmap_data)) { |
2300 bitmap_data_element.bitmap_data)) { | |
2301 thumbnail_db_->SetFaviconBitmapLastUpdateTime( | 2286 thumbnail_db_->SetFaviconBitmapLastUpdateTime( |
2302 bitmap_id, base::Time::Now()); | 2287 bitmap_id, base::Time::Now()); |
2303 } else { | 2288 } else { |
2304 thumbnail_db_->SetFaviconBitmap(bitmap_id, | 2289 thumbnail_db_->SetFaviconBitmap(bitmap_id, match_it->bitmap_data, |
2305 bitmap_data_element.bitmap_data, base::Time::Now()); | 2290 base::Time::Now()); |
| 2291 |
2306 if (favicon_bitmaps_changed) | 2292 if (favicon_bitmaps_changed) |
2307 *favicon_bitmaps_changed = true; | 2293 *favicon_bitmaps_changed = true; |
2308 } | 2294 } |
2309 } else { | 2295 to_add.erase(match_it); |
2310 thumbnail_db_->AddFaviconBitmap(icon_id, bitmap_data_element.bitmap_data, | |
2311 base::Time::Now(), bitmap_data_element.pixel_size); | |
2312 if (favicon_bitmaps_changed) | |
2313 *favicon_bitmaps_changed = true; | |
2314 } | 2296 } |
2315 } | 2297 } |
| 2298 |
| 2299 for (size_t i = 0; i < to_add.size(); ++i) { |
| 2300 thumbnail_db_->AddFaviconBitmap(icon_id, to_add[i].bitmap_data, |
| 2301 base::Time::Now(), to_add[i].pixel_size); |
| 2302 |
| 2303 if (favicon_bitmaps_changed) |
| 2304 *favicon_bitmaps_changed = true; |
| 2305 } |
2316 } | 2306 } |
2317 | 2307 |
2318 bool HistoryBackend::ValidateSetFaviconsParams( | 2308 bool HistoryBackend::ValidateSetFaviconsParams( |
2319 const std::vector<FaviconBitmapData>& favicon_bitmap_data, | 2309 const std::vector<FaviconBitmapData>& favicon_bitmap_data) const { |
2320 const IconURLSizesMap& icon_url_sizes) const { | 2310 typedef std::map<GURL, size_t> BitmapsPerIconURL; |
2321 if (icon_url_sizes.size() > kMaxFaviconsPerPage) | 2311 BitmapsPerIconURL num_bitmaps_per_icon_url; |
2322 return false; | |
2323 | |
2324 for (IconURLSizesMap::const_iterator it = icon_url_sizes.begin(); | |
2325 it != icon_url_sizes.end(); ++it) { | |
2326 if (it->second.size() > kMaxFaviconBitmapsPerIconURL) | |
2327 return false; | |
2328 } | |
2329 | |
2330 for (size_t i = 0; i < favicon_bitmap_data.size(); ++i) { | 2312 for (size_t i = 0; i < favicon_bitmap_data.size(); ++i) { |
2331 if (!favicon_bitmap_data[i].bitmap_data.get()) | 2313 if (!favicon_bitmap_data[i].bitmap_data.get()) |
2332 return false; | 2314 return false; |
2333 | 2315 |
2334 IconURLSizesMap::const_iterator it = | 2316 const GURL& icon_url = favicon_bitmap_data[i].icon_url; |
2335 icon_url_sizes.find(favicon_bitmap_data[i].icon_url); | 2317 if (!num_bitmaps_per_icon_url.count(icon_url)) |
2336 if (it == icon_url_sizes.end()) | 2318 num_bitmaps_per_icon_url[icon_url] = 1u; |
2337 return false; | 2319 else |
| 2320 ++num_bitmaps_per_icon_url[icon_url]; |
| 2321 } |
2338 | 2322 |
2339 const FaviconSizes& favicon_sizes = it->second; | 2323 if (num_bitmaps_per_icon_url.size() > kMaxFaviconsPerPage) |
2340 FaviconSizes::const_iterator it2 = std::find(favicon_sizes.begin(), | 2324 return false; |
2341 favicon_sizes.end(), favicon_bitmap_data[i].pixel_size); | 2325 |
2342 if (it2 == favicon_sizes.end()) | 2326 for (BitmapsPerIconURL::const_iterator it = num_bitmaps_per_icon_url.begin(); |
| 2327 it != num_bitmaps_per_icon_url.end(); ++it) { |
| 2328 if (it->second > kMaxFaviconBitmapsPerIconURL) |
2343 return false; | 2329 return false; |
2344 } | 2330 } |
2345 return true; | 2331 return true; |
2346 } | 2332 } |
2347 | 2333 |
2348 void HistoryBackend::SetFaviconSizes(FaviconID icon_id, | |
2349 const FaviconSizes& favicon_sizes, | |
2350 bool* favicon_bitmaps_deleted) { | |
2351 *favicon_bitmaps_deleted = false; | |
2352 | |
2353 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; | |
2354 thumbnail_db_->GetFaviconBitmapIDSizes(icon_id, &bitmap_id_sizes); | |
2355 | |
2356 // Remove bitmaps whose pixel size is not contained in |favicon_sizes|. | |
2357 for (size_t i = 0; i < bitmap_id_sizes.size(); ++i) { | |
2358 const gfx::Size& pixel_size = bitmap_id_sizes[i].pixel_size; | |
2359 FaviconSizes::const_iterator sizes_it = std::find(favicon_sizes.begin(), | |
2360 favicon_sizes.end(), pixel_size); | |
2361 if (sizes_it == favicon_sizes.end()) { | |
2362 thumbnail_db_->DeleteFaviconBitmap(bitmap_id_sizes[i].bitmap_id); | |
2363 *favicon_bitmaps_deleted = true; | |
2364 } | |
2365 } | |
2366 | |
2367 thumbnail_db_->SetFaviconSizes(icon_id, favicon_sizes); | |
2368 } | |
2369 | |
2370 bool HistoryBackend::IsFaviconBitmapDataEqual( | 2334 bool HistoryBackend::IsFaviconBitmapDataEqual( |
2371 FaviconBitmapID bitmap_id, | 2335 FaviconBitmapID bitmap_id, |
2372 const scoped_refptr<base::RefCountedMemory>& new_bitmap_data) { | 2336 const scoped_refptr<base::RefCountedMemory>& new_bitmap_data) { |
2373 if (!new_bitmap_data.get()) | 2337 if (!new_bitmap_data.get()) |
2374 return false; | 2338 return false; |
2375 | 2339 |
2376 scoped_refptr<base::RefCountedMemory> original_bitmap_data; | 2340 scoped_refptr<base::RefCountedMemory> original_bitmap_data; |
2377 thumbnail_db_->GetFaviconBitmap(bitmap_id, | 2341 thumbnail_db_->GetFaviconBitmap(bitmap_id, |
2378 NULL, | 2342 NULL, |
2379 &original_bitmap_data, | 2343 &original_bitmap_data, |
2380 NULL); | 2344 NULL); |
2381 return new_bitmap_data->Equals(original_bitmap_data); | 2345 return new_bitmap_data->Equals(original_bitmap_data); |
2382 } | 2346 } |
2383 | 2347 |
2384 bool HistoryBackend::GetFaviconsFromDB( | 2348 bool HistoryBackend::GetFaviconsFromDB( |
2385 const GURL& page_url, | 2349 const GURL& page_url, |
2386 int icon_types, | 2350 int icon_types, |
2387 int desired_size_in_dip, | 2351 int desired_size_in_dip, |
2388 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 2352 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
2389 std::vector<FaviconBitmapResult>* favicon_bitmap_results, | 2353 std::vector<FaviconBitmapResult>* favicon_bitmap_results) { |
2390 IconURLSizesMap* icon_url_sizes) { | |
2391 DCHECK(favicon_bitmap_results); | 2354 DCHECK(favicon_bitmap_results); |
2392 DCHECK(icon_url_sizes); | |
2393 favicon_bitmap_results->clear(); | 2355 favicon_bitmap_results->clear(); |
2394 icon_url_sizes->clear(); | |
2395 | 2356 |
2396 if (!db_.get() || !thumbnail_db_.get()) | 2357 if (!db_.get() || !thumbnail_db_.get()) |
2397 return false; | 2358 return false; |
2398 | 2359 |
2399 // Time the query. | 2360 // Time the query. |
2400 TimeTicks beginning_time = TimeTicks::Now(); | 2361 TimeTicks beginning_time = TimeTicks::Now(); |
2401 | 2362 |
2402 // Get FaviconIDs for |page_url| and one of |icon_types|. | 2363 // Get FaviconIDs for |page_url| and one of |icon_types|. |
2403 std::vector<IconMapping> icon_mappings; | 2364 std::vector<IconMapping> icon_mappings; |
2404 thumbnail_db_->GetIconMappingsForPageURL(page_url, icon_types, | 2365 thumbnail_db_->GetIconMappingsForPageURL(page_url, icon_types, |
2405 &icon_mappings); | 2366 &icon_mappings); |
2406 std::vector<FaviconID> favicon_ids; | 2367 std::vector<FaviconID> favicon_ids; |
2407 for (size_t i = 0; i < icon_mappings.size(); ++i) | 2368 for (size_t i = 0; i < icon_mappings.size(); ++i) |
2408 favicon_ids.push_back(icon_mappings[i].icon_id); | 2369 favicon_ids.push_back(icon_mappings[i].icon_id); |
2409 | 2370 |
2410 // Populate |favicon_bitmap_results| and |icon_url_sizes|. | 2371 // Populate |favicon_bitmap_results| and |icon_url_sizes|. |
2411 bool success = | 2372 bool success = GetFaviconBitmapResultsForBestMatch(favicon_ids, |
2412 GetFaviconBitmapResultsForBestMatch(favicon_ids, | 2373 desired_size_in_dip, desired_scale_factors, favicon_bitmap_results); |
2413 desired_size_in_dip, desired_scale_factors, favicon_bitmap_results) && | |
2414 BuildIconURLSizesMap(favicon_ids, icon_url_sizes); | |
2415 UMA_HISTOGRAM_TIMES("History.GetFavIconFromDB", // historical name | 2374 UMA_HISTOGRAM_TIMES("History.GetFavIconFromDB", // historical name |
2416 TimeTicks::Now() - beginning_time); | 2375 TimeTicks::Now() - beginning_time); |
2417 return success && !icon_url_sizes->empty(); | 2376 return success && !favicon_bitmap_results->empty(); |
2418 } | 2377 } |
2419 | 2378 |
2420 bool HistoryBackend::GetFaviconBitmapResultsForBestMatch( | 2379 bool HistoryBackend::GetFaviconBitmapResultsForBestMatch( |
2421 const std::vector<FaviconID>& candidate_favicon_ids, | 2380 const std::vector<FaviconID>& candidate_favicon_ids, |
2422 int desired_size_in_dip, | 2381 int desired_size_in_dip, |
2423 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 2382 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
2424 std::vector<history::FaviconBitmapResult>* favicon_bitmap_results) { | 2383 std::vector<FaviconBitmapResult>* favicon_bitmap_results) { |
2425 favicon_bitmap_results->clear(); | 2384 favicon_bitmap_results->clear(); |
2426 | 2385 |
2427 if (candidate_favicon_ids.empty()) | 2386 if (candidate_favicon_ids.empty()) |
2428 return true; | 2387 return true; |
2429 | 2388 |
2430 // Find the FaviconID and the FaviconBitmapIDs which best match | 2389 // Find the FaviconID and the FaviconBitmapIDs which best match |
2431 // |desired_size_in_dip| and |desired_scale_factors|. | 2390 // |desired_size_in_dip| and |desired_scale_factors|. |
2432 // TODO(pkotwicz): Select bitmap results from multiple favicons once | 2391 // TODO(pkotwicz): Select bitmap results from multiple favicons once |
2433 // content::FaviconStatus supports multiple icon URLs. | 2392 // content::FaviconStatus supports multiple icon URLs. |
2434 FaviconID best_favicon_id = 0; | 2393 FaviconID best_favicon_id = 0; |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2485 } | 2444 } |
2486 | 2445 |
2487 bitmap_result.expired = (Time::Now() - last_updated) > | 2446 bitmap_result.expired = (Time::Now() - last_updated) > |
2488 TimeDelta::FromDays(kFaviconRefetchDays); | 2447 TimeDelta::FromDays(kFaviconRefetchDays); |
2489 if (bitmap_result.is_valid()) | 2448 if (bitmap_result.is_valid()) |
2490 favicon_bitmap_results->push_back(bitmap_result); | 2449 favicon_bitmap_results->push_back(bitmap_result); |
2491 } | 2450 } |
2492 return true; | 2451 return true; |
2493 } | 2452 } |
2494 | 2453 |
2495 bool HistoryBackend::BuildIconURLSizesMap( | |
2496 const std::vector<FaviconID>& favicon_ids, | |
2497 IconURLSizesMap* icon_url_sizes) { | |
2498 icon_url_sizes->clear(); | |
2499 for (size_t i = 0; i < favicon_ids.size(); ++i) { | |
2500 GURL icon_url; | |
2501 FaviconSizes favicon_sizes; | |
2502 if (!thumbnail_db_->GetFaviconHeader(favicon_ids[i], &icon_url, NULL, | |
2503 &favicon_sizes)) { | |
2504 return false; | |
2505 } | |
2506 (*icon_url_sizes)[icon_url] = favicon_sizes; | |
2507 } | |
2508 return true; | |
2509 } | |
2510 | |
2511 bool HistoryBackend::SetFaviconMappingsForPageAndRedirects( | 2454 bool HistoryBackend::SetFaviconMappingsForPageAndRedirects( |
2512 const GURL& page_url, | 2455 const GURL& page_url, |
2513 IconType icon_type, | 2456 IconType icon_type, |
2514 const std::vector<FaviconID>& icon_ids) { | 2457 const std::vector<FaviconID>& icon_ids) { |
2515 if (!thumbnail_db_.get()) | 2458 if (!thumbnail_db_.get()) |
2516 return false; | 2459 return false; |
2517 | 2460 |
2518 // Find all the pages whose favicons we should set, we want to set it for | 2461 // Find all the pages whose favicons we should set, we want to set it for |
2519 // all the pages in the redirect chain if it redirected. | 2462 // all the pages in the redirect chain if it redirected. |
2520 history::RedirectList redirects; | 2463 history::RedirectList redirects; |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3042 info.url_id = visit.url_id; | 2985 info.url_id = visit.url_id; |
3043 info.time = visit.visit_time; | 2986 info.time = visit.visit_time; |
3044 info.transition = visit.transition; | 2987 info.transition = visit.transition; |
3045 // If we don't have a delegate yet during setup or shutdown, we will drop | 2988 // If we don't have a delegate yet during setup or shutdown, we will drop |
3046 // these notifications. | 2989 // these notifications. |
3047 if (delegate_.get()) | 2990 if (delegate_.get()) |
3048 delegate_->NotifyVisitDBObserversOnAddVisit(info); | 2991 delegate_->NotifyVisitDBObserversOnAddVisit(info); |
3049 } | 2992 } |
3050 | 2993 |
3051 } // namespace history | 2994 } // namespace history |
OLD | NEW |