Index: components/history/core/browser/history_backend.cc |
diff --git a/components/history/core/browser/history_backend.cc b/components/history/core/browser/history_backend.cc |
index 1110993c583f546d0b84c1d245aedc01a06cab74..0f39d0c8f715abce353b76fd8f56fc7ff97fab64 100644 |
--- a/components/history/core/browser/history_backend.cc |
+++ b/components/history/core/browser/history_backend.cc |
@@ -1599,9 +1599,11 @@ void HistoryBackend::MergeFavicon( |
favicon_base::FaviconID favicon_id = |
thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type, nullptr); |
+ bool favicon_created = false; |
if (!favicon_id) { |
// There is no favicon at |icon_url|, create it. |
favicon_id = thumbnail_db_->AddFavicon(icon_url, icon_type); |
+ favicon_created = true; |
} |
std::vector<FaviconBitmapIDSize> bitmap_id_sizes; |
@@ -1689,6 +1691,7 @@ void HistoryBackend::MergeFavicon( |
// Copy the favicon bitmaps mapped to |page_url| to the favicon at |icon_url| |
// till the limit of |kMaxFaviconBitmapsPerIconURL| is reached. |
+ bool favicon_bitmaps_copied = false; |
for (size_t i = 0; i < icon_mappings.size(); ++i) { |
if (favicon_sizes.size() >= kMaxFaviconBitmapsPerIconURL) |
break; |
@@ -1716,6 +1719,7 @@ void HistoryBackend::MergeFavicon( |
favicon_id, bitmaps_to_copy[j].bitmap_data, base::Time(), |
bitmaps_to_copy[j].pixel_size); |
favicon_sizes.push_back(bitmaps_to_copy[j].pixel_size); |
+ favicon_bitmaps_copied = true; |
if (favicon_sizes.size() >= kMaxFaviconBitmapsPerIconURL) |
break; |
@@ -1732,8 +1736,16 @@ void HistoryBackend::MergeFavicon( |
mapping_changed = true; |
} |
- if (mapping_changed || !bitmap_identical) |
+ if (mapping_changed) |
SendFaviconChangedNotificationForPageAndRedirects(page_url); |
+ |
+ if (!favicon_created && (!bitmap_identical || favicon_bitmaps_copied)) { |
+ // If there was a favicon at |icon_url| prior to MergeFavicon() being |
+ // called, there may be page URLs which also use the favicon at |icon_url|. |
+ // Notify the UI that the favicon has changed for |icon_url|. |
+ SendFaviconChangedNotificationForIconURL(icon_url); |
+ } |
+ |
ScheduleCommit(); |
} |
@@ -1746,29 +1758,32 @@ void HistoryBackend::SetFavicons(const GURL& page_url, |
DCHECK_GE(kMaxFaviconBitmapsPerIconURL, bitmaps.size()); |
- // Track whether the method modifies or creates any favicon bitmaps, favicons |
- // or icon mappings. |
- bool data_modified = false; |
- |
favicon_base::FaviconID icon_id = |
thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type, nullptr); |
+ bool favicon_created = false; |
if (!icon_id) { |
icon_id = thumbnail_db_->AddFavicon(icon_url, icon_type); |
- data_modified = true; |
+ favicon_created = true; |
} |
- data_modified |= SetFaviconBitmaps(icon_id, bitmaps); |
+ bool favicon_data_modified = SetFaviconBitmaps(icon_id, bitmaps); |
std::vector<favicon_base::FaviconID> icon_ids(1u, icon_id); |
- data_modified |= |
+ bool mapping_changed = |
SetFaviconMappingsForPageAndRedirects(page_url, icon_type, icon_ids); |
- if (data_modified) { |
- // Send notification to the UI as an icon mapping, favicon, or favicon |
- // bitmap was changed by this function. |
+ if (mapping_changed) { |
+ // Notify the UI that this function changed an icon mapping. |
SendFaviconChangedNotificationForPageAndRedirects(page_url); |
} |
+ |
+ if (favicon_data_modified && !favicon_created) { |
+ // If there was a favicon at |icon_url| prior to SetFavicons() being called, |
+ // there may be page URLs which also use the favicon at |icon_url|. Notify |
+ // the UI that the favicon has changed for |icon_url|. |
+ SendFaviconChangedNotificationForIconURL(icon_url); |
+ } |
ScheduleCommit(); |
} |
@@ -1794,7 +1809,7 @@ void HistoryBackend::SetImportedFavicons( |
Time now = Time::Now(); |
// Track all URLs that had their favicons set or updated. |
- std::set<GURL> favicons_changed; |
+ std::vector<GURL> favicons_changed; |
for (size_t i = 0; i < favicon_usage.size(); i++) { |
favicon_base::FaviconID favicon_id = |
@@ -1828,7 +1843,7 @@ void HistoryBackend::SetImportedFavicons( |
url_info.set_hidden(false); |
db_->AddURL(url_info); |
thumbnail_db_->AddIconMapping(*url, favicon_id); |
- favicons_changed.insert(*url); |
+ favicons_changed.push_back(*url); |
} |
} else { |
if (!thumbnail_db_->GetIconMappingsForPageURL( |
@@ -1836,7 +1851,7 @@ void HistoryBackend::SetImportedFavicons( |
// URL is present in history, update the favicon *only* if it is not |
// set already. |
thumbnail_db_->AddIconMapping(*url, favicon_id); |
- favicons_changed.insert(*url); |
+ favicons_changed.push_back(*url); |
} |
} |
} |
@@ -1844,7 +1859,7 @@ void HistoryBackend::SetImportedFavicons( |
if (!favicons_changed.empty()) { |
// Send the notification about the changed favicon URLs. |
- NotifyFaviconChanged(favicons_changed); |
+ NotifyFaviconsChanged(favicons_changed, std::vector<GURL>()); |
} |
} |
@@ -2173,11 +2188,18 @@ void HistoryBackend::SendFaviconChangedNotificationForPageAndRedirects( |
RedirectList redirect_list; |
GetCachedRecentRedirects(page_url, &redirect_list); |
if (!redirect_list.empty()) { |
- std::set<GURL> favicons_changed(redirect_list.begin(), redirect_list.end()); |
- NotifyFaviconChanged(favicons_changed); |
+ std::vector<GURL> favicons_changed(redirect_list.begin(), |
+ redirect_list.end()); |
+ NotifyFaviconsChanged(favicons_changed, std::vector<GURL>()); |
} |
} |
+void HistoryBackend::SendFaviconChangedNotificationForIconURL( |
+ const GURL& icon_url) { |
+ NotifyFaviconsChanged(std::vector<GURL>(), |
+ std::vector<GURL>(1u, icon_url)); |
+} |
+ |
void HistoryBackend::Commit() { |
if (!db_) |
return; |
@@ -2460,9 +2482,10 @@ void HistoryBackend::ProcessDBTask( |
ProcessDBTaskImpl(); |
} |
-void HistoryBackend::NotifyFaviconChanged(const std::set<GURL>& urls) { |
+void HistoryBackend::NotifyFaviconsChanged(const std::vector<GURL>& page_urls, |
+ const std::vector<GURL>& icon_urls) { |
if (delegate_) |
- delegate_->NotifyFaviconChanged(urls); |
+ delegate_->NotifyFaviconsChanged(page_urls, icon_urls); |
} |
void HistoryBackend::NotifyURLVisited(ui::PageTransition transition, |