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

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

Issue 8275004: Revert 105300 - HQP Refactoring (in Preparation for SQLite Cache) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_IN_MEMORY_URL_INDEX_H_ 5 #ifndef CHROME_BROWSER_HISTORY_IN_MEMORY_URL_INDEX_H_
6 #define CHROME_BROWSER_HISTORY_IN_MEMORY_URL_INDEX_H_ 6 #define CHROME_BROWSER_HISTORY_IN_MEMORY_URL_INDEX_H_
7 #pragma once 7 #pragma once
8 8
9 #include <functional> 9 #include <functional>
10 #include <map> 10 #include <map>
11 #include <set> 11 #include <set>
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/basictypes.h" 15 #include "base/basictypes.h"
16 #include "base/file_path.h" 16 #include "base/file_path.h"
17 #include "base/gtest_prod_util.h" 17 #include "base/gtest_prod_util.h"
18 #include "base/memory/linked_ptr.h" 18 #include "base/memory/linked_ptr.h"
19 #include "base/memory/scoped_ptr.h" 19 #include "base/memory/scoped_ptr.h"
20 #include "base/string16.h" 20 #include "base/string16.h"
21 #include "chrome/browser/autocomplete/autocomplete_match.h" 21 #include "chrome/browser/autocomplete/autocomplete_match.h"
22 #include "chrome/browser/autocomplete/history_provider_util.h" 22 #include "chrome/browser/autocomplete/history_provider_util.h"
23 #include "chrome/browser/history/history_types.h" 23 #include "chrome/browser/history/history_types.h"
24 #include "chrome/browser/history/in_memory_url_index_types.h"
25 #include "chrome/browser/history/in_memory_url_index_cache.pb.h" 24 #include "chrome/browser/history/in_memory_url_index_cache.pb.h"
26 #include "content/common/notification_observer.h"
27 #include "content/common/notification_registrar.h"
28 #include "sql/connection.h" 25 #include "sql/connection.h"
29 #include "testing/gtest/include/gtest/gtest_prod.h" 26 #include "testing/gtest/include/gtest/gtest_prod.h"
30 27
31 class Profile; 28 class Profile;
32 29
30 namespace base {
31 class Time;
32 }
33
33 namespace in_memory_url_index { 34 namespace in_memory_url_index {
34 class InMemoryURLIndexCacheItem; 35 class InMemoryURLIndexCacheItem;
35 } 36 }
36 37
37 namespace history { 38 namespace history {
38 39
39 namespace imui = in_memory_url_index; 40 namespace imui = in_memory_url_index;
40 41
41 class URLDatabase; 42 class URLDatabase;
42 struct URLsDeletedDetails; 43
43 struct URLsModifiedDetails; 44 // Specifies where an omnibox term occurs within a string. Used for specifying
44 struct URLVisitedDetails; 45 // highlights in AutocompleteMatches (ACMatchClassifications) and to assist in
46 // scoring a result.
47 struct TermMatch {
48 TermMatch(int term_num, size_t offset, size_t length)
49 : term_num(term_num),
50 offset(offset),
51 length(length) {}
52
53 int term_num; // The index of the term in the original search string.
54 size_t offset; // The starting offset of the substring match.
55 size_t length; // The length of the substring match.
56 };
57 typedef std::vector<TermMatch> TermMatches;
58
59 // Used for intermediate history result operations.
60 struct ScoredHistoryMatch : public HistoryMatch {
61 ScoredHistoryMatch(); // Required by STL.
62 explicit ScoredHistoryMatch(const URLRow& url_info);
63 ~ScoredHistoryMatch();
64
65 static bool MatchScoreGreater(const ScoredHistoryMatch& m1,
66 const ScoredHistoryMatch& m2);
67
68 // An interim score taking into consideration location and completeness
69 // of the match.
70 int raw_score;
71 TermMatches url_matches; // Term matches within the URL.
72 TermMatches title_matches; // Term matches within the page title.
73 bool can_inline; // True if this is a candidate for in-line autocompletion.
74 };
75 typedef std::vector<ScoredHistoryMatch> ScoredHistoryMatches;
45 76
46 // The URL history source. 77 // The URL history source.
47 // Holds portions of the URL database in memory in an indexed form. Used to 78 // Holds portions of the URL database in memory in an indexed form. Used to
48 // quickly look up matching URLs for a given query string. Used by 79 // quickly look up matching URLs for a given query string. Used by
49 // the HistoryURLProvider for inline autocomplete and to provide URL 80 // the HistoryURLProvider for inline autocomplete and to provide URL
50 // matches to the omnibox. 81 // matches to the omnibox.
51 // 82 //
52 // Note about multi-byte codepoints and the data structures in the 83 // Note about multi-byte codepoints and the data structures in the
53 // InMemoryURLIndex class: One will quickly notice that no effort is made to 84 // InMemoryURLIndex class: One will quickly notice that no effort is made to
54 // insure that multi-byte character boundaries are detected when indexing the 85 // insure that multi-byte character boundaries are detected when indexing the
55 // words and characters in the URL history database except when converting 86 // words and characters in the URL history database except when converting
56 // URL strings to lowercase. Multi-byte-edness makes no difference when 87 // URL strings to lowercase. Multi-byte-edness makes no difference when
57 // indexing or when searching the index as the final filtering of results 88 // indexing or when searching the index as the final filtering of results
58 // is dependent on the comparison of a string of bytes, not individual 89 // is dependent on the comparison of a string of bytes, not individual
59 // characters. While the lookup of those bytes during a search in the 90 // characters. While the lookup of those bytes during a search in the
60 // |char_word_map_| could serve up words in which the individual char16 91 // |char_word_map_| could serve up words in which the individual char16
61 // occurs as a portion of a composite character the next filtering step 92 // occurs as a portion of a composite character the next filtering step
62 // will eliminate such words except in the case where a single character 93 // will eliminate such words except in the case where a single character
63 // is being searched on and which character occurs as the second char16 of a 94 // is being searched on and which character occurs as the second char16 of a
64 // multi-char16 instance. 95 // multi-char16 instance.
65 class InMemoryURLIndex : public NotificationObserver { 96 class InMemoryURLIndex {
66 public: 97 public:
67 // |history_dir| is a path to the directory containing the history database 98 // |history_dir| is a path to the directory containing the history database
68 // within the profile wherein the cache and transaction journals will be 99 // within the profile wherein the cache and transaction journals will be
69 // stored. 100 // stored.
70 explicit InMemoryURLIndex(Profile* profile, 101 explicit InMemoryURLIndex(const FilePath& history_dir);
71 const FilePath& history_dir); 102 ~InMemoryURLIndex();
72 virtual ~InMemoryURLIndex(); 103
104 // Convenience types
105 typedef std::vector<string16> String16Vector;
73 106
74 // Opens and indexes the URL history database. 107 // Opens and indexes the URL history database.
75 // |languages| gives a list of language encodings with which the history 108 // |languages| gives a list of language encodings with which the history
76 // URLs and omnibox searches are interpreted, i.e. when each is broken 109 // URLs and omnibox searches are interpreted, i.e. when each is broken
77 // down into words and each word is broken down into characters. 110 // down into words and each word is broken down into characters.
78 bool Init(URLDatabase* history_db, const std::string& languages); 111 bool Init(URLDatabase* history_db, const std::string& languages);
79 112
80 // Reloads the history index. Attempts to reload from the cache unless 113 // Reloads the history index. Attempts to reload from the cache unless
81 // |clear_cache| is true. If the cache is unavailable then reload the 114 // |clear_cache| is true. If the cache is unavailable then reload the
82 // index from |history_db|. 115 // index from |history_db|.
(...skipping 20 matching lines...) Expand all
103 // A search request which results in more than |kItemsToScoreLimit| total 136 // A search request which results in more than |kItemsToScoreLimit| total
104 // candidate items returns no matches (though the results set will be 137 // candidate items returns no matches (though the results set will be
105 // retained and used for subsequent calls to this function) as the scoring 138 // retained and used for subsequent calls to this function) as the scoring
106 // of such a large number of candidates may cause perceptible typing response 139 // of such a large number of candidates may cause perceptible typing response
107 // delays in the omnibox. This is likely to occur for short omnibox terms 140 // delays in the omnibox. This is likely to occur for short omnibox terms
108 // such as 'h' and 'w' which will be found in nearly all history candidates. 141 // such as 'h' and 'w' which will be found in nearly all history candidates.
109 ScoredHistoryMatches HistoryItemsForTerms(const String16Vector& terms); 142 ScoredHistoryMatches HistoryItemsForTerms(const String16Vector& terms);
110 143
111 // Updates or adds an history item to the index if it meets the minimum 144 // Updates or adds an history item to the index if it meets the minimum
112 // 'quick' criteria. 145 // 'quick' criteria.
113 void UpdateURL(const URLRow& row); 146 void UpdateURL(URLID row_id, const URLRow& row);
114 147
115 // Deletes indexing data for an history item. The item may not have actually 148 // Deletes indexing data for an history item. The item may not have actually
116 // been indexed (which is the case if it did not previously meet minimum 149 // been indexed (which is the case if it did not previously meet minimum
117 // 'quick' criteria). 150 // 'quick' criteria).
118 void DeleteURL(const URLRow& row); 151 void DeleteURL(URLID row_id);
119 152
120 // Notification callback. 153 // Breaks the |uni_string| string down into individual words and return
121 virtual void Observe(int type, 154 // a vector with the individual words in their original order. If
122 const NotificationSource& source, 155 // |break_on_space| is false then the resulting list will contain only words
123 const NotificationDetails& details); 156 // containing alpha-numeric characters. If |break_on_space| is true then the
157 // resulting list will contain strings broken at whitespace.
158 //
159 // Example:
160 // Given: |uni_string|: "http://www.google.com/ harry the rabbit."
161 // With |break_on_space| false the returned list will contain:
162 // "http", "www", "google", "com", "harry", "the", "rabbit"
163 // With |break_on_space| true the returned list will contain:
164 // "http://", "www.google.com/", "harry", "the", "rabbit."
165 static String16Vector WordVectorFromString16(const string16& uni_string,
166 bool break_on_space);
167
168 // Extract and return the offsets from |matches|.
169 static std::vector<size_t> OffsetsFromTermMatches(const TermMatches& matches);
170
171 // Replace the offsets in |matches| with those given in |offsets|, deleting
172 // any which are npos, and return the updated list of matches.
173 static TermMatches ReplaceOffsetsInTermMatches(
174 const TermMatches& matches,
175 const std::vector<size_t>& offsets);
124 176
125 private: 177 private:
126 friend class AddHistoryMatch; 178 friend class AddHistoryMatch;
127 friend class InMemoryURLIndexTest; 179 friend class InMemoryURLIndexTest;
128 FRIEND_TEST_ALL_PREFIXES(LimitedInMemoryURLIndexTest, Initialization); 180 FRIEND_TEST_ALL_PREFIXES(LimitedInMemoryURLIndexTest, Initialization);
129 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, CacheFilePath); 181 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, CacheFilePath);
130 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, CacheSaveRestore); 182 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, CacheSaveRestore);
131 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, Char16Utilities); 183 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, Char16Utilities);
132 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, NonUniqueTermCharacterSets); 184 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, NonUniqueTermCharacterSets);
133 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, Scoring); 185 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, Scoring);
134 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, StaticFunctions); 186 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, StaticFunctions);
135 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, TitleSearch); 187 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, TitleSearch);
136 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, TypedCharacterCaching); 188 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, TypedCharacterCaching);
137 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, WhitelistedURLs); 189 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, WhitelistedURLs);
138 190
139 // Signals that there are no previously cached results for the typed term. 191 // Signals that there are no previously cached results for the typed term.
140 static const size_t kNoCachedResultForTerm; 192 static const size_t kNoCachedResultForTerm;
141 193
142 // Creating one of me without a history path is not allowed (tests excepted). 194 // Creating one of me without a history path is not allowed (tests excepted).
143 InMemoryURLIndex(); 195 InMemoryURLIndex();
144 196
197 // Convenience types.
198 typedef std::set<string16> String16Set;
199 typedef std::set<char16> Char16Set;
200 typedef std::vector<char16> Char16Vector;
201
202 // An index into list of all of the words we have indexed.
203 typedef int WordID;
204
205 // A map allowing a WordID to be determined given a word.
206 typedef std::map<string16, WordID> WordMap;
207
208 // A map from character to word_ids.
209 typedef std::set<WordID> WordIDSet; // An index into the WordList.
210 typedef std::map<char16, WordIDSet> CharWordIDMap;
211
212 // A map from word_id to history item.
213 // TODO(mrossetti): URLID is 64 bit: a memory bloat and performance hit.
214 // Consider using a smaller type.
215 typedef URLID HistoryID;
216 typedef std::set<HistoryID> HistoryIDSet;
217 typedef std::map<WordID, HistoryIDSet> WordIDHistoryMap;
218
219
145 // Support caching of term results so that we can optimize searches which 220 // Support caching of term results so that we can optimize searches which
146 // build upon a previous search. Each entry in this map represents one 221 // build upon a previous search. Each entry in this map represents one
147 // search term from the most recent search. For example, if the user had 222 // search term from the most recent search. For example, if the user had
148 // typed "google blog trans" and then typed an additional 'l' (at the end, 223 // typed "google blog trans" and then typed an additional 'l' (at the end,
149 // of course) then there would be four items in the cache: 'blog', 'google', 224 // of course) then there would be four items in the cache: 'blog', 'google',
150 // 'trans', and 'transl'. All would be marked as being in use except for the 225 // 'trans', and 'transl'. All would be marked as being in use except for the
151 // 'trans' item; its cached data would have been used when optimizing the 226 // 'trans' item; its cached data would have been used when optimizing the
152 // construction of the search results candidates for 'transl' but then would 227 // construction of the search results candidates for 'transl' but then would
153 // no longer needed. 228 // no longer needed.
154 // 229 //
(...skipping 11 matching lines...) Expand all
166 SearchTermCacheItem(); 241 SearchTermCacheItem();
167 242
168 ~SearchTermCacheItem(); 243 ~SearchTermCacheItem();
169 244
170 WordIDSet word_id_set_; 245 WordIDSet word_id_set_;
171 HistoryIDSet history_id_set_; 246 HistoryIDSet history_id_set_;
172 bool used_; // True if this item has been used for the current term search. 247 bool used_; // True if this item has been used for the current term search.
173 }; 248 };
174 typedef std::map<string16, SearchTermCacheItem> SearchTermCacheMap; 249 typedef std::map<string16, SearchTermCacheItem> SearchTermCacheMap;
175 250
251 // TODO(rohitrao): Probably replace this with QueryResults.
252 typedef std::vector<URLRow> URLRowVector;
253
254 // A map from history_id to the history's URL and title.
255 typedef std::map<HistoryID, URLRow> HistoryInfoMap;
256
176 // A helper class which performs the final filter on each candidate 257 // A helper class which performs the final filter on each candidate
177 // history URL match, inserting accepted matches into |scored_matches_| 258 // history URL match, inserting accepted matches into |scored_matches_|
178 // and trimming the maximum number of matches to 10. 259 // and trimming the maximum number of matches to 10.
179 class AddHistoryMatch : public std::unary_function<HistoryID, void> { 260 class AddHistoryMatch : public std::unary_function<HistoryID, void> {
180 public: 261 public:
181 AddHistoryMatch(const InMemoryURLIndex& index, 262 AddHistoryMatch(const InMemoryURLIndex& index,
182 const String16Vector& lower_terms); 263 const String16Vector& lower_terms);
183 ~AddHistoryMatch(); 264 ~AddHistoryMatch();
184 265
185 void operator()(const HistoryID history_id); 266 void operator()(const HistoryID history_id);
186 267
187 ScoredHistoryMatches ScoredMatches() const { return scored_matches_; } 268 ScoredHistoryMatches ScoredMatches() const { return scored_matches_; }
188 269
189 private: 270 private:
190 const InMemoryURLIndex& index_; 271 const InMemoryURLIndex& index_;
191 ScoredHistoryMatches scored_matches_; 272 ScoredHistoryMatches scored_matches_;
192 const String16Vector& lower_terms_; 273 const String16Vector& lower_terms_;
193 }; 274 };
194 275
195 // Initializes all index data members in preparation for restoring the index 276 // Initializes all index data members in preparation for restoring the index
196 // from the cache or a complete rebuild from the history database. 277 // from the cache or a complete rebuild from the history database.
197 void ClearPrivateData(); 278 void ClearPrivateData();
198 279
199 // Initializes the whitelist of URL schemes. 280 // Initializes the whitelist of URL schemes.
200 static void InitializeSchemeWhitelist(std::set<std::string>* whitelist); 281 static void InitializeSchemeWhitelist(std::set<std::string>* whitelist);
201 282
283 // Breaks a string down into individual words.
284 static String16Set WordSetFromString16(const string16& uni_string);
285
286 // Given a set of Char16s, finds words containing those characters.
287 WordIDSet WordIDSetForTermChars(const Char16Set& term_chars);
288
289 // Creates a TermMatches which has an entry for each occurrence of the string
290 // |term| found in the string |string|. Mark each match with |term_num| so
291 // that the resulting TermMatches can be merged with other TermMatches for
292 // other terms.
293 static TermMatches MatchTermInString(const string16& term,
294 const string16& string,
295 int term_num);
296
202 // URL History indexing support functions. 297 // URL History indexing support functions.
203 298
204 // Indexes one URL history item. 299 // Indexes one URL history item.
205 bool IndexRow(const URLRow& row); 300 bool IndexRow(const URLRow& row);
206 301
207 // Parses and indexes the words in the URL and page title of |row|. 302 // Breaks the |uni_word| string down into its individual characters.
208 void AddRowWordsToIndex(const URLRow& row); 303 // Note that this is temporarily intended to work on a single word, but
209 304 // _will_ work on a string of words, perhaps with unexpected results.
210 // Removes |row| and all associated words and characters from the index. 305 // TODO(mrossetti): Lots of optimizations possible here for not restarting
211 void RemoveRowFromIndex(const URLRow& row); 306 // a search if the user is just typing along. Also, change this to uniString
212 307 // and properly handle substring matches, scoring and sorting the results
213 // Removes all words and characters associated with |row| from the index. 308 // by score. Also, provide the metrics for where the matches occur so that
214 void RemoveRowWordsFromIndex(const URLRow& row); 309 // the UI can highlight the matched sections.
310 static Char16Set Char16SetFromString16(const string16& uni_word);
215 311
216 // Given a single word in |uni_word|, adds a reference for the containing 312 // Given a single word in |uni_word|, adds a reference for the containing
217 // history item identified by |history_id| to the index. 313 // history item identified by |history_id| to the index.
218 void AddWordToIndex(const string16& uni_word, HistoryID history_id); 314 void AddWordToIndex(const string16& uni_word, HistoryID history_id);
219 315
220 // Updates an existing entry in the word/history index by adding the 316 // Updates an existing entry in the word/history index by adding the
221 // |history_id| to set for |word_id| in the word_id_history_map_. 317 // |history_id| to set for |word_id| in the word_id_history_map_.
222 void UpdateWordHistory(WordID word_id, HistoryID history_id); 318 void UpdateWordHistory(WordID word_id, HistoryID history_id);
223 319
224 // Creates a new entry in the word/history map for |word_id| and add 320 // Creates a new entry in the word/history map for |word_id| and add
(...skipping 24 matching lines...) Expand all
249 static ScoredHistoryMatch ScoredMatchForURL( 345 static ScoredHistoryMatch ScoredMatchForURL(
250 const URLRow& row, 346 const URLRow& row,
251 const String16Vector& terms_vector); 347 const String16Vector& terms_vector);
252 348
253 // Calculates a component score based on position, ordering and total 349 // Calculates a component score based on position, ordering and total
254 // substring match size using metrics recorded in |matches|. |max_length| 350 // substring match size using metrics recorded in |matches|. |max_length|
255 // is the length of the string against which the terms are being searched. 351 // is the length of the string against which the terms are being searched.
256 static int ScoreComponentForMatches(const TermMatches& matches, 352 static int ScoreComponentForMatches(const TermMatches& matches,
257 size_t max_length); 353 size_t max_length);
258 354
355 // Sorts and removes overlapping substring matches from |matches| and
356 // returns the cleaned up matches.
357 static TermMatches SortAndDeoverlap(const TermMatches& matches);
358
259 // Determines if |gurl| has a whitelisted scheme and returns true if so. 359 // Determines if |gurl| has a whitelisted scheme and returns true if so.
260 bool URLSchemeIsWhitelisted(const GURL& gurl) const; 360 bool URLSchemeIsWhitelisted(const GURL& gurl) const;
261 361
262 // Notification handlers.
263 void OnURLVisited(const URLVisitedDetails* details);
264 void OnURLsModified(const URLsModifiedDetails* details);
265 void OnURLsDeleted(const URLsDeletedDetails* details);
266
267 // Utility functions supporting RestoreFromCache and SaveToCache. 362 // Utility functions supporting RestoreFromCache and SaveToCache.
268 363
269 // Construct a file path for the cache file within the same directory where 364 // Construct a file path for the cache file within the same directory where
270 // the history database is kept and saves that path to |file_path|. Returns 365 // the history database is kept and saves that path to |file_path|. Returns
271 // true if |file_path| can be successfully constructed. (This function 366 // true if |file_path| can be successfully constructed. (This function
272 // provided as a hook for unit testing.) 367 // provided as a hook for unit testing.)
273 bool GetCacheFilePath(FilePath* file_path); 368 bool GetCacheFilePath(FilePath* file_path);
274 369
275 // Encode a data structure into the protobuf |cache|. 370 // Encode a data structure into the protobuf |cache|.
276 void SavePrivateData(imui::InMemoryURLIndexCacheItem* cache) const; 371 void SavePrivateData(imui::InMemoryURLIndexCacheItem* cache) const;
277 void SaveWordList(imui::InMemoryURLIndexCacheItem* cache) const; 372 void SaveWordList(imui::InMemoryURLIndexCacheItem* cache) const;
278 void SaveWordMap(imui::InMemoryURLIndexCacheItem* cache) const; 373 void SaveWordMap(imui::InMemoryURLIndexCacheItem* cache) const;
279 void SaveCharWordMap(imui::InMemoryURLIndexCacheItem* cache) const; 374 void SaveCharWordMap(imui::InMemoryURLIndexCacheItem* cache) const;
280 void SaveWordIDHistoryMap(imui::InMemoryURLIndexCacheItem* cache) const; 375 void SaveWordIDHistoryMap(imui::InMemoryURLIndexCacheItem* cache) const;
281 void SaveHistoryInfoMap(imui::InMemoryURLIndexCacheItem* cache) const; 376 void SaveHistoryInfoMap(imui::InMemoryURLIndexCacheItem* cache) const;
282 377
283 // Decode a data structure from the protobuf |cache|. Return false if there 378 // Decode a data structure from the protobuf |cache|. Return false if there
284 // is any kind of failure. 379 // is any kind of failure.
285 bool RestorePrivateData(const imui::InMemoryURLIndexCacheItem& cache); 380 bool RestorePrivateData(const imui::InMemoryURLIndexCacheItem& cache);
286 bool RestoreWordList(const imui::InMemoryURLIndexCacheItem& cache); 381 bool RestoreWordList(const imui::InMemoryURLIndexCacheItem& cache);
287 bool RestoreWordMap(const imui::InMemoryURLIndexCacheItem& cache); 382 bool RestoreWordMap(const imui::InMemoryURLIndexCacheItem& cache);
288 bool RestoreCharWordMap(const imui::InMemoryURLIndexCacheItem& cache); 383 bool RestoreCharWordMap(const imui::InMemoryURLIndexCacheItem& cache);
289 bool RestoreWordIDHistoryMap(const imui::InMemoryURLIndexCacheItem& cache); 384 bool RestoreWordIDHistoryMap(const imui::InMemoryURLIndexCacheItem& cache);
290 bool RestoreHistoryInfoMap(const imui::InMemoryURLIndexCacheItem& cache); 385 bool RestoreHistoryInfoMap(const imui::InMemoryURLIndexCacheItem& cache);
291 386
292 NotificationRegistrar registrar_;
293
294 // Directory where cache file resides. This is, except when unit testing, 387 // Directory where cache file resides. This is, except when unit testing,
295 // the same directory in which the profile's history database is found. It 388 // the same directory in which the profile's history database is found. It
296 // should never be empty. 389 // should never be empty.
297 FilePath history_dir_; 390 FilePath history_dir_;
298 391
299 // The timestamp of when the cache was last saved. This is used to validate 392 // The timestamp of when the cache was last saved. This is used to validate
300 // the transaction journal's applicability to the cache. The timestamp is 393 // the transaction journal's applicability to the cache. The timestamp is
301 // initialized to the NULL time, indicating that the cache was not used with 394 // initialized to the NULL time, indicating that the cache was not used with
302 // the InMemoryURLIndex was last populated. 395 // the InMemoryURLIndex was last populated.
303 base::Time last_saved_; 396 base::Time last_saved_;
304 397
305 // The index's durable private data. 398 // A list of all of indexed words. The index of a word in this list is the
306 scoped_ptr<URLIndexPrivateData> private_data_; 399 // ID of the word in the word_map_. It reduces the memory overhead by
400 // replacing a potentially long and repeated string with a simple index.
401 // NOTE: A word will _never_ be removed from this vector thus insuring
402 // the immutability of the word_id throughout the session, reducing
403 // maintenance complexity.
404 // TODO(mrossetti): Profile the vector allocation and determine if judicious
405 // 'reserve' calls are called for.
406 String16Vector word_list_;
407
408 int history_item_count_;
409 WordMap word_map_;
410 CharWordIDMap char_word_map_;
411 WordIDHistoryMap word_id_history_map_;
412 HistoryInfoMap history_info_map_;
307 413
308 // Cache of search terms. 414 // Cache of search terms.
309 SearchTermCacheMap search_term_cache_; 415 SearchTermCacheMap search_term_cache_;
310 416
311 // Languages used during the word-breaking process during indexing. 417 // Languages used during the word-breaking process during indexing.
312 std::string languages_; 418 std::string languages_;
313 419
314 // Only URLs with a whitelisted scheme are indexed. 420 // Only URLs with a whitelisted scheme are indexed.
315 std::set<std::string> scheme_whitelist_; 421 std::set<std::string> scheme_whitelist_;
316 422
317 DISALLOW_COPY_AND_ASSIGN(InMemoryURLIndex); 423 DISALLOW_COPY_AND_ASSIGN(InMemoryURLIndex);
318 }; 424 };
319 425
320 } // namespace history 426 } // namespace history
321 427
322 #endif // CHROME_BROWSER_HISTORY_IN_MEMORY_URL_INDEX_H_ 428 #endif // CHROME_BROWSER_HISTORY_IN_MEMORY_URL_INDEX_H_
OLDNEW
« no previous file with comments | « chrome/browser/history/in_memory_history_backend.cc ('k') | chrome/browser/history/in_memory_url_index.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698