Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(759)

Side by Side Diff: components/history/core/browser/history_backend.cc

Issue 2891333002: Introduce dedicated enum value for icons from Web Manifests (Closed)
Patch Set: Put browsertest behind #if. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/history/core/browser/history_backend.h" 5 #include "components/history/core/browser/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 2099 matching lines...) Expand 10 before | Expand all | Expand 10 after
2110 return mappings_changed; 2110 return mappings_changed;
2111 } 2111 }
2112 2112
2113 bool HistoryBackend::SetFaviconMappingsForPage( 2113 bool HistoryBackend::SetFaviconMappingsForPage(
2114 const GURL& page_url, 2114 const GURL& page_url,
2115 favicon_base::IconType icon_type, 2115 favicon_base::IconType icon_type,
2116 const std::vector<favicon_base::FaviconID>& icon_ids) { 2116 const std::vector<favicon_base::FaviconID>& icon_ids) {
2117 DCHECK_LE(icon_ids.size(), kMaxFaviconsPerPage); 2117 DCHECK_LE(icon_ids.size(), kMaxFaviconsPerPage);
2118 bool mappings_changed = false; 2118 bool mappings_changed = false;
2119 2119
2120 // Two icon types are considered 'equivalent' if one of the icon types is 2120 // Two icon types are considered 'equivalent' if both types are one of
2121 // TOUCH_ICON and the other is TOUCH_PRECOMPOSED_ICON. 2121 // TOUCH_ICON, TOUCH_PRECOMPOSED_ICON or WEB_MANIFEST_ICON.
2122 // 2122 const int equivalent_types = favicon_base::TOUCH_ICON |
2123 favicon_base::TOUCH_PRECOMPOSED_ICON |
2124 favicon_base::WEB_MANIFEST_ICON;
2125
2123 // Sets the icon mappings from |page_url| for |icon_type| to the favicons 2126 // Sets the icon mappings from |page_url| for |icon_type| to the favicons
2124 // with |icon_ids|. Mappings for |page_url| to favicons of type |icon_type| 2127 // with |icon_ids|. Mappings for |page_url| to favicons of type |icon_type|
2125 // whose FaviconID is not in |icon_ids| are removed. All icon mappings for 2128 // whose FaviconID is not in |icon_ids| are removed. All icon mappings for
2126 // |page_url| to favicons of a type equivalent to |icon_type| are removed. 2129 // |page_url| to favicons of a type equivalent to |icon_type| are removed.
2127 // Remove any favicons which are orphaned as a result of the removal of the 2130 // Remove any favicons which are orphaned as a result of the removal of the
2128 // icon mappings. 2131 // icon mappings.
2129 2132
2130 std::vector<favicon_base::FaviconID> unmapped_icon_ids = icon_ids; 2133 std::vector<favicon_base::FaviconID> unmapped_icon_ids = icon_ids;
2131 2134
2132 std::vector<IconMapping> icon_mappings; 2135 std::vector<IconMapping> icon_mappings;
2133 thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings); 2136 thumbnail_db_->GetIconMappingsForPageURL(page_url, &icon_mappings);
2134 2137
2135 for (std::vector<IconMapping>::iterator m = icon_mappings.begin(); 2138 for (std::vector<IconMapping>::iterator m = icon_mappings.begin();
2136 m != icon_mappings.end(); ++m) { 2139 m != icon_mappings.end(); ++m) {
2137 std::vector<favicon_base::FaviconID>::iterator icon_id_it = std::find( 2140 std::vector<favicon_base::FaviconID>::iterator icon_id_it = std::find(
2138 unmapped_icon_ids.begin(), unmapped_icon_ids.end(), m->icon_id); 2141 unmapped_icon_ids.begin(), unmapped_icon_ids.end(), m->icon_id);
2139 2142
2140 // If the icon mapping already exists, avoid removing it and adding it back. 2143 // If the icon mapping already exists, avoid removing it and adding it back.
2141 if (icon_id_it != unmapped_icon_ids.end()) { 2144 if (icon_id_it != unmapped_icon_ids.end()) {
2142 unmapped_icon_ids.erase(icon_id_it); 2145 unmapped_icon_ids.erase(icon_id_it);
2143 continue; 2146 continue;
2144 } 2147 }
2145 2148
2146 if ((icon_type == favicon_base::TOUCH_ICON && 2149 if (icon_type == m->icon_type || ((icon_type & equivalent_types) != 0 &&
2147 m->icon_type == favicon_base::TOUCH_PRECOMPOSED_ICON) || 2150 (m->icon_type & equivalent_types) != 0)) {
2148 (icon_type == favicon_base::TOUCH_PRECOMPOSED_ICON &&
2149 m->icon_type == favicon_base::TOUCH_ICON) ||
2150 (icon_type == m->icon_type)) {
2151 thumbnail_db_->DeleteIconMapping(m->mapping_id); 2151 thumbnail_db_->DeleteIconMapping(m->mapping_id);
2152 2152
2153 // Removing the icon mapping may have orphaned the associated favicon so 2153 // Removing the icon mapping may have orphaned the associated favicon so
2154 // we must recheck it. This is not super fast, but this case will get 2154 // we must recheck it. This is not super fast, but this case will get
2155 // triggered rarely, since normally a page will always map to the same 2155 // triggered rarely, since normally a page will always map to the same
2156 // favicon IDs. It will mostly happen for favicons we import. 2156 // favicon IDs. It will mostly happen for favicons we import.
2157 if (!thumbnail_db_->HasMappingFor(m->icon_id)) 2157 if (!thumbnail_db_->HasMappingFor(m->icon_id))
2158 thumbnail_db_->DeleteFavicon(m->icon_id); 2158 thumbnail_db_->DeleteFavicon(m->icon_id);
2159 mappings_changed = true; 2159 mappings_changed = true;
2160 } 2160 }
(...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after
2636 // transaction is currently open. 2636 // transaction is currently open.
2637 db_->CommitTransaction(); 2637 db_->CommitTransaction();
2638 db_->Vacuum(); 2638 db_->Vacuum();
2639 db_->BeginTransaction(); 2639 db_->BeginTransaction();
2640 db_->GetStartDate(&first_recorded_time_); 2640 db_->GetStartDate(&first_recorded_time_);
2641 2641
2642 return true; 2642 return true;
2643 } 2643 }
2644 2644
2645 } // namespace history 2645 } // namespace history
OLDNEW
« no previous file with comments | « components/favicon_base/favicon_types.h ('k') | components/history/core/browser/history_backend_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698