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

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

Issue 872313005: Remove dependency on visitedlink from history (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@init-prefs
Patch Set: Rebase Created 5 years, 10 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
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_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 <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
(...skipping 11 matching lines...) Expand all
22 #include "base/strings/string16.h" 22 #include "base/strings/string16.h"
23 #include "base/task/cancelable_task_tracker.h" 23 #include "base/task/cancelable_task_tracker.h"
24 #include "base/threading/thread_checker.h" 24 #include "base/threading/thread_checker.h"
25 #include "base/time/time.h" 25 #include "base/time/time.h"
26 #include "chrome/browser/history/delete_directive_handler.h" 26 #include "chrome/browser/history/delete_directive_handler.h"
27 #include "chrome/browser/history/typed_url_syncable_service.h" 27 #include "chrome/browser/history/typed_url_syncable_service.h"
28 #include "components/favicon_base/favicon_callback.h" 28 #include "components/favicon_base/favicon_callback.h"
29 #include "components/favicon_base/favicon_usage_data.h" 29 #include "components/favicon_base/favicon_usage_data.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 "sql/init_status.h" 32 #include "sql/init_status.h"
34 #include "sync/api/syncable_service.h" 33 #include "sync/api/syncable_service.h"
35 #include "ui/base/page_transition_types.h" 34 #include "ui/base/page_transition_types.h"
36 35
37 #if defined(OS_ANDROID) 36 #if defined(OS_ANDROID)
38 class AndroidHistoryProviderService; 37 class AndroidHistoryProviderService;
39 #endif 38 #endif
40 39
41 class GURL; 40 class GURL;
42 class HistoryService;
43 class PageUsageRequest; 41 class PageUsageRequest;
44 class Profile;
45 class SkBitmap; 42 class SkBitmap;
46 43
47 namespace base { 44 namespace base {
48 class FilePath; 45 class FilePath;
49 class Thread; 46 class Thread;
50 } 47 }
51 48
52 namespace visitedlink {
53 class VisitedLinkMaster;
54 }
55
56 namespace history { 49 namespace history {
57 50
58 struct DownloadRow; 51 struct DownloadRow;
59 struct HistoryAddPageArgs; 52 struct HistoryAddPageArgs;
60 class HistoryBackend; 53 class HistoryBackend;
61 class HistoryClient; 54 class HistoryClient;
62 class HistoryDBTask; 55 class HistoryDBTask;
63 class HistoryDatabase; 56 class HistoryDatabase;
64 struct HistoryDatabaseParams; 57 struct HistoryDatabaseParams;
65 class HistoryQueryTest; 58 class HistoryQueryTest;
66 class HistoryServiceObserver; 59 class HistoryServiceObserver;
67 class HistoryTest; 60 class HistoryTest;
68 class InMemoryHistoryBackend; 61 class InMemoryHistoryBackend;
69 class InMemoryURLIndex; 62 class InMemoryURLIndex;
70 class InMemoryURLIndexTest; 63 class InMemoryURLIndexTest;
71 struct KeywordSearchTermVisit; 64 struct KeywordSearchTermVisit;
72 class PageUsageData; 65 class PageUsageData;
73 class URLDatabase; 66 class URLDatabase;
67 class VisitDelegate;
74 class VisitFilter; 68 class VisitFilter;
75 class WebHistoryService; 69 class WebHistoryService;
76 70
77 } // namespace history 71 } // namespace history
78 72
79 // The history service records page titles, and visit times, as well as 73 // The history service records page titles, and visit times, as well as
80 // (eventually) information about autocomplete. 74 // (eventually) information about autocomplete.
81 // 75 //
82 // This service is thread safe. Each request callback is invoked in the 76 // This service is thread safe. Each request callback is invoked in the
83 // thread that made the request. 77 // thread that made the request.
84 class HistoryService : public syncer::SyncableService, 78 class HistoryService : public syncer::SyncableService, public KeyedService {
85 public KeyedService,
86 public visitedlink::VisitedLinkDelegate {
87 public: 79 public:
88 // Miscellaneous commonly-used types. 80 // Miscellaneous commonly-used types.
89 typedef std::vector<history::PageUsageData*> PageUsageDataList; 81 typedef std::vector<history::PageUsageData*> PageUsageDataList;
90 82
91 // Must call Init after construction. The |history::HistoryClient| object 83 // Must call Init after construction. The empty constructor provided only for
92 // must be valid for the whole lifetime of |HistoryService|. 84 // unit tests. When using the full constructor, |history_client| and |profile|
93 HistoryService(history::HistoryClient* client, Profile* profile); 85 // should only be null during testing, while |visit_delegate| may be null if
94 // The empty constructor is provided only for testing. 86 // the embedder use another way to track visited links.
95 HistoryService(); 87 HistoryService();
96 88 HistoryService(history::HistoryClient* history_client,
89 scoped_ptr<history::VisitDelegate> visit_delegate);
97 ~HistoryService() override; 90 ~HistoryService() override;
98 91
99 // Initializes the history service, returning true on success. On false, do 92 // Initializes the history service, returning true on success. On false, do
100 // not call any other functions. The given directory will be used for storing 93 // not call any other functions. The given directory will be used for storing
101 // the history files. |languages| is a comma-separated list of languages to 94 // the history files. |languages| is a comma-separated list of languages to
102 // use when interpreting URLs, it must not be empty (except during testing). 95 // use when interpreting URLs, it must not be empty (except during testing).
103 bool Init(const std::string& languages, 96 bool Init(const std::string& languages,
104 const history::HistoryDatabaseParams& history_database_params) { 97 const history::HistoryDatabaseParams& history_database_params) {
105 return Init(false, languages, history_database_params); 98 return Init(false, languages, history_database_params);
106 } 99 }
107 100
108 // Triggers the backend to load if it hasn't already, and then returns whether 101 // Triggers the backend to load if it hasn't already, and then returns whether
109 // it's finished loading. 102 // it's finished loading.
110 // Note: Virtual needed for mocking. 103 // Note: Virtual needed for mocking.
111 virtual bool BackendLoaded(); 104 virtual bool BackendLoaded();
112 105
113 // Returns true if the backend has finished loading. 106 // Returns true if the backend has finished loading.
114 bool backend_loaded() const { return backend_loaded_; } 107 bool backend_loaded() const { return backend_loaded_; }
115 108
116 // Context ids are used to scope page IDs (see AddPage). These contexts 109 // Context ids are used to scope page IDs (see AddPage). These contexts
117 // must tell us when they are being invalidated so that we can clear 110 // must tell us when they are being invalidated so that we can clear
118 // out any cached data associated with that context. 111 // out any cached data associated with that context.
119 void ClearCachedDataForContextID(history::ContextID context_id); 112 void ClearCachedDataForContextID(history::ContextID context_id);
120 113
121 // Triggers the backend to load if it hasn't already, and then returns the 114 // Triggers the backend to load if it hasn't already, and then returns the
122 // in-memory URL database. The returned pointer MAY BE NULL if the in-memory 115 // in-memory URL database. The returned pointer may be null if the in-memory
123 // database has not been loaded yet. This pointer is owned by the history 116 // database has not been loaded yet. This pointer is owned by the history
124 // system. Callers should not store or cache this value. 117 // system. Callers should not store or cache this value.
125 // 118 //
126 // TODO(brettw) this should return the InMemoryHistoryBackend. 119 // TODO(brettw) this should return the InMemoryHistoryBackend.
127 history::URLDatabase* InMemoryDatabase(); 120 history::URLDatabase* InMemoryDatabase();
128 121
129 // Following functions get URL information from in-memory database. 122 // Following functions get URL information from in-memory database.
130 // They return false if database is not available (e.g. not loaded yet) or the 123 // They return false if database is not available (e.g. not loaded yet) or the
131 // URL does not exist. 124 // URL does not exist.
132 125
(...skipping 21 matching lines...) Expand all
154 147
155 // Navigation ---------------------------------------------------------------- 148 // Navigation ----------------------------------------------------------------
156 149
157 // Adds the given canonical URL to history with the given time as the visit 150 // Adds the given canonical URL to history with the given time as the visit
158 // time. Referrer may be the empty string. 151 // time. Referrer may be the empty string.
159 // 152 //
160 // The supplied context id is used to scope the given page ID. Page IDs 153 // The supplied context id is used to scope the given page ID. Page IDs
161 // are only unique inside a given context, so we need that to differentiate 154 // are only unique inside a given context, so we need that to differentiate
162 // them. 155 // them.
163 // 156 //
164 // The context/page ids can be NULL if there is no meaningful tracking 157 // The context/page ids can be null if there is no meaningful tracking
165 // information that can be performed on the given URL. The 'nav_entry_id' 158 // information that can be performed on the given URL. The 'nav_entry_id'
166 // should be the unique ID of the current navigation entry in the given 159 // should be the unique ID of the current navigation entry in the given
167 // process. 160 // process.
168 // 161 //
169 // 'redirects' is an array of redirect URLs leading to this page, with the 162 // 'redirects' is an array of redirect URLs leading to this page, with the
170 // page itself as the last item (so when there is no redirect, it will have 163 // page itself as the last item (so when there is no redirect, it will have
171 // one entry). If there are no redirects, this array may also be empty for 164 // one entry). If there are no redirects, this array may also be empty for
172 // the convenience of callers. 165 // the convenience of callers.
173 // 166 //
174 // 'did_replace_entry' is true when the navigation entry for this page has 167 // 'did_replace_entry' is true when the navigation entry for this page has
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 // Implemented by the caller of 'GetNextDownloadId' below, and is called with 379 // Implemented by the caller of 'GetNextDownloadId' below, and is called with
387 // the maximum id of all downloads records in the database plus 1. 380 // the maximum id of all downloads records in the database plus 1.
388 typedef base::Callback<void(uint32)> DownloadIdCallback; 381 typedef base::Callback<void(uint32)> DownloadIdCallback;
389 382
390 // Responds on the calling thread with the maximum id of all downloads records 383 // Responds on the calling thread with the maximum id of all downloads records
391 // in the database plus 1. 384 // in the database plus 1.
392 void GetNextDownloadId(const DownloadIdCallback& callback); 385 void GetNextDownloadId(const DownloadIdCallback& callback);
393 386
394 // Implemented by the caller of 'QueryDownloads' below, and is called when the 387 // Implemented by the caller of 'QueryDownloads' below, and is called when the
395 // history service has retrieved a list of all download state. The call 388 // history service has retrieved a list of all download state. The call
396 typedef base::Callback<void( 389 typedef base::Callback<void(scoped_ptr<std::vector<history::DownloadRow>>)>
397 scoped_ptr<std::vector<history::DownloadRow> >)> 390 DownloadQueryCallback;
398 DownloadQueryCallback;
399 391
400 // Begins a history request to retrieve the state of all downloads in the 392 // Begins a history request to retrieve the state of all downloads in the
401 // history db. 'callback' runs when the history service request is complete, 393 // history db. 'callback' runs when the history service request is complete,
402 // at which point 'info' contains an array of history::DownloadRow, one per 394 // at which point 'info' contains an array of history::DownloadRow, one per
403 // download. The callback is called on the thread that calls QueryDownloads(). 395 // download. The callback is called on the thread that calls QueryDownloads().
404 void QueryDownloads(const DownloadQueryCallback& callback); 396 void QueryDownloads(const DownloadQueryCallback& callback);
405 397
406 // Called to update the history service about the current state of a download. 398 // Called to update the history service about the current state of a download.
407 // This is a 'fire and forget' query, so just pass the relevant state info to 399 // This is a 'fire and forget' query, so just pass the relevant state info to
408 // the database with no need for a callback. 400 // the database with no need for a callback.
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 const std::string& languages, 556 const std::string& languages,
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
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_
OLDNEW
« no previous file with comments | « chrome/browser/history/history_backend_unittest.cc ('k') | chrome/browser/history/history_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698