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

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, 4 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
Index: chrome/browser/history/history_backend.h
diff --git a/chrome/browser/history/history_backend.h b/chrome/browser/history/history_backend.h
index a80c8e30a810794ffb287b53bf6956cd68e856b6..29d825366bc2193c9baa30ce9dc798c00d34758b 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;
@@ -249,28 +250,40 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
// Favicon -------------------------------------------------------------------
void GetFavicon(scoped_refptr<GetFaviconRequest> request,
- const GURL& icon_url,
- int icon_types);
+ const std::vector<GURL>& icon_urls,
+ int icon_types,
+ const gfx::Size& desired_dip_size,
+ const std::vector<ui::ScaleFactor>& desired_scale_factors);
- void GetFaviconForURL(scoped_refptr<GetFaviconRequest> request,
- const GURL& page_url,
- int icon_types);
+ void GetFaviconForURL(
+ scoped_refptr<GetFaviconRequest> request,
+ const GURL& page_url,
+ int icon_types,
+ const gfx::Size& desired_dip_size,
+ const std::vector<ui::ScaleFactor>& desired_scale_factors);
- void GetFaviconForID(scoped_refptr<GetFaviconRequest> request, FaviconID id);
+ void UpdateFaviconMappingsAndFetch(
+ scoped_refptr<GetFaviconRequest> request,
+ const GURL& page_url,
+ const std::vector<GURL>& icon_urls,
+ IconType icon_type,
+ const gfx::Size& desired_dip_size,
+ const std::vector<ui::ScaleFactor>& desired_scale_factors);
- void SetFavicon(const GURL& page_url,
- const GURL& icon_url,
- scoped_refptr<base::RefCountedMemory> data,
- IconType icon_type);
+ void AddFavicons(const GURL& page_url,
+ const GURL& icon_url,
+ IconType icon_type,
+ const std::vector<FaviconBitmapData>& favicon_bitmaps);
- void UpdateFaviconMappingAndFetch(scoped_refptr<GetFaviconRequest> request,
- const GURL& page_url,
- const GURL& icon_url,
- IconType icon_type);
+ void SetFavicons(const GURL& page_url,
+ const GURL& icon_url,
+ IconType icon_type,
+ const std::vector<FaviconBitmapData>& favicon_bitmaps,
+ 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);
@@ -442,6 +455,14 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
// code to avoid syncing visits that would immediately be expired).
virtual bool IsExpiredVisitTime(const base::Time& time);
+ // Set whether HistoryBackend::SetFavicon is cripled such that it can only be
+ // used to set favicon bitmaps of size 0 0 for a single URL.
+ // TODO(pkotwicz): Remove this restriction.
+ void set_single_favicon_bitmap_per_icon_type(
+ bool single_favicon_bitmap_per_icon_type) {
+ single_favicon_bitmap_per_icon_type_ = single_favicon_bitmap_per_icon_type;
+ }
+
protected:
virtual ~HistoryBackend();
@@ -463,10 +484,18 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
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,
+ SetFaviconMappingsForPageAndRedirects);
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest,
+ SetFaviconMappingsForPageDuplicates);
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, SetFavicons);
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, SetFaviconsDeleteBitmaps);
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, SetFaviconsReplaceBitmapData);
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetMostRecentVisits);
- FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetFaviconForURL);
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetFaviconsFromDB);
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetFaviconsFromDBExpired);
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetFaviconsFromDBIconType);
+ FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetFaviconsFromDBEmpty);
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest,
CloneFaviconIsRestrictedToSameDomain);
FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, QueryFilteredURLs);
@@ -578,32 +607,82 @@ 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.
+ // 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.
// Only a single type can be given in icon_type when page_url is specified.
- void UpdateFaviconMappingAndFetchImpl(
+ void UpdateFaviconMappingsAndFetchImpl(
const GURL* page_url,
- const GURL& icon_url,
+ const std::vector<GURL>& icon_urls,
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);
+ int icon_types,
+ const gfx::Size& desired_dip_size,
+ const std::vector<ui::ScaleFactor> desired_scale_factors);
+
+ // Set the favicon bitmaps for the favicon at |icon_id|.
+ void SetFaviconBitmaps(
+ FaviconID icon_id,
+ const std::vector<FaviconBitmapData>& favicon_bitmaps);
+
+ // Returns true if |elements| and |icon_url_sizes| passed to SetFavicons
+ // are valid.
+ bool ValidateSetFaviconsParams(
+ const std::vector<FaviconBitmapData>& favicon_bitmaps,
+ const IconURLSizesMap& icon_url_sizes) const;
+
+ // Sets the sizes that the thumbnail database knows that the favicon at
+ // |icon_id| is available at from the web. See history_types for a more
+ // in depth discussion about FaviconSizes.
+ void SetFaviconSizes(FaviconID icon_id,
+ const std::vector<gfx::Size>& sizes);
+
+ // Returns true if there are favicons for |page_url| and one of the types in
+ // |icon_types|.
+ // |favicon_data| is set to the favicon bitmaps which most closely match
+ // |desired_dip_size| and |desired_scale_factors|. See the comment for
+ // GetFaviconDataForBestMatch() for more details on how FaviconData is
+ // constructed.
+ // |mapped_icon_urls| is set to all of the icon URLs which are mapped to
+ // |page_url| with one of the types in |icon_types|. If |icon_types| contains
+ // multiple icon types and there are several matched icon types in the
+ // database, icon URLs of a only single type will be in |mapped_icon_urls|
+ // in the priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON, and FAVICON.
+ bool GetFaviconFromDB(
+ const GURL& page_url,
+ int icon_types,
+ const gfx::Size& desired_dip_size,
+ const std::vector<ui::ScaleFactor>& desired_scale_factors,
+ FaviconData* favicon_data,
+ std::vector<GURL>* mapped_icon_urls);
+
+ // Construct a FaviconData object from the favicon bitmaps which most closely
+ // match |desired_dip_size| and |desired_scale_factors|.
+ // Goodness is computed on a per favicon id basis, thus all of
+ // FaviconData::bitmaps are guaranteed to be for the same FaviconID.
+ // FaviconData::bitmaps may not contain all the favicon bitmaps for FaviconID
+ // which are in the database. Returns true on success.
+ bool GetFaviconDataForBestMatch(
+ const std::vector<FaviconID>& candidate_favicon_ids,
+ const gfx::Size& desired_dip_size,
+ const std::vector<ui::ScaleFactor>& desired_scale_factors,
+ FaviconData* favicon_data);
+
+ // Define type used solely in SetFaviconMappingsForPageAndRedirects.
+ typedef std::map<GURL, FaviconID> IconURLFaviconIDMap;
+
+ // Maps the favicon ids in |icon_url_id_map| to |page_url| (and all
+ // redirects) for |icon_type|. This will also broadcast notifications as
+ // necessary.
+ void SetFaviconMappingsForPageAndRedirects(
+ const GURL& page_url,
+ const IconType icon_type,
+ const IconURLFaviconIDMap& icon_url_id_map);
+
+ // Maps the favicon ids in |icon_url_id_map| to |page_url| for |icon_type|.
+ bool SetFaviconMappingsForPage(const GURL& page_url,
+ IconType icon_type,
+ const IconURLFaviconIDMap& icon_url_id_map);
// Generic stuff -------------------------------------------------------------
@@ -647,16 +726,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,
- FaviconData* favicon_data);
-
- // 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, FaviconData* favicon_data);
-
// Notify any observers of an addition to the visit database.
void NotifyVisitObservers(const VisitRow& visit);
@@ -756,6 +825,10 @@ class HistoryBackend : public base::RefCountedThreadSafe<HistoryBackend>,
scoped_ptr<AndroidProviderBackend> android_provider_backend_;
#endif
+ // If true HistoryBackend::SetFavicons is cripled such that it can only be
+ // used to set favicon bitmapas for a single URL and 0 0 bitmap size.
+ bool single_favicon_bitmap_per_icon_type_;
+
DISALLOW_COPY_AND_ASSIGN(HistoryBackend);
};

Powered by Google App Engine
This is Rietveld 408576698