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 <list> | 8 #include <list> |
9 #include <map> | 9 #include <map> |
10 #include <set> | 10 #include <set> |
(...skipping 1835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1846 thumbnail_db_->GetFaviconBitmapIDSizes(icon_mappings[i].icon_id, | 1846 thumbnail_db_->GetFaviconBitmapIDSizes(icon_mappings[i].icon_id, |
1847 &bitmap_id_sizes); | 1847 &bitmap_id_sizes); |
1848 | 1848 |
1849 for (size_t j = 0; j < bitmap_id_sizes.size(); ++j) { | 1849 for (size_t j = 0; j < bitmap_id_sizes.size(); ++j) { |
1850 if (bitmap_id_sizes[j].pixel_size == pixel_size) { | 1850 if (bitmap_id_sizes[j].pixel_size == pixel_size) { |
1851 // There is a favicon bitmap of |pixel_size| already mapped to | 1851 // There is a favicon bitmap of |pixel_size| already mapped to |
1852 // |page_url|, replace it. | 1852 // |page_url|, replace it. |
1853 thumbnail_db_->SetFaviconBitmap(bitmap_id_sizes[j].bitmap_id, | 1853 thumbnail_db_->SetFaviconBitmap(bitmap_id_sizes[j].bitmap_id, |
1854 bitmap_data, base::Time::Now()); | 1854 bitmap_data, base::Time::Now()); |
1855 | 1855 |
1856 // TODO(pkotwicz): Investigate as to whether the UI should be notified. | 1856 // Send notification to the UI that the favicon bitmap was updated. |
| 1857 SendFaviconChangedNotificationForPageAndRedirects(page_url); |
1857 ScheduleCommit(); | 1858 ScheduleCommit(); |
1858 return; | 1859 return; |
1859 } | 1860 } |
1860 } | 1861 } |
1861 } | 1862 } |
1862 | 1863 |
1863 // There is no exact match for |pixel_size|. Create a new favicon with a fake | 1864 // There is no exact match for |pixel_size|. Create a new favicon with a fake |
1864 // icon URL. Use |page_url| as the fake icon URL as it is guaranteed to be | 1865 // icon URL. Use |page_url| as the fake icon URL as it is guaranteed to be |
1865 // unique. | 1866 // unique. |
1866 const GURL& fake_icon_url = page_url; | 1867 const GURL& fake_icon_url = page_url; |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1926 | 1927 |
1927 // Build map of FaviconBitmapData for each icon url. | 1928 // Build map of FaviconBitmapData for each icon url. |
1928 typedef std::map<GURL, std::vector<FaviconBitmapData> > | 1929 typedef std::map<GURL, std::vector<FaviconBitmapData> > |
1929 BitmapDataByIconURL; | 1930 BitmapDataByIconURL; |
1930 BitmapDataByIconURL grouped_by_icon_url; | 1931 BitmapDataByIconURL grouped_by_icon_url; |
1931 for (size_t i = 0; i < favicon_bitmap_data.size(); ++i) { | 1932 for (size_t i = 0; i < favicon_bitmap_data.size(); ++i) { |
1932 const GURL& icon_url = favicon_bitmap_data[i].icon_url; | 1933 const GURL& icon_url = favicon_bitmap_data[i].icon_url; |
1933 grouped_by_icon_url[icon_url].push_back(favicon_bitmap_data[i]); | 1934 grouped_by_icon_url[icon_url].push_back(favicon_bitmap_data[i]); |
1934 } | 1935 } |
1935 | 1936 |
1936 bool favicon_bitmap_added_or_removed = false; | |
1937 | |
1938 std::vector<FaviconID> icon_ids; | 1937 std::vector<FaviconID> icon_ids; |
1939 for (IconURLSizesMap::const_iterator it = icon_url_sizes.begin(); | 1938 for (IconURLSizesMap::const_iterator it = icon_url_sizes.begin(); |
1940 it != icon_url_sizes.end(); ++it) { | 1939 it != icon_url_sizes.end(); ++it) { |
1941 const GURL& icon_url = it->first; | 1940 const GURL& icon_url = it->first; |
1942 FaviconID icon_id = | 1941 FaviconID icon_id = |
1943 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type, NULL); | 1942 thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type, NULL); |
1944 if (icon_id) { | 1943 if (icon_id) |
1945 bool favicon_bitmap_removed = false; | 1944 SetFaviconSizes(icon_id, it->second); |
1946 SetFaviconSizes(icon_id, it->second, &favicon_bitmap_removed); | 1945 else |
1947 favicon_bitmap_added_or_removed |= favicon_bitmap_removed; | |
1948 } else { | |
1949 icon_id = thumbnail_db_->AddFavicon(icon_url, icon_type, it->second); | 1946 icon_id = thumbnail_db_->AddFavicon(icon_url, icon_type, it->second); |
1950 } | |
1951 icon_ids.push_back(icon_id); | 1947 icon_ids.push_back(icon_id); |
1952 | 1948 |
1953 BitmapDataByIconURL::iterator grouped_by_icon_url_it = | 1949 BitmapDataByIconURL::iterator grouped_by_icon_url_it = |
1954 grouped_by_icon_url.find(icon_url); | 1950 grouped_by_icon_url.find(icon_url); |
1955 if (grouped_by_icon_url_it != grouped_by_icon_url.end()) { | 1951 if (grouped_by_icon_url_it != grouped_by_icon_url.end()) |
1956 bool favicon_bitmap_added = false; | 1952 SetFaviconBitmaps(icon_id, grouped_by_icon_url_it->second); |
1957 SetFaviconBitmaps(icon_id, grouped_by_icon_url_it->second, | |
1958 &favicon_bitmap_added); | |
1959 favicon_bitmap_added_or_removed |= favicon_bitmap_added; | |
1960 } | |
1961 } | 1953 } |
1962 | 1954 |
1963 bool mappings_changed = | 1955 SetFaviconMappingsForPageAndRedirects(page_url, icon_type, icon_ids); |
1964 SetFaviconMappingsForPageAndRedirects(page_url, icon_type, icon_ids); | |
1965 | 1956 |
1966 // Send notification to the UI if icon mappings, favicons, or favicon bitmaps | 1957 // Send notification to the UI as an icon mapping, favicon, or favicon bitmap |
1967 // were added or removed. Favicon addition and removal is not tracked as | 1958 // almost certainly was changed by this function. The situations where no |
1968 // adding or removing a favicon will always be accompanied by an update in | 1959 // data was changed, notably when |favicon_bitmap_data| is empty do not occur |
1969 // icon mappings. | 1960 // in practice. |
1970 // TODO(pkotwicz): Investigate if notifications should be sent when a favicon | 1961 SendFaviconChangedNotificationForPageAndRedirects(page_url); |
1971 // bitmap has been updated but not added or removed. | |
1972 if (mappings_changed || favicon_bitmap_added_or_removed) | |
1973 SendFaviconChangedNotificationForPageAndRedirects(page_url); | |
1974 ScheduleCommit(); | 1962 ScheduleCommit(); |
1975 } | 1963 } |
1976 | 1964 |
1977 void HistoryBackend::SetFaviconsOutOfDateForPage(const GURL& page_url) { | 1965 void HistoryBackend::SetFaviconsOutOfDateForPage(const GURL& page_url) { |
1978 std::vector<IconMapping> icon_mappings; | 1966 std::vector<IconMapping> icon_mappings; |
1979 | 1967 |
1980 if (!thumbnail_db_.get() || | 1968 if (!thumbnail_db_.get() || |
1981 !thumbnail_db_->GetIconMappingsForPageURL(page_url, | 1969 !thumbnail_db_->GetIconMappingsForPageURL(page_url, |
1982 &icon_mappings)) | 1970 &icon_mappings)) |
1983 return; | 1971 return; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2135 desired_scale_factors, &favicon_bitmap_results); | 2123 desired_scale_factors, &favicon_bitmap_results); |
2136 IconURLSizesMap icon_url_sizes; | 2124 IconURLSizesMap icon_url_sizes; |
2137 BuildIconURLSizesMap(favicon_ids, &icon_url_sizes); | 2125 BuildIconURLSizesMap(favicon_ids, &icon_url_sizes); |
2138 | 2126 |
2139 request->ForwardResult(request->handle(), favicon_bitmap_results, | 2127 request->ForwardResult(request->handle(), favicon_bitmap_results, |
2140 icon_url_sizes); | 2128 icon_url_sizes); |
2141 } | 2129 } |
2142 | 2130 |
2143 void HistoryBackend::SetFaviconBitmaps( | 2131 void HistoryBackend::SetFaviconBitmaps( |
2144 FaviconID icon_id, | 2132 FaviconID icon_id, |
2145 const std::vector<FaviconBitmapData>& favicon_bitmap_data, | 2133 const std::vector<FaviconBitmapData>& favicon_bitmap_data) { |
2146 bool* favicon_bitmap_added) { | |
2147 *favicon_bitmap_added = false; | |
2148 | |
2149 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; | 2134 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; |
2150 thumbnail_db_->GetFaviconBitmapIDSizes(icon_id, &bitmap_id_sizes); | 2135 thumbnail_db_->GetFaviconBitmapIDSizes(icon_id, &bitmap_id_sizes); |
2151 | 2136 |
2152 // A nested loop is ok because in practice neither |favicon_bitmap_data| nor | 2137 // A nested loop is ok because in practice neither |favicon_bitmap_data| nor |
2153 // |bitmap_id_sizes| will have many elements. | 2138 // |bitmap_id_sizes| will have many elements. |
2154 for (size_t i = 0; i < favicon_bitmap_data.size(); ++i) { | 2139 for (size_t i = 0; i < favicon_bitmap_data.size(); ++i) { |
2155 const FaviconBitmapData& bitmap_data_element = favicon_bitmap_data[i]; | 2140 const FaviconBitmapData& bitmap_data_element = favicon_bitmap_data[i]; |
2156 FaviconBitmapID bitmap_id = 0; | 2141 FaviconBitmapID bitmap_id = 0; |
2157 for (size_t j = 0; j < bitmap_id_sizes.size(); ++j) { | 2142 for (size_t j = 0; j < bitmap_id_sizes.size(); ++j) { |
2158 if (bitmap_id_sizes[j].pixel_size == bitmap_data_element.pixel_size) { | 2143 if (bitmap_id_sizes[j].pixel_size == bitmap_data_element.pixel_size) { |
2159 bitmap_id = bitmap_id_sizes[j].bitmap_id; | 2144 bitmap_id = bitmap_id_sizes[j].bitmap_id; |
2160 break; | 2145 break; |
2161 } | 2146 } |
2162 } | 2147 } |
2163 if (bitmap_id) { | 2148 if (bitmap_id) { |
2164 thumbnail_db_->SetFaviconBitmap(bitmap_id, | 2149 thumbnail_db_->SetFaviconBitmap(bitmap_id, |
2165 bitmap_data_element.bitmap_data, base::Time::Now()); | 2150 bitmap_data_element.bitmap_data, base::Time::Now()); |
2166 } else { | 2151 } else { |
2167 thumbnail_db_->AddFaviconBitmap(icon_id, bitmap_data_element.bitmap_data, | 2152 thumbnail_db_->AddFaviconBitmap(icon_id, bitmap_data_element.bitmap_data, |
2168 base::Time::Now(), bitmap_data_element.pixel_size); | 2153 base::Time::Now(), bitmap_data_element.pixel_size); |
2169 *favicon_bitmap_added = true; | |
2170 } | 2154 } |
2171 } | 2155 } |
2172 } | 2156 } |
2173 | 2157 |
2174 bool HistoryBackend::ValidateSetFaviconsParams( | 2158 bool HistoryBackend::ValidateSetFaviconsParams( |
2175 const std::vector<FaviconBitmapData>& favicon_bitmap_data, | 2159 const std::vector<FaviconBitmapData>& favicon_bitmap_data, |
2176 const IconURLSizesMap& icon_url_sizes) const { | 2160 const IconURLSizesMap& icon_url_sizes) const { |
2177 if (icon_url_sizes.size() > kMaxFaviconsPerPage) | 2161 if (icon_url_sizes.size() > kMaxFaviconsPerPage) |
2178 return false; | 2162 return false; |
2179 | 2163 |
(...skipping 14 matching lines...) Expand all Loading... |
2194 | 2178 |
2195 const FaviconSizes& favicon_sizes = it->second; | 2179 const FaviconSizes& favicon_sizes = it->second; |
2196 FaviconSizes::const_iterator it2 = std::find(favicon_sizes.begin(), | 2180 FaviconSizes::const_iterator it2 = std::find(favicon_sizes.begin(), |
2197 favicon_sizes.end(), favicon_bitmap_data[i].pixel_size); | 2181 favicon_sizes.end(), favicon_bitmap_data[i].pixel_size); |
2198 if (it2 == favicon_sizes.end()) | 2182 if (it2 == favicon_sizes.end()) |
2199 return false; | 2183 return false; |
2200 } | 2184 } |
2201 return true; | 2185 return true; |
2202 } | 2186 } |
2203 | 2187 |
2204 void HistoryBackend::SetFaviconSizes( | 2188 void HistoryBackend::SetFaviconSizes(FaviconID icon_id, |
2205 FaviconID icon_id, | 2189 const FaviconSizes& favicon_sizes) { |
2206 const FaviconSizes& favicon_sizes, | |
2207 bool* favicon_bitmap_removed) { | |
2208 *favicon_bitmap_removed = false; | |
2209 | |
2210 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; | 2190 std::vector<FaviconBitmapIDSize> bitmap_id_sizes; |
2211 thumbnail_db_->GetFaviconBitmapIDSizes(icon_id, &bitmap_id_sizes); | 2191 thumbnail_db_->GetFaviconBitmapIDSizes(icon_id, &bitmap_id_sizes); |
2212 | 2192 |
2213 // Remove bitmaps whose pixel size is not contained in |favicon_sizes|. | 2193 // Remove bitmaps whose pixel size is not contained in |favicon_sizes|. |
2214 for (size_t i = 0; i < bitmap_id_sizes.size(); ++i) { | 2194 for (size_t i = 0; i < bitmap_id_sizes.size(); ++i) { |
2215 const gfx::Size& pixel_size = bitmap_id_sizes[i].pixel_size; | 2195 const gfx::Size& pixel_size = bitmap_id_sizes[i].pixel_size; |
2216 FaviconSizes::const_iterator sizes_it = std::find(favicon_sizes.begin(), | 2196 FaviconSizes::const_iterator sizes_it = std::find(favicon_sizes.begin(), |
2217 favicon_sizes.end(), pixel_size); | 2197 favicon_sizes.end(), pixel_size); |
2218 if (sizes_it == favicon_sizes.end()) { | 2198 if (sizes_it == favicon_sizes.end()) |
2219 thumbnail_db_->DeleteFaviconBitmap(bitmap_id_sizes[i].bitmap_id); | 2199 thumbnail_db_->DeleteFaviconBitmap(bitmap_id_sizes[i].bitmap_id); |
2220 *favicon_bitmap_removed = true; | |
2221 } | |
2222 } | 2200 } |
2223 | 2201 |
2224 thumbnail_db_->SetFaviconSizes(icon_id, favicon_sizes); | 2202 thumbnail_db_->SetFaviconSizes(icon_id, favicon_sizes); |
2225 } | 2203 } |
2226 | 2204 |
2227 bool HistoryBackend::GetFaviconsFromDB( | 2205 bool HistoryBackend::GetFaviconsFromDB( |
2228 const GURL& page_url, | 2206 const GURL& page_url, |
2229 int icon_types, | 2207 int icon_types, |
2230 int desired_size_in_dip, | 2208 int desired_size_in_dip, |
2231 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 2209 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2841 info.url_id = visit.url_id; | 2819 info.url_id = visit.url_id; |
2842 info.time = visit.visit_time; | 2820 info.time = visit.visit_time; |
2843 info.transition = visit.transition; | 2821 info.transition = visit.transition; |
2844 // If we don't have a delegate yet during setup or shutdown, we will drop | 2822 // If we don't have a delegate yet during setup or shutdown, we will drop |
2845 // these notifications. | 2823 // these notifications. |
2846 if (delegate_.get()) | 2824 if (delegate_.get()) |
2847 delegate_->NotifyVisitDBObserversOnAddVisit(info); | 2825 delegate_->NotifyVisitDBObserversOnAddVisit(info); |
2848 } | 2826 } |
2849 | 2827 |
2850 } // namespace history | 2828 } // namespace history |
OLD | NEW |