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

Unified Diff: chrome/browser/history/history_backend.h

Issue 10802066: Adds support for saving favicon size into history database. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/history/history.cc ('k') | chrome/browser/history/history_backend.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/history/history_backend.h
diff --git a/chrome/browser/history/history_backend.h b/chrome/browser/history/history_backend.h
index 1bea48930eee146b956f0d45b60b95d3b51c673b..4346d82fe65b85f7b3ec0ff61596fb532723e2e5 100644
--- a/chrome/browser/history/history_backend.h
+++ b/chrome/browser/history/history_backend.h
@@ -23,6 +23,7 @@
#include "chrome/browser/history/visit_tracker.h"
#include "chrome/browser/search_engines/template_url_id.h"
#include "sql/init_status.h"
+#include "ui/base/layout.h"
class BookmarkService;
class TestingProfile;
@@ -248,29 +249,42 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
// Favicon -------------------------------------------------------------------
- void GetFavicon(scoped_refptr<GetFaviconRequest> request,
- const GURL& icon_url,
- int icon_types);
+ void GetFavicons(scoped_refptr<GetFaviconRequest> request,
+ const std::vector<GURL>& icon_urls,
+ int icon_types,
+ int desired_size_in_dip,
+ const std::vector<ui::ScaleFactor>& desired_scale_factors);
- void GetFaviconForURL(scoped_refptr<GetFaviconRequest> request,
- const GURL& page_url,
- int icon_types);
+ void GetFaviconsForURL(
+ scoped_refptr<GetFaviconRequest> request,
+ const GURL& page_url,
+ int icon_types,
+ int desired_size_in_dip,
+ const std::vector<ui::ScaleFactor>& desired_scale_factors);
- void GetFaviconForID(scoped_refptr<GetFaviconRequest> request, FaviconID id);
+ void GetFaviconForID(
+ scoped_refptr<GetFaviconRequest> request,
+ FaviconID favicon_id,
+ int desired_size_in_dip,
+ ui::ScaleFactor desired_scale_factor);
- void SetFavicon(const GURL& page_url,
- const GURL& icon_url,
- scoped_refptr<base::RefCountedMemory> data,
- IconType icon_type);
+ void UpdateFaviconMappingsAndFetch(
+ scoped_refptr<GetFaviconRequest> request,
+ const GURL& page_url,
+ const std::vector<GURL>& icon_urls,
+ int icon_types,
+ int desired_size_in_dip,
+ const std::vector<ui::ScaleFactor>& desired_scale_factors);
- void UpdateFaviconMappingAndFetch(scoped_refptr<GetFaviconRequest> request,
- const GURL& page_url,
- const GURL& icon_url,
- IconType icon_type);
+ void SetFavicons(
+ const GURL& page_url,
+ IconType icon_type,
+ const std::vector<FaviconBitmapData>& favicon_bitmap_data,
+ const IconURLSizesMap& icon_url_sizes);
- void SetFaviconOutOfDateForPage(const GURL& page_url);
+ void SetFaviconsOutOfDateForPage(const GURL& page_url);
- void CloneFavicon(const GURL& old_page_url, const GURL& new_page_url);
+ void CloneFavicons(const GURL& old_page_url, const GURL& new_page_url);
void SetImportedFavicons(
const std::vector<ImportedFaviconUsage>& favicon_usage);
@@ -459,15 +473,30 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, AddPageVisitSource);
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, AddPageArgsSource);
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, AddVisitsSource);
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetMostRecentVisits);
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, RemoveVisitsSource);
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, RemoveVisitsTransitions);
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MigrationVisitSource);
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MigrationIconMapping);
- FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, SetFaviconMapping);
- FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, AddOrUpdateIconMapping);
- FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, SetSameFaviconURLForTwoPages);
- FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetMostRecentVisits);
- FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetFaviconForURL);
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest,
+ SetFaviconMappingsForPageAndRedirects);
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest,
+ SetFaviconMappingsForPageDuplicates);
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, SetFavicons);
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest,
+ SetFaviconsSameFaviconURLForTwoPages);
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, SetFaviconsDeleteBitmaps);
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, SetFaviconsReplaceBitmapData);
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest,
+ UpdateFaviconMappingsAndFetchMultipleIconTypes);
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetFaviconsFromDBEmpty);
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest,
+ GetFaviconsFromDBNoFaviconBitmaps);
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest,
+ GetFaviconsFromDBSelectClosestMatch);
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetFaviconsFromDBSingleIconURL);
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetFaviconsFromDBIconType);
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetFaviconsFromDBExpired);
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest,
CloneFaviconIsRestrictedToSameDomain);
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, QueryFilteredURLs);
@@ -579,32 +608,110 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
// Favicons ------------------------------------------------------------------
- // Used by both UpdateFaviconMappingAndFetch and GetFavicon.
- // If page_url is non-null and SetFavicon has previously been invoked for
- // icon_url the favicon url for page_url (and all redirects) is set to
- // icon_url.
- // Only a single type can be given in icon_type when page_url is specified.
- void UpdateFaviconMappingAndFetchImpl(
- const GURL* page_url,
- const GURL& icon_url,
+ // Used by both UpdateFaviconMappingsAndFetch and GetFavicons.
+ // If |page_url| is non-null, the icon urls for |page_url| (and all
+ // redirects) are set to the subset of |icon_urls| for which icons are
+ // already stored in the database.
+ // If |page_url| is non-null, |icon_types| can be multiple icon types
+ // only if |icon_types| == TOUCH_ICON | TOUCH_PRECOMPOSED_ICON.
+ // If multiple icon types are specified, |page_url| will be mapped to the
+ // icon URLs of the largest type available in the database.
+ void UpdateFaviconMappingsAndFetchImpl(
scoped_refptr<GetFaviconRequest> request,
- int icon_type);
-
- // Sets the favicon url id for page_url to id. This will also broadcast
- // notifications as necessary.
- void SetFaviconMapping(const GURL& page_url,
- FaviconID id,
- IconType icon_type);
-
- // Updates the FaviconID associated with the url of a page. If there is an
- // existing mapping between |page_url| and |id| this does nothing and returns
- // false. If the mapping needs to be added or updated, true is returned. If
- // there is an existing mapping but it does not map to |id|, then the |id| of
- // the replaced FaviconID is set in |replaced_icon_id|.
- bool AddOrUpdateIconMapping(const GURL& page_url,
- FaviconID id,
- IconType icon_type,
- FaviconID* replaced_icon_id);
+ const GURL* page_url,
+ const std::vector<GURL>& icon_urls,
+ int icon_types,
+ int desired_size_in_dip,
+ const std::vector<ui::ScaleFactor>& desired_scale_factors);
+
+ // Set the favicon bitmaps for |icon_id|.
+ // For each entry in |favicon_bitmap_data|, if a favicon bitmap already
+ // exists at the entry's pixel size, replace the favicon bitmap's data with
+ // the entry's bitmap data. Otherwise add a new favicon bitmap.
+ void SetFaviconBitmaps(
+ FaviconID icon_id,
+ const std::vector<FaviconBitmapData>& favicon_bitmap_data);
+
+ // Returns true if |favicon_bitmap_data| and |icon_url_sizes| passed to
+ // SetFavicons() are valid.
+ // Criteria:
+ // 1) |icon_url_sizes| contains no more than
+ // kMaxFaviconsPerPage icon URLs.
+ // kMaxFaviconBitmapsPerIconURL favicon sizes for each icon URL.
+ // 2) The icon URLs and favicon sizes of |favicon_bitmap_data| are a subset
+ // of |icon_url_sizes|.
+ // 3) The favicon sizes for entries in |icon_url_sizes| which have associated
+ // data in |favicon_bitmap_data| is not history::GetDefaultFaviconSizes().
+ // 4) FaviconBitmapData::bitmap_data contains non NULL bitmap data.
+ bool ValidateSetFaviconsParams(
+ const std::vector<FaviconBitmapData>& favicon_bitmap_data,
+ const IconURLSizesMap& icon_url_sizes) const;
+
+ // Sets the sizes that the thumbnail database knows that the favicon at
+ // |icon_id| is available from the web. See history_types.h for a more
+ // detailed description of FaviconSizes.
+ // Deletes any favicon bitmaps currently mapped to |icon_id| whose pixel
+ // sizes are not contained in |favicon_sizes|.
+ void SetFaviconSizes(FaviconID icon_id, const FaviconSizes& favicon_sizes);
+
+ // Returns true if there are favicons for |page_url| and one of the types in
+ // |icon_types|.
+ // |favicon_bitmap_results| is set to the favicon bitmaps which most closely
+ // match |desired_size_in_dip| and |desired_scale_factors|. If
+ // |desired_size_in_dip| is 0, the largest favicon bitmap with one of the icon
+ // types in |icon_types| is returned. If |icon_types| contains multiple icon
+ // types and there are several matched icon types in the database, results
+ // will only be returned for a single icon type in the priority of
+ // TOUCH_PRECOMPOSED_ICON, TOUCH_ICON, and FAVICON. See the comment for
+ // GetFaviconResultsForBestMatch() for more details on how
+ // |favicon_bitmap_results| is constructed.
+ // |icon_url_sizes| is set to a mapping of all the icon URLs which are mapped
+ // to |page_url| to the sizes of the favicon bitmaps available at each icon
+ // URL on the web.
+ bool GetFaviconsFromDB(
+ const GURL& page_url,
+ int icon_types,
+ const int desired_size_in_dip,
+ const std::vector<ui::ScaleFactor>& desired_scale_factors,
+ std::vector<FaviconBitmapResult>* favicon_bitmap_results,
+ IconURLSizesMap* icon_url_sizes);
+
+ // Returns the favicon bitmaps which most closely match |desired_size_in_dip|
+ // and |desired_scale_factors| in |favicon_bitmap_results|. If
+ // |desired_size_in_dip| is 0, only the largest favicon bitmap is returned.
+ // Goodness is computed via SelectFaviconBitmapIDs(). It is computed on a
+ // per favicon id basis, thus all |favicon_bitmap_results| are guaranteed to
+ // be for the same FaviconID. |favicon_bitmap_results| will have at most one
+ // entry for each desired scale factor. There will be less entries if the same
+ // favicon bitmap is the best result for multiple scale factors.
+ // Returns true if there were no errors.
+ bool GetFaviconBitmapResultsForBestMatch(
+ const std::vector<FaviconID>& candidate_favicon_ids,
+ int desired_size_in_dip,
+ const std::vector<ui::ScaleFactor>& desired_scale_factors,
+ std::vector<FaviconBitmapResult>* favicon_bitmap_results);
+
+ // Build mapping of the icon URLs for |favicon_ids| to the sizes of the
+ // favicon bitmaps available at each icon URL on the web. Favicon bitmaps
+ // might not be cached in the thumbnail database for any of the sizes in the
+ // returned map. See history_types.h for a more detailed description of
+ // IconURLSizesMap.
+ // Returns true if map was successfully built.
+ bool BuildIconURLSizesMap(const std::vector<FaviconID>& favicon_ids,
+ IconURLSizesMap* icon_url_sizes);
+
+ // Maps the favicon ids in |icon_ids| to |page_url| (and all redirects)
+ // for |icon_type|. This will also broadcast notifications as necessary.
+ void SetFaviconMappingsForPageAndRedirects(
+ const GURL& page_url,
+ IconType icon_type,
+ const std::vector<FaviconID>& icon_ids);
+
+ // Maps the favicon ids in |icon_ids| to |page_url| for |icon_type|.
+ // Returns true if the function changed some of |page_url|'s mappings.
+ bool SetFaviconMappingsForPage(const GURL& page_url,
+ IconType icon_type,
+ const std::vector<FaviconID>& icon_ids);
// Generic stuff -------------------------------------------------------------
@@ -648,19 +755,6 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
// NULL during testing.
BookmarkService* GetBookmarkService();
- // If there is a favicon for |page_url| and one of the types in |icon_types|,
- // |favicon| is set appropriately and true is returned.
- bool GetFaviconFromDB(
- const GURL& page_url,
- int icon_types,
- std::vector<FaviconBitmapResult>* favicon_bitmap_results);
-
- // Get favicon by the given |favicon_id|, the |favicon| is set appropriately
- // and true if returned on success, otherwise false is returned.
- bool GetFaviconFromDB(
- FaviconID favicon_id,
- std::vector<FaviconBitmapResult>* favicon_bitmap_results);
-
// Notify any observers of an addition to the visit database.
void NotifyVisitObservers(const VisitRow& visit);
« no previous file with comments | « chrome/browser/history/history.cc ('k') | chrome/browser/history/history_backend.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698