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 COMPONENTS_OMNIBOX_BROWSER_IN_MEMORY_URL_INDEX_H_ | 5 #ifndef COMPONENTS_OMNIBOX_BROWSER_IN_MEMORY_URL_INDEX_H_ |
6 #define COMPONENTS_OMNIBOX_BROWSER_IN_MEMORY_URL_INDEX_H_ | 6 #define COMPONENTS_OMNIBOX_BROWSER_IN_MEMORY_URL_INDEX_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <functional> | 10 #include <functional> |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 virtual ~SaveCacheObserver(); | 96 virtual ~SaveCacheObserver(); |
97 | 97 |
98 // Callback that lets the observer know that the save succeeded. | 98 // Callback that lets the observer know that the save succeeded. |
99 // This is called on the UI thread. | 99 // This is called on the UI thread. |
100 virtual void OnCacheSaveFinished(bool succeeded) = 0; | 100 virtual void OnCacheSaveFinished(bool succeeded) = 0; |
101 }; | 101 }; |
102 | 102 |
103 // |history_service| which may be null during unit testing is used to register | 103 // |history_service| which may be null during unit testing is used to register |
104 // |as an HistoryServiceObserver. |history_dir| is a path to the directory | 104 // |as an HistoryServiceObserver. |history_dir| is a path to the directory |
105 // containing the history database within the profile wherein the cache and | 105 // containing the history database within the profile wherein the cache and |
106 // transaction journals will be stored. |languages| gives a list of language | 106 // transaction journals will be stored. |
107 // encodings by which URLs and omnibox searches are broken down into words and | |
108 // characters. | |
109 InMemoryURLIndex(bookmarks::BookmarkModel* bookmark_model, | 107 InMemoryURLIndex(bookmarks::BookmarkModel* bookmark_model, |
110 history::HistoryService* history_service, | 108 history::HistoryService* history_service, |
111 TemplateURLService* template_url_service, | 109 TemplateURLService* template_url_service, |
112 base::SequencedWorkerPool* worker_pool, | 110 base::SequencedWorkerPool* worker_pool, |
113 const base::FilePath& history_dir, | 111 const base::FilePath& history_dir, |
114 const std::string& languages, | |
115 const SchemeSet& client_schemes_to_whitelist); | 112 const SchemeSet& client_schemes_to_whitelist); |
116 ~InMemoryURLIndex() override; | 113 ~InMemoryURLIndex() override; |
117 | 114 |
118 // Opens and prepares the index of historical URL visits. If the index private | 115 // Opens and prepares the index of historical URL visits. If the index private |
119 // data cannot be restored from its cache file then it is rebuilt from the | 116 // data cannot be restored from its cache file then it is rebuilt from the |
120 // history database. | 117 // history database. |
121 void Init(); | 118 void Init(); |
122 | 119 |
123 // Scans the history index and returns a vector with all scored, matching | 120 // Scans the history index and returns a vector with all scored, matching |
124 // history items. This entry point simply forwards the call on to the | 121 // history items. This entry point simply forwards the call on to the |
(...skipping 28 matching lines...) Expand all Loading... |
153 friend class ::HistoryQuickProviderTest; | 150 friend class ::HistoryQuickProviderTest; |
154 friend class InMemoryURLIndexTest; | 151 friend class InMemoryURLIndexTest; |
155 friend class InMemoryURLIndexCacheTest; | 152 friend class InMemoryURLIndexCacheTest; |
156 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, ExpireRow); | 153 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, ExpireRow); |
157 FRIEND_TEST_ALL_PREFIXES(LimitedInMemoryURLIndexTest, Initialization); | 154 FRIEND_TEST_ALL_PREFIXES(LimitedInMemoryURLIndexTest, Initialization); |
158 | 155 |
159 // HistoryDBTask used to rebuild our private data from the history database. | 156 // HistoryDBTask used to rebuild our private data from the history database. |
160 class RebuildPrivateDataFromHistoryDBTask : public history::HistoryDBTask { | 157 class RebuildPrivateDataFromHistoryDBTask : public history::HistoryDBTask { |
161 public: | 158 public: |
162 explicit RebuildPrivateDataFromHistoryDBTask( | 159 explicit RebuildPrivateDataFromHistoryDBTask( |
163 InMemoryURLIndex* index, | 160 InMemoryURLIndex* index, const SchemeSet& scheme_whitelist); |
164 const std::string& languages, | |
165 const SchemeSet& scheme_whitelist); | |
166 | 161 |
167 bool RunOnDBThread(history::HistoryBackend* backend, | 162 bool RunOnDBThread(history::HistoryBackend* backend, |
168 history::HistoryDatabase* db) override; | 163 history::HistoryDatabase* db) override; |
169 void DoneRunOnMainThread() override; | 164 void DoneRunOnMainThread() override; |
170 | 165 |
171 private: | 166 private: |
172 ~RebuildPrivateDataFromHistoryDBTask() override; | 167 ~RebuildPrivateDataFromHistoryDBTask() override; |
173 | 168 |
174 InMemoryURLIndex* index_; // Call back to this index at completion. | 169 InMemoryURLIndex* index_; // Call back to this index at completion. |
175 std::string languages_; // Languages for word-breaking. | |
176 SchemeSet scheme_whitelist_; // Schemes to be indexed. | 170 SchemeSet scheme_whitelist_; // Schemes to be indexed. |
177 bool succeeded_; // Indicates if the rebuild was successful. | 171 bool succeeded_; // Indicates if the rebuild was successful. |
178 scoped_refptr<URLIndexPrivateData> data_; // The rebuilt private data. | 172 scoped_refptr<URLIndexPrivateData> data_; // The rebuilt private data. |
179 | 173 |
180 DISALLOW_COPY_AND_ASSIGN(RebuildPrivateDataFromHistoryDBTask); | 174 DISALLOW_COPY_AND_ASSIGN(RebuildPrivateDataFromHistoryDBTask); |
181 }; | 175 }; |
182 | 176 |
183 // Initializes all index data members in preparation for restoring the index | 177 // Initializes all index data members in preparation for restoring the index |
184 // from the cache or a complete rebuild from the history database. | 178 // from the cache or a complete rebuild from the history database. |
185 void ClearPrivateData(); | 179 void ClearPrivateData(); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 | 276 |
283 // The TemplateURLService; may be null when testing. Used to identify URLs | 277 // The TemplateURLService; may be null when testing. Used to identify URLs |
284 // that are from the default search provider. | 278 // that are from the default search provider. |
285 TemplateURLService* template_url_service_; | 279 TemplateURLService* template_url_service_; |
286 | 280 |
287 // Directory where cache file resides. This is, except when unit testing, | 281 // Directory where cache file resides. This is, except when unit testing, |
288 // the same directory in which the history database is found. It should never | 282 // the same directory in which the history database is found. It should never |
289 // be empty. | 283 // be empty. |
290 base::FilePath history_dir_; | 284 base::FilePath history_dir_; |
291 | 285 |
292 // Languages used during the word-breaking process during indexing. | |
293 std::string languages_; | |
294 | |
295 // Only URLs with a whitelisted scheme are indexed. | 286 // Only URLs with a whitelisted scheme are indexed. |
296 SchemeSet scheme_whitelist_; | 287 SchemeSet scheme_whitelist_; |
297 | 288 |
298 // The index's durable private data. | 289 // The index's durable private data. |
299 scoped_refptr<URLIndexPrivateData> private_data_; | 290 scoped_refptr<URLIndexPrivateData> private_data_; |
300 | 291 |
301 // Observers to notify upon restoral or save of the private data cache. | 292 // Observers to notify upon restoral or save of the private data cache. |
302 RestoreCacheObserver* restore_cache_observer_; | 293 RestoreCacheObserver* restore_cache_observer_; |
303 SaveCacheObserver* save_cache_observer_; | 294 SaveCacheObserver* save_cache_observer_; |
304 | 295 |
(...skipping 19 matching lines...) Expand all Loading... |
324 // This flag is set to true if we want to listen to the | 315 // This flag is set to true if we want to listen to the |
325 // HistoryServiceLoaded Notification. | 316 // HistoryServiceLoaded Notification. |
326 bool listen_to_history_service_loaded_; | 317 bool listen_to_history_service_loaded_; |
327 | 318 |
328 base::ThreadChecker thread_checker_; | 319 base::ThreadChecker thread_checker_; |
329 | 320 |
330 DISALLOW_COPY_AND_ASSIGN(InMemoryURLIndex); | 321 DISALLOW_COPY_AND_ASSIGN(InMemoryURLIndex); |
331 }; | 322 }; |
332 | 323 |
333 #endif // COMPONENTS_OMNIBOX_BROWSER_IN_MEMORY_URL_INDEX_H_ | 324 #endif // COMPONENTS_OMNIBOX_BROWSER_IN_MEMORY_URL_INDEX_H_ |
OLD | NEW |