| 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 | 7 |
| 8 #include <set> | 8 #include <set> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "base/file_path.h" | 11 #include "base/file_path.h" |
| 12 #include "base/gtest_prod_util.h" | 12 #include "base/gtest_prod_util.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "chrome/browser/history/in_memory_url_index_types.h" | 14 #include "chrome/browser/history/in_memory_url_index_types.h" |
| 15 #include "chrome/browser/history/in_memory_url_index_cache.pb.h" | 15 #include "chrome/browser/history/in_memory_url_index_cache.pb.h" |
| 16 #include "chrome/browser/history/scored_history_match.h" | 16 #include "chrome/browser/history/scored_history_match.h" |
| 17 #include "content/public/browser/notification_details.h" | 17 #include "content/public/browser/notification_details.h" |
| 18 | 18 |
| 19 class HistoryQuickProviderTest; | 19 class HistoryQuickProviderTest; |
| 20 class Profile; |
| 20 | 21 |
| 21 namespace in_memory_url_index { | 22 namespace in_memory_url_index { |
| 22 class InMemoryURLIndexCacheItem; | 23 class InMemoryURLIndexCacheItem; |
| 23 } | 24 } |
| 24 | 25 |
| 25 namespace history { | 26 namespace history { |
| 26 | 27 |
| 27 namespace imui = in_memory_url_index; | 28 namespace imui = in_memory_url_index; |
| 28 | 29 |
| 29 class HistoryDatabase; | 30 class HistoryDatabase; |
| 30 class InMemoryURLIndex; | 31 class InMemoryURLIndex; |
| 31 class RefCountedBool; | 32 class RefCountedBool; |
| 32 | 33 |
| 33 // Current version of the cache file. | 34 // Current version of the cache file. |
| 34 static const int kCurrentCacheFileVersion = 1; | 35 static const int kCurrentCacheFileVersion = 1; |
| 35 | 36 |
| 36 // A structure private to InMemoryURLIndex describing its internal data and | 37 // A structure private to InMemoryURLIndex describing its internal data and |
| 37 // providing for restoring, rebuilding and updating that internal data. As | 38 // providing for restoring, rebuilding and updating that internal data. As |
| 38 // this class is for exclusive use by the InMemoryURLIndex class there should | 39 // this class is for exclusive use by the InMemoryURLIndex class there should |
| 39 // be no calls from any other class. | 40 // be no calls from any other class. |
| 40 // | 41 // |
| 41 // All public member functions are called on the main thread unless otherwise | 42 // All public member functions are called on the main thread unless otherwise |
| 42 // annotated. | 43 // annotated. |
| 43 class URLIndexPrivateData | 44 class URLIndexPrivateData |
| 44 : public base::RefCountedThreadSafe<URLIndexPrivateData> { | 45 : public base::RefCountedThreadSafe<URLIndexPrivateData> { |
| 45 public: | 46 public: |
| 46 URLIndexPrivateData(); | 47 explicit URLIndexPrivateData(Profile* profile); |
| 47 | 48 |
| 48 // Given a string16 in |term_string|, scans the history index and returns a | 49 // Given a string16 in |term_string|, scans the history index and returns a |
| 49 // vector with all scored, matching history items. The |term_string| is | 50 // vector with all scored, matching history items. The |term_string| is |
| 50 // broken down into individual terms (words), each of which must occur in the | 51 // broken down into individual terms (words), each of which must occur in the |
| 51 // candidate history item's URL or page title for the item to qualify; | 52 // candidate history item's URL or page title for the item to qualify; |
| 52 // however, the terms do not necessarily have to be adjacent. Once we have | 53 // however, the terms do not necessarily have to be adjacent. Once we have |
| 53 // a set of candidates, they are filtered to insure that all |term_string| | 54 // a set of candidates, they are filtered to insure that all |term_string| |
| 54 // terms, as separated by whitespace, occur within the candidate's URL | 55 // terms, as separated by whitespace, occur within the candidate's URL |
| 55 // or page title. Scores are then calculated on no more than | 56 // or page title. Scores are then calculated on no more than |
| 56 // |kItemsToScoreLimit| candidates, as the scoring of such a large number of | 57 // |kItemsToScoreLimit| candidates, as the scoring of such a large number of |
| (...skipping 19 matching lines...) Expand all Loading... |
| 76 // Deletes index data for the history item with the given |url|. | 77 // Deletes index data for the history item with the given |url|. |
| 77 // The item may not have actually been indexed, which is the case if it did | 78 // The item may not have actually been indexed, which is the case if it did |
| 78 // not previously meet minimum 'quick' criteria. Returns true if the index | 79 // not previously meet minimum 'quick' criteria. Returns true if the index |
| 79 // was actually updated. | 80 // was actually updated. |
| 80 bool DeleteURL(const GURL& url); | 81 bool DeleteURL(const GURL& url); |
| 81 | 82 |
| 82 // Creates a new URLIndexPrivateData object, populates it from the contents | 83 // Creates a new URLIndexPrivateData object, populates it from the contents |
| 83 // of the cache file stored in |file_path|, and assigns it to |private_data|. | 84 // of the cache file stored in |file_path|, and assigns it to |private_data|. |
| 84 // |languages| will be used to break URLs and page titles into words. | 85 // |languages| will be used to break URLs and page titles into words. |
| 85 static void RestoreFromFileTask( | 86 static void RestoreFromFileTask( |
| 87 Profile* profile, |
| 86 const FilePath& file_path, | 88 const FilePath& file_path, |
| 87 scoped_refptr<URLIndexPrivateData> private_data, | 89 scoped_refptr<URLIndexPrivateData> private_data, |
| 88 const std::string& languages); | 90 const std::string& languages); |
| 89 | 91 |
| 90 // Constructs a new object by rebuilding its contents from the history | 92 // Constructs a new object by rebuilding its contents from the history |
| 91 // database in |history_db|. Returns the new URLIndexPrivateData which on | 93 // database in |history_db|. Returns the new URLIndexPrivateData which on |
| 92 // success will contain the rebuilt data but upon failure will be empty. | 94 // success will contain the rebuilt data but upon failure will be empty. |
| 93 // |languages| gives a list of language encodings by which the URLs and page | 95 // |languages| gives a list of language encodings by which the URLs and page |
| 94 // titles are broken down into words and characters. | 96 // titles are broken down into words and characters. |
| 95 static scoped_refptr<URLIndexPrivateData> RebuildFromHistory( | 97 static scoped_refptr<URLIndexPrivateData> RebuildFromHistory( |
| 98 Profile* profile, |
| 96 HistoryDatabase* history_db, | 99 HistoryDatabase* history_db, |
| 97 const std::string& languages, | 100 const std::string& languages, |
| 98 const std::set<std::string>& scheme_whitelist); | 101 const std::set<std::string>& scheme_whitelist); |
| 99 | 102 |
| 100 // Writes |private_data| as a cache file to |file_path| and returns success | 103 // Writes |private_data| as a cache file to |file_path| and returns success |
| 101 // via |succeeded|. | 104 // via |succeeded|. |
| 102 static void WritePrivateDataToCacheFileTask( | 105 static void WritePrivateDataToCacheFileTask( |
| 103 scoped_refptr<URLIndexPrivateData> private_data, | 106 scoped_refptr<URLIndexPrivateData> private_data, |
| 104 const FilePath& file_path, | 107 const FilePath& file_path, |
| 105 scoped_refptr<RefCountedBool> succeeded); | 108 scoped_refptr<RefCountedBool> succeeded); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 void SaveCharWordMap(imui::InMemoryURLIndexCacheItem* cache) const; | 264 void SaveCharWordMap(imui::InMemoryURLIndexCacheItem* cache) const; |
| 262 void SaveWordIDHistoryMap(imui::InMemoryURLIndexCacheItem* cache) const; | 265 void SaveWordIDHistoryMap(imui::InMemoryURLIndexCacheItem* cache) const; |
| 263 void SaveHistoryInfoMap(imui::InMemoryURLIndexCacheItem* cache) const; | 266 void SaveHistoryInfoMap(imui::InMemoryURLIndexCacheItem* cache) const; |
| 264 void SaveWordStartsMap(imui::InMemoryURLIndexCacheItem* cache) const; | 267 void SaveWordStartsMap(imui::InMemoryURLIndexCacheItem* cache) const; |
| 265 | 268 |
| 266 // Constructs a new object by restoring its contents from the file at |path|. | 269 // Constructs a new object by restoring its contents from the file at |path|. |
| 267 // Returns the new URLIndexPrivateData which on success will contain the | 270 // Returns the new URLIndexPrivateData which on success will contain the |
| 268 // restored data but upon failure will be empty. |languages| will be used to | 271 // restored data but upon failure will be empty. |languages| will be used to |
| 269 // break URLs and page titles into words | 272 // break URLs and page titles into words |
| 270 static scoped_refptr<URLIndexPrivateData> RestoreFromFile( | 273 static scoped_refptr<URLIndexPrivateData> RestoreFromFile( |
| 274 Profile* profile, |
| 271 const FilePath& path, | 275 const FilePath& path, |
| 272 const std::string& languages); | 276 const std::string& languages); |
| 273 | 277 |
| 274 // Decode a data structure from the protobuf |cache|. Return false if there | 278 // Decode a data structure from the protobuf |cache|. Return false if there |
| 275 // is any kind of failure. |languages| will be used to break URLs and page | 279 // is any kind of failure. |languages| will be used to break URLs and page |
| 276 // titles into words | 280 // titles into words |
| 277 bool RestorePrivateData(const imui::InMemoryURLIndexCacheItem& cache, | 281 bool RestorePrivateData(const imui::InMemoryURLIndexCacheItem& cache, |
| 278 const std::string& languages); | 282 const std::string& languages); |
| 279 bool RestoreWordList(const imui::InMemoryURLIndexCacheItem& cache); | 283 bool RestoreWordList(const imui::InMemoryURLIndexCacheItem& cache); |
| 280 bool RestoreWordMap(const imui::InMemoryURLIndexCacheItem& cache); | 284 bool RestoreWordMap(const imui::InMemoryURLIndexCacheItem& cache); |
| 281 bool RestoreCharWordMap(const imui::InMemoryURLIndexCacheItem& cache); | 285 bool RestoreCharWordMap(const imui::InMemoryURLIndexCacheItem& cache); |
| 282 bool RestoreWordIDHistoryMap(const imui::InMemoryURLIndexCacheItem& cache); | 286 bool RestoreWordIDHistoryMap(const imui::InMemoryURLIndexCacheItem& cache); |
| 283 bool RestoreHistoryInfoMap(const imui::InMemoryURLIndexCacheItem& cache); | 287 bool RestoreHistoryInfoMap(const imui::InMemoryURLIndexCacheItem& cache); |
| 284 bool RestoreWordStartsMap(const imui::InMemoryURLIndexCacheItem& cache, | 288 bool RestoreWordStartsMap(const imui::InMemoryURLIndexCacheItem& cache, |
| 285 const std::string& languages); | 289 const std::string& languages); |
| 286 | 290 |
| 287 // Determines if |gurl| has a whitelisted scheme and returns true if so. | 291 // Determines if |gurl| has a whitelisted scheme and returns true if so. |
| 288 static bool URLSchemeIsWhitelisted(const GURL& gurl, | 292 static bool URLSchemeIsWhitelisted(const GURL& gurl, |
| 289 const std::set<std::string>& whitelist); | 293 const std::set<std::string>& whitelist); |
| 290 | 294 |
| 291 // Cache of search terms. | 295 // Cache of search terms. |
| 292 SearchTermCacheMap search_term_cache_; | 296 SearchTermCacheMap search_term_cache_; |
| 293 | 297 |
| 298 Profile* profile_; |
| 299 |
| 294 // Start of data members that are cached ------------------------------------- | 300 // Start of data members that are cached ------------------------------------- |
| 295 | 301 |
| 296 // The version of the cache file most recently used to restore this instance | 302 // The version of the cache file most recently used to restore this instance |
| 297 // of the private data. If the private data was rebuilt from the history | 303 // of the private data. If the private data was rebuilt from the history |
| 298 // database this will be 0. | 304 // database this will be 0. |
| 299 int restored_cache_version_; | 305 int restored_cache_version_; |
| 300 | 306 |
| 301 // A list of all of indexed words. The index of a word in this list is the | 307 // A list of all of indexed words. The index of a word in this list is the |
| 302 // ID of the word in the word_map_. It reduces the memory overhead by | 308 // ID of the word in the word_map_. It reduces the memory overhead by |
| 303 // replacing a potentially long and repeated string with a simple index. | 309 // replacing a potentially long and repeated string with a simple index. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 // Used for unit testing only. Records the number of candidate history items | 354 // Used for unit testing only. Records the number of candidate history items |
| 349 // at three stages in the index searching process. | 355 // at three stages in the index searching process. |
| 350 size_t pre_filter_item_count_; // After word index is queried. | 356 size_t pre_filter_item_count_; // After word index is queried. |
| 351 size_t post_filter_item_count_; // After trimming large result set. | 357 size_t post_filter_item_count_; // After trimming large result set. |
| 352 size_t post_scoring_item_count_; // After performing final filter/scoring. | 358 size_t post_scoring_item_count_; // After performing final filter/scoring. |
| 353 }; | 359 }; |
| 354 | 360 |
| 355 } // namespace history | 361 } // namespace history |
| 356 | 362 |
| 357 #endif // CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_ | 363 #endif // CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_ |
| OLD | NEW |