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 all the favicon bitmaps from the history |
693 void GetFavicon(FaviconService::GetFaviconRequest* request, | 694 // backend for the favicons at |icon_urls|. |
694 const GURL& icon_url, | 695 void GetFavicons(FaviconService::GetFaviconRequest* request, |
695 history::IconType icon_type); | 696 const std::vector<GURL>& icon_urls, |
697 int icon_types, | |
698 int desired_size_in_dip, | |
699 const std::vector<ui::ScaleFactor>& desired_scale_factors); | |
696 | 700 |
697 // Used by the FaviconService to update the favicon mappings on the history | 701 // Used by the FaviconService to get all the favicons mapped to |page_url| |
698 // backend. | 702 // from the history backend. |
michaelbai
2012/09/04 21:18:53
From the comments it is not clear to me that, how
pkotwicz
2012/09/04 22:40:54
You cannot get all of the favicon bitmaps from thi
| |
699 void UpdateFaviconMappingAndFetch(FaviconService::GetFaviconRequest* request, | 703 void GetFaviconsForURL( |
700 const GURL& page_url, | 704 FaviconService::GetFaviconRequest* request, |
701 const GURL& icon_url, | 705 const GURL& page_url, |
702 history::IconType icon_type); | 706 int icon_types, |
703 | 707 int desired_size_in_dip, |
704 // Used by the FaviconService to get a favicon from the history backend. | 708 const std::vector<ui::ScaleFactor>& desired_scale_factors); |
705 void GetFaviconForURL(FaviconService::GetFaviconRequest* request, | |
706 const GURL& page_url, | |
707 int icon_types); | |
708 | 709 |
709 // Used by the FaviconService to get a favicon from the history backend. | 710 // Used by the FaviconService to get a favicon from the history backend. |
710 void GetFaviconForID(FaviconService::GetFaviconRequest* request, | 711 void GetFaviconForID(FaviconService::GetFaviconRequest* request, |
711 history::FaviconID id); | 712 history::FaviconID id, |
713 int desired_size_in_dip, | |
714 ui::ScaleFactor desired_scale_facot); | |
715 | |
716 // Used by the FaviconService to update the favicon mappings on the history | |
717 // backend for favicons of type FAVICON. | |
718 // |icon_urls| is a list of all the favicon URLs known for |page_url|. It is | |
719 // important for this list to be complete as any favicons mapped to | |
720 // |page_url| whose icon URL is not in |icon_urls| will be deleted. | |
michaelbai
2012/09/04 21:18:53
The comment didn't say how the parameters icon_typ
pkotwicz
2012/09/04 22:40:54
I have updated the comments in this file in patch
| |
721 void UpdateFaviconMappingsAndFetch( | |
722 FaviconService::GetFaviconRequest* request, | |
723 const GURL& page_url, | |
724 const std::vector<GURL>& icon_urls, | |
725 int icon_types, | |
726 int desired_size_in_dip, | |
727 const std::vector<ui::ScaleFactor>& desired_scale_factors); | |
728 | |
729 // Used by the FaviconService to add favicons for a page on the history | |
730 // backend. This method queries for the IconURLSizesMap from |page_url|. If | |
731 // unavailable, a guess at what IconURLSizesMap should be is used. This | |
732 // function is inefficient. Do not use if at all possible. | |
733 // TODO(pkotwicz): Remove this function once it is no longer required by | |
734 // sync. | |
735 void MergeFavicon( | |
736 const GURL& page_url, | |
737 const GURL& icon_url, | |
738 history::IconType icon_type, | |
739 scoped_refptr<base::RefCountedMemory> bitmap_data, | |
740 const gfx::Size& pixel_size); | |
741 | |
742 // Used by the FaviconService to set the favicons for a page on the history | |
743 // backend. | |
744 // |elements| is a listing of additional favicon bitmaps to store for | |
michaelbai
2012/09/04 21:18:53
There is no elements argument in method's definiti
| |
745 // |page_url|. | |
746 // |icon_url_sizes| is a mapping of all the icon urls of favicons available | |
747 // for |page_url| to the sizes that those favicons are available at from the | |
748 // web. |elements| does not need to have entries for all the icon urls or | |
749 // sizes listed in |icon_url_sizes|. However, the icon urls and sizes in | |
750 // |elements| must be a subset of |icon_url_sizes|. It is important that | |
751 // |icon_url_sizes| be complete as mappings to favicons whose icon url or | |
752 // pixel size is not in |icon_url_sizes| will be deleted. | |
753 void SetFavicons( | |
754 const GURL& page_url, | |
755 history::IconType icon_type, | |
756 const std::vector<history::FaviconBitmapData>& favicon_bitmap_data, | |
757 const history::IconURLSizesMap& icon_url_sizes); | |
712 | 758 |
713 // Used by the FaviconService to mark the favicon for the page as being out | 759 // Used by the FaviconService to mark the favicon for the page as being out |
714 // of date. | 760 // of date. |
715 void SetFaviconOutOfDateForPage(const GURL& page_url); | 761 void SetFaviconsOutOfDateForPage(const GURL& page_url); |
716 | 762 |
717 // Used by the FaviconService to clone favicons from one page to another, | 763 // Used by the FaviconService to clone favicons from one page to another, |
718 // provided that other page does not already have favicons. | 764 // provided that other page does not already have favicons. |
719 void CloneFavicon(const GURL& old_page_url, const GURL& new_page_url); | 765 void CloneFavicons(const GURL& old_page_url, const GURL& new_page_url); |
720 | 766 |
721 // Used by the FaviconService for importing many favicons for many pages at | 767 // 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 | 768 // once. The pages must exist, any favicon sets for unknown pages will be |
723 // discarded. Existing favicons will not be overwritten. | 769 // discarded. Existing favicons will not be overwritten. |
724 void SetImportedFavicons( | 770 void SetImportedFavicons( |
725 const std::vector<history::ImportedFaviconUsage>& favicon_usage); | 771 const std::vector<history::ImportedFaviconUsage>& favicon_usage); |
726 | 772 |
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 | 773 // Sets the in-memory URL database. This is called by the backend once the |
736 // database is loaded to make it available. | 774 // database is loaded to make it available. |
737 void SetInMemoryBackend(int backend_id, | 775 void SetInMemoryBackend(int backend_id, |
738 history::InMemoryHistoryBackend* mem_backend); | 776 history::InMemoryHistoryBackend* mem_backend); |
739 | 777 |
740 // Called by our BackendDelegate when there is a problem reading the database. | 778 // Called by our BackendDelegate when there is a problem reading the database. |
741 void NotifyProfileError(int backend_id, sql::InitStatus init_status); | 779 void NotifyProfileError(int backend_id, sql::InitStatus init_status); |
742 | 780 |
743 // Call to schedule a given task for running on the history thread with the | 781 // Call to schedule a given task for running on the history thread with the |
744 // specified priority. The task will have ownership taken. | 782 // specified priority. The task will have ownership taken. |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
841 LoadBackendIfNecessary(); | 879 LoadBackendIfNecessary(); |
842 if (consumer) | 880 if (consumer) |
843 AddRequest(request, consumer); | 881 AddRequest(request, consumer); |
844 ScheduleTask(priority, | 882 ScheduleTask(priority, |
845 base::Bind(func, history_backend_.get(), | 883 base::Bind(func, history_backend_.get(), |
846 scoped_refptr<RequestType>(request), | 884 scoped_refptr<RequestType>(request), |
847 a, b, c, d)); | 885 a, b, c, d)); |
848 return request->handle(); | 886 return request->handle(); |
849 } | 887 } |
850 | 888 |
889 template<typename BackendFunc, | |
890 class RequestType, // Descendant of CancelableRequstBase. | |
891 typename ArgA, | |
892 typename ArgB, | |
893 typename ArgC, | |
894 typename ArgD, | |
895 typename ArgE> | |
896 Handle Schedule(SchedulePriority priority, | |
897 BackendFunc func, // Function to call on the HistoryBackend. | |
898 CancelableRequestConsumerBase* consumer, | |
899 RequestType* request, | |
900 const ArgA& a, | |
901 const ArgB& b, | |
902 const ArgC& c, | |
903 const ArgD& d, | |
904 const ArgE& e) { | |
905 DCHECK(thread_) << "History service being called after cleanup"; | |
906 LoadBackendIfNecessary(); | |
907 if (consumer) | |
908 AddRequest(request, consumer); | |
909 ScheduleTask(priority, | |
910 base::Bind(func, history_backend_.get(), | |
911 scoped_refptr<RequestType>(request), | |
912 a, b, c, d, e)); | |
913 return request->handle(); | |
914 } | |
915 | |
851 // ScheduleAndForget --------------------------------------------------------- | 916 // ScheduleAndForget --------------------------------------------------------- |
852 // | 917 // |
853 // Functions for scheduling operations on the history thread that do not need | 918 // Functions for scheduling operations on the history thread that do not need |
854 // any callbacks and are not cancelable. | 919 // any callbacks and are not cancelable. |
855 | 920 |
856 template<typename BackendFunc> | 921 template<typename BackendFunc> |
857 void ScheduleAndForget(SchedulePriority priority, | 922 void ScheduleAndForget(SchedulePriority priority, |
858 BackendFunc func) { // Function to call on backend. | 923 BackendFunc func) { // Function to call on backend. |
859 DCHECK(thread_) << "History service being called after cleanup"; | 924 DCHECK(thread_) << "History service being called after cleanup"; |
860 LoadBackendIfNecessary(); | 925 LoadBackendIfNecessary(); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
901 const ArgA& a, | 966 const ArgA& a, |
902 const ArgB& b, | 967 const ArgB& b, |
903 const ArgC& c, | 968 const ArgC& c, |
904 const ArgD& d) { | 969 const ArgD& d) { |
905 DCHECK(thread_) << "History service being called after cleanup"; | 970 DCHECK(thread_) << "History service being called after cleanup"; |
906 LoadBackendIfNecessary(); | 971 LoadBackendIfNecessary(); |
907 ScheduleTask(priority, base::Bind(func, history_backend_.get(), | 972 ScheduleTask(priority, base::Bind(func, history_backend_.get(), |
908 a, b, c, d)); | 973 a, b, c, d)); |
909 } | 974 } |
910 | 975 |
976 template<typename BackendFunc, | |
977 typename ArgA, | |
978 typename ArgB, | |
979 typename ArgC, | |
980 typename ArgD, | |
981 typename ArgE> | |
982 void ScheduleAndForget(SchedulePriority priority, | |
983 BackendFunc func, // Function to call on backend. | |
984 const ArgA& a, | |
985 const ArgB& b, | |
986 const ArgC& c, | |
987 const ArgD& d, | |
988 const ArgE& e) { | |
989 DCHECK(thread_) << "History service being called after cleanup"; | |
990 LoadBackendIfNecessary(); | |
991 ScheduleTask(priority, base::Bind(func, history_backend_.get(), | |
992 a, b, c, d, e)); | |
993 } | |
994 | |
911 content::NotificationRegistrar registrar_; | 995 content::NotificationRegistrar registrar_; |
912 | 996 |
913 // Some void primitives require some internal processing in the main thread | 997 // Some void primitives require some internal processing in the main thread |
914 // when done. We use this internal consumer for this purpose. | 998 // when done. We use this internal consumer for this purpose. |
915 CancelableRequestConsumer internal_consumer_; | 999 CancelableRequestConsumer internal_consumer_; |
916 | 1000 |
917 // The thread used by the history service to run complicated operations. | 1001 // The thread used by the history service to run complicated operations. |
918 // |thread_| is NULL once |Cleanup| is NULL. | 1002 // |thread_| is NULL once |Cleanup| is NULL. |
919 base::Thread* thread_; | 1003 base::Thread* thread_; |
920 | 1004 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
953 // The index used for quick history lookups. | 1037 // The index used for quick history lookups. |
954 scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_; | 1038 scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_; |
955 | 1039 |
956 scoped_refptr<ObserverListThreadSafe<history::VisitDatabaseObserver> > | 1040 scoped_refptr<ObserverListThreadSafe<history::VisitDatabaseObserver> > |
957 visit_database_observers_; | 1041 visit_database_observers_; |
958 | 1042 |
959 DISALLOW_COPY_AND_ASSIGN(HistoryService); | 1043 DISALLOW_COPY_AND_ASSIGN(HistoryService); |
960 }; | 1044 }; |
961 | 1045 |
962 #endif // CHROME_BROWSER_HISTORY_HISTORY_H_ | 1046 #endif // CHROME_BROWSER_HISTORY_HISTORY_H_ |
OLD | NEW |