diff options
Diffstat (limited to 'chromium/components/history/core/browser/history_backend.cc')
-rw-r--r-- | chromium/components/history/core/browser/history_backend.cc | 92 |
1 files changed, 34 insertions, 58 deletions
diff --git a/chromium/components/history/core/browser/history_backend.cc b/chromium/components/history/core/browser/history_backend.cc index dd82dc44197..14855781aac 100644 --- a/chromium/components/history/core/browser/history_backend.cc +++ b/chromium/components/history/core/browser/history_backend.cc @@ -219,7 +219,7 @@ void HistoryBackend::Init( delegate_->DBLoaded(); if (base::FeatureList::IsEnabled(switches::kSyncUSSTypedURL)) { typed_url_sync_bridge_ = base::MakeUnique<TypedURLSyncBridge>( - this, + this, db_.get(), base::BindRepeating( &ModelTypeChangeProcessor::Create, // TODO(gangwu): use ReportUnrecoverableError before launch. @@ -1424,13 +1424,13 @@ void HistoryBackend::DeleteFTSIndexDatabases() { num_databases_deleted); } -void HistoryBackend::GetFavicons( - const std::vector<GURL>& icon_urls, - int icon_types, +void HistoryBackend::GetFavicon( + const GURL& icon_url, + favicon_base::IconType icon_type, const std::vector<int>& desired_sizes, std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { - UpdateFaviconMappingsAndFetchImpl(nullptr, icon_urls, icon_types, - desired_sizes, bitmap_results); + UpdateFaviconMappingsAndFetchImpl(nullptr, icon_url, icon_type, desired_sizes, + bitmap_results); } void HistoryBackend::GetLargestFaviconForURL( @@ -1562,11 +1562,11 @@ void HistoryBackend::GetFaviconForID( void HistoryBackend::UpdateFaviconMappingsAndFetch( const GURL& page_url, - const std::vector<GURL>& icon_urls, - int icon_types, + const GURL& icon_url, + favicon_base::IconType icon_type, const std::vector<int>& desired_sizes, std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { - UpdateFaviconMappingsAndFetchImpl(&page_url, icon_urls, icon_types, + UpdateFaviconMappingsAndFetchImpl(&page_url, icon_url, icon_type, desired_sizes, bitmap_results); } @@ -1580,7 +1580,7 @@ void HistoryBackend::MergeFavicon( return; favicon_base::FaviconID favicon_id = - thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type, nullptr); + thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type); bool favicon_created = false; if (!favicon_id) { @@ -1780,8 +1780,8 @@ void HistoryBackend::SetImportedFavicons( for (size_t i = 0; i < favicon_usage.size(); i++) { favicon_base::FaviconID favicon_id = - thumbnail_db_->GetFaviconIDForFaviconURL( - favicon_usage[i].favicon_url, favicon_base::FAVICON, nullptr); + thumbnail_db_->GetFaviconIDForFaviconURL(favicon_usage[i].favicon_url, + favicon_base::FAVICON); if (!favicon_id) { // This favicon doesn't exist yet, so we create it using the given data. // TODO(pkotwicz): Pass in real pixel size. @@ -1840,7 +1840,7 @@ bool HistoryBackend::SetFaviconsImpl(const GURL& page_url, DCHECK_GE(kMaxFaviconBitmapsPerIconURL, bitmaps.size()); favicon_base::FaviconID icon_id = - thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type, nullptr); + thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type); bool favicon_created = false; if (!icon_id) { @@ -1876,17 +1876,10 @@ bool HistoryBackend::SetFaviconsImpl(const GURL& page_url, void HistoryBackend::UpdateFaviconMappingsAndFetchImpl( const GURL* page_url, - const std::vector<GURL>& icon_urls, - int icon_types, + const GURL& icon_url, + favicon_base::IconType icon_type, const std::vector<int>& desired_sizes, std::vector<favicon_base::FaviconRawBitmapResult>* bitmap_results) { - // If |page_url| is specified, |icon_types| must be either a single icon - // type or icon types which are equivalent. - DCHECK(!page_url || icon_types == favicon_base::FAVICON || - icon_types == favicon_base::TOUCH_ICON || - icon_types == favicon_base::TOUCH_PRECOMPOSED_ICON || - icon_types == - (favicon_base::TOUCH_ICON | favicon_base::TOUCH_PRECOMPOSED_ICON)); bitmap_results->clear(); if (!thumbnail_db_) { @@ -1895,33 +1888,14 @@ void HistoryBackend::UpdateFaviconMappingsAndFetchImpl( std::vector<favicon_base::FaviconID> favicon_ids; - // The icon type for which the mappings will the updated and data will be - // returned. - favicon_base::IconType selected_icon_type = favicon_base::INVALID_ICON; - - for (size_t i = 0; i < icon_urls.size(); ++i) { - const GURL& icon_url = icon_urls[i]; - favicon_base::IconType icon_type_out; - const favicon_base::FaviconID favicon_id = - thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_types, - &icon_type_out); - - if (favicon_id) { - // Return and update icon mappings only for the largest icon type. As - // |icon_urls| is not sorted in terms of icon type, clear |favicon_ids| - // if an |icon_url| with a larger icon type is found. - if (icon_type_out > selected_icon_type) { - selected_icon_type = icon_type_out; - favicon_ids.clear(); - } - if (icon_type_out == selected_icon_type) - favicon_ids.push_back(favicon_id); - } - } + const favicon_base::FaviconID favicon_id = + thumbnail_db_->GetFaviconIDForFaviconURL(icon_url, icon_type); + if (favicon_id) + favicon_ids.push_back(favicon_id); if (page_url && !favicon_ids.empty()) { bool mappings_updated = SetFaviconMappingsForPageAndRedirects( - *page_url, selected_icon_type, favicon_ids); + *page_url, icon_type, favicon_ids); if (mappings_updated) { SendFaviconChangedNotificationForPageAndRedirects(*page_url); ScheduleCommit(); @@ -2064,7 +2038,8 @@ bool HistoryBackend::GetFaviconBitmapResultsForBestMatch( &score); if (score > highest_score) { highest_score = score; - best_favicon_id = candidate_favicon_ids[i], best_bitmap_ids.clear(); + best_favicon_id = candidate_favicon_ids[i]; + best_bitmap_ids.clear(); for (size_t j = 0; j < candidate_bitmap_indices.size(); ++j) { size_t candidate_index = candidate_bitmap_indices[j]; best_bitmap_ids.push_back(bitmap_id_sizes[candidate_index].bitmap_id); @@ -2145,9 +2120,12 @@ bool HistoryBackend::SetFaviconMappingsForPage( DCHECK_LE(icon_ids.size(), kMaxFaviconsPerPage); bool mappings_changed = false; - // Two icon types are considered 'equivalent' if one of the icon types is - // TOUCH_ICON and the other is TOUCH_PRECOMPOSED_ICON. - // + // Two icon types are considered 'equivalent' if both types are one of + // TOUCH_ICON, TOUCH_PRECOMPOSED_ICON or WEB_MANIFEST_ICON. + const int equivalent_types = favicon_base::TOUCH_ICON | + favicon_base::TOUCH_PRECOMPOSED_ICON | + favicon_base::WEB_MANIFEST_ICON; + // Sets the icon mappings from |page_url| for |icon_type| to the favicons // with |icon_ids|. Mappings for |page_url| to favicons of type |icon_type| // whose FaviconID is not in |icon_ids| are removed. All icon mappings for @@ -2171,11 +2149,8 @@ bool HistoryBackend::SetFaviconMappingsForPage( continue; } - if ((icon_type == favicon_base::TOUCH_ICON && - m->icon_type == favicon_base::TOUCH_PRECOMPOSED_ICON) || - (icon_type == favicon_base::TOUCH_PRECOMPOSED_ICON && - m->icon_type == favicon_base::TOUCH_ICON) || - (icon_type == m->icon_type)) { + if (icon_type == m->icon_type || ((icon_type & equivalent_types) != 0 && + (m->icon_type & equivalent_types) != 0)) { thumbnail_db_->DeleteIconMapping(m->mapping_id); // Removing the icon mapping may have orphaned the associated favicon so @@ -2487,10 +2462,11 @@ base::SupportsUserData::Data* HistoryBackend::GetUserData( return supports_user_data_helper_->GetUserData(key); } -void HistoryBackend::SetUserData(const void* key, - base::SupportsUserData::Data* data) { +void HistoryBackend::SetUserData( + const void* key, + std::unique_ptr<base::SupportsUserData::Data> data) { DCHECK(supports_user_data_helper_); - supports_user_data_helper_->SetUserData(key, data); + supports_user_data_helper_->SetUserData(key, std::move(data)); } void HistoryBackend::ProcessDBTask( |