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_SERVICE_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_HISTORY_SERVICE_H_ |
6 #define CHROME_BROWSER_HISTORY_HISTORY_SERVICE_H_ | 6 #define CHROME_BROWSER_HISTORY_HISTORY_SERVICE_H_ |
7 | 7 |
8 #include <set> | 8 #include <set> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... | |
22 #include "base/task/cancelable_task_tracker.h" | 22 #include "base/task/cancelable_task_tracker.h" |
23 #include "base/threading/thread_checker.h" | 23 #include "base/threading/thread_checker.h" |
24 #include "base/time/time.h" | 24 #include "base/time/time.h" |
25 #include "chrome/browser/history/delete_directive_handler.h" | 25 #include "chrome/browser/history/delete_directive_handler.h" |
26 #include "chrome/browser/history/typed_url_syncable_service.h" | 26 #include "chrome/browser/history/typed_url_syncable_service.h" |
27 #include "chrome/common/ref_counted_util.h" | 27 #include "chrome/common/ref_counted_util.h" |
28 #include "components/favicon_base/favicon_callback.h" | 28 #include "components/favicon_base/favicon_callback.h" |
29 #include "components/history/core/browser/history_client.h" | 29 #include "components/history/core/browser/history_client.h" |
30 #include "components/history/core/browser/keyword_id.h" | 30 #include "components/history/core/browser/keyword_id.h" |
31 #include "components/keyed_service/core/keyed_service.h" | 31 #include "components/keyed_service/core/keyed_service.h" |
32 #include "components/visitedlink/browser/visitedlink_delegate.h" | |
33 #include "content/public/browser/download_manager_delegate.h" | 32 #include "content/public/browser/download_manager_delegate.h" |
34 #include "sql/init_status.h" | 33 #include "sql/init_status.h" |
35 #include "sync/api/syncable_service.h" | 34 #include "sync/api/syncable_service.h" |
36 #include "ui/base/page_transition_types.h" | 35 #include "ui/base/page_transition_types.h" |
37 | 36 |
38 #if defined(OS_ANDROID) | 37 #if defined(OS_ANDROID) |
39 class AndroidHistoryProviderService; | 38 class AndroidHistoryProviderService; |
40 #endif | 39 #endif |
41 | 40 |
42 class GURL; | 41 class GURL; |
43 class PageUsageData; | 42 class PageUsageData; |
44 class PageUsageRequest; | 43 class PageUsageRequest; |
45 class PrefService; | 44 class PrefService; |
46 class Profile; | 45 class Profile; |
47 struct ImportedFaviconUsage; | 46 struct ImportedFaviconUsage; |
48 class SkBitmap; | 47 class SkBitmap; |
49 | 48 |
50 namespace base { | 49 namespace base { |
51 class FilePath; | 50 class FilePath; |
52 class Thread; | 51 class Thread; |
53 } | 52 } |
54 | 53 |
55 namespace visitedlink { | |
56 class VisitedLinkMaster; | |
57 } | |
58 | |
59 namespace history { | 54 namespace history { |
60 | 55 |
61 class HistoryBackend; | 56 class HistoryBackend; |
62 class HistoryClient; | 57 class HistoryClient; |
63 class HistoryDatabase; | 58 class HistoryDatabase; |
64 struct HistoryDatabaseParams; | 59 struct HistoryDatabaseParams; |
65 class HistoryDBTask; | 60 class HistoryDBTask; |
66 class HistoryQueryTest; | 61 class HistoryQueryTest; |
67 class HistoryServiceObserver; | 62 class HistoryServiceObserver; |
68 class HistoryTest; | 63 class HistoryTest; |
69 class InMemoryHistoryBackend; | 64 class InMemoryHistoryBackend; |
70 class InMemoryURLIndex; | 65 class InMemoryURLIndex; |
71 class InMemoryURLIndexTest; | 66 class InMemoryURLIndexTest; |
72 class URLDatabase; | 67 class URLDatabase; |
68 class VisitDelegate; | |
73 class VisitFilter; | 69 class VisitFilter; |
74 struct DownloadRow; | 70 struct DownloadRow; |
75 struct HistoryAddPageArgs; | 71 struct HistoryAddPageArgs; |
76 struct KeywordSearchTermVisit; | 72 struct KeywordSearchTermVisit; |
77 class WebHistoryService; | 73 class WebHistoryService; |
78 | 74 |
79 } // namespace history | 75 } // namespace history |
80 | 76 |
81 // The history service records page titles, and visit times, as well as | 77 // The history service records page titles, and visit times, as well as |
82 // (eventually) information about autocomplete. | 78 // (eventually) information about autocomplete. |
83 // | 79 // |
84 // This service is thread safe. Each request callback is invoked in the | 80 // This service is thread safe. Each request callback is invoked in the |
85 // thread that made the request. | 81 // thread that made the request. |
86 class HistoryService : public syncer::SyncableService, | 82 class HistoryService : public syncer::SyncableService, public KeyedService { |
87 public KeyedService, | |
88 public visitedlink::VisitedLinkDelegate { | |
89 public: | 83 public: |
90 // Miscellaneous commonly-used types. | 84 // Miscellaneous commonly-used types. |
91 typedef std::vector<PageUsageData*> PageUsageDataList; | 85 typedef std::vector<PageUsageData*> PageUsageDataList; |
92 | 86 |
93 // Must call Init after construction. The |history::HistoryClient| object | 87 // Must call Init after construction. The empty constructor provided only for |
94 // must be valid for the whole lifetime of |HistoryService|. | 88 // unit tests. |
95 HistoryService(history::HistoryClient* client, Profile* profile); | |
96 // The empty constructor is provided only for testing. | |
97 HistoryService(); | 89 HistoryService(); |
98 | 90 HistoryService(history::HistoryClient* history_client, |
droger
2015/02/02 09:39:21
Do we need a comment here about null arguments?
Do
sdefresne
2015/02/04 18:01:54
Done.
| |
91 scoped_ptr<history::VisitDelegate> visit_delegate); | |
99 ~HistoryService() override; | 92 ~HistoryService() override; |
100 | 93 |
101 // Initializes the history service, returning true on success. On false, do | 94 // Initializes the history service, returning true on success. On false, do |
102 // not call any other functions. The given directory will be used for storing | 95 // not call any other functions. The given directory will be used for storing |
103 // the history files. | 96 // the history files. |
104 bool Init(PrefService* prefs, | 97 bool Init(PrefService* prefs, |
105 const history::HistoryDatabaseParams& history_database_params) { | 98 const history::HistoryDatabaseParams& history_database_params) { |
106 return Init(false, prefs, history_database_params); | 99 return Init(false, prefs, history_database_params); |
107 } | 100 } |
108 | 101 |
109 // Triggers the backend to load if it hasn't already, and then returns whether | 102 // Triggers the backend to load if it hasn't already, and then returns whether |
110 // it's finished loading. | 103 // it's finished loading. |
111 // Note: Virtual needed for mocking. | 104 // Note: Virtual needed for mocking. |
112 virtual bool BackendLoaded(); | 105 virtual bool BackendLoaded(); |
113 | 106 |
114 // Returns true if the backend has finished loading. | 107 // Returns true if the backend has finished loading. |
115 bool backend_loaded() const { return backend_loaded_; } | 108 bool backend_loaded() const { return backend_loaded_; } |
116 | 109 |
117 // Context ids are used to scope page IDs (see AddPage). These contexts | 110 // Context ids are used to scope page IDs (see AddPage). These contexts |
118 // must tell us when they are being invalidated so that we can clear | 111 // must tell us when they are being invalidated so that we can clear |
119 // out any cached data associated with that context. | 112 // out any cached data associated with that context. |
120 void ClearCachedDataForContextID(history::ContextID context_id); | 113 void ClearCachedDataForContextID(history::ContextID context_id); |
121 | 114 |
122 // Triggers the backend to load if it hasn't already, and then returns the | 115 // Triggers the backend to load if it hasn't already, and then returns the |
123 // in-memory URL database. The returned pointer MAY BE NULL if the in-memory | 116 // in-memory URL database. The returned pointer MAY BE null if the in-memory |
droger
2015/02/02 09:39:21
Nit: maybe this should stay in all caps? not sure.
sdefresne
2015/02/04 18:01:54
Done.
| |
124 // database has not been loaded yet. This pointer is owned by the history | 117 // database has not been loaded yet. This pointer is owned by the history |
125 // system. Callers should not store or cache this value. | 118 // system. Callers should not store or cache this value. |
126 // | 119 // |
127 // TODO(brettw) this should return the InMemoryHistoryBackend. | 120 // TODO(brettw) this should return the InMemoryHistoryBackend. |
128 history::URLDatabase* InMemoryDatabase(); | 121 history::URLDatabase* InMemoryDatabase(); |
129 | 122 |
130 // Following functions get URL information from in-memory database. | 123 // Following functions get URL information from in-memory database. |
131 // They return false if database is not available (e.g. not loaded yet) or the | 124 // They return false if database is not available (e.g. not loaded yet) or the |
132 // URL does not exist. | 125 // URL does not exist. |
133 | 126 |
(...skipping 21 matching lines...) Expand all Loading... | |
155 | 148 |
156 // Navigation ---------------------------------------------------------------- | 149 // Navigation ---------------------------------------------------------------- |
157 | 150 |
158 // Adds the given canonical URL to history with the given time as the visit | 151 // Adds the given canonical URL to history with the given time as the visit |
159 // time. Referrer may be the empty string. | 152 // time. Referrer may be the empty string. |
160 // | 153 // |
161 // The supplied context id is used to scope the given page ID. Page IDs | 154 // The supplied context id is used to scope the given page ID. Page IDs |
162 // are only unique inside a given context, so we need that to differentiate | 155 // are only unique inside a given context, so we need that to differentiate |
163 // them. | 156 // them. |
164 // | 157 // |
165 // The context/page ids can be NULL if there is no meaningful tracking | 158 // The context/page ids can be null if there is no meaningful tracking |
166 // information that can be performed on the given URL. The 'nav_entry_id' | 159 // information that can be performed on the given URL. The 'nav_entry_id' |
167 // should be the unique ID of the current navigation entry in the given | 160 // should be the unique ID of the current navigation entry in the given |
168 // process. | 161 // process. |
169 // | 162 // |
170 // 'redirects' is an array of redirect URLs leading to this page, with the | 163 // 'redirects' is an array of redirect URLs leading to this page, with the |
171 // page itself as the last item (so when there is no redirect, it will have | 164 // page itself as the last item (so when there is no redirect, it will have |
172 // one entry). If there are no redirects, this array may also be empty for | 165 // one entry). If there are no redirects, this array may also be empty for |
173 // the convenience of callers. | 166 // the convenience of callers. |
174 // | 167 // |
175 // 'did_replace_entry' is true when the navigation entry for this page has | 168 // 'did_replace_entry' is true when the navigation entry for this page has |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
383 void CreateDownload( | 376 void CreateDownload( |
384 const history::DownloadRow& info, | 377 const history::DownloadRow& info, |
385 const DownloadCreateCallback& callback); | 378 const DownloadCreateCallback& callback); |
386 | 379 |
387 // Responds on the calling thread with the maximum id of all downloads records | 380 // Responds on the calling thread with the maximum id of all downloads records |
388 // in the database plus 1. | 381 // in the database plus 1. |
389 void GetNextDownloadId(const content::DownloadIdCallback& callback); | 382 void GetNextDownloadId(const content::DownloadIdCallback& callback); |
390 | 383 |
391 // Implemented by the caller of 'QueryDownloads' below, and is called when the | 384 // Implemented by the caller of 'QueryDownloads' below, and is called when the |
392 // history service has retrieved a list of all download state. The call | 385 // history service has retrieved a list of all download state. The call |
393 typedef base::Callback<void( | 386 typedef base::Callback<void(scoped_ptr<std::vector<history::DownloadRow>>)> |
394 scoped_ptr<std::vector<history::DownloadRow> >)> | 387 DownloadQueryCallback; |
395 DownloadQueryCallback; | |
396 | 388 |
397 // Begins a history request to retrieve the state of all downloads in the | 389 // Begins a history request to retrieve the state of all downloads in the |
398 // history db. 'callback' runs when the history service request is complete, | 390 // history db. 'callback' runs when the history service request is complete, |
399 // at which point 'info' contains an array of history::DownloadRow, one per | 391 // at which point 'info' contains an array of history::DownloadRow, one per |
400 // download. The callback is called on the thread that calls QueryDownloads(). | 392 // download. The callback is called on the thread that calls QueryDownloads(). |
401 void QueryDownloads(const DownloadQueryCallback& callback); | 393 void QueryDownloads(const DownloadQueryCallback& callback); |
402 | 394 |
403 // Called to update the history service about the current state of a download. | 395 // Called to update the history service about the current state of a download. |
404 // This is a 'fire and forget' query, so just pass the relevant state info to | 396 // This is a 'fire and forget' query, so just pass the relevant state info to |
405 // the database with no need for a callback. | 397 // the database with no need for a callback. |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
543 friend class history::InMemoryURLIndexTest; | 535 friend class history::InMemoryURLIndexTest; |
544 template<typename Info, typename Callback> friend class DownloadRequest; | 536 template<typename Info, typename Callback> friend class DownloadRequest; |
545 friend class PageUsageRequest; | 537 friend class PageUsageRequest; |
546 friend class RedirectRequest; | 538 friend class RedirectRequest; |
547 friend class SyncBookmarkDataTypeControllerTest; | 539 friend class SyncBookmarkDataTypeControllerTest; |
548 friend class TestingProfile; | 540 friend class TestingProfile; |
549 | 541 |
550 // Called on shutdown, this will tell the history backend to complete and | 542 // Called on shutdown, this will tell the history backend to complete and |
551 // will release pointers to it. No other functions should be called once | 543 // will release pointers to it. No other functions should be called once |
552 // cleanup has happened that may dispatch to the history thread (because it | 544 // cleanup has happened that may dispatch to the history thread (because it |
553 // will be NULL). | 545 // will be null). |
554 // | 546 // |
555 // In practice, this will be called by the service manager (BrowserProcess) | 547 // In practice, this will be called by the service manager (BrowserProcess) |
556 // when it is being destroyed. Because that reference is being destroyed, it | 548 // when it is being destroyed. Because that reference is being destroyed, it |
557 // should be impossible for anybody else to call the service, even if it is | 549 // should be impossible for anybody else to call the service, even if it is |
558 // still in memory (pending requests may be holding a reference to us). | 550 // still in memory (pending requests may be holding a reference to us). |
559 void Cleanup(); | 551 void Cleanup(); |
560 | 552 |
561 // Implementation of visitedlink::VisitedLinkDelegate. | |
562 void RebuildTable(const scoped_refptr<URLEnumerator>& enumerator) override; | |
563 | |
564 // Low-level Init(). Same as the public version, but adds a |no_db| parameter | 553 // Low-level Init(). Same as the public version, but adds a |no_db| parameter |
565 // that is only set by unittests which causes the backend to not init its DB. | 554 // that is only set by unittests which causes the backend to not init its DB. |
566 bool Init(bool no_db, | 555 bool Init(bool no_db, |
567 PrefService* prefs, | 556 PrefService* prefs, |
568 const history::HistoryDatabaseParams& history_database_params); | 557 const history::HistoryDatabaseParams& history_database_params); |
569 | 558 |
570 // Called by the HistoryURLProvider class to schedule an autocomplete, it | 559 // Called by the HistoryURLProvider class to schedule an autocomplete, it |
571 // will be called back on the internal history thread with the history | 560 // will be called back on the internal history thread with the history |
572 // database so it can query. See history_autocomplete.cc for a diagram. | 561 // database so it can query. See history_autocomplete.cc for a diagram. |
573 void ScheduleAutocomplete(const base::Callback< | 562 void ScheduleAutocomplete(const base::Callback< |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
805 // This pointer will be NULL once Cleanup() has been called, meaning no | 794 // This pointer will be NULL once Cleanup() has been called, meaning no |
806 // more calls should be made to the history thread. | 795 // more calls should be made to the history thread. |
807 scoped_refptr<history::HistoryBackend> history_backend_; | 796 scoped_refptr<history::HistoryBackend> history_backend_; |
808 | 797 |
809 // A cache of the user-typed URLs kept in memory that is used by the | 798 // A cache of the user-typed URLs kept in memory that is used by the |
810 // autocomplete system. This will be NULL until the database has been created | 799 // autocomplete system. This will be NULL until the database has been created |
811 // on the background thread. | 800 // on the background thread. |
812 // TODO(mrossetti): Consider changing ownership. See http://crbug.com/138321 | 801 // TODO(mrossetti): Consider changing ownership. See http://crbug.com/138321 |
813 scoped_ptr<history::InMemoryHistoryBackend> in_memory_backend_; | 802 scoped_ptr<history::InMemoryHistoryBackend> in_memory_backend_; |
814 | 803 |
804 // The history service will inform its VisitDelegate of URLs recorded and | |
805 // removed from the history database. This may be null during testing. | |
806 scoped_ptr<history::VisitDelegate> visit_delegate_; | |
807 | |
815 // The history client, may be null when testing. The object should otherwise | 808 // The history client, may be null when testing. The object should otherwise |
816 // outlive |HistoryService|. | 809 // outlive |HistoryService|. |
817 history::HistoryClient* history_client_; | 810 history::HistoryClient* history_client_; |
818 | 811 |
819 // Used for propagating link highlighting data across renderers. May be null | |
820 // in tests. | |
821 scoped_ptr<visitedlink::VisitedLinkMaster> visitedlink_master_; | |
822 | |
823 // Has the backend finished loading? The backend is loaded once Init has | 812 // Has the backend finished loading? The backend is loaded once Init has |
824 // completed. | 813 // completed. |
825 bool backend_loaded_; | 814 bool backend_loaded_; |
826 | 815 |
827 // Cached values from Init(), used whenever we need to reload the backend. | 816 // Cached values from Init(), used whenever we need to reload the backend. |
828 base::FilePath history_dir_; | 817 base::FilePath history_dir_; |
829 bool no_db_; | 818 bool no_db_; |
830 | 819 |
831 // The index used for quick history lookups. | 820 // The index used for quick history lookups. |
832 // TODO(mrossetti): Move in_memory_url_index out of history_service. | 821 // TODO(mrossetti): Move in_memory_url_index out of history_service. |
833 // See http://crbug.com/138321 | 822 // See http://crbug.com/138321 |
834 scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_; | 823 scoped_ptr<history::InMemoryURLIndex> in_memory_url_index_; |
835 | 824 |
836 ObserverList<history::HistoryServiceObserver> observers_; | 825 ObserverList<history::HistoryServiceObserver> observers_; |
837 base::CallbackList<void(const std::set<GURL>&)> | 826 base::CallbackList<void(const std::set<GURL>&)> |
838 favicon_changed_callback_list_; | 827 favicon_changed_callback_list_; |
839 | 828 |
840 history::DeleteDirectiveHandler delete_directive_handler_; | 829 history::DeleteDirectiveHandler delete_directive_handler_; |
841 | 830 |
842 // All vended weak pointers are invalidated in Cleanup(). | 831 // All vended weak pointers are invalidated in Cleanup(). |
843 base::WeakPtrFactory<HistoryService> weak_ptr_factory_; | 832 base::WeakPtrFactory<HistoryService> weak_ptr_factory_; |
844 | 833 |
845 DISALLOW_COPY_AND_ASSIGN(HistoryService); | 834 DISALLOW_COPY_AND_ASSIGN(HistoryService); |
846 }; | 835 }; |
847 | 836 |
848 #endif // CHROME_BROWSER_HISTORY_HISTORY_SERVICE_H_ | 837 #endif // CHROME_BROWSER_HISTORY_HISTORY_SERVICE_H_ |
OLD | NEW |