Index: chrome/browser/history/url_index_private_data.h |
=================================================================== |
--- chrome/browser/history/url_index_private_data.h (revision 126922) |
+++ 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,18 +24,23 @@ |
namespace imui = in_memory_url_index; |
class HistoryDatabase; |
+class InMemoryURLIndex; |
+class RefCountedBool; |
// Current version of the cache file. |
static const int kCurrentCacheFileVersion = 1; |
// 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; |
@@ -129,28 +136,54 @@ |
// 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|. |
+ // |languages| will be used to break URLs and page titles into words and is |
+ // deliberately passed by value. |
+ static void RestoreFromFileTask( |
+ const FilePath& file_path, |
+ scoped_refptr<URLIndexPrivateData> private_data, |
+ std::string languages); |
- // 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. |languages| will be used to |
+ // break URLs and page titles into words |
+ static scoped_refptr<URLIndexPrivateData> RestoreFromFile( |
+ const FilePath& path, |
+ const std::string& languages); |
// 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. |
+ scoped_refptr<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); |
@@ -158,21 +191,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 |
@@ -182,7 +220,11 @@ |
// Parses and indexes the words in the URL and page title of |row| and |
// calculate the word starts in each, saving the starts in |word_starts|. |
- void AddRowWordsToIndex(const URLRow& row, RowWordStarts* word_starts); |
+ // |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, |
+ RowWordStarts* word_starts, |
+ const std::string& languages); |
// Removes |row| and all associated words and characters from the index. |
void RemoveRowFromIndex(const URLRow& row); |
@@ -235,13 +277,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; |
- |
- // Sets the version of the cache file that will be saved when calling |
- // SavePrivateData(). For unit testing only. |
- void set_saved_cache_version(int version) { saved_cache_version_ = version; } |
- |
// Encode a data structure into the protobuf |cache|. |
void SavePrivateData(imui::InMemoryURLIndexCacheItem* cache) const; |
void SaveWordList(imui::InMemoryURLIndexCacheItem* cache) const; |
@@ -252,24 +287,25 @@ |
void SaveWordStartsMap(imui::InMemoryURLIndexCacheItem* cache) const; |
// Decode a data structure from the protobuf |cache|. Return false if there |
- // is any kind of failure. |
- bool RestorePrivateData(const imui::InMemoryURLIndexCacheItem& cache); |
+ // is any kind of failure. |languages| will be used to break URLs and page |
+ // titles into words |
+ bool RestorePrivateData(const imui::InMemoryURLIndexCacheItem& cache, |
+ const std::string& languages); |
bool RestoreWordList(const imui::InMemoryURLIndexCacheItem& cache); |
bool RestoreWordMap(const imui::InMemoryURLIndexCacheItem& cache); |
bool RestoreCharWordMap(const imui::InMemoryURLIndexCacheItem& cache); |
bool RestoreWordIDHistoryMap(const imui::InMemoryURLIndexCacheItem& cache); |
bool RestoreHistoryInfoMap(const imui::InMemoryURLIndexCacheItem& cache); |
- bool RestoreWordStartsMap(const imui::InMemoryURLIndexCacheItem& cache); |
+ bool RestoreWordStartsMap(const imui::InMemoryURLIndexCacheItem& cache, |
+ const std::string& languages); |
+ // 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 ------------------------------------- |
// The version of the cache file most recently used to restore this instance |