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 // Favicon Bitmaps ----------------------------------------------------------- | 100 // Favicon Bitmaps ----------------------------------------------------------- |
101 | 101 |
| 102 // Returns true if there are favicon bitmaps for |icon_id|. If |
| 103 // |bitmap_size_listing| is non NULL, sets it to a listing of the favicon |
| 104 // bitmap ids and their associated pixel sizes for the favicon with |
| 105 // |icon_id|. |
| 106 bool GetFaviconBitmapIDSizeList( |
| 107 FaviconID icon_id, |
| 108 std::vector<FaviconBitmapIDSize>* bitmap_id_size_list); |
| 109 |
102 // Returns true if there are any matched bitmaps for the given |icon_id|. All | 110 // 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. | 111 // matched results are returned if |favicon_bitmaps| is not NULL. |
104 bool GetFaviconBitmaps(FaviconID icon_id, | 112 bool GetFaviconBitmaps(FaviconID icon_id, |
105 std::vector<FaviconBitmap>* favicon_bitmaps); | 113 std::vector<FaviconBitmap>* favicon_bitmaps); |
106 | 114 |
| 115 // Gets the favicon id, last updated time, bitmap data, and pixel size of the |
| 116 // favicon bitmap at |bitmap_id|. |
| 117 // Returns true if successful. |
| 118 bool GetFaviconBitmap(FaviconBitmapID bitmap_id, |
| 119 base::Time* last_updated, |
| 120 scoped_refptr<base::RefCountedMemory>* png_icon_data, |
| 121 gfx::Size* pixel_size); |
| 122 |
| 123 // Sets the bitmap data and the last updated time for the favicon bitmap at |
| 124 // |bitmap_id|. Returns true if successful. |
| 125 bool SetFaviconBitmap(FaviconBitmapID bitmap_id, |
| 126 scoped_refptr<base::RefCountedMemory> icon_data, |
| 127 base::Time time); |
| 128 |
107 // Adds a bitmap component at |pixel_size| for the favicon with |icon_id|. | 129 // 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 | 130 // Only favicons representing a .ico file should have multiple favicon bitmaps |
109 // per favicon. | 131 // per favicon. |
110 // |icon_data| is the png encoded data. | 132 // |icon_data| is the png encoded data. |
111 // The |time| indicates the access time, and is used to detect when the | 133 // The |time| indicates the access time, and is used to detect when the |
112 // favicon should be refreshed. | 134 // favicon should be refreshed. |
113 // |pixel_size| is the pixel dimensions of |icon_data|. | 135 // |pixel_size| is the pixel dimensions of |icon_data|. |
114 // Returns the id of the added bitmap or 0 if unsuccessful. | 136 // Returns the id of the added bitmap or 0 if unsuccessful. |
115 FaviconBitmapID AddFaviconBitmap( | 137 FaviconBitmapID AddFaviconBitmap( |
116 FaviconID icon_id, | 138 FaviconID icon_id, |
117 const scoped_refptr<base::RefCountedMemory>& icon_data, | 139 const scoped_refptr<base::RefCountedMemory>& icon_data, |
118 base::Time time, | 140 base::Time time, |
119 const gfx::Size& pixel_size); | 141 const gfx::Size& pixel_size); |
120 | 142 |
121 // Deletes the favicon bitmaps for the favicon with with |icon_id|. | 143 // Deletes the favicon bitmap with |bitmap_id|. Returns true if successful. |
122 // Returns true if successful. | 144 bool DeleteFaviconBitmap(FaviconBitmapID bitmap_id); |
123 bool DeleteFaviconBitmapsForFavicon(FaviconID icon_id); | |
124 | 145 |
125 // Favicons ------------------------------------------------------------------ | 146 // Favicons ------------------------------------------------------------------ |
126 | 147 |
127 // Updates the sizes associated with a favicon to |sizes|. See the comment | 148 // Updates the sizes associated with a favicon to |sizes|. See comment at |
128 // at the top of the .cc file for the format of the |sizes| parameter. | 149 // top of the .ccc file for description of |sizes|. |
129 bool SetFaviconSizes(FaviconID icon_id, const std::string& sizes); | 150 bool SetFaviconSizes(FaviconID icon_id, const FaviconSizes& sizes); |
130 | 151 |
131 // Sets the the favicon as out of date. This will set |last_updated| for all | 152 // Sets the the favicon as out of date. This will set |last_updated| for all |
132 // of the bitmaps for |icon_id| to be out of date. | 153 // of the bitmaps for |icon_id| to be out of date. |
133 bool SetFaviconOutOfDate(FaviconID icon_id); | 154 bool SetFaviconOutOfDate(FaviconID icon_id); |
134 | 155 |
135 // Returns the id of the entry in the favicon database with the specified url | 156 // Returns the id of the entry in the favicon database with the specified url |
136 // and icon type. If |required_icon_type| contains multiple icon types and | 157 // and icon type. If |required_icon_type| contains multiple icon types and |
137 // there are more than one matched icon in database, only one icon will be | 158 // there are more than one matched icon in database, only one icon will be |
138 // returned in the priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON, and | 159 // returned in the priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON, and |
139 // FAVICON, and the icon type is returned in icon_type parameter if it is not | 160 // FAVICON. |
140 // NULL. | |
141 // Returns 0 if no entry exists for the specified url. | 161 // Returns 0 if no entry exists for the specified url. |
142 FaviconID GetFaviconIDForFaviconURL(const GURL& icon_url, | 162 FaviconID GetFaviconIDForFaviconURL(const GURL& icon_url, |
143 int required_icon_type, | 163 int required_icon_type); |
144 IconType* icon_type); | |
145 | |
146 // Gets the png encoded favicon, last updated time, icon_url and icon_type for | |
147 // the specified favicon id. | |
148 // TODO(pkotwicz): Remove this function. | |
149 bool GetFavicon(FaviconID icon_id, | |
150 base::Time* last_updated, | |
151 scoped_refptr<base::RefCountedMemory>* png_icon_data, | |
152 GURL* icon_url, | |
153 IconType* icon_type); | |
154 | 164 |
155 // Gets the icon_url, icon_type and sizes for the specified |icon_id|. | 165 // Gets the icon_url, icon_type and sizes for the specified |icon_id|. |
156 bool GetFaviconHeader(FaviconID icon_id, | 166 bool GetFaviconHeader(FaviconID icon_id, |
157 GURL* icon_url, | 167 GURL* icon_url, |
158 IconType* icon_type, | 168 IconType* icon_type, |
159 std::string* sizes); | 169 FaviconSizes* sizes); |
160 | 170 |
161 // Adds the favicon URL and icon type to the favicon db, returning its id. | 171 // Adds favicon with |icon_url| and |icon_type| to the favicon db, returning |
| 172 // its id. |
162 FaviconID AddFavicon(const GURL& icon_url, IconType icon_type); | 173 FaviconID AddFavicon(const GURL& icon_url, IconType icon_type); |
163 | 174 |
164 // Adds a favicon with a single bitmap. This call is equivalent to calling | 175 // Adds a favicon with a single bitmap. This call is equivalent to calling |
165 // AddFavicon, SetFaviconSizes, and AddFaviconBitmap. | 176 // AddFavicon, SetFaviconSizes, and AddFaviconBitmap. |
166 FaviconID AddFavicon(const GURL& icon_url, | 177 FaviconID AddFavicon(const GURL& icon_url, |
167 IconType icon_type, | 178 IconType icon_type, |
168 const std::string& sizes, | 179 const FaviconSizes& sizes, |
169 const scoped_refptr<base::RefCountedMemory>& icon_data, | 180 const scoped_refptr<base::RefCountedMemory>& icon_data, |
170 base::Time time, | 181 base::Time time, |
171 const gfx::Size& pixel_size); | 182 const gfx::Size& pixel_size); |
172 | 183 |
173 // Delete the favicon with the provided id. Returns false on failure | 184 // Delete the favicon with the provided id. Returns false on failure |
174 bool DeleteFavicon(FaviconID id); | 185 bool DeleteFavicon(FaviconID id); |
175 | 186 |
176 // Icon Mapping -------------------------------------------------------------- | 187 // Icon Mapping -------------------------------------------------------------- |
177 // | 188 // |
178 // Returns true if there is a matched icon mapping for the given page and | 189 // Returns true if there is a matched icon mapping for the given page and |
179 // icon type. | 190 // icon type. |
180 // The matched icon mapping is returned in the icon_mapping parameter if it is | 191 // The matched icon mapping is returned in the icon_mapping parameter if it is |
181 // not NULL. | 192 // not NULL. |
182 bool GetIconMappingForPageURL(const GURL& page_url, | 193 |
183 IconType required_icon_type, | 194 // Returns true if there are icon mappings for the given page and icon type. |
184 IconMapping* icon_mapping); | 195 // If |required_icon_types| contains multiple icon types and there is more |
| 196 // than one matched icon type in the database, icons of only a single type |
| 197 // will be returned in the priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON, |
| 198 // and FAVICON. |
| 199 // The matched icon mappings are returned in the |icon_mappings| parameter if |
| 200 // it is not NULL. |
| 201 bool GetIconMappingsForPageURL(const GURL& page_url, |
| 202 int required_icon_types, |
| 203 std::vector<IconMapping>* mapping_data); |
185 | 204 |
186 // Returns true if there is any matched icon mapping for the given page. | 205 // Returns true if there is any matched icon mapping for the given page. |
187 // All matched icon mappings are returned in descent order of IconType if | 206 // All matched icon mappings are returned in descent order of IconType if |
188 // mapping_data is not NULL. | 207 // mapping_data is not NULL. |
189 bool GetIconMappingsForPageURL(const GURL& page_url, | 208 bool GetIconMappingsForPageURL(const GURL& page_url, |
190 std::vector<IconMapping>* mapping_data); | 209 std::vector<IconMapping>* mapping_data); |
191 | 210 |
192 // Adds a mapping between the given page_url and icon_id. | 211 // Adds a mapping between the given page_url and icon_id. |
193 // Returns the new mapping id if the adding succeeds, otherwise 0 is returned. | 212 // Returns the new mapping id if the adding succeeds, otherwise 0 is returned. |
194 IconMappingID AddIconMapping(const GURL& page_url, FaviconID icon_id); | 213 IconMappingID AddIconMapping(const GURL& page_url, FaviconID icon_id); |
195 | 214 |
196 // Updates the page and icon mapping for the given mapping_id with the given | 215 // Updates the page and icon mapping for the given mapping_id with the given |
197 // icon_id. | 216 // icon_id. |
198 // Returns true if the update succeeded. | 217 // Returns true if the update succeeded. |
199 bool UpdateIconMapping(IconMappingID mapping_id, FaviconID icon_id); | 218 bool UpdateIconMapping(IconMappingID mapping_id, FaviconID icon_id); |
200 | 219 |
201 // Deletes the icon mapping entries for the given page url. | 220 // Deletes the icon mapping entries for the given page url. |
202 // Returns true if the deletion succeeded. | 221 // Returns true if the deletion succeeded. |
203 bool DeleteIconMappings(const GURL& page_url); | 222 bool DeleteIconMappings(const GURL& page_url); |
204 | 223 |
| 224 // Deletes the icon mapping with |mapping_id|. |
| 225 // Returns true if the deletion succeeded. |
| 226 bool DeleteIconMapping(IconMappingID mapping_id); |
| 227 |
205 // Checks whether a favicon is used by any URLs in the database. | 228 // Checks whether a favicon is used by any URLs in the database. |
206 bool HasMappingFor(FaviconID id); | 229 bool HasMappingFor(FaviconID id); |
207 | 230 |
208 // Clones the existing mappings from |old_page_url| if |new_page_url| has no | 231 // Clones the existing mappings from |old_page_url| if |new_page_url| has no |
209 // mappings. Otherwise, will leave mappings alone. | 232 // mappings. Otherwise, will leave mappings alone. |
210 bool CloneIconMapping(const GURL& old_page_url, const GURL& new_page_url); | 233 bool CloneIconMappings(const GURL& old_page_url, const GURL& new_page_url); |
211 | 234 |
212 // The class to enumerate icon mappings. Use InitIconMappingEnumerator to | 235 // The class to enumerate icon mappings. Use InitIconMappingEnumerator to |
213 // initialize. | 236 // initialize. |
214 class IconMappingEnumerator { | 237 class IconMappingEnumerator { |
215 public: | 238 public: |
216 IconMappingEnumerator(); | 239 IconMappingEnumerator(); |
217 ~IconMappingEnumerator(); | 240 ~IconMappingEnumerator(); |
218 | 241 |
219 // Get the next icon mapping, return false if no more are available. | 242 // Get the next icon mapping, return false if no more are available. |
220 bool GetNextIconMapping(IconMapping* icon_mapping); | 243 bool GetNextIconMapping(IconMapping* icon_mapping); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 bool RenameAndDropThumbnails(const FilePath& old_db_file, | 295 bool RenameAndDropThumbnails(const FilePath& old_db_file, |
273 const FilePath& new_db_file); | 296 const FilePath& new_db_file); |
274 | 297 |
275 private: | 298 private: |
276 friend class ExpireHistoryBackend; | 299 friend class ExpireHistoryBackend; |
277 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, | 300 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, |
278 GetFaviconAfterMigrationToTopSites); | 301 GetFaviconAfterMigrationToTopSites); |
279 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion4); | 302 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion4); |
280 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion5); | 303 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion5); |
281 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion6); | 304 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, UpgradeToVersion6); |
| 305 FRIEND_TEST_ALL_PREFIXES(ThumbnailDatabaseTest, FaviconSizesToAndFromString); |
282 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MigrationIconMapping); | 306 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MigrationIconMapping); |
283 | 307 |
284 // Creates the thumbnail table, returning true if the table already exists | 308 // Creates the thumbnail table, returning true if the table already exists |
285 // or was successfully created. | 309 // or was successfully created. |
286 bool InitThumbnailTable(); | 310 bool InitThumbnailTable(); |
287 | 311 |
288 // Helper function to handle cleanup on upgrade failures. | 312 // Helper function to handle cleanup on upgrade failures. |
289 sql::InitStatus CantUpgradeToVersion(int cur_version); | 313 sql::InitStatus CantUpgradeToVersion(int cur_version); |
290 | 314 |
291 // Adds support for the new metadata on web page thumbnails. | 315 // Adds support for the new metadata on web page thumbnails. |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 // Adds a mapping between the given page_url and icon_id; The mapping will be | 368 // Adds a mapping between the given page_url and icon_id; The mapping will be |
345 // added to temp_icon_mapping table if is_temporary is true. | 369 // added to temp_icon_mapping table if is_temporary is true. |
346 // Returns the new mapping id if the adding succeeds, otherwise 0 is returned. | 370 // Returns the new mapping id if the adding succeeds, otherwise 0 is returned. |
347 IconMappingID AddIconMapping(const GURL& page_url, | 371 IconMappingID AddIconMapping(const GURL& page_url, |
348 FaviconID icon_id, | 372 FaviconID icon_id, |
349 bool is_temporary); | 373 bool is_temporary); |
350 | 374 |
351 // Returns True if the current database is latest. | 375 // Returns True if the current database is latest. |
352 bool IsLatestVersion(); | 376 bool IsLatestVersion(); |
353 | 377 |
| 378 // Converts the vector representation of sizes as passed into SetFaviconSizes |
| 379 // to a string to store in the |favicons| database table. |
| 380 // Format: |
| 381 // Each widthxheight pair is separated by a space. |
| 382 // Width and height are separated by a space. |
| 383 // For instance, if sizes contains pixel sizes (16x16, 32x32), the |
| 384 // string representation is "16 16 32 32". |
| 385 static void FaviconSizesToDatabaseString(const FaviconSizes& sizes, |
| 386 std::string* sizes_string); |
| 387 |
| 388 // Converts the string representation of sizes as stored in the |favicons| |
| 389 // database table to a vector. |
| 390 // Returns true if there were no errors. |
| 391 static bool DatabaseStringToFaviconSizes(const std::string sizes_string, |
| 392 FaviconSizes* sizes); |
| 393 |
354 sql::Connection db_; | 394 sql::Connection db_; |
355 sql::MetaTable meta_table_; | 395 sql::MetaTable meta_table_; |
356 | 396 |
357 // This object is created and managed by the history backend. We maintain an | 397 // This object is created and managed by the history backend. We maintain an |
358 // opaque pointer to the object for our use. | 398 // opaque pointer to the object for our use. |
359 // This can be NULL if there are no indexers registered to receive indexing | 399 // This can be NULL if there are no indexers registered to receive indexing |
360 // data from us. | 400 // data from us. |
361 const HistoryPublisher* history_publisher_; | 401 const HistoryPublisher* history_publisher_; |
362 | 402 |
363 // True if migration to TopSites has been done and the thumbnails | 403 // True if migration to TopSites has been done and the thumbnails |
364 // table should not be used. | 404 // table should not be used. |
365 bool use_top_sites_; | 405 bool use_top_sites_; |
366 }; | 406 }; |
367 | 407 |
368 } // namespace history | 408 } // namespace history |
369 | 409 |
370 #endif // CHROME_BROWSER_HISTORY_THUMBNAIL_DATABASE_H_ | 410 #endif // CHROME_BROWSER_HISTORY_THUMBNAIL_DATABASE_H_ |
OLD | NEW |