| 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 faf00c6db8293356065862bd9fdc5e72a72ba4c8..5a7fb5f58caa96edc743fb2286dc96f437121d5e 100644
|
| --- a/components/history/core/browser/history_backend.cc
|
| +++ b/components/history/core/browser/history_backend.cc
|
| @@ -1588,9 +1588,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;
|
| @@ -1674,6 +1676,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;
|
| @@ -1701,6 +1704,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;
|
| @@ -1717,8 +1721,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();
|
| }
|
|
|
| @@ -1731,29 +1743,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();
|
| }
|
|
|
| @@ -1779,7 +1794,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 =
|
| @@ -1813,7 +1828,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(
|
| @@ -1821,7 +1836,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);
|
| }
|
| }
|
| }
|
| @@ -1829,7 +1844,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>());
|
| }
|
| }
|
|
|
| @@ -2158,11 +2173,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;
|
| @@ -2445,9 +2467,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,
|
|
|