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

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: 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
« no previous file with comments | « chrome/browser/history/history_types.cc ('k') | chrome/browser/history/thumbnail_database.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 90
91 // If there is a thumbnail score for the id provided, retrieves the 91 // If there is a thumbnail score for the id provided, retrieves the
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 // Favicon Bitmaps -----------------------------------------------------------
101
102 // Returns true if there are any matched bitmaps for the given |icon_id|. All
103 // matched results are returned if |favicon_bitmaps| is not NULL.
104 bool GetFaviconBitmaps(FaviconID icon_id,
105 std::vector<FaviconBitmap>* favicon_bitmaps);
106
107 // Adds a bitmap component at |pixel_size| for the favicon with |icon_id|.
108 // Only favicons representing a .ico file should have multiple favicon bitmaps
109 // per favicon.
110 // |icon_data| is the png encoded data.
111 // The |time| indicates the access time, and is used to detect when the
112 // favicon should be refreshed.
113 // |pixel_size| is the pixel dimensions of |icon_data|.
114 // Returns the id of the added bitmap or 0 if unsuccessful.
115 FaviconBitmapID AddFaviconBitmap(
116 FaviconID icon_id,
117 const scoped_refptr<base::RefCountedMemory>& icon_data,
118 base::Time time,
119 const gfx::Size& pixel_size);
120
121 // Deletes the favicon bitmaps for the favicon with with |icon_id|.
122 // Returns true if successful.
123 bool DeleteFaviconBitmapsForFavicon(FaviconID icon_id);
124
100 // Favicons ------------------------------------------------------------------ 125 // Favicons ------------------------------------------------------------------
101 126
102 // Sets the bits for a favicon. This should be png encoded data. 127 // 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 128 // at the top of the .cc file for the format of the |sizes| parameter.
104 // should be refreshed. 129 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 130
109 // Sets the time the favicon was last updated. 131 // Sets the the favicon as out of date. This will set |last_updated| for all
110 bool SetFaviconLastUpdateTime(FaviconID icon_id, base::Time time); 132 // of the bitmaps for |icon_id| to be out of date.
133 bool SetFaviconOutOfDate(FaviconID icon_id);
111 134
112 // Returns the id of the entry in the favicon database with the specified url 135 // 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 136 // 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 137 // 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 138 // 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 139 // FAVICON, and the icon type is returned in icon_type parameter if it is not
117 // NULL. 140 // NULL.
118 // Returns 0 if no entry exists for the specified url. 141 // Returns 0 if no entry exists for the specified url.
119 FaviconID GetFaviconIDForFaviconURL(const GURL& icon_url, 142 FaviconID GetFaviconIDForFaviconURL(const GURL& icon_url,
120 int required_icon_type, 143 int required_icon_type,
121 IconType* icon_type); 144 IconType* icon_type);
122 145
123 // Gets the png encoded favicon, last updated time, icon_url and icon_type for 146 // Gets the png encoded favicon, last updated time, icon_url and icon_type for
124 // the specified favicon id. 147 // the specified favicon id.
148 // TODO(pkotwicz): Remove this function.
125 bool GetFavicon(FaviconID icon_id, 149 bool GetFavicon(FaviconID icon_id,
126 base::Time* last_updated, 150 base::Time* last_updated,
127 std::vector<unsigned char>* png_icon_data, 151 scoped_refptr<base::RefCountedMemory>* png_icon_data,
128 GURL* icon_url, 152 GURL* icon_url,
129 IconType* icon_type); 153 IconType* icon_type);
130 154
155 // Gets the icon_url, icon_type and sizes for the specified |icon_id|.
156 bool GetFaviconHeader(FaviconID icon_id,
157 GURL* icon_url,
158 IconType* icon_type,
159 std::string* sizes);
160
131 // Adds the favicon URL and icon type to the favicon db, returning its id. 161 // Adds the favicon URL and icon type to the favicon db, returning its id.
132 FaviconID AddFavicon(const GURL& icon_url, IconType icon_type); 162 FaviconID AddFavicon(const GURL& icon_url, IconType icon_type);
133 163
164 // Adds a favicon with a single bitmap. This call is equivalent to calling
165 // AddFavicon, SetFaviconSizes, and AddFaviconBitmap.
166 FaviconID AddFavicon(const GURL& icon_url,
167 IconType icon_type,
168 const std::string& sizes,
169 const scoped_refptr<base::RefCountedMemory>& icon_data,
170 base::Time time,
171 const gfx::Size& pixel_size);
172
134 // Delete the favicon with the provided id. Returns false on failure 173 // Delete the favicon with the provided id. Returns false on failure
135 bool DeleteFavicon(FaviconID id); 174 bool DeleteFavicon(FaviconID id);
136 175
137 // Icon Mapping -------------------------------------------------------------- 176 // Icon Mapping --------------------------------------------------------------
138 // 177 //
139 // Returns true if there is a matched icon mapping for the given page and 178 // Returns true if there is a matched icon mapping for the given page and
140 // icon type. 179 // icon type.
141 // The matched icon mapping is returned in the icon_mapping parameter if it is 180 // The matched icon mapping is returned in the icon_mapping parameter if it is
142 // not NULL. 181 // not NULL.
143 bool GetIconMappingForPageURL(const GURL& page_url, 182 bool GetIconMappingForPageURL(const GURL& page_url,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 // each call of GetNextIconMapping(). 226 // each call of GetNextIconMapping().
188 sql::Statement statement_; 227 sql::Statement statement_;
189 228
190 DISALLOW_COPY_AND_ASSIGN(IconMappingEnumerator); 229 DISALLOW_COPY_AND_ASSIGN(IconMappingEnumerator);
191 }; 230 };
192 231
193 // Return all icon mappings of the given |icon_type|. 232 // Return all icon mappings of the given |icon_type|.
194 bool InitIconMappingEnumerator(IconType type, 233 bool InitIconMappingEnumerator(IconType type,
195 IconMappingEnumerator* enumerator); 234 IconMappingEnumerator* enumerator);
196 235
197 // Temporary IconMapping ----------------------------------------------------- 236 // Temporary Tables ---------------------------------------------------------
198 // 237 //
199 // Creates a temporary table to store icon mapping. Icon mapping will be 238 // Creates empty temporary tables for each of the tables in the thumbnail
200 // copied to this table by AddToTemporaryIconMappingTable() and then the 239 // database. Favicon data which is not copied into the temporary tables will
201 // original table will be dropped, leaving only those copied mapping 240 // 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 241 // most of the favicons when clearing history.
203 // clearing history. 242 bool InitTemporaryTables();
204 bool InitTemporaryIconMappingTable() { 243
205 return InitIconMappingTable(&db_, true); 244 // Replaces the main tables in the thumbnail database with the temporary
206 } 245 // tables created with InitTemporaryTables(). This means that any data not
246 // copied over will be deleted.
247 bool CommitTemporaryTables();
207 248
208 // Copies the given icon mapping from the "main" icon_mapping table to the 249 // Copies the given icon mapping from the "main" icon_mapping table to the
209 // temporary one. This is only valid in between calls to 250 // temporary one. This is only valid in between calls to
210 // InitTemporaryIconMappingTable() 251 // InitTemporaryTables() and CommitTemporaryTables().
211 // and CommitTemporaryIconMappingTable().
212 // 252 //
213 // The ID of the favicon will change when this copy takes place. The new ID 253 // The ID of the favicon will change when this copy takes place. The new ID
214 // is returned, or 0 on failure. 254 // is returned, or 0 on failure.
215 IconMappingID AddToTemporaryIconMappingTable(const GURL& page_url, 255 IconMappingID AddToTemporaryIconMappingTable(const GURL& page_url,
216 const FaviconID icon_id); 256 const FaviconID icon_id);
217 257
218 // Replaces the main icon mapping table with the temporary table created by 258 // Copies the given favicon and associated favicon bitmaps from the "main"
219 // InitTemporaryIconMappingTable(). This will mean all icon mapping not copied 259 // favicon and favicon_bitmaps tables to the temporary ones. This is only
220 // over will be deleted. Returns true on success. 260 // valid in between calls to InitTemporaryTables() and
221 bool CommitTemporaryIconMappingTable(); 261 // 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 // 262 //
237 // The ID of the favicon will change when this copy takes place. The new ID 263 // The ID of the favicon will change when this copy takes place. The new ID
238 // is returned, or 0 on failure. 264 // is returned, or 0 on failure.
239 FaviconID CopyToTemporaryFaviconTable(FaviconID source); 265 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 266
246 // Returns true iff the thumbnails table exists. 267 // Returns true iff the thumbnails table exists.
247 // Migrating to TopSites is dropping the thumbnails table. 268 // Migrating to TopSites is dropping the thumbnails table.
248 bool NeedsMigrationToTopSites(); 269 bool NeedsMigrationToTopSites();
249 270
250 // Renames the database file and drops the Thumbnails table. 271 // Renames the database file and drops the Thumbnails table.
251 bool RenameAndDropThumbnails(const FilePath& old_db_file, 272 bool RenameAndDropThumbnails(const FilePath& old_db_file,
252 const FilePath& new_db_file); 273 const FilePath& new_db_file);
253 274
254 private: 275 private:
255 friend class ExpireHistoryBackend; 276 friend class ExpireHistoryBackend;
256 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, 277 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest,
257 GetFaviconAfterMigrationToTopSites); 278 GetFaviconAfterMigrationToTopSites);
258 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion4); 279 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion4);
259 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion5); 280 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion5);
281 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion6);
260 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MigrationIconMapping); 282 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MigrationIconMapping);
261 283
262 // Creates the thumbnail table, returning true if the table already exists 284 // Creates the thumbnail table, returning true if the table already exists
263 // or was successfully created. 285 // or was successfully created.
264 bool InitThumbnailTable(); 286 bool InitThumbnailTable();
265 287
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. 288 // Helper function to handle cleanup on upgrade failures.
276 sql::InitStatus CantUpgradeToVersion(int cur_version); 289 sql::InitStatus CantUpgradeToVersion(int cur_version);
277 290
278 // Adds support for the new metadata on web page thumbnails. 291 // Adds support for the new metadata on web page thumbnails.
279 bool UpgradeToVersion3(); 292 bool UpgradeToVersion3();
280 293
281 // Adds support for the icon_type in favicon table. 294 // Adds support for the icon_type in favicon table.
282 bool UpgradeToVersion4(); 295 bool UpgradeToVersion4();
283 296
284 // Adds support for sizes in favicon table. 297 // Adds support for sizes in favicon table.
285 bool UpgradeToVersion5(); 298 bool UpgradeToVersion5();
286 299
300 // Adds support for size in favicons table and removes sizes column.
301 bool UpgradeToVersion6();
302
287 // Migrates the icon mapping data from URL database to Thumbnail database. 303 // Migrates the icon mapping data from URL database to Thumbnail database.
288 // Return whether the migration succeeds. 304 // Return whether the migration succeeds.
289 bool MigrateIconMappingData(URLDatabase* url_db); 305 bool MigrateIconMappingData(URLDatabase* url_db);
290 306
307 // Creates the favicon table, returning true if the table already exists,
308 // or was successfully created. |is_temporary| will be false when generating
309 // the "regular" favicons table. The expirer sets this to true to generate the
310 // temporary table, which will have a different name but the same schema.
311 // |db| is the connection to use for initializing the table.
312 // A different connection is used in RenameAndDropThumbnails, when we
313 // need to copy the favicons between two database files.
314 bool InitFaviconsTable(sql::Connection* db, bool is_temporary);
315
291 // Creates the index over the favicon table. This will be called during 316 // Creates the index over the favicon table. This will be called during
292 // initialization after the table is created. This is a separate function 317 // initialization after the table is created. This is a separate function
293 // because it is used by SwapFaviconTables to create an index over the 318 // because it is used by SwapFaviconTables to create an index over the
294 // newly-renamed favicons table (formerly the temporary table with no index). 319 // newly-renamed favicons table (formerly the temporary table with no index).
295 bool InitFaviconsIndex(); 320 bool InitFaviconsIndex();
296 321
322 // Creates the favicon_bitmaps table, return true if the table already exists
323 // or was successfully created.
324 bool InitFaviconBitmapsTable(sql::Connection* db, bool is_temporary);
325
326 // Creates the index over the favicon_bitmaps table. This will be called
327 // during initialization after the table is created. This is a separate
328 // function because it is used by CommitTemporaryTables to create an
329 // index over the newly-renamed favicon_bitmaps table (formerly the temporary
330 // table with no index).
331 bool InitFaviconBitmapsIndex();
332
297 // Creates the icon_map table, return true if the table already exists or was 333 // Creates the icon_map table, return true if the table already exists or was
298 // successfully created. 334 // successfully created.
299 bool InitIconMappingTable(sql::Connection* db, bool is_temporary); 335 bool InitIconMappingTable(sql::Connection* db, bool is_temporary);
300 336
301 // Creates the index over the icon_mapping table, This will be called during 337 // 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 338 // initialization after the table is created. This is a separate function
303 // because it is used by CommitTemporaryIconMappingTable to create an index 339 // because it is used by CommitTemporaryIconMappingTable to create an index
304 // over the newly-renamed icon_mapping table (formerly the temporary table 340 // over the newly-renamed icon_mapping table (formerly the temporary table
305 // with no index). 341 // with no index).
306 bool InitIconMappingIndex(); 342 bool InitIconMappingIndex();
(...skipping 18 matching lines...) Expand all
325 const HistoryPublisher* history_publisher_; 361 const HistoryPublisher* history_publisher_;
326 362
327 // True if migration to TopSites has been done and the thumbnails 363 // True if migration to TopSites has been done and the thumbnails
328 // table should not be used. 364 // table should not be used.
329 bool use_top_sites_; 365 bool use_top_sites_;
330 }; 366 };
331 367
332 } // namespace history 368 } // namespace history
333 369
334 #endif // CHROME_BROWSER_HISTORY_THUMBNAIL_DATABASE_H_ 370 #endif // CHROME_BROWSER_HISTORY_THUMBNAIL_DATABASE_H_
OLDNEW
« no previous file with comments | « chrome/browser/history/history_types.cc ('k') | chrome/browser/history/thumbnail_database.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698