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_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_HISTORY_H_ |
6 #define CHROME_BROWSER_HISTORY_HISTORY_H_ | 6 #define CHROME_BROWSER_HISTORY_HISTORY_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
679 // Notification from the backend that it has finished loading. Sends | 679 // Notification from the backend that it has finished loading. Sends |
680 // notification (NOTIFY_HISTORY_LOADED) and sets backend_loaded_ to true. | 680 // notification (NOTIFY_HISTORY_LOADED) and sets backend_loaded_ to true. |
681 void OnDBLoaded(int backend_id); | 681 void OnDBLoaded(int backend_id); |
682 | 682 |
683 // Favicon ------------------------------------------------------------------- | 683 // Favicon ------------------------------------------------------------------- |
684 | 684 |
685 // These favicon methods are exposed to the FaviconService. Instead of calling | 685 // These favicon methods are exposed to the FaviconService. Instead of calling |
686 // these methods directly you should call the respective method on the | 686 // these methods directly you should call the respective method on the |
687 // FaviconService. | 687 // FaviconService. |
688 | 688 |
689 // Used by the FaviconService to get a favicon from the history backend. | 689 // Used by the FaviconService to get the favicon bitmap from the history |
690 void GetFavicon(FaviconService::GetFaviconRequest* request, | 690 // backend whose size is closest to |pixel_size|. |
691 const GURL& icon_url, | 691 void GetFaviconClosestToSize(FaviconService::GetFaviconRequest* request, |
| 692 const GURL& icon_url, |
| 693 history::IconType icon_type, |
| 694 const gfx::Size& pixel_size); |
| 695 |
| 696 // Used by FaviconService to get all the favicon bitmaps from the history |
| 697 // backend for the favicons at |icon_urls|. |
| 698 void GetFavicons(FaviconService::GetFaviconRequest* request, |
| 699 const std::vector<GURL>& icon_urls, |
692 history::IconType icon_type); | 700 history::IconType icon_type); |
693 | 701 |
| 702 // Used by the FaviconService to get the favicon bitmap mapped to |page_url| |
| 703 // from the history backend whose size is closest to |pixel_size|. |
| 704 void GetFaviconForURLClosestToSize(FaviconService::GetFaviconRequest* request, |
| 705 const GURL& page_url, |
| 706 int icon_types, |
| 707 const gfx::Size& pixel_size); |
| 708 |
| 709 // Used by the FaviconService to get all the favicons mapped to |page_url| |
| 710 // from the history backend. |
| 711 void GetFaviconsForURL(FaviconService::GetFaviconRequest* request, |
| 712 const GURL& page_url, |
| 713 int icon_types); |
| 714 |
694 // Used by the FaviconService to update the favicon mappings on the history | 715 // Used by the FaviconService to update the favicon mappings on the history |
695 // backend. | 716 // backend. |
696 void UpdateFaviconMappingAndFetch(FaviconService::GetFaviconRequest* request, | 717 void UpdateFaviconMappingsAndFetch(FaviconService::GetFaviconRequest* request, |
697 const GURL& page_url, | 718 const GURL& page_url, |
698 const GURL& icon_url, | 719 const std::vector<GURL>& icon_urls, |
699 history::IconType icon_type); | 720 history::IconType icon_type); |
700 | 721 |
701 // Used by the FaviconService to get a favicon from the history backend. | 722 // Used by the FaviconService to add favicons for a page on the history |
702 void GetFaviconForURL(FaviconService::GetFaviconRequest* request, | 723 // backend. This method queries for the IconURLSizesMap from |page_url|. If |
703 const GURL& page_url, | 724 // unavailable, a guess at what IconURLSizesMap should be is used. This |
704 int icon_types); | 725 // function is inefficient. Do not use if at all possible. |
| 726 // TODO(pkotwicz): Remove this function once it is no longer required by |
| 727 // sync. |
| 728 void AddFavicons(const GURL& page_url, |
| 729 history::IconType icon_type, |
| 730 const std::vector<history::FaviconDataElement>& elements); |
705 | 731 |
706 // Used by the FaviconService to get a favicon from the history backend. | 732 // Used by the FaviconService to set the favicons for a page on the history |
707 void GetFaviconForID(FaviconService::GetFaviconRequest* request, | 733 // backend. |
708 history::FaviconID id); | 734 // |elements| is a listing of additional favicon bitmaps to store for |
| 735 // |page_url|. |
| 736 // |icon_url_sizes| is a mapping of all the icon urls of favicons available |
| 737 // for |page_url| to the sizes that those favicons are available at from the |
| 738 // web. |elements| does not need to have entries for all the icon urls or |
| 739 // sizes listed in |icon_url_sizes|. However, the icon urls and sizes in |
| 740 // |elements| must be a subset of |icon_url_sizes|. It is important that |
| 741 // |icon_url_sizes| be complete as mappings to favicons whose icon url or |
| 742 // pixel size is not in |icon_url_sizes| will be deleted. |
| 743 void SetFavicons(const GURL& page_url, |
| 744 history::IconType icon_type, |
| 745 const std::vector<history::FaviconDataElement>& elements, |
| 746 const history::IconURLSizesMap& icon_url_sizes); |
709 | 747 |
710 // Used by the FaviconService to mark the favicon for the page as being out | 748 // Used by the FaviconService to mark the favicons for the page as being out |
711 // of date. | 749 // of date. |
712 void SetFaviconOutOfDateForPage(const GURL& page_url); | 750 void SetFaviconsOutOfDateForPage(const GURL& page_url); |
713 | 751 |
714 // Used by the FaviconService to clone favicons from one page to another, | 752 // Used by the FaviconService to clone favicons from one page to another, |
715 // provided that other page does not already have favicons. | 753 // provided that other page does not already have favicons. |
716 void CloneFavicon(const GURL& old_page_url, const GURL& new_page_url); | 754 void CloneFavicon(const GURL& old_page_url, const GURL& new_page_url); |
717 | 755 |
718 // Used by the FaviconService for importing many favicons for many pages at | 756 // Used by the FaviconService for importing many favicons for many pages at |
719 // once. The pages must exist, any favicon sets for unknown pages will be | 757 // once. The pages must exist, any favicon sets for unknown pages will be |
720 // discarded. Existing favicons will not be overwritten. | 758 // discarded. Existing favicons will not be overwritten. |
721 void SetImportedFavicons( | 759 void SetImportedFavicons( |
722 const std::vector<history::ImportedFaviconUsage>& favicon_usage); | 760 const std::vector<history::ImportedFaviconUsage>& favicon_usage); |
723 | 761 |
724 // Used by the FaviconService to set the favicon for a page on the history | |
725 // backend. | |
726 void SetFavicon(const GURL& page_url, | |
727 const GURL& icon_url, | |
728 const std::vector<unsigned char>& image_data, | |
729 history::IconType icon_type); | |
730 | |
731 | |
732 // Sets the in-memory URL database. This is called by the backend once the | 762 // Sets the in-memory URL database. This is called by the backend once the |
733 // database is loaded to make it available. | 763 // database is loaded to make it available. |
734 void SetInMemoryBackend(int backend_id, | 764 void SetInMemoryBackend(int backend_id, |
735 history::InMemoryHistoryBackend* mem_backend); | 765 history::InMemoryHistoryBackend* mem_backend); |
736 | 766 |
737 // Called by our BackendDelegate when there is a problem reading the database. | 767 // Called by our BackendDelegate when there is a problem reading the database. |
738 void NotifyProfileError(int backend_id, sql::InitStatus init_status); | 768 void NotifyProfileError(int backend_id, sql::InitStatus init_status); |
739 | 769 |
740 // Call to schedule a given task for running on the history thread with the | 770 // Call to schedule a given task for running on the history thread with the |
741 // specified priority. The task will have ownership taken. | 771 // specified priority. The task will have ownership taken. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
838 LoadBackendIfNecessary(); | 868 LoadBackendIfNecessary(); |
839 if (consumer) | 869 if (consumer) |
840 AddRequest(request, consumer); | 870 AddRequest(request, consumer); |
841 ScheduleTask(priority, | 871 ScheduleTask(priority, |
842 base::Bind(func, history_backend_.get(), | 872 base::Bind(func, history_backend_.get(), |
843 scoped_refptr<RequestType>(request), | 873 scoped_refptr<RequestType>(request), |
844 a, b, c, d)); | 874 a, b, c, d)); |
845 return request->handle(); | 875 return request->handle(); |
846 } | 876 } |
847 | 877 |
| 878 template<typename BackendFunc, |
| 879 class RequestType, // Descendant of CancelableRequstBase. |
| 880 typename ArgA, |
| 881 typename ArgB, |
| 882 typename ArgC, |
| 883 typename ArgD, |
| 884 typename ArgE> |
| 885 Handle Schedule(SchedulePriority priority, |
| 886 BackendFunc func, // Function to call on the HistoryBackend. |
| 887 CancelableRequestConsumerBase* consumer, |
| 888 RequestType* request, |
| 889 const ArgA& a, |
| 890 const ArgB& b, |
| 891 const ArgC& c, |
| 892 const ArgD& d, |
| 893 const ArgE& e) { |
| 894 DCHECK(thread_) << "History service being called after cleanup"; |
| 895 LoadBackendIfNecessary(); |
| 896 if (consumer) |
| 897 AddRequest(request, consumer); |
| 898 ScheduleTask(priority, |
| 899 base::Bind(func, history_backend_.get(), |
| 900 scoped_refptr<RequestType>(request), |
| 901 a, b, c, d, e)); |
| 902 return request->handle(); |
| 903 } |
| 904 |
848 // ScheduleAndForget --------------------------------------------------------- | 905 // ScheduleAndForget --------------------------------------------------------- |
849 // | 906 // |
850 // Functions for scheduling operations on the history thread that do not need | 907 // Functions for scheduling operations on the history thread that do not need |
851 // any callbacks and are not cancelable. | 908 // any callbacks and are not cancelable. |
852 | 909 |
853 template<typename BackendFunc> | 910 template<typename BackendFunc> |
854 void ScheduleAndForget(SchedulePriority priority, | 911 void ScheduleAndForget(SchedulePriority priority, |
855 BackendFunc func) { // Function to call on backend. | 912 BackendFunc func) { // Function to call on backend. |
856 DCHECK(thread_) << "History service being called after cleanup"; | 913 DCHECK(thread_) << "History service being called after cleanup"; |
857 LoadBackendIfNecessary(); | 914 LoadBackendIfNecessary(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
898 const ArgA& a, | 955 const ArgA& a, |
899 const ArgB& b, | 956 const ArgB& b, |
900 const ArgC& c, | 957 const ArgC& c, |
901 const ArgD& d) { | 958 const ArgD& d) { |
902 DCHECK(thread_) << "History service being called after cleanup"; | 959 DCHECK(thread_) << "History service being called after cleanup"; |
903 LoadBackendIfNecessary(); | 960 LoadBackendIfNecessary(); |
904 ScheduleTask(priority, base::Bind(func, history_backend_.get(), | 961 ScheduleTask(priority, base::Bind(func, history_backend_.get(), |
905 a, b, c, d)); | 962 a, b, c, d)); |
906 } | 963 } |
907 | 964 |
| 965 template<typename BackendFunc, |
| 966 typename ArgA, |
| 967 typename ArgB, |
| 968 typename ArgC, |
| 969 typename ArgD, |
| 970 typename ArgE> |
| 971 void ScheduleAndForget(SchedulePriority priority, |
| 972 BackendFunc func, // Function to call on backend. |
| 973 const ArgA& a, |
| 974 const ArgB& b, |
| 975 const ArgC& c, |
| 976 const ArgD& d, |
| 977 const ArgE& e) { |
| 978 DCHECK(thread_) << "History service being called after cleanup"; |
| 979 LoadBackendIfNecessary(); |
| 980 ScheduleTask(priority, base::Bind(func, history_backend_.get(), |
| 981 a, b, c, d, e)); |
| 982 } |
| 983 |
908 content::NotificationRegistrar registrar_; | 984 content::NotificationRegistrar registrar_; |
909 | 985 |
910 // Some void primitives require some internal processing in the main thread | 986 // Some void primitives require some internal processing in the main thread |
911 // when done. We use this internal consumer for this purpose. | 987 // when done. We use this internal consumer for this purpose. |
912 CancelableRequestConsumer internal_consumer_; | 988 CancelableRequestConsumer internal_consumer_; |
913 | 989 |
914 // The thread used by the history service to run complicated operations. | 990 // The thread used by the history service to run complicated operations. |
915 // |thread_| is NULL once |Cleanup| is NULL. | 991 // |thread_| is NULL once |Cleanup| is NULL. |
916 base::Thread* thread_; | 992 base::Thread* thread_; |
917 | 993 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
950 // The index used for quick history lookups. | 1026 // The index used for quick history lookups. |
951 scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_; | 1027 scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_; |
952 | 1028 |
953 scoped_refptr<ObserverListThreadSafe<history::VisitDatabaseObserver> > | 1029 scoped_refptr<ObserverListThreadSafe<history::VisitDatabaseObserver> > |
954 visit_database_observers_; | 1030 visit_database_observers_; |
955 | 1031 |
956 DISALLOW_COPY_AND_ASSIGN(HistoryService); | 1032 DISALLOW_COPY_AND_ASSIGN(HistoryService); |
957 }; | 1033 }; |
958 | 1034 |
959 #endif // CHROME_BROWSER_HISTORY_HISTORY_H_ | 1035 #endif // CHROME_BROWSER_HISTORY_HISTORY_H_ |
OLD | NEW |