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

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: Pass bool value, not pointer. Sync to clear up Linux fails (hopefully). 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(URLIndexPrivateData* private_data,
155 const FilePath& file_path,
156 bool* succeeded);
157
143 // Caches the index private data and writes the cache file to the profile 158 // Caches the index private data and writes the cache file to the profile
144 // directory. 159 // directory. Called by WritePrivateDataToCacheFileTask.
145 bool SaveToFile(const FilePath& file_path); 160 bool SaveToFile(const FilePath& file_path);
146 161
147 // Initializes all index data members in preparation for restoring the index 162 // Initializes all index data members in preparation for restoring the index
148 // from the cache or a complete rebuild from the history database. 163 // from the cache or a complete rebuild from the history database.
149 void Clear(); 164 void Clear();
150 165
166 // Returns true if there is no data in the index.
167 bool Empty() const;
168
151 // Adds |word_id| to |history_id|'s entry in the history/word map, 169 // Adds |word_id| to |history_id|'s entry in the history/word map,
152 // creating a new entry if one does not already exist. 170 // creating a new entry if one does not already exist.
153 void AddToHistoryIDWordMap(HistoryID history_id, WordID word_id); 171 void AddToHistoryIDWordMap(HistoryID history_id, WordID word_id);
154 172
155 // Given a set of Char16s, finds words containing those characters. 173 // Given a set of Char16s, finds words containing those characters.
156 WordIDSet WordIDSetForTermChars(const Char16Set& term_chars); 174 WordIDSet WordIDSetForTermChars(const Char16Set& term_chars);
157 175
158 // Initializes the whitelist of URL schemes. 176 // Initializes the whitelist of URL schemes.
159 static void InitializeSchemeWhitelist(std::set<std::string>* whitelist); 177 static void InitializeSchemeWhitelist(std::set<std::string>* whitelist);
160 178
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 const URLRow& row, 241 const URLRow& row,
224 const string16& lower_string, 242 const string16& lower_string,
225 const String16Vector& terms_vector); 243 const String16Vector& terms_vector);
226 244
227 // Calculates a component score based on position, ordering and total 245 // Calculates a component score based on position, ordering and total
228 // substring match size using metrics recorded in |matches|. |max_length| 246 // substring match size using metrics recorded in |matches|. |max_length|
229 // is the length of the string against which the terms are being searched. 247 // is the length of the string against which the terms are being searched.
230 static int ScoreComponentForMatches(const TermMatches& matches, 248 static int ScoreComponentForMatches(const TermMatches& matches,
231 size_t max_length); 249 size_t max_length);
232 250
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|. 251 // Encode a data structure into the protobuf |cache|.
237 void SavePrivateData(imui::InMemoryURLIndexCacheItem* cache) const; 252 void SavePrivateData(imui::InMemoryURLIndexCacheItem* cache) const;
238 void SaveWordList(imui::InMemoryURLIndexCacheItem* cache) const; 253 void SaveWordList(imui::InMemoryURLIndexCacheItem* cache) const;
239 void SaveWordMap(imui::InMemoryURLIndexCacheItem* cache) const; 254 void SaveWordMap(imui::InMemoryURLIndexCacheItem* cache) const;
240 void SaveCharWordMap(imui::InMemoryURLIndexCacheItem* cache) const; 255 void SaveCharWordMap(imui::InMemoryURLIndexCacheItem* cache) const;
241 void SaveWordIDHistoryMap(imui::InMemoryURLIndexCacheItem* cache) const; 256 void SaveWordIDHistoryMap(imui::InMemoryURLIndexCacheItem* cache) const;
242 void SaveHistoryInfoMap(imui::InMemoryURLIndexCacheItem* cache) const; 257 void SaveHistoryInfoMap(imui::InMemoryURLIndexCacheItem* cache) const;
243 258
244 // Decode a data structure from the protobuf |cache|. Return false if there 259 // Decode a data structure from the protobuf |cache|. Return false if there
245 // is any kind of failure. 260 // is any kind of failure.
246 bool RestorePrivateData(const imui::InMemoryURLIndexCacheItem& cache); 261 bool RestorePrivateData(const imui::InMemoryURLIndexCacheItem& cache);
247 bool RestoreWordList(const imui::InMemoryURLIndexCacheItem& cache); 262 bool RestoreWordList(const imui::InMemoryURLIndexCacheItem& cache);
248 bool RestoreWordMap(const imui::InMemoryURLIndexCacheItem& cache); 263 bool RestoreWordMap(const imui::InMemoryURLIndexCacheItem& cache);
249 bool RestoreCharWordMap(const imui::InMemoryURLIndexCacheItem& cache); 264 bool RestoreCharWordMap(const imui::InMemoryURLIndexCacheItem& cache);
250 bool RestoreWordIDHistoryMap(const imui::InMemoryURLIndexCacheItem& cache); 265 bool RestoreWordIDHistoryMap(const imui::InMemoryURLIndexCacheItem& cache);
251 bool RestoreHistoryInfoMap(const imui::InMemoryURLIndexCacheItem& cache); 266 bool RestoreHistoryInfoMap(const imui::InMemoryURLIndexCacheItem& cache);
252 267
268 // Determines if |gurl| has a whitelisted scheme and returns true if so.
269 bool URLSchemeIsWhitelisted(const GURL& gurl) const;
270
253 // Cache of search terms. 271 // Cache of search terms.
254 SearchTermCacheMap search_term_cache_; 272 SearchTermCacheMap search_term_cache_;
255 273
256 // Languages used during the word-breaking process during indexing. 274 // Languages used during the word-breaking process during indexing.
257 std::string languages_; 275 std::string languages_;
258 276
259 // Only URLs with a whitelisted scheme are indexed. 277 // Only URLs with a whitelisted scheme are indexed.
260 std::set<std::string> scheme_whitelist_; 278 std::set<std::string> scheme_whitelist_;
261 279
262 // Start of data members that are cached ------------------------------------- 280 // 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 320 // Used for unit testing only. Records the number of candidate history items
303 // at three stages in the index searching process. 321 // at three stages in the index searching process.
304 size_t pre_filter_item_count_; // After word index is queried. 322 size_t pre_filter_item_count_; // After word index is queried.
305 size_t post_filter_item_count_; // After trimming large result set. 323 size_t post_filter_item_count_; // After trimming large result set.
306 size_t post_scoring_item_count_; // After performing final filter/scoring. 324 size_t post_scoring_item_count_; // After performing final filter/scoring.
307 }; 325 };
308 326
309 } // namespace history 327 } // namespace history
310 328
311 #endif // CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_ 329 #endif // CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698