| Index: chrome/browser/history/url_index_private_data.h
|
| ===================================================================
|
| --- chrome/browser/history/url_index_private_data.h (revision 125451)
|
| +++ chrome/browser/history/url_index_private_data.h (working copy)
|
| @@ -8,8 +8,10 @@
|
|
|
| #include "base/file_path.h"
|
| #include "base/gtest_prod_util.h"
|
| +#include "base/memory/ref_counted.h"
|
| #include "chrome/browser/history/in_memory_url_index_types.h"
|
| #include "chrome/browser/history/in_memory_url_index_cache.pb.h"
|
| +#include "content/public/browser/notification_details.h"
|
|
|
| class HistoryQuickProviderTest;
|
|
|
| @@ -22,15 +24,20 @@
|
| namespace imui = in_memory_url_index;
|
|
|
| class HistoryDatabase;
|
| +class InMemoryURLIndex;
|
| +class RefCountedBool;
|
|
|
| // A structure describing the InMemoryURLIndex's internal data and providing for
|
| // restoring, rebuilding and updating that internal data.
|
| -class URLIndexPrivateData {
|
| +class URLIndexPrivateData
|
| + : public base::RefCountedThreadSafe<URLIndexPrivateData> {
|
| public:
|
| URLIndexPrivateData();
|
| +
|
| + private:
|
| + friend class base::RefCountedThreadSafe<URLIndexPrivateData>;
|
| ~URLIndexPrivateData();
|
|
|
| - private:
|
| friend class AddHistoryMatch;
|
| friend class ::HistoryQuickProviderTest;
|
| friend class InMemoryURLIndex;
|
| @@ -126,28 +133,50 @@
|
| // to this function.
|
| ScoredHistoryMatches HistoryItemsForTerms(const string16& term_string);
|
|
|
| - // Sets the |languages| to a list of language encodings with which the history
|
| - // URLs and omnibox searches are interpreted, i.e. how each is broken
|
| - // down into words and each word is broken down into characters.
|
| - void set_languages(const std::string& languages) { languages_ = languages; }
|
| + // Creates a new URLIndexPrivateData object, populates it from the contents
|
| + // of the cache file stored in |file_path|, and assigns it to
|
| + // |private_data_ptr|.
|
| + static void RestoreFromFileTask(
|
| + const FilePath& file_path,
|
| + scoped_refptr<URLIndexPrivateData> private_data_ptr);
|
|
|
| - // Restores the index's private data from the cache file stored in the
|
| - // profile directory and returns true if successful.
|
| - bool RestoreFromFile(const FilePath& file_path);
|
| + // Constructs a new object by restoring its contents from the file at |path|.
|
| + // Returns the new URLIndexPrivateData which on success will contain the
|
| + // restored data but upon failure will be empty.
|
| + static scoped_refptr<URLIndexPrivateData> RestoreFromFile(
|
| + const FilePath& path);
|
|
|
| // Constructs a new object by rebuilding its contents from the history
|
| // database in |history_db|. Returns the new URLIndexPrivateData which on
|
| // success will contain the rebuilt data but upon failure will be empty.
|
| - static URLIndexPrivateData* RebuildFromHistory(HistoryDatabase* history_db);
|
| + // |languages| gives a list of language encodings by which the URLs and page
|
| + // titles are broken down into words and characters.
|
| + static scoped_refptr<URLIndexPrivateData> RebuildFromHistory(
|
| + HistoryDatabase* history_db,
|
| + const std::string& languages,
|
| + const std::set<std::string>& scheme_whitelist);
|
|
|
| + // Writes |private_data| as a cache file to |file_path| and returns success
|
| + // via |succeeded|.
|
| + static void WritePrivateDataToCacheFileTask(
|
| + scoped_refptr<URLIndexPrivateData> private_data,
|
| + const FilePath& file_path,
|
| + scoped_refptr<RefCountedBool> succeeded);
|
| +
|
| // Caches the index private data and writes the cache file to the profile
|
| - // directory.
|
| + // directory. Called by WritePrivateDataToCacheFileTask.
|
| bool SaveToFile(const FilePath& file_path);
|
|
|
| // Initializes all index data members in preparation for restoring the index
|
| // from the cache or a complete rebuild from the history database.
|
| void Clear();
|
|
|
| + // Returns true if there is no data in the index.
|
| + bool Empty() const;
|
| +
|
| + // Creates a copy of ourself.
|
| + URLIndexPrivateData* Duplicate() const;
|
| +
|
| // Adds |word_id| to |history_id|'s entry in the history/word map,
|
| // creating a new entry if one does not already exist.
|
| void AddToHistoryIDWordMap(HistoryID history_id, WordID word_id);
|
| @@ -155,21 +184,26 @@
|
| // Given a set of Char16s, finds words containing those characters.
|
| WordIDSet WordIDSetForTermChars(const Char16Set& term_chars);
|
|
|
| - // Initializes the whitelist of URL schemes.
|
| - static void InitializeSchemeWhitelist(std::set<std::string>* whitelist);
|
| -
|
| // URL History indexing support functions.
|
|
|
| // Indexes one URL history item as described by |row|. Returns true if the
|
| - // row was actually indexed.
|
| - bool IndexRow(const URLRow& row);
|
| + // row was actually indexed. |languages| gives a list of language encodings by
|
| + // which the URLs and page titles are broken down into words and characters.
|
| + // |scheme_whitelist| is used to filter non-qualifying schemes.
|
| + bool IndexRow(const URLRow& row,
|
| + const std::string& languages,
|
| + const std::set<std::string>& scheme_whitelist);
|
|
|
| // Adds the history item in |row| to the index if it does not already already
|
| // exist and it meets the minimum 'quick' criteria. If the row already exists
|
| // in the index then the index will be updated if the row still meets the
|
| // criteria, otherwise the row will be removed from the index. Returns true
|
| - // if the index was actually updated.
|
| - bool UpdateURL(const URLRow& row);
|
| + // if the index was actually updated. |languages| gives a list of language
|
| + // encodings by which the URLs and page titles are broken down into words and
|
| + // characters. |scheme_whitelist| is used to filter non-qualifying schemes.
|
| + bool UpdateURL(const URLRow& row,
|
| + const std::string& languages,
|
| + const std::set<std::string>& scheme_whitelist);
|
|
|
| // Deletes indexing data for the history item with the URL given in |url|.
|
| // The item may not have actually been indexed, which is the case if it did
|
| @@ -178,7 +212,10 @@
|
| bool DeleteURL(const GURL& url);
|
|
|
| // Parses and indexes the words in the URL and page title of |row|.
|
| - void AddRowWordsToIndex(const URLRow& row);
|
| + // |languages| gives a list of language encodings by which the URLs and page
|
| + // titles are broken down into words and characters.
|
| + void AddRowWordsToIndex(const URLRow& row,
|
| + const std::string& languages);
|
|
|
| // Removes |row| and all associated words and characters from the index.
|
| void RemoveRowFromIndex(const URLRow& row);
|
| @@ -230,9 +267,6 @@
|
| static int ScoreComponentForMatches(const TermMatches& matches,
|
| size_t max_length);
|
|
|
| - // Determines if |gurl| has a whitelisted scheme and returns true if so.
|
| - bool URLSchemeIsWhitelisted(const GURL& gurl) const;
|
| -
|
| // Encode a data structure into the protobuf |cache|.
|
| void SavePrivateData(imui::InMemoryURLIndexCacheItem* cache) const;
|
| void SaveWordList(imui::InMemoryURLIndexCacheItem* cache) const;
|
| @@ -250,15 +284,13 @@
|
| bool RestoreWordIDHistoryMap(const imui::InMemoryURLIndexCacheItem& cache);
|
| bool RestoreHistoryInfoMap(const imui::InMemoryURLIndexCacheItem& cache);
|
|
|
| + // Determines if |gurl| has a whitelisted scheme and returns true if so.
|
| + static bool URLSchemeIsWhitelisted(const GURL& gurl,
|
| + const std::set<std::string>& whitelist);
|
| +
|
| // Cache of search terms.
|
| SearchTermCacheMap search_term_cache_;
|
|
|
| - // Languages used during the word-breaking process during indexing.
|
| - std::string languages_;
|
| -
|
| - // Only URLs with a whitelisted scheme are indexed.
|
| - std::set<std::string> scheme_whitelist_;
|
| -
|
| // Start of data members that are cached -------------------------------------
|
|
|
| // A list of all of indexed words. The index of a word in this list is the
|
|
|