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