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_URL_INDEX_PRIVATE_DATA_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_ |
6 #define CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_ | 6 #define CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
11 #include "chrome/browser/history/in_memory_url_index_types.h" | 11 #include "chrome/browser/history/in_memory_url_index_types.h" |
12 #include "chrome/browser/history/in_memory_url_index_cache.pb.h" | 12 #include "chrome/browser/history/in_memory_url_index_cache.pb.h" |
13 | 13 |
| 14 class HistoryQuickProviderTest; |
| 15 |
14 namespace in_memory_url_index { | 16 namespace in_memory_url_index { |
15 class InMemoryURLIndexCacheItem; | 17 class InMemoryURLIndexCacheItem; |
16 } | 18 } |
17 | 19 |
18 namespace history { | 20 namespace history { |
19 | 21 |
20 namespace imui = in_memory_url_index; | 22 namespace imui = in_memory_url_index; |
21 | 23 |
| 24 class HistoryDatabase; |
| 25 |
22 // A structure describing the InMemoryURLIndex's internal data and providing for | 26 // A structure describing the InMemoryURLIndex's internal data and providing for |
23 // restoring, rebuilding and updating that internal data. | 27 // restoring, rebuilding and updating that internal data. |
24 class URLIndexPrivateData { | 28 class URLIndexPrivateData { |
25 public: | 29 public: |
26 URLIndexPrivateData(); | 30 URLIndexPrivateData(); |
27 ~URLIndexPrivateData(); | 31 ~URLIndexPrivateData(); |
28 | 32 |
29 private: | 33 private: |
| 34 friend class AddHistoryMatch; |
| 35 friend class ::HistoryQuickProviderTest; |
30 friend class InMemoryURLIndex; | 36 friend class InMemoryURLIndex; |
31 friend class AddHistoryMatch; | |
32 friend class InMemoryURLIndexTest; | 37 friend class InMemoryURLIndexTest; |
33 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, CacheSaveRestore); | 38 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, CacheSaveRestore); |
34 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, HugeResultSet); | 39 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, HugeResultSet); |
35 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, Scoring); | 40 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, Scoring); |
36 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, TitleSearch); | 41 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, TitleSearch); |
37 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, TypedCharacterCaching); | 42 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, TypedCharacterCaching); |
38 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, WhitelistedURLs); | 43 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, WhitelistedURLs); |
39 FRIEND_TEST_ALL_PREFIXES(LimitedInMemoryURLIndexTest, Initialization); | 44 FRIEND_TEST_ALL_PREFIXES(LimitedInMemoryURLIndexTest, Initialization); |
40 | 45 |
41 // Support caching of term results so that we can optimize searches which | 46 // Support caching of term results so that we can optimize searches which |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 128 |
124 // Sets the |languages| to a list of language encodings with which the history | 129 // Sets the |languages| to a list of language encodings with which the history |
125 // URLs and omnibox searches are interpreted, i.e. how each is broken | 130 // URLs and omnibox searches are interpreted, i.e. how each is broken |
126 // down into words and each word is broken down into characters. | 131 // down into words and each word is broken down into characters. |
127 void set_languages(const std::string& languages) { languages_ = languages; } | 132 void set_languages(const std::string& languages) { languages_ = languages; } |
128 | 133 |
129 // Restores the index's private data from the cache file stored in the | 134 // Restores the index's private data from the cache file stored in the |
130 // profile directory and returns true if successful. | 135 // profile directory and returns true if successful. |
131 bool RestoreFromFile(const FilePath& file_path); | 136 bool RestoreFromFile(const FilePath& file_path); |
132 | 137 |
| 138 // Constructs a new object by rebuilding its contents from the history |
| 139 // database in |history_db|. Returns the new URLIndexPrivateData which on |
| 140 // success will contain the rebuilt data but upon failure will be empty. |
| 141 static URLIndexPrivateData* RebuildFromHistory(HistoryDatabase* history_db); |
| 142 |
133 // Caches the index private data and writes the cache file to the profile | 143 // Caches the index private data and writes the cache file to the profile |
134 // directory. | 144 // directory. |
135 bool SaveToFile(const FilePath& file_path); | 145 bool SaveToFile(const FilePath& file_path); |
136 | 146 |
137 // Reloads the history index from |history_db|. | |
138 bool ReloadFromHistory(URLDatabase* history_db); | |
139 | |
140 // Initializes all index data members in preparation for restoring the index | 147 // Initializes all index data members in preparation for restoring the index |
141 // from the cache or a complete rebuild from the history database. | 148 // from the cache or a complete rebuild from the history database. |
142 void Clear(); | 149 void Clear(); |
143 | 150 |
144 // Adds |word_id| to |history_id|'s entry in the history/word map, | 151 // Adds |word_id| to |history_id|'s entry in the history/word map, |
145 // creating a new entry if one does not already exist. | 152 // creating a new entry if one does not already exist. |
146 void AddToHistoryIDWordMap(HistoryID history_id, WordID word_id); | 153 void AddToHistoryIDWordMap(HistoryID history_id, WordID word_id); |
147 | 154 |
148 // Given a set of Char16s, finds words containing those characters. | 155 // Given a set of Char16s, finds words containing those characters. |
149 WordIDSet WordIDSetForTermChars(const Char16Set& term_chars); | 156 WordIDSet WordIDSetForTermChars(const Char16Set& term_chars); |
150 | 157 |
151 // Initializes the whitelist of URL schemes. | 158 // Initializes the whitelist of URL schemes. |
152 static void InitializeSchemeWhitelist(std::set<std::string>* whitelist); | 159 static void InitializeSchemeWhitelist(std::set<std::string>* whitelist); |
153 | 160 |
154 // URL History indexing support functions. | 161 // URL History indexing support functions. |
155 | 162 |
156 // Indexes one URL history item. | 163 // Indexes one URL history item as described by |row|. Returns true if the |
157 void IndexRow(const URLRow& row); | 164 // row was actually indexed. |
| 165 bool IndexRow(const URLRow& row); |
158 | 166 |
159 // Updates or adds an history item to the index if it meets the minimum | 167 // Adds the history item in |row| to the index if it does not already already |
160 // 'quick' criteria. | 168 // exist and it meets the minimum 'quick' criteria. If the row already exists |
161 void UpdateURL(URLID row_id, const URLRow& row); | 169 // in the index then the index will be updated if the row still meets the |
| 170 // criteria, otherwise the row will be removed from the index. Returns true |
| 171 // if the index was actually updated. |
| 172 bool UpdateURL(const URLRow& row); |
162 | 173 |
163 // Deletes indexing data for an history item. The item may not have actually | 174 // Deletes indexing data for the history item with the URL given in |url|. |
164 // been indexed (which is the case if it did not previously meet minimum | 175 // The item may not have actually been indexed, which is the case if it did |
165 // 'quick' criteria). | 176 // not previously meet minimum 'quick' criteria. Returns true if the index |
166 void DeleteURL(URLID row_id); | 177 // was actually updated. |
| 178 bool DeleteURL(const GURL& url); |
167 | 179 |
168 // Parses and indexes the words in the URL and page title of |row|. | 180 // Parses and indexes the words in the URL and page title of |row|. |
169 void AddRowWordsToIndex(const URLRow& row); | 181 void AddRowWordsToIndex(const URLRow& row); |
170 | 182 |
171 // Removes |row| and all associated words and characters from the index. | 183 // Removes |row| and all associated words and characters from the index. |
172 void RemoveRowFromIndex(const URLRow& row); | 184 void RemoveRowFromIndex(const URLRow& row); |
173 | 185 |
174 // Removes all words and characters associated with |row| from the index. | 186 // Removes all words and characters associated with |row| from the index. |
175 void RemoveRowWordsFromIndex(const URLRow& row); | 187 void RemoveRowWordsFromIndex(const URLRow& row); |
176 | 188 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 // Used for unit testing only. Records the number of candidate history items | 302 // Used for unit testing only. Records the number of candidate history items |
291 // at three stages in the index searching process. | 303 // at three stages in the index searching process. |
292 size_t pre_filter_item_count_; // After word index is queried. | 304 size_t pre_filter_item_count_; // After word index is queried. |
293 size_t post_filter_item_count_; // After trimming large result set. | 305 size_t post_filter_item_count_; // After trimming large result set. |
294 size_t post_scoring_item_count_; // After performing final filter/scoring. | 306 size_t post_scoring_item_count_; // After performing final filter/scoring. |
295 }; | 307 }; |
296 | 308 |
297 } // namespace history | 309 } // namespace history |
298 | 310 |
299 #endif // CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_ | 311 #endif // CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_ |
OLD | NEW |