Chromium Code Reviews| Index: chrome/browser/history/thumbnail_database.h |
| diff --git a/chrome/browser/history/thumbnail_database.h b/chrome/browser/history/thumbnail_database.h |
| index e2209e17a6af2405519645408b3f8c46e1721637..bfd40b439b4927e7b5195d87388718ee7436a88a 100644 |
| --- a/chrome/browser/history/thumbnail_database.h |
| +++ b/chrome/browser/history/thumbnail_database.h |
| @@ -40,6 +40,54 @@ class HistoryPublisher; |
| // higher latency (it's OK for thumbnails to come in slower than the rest |
| // of the data). Moving this to a separate thread would not block potentially |
| // higher priority history operations. |
| +// |
| +// Description of tables: |
|
sky
2012/08/16 16:12:57
Move this to the .cc since its an implementation d
pkotwicz
2012/08/16 19:22:46
Done.
|
| +// |
| +// icon_mapping |
| +// id Unique ID. |
| +// page_url Page URL which has one or more associated favicons. |
| +// icon_id |
|
sky
2012/08/16 16:12:57
Document icon_id too.
pkotwicz
2012/08/16 19:22:46
Done.
|
| +// |
| +// favicons This table associates a row to each favicon for a |
| +// |page_url| in the |icon_mapping| table. This should |
|
sky
2012/08/16 16:12:57
Not 'should', but does. Eg This is the defualt fav
pkotwicz
2012/08/16 19:22:46
Done.
|
| +// be the default favicon |page_url|/favicon.ico plus any |
| +// favicons associated via |
| +// <link rel="icon_type" href="url">. |
| +// The |id| should match the |icon_id| field in the |
|
sky
2012/08/16 16:12:57
Same here, 'The id matches the icon_id field...
pkotwicz
2012/08/16 19:22:46
Done.
|
| +// appropriate row in the icon_mapping table. |
| +// |
| +// id Unique ID. |
| +// url The URL at which the favicon file is located. |
| +// icon_type The type of the favicon specified in the rel attribute of |
| +// the link tag. The FAVICON type is used for the default |
| +// favicon.ico favicon. |
| +// sizes Sizes is a listing of all the sizes at which the favicon |
| +// at |url| is available from the web. Note that this may |
| +// include sizes for which a bitmap is not stored in the |
| +// favicon_bitmaps table. Each widthxheight pair is |
| +// separated by a space. Width and height are separated by |
| +// a space as well. For instance, if |icon_id| represents a |
| +// .ico file containing 16x16 and 32x32 bitmaps, |sizes| |
| +// would be "16 16 32 32". |
| +// |
| +// favicon_bitmaps This table contains the PNG encoded bitmap data of the |
| +// favicons. There is a separate row for every size in a |
| +// multi resolution bitmap. The bitmap data is associated |
| +// to the favicon via the |icon_id| field which should match |
| +// the |id| field in the appropriate row in the |favicons| |
| +// table. |
| +// Note that it is not necessary for there to be a row for |
|
sky
2012/08/16 16:12:57
There is not necessarily a row for each size speci
pkotwicz
2012/08/16 19:22:46
Done.
|
| +// each size specified in the sizes attribute. |
| +// |
| +// id Unique ID. |
| +// icon_id |
| +// last_updated The time at which this favicon was inserted into the |
| +// table. This is used to determine if it needs to be |
| +// redownloaded from the web. |
| +// image_data PNG encoded data of the favicon. |
| +// width Pixel width of |image_data|. |
| +// height Pixel height of |image_data|. |
| + |
| class ThumbnailDatabase { |
| public: |
| ThumbnailDatabase(); |
| @@ -97,17 +145,43 @@ class ThumbnailDatabase { |
| // Returns true on success. |
| bool RecreateThumbnailTable(); |
| + // Favicon Bitmaps ----------------------------------------------------------- |
| + |
| + // Returns true if there are any matched bitmaps for the given |icon_id|. All |
| + // matched results are returned if |favicon_bitmaps| is not NULL. |
| + bool GetFaviconBitmaps(FaviconID icon_id, |
| + std::vector<FaviconBitmap>* favicon_bitmaps); |
| + |
| + // Adds a bitmap component at |pixel_size| for the favicon with |icon_id|. |
| + // Only favicons representing a .ico file should have multiple favicon bitmaps |
| + // per favicon. |
| + // |icon_data| is the png encoded data. |
| + // The |time| indicates the access time, and is used to detect when the |
| + // favicon should be refreshed. |
| + // |pixel_size| is the pixel dimensions of |icon_data|. |
| + // Returns the id of the added bitmap or 0 if unsuccessful. |
| + FaviconBitmapID AddFaviconBitmap( |
| + FaviconID icon_id, |
| + scoped_refptr<base::RefCountedMemory> icon_data, |
| + base::Time time, |
| + const gfx::Size& pixel_size); |
| + |
| + // Sets the bitmap data and the last updated time for a favicon bitmap |
| + // contained by the favicon at |favicon_id|. Returns true if successful. |
| + // TODO(pkotwicz): Use FaviconBitmapID instead. |
| + bool SetFaviconBitmap(FaviconID favicon_id, |
| + scoped_refptr<base::RefCountedMemory> icon_data, |
| + base::Time time); |
| + |
| // Favicons ------------------------------------------------------------------ |
| - // Sets the bits for a favicon. This should be png encoded data. |
| - // The time indicates the access time, and is used to detect when the favicon |
| - // should be refreshed. |
| - bool SetFavicon(FaviconID icon_id, |
| - scoped_refptr<base::RefCountedMemory> icon_data, |
| - base::Time time); |
| + // Updates the sizes associated with a favicon to |sizes|. See the comment |
| + // at the top of the file for the format of the |sizes| parameter. |
| + bool SetFaviconSizes(FaviconID icon_id, const std::string& sizes); |
| - // Sets the time the favicon was last updated. |
| - bool SetFaviconLastUpdateTime(FaviconID icon_id, base::Time time); |
| + // Sets the the favicon as out of date. This will set |last_updated| for all |
| + // of the bitmaps for |icon_id| to be out of date. |
| + bool SetFaviconOutOfDate(FaviconID icon_id); |
| // Returns the id of the entry in the favicon database with the specified url |
| // and icon type. If |required_icon_type| contains multiple icon types and |
| @@ -122,15 +196,31 @@ class ThumbnailDatabase { |
| // Gets the png encoded favicon, last updated time, icon_url and icon_type for |
| // the specified favicon id. |
| + // TODO(pkotwicz): Remove this function. |
| bool GetFavicon(FaviconID icon_id, |
| base::Time* last_updated, |
| - std::vector<unsigned char>* png_icon_data, |
| + scoped_refptr<base::RefCountedMemory>* png_icon_data, |
| GURL* icon_url, |
| IconType* icon_type); |
| + // Gets the icon_url, icon_type and sizes for the specified |icon_id|. |
| + bool GetFaviconHeader(FaviconID icon_id, |
| + GURL* icon_url, |
| + IconType* icon_type, |
| + std::string* sizes); |
| + |
| // Adds the favicon URL and icon type to the favicon db, returning its id. |
| FaviconID AddFavicon(const GURL& icon_url, IconType icon_type); |
| + // Adds a favicon with a single bitmap. This call is equivalent to calling |
| + // AddFavicon, SetFaviconSizes, and AddFaviconBitmap. |
| + FaviconID AddFavicon(const GURL& icon_url, |
| + IconType icon_type, |
| + const std::string& sizes, |
| + scoped_refptr<base::RefCountedMemory> icon_data, |
| + base::Time time, |
| + const gfx::Size& pixel_size); |
| + |
| // Delete the favicon with the provided id. Returns false on failure |
| bool DeleteFavicon(FaviconID id); |
| @@ -194,54 +284,36 @@ class ThumbnailDatabase { |
| bool InitIconMappingEnumerator(IconType type, |
| IconMappingEnumerator* enumerator); |
| - // Temporary IconMapping ----------------------------------------------------- |
| + // Temporary Tables --------------------------------------------------------- |
| // |
| - // Creates a temporary table to store icon mapping. Icon mapping will be |
| - // copied to this table by AddToTemporaryIconMappingTable() and then the |
| - // original table will be dropped, leaving only those copied mapping |
| - // remaining. This is used to quickly delete most of the icon mapping when |
| - // clearing history. |
| - bool InitTemporaryIconMappingTable() { |
| - return InitIconMappingTable(&db_, true); |
| - } |
| + // Creates empty temporary tables for each of the tables in the thumbnail |
| + // database. Favicon data which is not copied into the temporary tables will |
| + // be deleted when CommitTemporaryTables() is called. This is used to delete |
| + // most of the favicons when clearing history. |
| + bool InitTemporaryTables(); |
| + |
| + // Replaces the main tables in the thumbnail database with the temporary |
| + // tables created with InitTemporaryTables(). This means that any data not |
| + // copied over will be deleted. |
| + bool CommitTemporaryTables(); |
| // Copies the given icon mapping from the "main" icon_mapping table to the |
| // temporary one. This is only valid in between calls to |
| - // InitTemporaryIconMappingTable() |
| - // and CommitTemporaryIconMappingTable(). |
| + // InitTemporaryTables() and CommitTemporaryTables(). |
| // |
| // The ID of the favicon will change when this copy takes place. The new ID |
| // is returned, or 0 on failure. |
| IconMappingID AddToTemporaryIconMappingTable(const GURL& page_url, |
| const FaviconID icon_id); |
| - // Replaces the main icon mapping table with the temporary table created by |
| - // InitTemporaryIconMappingTable(). This will mean all icon mapping not copied |
| - // over will be deleted. Returns true on success. |
| - bool CommitTemporaryIconMappingTable(); |
| - |
| - // Temporary Favicons -------------------------------------------------------- |
| - |
| - // Create a temporary table to store favicons. Favicons will be copied to |
| - // this table by CopyToTemporaryFaviconTable() and then the original table |
| - // will be dropped, leaving only those copied favicons remaining. This is |
| - // used to quickly delete most of the favicons when clearing history. |
| - bool InitTemporaryFaviconsTable() { |
| - return InitFaviconsTable(&db_, true); |
| - } |
| - |
| - // Copies the given favicon from the "main" favicon table to the temporary |
| - // one. This is only valid in between calls to InitTemporaryFaviconsTable() |
| - // and CommitTemporaryFaviconTable(). |
| + // Copies the given favicon and associated favicon bitmaps from the "main" |
| + // favicon and favicon_bitmaps tables to the temporary ones. This is only |
| + // valid in between calls to InitTemporaryTables() and |
| + // CommitTemporaryTables(). |
| // |
| // The ID of the favicon will change when this copy takes place. The new ID |
| // is returned, or 0 on failure. |
| - FaviconID CopyToTemporaryFaviconTable(FaviconID source); |
| - |
| - // Replaces the main URL table with the temporary table created by |
| - // InitTemporaryFaviconsTable(). This will mean all favicons not copied over |
| - // will be deleted. Returns true on success. |
| - bool CommitTemporaryFaviconTable(); |
| + FaviconID CopyFaviconAndFaviconBitmapsToTemporaryTables(FaviconID source); |
| // Returns true iff the thumbnails table exists. |
| // Migrating to TopSites is dropping the thumbnails table. |
| @@ -257,21 +329,13 @@ class ThumbnailDatabase { |
| GetFaviconAfterMigrationToTopSites); |
| FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion4); |
| FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion5); |
| + FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion6); |
| FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MigrationIconMapping); |
| // Creates the thumbnail table, returning true if the table already exists |
| // or was successfully created. |
| bool InitThumbnailTable(); |
| - // Creates the favicon table, returning true if the table already exists, |
| - // or was successfully created. |is_temporary| will be false when generating |
| - // the "regular" favicons table. The expirer sets this to true to generate the |
| - // temporary table, which will have a different name but the same schema. |
| - // |db| is the connection to use for initializing the table. |
| - // A different connection is used in RenameAndDropThumbnails, when we |
| - // need to copy the favicons between two database files. |
| - bool InitFaviconsTable(sql::Connection* db, bool is_temporary); |
| - |
| // Helper function to handle cleanup on upgrade failures. |
| sql::InitStatus CantUpgradeToVersion(int cur_version); |
| @@ -284,16 +348,39 @@ class ThumbnailDatabase { |
| // Adds support for sizes in favicon table. |
| bool UpgradeToVersion5(); |
| + // Adds support for size in favicons table and removes sizes column. |
| + bool UpgradeToVersion6(); |
| + |
| // Migrates the icon mapping data from URL database to Thumbnail database. |
| // Return whether the migration succeeds. |
| bool MigrateIconMappingData(URLDatabase* url_db); |
| + // Creates the favicon table, returning true if the table already exists, |
| + // or was successfully created. |is_temporary| will be false when generating |
| + // the "regular" favicons table. The expirer sets this to true to generate the |
| + // temporary table, which will have a different name but the same schema. |
| + // |db| is the connection to use for initializing the table. |
| + // A different connection is used in RenameAndDropThumbnails, when we |
| + // need to copy the favicons between two database files. |
| + bool InitFaviconsTable(sql::Connection* db, bool is_temporary); |
| + |
| // Creates the index over the favicon table. This will be called during |
| // initialization after the table is created. This is a separate function |
| // because it is used by SwapFaviconTables to create an index over the |
| // newly-renamed favicons table (formerly the temporary table with no index). |
| bool InitFaviconsIndex(); |
| + // Creates the favicon_bitmaps table, return true if the table already exists |
| + // or was successfully created. |
| + bool InitFaviconBitmapsTable(sql::Connection* db, bool is_temporary); |
| + |
| + // Creates the index over the favicon_bitmaps table. This will be called |
| + // during initialization after the table is created. This is a separate |
| + // function because it is used by CommitTemporaryTables to create an |
| + // index over the newly-renamed favicon_bitmaps table (formerly the temporary |
| + // table with no index). |
| + bool InitFaviconBitmapsIndex(); |
| + |
| // Creates the icon_map table, return true if the table already exists or was |
| // successfully created. |
| bool InitIconMappingTable(sql::Connection* db, bool is_temporary); |