| 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/files/file_path.h" | 11 #include "base/files/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/common/cancelable_request.h" | |
| 15 #include "chrome/browser/history/history_service.h" | 14 #include "chrome/browser/history/history_service.h" |
| 16 #include "chrome/browser/history/in_memory_url_index_cache.pb.h" | 15 #include "chrome/browser/history/in_memory_url_index_cache.pb.h" |
| 17 #include "chrome/browser/history/in_memory_url_index_types.h" | 16 #include "chrome/browser/history/in_memory_url_index_types.h" |
| 18 #include "chrome/browser/history/scored_history_match.h" | 17 #include "chrome/browser/history/scored_history_match.h" |
| 19 | 18 |
| 20 class HistoryQuickProviderTest; | 19 class HistoryQuickProviderTest; |
| 21 | 20 |
| 22 namespace in_memory_url_index { | 21 namespace in_memory_url_index { |
| 23 class InMemoryURLIndexCacheItem; | 22 class InMemoryURLIndexCacheItem; |
| 24 } | 23 } |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 // in the index then the index will be updated if the row still meets the | 78 // in the index then the index will be updated if the row still meets the |
| 80 // criteria, otherwise the row will be removed from the index. Returns true | 79 // criteria, otherwise the row will be removed from the index. Returns true |
| 81 // if the index was actually updated. |languages| gives a list of language | 80 // if the index was actually updated. |languages| gives a list of language |
| 82 // encodings by which the URLs and page titles are broken down into words and | 81 // encodings by which the URLs and page titles are broken down into words and |
| 83 // characters. |scheme_whitelist| is used to filter non-qualifying schemes. | 82 // characters. |scheme_whitelist| is used to filter non-qualifying schemes. |
| 84 // |history_service| is used to schedule an update to the recent visits | 83 // |history_service| is used to schedule an update to the recent visits |
| 85 // component of this URL's entry in the index. | 84 // component of this URL's entry in the index. |
| 86 bool UpdateURL(HistoryService* history_service, | 85 bool UpdateURL(HistoryService* history_service, |
| 87 const URLRow& row, | 86 const URLRow& row, |
| 88 const std::string& languages, | 87 const std::string& languages, |
| 89 const std::set<std::string>& scheme_whitelist); | 88 const std::set<std::string>& scheme_whitelist, |
| 89 base::CancelableTaskTracker* tracker); |
| 90 | 90 |
| 91 // Updates the entry for |url_id| in the index, replacing its | 91 // Updates the entry for |url_id| in the index, replacing its |
| 92 // recent visits information with |recent_visits|. If |url_id| | 92 // recent visits information with |recent_visits|. If |url_id| |
| 93 // is not in the index, does nothing. | 93 // is not in the index, does nothing. |
| 94 void UpdateRecentVisits(URLID url_id, | 94 void UpdateRecentVisits(URLID url_id, |
| 95 const VisitVector& recent_visits); | 95 const VisitVector& recent_visits); |
| 96 | 96 |
| 97 // Using |history_service| schedules an update (using the historyDB | 97 // Using |history_service| schedules an update (using the historyDB |
| 98 // thread) for the recent visits information for |url_id|. Unless | 98 // thread) for the recent visits information for |url_id|. Unless |
| 99 // something unexpectedly goes wrong, UdpateRecentVisits() should | 99 // something unexpectedly goes wrong, UdpateRecentVisits() should |
| 100 // eventually be called from a callback. | 100 // eventually be called from a callback. |
| 101 void ScheduleUpdateRecentVisits(HistoryService* history_service, | 101 void ScheduleUpdateRecentVisits(HistoryService* history_service, |
| 102 URLID url_id); | 102 URLID url_id, |
| 103 base::CancelableTaskTracker* tracker); |
| 103 | 104 |
| 104 // Deletes index data for the history item with the given |url|. | 105 // Deletes index data for the history item with the given |url|. |
| 105 // The item may not have actually been indexed, which is the case if it did | 106 // The item may not have actually been indexed, which is the case if it did |
| 106 // not previously meet minimum 'quick' criteria. Returns true if the index | 107 // not previously meet minimum 'quick' criteria. Returns true if the index |
| 107 // was actually updated. | 108 // was actually updated. |
| 108 bool DeleteURL(const GURL& url); | 109 bool DeleteURL(const GURL& url); |
| 109 | 110 |
| 110 // Constructs a new object by restoring its contents from the cache file | 111 // Constructs a new object by restoring its contents from the cache file |
| 111 // at |path|. Returns the new URLIndexPrivateData which on success will | 112 // at |path|. Returns the new URLIndexPrivateData which on success will |
| 112 // contain the restored data but upon failure will be empty. |languages| | 113 // contain the restored data but upon failure will be empty. |languages| |
| (...skipping 11 matching lines...) Expand all Loading... |
| 124 static scoped_refptr<URLIndexPrivateData> RebuildFromHistory( | 125 static scoped_refptr<URLIndexPrivateData> RebuildFromHistory( |
| 125 HistoryDatabase* history_db, | 126 HistoryDatabase* history_db, |
| 126 const std::string& languages, | 127 const std::string& languages, |
| 127 const std::set<std::string>& scheme_whitelist); | 128 const std::set<std::string>& scheme_whitelist); |
| 128 | 129 |
| 129 // Writes |private_data| as a cache file to |file_path| and returns success. | 130 // Writes |private_data| as a cache file to |file_path| and returns success. |
| 130 static bool WritePrivateDataToCacheFileTask( | 131 static bool WritePrivateDataToCacheFileTask( |
| 131 scoped_refptr<URLIndexPrivateData> private_data, | 132 scoped_refptr<URLIndexPrivateData> private_data, |
| 132 const base::FilePath& file_path); | 133 const base::FilePath& file_path); |
| 133 | 134 |
| 134 // Stops all pending updates to recent visits fields. This should be | |
| 135 // called during shutdown. | |
| 136 void CancelPendingUpdates(); | |
| 137 | |
| 138 // Creates a copy of ourself. | 135 // Creates a copy of ourself. |
| 139 scoped_refptr<URLIndexPrivateData> Duplicate() const; | 136 scoped_refptr<URLIndexPrivateData> Duplicate() const; |
| 140 | 137 |
| 141 // Returns true if there is no data in the index. | 138 // Returns true if there is no data in the index. |
| 142 bool Empty() const; | 139 bool Empty() const; |
| 143 | 140 |
| 144 // Initializes all index data members in preparation for restoring the index | 141 // Initializes all index data members in preparation for restoring the index |
| 145 // from the cache or a complete rebuild from the history database. | 142 // from the cache or a complete rebuild from the history database. |
| 146 void Clear(); | 143 void Clear(); |
| 147 | 144 |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 // |history_db| is not NULL then this function uses the history database | 251 // |history_db| is not NULL then this function uses the history database |
| 255 // synchronously to get the URL's recent visits information. This mode should | 252 // synchronously to get the URL's recent visits information. This mode should |
| 256 // only be used on the historyDB thread. If |history_db| is NULL, then | 253 // only be used on the historyDB thread. If |history_db| is NULL, then |
| 257 // this function uses |history_service| to schedule a task on the | 254 // this function uses |history_service| to schedule a task on the |
| 258 // historyDB thread to fetch and update the recent visits | 255 // historyDB thread to fetch and update the recent visits |
| 259 // information. | 256 // information. |
| 260 bool IndexRow(HistoryDatabase* history_db, | 257 bool IndexRow(HistoryDatabase* history_db, |
| 261 HistoryService* history_service, | 258 HistoryService* history_service, |
| 262 const URLRow& row, | 259 const URLRow& row, |
| 263 const std::string& languages, | 260 const std::string& languages, |
| 264 const std::set<std::string>& scheme_whitelist); | 261 const std::set<std::string>& scheme_whitelist, |
| 262 base::CancelableTaskTracker* tracker); |
| 265 | 263 |
| 266 // Parses and indexes the words in the URL and page title of |row| and | 264 // Parses and indexes the words in the URL and page title of |row| and |
| 267 // calculate the word starts in each, saving the starts in |word_starts|. | 265 // calculate the word starts in each, saving the starts in |word_starts|. |
| 268 // |languages| gives a list of language encodings by which the URLs and page | 266 // |languages| gives a list of language encodings by which the URLs and page |
| 269 // titles are broken down into words and characters. | 267 // titles are broken down into words and characters. |
| 270 void AddRowWordsToIndex(const URLRow& row, | 268 void AddRowWordsToIndex(const URLRow& row, |
| 271 RowWordStarts* word_starts, | 269 RowWordStarts* word_starts, |
| 272 const std::string& languages); | 270 const std::string& languages); |
| 273 | 271 |
| 274 // Given a single word in |uni_word|, adds a reference for the containing | 272 // Given a single word in |uni_word|, adds a reference for the containing |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 bool RestoreWordStartsMap(const imui::InMemoryURLIndexCacheItem& cache, | 320 bool RestoreWordStartsMap(const imui::InMemoryURLIndexCacheItem& cache, |
| 323 const std::string& languages); | 321 const std::string& languages); |
| 324 | 322 |
| 325 // Determines if |gurl| has a whitelisted scheme and returns true if so. | 323 // Determines if |gurl| has a whitelisted scheme and returns true if so. |
| 326 static bool URLSchemeIsWhitelisted(const GURL& gurl, | 324 static bool URLSchemeIsWhitelisted(const GURL& gurl, |
| 327 const std::set<std::string>& whitelist); | 325 const std::set<std::string>& whitelist); |
| 328 | 326 |
| 329 // Cache of search terms. | 327 // Cache of search terms. |
| 330 SearchTermCacheMap search_term_cache_; | 328 SearchTermCacheMap search_term_cache_; |
| 331 | 329 |
| 332 // Allows canceling pending requests to update recent visits information. | |
| 333 CancelableRequestConsumer recent_visits_consumer_; | |
| 334 | |
| 335 // Start of data members that are cached ------------------------------------- | 330 // Start of data members that are cached ------------------------------------- |
| 336 | 331 |
| 337 // The version of the cache file most recently used to restore this instance | 332 // The version of the cache file most recently used to restore this instance |
| 338 // of the private data. If the private data was rebuilt from the history | 333 // of the private data. If the private data was rebuilt from the history |
| 339 // database this will be 0. | 334 // database this will be 0. |
| 340 int restored_cache_version_; | 335 int restored_cache_version_; |
| 341 | 336 |
| 342 // The last time the data was rebuilt from the history database. | 337 // The last time the data was rebuilt from the history database. |
| 343 base::Time last_time_rebuilt_from_history_; | 338 base::Time last_time_rebuilt_from_history_; |
| 344 | 339 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 // Used for unit testing only. Records the number of candidate history items | 387 // Used for unit testing only. Records the number of candidate history items |
| 393 // at three stages in the index searching process. | 388 // at three stages in the index searching process. |
| 394 size_t pre_filter_item_count_; // After word index is queried. | 389 size_t pre_filter_item_count_; // After word index is queried. |
| 395 size_t post_filter_item_count_; // After trimming large result set. | 390 size_t post_filter_item_count_; // After trimming large result set. |
| 396 size_t post_scoring_item_count_; // After performing final filter/scoring. | 391 size_t post_scoring_item_count_; // After performing final filter/scoring. |
| 397 }; | 392 }; |
| 398 | 393 |
| 399 } // namespace history | 394 } // namespace history |
| 400 | 395 |
| 401 #endif // CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_ | 396 #endif // CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_ |
| OLD | NEW |