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

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

Issue 9030031: Move InMemoryURLIndex Caching Operations to FILE Thread (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Use proper refcounted structures for passing around status. Created 8 years, 9 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) 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 "base/memory/scoped_ptr.h"
11 #include "chrome/browser/history/in_memory_url_index_types.h" 12 #include "chrome/browser/history/in_memory_url_index_types.h"
12 #include "chrome/browser/history/in_memory_url_index_cache.pb.h" 13 #include "chrome/browser/history/in_memory_url_index_cache.pb.h"
14 #include "content/public/browser/notification_details.h"
13 15
14 class HistoryQuickProviderTest; 16 class HistoryQuickProviderTest;
15 17
16 namespace in_memory_url_index { 18 namespace in_memory_url_index {
17 class InMemoryURLIndexCacheItem; 19 class InMemoryURLIndexCacheItem;
18 } 20 }
19 21
20 namespace history { 22 namespace history {
21 23
22 namespace imui = in_memory_url_index; 24 namespace imui = in_memory_url_index;
23 25
24 class HistoryDatabase; 26 class HistoryDatabase;
27 class InMemoryURLIndex;
25 28
26 // A structure describing the InMemoryURLIndex's internal data and providing for 29 // A structure describing the InMemoryURLIndex's internal data and providing for
27 // restoring, rebuilding and updating that internal data. 30 // restoring, rebuilding and updating that internal data.
28 class URLIndexPrivateData { 31 class URLIndexPrivateData {
29 public: 32 public:
30 URLIndexPrivateData(); 33 URLIndexPrivateData();
31 ~URLIndexPrivateData(); 34 ~URLIndexPrivateData();
32 35
33 private: 36 private:
34 friend class AddHistoryMatch; 37 friend class AddHistoryMatch;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 // descending score. The full results set (i.e. beyond the 127 // descending score. The full results set (i.e. beyond the
125 // |kItemsToScoreLimit| limit) will be retained and used for subsequent calls 128 // |kItemsToScoreLimit| limit) will be retained and used for subsequent calls
126 // to this function. 129 // to this function.
127 ScoredHistoryMatches HistoryItemsForTerms(const string16& term_string); 130 ScoredHistoryMatches HistoryItemsForTerms(const string16& term_string);
128 131
129 // Sets the |languages| to a list of language encodings with which the history 132 // Sets the |languages| to a list of language encodings with which the history
130 // URLs and omnibox searches are interpreted, i.e. how each is broken 133 // URLs and omnibox searches are interpreted, i.e. how each is broken
131 // down into words and each word is broken down into characters. 134 // down into words and each word is broken down into characters.
132 void set_languages(const std::string& languages) { languages_ = languages; } 135 void set_languages(const std::string& languages) { languages_ = languages; }
133 136
134 // Restores the index's private data from the cache file stored in the 137 // Creates a new URLIndexPrivateData object, populates it from the contents
135 // profile directory and returns true if successful. 138 // of the cache file stored in |file_path|, and assigns it to |data|.
136 bool RestoreFromFile(const FilePath& file_path); 139 static void RestoreFromFileTask(const FilePath& file_path,
140 URLIndexPrivateData* data);
141
142 // Constructs a new object by restoring its contents from the file at |path|.
143 // Returns the new URLIndexPrivateData which on success will contain the
144 // restored data but upon failure will be empty.
145 static URLIndexPrivateData* RestoreFromFile(const FilePath& path);
137 146
138 // Constructs a new object by rebuilding its contents from the history 147 // Constructs a new object by rebuilding its contents from the history
139 // database in |history_db|. Returns the new URLIndexPrivateData which on 148 // database in |history_db|. Returns the new URLIndexPrivateData which on
140 // success will contain the rebuilt data but upon failure will be empty. 149 // success will contain the rebuilt data but upon failure will be empty.
141 static URLIndexPrivateData* RebuildFromHistory(HistoryDatabase* history_db); 150 static URLIndexPrivateData* RebuildFromHistory(HistoryDatabase* history_db);
142 151
152 // Writes |private_data| as a cache file to |file_path| and returns success
153 // via |succeeded|.
154 static void WritePrivateDataToCacheFileTask(
155 scoped_ptr<URLIndexPrivateData> private_data,
156 const FilePath& file_path,
157 scoped_refptr<history::RefCountedBool> succeeded);
158
143 // Caches the index private data and writes the cache file to the profile 159 // Caches the index private data and writes the cache file to the profile
144 // directory. 160 // directory. Called by WritePrivateDataToCacheFileTask.
145 bool SaveToFile(const FilePath& file_path); 161 bool SaveToFile(const FilePath& file_path);
146 162
147 // Initializes all index data members in preparation for restoring the index 163 // Initializes all index data members in preparation for restoring the index
148 // from the cache or a complete rebuild from the history database. 164 // from the cache or a complete rebuild from the history database.
149 void Clear(); 165 void Clear();
150 166
167 // Returns true if there is no data in the index.
168 bool Empty() const;
169
151 // Adds |word_id| to |history_id|'s entry in the history/word map, 170 // Adds |word_id| to |history_id|'s entry in the history/word map,
152 // creating a new entry if one does not already exist. 171 // creating a new entry if one does not already exist.
153 void AddToHistoryIDWordMap(HistoryID history_id, WordID word_id); 172 void AddToHistoryIDWordMap(HistoryID history_id, WordID word_id);
154 173
155 // Given a set of Char16s, finds words containing those characters. 174 // Given a set of Char16s, finds words containing those characters.
156 WordIDSet WordIDSetForTermChars(const Char16Set& term_chars); 175 WordIDSet WordIDSetForTermChars(const Char16Set& term_chars);
157 176
158 // Initializes the whitelist of URL schemes. 177 // Initializes the whitelist of URL schemes.
159 static void InitializeSchemeWhitelist(std::set<std::string>* whitelist); 178 static void InitializeSchemeWhitelist(std::set<std::string>* whitelist);
160 179
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 const URLRow& row, 242 const URLRow& row,
224 const string16& lower_string, 243 const string16& lower_string,
225 const String16Vector& terms_vector); 244 const String16Vector& terms_vector);
226 245
227 // Calculates a component score based on position, ordering and total 246 // Calculates a component score based on position, ordering and total
228 // substring match size using metrics recorded in |matches|. |max_length| 247 // substring match size using metrics recorded in |matches|. |max_length|
229 // is the length of the string against which the terms are being searched. 248 // is the length of the string against which the terms are being searched.
230 static int ScoreComponentForMatches(const TermMatches& matches, 249 static int ScoreComponentForMatches(const TermMatches& matches,
231 size_t max_length); 250 size_t max_length);
232 251
233 // Determines if |gurl| has a whitelisted scheme and returns true if so.
234 bool URLSchemeIsWhitelisted(const GURL& gurl) const;
235
236 // Encode a data structure into the protobuf |cache|. 252 // Encode a data structure into the protobuf |cache|.
237 void SavePrivateData(imui::InMemoryURLIndexCacheItem* cache) const; 253 void SavePrivateData(imui::InMemoryURLIndexCacheItem* cache) const;
238 void SaveWordList(imui::InMemoryURLIndexCacheItem* cache) const; 254 void SaveWordList(imui::InMemoryURLIndexCacheItem* cache) const;
239 void SaveWordMap(imui::InMemoryURLIndexCacheItem* cache) const; 255 void SaveWordMap(imui::InMemoryURLIndexCacheItem* cache) const;
240 void SaveCharWordMap(imui::InMemoryURLIndexCacheItem* cache) const; 256 void SaveCharWordMap(imui::InMemoryURLIndexCacheItem* cache) const;
241 void SaveWordIDHistoryMap(imui::InMemoryURLIndexCacheItem* cache) const; 257 void SaveWordIDHistoryMap(imui::InMemoryURLIndexCacheItem* cache) const;
242 void SaveHistoryInfoMap(imui::InMemoryURLIndexCacheItem* cache) const; 258 void SaveHistoryInfoMap(imui::InMemoryURLIndexCacheItem* cache) const;
243 259
244 // Decode a data structure from the protobuf |cache|. Return false if there 260 // Decode a data structure from the protobuf |cache|. Return false if there
245 // is any kind of failure. 261 // is any kind of failure.
246 bool RestorePrivateData(const imui::InMemoryURLIndexCacheItem& cache); 262 bool RestorePrivateData(const imui::InMemoryURLIndexCacheItem& cache);
247 bool RestoreWordList(const imui::InMemoryURLIndexCacheItem& cache); 263 bool RestoreWordList(const imui::InMemoryURLIndexCacheItem& cache);
248 bool RestoreWordMap(const imui::InMemoryURLIndexCacheItem& cache); 264 bool RestoreWordMap(const imui::InMemoryURLIndexCacheItem& cache);
249 bool RestoreCharWordMap(const imui::InMemoryURLIndexCacheItem& cache); 265 bool RestoreCharWordMap(const imui::InMemoryURLIndexCacheItem& cache);
250 bool RestoreWordIDHistoryMap(const imui::InMemoryURLIndexCacheItem& cache); 266 bool RestoreWordIDHistoryMap(const imui::InMemoryURLIndexCacheItem& cache);
251 bool RestoreHistoryInfoMap(const imui::InMemoryURLIndexCacheItem& cache); 267 bool RestoreHistoryInfoMap(const imui::InMemoryURLIndexCacheItem& cache);
252 268
269 // Determines if |gurl| has a whitelisted scheme and returns true if so.
270 bool URLSchemeIsWhitelisted(const GURL& gurl) const;
271
253 // Cache of search terms. 272 // Cache of search terms.
254 SearchTermCacheMap search_term_cache_; 273 SearchTermCacheMap search_term_cache_;
255 274
256 // Languages used during the word-breaking process during indexing. 275 // Languages used during the word-breaking process during indexing.
257 std::string languages_; 276 std::string languages_;
258 277
259 // Only URLs with a whitelisted scheme are indexed. 278 // Only URLs with a whitelisted scheme are indexed.
260 std::set<std::string> scheme_whitelist_; 279 std::set<std::string> scheme_whitelist_;
261 280
262 // Start of data members that are cached ------------------------------------- 281 // Start of data members that are cached -------------------------------------
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 // Used for unit testing only. Records the number of candidate history items 321 // Used for unit testing only. Records the number of candidate history items
303 // at three stages in the index searching process. 322 // at three stages in the index searching process.
304 size_t pre_filter_item_count_; // After word index is queried. 323 size_t pre_filter_item_count_; // After word index is queried.
305 size_t post_filter_item_count_; // After trimming large result set. 324 size_t post_filter_item_count_; // After trimming large result set.
306 size_t post_scoring_item_count_; // After performing final filter/scoring. 325 size_t post_scoring_item_count_; // After performing final filter/scoring.
307 }; 326 };
308 327
309 } // namespace history 328 } // namespace history
310 329
311 #endif // CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_ 330 #endif // CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698