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_BACKEND_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H_ |
6 #define CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H_ | 6 #define CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <string> | 9 #include <string> |
10 #include <utility> | 10 #include <utility> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/containers/mru_cache.h" | 13 #include "base/containers/mru_cache.h" |
14 #include "base/files/file_path.h" | 14 #include "base/files/file_path.h" |
15 #include "base/gtest_prod_util.h" | 15 #include "base/gtest_prod_util.h" |
16 #include "base/memory/memory_pressure_listener.h" | 16 #include "base/memory/memory_pressure_listener.h" |
17 #include "base/memory/scoped_ptr.h" | 17 #include "base/memory/scoped_ptr.h" |
18 #include "chrome/browser/history/archived_database.h" | 18 #include "chrome/browser/history/archived_database.h" |
19 #include "chrome/browser/history/expire_history_backend.h" | 19 #include "chrome/browser/history/expire_history_backend.h" |
20 #include "chrome/browser/history/history_database.h" | 20 #include "chrome/browser/history/history_database.h" |
21 #include "chrome/browser/history/history_marshaling.h" | 21 #include "chrome/browser/history/history_marshaling.h" |
22 #include "chrome/browser/history/history_types.h" | 22 #include "chrome/browser/history/history_types.h" |
23 #include "chrome/browser/history/thumbnail_database.h" | 23 #include "chrome/browser/history/thumbnail_database.h" |
24 #include "chrome/browser/history/visit_tracker.h" | 24 #include "chrome/browser/history/visit_tracker.h" |
25 #include "chrome/browser/search_engines/template_url_id.h" | 25 #include "chrome/browser/search_engines/template_url_id.h" |
26 #include "sql/init_status.h" | 26 #include "sql/init_status.h" |
27 #include "ui/base/layout.h" | 27 #include "ui/base/layout.h" |
28 | 28 |
29 class BookmarkService; | |
30 class TestingProfile; | 29 class TestingProfile; |
31 class TypedUrlSyncableService; | 30 class TypedUrlSyncableService; |
32 struct ThumbnailScore; | 31 struct ThumbnailScore; |
33 | 32 |
34 namespace history { | 33 namespace history { |
35 #if defined(OS_ANDROID) | 34 #if defined(OS_ANDROID) |
36 class AndroidProviderBackend; | 35 class AndroidProviderBackend; |
37 #endif | 36 #endif |
38 | 37 |
39 class CommitLaterTask; | 38 class CommitLaterTask; |
| 39 class HistoryClient; |
40 class VisitFilter; | 40 class VisitFilter; |
41 struct DownloadRow; | 41 struct DownloadRow; |
42 | 42 |
43 // The maximum number of icons URLs per page which can be stored in the | 43 // The maximum number of icons URLs per page which can be stored in the |
44 // thumbnail database. | 44 // thumbnail database. |
45 static const size_t kMaxFaviconsPerPage = 8; | 45 static const size_t kMaxFaviconsPerPage = 8; |
46 | 46 |
47 // The maximum number of bitmaps for a single icon URL which can be stored in | 47 // The maximum number of bitmaps for a single icon URL which can be stored in |
48 // the thumbnail database. | 48 // the thumbnail database. |
49 static const size_t kMaxFaviconBitmapsPerIconURL = 8; | 49 static const size_t kMaxFaviconBitmapsPerIconURL = 8; |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 }; | 98 }; |
99 | 99 |
100 // Init must be called to complete object creation. This object can be | 100 // Init must be called to complete object creation. This object can be |
101 // constructed on any thread, but all other functions including Init() must | 101 // constructed on any thread, but all other functions including Init() must |
102 // be called on the history thread. | 102 // be called on the history thread. |
103 // | 103 // |
104 // |history_dir| is the directory where the history files will be placed. | 104 // |history_dir| is the directory where the history files will be placed. |
105 // See the definition of BroadcastNotificationsCallback above. This function | 105 // See the definition of BroadcastNotificationsCallback above. This function |
106 // takes ownership of the callback pointer. | 106 // takes ownership of the callback pointer. |
107 // | 107 // |
108 // |bookmark_service| is used to determine bookmarked URLs when deleting and | 108 // |history_client| is used to determine bookmarked URLs when deleting and |
109 // may be NULL. | 109 // may be NULL. |
110 // | 110 // |
111 // This constructor is fast and does no I/O, so can be called at any time. | 111 // This constructor is fast and does no I/O, so can be called at any time. |
112 HistoryBackend(const base::FilePath& history_dir, | 112 HistoryBackend(const base::FilePath& history_dir, |
113 Delegate* delegate, | 113 Delegate* delegate, |
114 BookmarkService* bookmark_service); | 114 HistoryClient* history_client); |
115 | 115 |
116 // Must be called after creation but before any objects are created. If this | 116 // Must be called after creation but before any objects are created. If this |
117 // fails, all other functions will fail as well. (Since this runs on another | 117 // fails, all other functions will fail as well. (Since this runs on another |
118 // thread, we don't bother returning failure.) | 118 // thread, we don't bother returning failure.) |
119 // | 119 // |
120 // |languages| gives a list of language encodings with which the history | 120 // |languages| gives a list of language encodings with which the history |
121 // URLs and omnibox searches are interpreted. | 121 // URLs and omnibox searches are interpreted. |
122 // |force_fail| can be set during unittests to unconditionally fail to init. | 122 // |force_fail| can be set during unittests to unconditionally fail to init. |
123 void Init(const std::string& languages, bool force_fail); | 123 void Init(const std::string& languages, bool force_fail); |
124 | 124 |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 // Deletes all information in the history database, except for the supplied | 789 // Deletes all information in the history database, except for the supplied |
790 // set of URLs in the URL table (these should correspond to the bookmarked | 790 // set of URLs in the URL table (these should correspond to the bookmarked |
791 // URLs). | 791 // URLs). |
792 // | 792 // |
793 // The IDs of the URLs may change. | 793 // The IDs of the URLs may change. |
794 bool ClearAllMainHistory(const URLRows& kept_urls); | 794 bool ClearAllMainHistory(const URLRows& kept_urls); |
795 | 795 |
796 // Deletes the FTS index database files, which are no longer used. | 796 // Deletes the FTS index database files, which are no longer used. |
797 void DeleteFTSIndexDatabases(); | 797 void DeleteFTSIndexDatabases(); |
798 | 798 |
799 // Returns the BookmarkService, blocking until it is loaded. This may return | |
800 // NULL during testing. | |
801 BookmarkService* GetBookmarkService(); | |
802 | |
803 // Notify any observers of an addition to the visit database. | 799 // Notify any observers of an addition to the visit database. |
804 void NotifyVisitObservers(const VisitRow& visit); | 800 void NotifyVisitObservers(const VisitRow& visit); |
805 | 801 |
806 // Data ---------------------------------------------------------------------- | 802 // Data ---------------------------------------------------------------------- |
807 | 803 |
808 // Delegate. See the class definition above for more information. This will | 804 // Delegate. See the class definition above for more information. This will |
809 // be NULL before Init is called and after Cleanup, but is guaranteed | 805 // be NULL before Init is called and after Cleanup, but is guaranteed |
810 // non-NULL in between. | 806 // non-NULL in between. |
811 scoped_ptr<Delegate> delegate_; | 807 scoped_ptr<Delegate> delegate_; |
812 | 808 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
856 VisitTracker tracker_; | 852 VisitTracker tracker_; |
857 | 853 |
858 // A boolean variable to track whether we have already purged obsolete segment | 854 // A boolean variable to track whether we have already purged obsolete segment |
859 // data. | 855 // data. |
860 bool segment_queried_; | 856 bool segment_queried_; |
861 | 857 |
862 // HistoryDBTasks to run. Be sure to AddRef when adding, and Release when | 858 // HistoryDBTasks to run. Be sure to AddRef when adding, and Release when |
863 // done. | 859 // done. |
864 std::list<HistoryDBTaskRequest*> db_task_requests_; | 860 std::list<HistoryDBTaskRequest*> db_task_requests_; |
865 | 861 |
866 // Used to determine if a URL is bookmarked. This is owned by the Profile and | 862 // Used to determine if a URL is bookmarked; may be NULL. |
867 // may be NULL (during testing). | 863 HistoryClient* history_client_; |
868 // | |
869 // Use GetBookmarkService to access this, which makes sure the service is | |
870 // loaded. | |
871 BookmarkService* bookmark_service_; | |
872 | 864 |
873 #if defined(OS_ANDROID) | 865 #if defined(OS_ANDROID) |
874 // Used to provide the Android ContentProvider APIs. | 866 // Used to provide the Android ContentProvider APIs. |
875 scoped_ptr<AndroidProviderBackend> android_provider_backend_; | 867 scoped_ptr<AndroidProviderBackend> android_provider_backend_; |
876 | 868 |
877 // Used to provide UMA on the number of page visits that are to the most | 869 // Used to provide UMA on the number of page visits that are to the most |
878 // visited URLs. This is here because the backend both has access to this | 870 // visited URLs. This is here because the backend both has access to this |
879 // information and is notified of page visits. The top sites service should | 871 // information and is notified of page visits. The top sites service should |
880 // be used instead whenever possible. | 872 // be used instead whenever possible. |
881 std::map<GURL, int> most_visited_urls_map_; | 873 std::map<GURL, int> most_visited_urls_map_; |
882 #endif | 874 #endif |
883 | 875 |
884 // Used to manage syncing of the typed urls datatype. This will be NULL | 876 // Used to manage syncing of the typed urls datatype. This will be NULL |
885 // before Init is called. | 877 // before Init is called. |
886 scoped_ptr<TypedUrlSyncableService> typed_url_syncable_service_; | 878 scoped_ptr<TypedUrlSyncableService> typed_url_syncable_service_; |
887 | 879 |
888 // Listens for the system being under memory pressure. | 880 // Listens for the system being under memory pressure. |
889 scoped_ptr<base::MemoryPressureListener> memory_pressure_listener_; | 881 scoped_ptr<base::MemoryPressureListener> memory_pressure_listener_; |
890 | 882 |
891 DISALLOW_COPY_AND_ASSIGN(HistoryBackend); | 883 DISALLOW_COPY_AND_ASSIGN(HistoryBackend); |
892 }; | 884 }; |
893 | 885 |
894 } // namespace history | 886 } // namespace history |
895 | 887 |
896 #endif // CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H_ | 888 #endif // CHROME_BROWSER_HISTORY_HISTORY_BACKEND_H_ |
OLD | NEW |