| 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" | 14 #include "chrome/browser/common/cancelable_request.h" |
| 15 #include "chrome/browser/history/history_service.h" | 15 #include "chrome/browser/history/history_service.h" |
| 16 #include "chrome/browser/history/in_memory_url_index_cache.pb.h" | 16 #include "chrome/browser/history/in_memory_url_index_cache.pb.h" |
| 17 #include "chrome/browser/history/in_memory_url_index_types.h" | 17 #include "chrome/browser/history/in_memory_url_index_types.h" |
| 18 #include "chrome/browser/history/scored_history_match.h" | 18 #include "chrome/browser/history/scored_history_match.h" |
| 19 | 19 |
| 20 class BookmarkService; | |
| 21 class HistoryQuickProviderTest; | 20 class HistoryQuickProviderTest; |
| 22 | 21 |
| 23 namespace in_memory_url_index { | 22 namespace in_memory_url_index { |
| 24 class InMemoryURLIndexCacheItem; | 23 class InMemoryURLIndexCacheItem; |
| 25 } | 24 } |
| 26 | 25 |
| 27 namespace history { | 26 namespace history { |
| 28 | 27 |
| 29 namespace imui = in_memory_url_index; | 28 namespace imui = in_memory_url_index; |
| 30 | 29 |
| 30 class HistoryClient; |
| 31 class HistoryDatabase; | 31 class HistoryDatabase; |
| 32 class InMemoryURLIndex; | 32 class InMemoryURLIndex; |
| 33 class RefCountedBool; | 33 class RefCountedBool; |
| 34 | 34 |
| 35 // Current version of the cache file. | 35 // Current version of the cache file. |
| 36 static const int kCurrentCacheFileVersion = 5; | 36 static const int kCurrentCacheFileVersion = 5; |
| 37 | 37 |
| 38 // A structure private to InMemoryURLIndex describing its internal data and | 38 // A structure private to InMemoryURLIndex describing its internal data and |
| 39 // providing for restoring, rebuilding and updating that internal data. As | 39 // providing for restoring, rebuilding and updating that internal data. As |
| 40 // this class is for exclusive use by the InMemoryURLIndex class there should | 40 // this class is for exclusive use by the InMemoryURLIndex class there should |
| (...skipping 15 matching lines...) Expand all Loading... |
| 56 // set). Once we have a set of candidates, they are filtered to ensure | 56 // set). Once we have a set of candidates, they are filtered to ensure |
| 57 // that all |term_string| terms, as separated by whitespace and the | 57 // that all |term_string| terms, as separated by whitespace and the |
| 58 // cursor (if set), occur within the candidate's URL or page title. | 58 // cursor (if set), occur within the candidate's URL or page title. |
| 59 // Scores are then calculated on no more than |kItemsToScoreLimit| | 59 // Scores are then calculated on no more than |kItemsToScoreLimit| |
| 60 // candidates, as the scoring of such a large number of candidates may | 60 // candidates, as the scoring of such a large number of candidates may |
| 61 // cause perceptible typing response delays in the omnibox. This is | 61 // cause perceptible typing response delays in the omnibox. This is |
| 62 // likely to occur for short omnibox terms such as 'h' and 'w' which | 62 // likely to occur for short omnibox terms such as 'h' and 'w' which |
| 63 // will be found in nearly all history candidates. Results are sorted by | 63 // will be found in nearly all history candidates. Results are sorted by |
| 64 // descending score. The full results set (i.e. beyond the | 64 // descending score. The full results set (i.e. beyond the |
| 65 // |kItemsToScoreLimit| limit) will be retained and used for subsequent calls | 65 // |kItemsToScoreLimit| limit) will be retained and used for subsequent calls |
| 66 // to this function. |bookmark_service| is used to boost a result's score if | 66 // to this function. |history_client| is used to boost a result's score if |
| 67 // its URL is referenced by one or more of the user's bookmarks. |languages| | 67 // its URL is referenced by one or more of the user's bookmarks. |languages| |
| 68 // is used to help parse/format the URLs in the history index. In total, | 68 // is used to help parse/format the URLs in the history index. In total, |
| 69 // |max_matches| of items will be returned in the |ScoredHistoryMatches| | 69 // |max_matches| of items will be returned in the |ScoredHistoryMatches| |
| 70 // vector. | 70 // vector. |
| 71 ScoredHistoryMatches HistoryItemsForTerms(base::string16 term_string, | 71 ScoredHistoryMatches HistoryItemsForTerms(base::string16 term_string, |
| 72 size_t cursor_position, | 72 size_t cursor_position, |
| 73 size_t max_matches, | 73 size_t max_matches, |
| 74 const std::string& languages, | 74 const std::string& languages, |
| 75 BookmarkService* bookmark_service); | 75 HistoryClient* history_client); |
| 76 | 76 |
| 77 // Adds the history item in |row| to the index if it does not already already | 77 // Adds the history item in |row| to the index if it does not already already |
| 78 // exist and it meets the minimum 'quick' criteria. If the row already exists | 78 // exist and it meets the minimum 'quick' criteria. If the row already exists |
| 79 // in the index then the index will be updated if the row still meets the | 79 // 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 | 80 // 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 | 81 // 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 | 82 // 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. | 83 // characters. |scheme_whitelist| is used to filter non-qualifying schemes. |
| 84 // |history_service| is used to schedule an update to the recent visits | 84 // |history_service| is used to schedule an update to the recent visits |
| 85 // component of this URL's entry in the index. | 85 // component of this URL's entry in the index. |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 bool used_; // True if this item has been used for the current term search. | 192 bool used_; // True if this item has been used for the current term search. |
| 193 }; | 193 }; |
| 194 typedef std::map<base::string16, SearchTermCacheItem> SearchTermCacheMap; | 194 typedef std::map<base::string16, SearchTermCacheItem> SearchTermCacheMap; |
| 195 | 195 |
| 196 // A helper class which performs the final filter on each candidate | 196 // A helper class which performs the final filter on each candidate |
| 197 // history URL match, inserting accepted matches into |scored_matches_|. | 197 // history URL match, inserting accepted matches into |scored_matches_|. |
| 198 class AddHistoryMatch : public std::unary_function<HistoryID, void> { | 198 class AddHistoryMatch : public std::unary_function<HistoryID, void> { |
| 199 public: | 199 public: |
| 200 AddHistoryMatch(const URLIndexPrivateData& private_data, | 200 AddHistoryMatch(const URLIndexPrivateData& private_data, |
| 201 const std::string& languages, | 201 const std::string& languages, |
| 202 BookmarkService* bookmark_service, | 202 HistoryClient* history_client, |
| 203 const base::string16& lower_string, | 203 const base::string16& lower_string, |
| 204 const String16Vector& lower_terms, | 204 const String16Vector& lower_terms, |
| 205 const base::Time now); | 205 const base::Time now); |
| 206 ~AddHistoryMatch(); | 206 ~AddHistoryMatch(); |
| 207 | 207 |
| 208 void operator()(const HistoryID history_id); | 208 void operator()(const HistoryID history_id); |
| 209 | 209 |
| 210 ScoredHistoryMatches ScoredMatches() const { return scored_matches_; } | 210 ScoredHistoryMatches ScoredMatches() const { return scored_matches_; } |
| 211 | 211 |
| 212 private: | 212 private: |
| 213 const URLIndexPrivateData& private_data_; | 213 const URLIndexPrivateData& private_data_; |
| 214 const std::string& languages_; | 214 const std::string& languages_; |
| 215 BookmarkService* bookmark_service_; | 215 HistoryClient* history_client_; |
| 216 ScoredHistoryMatches scored_matches_; | 216 ScoredHistoryMatches scored_matches_; |
| 217 const base::string16& lower_string_; | 217 const base::string16& lower_string_; |
| 218 const String16Vector& lower_terms_; | 218 const String16Vector& lower_terms_; |
| 219 WordStarts lower_terms_to_word_starts_offsets_; | 219 WordStarts lower_terms_to_word_starts_offsets_; |
| 220 const base::Time now_; | 220 const base::Time now_; |
| 221 }; | 221 }; |
| 222 | 222 |
| 223 // A helper predicate class used to filter excess history items when the | 223 // A helper predicate class used to filter excess history items when the |
| 224 // candidate results set is too large. | 224 // candidate results set is too large. |
| 225 class HistoryItemFactorGreater | 225 class HistoryItemFactorGreater |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 392 // Used for unit testing only. Records the number of candidate history items | 392 // Used for unit testing only. Records the number of candidate history items |
| 393 // at three stages in the index searching process. | 393 // at three stages in the index searching process. |
| 394 size_t pre_filter_item_count_; // After word index is queried. | 394 size_t pre_filter_item_count_; // After word index is queried. |
| 395 size_t post_filter_item_count_; // After trimming large result set. | 395 size_t post_filter_item_count_; // After trimming large result set. |
| 396 size_t post_scoring_item_count_; // After performing final filter/scoring. | 396 size_t post_scoring_item_count_; // After performing final filter/scoring. |
| 397 }; | 397 }; |
| 398 | 398 |
| 399 } // namespace history | 399 } // namespace history |
| 400 | 400 |
| 401 #endif // CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_ | 401 #endif // CHROME_BROWSER_HISTORY_URL_INDEX_PRIVATE_DATA_H_ |
| OLD | NEW |