Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Side by Side Diff: chrome/browser/history/history.h

Issue 10802066: Adds support for saving favicon size into history database. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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|. If |desired_size_in_dip| is 0,
695 history::IconType icon_type); 696 // the largest favicon bitmap for |icon_types| is returned. The returned
697 // FaviconBitmapResults will have at most one result for each of
698 // |desired_scale_factors|. If a favicon bitmap is determined to be the best
699 // candidate for multiple scale factors there will be less results.
700 // If |icon_types| has several types, results for only a single type will be
701 // returned in the priority of TOUCH_PRECOMPOSED_ICON, TOUCH_ICON, and
702 // FAVICON.
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|. If |desired_size_in_dip| is 0, the largest favicon
712 // bitmap for |icon_types| is returned. The returned FaviconBitmapResults will
713 // have at most one result for each of |desired_scale_factors|. If a favicon
714 // bitmap is determined to be the best candidate for multiple scale factors
715 // there will be less results. If |icon_types| has several types, results for
716 // only a single type will be returned in the priority of
717 // TOUCH_PRECOMPOSED_ICON, TOUCH_ICON, and 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 // with |favicon_id| from the history backend. If |desired_size_in_dip| is 0,
728 // the largest favicon bitmap for |favicon_id| is returned.
729 void GetFaviconForID(FaviconService::GetFaviconRequest* request,
730 history::FaviconID favicon_id,
731 int desired_size_in_dip,
732 ui::ScaleFactor desired_scale_factor);
733
734 // Used by the FaviconService to replace the favicon mappings to |page_url|
735 // for |icon_types| on the history backend.
736 // Sample |icon_urls|:
737 // { ICON_URL1 -> TOUCH_ICON, known to the database,
738 // ICON_URL2 -> TOUCH_ICON, not known to the database,
739 // ICON_URL3 -> TOUCH_PRECOMPOSED_ICON, known to the database }
740 // The new mappings are computed from |icon_urls| with these rules:
741 // 1) Any urls in |icon_urls| which are not already known to the database are
742 // rejected.
743 // Sample new mappings to |page_url|: { ICON_URL1, ICON_URL3 }
744 // 2) If |icon_types| has multiple types, the mappings are only set for the
745 // largest icon type.
746 // Sample new mappings to |page_url|: { ICON_URL3 }
747 // |icon_types| can only have multiple IconTypes if
748 // |icon_types| == TOUCH_ICON | TOUCH_PRECOMPOSED_ICON.
749 // The favicon bitmaps which most closely match |desired_size_in_dip|
750 // and |desired_scale_factors| from the favicons which were just mapped
751 // to |page_url| are returned. If |desired_size_in_dip| is 0, the
752 // largest favicon bitmap is returned.
753 void UpdateFaviconMappingsAndFetch(
754 FaviconService::GetFaviconRequest* request,
755 const GURL& page_url,
756 const std::vector<GURL>& icon_urls,
757 int icon_types,
758 int desired_size_in_dip,
759 const std::vector<ui::ScaleFactor>& desired_scale_factors);
760
761 // Used by the FaviconService to set the favicons for a page on the history
698 // backend. 762 // backend.
699 void UpdateFaviconMappingAndFetch(FaviconService::GetFaviconRequest* request, 763 // |favicon_bitmap_data| is a listing of additional favicon bitmaps to store
700 const GURL& page_url, 764 // for |page_url|.
701 const GURL& icon_url, 765 // |expired| and |icon_type| fields in FaviconBitmapData are ignored.
702 history::IconType icon_type); 766 // |icon_url_sizes| is a mapping of all the icon urls of the favicons
703 767 // available for |page_url| to the sizes that those favicons are available
704 // Used by the FaviconService to get a favicon from the history backend. 768 // from the web.
705 void GetFaviconForURL(FaviconService::GetFaviconRequest* request, 769 // |favicon_bitmap_data| does not need to have entries for all the icon urls
706 const GURL& page_url, 770 // or sizes listed in |icon_url_sizes|. However, the icon urls and pixel
707 int icon_types); 771 // sizes in |favicon_bitmap_data| must be a subset of |icon_url_sizes|. It is
708 772 // important that |icon_url_sizes| be complete as mappings to favicons whose
709 // Used by the FaviconService to get a favicon from the history backend. 773 // icon url or pixel size is not in |icon_url_sizes| will be deleted.
710 void GetFaviconForID(FaviconService::GetFaviconRequest* request, 774 // See HistoryBackend::ValidateSetFaviconsParams() for more details on the
711 history::FaviconID id); 775 // criteria for |favicon_bitmap_data| and |icon_url_sizes| to be valid.
776 void SetFavicons(
777 const GURL& page_url,
778 history::IconType icon_type,
779 const std::vector<history::FaviconBitmapData>& favicon_bitmap_data,
780 const history::IconURLSizesMap& icon_url_sizes);
712 781
713 // Used by the FaviconService to mark the favicon for the page as being out 782 // Used by the FaviconService to mark the favicon for the page as being out
714 // of date. 783 // of date.
715 void SetFaviconOutOfDateForPage(const GURL& page_url); 784 void SetFaviconsOutOfDateForPage(const GURL& page_url);
716 785
717 // Used by the FaviconService to clone favicons from one page to another, 786 // Used by the FaviconService to clone favicons from one page to another,
718 // provided that other page does not already have favicons. 787 // provided that other page does not already have favicons.
719 void CloneFavicon(const GURL& old_page_url, const GURL& new_page_url); 788 void CloneFavicons(const GURL& old_page_url, const GURL& new_page_url);
720 789
721 // Used by the FaviconService for importing many favicons for many pages at 790 // 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 791 // once. The pages must exist, any favicon sets for unknown pages will be
723 // discarded. Existing favicons will not be overwritten. 792 // discarded. Existing favicons will not be overwritten.
724 void SetImportedFavicons( 793 void SetImportedFavicons(
725 const std::vector<history::ImportedFaviconUsage>& favicon_usage); 794 const std::vector<history::ImportedFaviconUsage>& favicon_usage);
726 795
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 796 // Sets the in-memory URL database. This is called by the backend once the
736 // database is loaded to make it available. 797 // database is loaded to make it available.
737 void SetInMemoryBackend(int backend_id, 798 void SetInMemoryBackend(int backend_id,
738 history::InMemoryHistoryBackend* mem_backend); 799 history::InMemoryHistoryBackend* mem_backend);
739 800
740 // Called by our BackendDelegate when there is a problem reading the database. 801 // Called by our BackendDelegate when there is a problem reading the database.
741 void NotifyProfileError(int backend_id, sql::InitStatus init_status); 802 void NotifyProfileError(int backend_id, sql::InitStatus init_status);
742 803
743 // Call to schedule a given task for running on the history thread with the 804 // Call to schedule a given task for running on the history thread with the
744 // specified priority. The task will have ownership taken. 805 // specified priority. The task will have ownership taken.
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 const ArgA& a, 897 const ArgA& a,
837 const ArgB& b, 898 const ArgB& b,
838 const ArgC& c, 899 const ArgC& c,
839 const ArgD& d) { 900 const ArgD& d) {
840 DCHECK(thread_) << "History service being called after cleanup"; 901 DCHECK(thread_) << "History service being called after cleanup";
841 LoadBackendIfNecessary(); 902 LoadBackendIfNecessary();
842 if (consumer) 903 if (consumer)
843 AddRequest(request, consumer); 904 AddRequest(request, consumer);
844 ScheduleTask(priority, 905 ScheduleTask(priority,
845 base::Bind(func, history_backend_.get(), 906 base::Bind(func, history_backend_.get(),
846 scoped_refptr<RequestType>(request), 907 scoped_refptr<RequestType>(request), a, b, c, d));
847 a, b, c, d));
848 return request->handle(); 908 return request->handle();
849 } 909 }
850 910
911 template<typename BackendFunc,
912 class RequestType, // Descendant of CancelableRequstBase.
913 typename ArgA,
914 typename ArgB,
915 typename ArgC,
916 typename ArgD,
917 typename ArgE>
918 Handle Schedule(SchedulePriority priority,
919 BackendFunc func, // Function to call on the HistoryBackend.
920 CancelableRequestConsumerBase* consumer,
921 RequestType* request,
922 const ArgA& a,
923 const ArgB& b,
924 const ArgC& c,
925 const ArgD& d,
926 const ArgE& e) {
927 DCHECK(thread_) << "History service being called after cleanup";
928 LoadBackendIfNecessary();
929 if (consumer)
930 AddRequest(request, consumer);
931 ScheduleTask(priority,
932 base::Bind(func, history_backend_.get(),
933 scoped_refptr<RequestType>(request),
934 a, b, c, d, e));
935 return request->handle();
936 }
937
851 // ScheduleAndForget --------------------------------------------------------- 938 // ScheduleAndForget ---------------------------------------------------------
852 // 939 //
853 // Functions for scheduling operations on the history thread that do not need 940 // Functions for scheduling operations on the history thread that do not need
854 // any callbacks and are not cancelable. 941 // any callbacks and are not cancelable.
855 942
856 template<typename BackendFunc> 943 template<typename BackendFunc>
857 void ScheduleAndForget(SchedulePriority priority, 944 void ScheduleAndForget(SchedulePriority priority,
858 BackendFunc func) { // Function to call on backend. 945 BackendFunc func) { // Function to call on backend.
859 DCHECK(thread_) << "History service being called after cleanup"; 946 DCHECK(thread_) << "History service being called after cleanup";
860 LoadBackendIfNecessary(); 947 LoadBackendIfNecessary();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 const ArgA& a, 988 const ArgA& a,
902 const ArgB& b, 989 const ArgB& b,
903 const ArgC& c, 990 const ArgC& c,
904 const ArgD& d) { 991 const ArgD& d) {
905 DCHECK(thread_) << "History service being called after cleanup"; 992 DCHECK(thread_) << "History service being called after cleanup";
906 LoadBackendIfNecessary(); 993 LoadBackendIfNecessary();
907 ScheduleTask(priority, base::Bind(func, history_backend_.get(), 994 ScheduleTask(priority, base::Bind(func, history_backend_.get(),
908 a, b, c, d)); 995 a, b, c, d));
909 } 996 }
910 997
998 template<typename BackendFunc,
999 typename ArgA,
1000 typename ArgB,
1001 typename ArgC,
1002 typename ArgD,
1003 typename ArgE>
1004 void ScheduleAndForget(SchedulePriority priority,
1005 BackendFunc func, // Function to call on backend.
1006 const ArgA& a,
1007 const ArgB& b,
1008 const ArgC& c,
1009 const ArgD& d,
1010 const ArgE& e) {
1011 DCHECK(thread_) << "History service being called after cleanup";
1012 LoadBackendIfNecessary();
1013 ScheduleTask(priority, base::Bind(func, history_backend_.get(),
1014 a, b, c, d, e));
1015 }
1016
911 content::NotificationRegistrar registrar_; 1017 content::NotificationRegistrar registrar_;
912 1018
913 // Some void primitives require some internal processing in the main thread 1019 // Some void primitives require some internal processing in the main thread
914 // when done. We use this internal consumer for this purpose. 1020 // when done. We use this internal consumer for this purpose.
915 CancelableRequestConsumer internal_consumer_; 1021 CancelableRequestConsumer internal_consumer_;
916 1022
917 // The thread used by the history service to run complicated operations. 1023 // The thread used by the history service to run complicated operations.
918 // |thread_| is NULL once |Cleanup| is NULL. 1024 // |thread_| is NULL once |Cleanup| is NULL.
919 base::Thread* thread_; 1025 base::Thread* thread_;
920 1026
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
953 // The index used for quick history lookups. 1059 // The index used for quick history lookups.
954 scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_; 1060 scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_;
955 1061
956 scoped_refptr<ObserverListThreadSafe<history::VisitDatabaseObserver> > 1062 scoped_refptr<ObserverListThreadSafe<history::VisitDatabaseObserver> >
957 visit_database_observers_; 1063 visit_database_observers_;
958 1064
959 DISALLOW_COPY_AND_ASSIGN(HistoryService); 1065 DISALLOW_COPY_AND_ASSIGN(HistoryService);
960 }; 1066 };
961 1067
962 #endif // CHROME_BROWSER_HISTORY_HISTORY_H_ 1068 #endif // CHROME_BROWSER_HISTORY_HISTORY_H_
OLDNEW
« no previous file with comments | « chrome/browser/history/android/android_provider_backend_unittest.cc ('k') | chrome/browser/history/history.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698