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