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

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

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