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

Side by Side Diff: chrome/browser/history/thumbnail_database.h

Issue 10815068: Changes favicon database to support storing bitmaps of different sizes for the same icon_url (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved some of the android stuff to 10831341 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 unified diff | Download patch | Annotate | Revision Log
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 #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 22 matching lines...) Expand all
33 class ExpireHistoryBackend; 33 class ExpireHistoryBackend;
34 class HistoryPublisher; 34 class HistoryPublisher;
35 35
36 // This database interface is owned by the history backend and runs on the 36 // This database interface is owned by the history backend and runs on the
37 // history thread. It is a totally separate component from history partially 37 // history thread. It is a totally separate component from history partially
38 // because we may want to move it to its own thread in the future. The 38 // because we may want to move it to its own thread in the future. The
39 // operations we will do on this database will be slow, but we can tolerate 39 // operations we will do on this database will be slow, but we can tolerate
40 // higher latency (it's OK for thumbnails to come in slower than the rest 40 // higher latency (it's OK for thumbnails to come in slower than the rest
41 // of the data). Moving this to a separate thread would not block potentially 41 // of the data). Moving this to a separate thread would not block potentially
42 // higher priority history operations. 42 // higher priority history operations.
43 //
44 // 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.
45 //
46 // icon_mapping
47 // id Unique ID.
48 // page_url Page URL which has one or more associated favicons.
49 // icon_id
sky 2012/08/16 16:12:57 Document icon_id too.
pkotwicz 2012/08/16 19:22:46 Done.
50 //
51 // favicons This table associates a row to each favicon for a
52 // |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.
53 // be the default favicon |page_url|/favicon.ico plus any
54 // favicons associated via
55 // <link rel="icon_type" href="url">.
56 // 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.
57 // appropriate row in the icon_mapping table.
58 //
59 // id Unique ID.
60 // url The URL at which the favicon file is located.
61 // icon_type The type of the favicon specified in the rel attribute of
62 // the link tag. The FAVICON type is used for the default
63 // favicon.ico favicon.
64 // sizes Sizes is a listing of all the sizes at which the favicon
65 // at |url| is available from the web. Note that this may
66 // include sizes for which a bitmap is not stored in the
67 // favicon_bitmaps table. Each widthxheight pair is
68 // separated by a space. Width and height are separated by
69 // a space as well. For instance, if |icon_id| represents a
70 // .ico file containing 16x16 and 32x32 bitmaps, |sizes|
71 // would be "16 16 32 32".
72 //
73 // favicon_bitmaps This table contains the PNG encoded bitmap data of the
74 // favicons. There is a separate row for every size in a
75 // multi resolution bitmap. The bitmap data is associated
76 // to the favicon via the |icon_id| field which should match
77 // the |id| field in the appropriate row in the |favicons|
78 // table.
79 // 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.
80 // each size specified in the sizes attribute.
81 //
82 // id Unique ID.
83 // icon_id
84 // last_updated The time at which this favicon was inserted into the
85 // table. This is used to determine if it needs to be
86 // redownloaded from the web.
87 // image_data PNG encoded data of the favicon.
88 // width Pixel width of |image_data|.
89 // height Pixel height of |image_data|.
90
43 class ThumbnailDatabase { 91 class ThumbnailDatabase {
44 public: 92 public:
45 ThumbnailDatabase(); 93 ThumbnailDatabase();
46 ~ThumbnailDatabase(); 94 ~ThumbnailDatabase();
47 95
48 // Must be called after creation but before any other methods are called. 96 // Must be called after creation but before any other methods are called.
49 // When not INIT_OK, no other functions should be called. 97 // When not INIT_OK, no other functions should be called.
50 sql::InitStatus Init(const FilePath& db_name, 98 sql::InitStatus Init(const FilePath& db_name,
51 const HistoryPublisher* history_publisher, 99 const HistoryPublisher* history_publisher,
52 URLDatabase* url_database); 100 URLDatabase* url_database);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 138
91 // If there is a thumbnail score for the id provided, retrieves the 139 // If there is a thumbnail score for the id provided, retrieves the
92 // current thumbnail score and places it in |score| and returns 140 // current thumbnail score and places it in |score| and returns
93 // true. Returns false otherwise. 141 // true. Returns false otherwise.
94 bool ThumbnailScoreForId(URLID id, ThumbnailScore* score); 142 bool ThumbnailScoreForId(URLID id, ThumbnailScore* score);
95 143
96 // Called by the to delete all old thumbnails and make a clean table. 144 // Called by the to delete all old thumbnails and make a clean table.
97 // Returns true on success. 145 // Returns true on success.
98 bool RecreateThumbnailTable(); 146 bool RecreateThumbnailTable();
99 147
148 // Favicon Bitmaps -----------------------------------------------------------
149
150 // Returns true if there are any matched bitmaps for the given |icon_id|. All
151 // matched results are returned if |favicon_bitmaps| is not NULL.
152 bool GetFaviconBitmaps(FaviconID icon_id,
153 std::vector<FaviconBitmap>* favicon_bitmaps);
154
155 // Adds a bitmap component at |pixel_size| for the favicon with |icon_id|.
156 // Only favicons representing a .ico file should have multiple favicon bitmaps
157 // per favicon.
158 // |icon_data| is the png encoded data.
159 // The |time| indicates the access time, and is used to detect when the
160 // favicon should be refreshed.
161 // |pixel_size| is the pixel dimensions of |icon_data|.
162 // Returns the id of the added bitmap or 0 if unsuccessful.
163 FaviconBitmapID AddFaviconBitmap(
164 FaviconID icon_id,
165 scoped_refptr<base::RefCountedMemory> icon_data,
166 base::Time time,
167 const gfx::Size& pixel_size);
168
169 // Sets the bitmap data and the last updated time for a favicon bitmap
170 // contained by the favicon at |favicon_id|. Returns true if successful.
171 // TODO(pkotwicz): Use FaviconBitmapID instead.
172 bool SetFaviconBitmap(FaviconID favicon_id,
173 scoped_refptr<base::RefCountedMemory> icon_data,
174 base::Time time);
175
100 // Favicons ------------------------------------------------------------------ 176 // Favicons ------------------------------------------------------------------
101 177
102 // Sets the bits for a favicon. This should be png encoded data. 178 // Updates the sizes associated with a favicon to |sizes|. See the comment
103 // The time indicates the access time, and is used to detect when the favicon 179 // at the top of the file for the format of the |sizes| parameter.
104 // should be refreshed. 180 bool SetFaviconSizes(FaviconID icon_id, const std::string& sizes);
105 bool SetFavicon(FaviconID icon_id,
106 scoped_refptr<base::RefCountedMemory> icon_data,
107 base::Time time);
108 181
109 // Sets the time the favicon was last updated. 182 // Sets the the favicon as out of date. This will set |last_updated| for all
110 bool SetFaviconLastUpdateTime(FaviconID icon_id, base::Time time); 183 // of the bitmaps for |icon_id| to be out of date.
184 bool SetFaviconOutOfDate(FaviconID icon_id);
111 185
112 // Returns the id of the entry in the favicon database with the specified url 186 // 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 187 // 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 188 // 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 189 // 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 190 // FAVICON, and the icon type is returned in icon_type parameter if it is not
117 // NULL. 191 // NULL.
118 // Returns 0 if no entry exists for the specified url. 192 // Returns 0 if no entry exists for the specified url.
119 FaviconID GetFaviconIDForFaviconURL(const GURL& icon_url, 193 FaviconID GetFaviconIDForFaviconURL(const GURL& icon_url,
120 int required_icon_type, 194 int required_icon_type,
121 IconType* icon_type); 195 IconType* icon_type);
122 196
123 // Gets the png encoded favicon, last updated time, icon_url and icon_type for 197 // Gets the png encoded favicon, last updated time, icon_url and icon_type for
124 // the specified favicon id. 198 // the specified favicon id.
199 // TODO(pkotwicz): Remove this function.
125 bool GetFavicon(FaviconID icon_id, 200 bool GetFavicon(FaviconID icon_id,
126 base::Time* last_updated, 201 base::Time* last_updated,
127 std::vector<unsigned char>* png_icon_data, 202 scoped_refptr<base::RefCountedMemory>* png_icon_data,
128 GURL* icon_url, 203 GURL* icon_url,
129 IconType* icon_type); 204 IconType* icon_type);
130 205
206 // Gets the icon_url, icon_type and sizes for the specified |icon_id|.
207 bool GetFaviconHeader(FaviconID icon_id,
208 GURL* icon_url,
209 IconType* icon_type,
210 std::string* sizes);
211
131 // Adds the favicon URL and icon type to the favicon db, returning its id. 212 // Adds the favicon URL and icon type to the favicon db, returning its id.
132 FaviconID AddFavicon(const GURL& icon_url, IconType icon_type); 213 FaviconID AddFavicon(const GURL& icon_url, IconType icon_type);
133 214
215 // Adds a favicon with a single bitmap. This call is equivalent to calling
216 // AddFavicon, SetFaviconSizes, and AddFaviconBitmap.
217 FaviconID AddFavicon(const GURL& icon_url,
218 IconType icon_type,
219 const std::string& sizes,
220 scoped_refptr<base::RefCountedMemory> icon_data,
221 base::Time time,
222 const gfx::Size& pixel_size);
223
134 // Delete the favicon with the provided id. Returns false on failure 224 // Delete the favicon with the provided id. Returns false on failure
135 bool DeleteFavicon(FaviconID id); 225 bool DeleteFavicon(FaviconID id);
136 226
137 // Icon Mapping -------------------------------------------------------------- 227 // Icon Mapping --------------------------------------------------------------
138 // 228 //
139 // Returns true if there is a matched icon mapping for the given page and 229 // Returns true if there is a matched icon mapping for the given page and
140 // icon type. 230 // icon type.
141 // The matched icon mapping is returned in the icon_mapping parameter if it is 231 // The matched icon mapping is returned in the icon_mapping parameter if it is
142 // not NULL. 232 // not NULL.
143 bool GetIconMappingForPageURL(const GURL& page_url, 233 bool GetIconMappingForPageURL(const GURL& page_url,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 // each call of GetNextIconMapping(). 277 // each call of GetNextIconMapping().
188 sql::Statement statement_; 278 sql::Statement statement_;
189 279
190 DISALLOW_COPY_AND_ASSIGN(IconMappingEnumerator); 280 DISALLOW_COPY_AND_ASSIGN(IconMappingEnumerator);
191 }; 281 };
192 282
193 // Return all icon mappings of the given |icon_type|. 283 // Return all icon mappings of the given |icon_type|.
194 bool InitIconMappingEnumerator(IconType type, 284 bool InitIconMappingEnumerator(IconType type,
195 IconMappingEnumerator* enumerator); 285 IconMappingEnumerator* enumerator);
196 286
197 // Temporary IconMapping ----------------------------------------------------- 287 // Temporary Tables ---------------------------------------------------------
198 // 288 //
199 // Creates a temporary table to store icon mapping. Icon mapping will be 289 // Creates empty temporary tables for each of the tables in the thumbnail
200 // copied to this table by AddToTemporaryIconMappingTable() and then the 290 // database. Favicon data which is not copied into the temporary tables will
201 // original table will be dropped, leaving only those copied mapping 291 // be deleted when CommitTemporaryTables() is called. This is used to delete
202 // remaining. This is used to quickly delete most of the icon mapping when 292 // most of the favicons when clearing history.
203 // clearing history. 293 bool InitTemporaryTables();
204 bool InitTemporaryIconMappingTable() { 294
205 return InitIconMappingTable(&db_, true); 295 // Replaces the main tables in the thumbnail database with the temporary
206 } 296 // tables created with InitTemporaryTables(). This means that any data not
297 // copied over will be deleted.
298 bool CommitTemporaryTables();
207 299
208 // Copies the given icon mapping from the "main" icon_mapping table to the 300 // Copies the given icon mapping from the "main" icon_mapping table to the
209 // temporary one. This is only valid in between calls to 301 // temporary one. This is only valid in between calls to
210 // InitTemporaryIconMappingTable() 302 // InitTemporaryTables() and CommitTemporaryTables().
211 // and CommitTemporaryIconMappingTable().
212 // 303 //
213 // The ID of the favicon will change when this copy takes place. The new ID 304 // The ID of the favicon will change when this copy takes place. The new ID
214 // is returned, or 0 on failure. 305 // is returned, or 0 on failure.
215 IconMappingID AddToTemporaryIconMappingTable(const GURL& page_url, 306 IconMappingID AddToTemporaryIconMappingTable(const GURL& page_url,
216 const FaviconID icon_id); 307 const FaviconID icon_id);
217 308
218 // Replaces the main icon mapping table with the temporary table created by 309 // Copies the given favicon and associated favicon bitmaps from the "main"
219 // InitTemporaryIconMappingTable(). This will mean all icon mapping not copied 310 // favicon and favicon_bitmaps tables to the temporary ones. This is only
220 // over will be deleted. Returns true on success. 311 // valid in between calls to InitTemporaryTables() and
221 bool CommitTemporaryIconMappingTable(); 312 // CommitTemporaryTables().
222
223 // Temporary Favicons --------------------------------------------------------
224
225 // Create a temporary table to store favicons. Favicons will be copied to
226 // this table by CopyToTemporaryFaviconTable() and then the original table
227 // will be dropped, leaving only those copied favicons remaining. This is
228 // used to quickly delete most of the favicons when clearing history.
229 bool InitTemporaryFaviconsTable() {
230 return InitFaviconsTable(&db_, true);
231 }
232
233 // Copies the given favicon from the "main" favicon table to the temporary
234 // one. This is only valid in between calls to InitTemporaryFaviconsTable()
235 // and CommitTemporaryFaviconTable().
236 // 313 //
237 // The ID of the favicon will change when this copy takes place. The new ID 314 // The ID of the favicon will change when this copy takes place. The new ID
238 // is returned, or 0 on failure. 315 // is returned, or 0 on failure.
239 FaviconID CopyToTemporaryFaviconTable(FaviconID source); 316 FaviconID CopyFaviconAndFaviconBitmapsToTemporaryTables(FaviconID source);
240
241 // Replaces the main URL table with the temporary table created by
242 // InitTemporaryFaviconsTable(). This will mean all favicons not copied over
243 // will be deleted. Returns true on success.
244 bool CommitTemporaryFaviconTable();
245 317
246 // Returns true iff the thumbnails table exists. 318 // Returns true iff the thumbnails table exists.
247 // Migrating to TopSites is dropping the thumbnails table. 319 // Migrating to TopSites is dropping the thumbnails table.
248 bool NeedsMigrationToTopSites(); 320 bool NeedsMigrationToTopSites();
249 321
250 // Renames the database file and drops the Thumbnails table. 322 // Renames the database file and drops the Thumbnails table.
251 bool RenameAndDropThumbnails(const FilePath& old_db_file, 323 bool RenameAndDropThumbnails(const FilePath& old_db_file,
252 const FilePath& new_db_file); 324 const FilePath& new_db_file);
253 325
254 private: 326 private:
255 friend class ExpireHistoryBackend; 327 friend class ExpireHistoryBackend;
256 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, 328 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest,
257 GetFaviconAfterMigrationToTopSites); 329 GetFaviconAfterMigrationToTopSites);
258 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion4); 330 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion4);
259 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion5); 331 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion5);
332 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion6);
260 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MigrationIconMapping); 333 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MigrationIconMapping);
261 334
262 // Creates the thumbnail table, returning true if the table already exists 335 // Creates the thumbnail table, returning true if the table already exists
263 // or was successfully created. 336 // or was successfully created.
264 bool InitThumbnailTable(); 337 bool InitThumbnailTable();
265 338
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. 339 // Helper function to handle cleanup on upgrade failures.
276 sql::InitStatus CantUpgradeToVersion(int cur_version); 340 sql::InitStatus CantUpgradeToVersion(int cur_version);
277 341
278 // Adds support for the new metadata on web page thumbnails. 342 // Adds support for the new metadata on web page thumbnails.
279 bool UpgradeToVersion3(); 343 bool UpgradeToVersion3();
280 344
281 // Adds support for the icon_type in favicon table. 345 // Adds support for the icon_type in favicon table.
282 bool UpgradeToVersion4(); 346 bool UpgradeToVersion4();
283 347
284 // Adds support for sizes in favicon table. 348 // Adds support for sizes in favicon table.
285 bool UpgradeToVersion5(); 349 bool UpgradeToVersion5();
286 350
351 // Adds support for size in favicons table and removes sizes column.
352 bool UpgradeToVersion6();
353
287 // Migrates the icon mapping data from URL database to Thumbnail database. 354 // Migrates the icon mapping data from URL database to Thumbnail database.
288 // Return whether the migration succeeds. 355 // Return whether the migration succeeds.
289 bool MigrateIconMappingData(URLDatabase* url_db); 356 bool MigrateIconMappingData(URLDatabase* url_db);
290 357
358 // Creates the favicon table, returning true if the table already exists,
359 // or was successfully created. |is_temporary| will be false when generating
360 // the "regular" favicons table. The expirer sets this to true to generate the
361 // temporary table, which will have a different name but the same schema.
362 // |db| is the connection to use for initializing the table.
363 // A different connection is used in RenameAndDropThumbnails, when we
364 // need to copy the favicons between two database files.
365 bool InitFaviconsTable(sql::Connection* db, bool is_temporary);
366
291 // Creates the index over the favicon table. This will be called during 367 // Creates the index over the favicon table. This will be called during
292 // initialization after the table is created. This is a separate function 368 // initialization after the table is created. This is a separate function
293 // because it is used by SwapFaviconTables to create an index over the 369 // because it is used by SwapFaviconTables to create an index over the
294 // newly-renamed favicons table (formerly the temporary table with no index). 370 // newly-renamed favicons table (formerly the temporary table with no index).
295 bool InitFaviconsIndex(); 371 bool InitFaviconsIndex();
296 372
373 // Creates the favicon_bitmaps table, return true if the table already exists
374 // or was successfully created.
375 bool InitFaviconBitmapsTable(sql::Connection* db, bool is_temporary);
376
377 // Creates the index over the favicon_bitmaps table. This will be called
378 // during initialization after the table is created. This is a separate
379 // function because it is used by CommitTemporaryTables to create an
380 // index over the newly-renamed favicon_bitmaps table (formerly the temporary
381 // table with no index).
382 bool InitFaviconBitmapsIndex();
383
297 // Creates the icon_map table, return true if the table already exists or was 384 // Creates the icon_map table, return true if the table already exists or was
298 // successfully created. 385 // successfully created.
299 bool InitIconMappingTable(sql::Connection* db, bool is_temporary); 386 bool InitIconMappingTable(sql::Connection* db, bool is_temporary);
300 387
301 // Creates the index over the icon_mapping table, This will be called during 388 // 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 389 // initialization after the table is created. This is a separate function
303 // because it is used by CommitTemporaryIconMappingTable to create an index 390 // because it is used by CommitTemporaryIconMappingTable to create an index
304 // over the newly-renamed icon_mapping table (formerly the temporary table 391 // over the newly-renamed icon_mapping table (formerly the temporary table
305 // with no index). 392 // with no index).
306 bool InitIconMappingIndex(); 393 bool InitIconMappingIndex();
(...skipping 18 matching lines...) Expand all
325 const HistoryPublisher* history_publisher_; 412 const HistoryPublisher* history_publisher_;
326 413
327 // True if migration to TopSites has been done and the thumbnails 414 // True if migration to TopSites has been done and the thumbnails
328 // table should not be used. 415 // table should not be used.
329 bool use_top_sites_; 416 bool use_top_sites_;
330 }; 417 };
331 418
332 } // namespace history 419 } // namespace history
333 420
334 #endif // CHROME_BROWSER_HISTORY_THUMBNAIL_DATABASE_H_ 421 #endif // CHROME_BROWSER_HISTORY_THUMBNAIL_DATABASE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698