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 |
11 #include "base/basictypes.h" | 11 #include "base/basictypes.h" |
12 #include "base/callback.h" | 12 #include "base/callback.h" |
13 #include "base/file_path.h" | 13 #include "base/file_path.h" |
14 #include "base/memory/ref_counted.h" | 14 #include "base/memory/ref_counted.h" |
15 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
16 #include "base/observer_list_threadsafe.h" | 16 #include "base/observer_list_threadsafe.h" |
17 #include "base/string16.h" | 17 #include "base/string16.h" |
18 #include "chrome/browser/cancelable_request.h" | 18 #include "chrome/browser/cancelable_request.h" |
19 #include "chrome/browser/favicon/favicon_service.h" | 19 #include "chrome/browser/favicon/favicon_service.h" |
20 #include "chrome/browser/history/history_types.h" | 20 #include "chrome/browser/history/history_types.h" |
21 #include "chrome/browser/profiles/refcounted_profile_keyed_service.h" | 21 #include "chrome/browser/profiles/refcounted_profile_keyed_service.h" |
22 #include "chrome/browser/search_engines/template_url_id.h" | 22 #include "chrome/browser/search_engines/template_url_id.h" |
23 #include "chrome/common/ref_counted_util.h" | 23 #include "chrome/common/ref_counted_util.h" |
24 #include "content/public/browser/notification_observer.h" | 24 #include "content/public/browser/notification_observer.h" |
25 #include "content/public/browser/notification_registrar.h" | 25 #include "content/public/browser/notification_registrar.h" |
26 #include "content/public/common/page_transition_types.h" | 26 #include "content/public/common/page_transition_types.h" |
27 #include "sql/init_status.h" | 27 #include "sql/init_status.h" |
28 #include "ui/base/layout.h" | |
28 | 29 |
29 #if defined(OS_ANDROID) | 30 #if defined(OS_ANDROID) |
30 #include "chrome/browser/history/android/android_history_provider_service.h" | 31 #include "chrome/browser/history/android/android_history_provider_service.h" |
31 #endif | 32 #endif |
32 | 33 |
33 class BookmarkService; | 34 class BookmarkService; |
34 class FilePath; | 35 class FilePath; |
35 class GURL; | 36 class GURL; |
36 class HistoryURLProvider; | 37 class HistoryURLProvider; |
37 struct HistoryURLProviderParams; | 38 struct HistoryURLProviderParams; |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
682 // Notification from the backend that it has finished loading. Sends | 683 // Notification from the backend that it has finished loading. Sends |
683 // notification (NOTIFY_HISTORY_LOADED) and sets backend_loaded_ to true. | 684 // notification (NOTIFY_HISTORY_LOADED) and sets backend_loaded_ to true. |
684 void OnDBLoaded(int backend_id); | 685 void OnDBLoaded(int backend_id); |
685 | 686 |
686 // Favicon ------------------------------------------------------------------- | 687 // Favicon ------------------------------------------------------------------- |
687 | 688 |
688 // These favicon methods are exposed to the FaviconService. Instead of calling | 689 // These favicon methods are exposed to the FaviconService. Instead of calling |
689 // these methods directly you should call the respective method on the | 690 // these methods directly you should call the respective method on the |
690 // FaviconService. | 691 // FaviconService. |
691 | 692 |
692 // Used by the FaviconService to get a favicon from the history backend. | 693 // Used by FaviconService to get the favicon bitmaps from the history backend |
693 void GetFavicon(FaviconService::GetFaviconRequest* request, | 694 // which most closely match |desired_size_in_dip| x |desired_size_in_dip| and |
694 const GURL& icon_url, | 695 // |desired_scale_factors| for |icon_types|. The returned FaviconBitmapResults |
695 history::IconType icon_type); | 696 // will have at most one result for each of |desired_scale_factors|. If a |
697 // favicon bitmap is determined to be the best candidate for multiple scale | |
698 // factors there will be less results. | |
699 // If |icon_types| has several types, results for only a single type will be | |
700 // returned in the priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON, and | |
701 // FAVICON. |icon_types| can only have multiple IconTypes if | |
702 // |icon_types| == TOUCH_ICON | TOUCH_PRECOMPOSED_ICON. | |
703 void GetFavicons(FaviconService::GetFaviconRequest* request, | |
704 const std::vector<GURL>& icon_urls, | |
705 int icon_types, | |
706 int desired_size_in_dip, | |
707 const std::vector<ui::ScaleFactor>& desired_scale_factors); | |
696 | 708 |
697 // Used by the FaviconService to update the favicon mappings on the history | 709 // Used by the FaviconService to get favicons mapped to |page_url| for |
710 // |icon_types| which most closely match |desired_size_in_dip| and | |
711 // |desired_scale_factors|. The returned FaviconBitmapResults will have | |
712 // at most one result for each of |desired_scale_factors|. If a favicon | |
713 // bitmap is determined to be the best candidate for multiple scale factors | |
714 // there will be less results. | |
715 // If |icon_types| has several types, results for only a single type will be | |
716 // returned in the priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON, and | |
717 // FAVICON. | |
718 void GetFaviconsForURL( | |
719 FaviconService::GetFaviconRequest* request, | |
720 const GURL& page_url, | |
721 int icon_types, | |
722 int desired_size_in_dip, | |
723 const std::vector<ui::ScaleFactor>& desired_scale_factors); | |
724 | |
725 // Used by the FaviconService to get the favicon bitmap which most closely | |
726 // matches |desired_size_in_dip| and |desired_scale_factor| from the favicon | |
727 // at |id| from the history backend. | |
728 void GetFaviconForID(FaviconService::GetFaviconRequest* request, | |
729 history::FaviconID id, | |
730 int desired_size_in_dip, | |
731 ui::ScaleFactor desired_scale_factor); | |
732 | |
733 // Used by the FaviconService to replace the favicon mappings to |page_url| | |
734 // for |icon_types| on the history backend. | |
735 // Sample |icon_urls|: | |
736 // { ICON_URL1 -> TOUCH_ICON, known to the database, | |
737 // ICON_URL2 -> TOUCH_ICON, not known to the database, | |
738 // ICON_URL3 -> TOUCH_PRECOMPOSED_ICON, known to the database } | |
739 // The new mappings are computed from |icon_urls| by these rules: | |
740 // 1) Any urls in |icon_urls| which are not already known to the database are | |
741 // rejected. | |
742 // Sample new mappings to |page_url|: { ICON_URL1, ICON_URL3 } | |
743 // 2) If |icon_types| has multiple types, the mappings are set only for the | |
744 // largest icon type. | |
745 // Sample new mappings to |page_url|: { ICON_URL3 } | |
746 // |icon_types| can only have multiple IconTypes if | |
747 // |icon_types| == TOUCH_ICON | TOUCH_PRECOMPOSED_ICON. | |
748 // The favicon bitmaps which most closely match |desired_size_in_dip| | |
749 // and |desired_scale_factors| from the favicons which were just mapped | |
750 // to |page_url| are returned. | |
751 void UpdateFaviconMappingsAndFetch( | |
752 FaviconService::GetFaviconRequest* request, | |
753 const GURL& page_url, | |
754 const std::vector<GURL>& icon_urls, | |
755 int icon_types, | |
756 int desired_size_in_dip, | |
757 const std::vector<ui::ScaleFactor>& desired_scale_factors); | |
758 | |
759 // Used by the FaviconService to set a favicon for |page_url| at |icon_url|. | |
760 // The favicon will only be set if |icon_url| and |pixel_size| are consistent | |
761 // with the database's knowledge of the icons mapped to |page_url| and the | |
762 // sizes of the favicon bitmaps at |icon_url|. | |
763 // If neither |page_url| nor |icon_url| are known to the database, the favicon | |
764 // is added with an empty size such that the icon is fetched from the web | |
765 // when |page_url| is visited. | |
766 // TODO(pkotwicz): Remove this function once it is no longer required by | |
767 // sync. | |
768 void MergeFavicon( | |
sky
2012/09/04 20:52:29
I don't understand the use case for this, and espe
pkotwicz
2012/09/04 22:40:54
The use case for this is sync to use this function
| |
769 const GURL& page_url, | |
770 const GURL& icon_url, | |
771 history::IconType icon_type, | |
772 scoped_refptr<base::RefCountedMemory> bitmap_data, | |
773 const gfx::Size& pixel_size); | |
774 | |
775 // Used by the FaviconService to set the favicons for a page on the history | |
698 // backend. | 776 // backend. |
699 void UpdateFaviconMappingAndFetch(FaviconService::GetFaviconRequest* request, | 777 // |favicon_bitmap_data| is a listing of additional favicon bitmaps to store |
700 const GURL& page_url, | 778 // for |page_url|. |
701 const GURL& icon_url, | 779 // |icon_url_sizes| is a mapping of all the icon urls of favicons available |
702 history::IconType icon_type); | 780 // for |page_url| to the sizes that those favicons are available from the web. |
703 | 781 // |favicon_bitmap_data| does not need to have entries for all the icon urls |
704 // Used by the FaviconService to get a favicon from the history backend. | 782 // or sizes listed in |icon_url_sizes|. However, the icon urls and favicon |
705 void GetFaviconForURL(FaviconService::GetFaviconRequest* request, | 783 // sizes in |favicon_bitmap_data| must be a subset of |icon_url_sizes|. It is |
706 const GURL& page_url, | 784 // important that |icon_url_sizes| be complete as mappings to favicons whose |
707 int icon_types); | 785 // icon url or pixel size is not in |icon_url_sizes| will be deleted. |
708 | 786 // |expired| and |icon_type| fields in FaviconBitmapData are ignored. |
709 // Used by the FaviconService to get a favicon from the history backend. | 787 void SetFavicons( |
710 void GetFaviconForID(FaviconService::GetFaviconRequest* request, | 788 const GURL& page_url, |
711 history::FaviconID id); | 789 history::IconType icon_type, |
790 const std::vector<history::FaviconBitmapData>& favicon_bitmap_data, | |
791 const history::IconURLSizesMap& icon_url_sizes); | |
712 | 792 |
713 // Used by the FaviconService to mark the favicon for the page as being out | 793 // Used by the FaviconService to mark the favicon for the page as being out |
714 // of date. | 794 // of date. |
715 void SetFaviconOutOfDateForPage(const GURL& page_url); | 795 void SetFaviconsOutOfDateForPage(const GURL& page_url); |
716 | 796 |
717 // Used by the FaviconService to clone favicons from one page to another, | 797 // Used by the FaviconService to clone favicons from one page to another, |
718 // provided that other page does not already have favicons. | 798 // provided that other page does not already have favicons. |
719 void CloneFavicon(const GURL& old_page_url, const GURL& new_page_url); | 799 void CloneFavicons(const GURL& old_page_url, const GURL& new_page_url); |
720 | 800 |
721 // Used by the FaviconService for importing many favicons for many pages at | 801 // Used by the FaviconService for importing many favicons for many pages at |
722 // once. The pages must exist, any favicon sets for unknown pages will be | 802 // once. The pages must exist, any favicon sets for unknown pages will be |
723 // discarded. Existing favicons will not be overwritten. | 803 // discarded. Existing favicons will not be overwritten. |
724 void SetImportedFavicons( | 804 void SetImportedFavicons( |
725 const std::vector<history::ImportedFaviconUsage>& favicon_usage); | 805 const std::vector<history::ImportedFaviconUsage>& favicon_usage); |
726 | 806 |
727 // Used by the FaviconService to set the favicon for a page on the history | |
728 // backend. | |
729 void SetFavicon(const GURL& page_url, | |
730 const GURL& icon_url, | |
731 const std::vector<unsigned char>& image_data, | |
732 history::IconType icon_type); | |
733 | |
734 | |
735 // Sets the in-memory URL database. This is called by the backend once the | 807 // Sets the in-memory URL database. This is called by the backend once the |
736 // database is loaded to make it available. | 808 // database is loaded to make it available. |
737 void SetInMemoryBackend(int backend_id, | 809 void SetInMemoryBackend(int backend_id, |
738 history::InMemoryHistoryBackend* mem_backend); | 810 history::InMemoryHistoryBackend* mem_backend); |
739 | 811 |
740 // Called by our BackendDelegate when there is a problem reading the database. | 812 // Called by our BackendDelegate when there is a problem reading the database. |
741 void NotifyProfileError(int backend_id, sql::InitStatus init_status); | 813 void NotifyProfileError(int backend_id, sql::InitStatus init_status); |
742 | 814 |
743 // Call to schedule a given task for running on the history thread with the | 815 // Call to schedule a given task for running on the history thread with the |
744 // specified priority. The task will have ownership taken. | 816 // specified priority. The task will have ownership taken. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
841 LoadBackendIfNecessary(); | 913 LoadBackendIfNecessary(); |
842 if (consumer) | 914 if (consumer) |
843 AddRequest(request, consumer); | 915 AddRequest(request, consumer); |
844 ScheduleTask(priority, | 916 ScheduleTask(priority, |
845 base::Bind(func, history_backend_.get(), | 917 base::Bind(func, history_backend_.get(), |
846 scoped_refptr<RequestType>(request), | 918 scoped_refptr<RequestType>(request), |
847 a, b, c, d)); | 919 a, b, c, d)); |
848 return request->handle(); | 920 return request->handle(); |
849 } | 921 } |
850 | 922 |
923 template<typename BackendFunc, | |
924 class RequestType, // Descendant of CancelableRequstBase. | |
925 typename ArgA, | |
926 typename ArgB, | |
927 typename ArgC, | |
928 typename ArgD, | |
929 typename ArgE> | |
930 Handle Schedule(SchedulePriority priority, | |
931 BackendFunc func, // Function to call on the HistoryBackend. | |
932 CancelableRequestConsumerBase* consumer, | |
933 RequestType* request, | |
934 const ArgA& a, | |
935 const ArgB& b, | |
936 const ArgC& c, | |
937 const ArgD& d, | |
938 const ArgE& e) { | |
939 DCHECK(thread_) << "History service being called after cleanup"; | |
940 LoadBackendIfNecessary(); | |
941 if (consumer) | |
942 AddRequest(request, consumer); | |
943 ScheduleTask(priority, | |
944 base::Bind(func, history_backend_.get(), | |
945 scoped_refptr<RequestType>(request), | |
946 a, b, c, d, e)); | |
947 return request->handle(); | |
948 } | |
949 | |
851 // ScheduleAndForget --------------------------------------------------------- | 950 // ScheduleAndForget --------------------------------------------------------- |
852 // | 951 // |
853 // Functions for scheduling operations on the history thread that do not need | 952 // Functions for scheduling operations on the history thread that do not need |
854 // any callbacks and are not cancelable. | 953 // any callbacks and are not cancelable. |
855 | 954 |
856 template<typename BackendFunc> | 955 template<typename BackendFunc> |
857 void ScheduleAndForget(SchedulePriority priority, | 956 void ScheduleAndForget(SchedulePriority priority, |
858 BackendFunc func) { // Function to call on backend. | 957 BackendFunc func) { // Function to call on backend. |
859 DCHECK(thread_) << "History service being called after cleanup"; | 958 DCHECK(thread_) << "History service being called after cleanup"; |
860 LoadBackendIfNecessary(); | 959 LoadBackendIfNecessary(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
901 const ArgA& a, | 1000 const ArgA& a, |
902 const ArgB& b, | 1001 const ArgB& b, |
903 const ArgC& c, | 1002 const ArgC& c, |
904 const ArgD& d) { | 1003 const ArgD& d) { |
905 DCHECK(thread_) << "History service being called after cleanup"; | 1004 DCHECK(thread_) << "History service being called after cleanup"; |
906 LoadBackendIfNecessary(); | 1005 LoadBackendIfNecessary(); |
907 ScheduleTask(priority, base::Bind(func, history_backend_.get(), | 1006 ScheduleTask(priority, base::Bind(func, history_backend_.get(), |
908 a, b, c, d)); | 1007 a, b, c, d)); |
909 } | 1008 } |
910 | 1009 |
1010 template<typename BackendFunc, | |
1011 typename ArgA, | |
1012 typename ArgB, | |
1013 typename ArgC, | |
1014 typename ArgD, | |
1015 typename ArgE> | |
1016 void ScheduleAndForget(SchedulePriority priority, | |
1017 BackendFunc func, // Function to call on backend. | |
1018 const ArgA& a, | |
1019 const ArgB& b, | |
1020 const ArgC& c, | |
1021 const ArgD& d, | |
1022 const ArgE& e) { | |
1023 DCHECK(thread_) << "History service being called after cleanup"; | |
1024 LoadBackendIfNecessary(); | |
1025 ScheduleTask(priority, base::Bind(func, history_backend_.get(), | |
1026 a, b, c, d, e)); | |
1027 } | |
1028 | |
911 content::NotificationRegistrar registrar_; | 1029 content::NotificationRegistrar registrar_; |
912 | 1030 |
913 // Some void primitives require some internal processing in the main thread | 1031 // Some void primitives require some internal processing in the main thread |
914 // when done. We use this internal consumer for this purpose. | 1032 // when done. We use this internal consumer for this purpose. |
915 CancelableRequestConsumer internal_consumer_; | 1033 CancelableRequestConsumer internal_consumer_; |
916 | 1034 |
917 // The thread used by the history service to run complicated operations. | 1035 // The thread used by the history service to run complicated operations. |
918 // |thread_| is NULL once |Cleanup| is NULL. | 1036 // |thread_| is NULL once |Cleanup| is NULL. |
919 base::Thread* thread_; | 1037 base::Thread* thread_; |
920 | 1038 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
953 // The index used for quick history lookups. | 1071 // The index used for quick history lookups. |
954 scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_; | 1072 scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_; |
955 | 1073 |
956 scoped_refptr<ObserverListThreadSafe<history::VisitDatabaseObserver> > | 1074 scoped_refptr<ObserverListThreadSafe<history::VisitDatabaseObserver> > |
957 visit_database_observers_; | 1075 visit_database_observers_; |
958 | 1076 |
959 DISALLOW_COPY_AND_ASSIGN(HistoryService); | 1077 DISALLOW_COPY_AND_ASSIGN(HistoryService); |
960 }; | 1078 }; |
961 | 1079 |
962 #endif // CHROME_BROWSER_HISTORY_HISTORY_H_ | 1080 #endif // CHROME_BROWSER_HISTORY_HISTORY_H_ |
OLD | NEW |