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