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_HISTORY_BACKEND_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H_ |
6 #define CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H_ | 6 #define CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
251 // | 251 // |
252 // Exposed for testing reasons. | 252 // Exposed for testing reasons. |
253 void GetPageThumbnailDirectly( | 253 void GetPageThumbnailDirectly( |
254 const GURL& page_url, | 254 const GURL& page_url, |
255 scoped_refptr<base::RefCountedBytes>* data); | 255 scoped_refptr<base::RefCountedBytes>* data); |
256 | 256 |
257 void MigrateThumbnailsDatabase(); | 257 void MigrateThumbnailsDatabase(); |
258 | 258 |
259 // Favicon ------------------------------------------------------------------- | 259 // Favicon ------------------------------------------------------------------- |
260 | 260 |
261 struct FaviconResults { | |
262 FaviconResults(); | |
263 ~FaviconResults(); | |
264 void Clear(); | |
265 | |
266 std::vector<history::FaviconBitmapResult> bitmap_results; | |
267 IconURLSizesMap size_map; | |
268 }; | |
269 | |
270 void GetFavicons(const std::vector<GURL>& icon_urls, | 261 void GetFavicons(const std::vector<GURL>& icon_urls, |
271 int icon_types, | 262 int icon_types, |
272 int desired_size_in_dip, | 263 int desired_size_in_dip, |
273 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 264 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
274 FaviconResults* results); | 265 std::vector<FaviconBitmapResult>* bitmap_results); |
275 | 266 |
276 void GetFaviconsForURL( | 267 void GetFaviconsForURL( |
277 const GURL& page_url, | 268 const GURL& page_url, |
278 int icon_types, | 269 int icon_types, |
279 int desired_size_in_dip, | 270 int desired_size_in_dip, |
280 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 271 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
281 FaviconResults* results); | 272 std::vector<FaviconBitmapResult>* bitmap_results); |
282 | 273 |
283 void GetFaviconForID( | 274 void GetFaviconForID( |
284 FaviconID favicon_id, | 275 FaviconID favicon_id, |
285 int desired_size_in_dip, | 276 int desired_size_in_dip, |
286 ui::ScaleFactor desired_scale_factor, | 277 ui::ScaleFactor desired_scale_factor, |
287 FaviconResults* results); | 278 std::vector<FaviconBitmapResult>* bitmap_results); |
288 | 279 |
289 void UpdateFaviconMappingsAndFetch( | 280 void UpdateFaviconMappingsAndFetch( |
290 const GURL& page_url, | 281 const GURL& page_url, |
291 const std::vector<GURL>& icon_urls, | 282 const std::vector<GURL>& icon_urls, |
292 int icon_types, | 283 int icon_types, |
293 int desired_size_in_dip, | 284 int desired_size_in_dip, |
294 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 285 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
295 FaviconResults* results); | 286 std::vector<FaviconBitmapResult>* bitmap_results); |
296 | 287 |
297 void MergeFavicon(const GURL& page_url, | 288 void MergeFavicon(const GURL& page_url, |
298 const GURL& icon_url, | 289 const GURL& icon_url, |
299 IconType icon_type, | 290 IconType icon_type, |
300 scoped_refptr<base::RefCountedMemory> bitmap_data, | 291 scoped_refptr<base::RefCountedMemory> bitmap_data, |
301 const gfx::Size& pixel_size); | 292 const gfx::Size& pixel_size); |
302 | 293 |
303 void SetFavicons( | 294 void SetFavicons( |
304 const GURL& page_url, | 295 const GURL& page_url, |
305 IconType icon_type, | 296 IconType icon_type, |
306 const std::vector<FaviconBitmapData>& favicon_bitmap_data, | 297 const std::vector<FaviconBitmapData>& favicon_bitmap_data); |
307 const IconURLSizesMap& icon_url_sizes); | |
308 | 298 |
309 void SetFaviconsOutOfDateForPage(const GURL& page_url); | 299 void SetFaviconsOutOfDateForPage(const GURL& page_url); |
310 | 300 |
311 void CloneFavicons(const GURL& old_page_url, const GURL& new_page_url); | 301 void CloneFavicons(const GURL& old_page_url, const GURL& new_page_url); |
312 | 302 |
313 void SetImportedFavicons( | 303 void SetImportedFavicons( |
314 const std::vector<ImportedFaviconUsage>& favicon_usage); | 304 const std::vector<ImportedFaviconUsage>& favicon_usage); |
315 | 305 |
316 // Downloads ----------------------------------------------------------------- | 306 // Downloads ----------------------------------------------------------------- |
317 | 307 |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
509 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, AddVisitsSource); | 499 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, AddVisitsSource); |
510 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetMostRecentVisits); | 500 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, GetMostRecentVisits); |
511 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, RemoveVisitsSource); | 501 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, RemoveVisitsSource); |
512 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, RemoveVisitsTransitions); | 502 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, RemoveVisitsTransitions); |
513 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MigrationVisitSource); | 503 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MigrationVisitSource); |
514 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MigrationIconMapping); | 504 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MigrationIconMapping); |
515 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, | 505 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, |
516 SetFaviconMappingsForPageAndRedirects); | 506 SetFaviconMappingsForPageAndRedirects); |
517 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, | 507 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, |
518 SetFaviconMappingsForPageDuplicates); | 508 SetFaviconMappingsForPageDuplicates); |
519 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, SetFavicons); | |
520 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, SetFaviconsDeleteBitmaps); | 509 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, SetFaviconsDeleteBitmaps); |
521 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, SetFaviconsReplaceBitmapData); | 510 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, SetFaviconsReplaceBitmapData); |
522 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, | 511 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, |
523 SetFaviconsSameFaviconURLForTwoPages); | 512 SetFaviconsSameFaviconURLForTwoPages); |
524 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, | 513 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, |
525 UpdateFaviconMappingsAndFetchNoChange); | 514 UpdateFaviconMappingsAndFetchNoChange); |
526 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MergeFaviconPageURLNotInDB); | 515 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MergeFaviconPageURLNotInDB); |
527 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MergeFaviconPageURLInDB); | 516 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MergeFaviconPageURLInDB); |
528 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MergeFaviconMaxFaviconsPerPage); | 517 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, MergeFaviconMaxFaviconsPerPage); |
529 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, | 518 FRIEND_TEST_ALL_PREFIXES(HistoryBackendTest, |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
664 // If |page_url| is non-null, |icon_types| can be multiple icon types | 653 // If |page_url| is non-null, |icon_types| can be multiple icon types |
665 // only if |icon_types| == TOUCH_ICON | TOUCH_PRECOMPOSED_ICON. | 654 // only if |icon_types| == TOUCH_ICON | TOUCH_PRECOMPOSED_ICON. |
666 // If multiple icon types are specified, |page_url| will be mapped to the | 655 // If multiple icon types are specified, |page_url| will be mapped to the |
667 // icon URLs of the largest type available in the database. | 656 // icon URLs of the largest type available in the database. |
668 void UpdateFaviconMappingsAndFetchImpl( | 657 void UpdateFaviconMappingsAndFetchImpl( |
669 const GURL* page_url, | 658 const GURL* page_url, |
670 const std::vector<GURL>& icon_urls, | 659 const std::vector<GURL>& icon_urls, |
671 int icon_types, | 660 int icon_types, |
672 int desired_size_in_dip, | 661 int desired_size_in_dip, |
673 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 662 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
674 FaviconResults* results); | 663 std::vector<FaviconBitmapResult>* results); |
675 | 664 |
676 // Set the favicon bitmaps for |icon_id|. | 665 // Set the favicon bitmaps for |icon_id|. |
677 // For each entry in |favicon_bitmap_data|, if a favicon bitmap already | 666 // For each entry in |favicon_bitmap_data|, if a favicon bitmap already |
678 // exists at the entry's pixel size, replace the favicon bitmap's data with | 667 // exists at the entry's pixel size, replace the favicon bitmap's data with |
679 // the entry's bitmap data. Otherwise add a new favicon bitmap. | 668 // the entry's bitmap data. Otherwise add a new favicon bitmap. |
| 669 // Any favicon bitmaps already mapped to |icon_id| whose pixel sizes are not |
| 670 // in |favicon_bitmap_data| are deleted. |
680 // If not NULL, |favicon_bitmaps_changed| is set to whether any of the bitmap | 671 // If not NULL, |favicon_bitmaps_changed| is set to whether any of the bitmap |
681 // data at |icon_id| is changed as a result of calling this method. | 672 // data at |icon_id| is changed as a result of calling this method. |
682 // Computing |favicon_bitmaps_changed| requires additional database queries | 673 // Computing |favicon_bitmaps_changed| requires additional database queries |
683 // so should be avoided if unnecessary. | 674 // so should be avoided if unnecessary. |
684 void SetFaviconBitmaps( | 675 void SetFaviconBitmaps( |
685 FaviconID icon_id, | 676 FaviconID icon_id, |
686 const std::vector<FaviconBitmapData>& favicon_bitmap_data, | 677 const std::vector<FaviconBitmapData>& favicon_bitmap_data, |
687 bool* favicon_bitmaps_changed); | 678 bool* favicon_bitmaps_changed); |
688 | 679 |
689 // Returns true if |favicon_bitmap_data| and |icon_url_sizes| passed to | 680 // Returns true if |favicon_bitmap_data| passed to SetFavicons() is valid. |
690 // SetFavicons() are valid. | |
691 // Criteria: | 681 // Criteria: |
692 // 1) |icon_url_sizes| contains no more than | 682 // 1) |favicon_bitmap_data| contains no more than |
693 // kMaxFaviconsPerPage icon URLs. | 683 // kMaxFaviconsPerPage unique icon URLs. |
694 // kMaxFaviconBitmapsPerIconURL favicon sizes for each icon URL. | 684 // kMaxFaviconBitmapsPerIconURL favicon bitmaps for each icon URL. |
695 // 2) The icon URLs and favicon sizes of |favicon_bitmap_data| are a subset | 685 // 2) FaviconBitmapData::bitmap_data contains non NULL bitmap data. |
696 // of |icon_url_sizes|. | |
697 // 3) The favicon sizes for entries in |icon_url_sizes| which have associated | |
698 // data in |favicon_bitmap_data| is not history::GetDefaultFaviconSizes(). | |
699 // 4) FaviconBitmapData::bitmap_data contains non NULL bitmap data. | |
700 bool ValidateSetFaviconsParams( | 686 bool ValidateSetFaviconsParams( |
701 const std::vector<FaviconBitmapData>& favicon_bitmap_data, | 687 const std::vector<FaviconBitmapData>& favicon_bitmap_data) const; |
702 const IconURLSizesMap& icon_url_sizes) const; | |
703 | |
704 // Sets the sizes that the thumbnail database knows that the favicon at | |
705 // |icon_id| is available from the web. See history_types.h for a more | |
706 // detailed description of FaviconSizes. | |
707 // Deletes any favicon bitmaps currently mapped to |icon_id| whose pixel | |
708 // sizes are not contained in |favicon_sizes|. | |
709 // |favicon_bitmaps_deleted| is set to true if at least one favicon bitmap | |
710 // is deleted. | |
711 void SetFaviconSizes(FaviconID icon_id, | |
712 const FaviconSizes& favicon_sizes, | |
713 bool* favicon_bitmaps_deleted); | |
714 | 688 |
715 // Returns true if the bitmap data at |bitmap_id| equals |new_bitmap_data|. | 689 // Returns true if the bitmap data at |bitmap_id| equals |new_bitmap_data|. |
716 bool IsFaviconBitmapDataEqual( | 690 bool IsFaviconBitmapDataEqual( |
717 FaviconBitmapID bitmap_id, | 691 FaviconBitmapID bitmap_id, |
718 const scoped_refptr<base::RefCountedMemory>& new_bitmap_data); | 692 const scoped_refptr<base::RefCountedMemory>& new_bitmap_data); |
719 | 693 |
720 // Returns true if there are favicons for |page_url| and one of the types in | 694 // Returns true if there are favicons for |page_url| and one of the types in |
721 // |icon_types|. | 695 // |icon_types|. |
722 // |favicon_bitmap_results| is set to the favicon bitmaps which most closely | 696 // |favicon_bitmap_results| is set to the favicon bitmaps which most closely |
723 // match |desired_size_in_dip| and |desired_scale_factors|. If | 697 // match |desired_size_in_dip| and |desired_scale_factors|. If |
724 // |desired_size_in_dip| is 0, the largest favicon bitmap with one of the icon | 698 // |desired_size_in_dip| is 0, the largest favicon bitmap with one of the icon |
725 // types in |icon_types| is returned. If |icon_types| contains multiple icon | 699 // types in |icon_types| is returned. If |icon_types| contains multiple icon |
726 // types and there are several matched icon types in the database, results | 700 // types and there are several matched icon types in the database, results |
727 // will only be returned for a single icon type in the priority of | 701 // will only be returned for a single icon type in the priority of |
728 // TOUCH_PRECOMPOSED_ICON, TOUCH_ICON, and FAVICON. See the comment for | 702 // TOUCH_PRECOMPOSED_ICON, TOUCH_ICON, and FAVICON. See the comment for |
729 // GetFaviconResultsForBestMatch() for more details on how | 703 // GetFaviconResultsForBestMatch() for more details on how |
730 // |favicon_bitmap_results| is constructed. | 704 // |favicon_bitmap_results| is constructed. |
731 // |icon_url_sizes| is set to a mapping of all the icon URLs which are mapped | |
732 // to |page_url| to the sizes of the favicon bitmaps available at each icon | |
733 // URL on the web. | |
734 bool GetFaviconsFromDB( | 705 bool GetFaviconsFromDB( |
735 const GURL& page_url, | 706 const GURL& page_url, |
736 int icon_types, | 707 int icon_types, |
737 const int desired_size_in_dip, | 708 const int desired_size_in_dip, |
738 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 709 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
739 std::vector<FaviconBitmapResult>* favicon_bitmap_results, | 710 std::vector<FaviconBitmapResult>* favicon_bitmap_results); |
740 IconURLSizesMap* icon_url_sizes); | |
741 | 711 |
742 // Returns the favicon bitmaps which most closely match |desired_size_in_dip| | 712 // Returns the favicon bitmaps which most closely match |desired_size_in_dip| |
743 // and |desired_scale_factors| in |favicon_bitmap_results|. If | 713 // and |desired_scale_factors| in |favicon_bitmap_results|. If |
744 // |desired_size_in_dip| is 0, only the largest favicon bitmap is returned. | 714 // |desired_size_in_dip| is 0, only the largest favicon bitmap is returned. |
745 // Goodness is computed via SelectFaviconBitmapIDs(). It is computed on a | 715 // Goodness is computed via SelectFaviconBitmapIDs(). It is computed on a |
746 // per favicon id basis, thus all |favicon_bitmap_results| are guaranteed to | 716 // per favicon id basis, thus all |favicon_bitmap_results| are guaranteed to |
747 // be for the same FaviconID. |favicon_bitmap_results| will have at most one | 717 // be for the same FaviconID. |favicon_bitmap_results| will have at most one |
748 // entry for each desired scale factor. There will be less entries if the same | 718 // entry for each desired scale factor. There will be less entries if the same |
749 // favicon bitmap is the best result for multiple scale factors. | 719 // favicon bitmap is the best result for multiple scale factors. |
750 // Returns true if there were no errors. | 720 // Returns true if there were no errors. |
751 bool GetFaviconBitmapResultsForBestMatch( | 721 bool GetFaviconBitmapResultsForBestMatch( |
752 const std::vector<FaviconID>& candidate_favicon_ids, | 722 const std::vector<FaviconID>& candidate_favicon_ids, |
753 int desired_size_in_dip, | 723 int desired_size_in_dip, |
754 const std::vector<ui::ScaleFactor>& desired_scale_factors, | 724 const std::vector<ui::ScaleFactor>& desired_scale_factors, |
755 std::vector<FaviconBitmapResult>* favicon_bitmap_results); | 725 std::vector<FaviconBitmapResult>* favicon_bitmap_results); |
756 | 726 |
757 // Build mapping of the icon URLs for |favicon_ids| to the sizes of the | |
758 // favicon bitmaps available at each icon URL on the web. Favicon bitmaps | |
759 // might not be cached in the thumbnail database for any of the sizes in the | |
760 // returned map. See history_types.h for a more detailed description of | |
761 // IconURLSizesMap. | |
762 // Returns true if map was successfully built. | |
763 bool BuildIconURLSizesMap(const std::vector<FaviconID>& favicon_ids, | |
764 IconURLSizesMap* icon_url_sizes); | |
765 | |
766 // Maps the favicon ids in |icon_ids| to |page_url| (and all redirects) | 727 // Maps the favicon ids in |icon_ids| to |page_url| (and all redirects) |
767 // for |icon_type|. | 728 // for |icon_type|. |
768 // Returns true if the mappings for the page or any of its redirects were | 729 // Returns true if the mappings for the page or any of its redirects were |
769 // changed. | 730 // changed. |
770 bool SetFaviconMappingsForPageAndRedirects( | 731 bool SetFaviconMappingsForPageAndRedirects( |
771 const GURL& page_url, | 732 const GURL& page_url, |
772 IconType icon_type, | 733 IconType icon_type, |
773 const std::vector<FaviconID>& icon_ids); | 734 const std::vector<FaviconID>& icon_ids); |
774 | 735 |
775 // Maps the favicon ids in |icon_ids| to |page_url| for |icon_type|. | 736 // Maps the favicon ids in |icon_ids| to |page_url| for |icon_type|. |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
915 // Used to provide the Android ContentProvider APIs. | 876 // Used to provide the Android ContentProvider APIs. |
916 scoped_ptr<AndroidProviderBackend> android_provider_backend_; | 877 scoped_ptr<AndroidProviderBackend> android_provider_backend_; |
917 #endif | 878 #endif |
918 | 879 |
919 DISALLOW_COPY_AND_ASSIGN(HistoryBackend); | 880 DISALLOW_COPY_AND_ASSIGN(HistoryBackend); |
920 }; | 881 }; |
921 | 882 |
922 } // namespace history | 883 } // namespace history |
923 | 884 |
924 #endif // CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H_ | 885 #endif // CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H_ |
OLD | NEW |