| 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 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <set> | 9 #include <set> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
| 13 #include "base/callback.h" | 13 #include "base/callback.h" |
| 14 #include "base/file_path.h" | 14 #include "base/file_path.h" |
| 15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/observer_list_threadsafe.h" | 17 #include "base/observer_list_threadsafe.h" |
| 18 #include "base/string16.h" | 18 #include "base/string16.h" |
| 19 #include "chrome/browser/cancelable_request.h" | 19 #include "chrome/browser/cancelable_request.h" |
| 20 #include "chrome/browser/favicon/favicon_service.h" | 20 #include "chrome/browser/favicon/favicon_service.h" |
| 21 #include "chrome/browser/history/history_types.h" | 21 #include "chrome/browser/history/history_types.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 | 28 |
| 29 #if defined(OS_ANDROID) |
| 30 #include "chrome/browser/history/android/android_history_provider_service.h" |
| 31 #endif |
| 32 |
| 29 class BookmarkService; | 33 class BookmarkService; |
| 30 class FilePath; | 34 class FilePath; |
| 31 class GURL; | 35 class GURL; |
| 32 class HistoryURLProvider; | 36 class HistoryURLProvider; |
| 33 struct HistoryURLProviderParams; | 37 struct HistoryURLProviderParams; |
| 34 class PageUsageData; | 38 class PageUsageData; |
| 35 class PageUsageRequest; | 39 class PageUsageRequest; |
| 36 class Profile; | 40 class Profile; |
| 37 | 41 |
| 38 namespace base { | 42 namespace base { |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 // These are not currently used, hopefully we can do something in the future | 614 // These are not currently used, hopefully we can do something in the future |
| 611 // to ensure that the most important things happen first. | 615 // to ensure that the most important things happen first. |
| 612 enum SchedulePriority { | 616 enum SchedulePriority { |
| 613 PRIORITY_UI, // The highest priority (must respond to UI events). | 617 PRIORITY_UI, // The highest priority (must respond to UI events). |
| 614 PRIORITY_NORMAL, // Normal stuff like adding a page. | 618 PRIORITY_NORMAL, // Normal stuff like adding a page. |
| 615 PRIORITY_LOW, // Low priority things like indexing or expiration. | 619 PRIORITY_LOW, // Low priority things like indexing or expiration. |
| 616 }; | 620 }; |
| 617 | 621 |
| 618 private: | 622 private: |
| 619 class BackendDelegate; | 623 class BackendDelegate; |
| 624 #if defined(OS_ANDROID) |
| 625 friend class AndroidHistoryProviderService; |
| 626 #endif |
| 620 friend class base::RefCountedThreadSafe<HistoryService>; | 627 friend class base::RefCountedThreadSafe<HistoryService>; |
| 621 friend class BackendDelegate; | 628 friend class BackendDelegate; |
| 622 friend class FaviconService; | 629 friend class FaviconService; |
| 623 friend class history::HistoryBackend; | 630 friend class history::HistoryBackend; |
| 624 friend class history::HistoryQueryTest; | 631 friend class history::HistoryQueryTest; |
| 625 friend class HistoryOperation; | 632 friend class HistoryOperation; |
| 626 friend class HistoryURLProvider; | 633 friend class HistoryURLProvider; |
| 627 friend class HistoryURLProviderTest; | 634 friend class HistoryURLProviderTest; |
| 628 friend class history::InMemoryURLIndexTest; | 635 friend class history::InMemoryURLIndexTest; |
| 629 template<typename Info, typename Callback> friend class DownloadRequest; | 636 template<typename Info, typename Callback> friend class DownloadRequest; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 DCHECK(thread_) << "History service being called after cleanup"; | 803 DCHECK(thread_) << "History service being called after cleanup"; |
| 797 LoadBackendIfNecessary(); | 804 LoadBackendIfNecessary(); |
| 798 if (consumer) | 805 if (consumer) |
| 799 AddRequest(request, consumer); | 806 AddRequest(request, consumer); |
| 800 ScheduleTask(priority, | 807 ScheduleTask(priority, |
| 801 base::Bind(func, history_backend_.get(), | 808 base::Bind(func, history_backend_.get(), |
| 802 scoped_refptr<RequestType>(request), a, b, c)); | 809 scoped_refptr<RequestType>(request), a, b, c)); |
| 803 return request->handle(); | 810 return request->handle(); |
| 804 } | 811 } |
| 805 | 812 |
| 813 template<typename BackendFunc, |
| 814 class RequestType, // Descendant of CancelableRequstBase. |
| 815 typename ArgA, |
| 816 typename ArgB, |
| 817 typename ArgC, |
| 818 typename ArgD> |
| 819 Handle Schedule(SchedulePriority priority, |
| 820 BackendFunc func, // Function to call on the HistoryBackend. |
| 821 CancelableRequestConsumerBase* consumer, |
| 822 RequestType* request, |
| 823 const ArgA& a, |
| 824 const ArgB& b, |
| 825 const ArgC& c, |
| 826 const ArgD& d) { |
| 827 DCHECK(thread_) << "History service being called after cleanup"; |
| 828 LoadBackendIfNecessary(); |
| 829 if (consumer) |
| 830 AddRequest(request, consumer); |
| 831 ScheduleTask(priority, |
| 832 base::Bind(func, history_backend_.get(), |
| 833 scoped_refptr<RequestType>(request), |
| 834 a, b, c, d)); |
| 835 return request->handle(); |
| 836 } |
| 837 |
| 806 // ScheduleAndForget --------------------------------------------------------- | 838 // ScheduleAndForget --------------------------------------------------------- |
| 807 // | 839 // |
| 808 // Functions for scheduling operations on the history thread that do not need | 840 // Functions for scheduling operations on the history thread that do not need |
| 809 // any callbacks and are not cancelable. | 841 // any callbacks and are not cancelable. |
| 810 | 842 |
| 811 template<typename BackendFunc> | 843 template<typename BackendFunc> |
| 812 void ScheduleAndForget(SchedulePriority priority, | 844 void ScheduleAndForget(SchedulePriority priority, |
| 813 BackendFunc func) { // Function to call on backend. | 845 BackendFunc func) { // Function to call on backend. |
| 814 DCHECK(thread_) << "History service being called after cleanup"; | 846 DCHECK(thread_) << "History service being called after cleanup"; |
| 815 LoadBackendIfNecessary(); | 847 LoadBackendIfNecessary(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 856 const ArgA& a, | 888 const ArgA& a, |
| 857 const ArgB& b, | 889 const ArgB& b, |
| 858 const ArgC& c, | 890 const ArgC& c, |
| 859 const ArgD& d) { | 891 const ArgD& d) { |
| 860 DCHECK(thread_) << "History service being called after cleanup"; | 892 DCHECK(thread_) << "History service being called after cleanup"; |
| 861 LoadBackendIfNecessary(); | 893 LoadBackendIfNecessary(); |
| 862 ScheduleTask(priority, base::Bind(func, history_backend_.get(), | 894 ScheduleTask(priority, base::Bind(func, history_backend_.get(), |
| 863 a, b, c, d)); | 895 a, b, c, d)); |
| 864 } | 896 } |
| 865 | 897 |
| 898 #if defined(OS_ANDROID) |
| 899 // Android Provider --------------------------------------------------------- |
| 900 // |
| 901 // These Android provider related methods are exposed to the |
| 902 // AndroidHistoryProviderService. Instead of calling these methods directly |
| 903 // you should call the respective method on the AndroidHistoryProviderService. |
| 904 |
| 905 // Used by the AndroidHistoryProviderService to add the history and the |
| 906 // bookmarks. |
| 907 void InsertHistoryAndBookmark( |
| 908 AndroidHistoryProviderService::InsertRequest* request, |
| 909 const history::HistoryAndBookmarkRow& row); |
| 910 |
| 911 // Used by the AndroidHistoryProviderService to query the history and the |
| 912 // bookmarks. |
| 913 void QueryHistoryAndBookmarks( |
| 914 AndroidHistoryProviderService::QueryRequest* request, |
| 915 const std::vector<history::HistoryAndBookmarkRow::ColumnID>& projections, |
| 916 const std::string& selection, |
| 917 const std::vector<string16>& selection_args, |
| 918 const std::string& sort_order); |
| 919 |
| 920 // Used by the AndroidHistoryProviderService to update the history and the |
| 921 // bookmarks. |
| 922 void UpdateHistoryAndBookmarks( |
| 923 AndroidHistoryProviderService::UpdateRequest* request, |
| 924 const history::HistoryAndBookmarkRow& row, |
| 925 const std::string& selection, |
| 926 const std::vector<string16>& selection_args); |
| 927 |
| 928 // Used by the AndroidHistoryProviderService to delete the history and the |
| 929 // bookmarks. |
| 930 void DeleteHistoryAndBookmarks( |
| 931 AndroidHistoryProviderService::DeleteRequest* request, |
| 932 const std::string& selection, |
| 933 const std::vector<string16>& selection_args); |
| 934 |
| 935 // Used by the AndroidHistoryProviderService to delete the history. |
| 936 void DeleteHistory(AndroidHistoryProviderService::DeleteRequest* request, |
| 937 const std::string& selection, |
| 938 const std::vector<string16>& selection_args); |
| 939 |
| 940 // Used by the AndroidHistoryProviderService to move the given |statement|'s |
| 941 // current row to |destination|. |
| 942 void MoveStatement( |
| 943 AndroidHistoryProviderService::MoveStatementRequest* request, |
| 944 history::AndroidStatement* statement, |
| 945 int current_pos, |
| 946 int destination); |
| 947 |
| 948 // Used by the AndroidHistoryProviderService to close the statement in db |
| 949 // thread. |
| 950 void CloseStatement(history::AndroidStatement* statement); |
| 951 |
| 952 // Used by the AndroidHistoryProviderService to add the search term. |
| 953 void InsertSearchTerm(AndroidHistoryProviderService::InsertRequest* request, |
| 954 const history::SearchRow& row); |
| 955 |
| 956 // Used by the AndroidHistoryProviderService to update the search terms. |
| 957 void UpdateSearchTerms(AndroidHistoryProviderService::UpdateRequest* request, |
| 958 const history::SearchRow& row, |
| 959 const std::string& selection, |
| 960 const std::vector<string16>& selection_arg); |
| 961 |
| 962 // Used by the AndroidHistoryProviderService to delete the search terms. |
| 963 void DeleteSearchTerms(AndroidHistoryProviderService::DeleteRequest* request, |
| 964 const std::string& selection, |
| 965 const std::vector<string16>& selection_arg); |
| 966 |
| 967 // Used by the AndroidHistoryProviderService to query the search terms. |
| 968 void QuerySearchTerms( |
| 969 AndroidHistoryProviderService::QueryRequest* request, |
| 970 const std::vector<history::SearchRow::ColumnID>& projections, |
| 971 const std::string& selection, |
| 972 const std::vector<string16>& selection_args, |
| 973 const std::string& sort_order); |
| 974 |
| 975 #endif // defined(OS_ANDROID) |
| 976 |
| 866 content::NotificationRegistrar registrar_; | 977 content::NotificationRegistrar registrar_; |
| 867 | 978 |
| 868 // Some void primitives require some internal processing in the main thread | 979 // Some void primitives require some internal processing in the main thread |
| 869 // when done. We use this internal consumer for this purpose. | 980 // when done. We use this internal consumer for this purpose. |
| 870 CancelableRequestConsumer internal_consumer_; | 981 CancelableRequestConsumer internal_consumer_; |
| 871 | 982 |
| 872 // The thread used by the history service to run complicated operations. | 983 // The thread used by the history service to run complicated operations. |
| 873 // |thread_| is NULL once |Cleanup| is NULL. | 984 // |thread_| is NULL once |Cleanup| is NULL. |
| 874 base::Thread* thread_; | 985 base::Thread* thread_; |
| 875 | 986 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 908 // The index used for quick history lookups. | 1019 // The index used for quick history lookups. |
| 909 scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_; | 1020 scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_; |
| 910 | 1021 |
| 911 scoped_refptr<ObserverListThreadSafe<history::VisitDatabaseObserver> > | 1022 scoped_refptr<ObserverListThreadSafe<history::VisitDatabaseObserver> > |
| 912 visit_database_observers_; | 1023 visit_database_observers_; |
| 913 | 1024 |
| 914 DISALLOW_COPY_AND_ASSIGN(HistoryService); | 1025 DISALLOW_COPY_AND_ASSIGN(HistoryService); |
| 915 }; | 1026 }; |
| 916 | 1027 |
| 917 #endif // CHROME_BROWSER_HISTORY_HISTORY_H_ | 1028 #endif // CHROME_BROWSER_HISTORY_HISTORY_H_ |
| OLD | NEW |