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

Side by Side Diff: chrome/browser/autocomplete/in_memory_url_index.h

Issue 1181353003: Revert of Revert of Abstract //content-level dependencies out of InMemoryURLIndex (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 6 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
« no previous file with comments | « no previous file | chrome/browser/autocomplete/in_memory_url_index.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_AUTOCOMPLETE_IN_MEMORY_URL_INDEX_H_ 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_IN_MEMORY_URL_INDEX_H_
6 #define CHROME_BROWSER_AUTOCOMPLETE_IN_MEMORY_URL_INDEX_H_ 6 #define CHROME_BROWSER_AUTOCOMPLETE_IN_MEMORY_URL_INDEX_H_
7 7
8 #include <functional> 8 #include <functional>
9 #include <map> 9 #include <map>
10 #include <set> 10 #include <set>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/basictypes.h" 14 #include "base/basictypes.h"
15 #include "base/files/file_path.h" 15 #include "base/files/file_path.h"
16 #include "base/gtest_prod_util.h" 16 #include "base/gtest_prod_util.h"
17 #include "base/memory/ref_counted.h" 17 #include "base/memory/ref_counted.h"
18 #include "base/memory/weak_ptr.h" 18 #include "base/memory/weak_ptr.h"
19 #include "base/strings/string16.h" 19 #include "base/strings/string16.h"
20 #include "base/task/cancelable_task_tracker.h" 20 #include "base/task/cancelable_task_tracker.h"
21 #include "base/threading/sequenced_worker_pool.h"
22 #include "base/threading/thread_checker.h"
21 #include "components/history/core/browser/history_db_task.h" 23 #include "components/history/core/browser/history_db_task.h"
22 #include "components/history/core/browser/history_service_observer.h" 24 #include "components/history/core/browser/history_service_observer.h"
23 #include "components/history/core/browser/history_types.h" 25 #include "components/history/core/browser/history_types.h"
24 #include "components/keyed_service/core/keyed_service.h" 26 #include "components/keyed_service/core/keyed_service.h"
25 #include "components/omnibox/scored_history_match.h" 27 #include "components/omnibox/scored_history_match.h"
26 28
27 class HistoryQuickProviderTest; 29 class HistoryQuickProviderTest;
28 30
29 namespace base { 31 namespace base {
30 class SequencedTaskRunner; 32 class SequencedTaskRunner;
31 class Time; 33 class Time;
32 } 34 }
33 35
34 namespace bookmarks { 36 namespace bookmarks {
35 class BookmarkModel; 37 class BookmarkModel;
36 } 38 }
37 39
38 namespace in_memory_url_index { 40 namespace in_memory_url_index {
39 class InMemoryURLIndexCacheItem; 41 class InMemoryURLIndexCacheItem;
40 } 42 }
41 43
42 namespace history { 44 namespace history {
43 class HistoryDatabase; 45 class HistoryDatabase;
44 class HistoryService; 46 class HistoryService;
45 } 47 }
46 48
47 class URLIndexPrivateData; 49 class URLIndexPrivateData;
48 50
51 typedef std::set<std::string> SchemeSet;
52
49 // The URL history source. 53 // The URL history source.
50 // Holds portions of the URL database in memory in an indexed form. Used to 54 // Holds portions of the URL database in memory in an indexed form. Used to
51 // quickly look up matching URLs for a given query string. Used by 55 // quickly look up matching URLs for a given query string. Used by
52 // the HistoryURLProvider for inline autocomplete and to provide URL 56 // the HistoryURLProvider for inline autocomplete and to provide URL
53 // matches to the omnibox. 57 // matches to the omnibox.
54 // 58 //
55 // Note about multi-byte codepoints and the data structures in the 59 // Note about multi-byte codepoints and the data structures in the
56 // InMemoryURLIndex class: One will quickly notice that no effort is made to 60 // InMemoryURLIndex class: One will quickly notice that no effort is made to
57 // insure that multi-byte character boundaries are detected when indexing the 61 // insure that multi-byte character boundaries are detected when indexing the
58 // words and characters in the URL history database except when converting 62 // words and characters in the URL history database except when converting
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 }; 98 };
95 99
96 // |history_service| which may be null during unit testing is used to register 100 // |history_service| which may be null during unit testing is used to register
97 // |as an HistoryServiceObserver. |history_dir| is a path to the directory 101 // |as an HistoryServiceObserver. |history_dir| is a path to the directory
98 // containing the history database within the profile wherein the cache and 102 // containing the history database within the profile wherein the cache and
99 // transaction journals will be stored. |languages| gives a list of language 103 // transaction journals will be stored. |languages| gives a list of language
100 // encodings by which URLs and omnibox searches are broken down into words and 104 // encodings by which URLs and omnibox searches are broken down into words and
101 // characters. 105 // characters.
102 InMemoryURLIndex(bookmarks::BookmarkModel* bookmark_model, 106 InMemoryURLIndex(bookmarks::BookmarkModel* bookmark_model,
103 history::HistoryService* history_service, 107 history::HistoryService* history_service,
108 base::SequencedWorkerPool* worker_pool,
104 const base::FilePath& history_dir, 109 const base::FilePath& history_dir,
105 const std::string& languages); 110 const std::string& languages,
111 const SchemeSet& client_schemes_to_whitelist);
106 ~InMemoryURLIndex() override; 112 ~InMemoryURLIndex() override;
107 113
108 // Opens and prepares the index of historical URL visits. If the index private 114 // Opens and prepares the index of historical URL visits. If the index private
109 // data cannot be restored from its cache file then it is rebuilt from the 115 // data cannot be restored from its cache file then it is rebuilt from the
110 // history database. 116 // history database.
111 void Init(); 117 void Init();
112 118
113 // Scans the history index and returns a vector with all scored, matching 119 // Scans the history index and returns a vector with all scored, matching
114 // history items. This entry point simply forwards the call on to the 120 // history items. This entry point simply forwards the call on to the
115 // URLIndexPrivateData class. For a complete description of this function 121 // URLIndexPrivateData class. For a complete description of this function
(...skipping 29 matching lines...) Expand all
145 friend class InMemoryURLIndexCacheTest; 151 friend class InMemoryURLIndexCacheTest;
146 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, ExpireRow); 152 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, ExpireRow);
147 FRIEND_TEST_ALL_PREFIXES(LimitedInMemoryURLIndexTest, Initialization); 153 FRIEND_TEST_ALL_PREFIXES(LimitedInMemoryURLIndexTest, Initialization);
148 154
149 // HistoryDBTask used to rebuild our private data from the history database. 155 // HistoryDBTask used to rebuild our private data from the history database.
150 class RebuildPrivateDataFromHistoryDBTask : public history::HistoryDBTask { 156 class RebuildPrivateDataFromHistoryDBTask : public history::HistoryDBTask {
151 public: 157 public:
152 explicit RebuildPrivateDataFromHistoryDBTask( 158 explicit RebuildPrivateDataFromHistoryDBTask(
153 InMemoryURLIndex* index, 159 InMemoryURLIndex* index,
154 const std::string& languages, 160 const std::string& languages,
155 const std::set<std::string>& scheme_whitelist); 161 const SchemeSet& scheme_whitelist);
156 162
157 bool RunOnDBThread(history::HistoryBackend* backend, 163 bool RunOnDBThread(history::HistoryBackend* backend,
158 history::HistoryDatabase* db) override; 164 history::HistoryDatabase* db) override;
159 void DoneRunOnMainThread() override; 165 void DoneRunOnMainThread() override;
160 166
161 private: 167 private:
162 ~RebuildPrivateDataFromHistoryDBTask() override; 168 ~RebuildPrivateDataFromHistoryDBTask() override;
163 169
164 InMemoryURLIndex* index_; // Call back to this index at completion. 170 InMemoryURLIndex* index_; // Call back to this index at completion.
165 std::string languages_; // Languages for word-breaking. 171 std::string languages_; // Languages for word-breaking.
166 std::set<std::string> scheme_whitelist_; // Schemes to be indexed. 172 SchemeSet scheme_whitelist_; // Schemes to be indexed.
167 bool succeeded_; // Indicates if the rebuild was successful. 173 bool succeeded_; // Indicates if the rebuild was successful.
168 scoped_refptr<URLIndexPrivateData> data_; // The rebuilt private data. 174 scoped_refptr<URLIndexPrivateData> data_; // The rebuilt private data.
169 175
170 DISALLOW_COPY_AND_ASSIGN(RebuildPrivateDataFromHistoryDBTask); 176 DISALLOW_COPY_AND_ASSIGN(RebuildPrivateDataFromHistoryDBTask);
171 }; 177 };
172 178
173 // Initializes all index data members in preparation for restoring the index 179 // Initializes all index data members in preparation for restoring the index
174 // from the cache or a complete rebuild from the history database. 180 // from the cache or a complete rebuild from the history database.
175 void ClearPrivateData(); 181 void ClearPrivateData();
176 182
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
255 // Returns a pointer to our private data. For unit testing only. 261 // Returns a pointer to our private data. For unit testing only.
256 URLIndexPrivateData* private_data() { return private_data_.get(); } 262 URLIndexPrivateData* private_data() { return private_data_.get(); }
257 263
258 // Returns a pointer to our private data cancelable request tracker. For 264 // Returns a pointer to our private data cancelable request tracker. For
259 // unit testing only. 265 // unit testing only.
260 base::CancelableTaskTracker* private_data_tracker() { 266 base::CancelableTaskTracker* private_data_tracker() {
261 return &private_data_tracker_; 267 return &private_data_tracker_;
262 } 268 }
263 269
264 // Returns the set of whitelisted schemes. For unit testing only. 270 // Returns the set of whitelisted schemes. For unit testing only.
265 const std::set<std::string>& scheme_whitelist() { return scheme_whitelist_; } 271 const SchemeSet& scheme_whitelist() { return scheme_whitelist_; }
266 272
267 // The BookmarkModel; may be null when testing. 273 // The BookmarkModel; may be null when testing.
268 bookmarks::BookmarkModel* bookmark_model_; 274 bookmarks::BookmarkModel* bookmark_model_;
269 275
270 // The HistoryService; may be null when testing. 276 // The HistoryService; may be null when testing.
271 history::HistoryService* history_service_; 277 history::HistoryService* history_service_;
272 278
273 // Directory where cache file resides. This is, except when unit testing, 279 // Directory where cache file resides. This is, except when unit testing,
274 // the same directory in which the history database is found. It should never 280 // the same directory in which the history database is found. It should never
275 // be empty. 281 // be empty.
276 base::FilePath history_dir_; 282 base::FilePath history_dir_;
277 283
278 // Languages used during the word-breaking process during indexing. 284 // Languages used during the word-breaking process during indexing.
279 std::string languages_; 285 std::string languages_;
280 286
281 // Only URLs with a whitelisted scheme are indexed. 287 // Only URLs with a whitelisted scheme are indexed.
282 std::set<std::string> scheme_whitelist_; 288 SchemeSet scheme_whitelist_;
283 289
284 // The index's durable private data. 290 // The index's durable private data.
285 scoped_refptr<URLIndexPrivateData> private_data_; 291 scoped_refptr<URLIndexPrivateData> private_data_;
286 292
287 // Observers to notify upon restoral or save of the private data cache. 293 // Observers to notify upon restoral or save of the private data cache.
288 RestoreCacheObserver* restore_cache_observer_; 294 RestoreCacheObserver* restore_cache_observer_;
289 SaveCacheObserver* save_cache_observer_; 295 SaveCacheObserver* save_cache_observer_;
290 296
291 // Task runner from the worker pool, used for operations which require disk 297 // Task runner from the worker pool, used for operations which require disk
292 // access. 298 // access.
(...skipping 11 matching lines...) Expand all
304 // Set to true when changes to the index have been made and the index needs 310 // Set to true when changes to the index have been made and the index needs
305 // to be cached. Set to false when the index has been cached. Used as a 311 // to be cached. Set to false when the index has been cached. Used as a
306 // temporary safety check to insure that the cache is saved before the 312 // temporary safety check to insure that the cache is saved before the
307 // index has been destructed. 313 // index has been destructed.
308 bool needs_to_be_cached_; 314 bool needs_to_be_cached_;
309 315
310 // This flag is set to true if we want to listen to the 316 // This flag is set to true if we want to listen to the
311 // HistoryServiceLoaded Notification. 317 // HistoryServiceLoaded Notification.
312 bool listen_to_history_service_loaded_; 318 bool listen_to_history_service_loaded_;
313 319
320 base::ThreadChecker thread_checker_;
321
314 DISALLOW_COPY_AND_ASSIGN(InMemoryURLIndex); 322 DISALLOW_COPY_AND_ASSIGN(InMemoryURLIndex);
315 }; 323 };
316 324
317 #endif // CHROME_BROWSER_AUTOCOMPLETE_IN_MEMORY_URL_INDEX_H_ 325 #endif // CHROME_BROWSER_AUTOCOMPLETE_IN_MEMORY_URL_INDEX_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autocomplete/in_memory_url_index.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698