OLD | NEW |
---|---|
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 #ifndef CHROME_BROWSER_HISTORY_THUMBNAIL_DATABASE_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_THUMBNAIL_DATABASE_H_ |
6 #define CHROME_BROWSER_HISTORY_THUMBNAIL_DATABASE_H_ | 6 #define CHROME_BROWSER_HISTORY_THUMBNAIL_DATABASE_H_ |
7 | 7 |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 // current thumbnail score and places it in |score| and returns | 92 // current thumbnail score and places it in |score| and returns |
93 // true. Returns false otherwise. | 93 // true. Returns false otherwise. |
94 bool ThumbnailScoreForId(URLID id, ThumbnailScore* score); | 94 bool ThumbnailScoreForId(URLID id, ThumbnailScore* score); |
95 | 95 |
96 // Called by the to delete all old thumbnails and make a clean table. | 96 // Called by the to delete all old thumbnails and make a clean table. |
97 // Returns true on success. | 97 // Returns true on success. |
98 bool RecreateThumbnailTable(); | 98 bool RecreateThumbnailTable(); |
99 | 99 |
100 // Favicons ------------------------------------------------------------------ | 100 // Favicons ------------------------------------------------------------------ |
101 | 101 |
102 // Sets the bits for a favicon. This should be png encoded data. | 102 // Add a favicon frame. A favicon frame represents a bitmap component for a |
103 // particular size in an image file. Only favicons representing a .ico file | |
104 // should have multiple favicon frames per favicon. | |
105 // |icon_data| is the png encoded data. | |
103 // The time indicates the access time, and is used to detect when the favicon | 106 // The time indicates the access time, and is used to detect when the favicon |
104 // should be refreshed. | 107 // should be refreshed. |
105 bool SetFavicon(FaviconID icon_id, | 108 bool AddFaviconFrame(FaviconID icon_id, |
sky
2012/08/02 19:50:31
Can you use Image or Bitmap instead of Frame in al
| |
106 scoped_refptr<base::RefCountedMemory> icon_data, | 109 scoped_refptr<base::RefCountedMemory> icon_data, |
107 base::Time time); | 110 base::Time time); |
108 | 111 |
109 // Sets the time the favicon was last updated. | 112 // Sets the the favicon as out of date. This will set |last_updated| for all |
110 bool SetFaviconLastUpdateTime(FaviconID icon_id, base::Time time); | 113 // of the frames for |icon_id| to be out of date. |
114 bool SetFaviconOutOfDate(FaviconID icon_id); | |
111 | 115 |
112 // Returns the id of the entry in the favicon database with the specified url | 116 // Returns the id of the entry in the favicon database with the specified url |
113 // and icon type. If |required_icon_type| contains multiple icon types and | 117 // and icon type. If |required_icon_type| contains multiple icon types and |
114 // there are more than one matched icon in database, only one icon will be | 118 // there are more than one matched icon in database, only one icon will be |
115 // returned in the priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON, and | 119 // returned in the priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON, and |
116 // FAVICON, and the icon type is returned in icon_type parameter if it is not | 120 // FAVICON, and the icon type is returned in icon_type parameter if it is not |
117 // NULL. | 121 // NULL. |
118 // Returns 0 if no entry exists for the specified url. | 122 // Returns 0 if no entry exists for the specified url. |
119 FaviconID GetFaviconIDForFaviconURL(const GURL& icon_url, | 123 FaviconID GetFaviconIDForFaviconURL(const GURL& icon_url, |
120 int required_icon_type, | 124 int required_icon_type, |
121 IconType* icon_type); | 125 IconType* icon_type); |
122 | 126 |
123 // Gets the png encoded favicon, last updated time, icon_url and icon_type for | 127 // Gets the png encoded favicon, last updated time, icon_url and icon_type for |
124 // the specified favicon id. | 128 // the specified favicon id. |
125 bool GetFavicon(FaviconID icon_id, | 129 bool GetFavicon(FaviconID icon_id, |
126 base::Time* last_updated, | 130 base::Time* last_updated, |
127 std::vector<unsigned char>* png_icon_data, | 131 std::vector<unsigned char>* png_icon_data, |
128 GURL* icon_url, | 132 GURL* icon_url, |
129 IconType* icon_type); | 133 IconType* icon_type); |
130 | 134 |
135 // Gets the png encoded favicon and last updated time for the specified | |
136 // favicon id. | |
137 bool GetFaviconFrame(FaviconID icon_id, | |
sky
2012/08/02 19:50:31
Won't this need to take something that returns a v
| |
138 base::Time* last_updated, | |
139 std::vector<unsigned char>* png_icon_data); | |
140 | |
131 // Adds the favicon URL and icon type to the favicon db, returning its id. | 141 // Adds the favicon URL and icon type to the favicon db, returning its id. |
132 FaviconID AddFavicon(const GURL& icon_url, IconType icon_type); | 142 FaviconID AddFavicon(const GURL& icon_url, IconType icon_type); |
133 | 143 |
134 // Delete the favicon with the provided id. Returns false on failure | 144 // Delete the favicon with the provided id. Returns false on failure |
135 bool DeleteFavicon(FaviconID id); | 145 bool DeleteFavicon(FaviconID id); |
136 | 146 |
137 // Icon Mapping -------------------------------------------------------------- | 147 // Icon Mapping -------------------------------------------------------------- |
138 // | 148 // |
139 // Returns true if there is a matched icon mapping for the given page and | 149 // Returns true if there is a matched icon mapping for the given page and |
140 // icon type. | 150 // icon type. |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
231 } | 241 } |
232 | 242 |
233 // Copies the given favicon from the "main" favicon table to the temporary | 243 // Copies the given favicon from the "main" favicon table to the temporary |
234 // one. This is only valid in between calls to InitTemporaryFaviconsTable() | 244 // one. This is only valid in between calls to InitTemporaryFaviconsTable() |
235 // and CommitTemporaryFaviconTable(). | 245 // and CommitTemporaryFaviconTable(). |
236 // | 246 // |
237 // The ID of the favicon will change when this copy takes place. The new ID | 247 // The ID of the favicon will change when this copy takes place. The new ID |
238 // is returned, or 0 on failure. | 248 // is returned, or 0 on failure. |
239 FaviconID CopyToTemporaryFaviconTable(FaviconID source); | 249 FaviconID CopyToTemporaryFaviconTable(FaviconID source); |
240 | 250 |
241 // Replaces the main URL table with the temporary table created by | 251 // Replaces the main favicon table with the temporary table created by |
242 // InitTemporaryFaviconsTable(). This will mean all favicons not copied over | 252 // InitTemporaryFaviconsTable(). This will mean all favicons not copied over |
243 // will be deleted. Returns true on success. | 253 // will be deleted. Returns true on success. |
244 bool CommitTemporaryFaviconTable(); | 254 bool CommitTemporaryFaviconTable(); |
245 | 255 |
256 // Create a temporary table to store the favicon frames. Favicon frames will | |
257 // be copied to this table by CopyToTemporaryFaviconFramesTable() and then the | |
258 // original table will be dropped, leaving only the copied favicons | |
259 // remaining. | |
260 bool InitTemporaryFaviconFramesTable() { | |
261 return InitFaviconFramesTable(&db_, true); | |
262 } | |
263 | |
264 // Copies the frames corresponding to |icon_id| from the "main" favicon table | |
265 // to the temporary one. This is only valid in between calls to | |
266 // InitTemporaryFaviconFramesTable() | |
267 // and CommitTemporaryFaviconFrameTable(). | |
268 void CopyToTemporaryFaviconFramesTable(FaviconID icon_id); | |
269 | |
270 // Replaces the main favicon frame table with the temporary table created by | |
271 // InitTemporaryFaviconFramesTable(). This means that all favicon frames not | |
272 // copied over will be deleted. Returns true on success. | |
273 bool CommitTemporaryFaviconFrameTable(); | |
274 | |
246 // Returns true iff the thumbnails table exists. | 275 // Returns true iff the thumbnails table exists. |
247 // Migrating to TopSites is dropping the thumbnails table. | 276 // Migrating to TopSites is dropping the thumbnails table. |
248 bool NeedsMigrationToTopSites(); | 277 bool NeedsMigrationToTopSites(); |
249 | 278 |
250 // Renames the database file and drops the Thumbnails table. | 279 // Renames the database file and drops the Thumbnails table. |
251 bool RenameAndDropThumbnails(const FilePath& old_db_file, | 280 bool RenameAndDropThumbnails(const FilePath& old_db_file, |
252 const FilePath& new_db_file); | 281 const FilePath& new_db_file); |
253 | 282 |
254 private: | 283 private: |
255 friend class ExpireHistoryBackend; | 284 friend class ExpireHistoryBackend; |
256 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, | 285 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, |
257 GetFaviconAfterMigrationToTopSites); | 286 GetFaviconAfterMigrationToTopSites); |
258 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion4); | 287 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion4); |
259 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion5); | 288 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion5); |
289 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion6); | |
260 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MigrationIconMapping); | 290 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MigrationIconMapping); |
261 | 291 |
262 // Creates the thumbnail table, returning true if the table already exists | 292 // Creates the thumbnail table, returning true if the table already exists |
263 // or was successfully created. | 293 // or was successfully created. |
264 bool InitThumbnailTable(); | 294 bool InitThumbnailTable(); |
265 | 295 |
266 // Creates the favicon table, returning true if the table already exists, | |
267 // or was successfully created. |is_temporary| will be false when generating | |
268 // the "regular" favicons table. The expirer sets this to true to generate the | |
269 // temporary table, which will have a different name but the same schema. | |
270 // |db| is the connection to use for initializing the table. | |
271 // A different connection is used in RenameAndDropThumbnails, when we | |
272 // need to copy the favicons between two database files. | |
273 bool InitFaviconsTable(sql::Connection* db, bool is_temporary); | |
274 | |
275 // Helper function to handle cleanup on upgrade failures. | 296 // Helper function to handle cleanup on upgrade failures. |
276 sql::InitStatus CantUpgradeToVersion(int cur_version); | 297 sql::InitStatus CantUpgradeToVersion(int cur_version); |
277 | 298 |
278 // Adds support for the new metadata on web page thumbnails. | 299 // Adds support for the new metadata on web page thumbnails. |
279 bool UpgradeToVersion3(); | 300 bool UpgradeToVersion3(); |
280 | 301 |
281 // Adds support for the icon_type in favicon table. | 302 // Adds support for the icon_type in favicon table. |
282 bool UpgradeToVersion4(); | 303 bool UpgradeToVersion4(); |
283 | 304 |
284 // Adds support for sizes in favicon table. | 305 // Adds support for sizes in favicon table. |
285 bool UpgradeToVersion5(); | 306 bool UpgradeToVersion5(); |
286 | 307 |
308 // Adds support for size in favicons table and removes sizes column. | |
309 bool UpgradeToVersion6(); | |
310 | |
287 // Migrates the icon mapping data from URL database to Thumbnail database. | 311 // Migrates the icon mapping data from URL database to Thumbnail database. |
288 // Return whether the migration succeeds. | 312 // Return whether the migration succeeds. |
289 bool MigrateIconMappingData(URLDatabase* url_db); | 313 bool MigrateIconMappingData(URLDatabase* url_db); |
290 | 314 |
315 // Creates the favicon table, returning true if the table already exists, | |
316 // or was successfully created. |is_temporary| will be false when generating | |
317 // the "regular" favicons table. The expirer sets this to true to generate the | |
318 // temporary table, which will have a different name but the same schema. | |
319 // |db| is the connection to use for initializing the table. | |
320 // A different connection is used in RenameAndDropThumbnails, when we | |
321 // need to copy the favicons between two database files. | |
322 bool InitFaviconsTable(sql::Connection* db, bool is_temporary); | |
323 | |
291 // Creates the index over the favicon table. This will be called during | 324 // Creates the index over the favicon table. This will be called during |
292 // initialization after the table is created. This is a separate function | 325 // initialization after the table is created. This is a separate function |
293 // because it is used by SwapFaviconTables to create an index over the | 326 // because it is used by SwapFaviconTables to create an index over the |
294 // newly-renamed favicons table (formerly the temporary table with no index). | 327 // newly-renamed favicons table (formerly the temporary table with no index). |
295 bool InitFaviconsIndex(); | 328 bool InitFaviconsIndex(); |
296 | 329 |
330 // Creates the favicon_frames table, return true if the table already exists | |
331 // or was successfully created. | |
332 bool InitFaviconFramesTable(sql::Connection* db, bool is_temporary); | |
333 | |
334 // Creates the index over the favicon_frames table. This will be called | |
335 // during initialization after the table is created. This is a separate | |
336 // function because it is used by CommitTemporaryFaviconFrameTable to create | |
337 // an index over the newly-renamed favicon_frames table (formerly the | |
338 // temporary table with no index). | |
339 bool InitFaviconFramesIndex(); | |
340 | |
297 // Creates the icon_map table, return true if the table already exists or was | 341 // Creates the icon_map table, return true if the table already exists or was |
298 // successfully created. | 342 // successfully created. |
299 bool InitIconMappingTable(sql::Connection* db, bool is_temporary); | 343 bool InitIconMappingTable(sql::Connection* db, bool is_temporary); |
300 | 344 |
301 // Creates the index over the icon_mapping table, This will be called during | 345 // Creates the index over the icon_mapping table, This will be called during |
302 // initialization after the table is created. This is a separate function | 346 // initialization after the table is created. This is a separate function |
303 // because it is used by CommitTemporaryIconMappingTable to create an index | 347 // because it is used by CommitTemporaryIconMappingTable to create an index |
304 // over the newly-renamed icon_mapping table (formerly the temporary table | 348 // over the newly-renamed icon_mapping table (formerly the temporary table |
305 // with no index). | 349 // with no index). |
306 bool InitIconMappingIndex(); | 350 bool InitIconMappingIndex(); |
(...skipping 18 matching lines...) Expand all Loading... | |
325 const HistoryPublisher* history_publisher_; | 369 const HistoryPublisher* history_publisher_; |
326 | 370 |
327 // True if migration to TopSites has been done and the thumbnails | 371 // True if migration to TopSites has been done and the thumbnails |
328 // table should not be used. | 372 // table should not be used. |
329 bool use_top_sites_; | 373 bool use_top_sites_; |
330 }; | 374 }; |
331 | 375 |
332 } // namespace history | 376 } // namespace history |
333 | 377 |
334 #endif // CHROME_BROWSER_HISTORY_THUMBNAIL_DATABASE_H_ | 378 #endif // CHROME_BROWSER_HISTORY_THUMBNAIL_DATABASE_H_ |
OLD | NEW |