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

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: 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/ref_counted.h"
12 #include "base/memory/scoped_ptr.h"
11 #include "chrome/browser/history/in_memory_url_index_types.h" 13 #include "chrome/browser/history/in_memory_url_index_types.h"
12 #include "chrome/browser/history/in_memory_url_index_cache.pb.h" 14 #include "chrome/browser/history/in_memory_url_index_cache.pb.h"
15 #include "content/public/browser/notification_details.h"
13 16
14 class HistoryQuickProviderTest; 17 class HistoryQuickProviderTest;
15 18
16 namespace in_memory_url_index { 19 namespace in_memory_url_index {
17 class InMemoryURLIndexCacheItem; 20 class InMemoryURLIndexCacheItem;
18 } 21 }
19 22
20 namespace history { 23 namespace history {
21 24
22 namespace imui = in_memory_url_index; 25 namespace imui = in_memory_url_index;
23 26
24 class HistoryDatabase; 27 class HistoryDatabase;
28 class InMemoryURLIndex;
29 class URLIndexPrivateData;
30
31 // A helper class to carry around a pointer to private data that is being
32 // restored from the cache or rebuilt from the history database.
33 class RefCountedURLIndexPrivateDataPtr
34 : public base::RefCountedThreadSafe<RefCountedURLIndexPrivateDataPtr> {
35 public:
36 RefCountedURLIndexPrivateDataPtr();
37
38 URLIndexPrivateData* get();
39 URLIndexPrivateData* release();
brettw 2012/03/12 04:37:40 Delete release and reset.
mrossetti 2012/03/13 22:25:46 This whole class is gone now.
40 void reset(URLIndexPrivateData* data);
41
42 private:
43 friend class base::RefCountedThreadSafe<RefCountedURLIndexPrivateDataPtr>;
44 virtual ~RefCountedURLIndexPrivateDataPtr();
45
46 scoped_ptr<URLIndexPrivateData> data_;
brettw 2012/03/12 04:37:40 I don't think you should wrap a scoped_ptr with a
mrossetti 2012/03/12 23:21:13 Because I wanted the original class to be copy-abl
mrossetti 2012/03/13 22:25:46 Done.
47 };
25 48
26 // A structure describing the InMemoryURLIndex's internal data and providing for 49 // A structure describing the InMemoryURLIndex's internal data and providing for
27 // restoring, rebuilding and updating that internal data. 50 // restoring, rebuilding and updating that internal data.
28 class URLIndexPrivateData { 51 class URLIndexPrivateData {
29 public: 52 public:
30 URLIndexPrivateData(); 53 URLIndexPrivateData();
31 ~URLIndexPrivateData(); 54 ~URLIndexPrivateData();
32 55
33 private: 56 private:
34 friend class AddHistoryMatch; 57 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 147 // descending score. The full results set (i.e. beyond the
125 // |kItemsToScoreLimit| limit) will be retained and used for subsequent calls 148 // |kItemsToScoreLimit| limit) will be retained and used for subsequent calls
126 // to this function. 149 // to this function.
127 ScoredHistoryMatches HistoryItemsForTerms(const string16& term_string); 150 ScoredHistoryMatches HistoryItemsForTerms(const string16& term_string);
128 151
129 // Sets the |languages| to a list of language encodings with which the history 152 // 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 153 // URLs and omnibox searches are interpreted, i.e. how each is broken
131 // down into words and each word is broken down into characters. 154 // down into words and each word is broken down into characters.
132 void set_languages(const std::string& languages) { languages_ = languages; } 155 void set_languages(const std::string& languages) { languages_ = languages; }
133 156
134 // Restores the index's private data from the cache file stored in the 157 // Creates a new URLIndexPrivateData object, populates it from the contents
135 // profile directory and returns true if successful. 158 // of the cache file stored in |file_path|, and assigns it to
136 bool RestoreFromFile(const FilePath& file_path); 159 // |private_data_ptr|.
160 static void RestoreFromFileTask(
161 const FilePath& file_path,
162 scoped_refptr<RefCountedURLIndexPrivateDataPtr> private_data_ptr);
163
164 // Constructs a new object by restoring its contents from the file at |path|.
165 // Returns the new URLIndexPrivateData which on success will contain the
166 // restored data but upon failure will be empty.
167 static URLIndexPrivateData* RestoreFromFile(const FilePath& path);
137 168
138 // Constructs a new object by rebuilding its contents from the history 169 // Constructs a new object by rebuilding its contents from the history
139 // database in |history_db|. Returns the new URLIndexPrivateData which on 170 // database in |history_db|. Returns the new URLIndexPrivateData which on
140 // success will contain the rebuilt data but upon failure will be empty. 171 // success will contain the rebuilt data but upon failure will be empty.
141 static URLIndexPrivateData* RebuildFromHistory(HistoryDatabase* history_db); 172 static URLIndexPrivateData* RebuildFromHistory(HistoryDatabase* history_db);
142 173
174 // Writes |private_data| as a cache file to |file_path| and returns success
175 // via |succeeded|.
176 static void WritePrivateDataToCacheFileTask(
177 scoped_ptr<URLIndexPrivateData> private_data,
178 const FilePath& file_path,
179 scoped_refptr<history::RefCountedBool> succeeded);
180
143 // Caches the index private data and writes the cache file to the profile 181 // Caches the index private data and writes the cache file to the profile
144 // directory. 182 // directory. Called by WritePrivateDataToCacheFileTask.
145 bool SaveToFile(const FilePath& file_path); 183 bool SaveToFile(const FilePath& file_path);
146 184
147 // Initializes all index data members in preparation for restoring the index 185 // Initializes all index data members in preparation for restoring the index
148 // from the cache or a complete rebuild from the history database. 186 // from the cache or a complete rebuild from the history database.
149 void Clear(); 187 void Clear();
150 188
189 // Returns true if there is no data in the index.
190 bool Empty() const;
191
151 // Adds |word_id| to |history_id|'s entry in the history/word map, 192 // Adds |word_id| to |history_id|'s entry in the history/word map,
152 // creating a new entry if one does not already exist. 193 // creating a new entry if one does not already exist.
153 void AddToHistoryIDWordMap(HistoryID history_id, WordID word_id); 194 void AddToHistoryIDWordMap(HistoryID history_id, WordID word_id);
154 195
155 // Given a set of Char16s, finds words containing those characters. 196 // Given a set of Char16s, finds words containing those characters.
156 WordIDSet WordIDSetForTermChars(const Char16Set& term_chars); 197 WordIDSet WordIDSetForTermChars(const Char16Set& term_chars);
157 198
158 // Initializes the whitelist of URL schemes. 199 // Initializes the whitelist of URL schemes.
159 static void InitializeSchemeWhitelist(std::set<std::string>* whitelist); 200 static void InitializeSchemeWhitelist(std::set<std::string>* whitelist);
160 201
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 const URLRow& row, 264 const URLRow& row,
224 const string16& lower_string, 265 const string16& lower_string,
225 const String16Vector& terms_vector); 266 const String16Vector& terms_vector);
226 267
227 // Calculates a component score based on position, ordering and total 268 // Calculates a component score based on position, ordering and total
228 // substring match size using metrics recorded in |matches|. |max_length| 269 // substring match size using metrics recorded in |matches|. |max_length|
229 // is the length of the string against which the terms are being searched. 270 // is the length of the string against which the terms are being searched.
230 static int ScoreComponentForMatches(const TermMatches& matches, 271 static int ScoreComponentForMatches(const TermMatches& matches,
231 size_t max_length); 272 size_t max_length);
232 273
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|. 274 // Encode a data structure into the protobuf |cache|.
237 void SavePrivateData(imui::InMemoryURLIndexCacheItem* cache) const; 275 void SavePrivateData(imui::InMemoryURLIndexCacheItem* cache) const;
238 void SaveWordList(imui::InMemoryURLIndexCacheItem* cache) const; 276 void SaveWordList(imui::InMemoryURLIndexCacheItem* cache) const;
239 void SaveWordMap(imui::InMemoryURLIndexCacheItem* cache) const; 277 void SaveWordMap(imui::InMemoryURLIndexCacheItem* cache) const;
240 void SaveCharWordMap(imui::InMemoryURLIndexCacheItem* cache) const; 278 void SaveCharWordMap(imui::InMemoryURLIndexCacheItem* cache) const;
241 void SaveWordIDHistoryMap(imui::InMemoryURLIndexCacheItem* cache) const; 279 void SaveWordIDHistoryMap(imui::InMemoryURLIndexCacheItem* cache) const;
242 void SaveHistoryInfoMap(imui::InMemoryURLIndexCacheItem* cache) const; 280 void SaveHistoryInfoMap(imui::InMemoryURLIndexCacheItem* cache) const;
243 281
244 // Decode a data structure from the protobuf |cache|. Return false if there 282 // Decode a data structure from the protobuf |cache|. Return false if there
245 // is any kind of failure. 283 // is any kind of failure.
246 bool RestorePrivateData(const imui::InMemoryURLIndexCacheItem& cache); 284 bool RestorePrivateData(const imui::InMemoryURLIndexCacheItem& cache);
247 bool RestoreWordList(const imui::InMemoryURLIndexCacheItem& cache); 285 bool RestoreWordList(const imui::InMemoryURLIndexCacheItem& cache);
248 bool RestoreWordMap(const imui::InMemoryURLIndexCacheItem& cache); 286 bool RestoreWordMap(const imui::InMemoryURLIndexCacheItem& cache);
249 bool RestoreCharWordMap(const imui::InMemoryURLIndexCacheItem& cache); 287 bool RestoreCharWordMap(const imui::InMemoryURLIndexCacheItem& cache);
250 bool RestoreWordIDHistoryMap(const imui::InMemoryURLIndexCacheItem& cache); 288 bool RestoreWordIDHistoryMap(const imui::InMemoryURLIndexCacheItem& cache);
251 bool RestoreHistoryInfoMap(const imui::InMemoryURLIndexCacheItem& cache); 289 bool RestoreHistoryInfoMap(const imui::InMemoryURLIndexCacheItem& cache);
252 290
291 // Determines if |gurl| has a whitelisted scheme and returns true if so.
292 bool URLSchemeIsWhitelisted(const GURL& gurl) const;
293
253 // Cache of search terms. 294 // Cache of search terms.
254 SearchTermCacheMap search_term_cache_; 295 SearchTermCacheMap search_term_cache_;
255 296
256 // Languages used during the word-breaking process during indexing. 297 // Languages used during the word-breaking process during indexing.
257 std::string languages_; 298 std::string languages_;
258 299
259 // Only URLs with a whitelisted scheme are indexed. 300 // Only URLs with a whitelisted scheme are indexed.
260 std::set<std::string> scheme_whitelist_; 301 std::set<std::string> scheme_whitelist_;
261 302
262 // Start of data members that are cached ------------------------------------- 303 // 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 343 // Used for unit testing only. Records the number of candidate history items
303 // at three stages in the index searching process. 344 // at three stages in the index searching process.
304 size_t pre_filter_item_count_; // After word index is queried. 345 size_t pre_filter_item_count_; // After word index is queried.
305 size_t post_filter_item_count_; // After trimming large result set. 346 size_t post_filter_item_count_; // After trimming large result set.
306 size_t post_scoring_item_count_; // After performing final filter/scoring. 347 size_t post_scoring_item_count_; // After performing final filter/scoring.
307 }; 348 };
308 349
309 } // namespace history 350 } // namespace history
310 351
311 #endif // CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_ 352 #endif // CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698