| 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_IN_MEMORY_URL_INDEX_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_IN_MEMORY_URL_INDEX_H_ |
| 6 #define CHROME_BROWSER_HISTORY_IN_MEMORY_URL_INDEX_H_ | 6 #define CHROME_BROWSER_HISTORY_IN_MEMORY_URL_INDEX_H_ |
| 7 | 7 |
| 8 #include <functional> | 8 #include <functional> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <set> | 10 #include <set> |
| 11 #include <string> | 11 #include <string> |
| 12 #include <vector> | 12 #include <vector> |
| 13 | 13 |
| 14 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 15 #include "base/files/file_path.h" | 15 #include "base/files/file_path.h" |
| 16 #include "base/gtest_prod_util.h" | 16 #include "base/gtest_prod_util.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
| 20 #include "base/task/cancelable_task_tracker.h" | 20 #include "base/task/cancelable_task_tracker.h" |
| 21 #include "chrome/browser/history/scored_history_match.h" | |
| 22 #include "components/history/core/browser/history_db_task.h" | 21 #include "components/history/core/browser/history_db_task.h" |
| 23 #include "components/history/core/browser/history_service_observer.h" | 22 #include "components/history/core/browser/history_service_observer.h" |
| 24 #include "components/history/core/browser/history_types.h" | 23 #include "components/history/core/browser/history_types.h" |
| 24 #include "components/history/core/browser/scored_history_match.h" |
| 25 #include "sql/connection.h" | 25 #include "sql/connection.h" |
| 26 | 26 |
| 27 class HistoryService; | 27 class HistoryService; |
| 28 class HistoryQuickProviderTest; | 28 class HistoryQuickProviderTest; |
| 29 | 29 |
| 30 namespace base { | 30 namespace base { |
| 31 class Time; | 31 class Time; |
| 32 } | 32 } |
| 33 | 33 |
| 34 namespace in_memory_url_index { | 34 namespace in_memory_url_index { |
| 35 class InMemoryURLIndexCacheItem; | 35 class InMemoryURLIndexCacheItem; |
| 36 } | 36 } |
| 37 | 37 |
| 38 namespace history { | 38 namespace history { |
| 39 | 39 |
| 40 namespace imui = in_memory_url_index; | 40 namespace imui = in_memory_url_index; |
| 41 | 41 |
| 42 class HistoryClient; | |
| 43 class HistoryDatabase; | 42 class HistoryDatabase; |
| 44 class URLIndexPrivateData; | 43 class URLIndexPrivateData; |
| 45 | 44 |
| 46 // The URL history source. | 45 // The URL history source. |
| 47 // Holds portions of the URL database in memory in an indexed form. Used to | 46 // Holds portions of the URL database in memory in an indexed form. Used to |
| 48 // quickly look up matching URLs for a given query string. Used by | 47 // quickly look up matching URLs for a given query string. Used by |
| 49 // the HistoryURLProvider for inline autocomplete and to provide URL | 48 // the HistoryURLProvider for inline autocomplete and to provide URL |
| 50 // matches to the omnibox. | 49 // matches to the omnibox. |
| 51 // | 50 // |
| 52 // Note about multi-byte codepoints and the data structures in the | 51 // Note about multi-byte codepoints and the data structures in the |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 }; | 89 }; |
| 91 | 90 |
| 92 // |history_service| which may be null during unit testing is used to register | 91 // |history_service| which may be null during unit testing is used to register |
| 93 // |as an HistoryServiceObserver. |history_dir| is a path to the directory | 92 // |as an HistoryServiceObserver. |history_dir| is a path to the directory |
| 94 // containing the history database within the profile wherein the cache and | 93 // containing the history database within the profile wherein the cache and |
| 95 // transaction journals will be stored. |languages| gives a list of language | 94 // transaction journals will be stored. |languages| gives a list of language |
| 96 // encodings by which URLs and omnibox searches are broken down into words and | 95 // encodings by which URLs and omnibox searches are broken down into words and |
| 97 // characters. | 96 // characters. |
| 98 InMemoryURLIndex(HistoryService* history_service, | 97 InMemoryURLIndex(HistoryService* history_service, |
| 99 const base::FilePath& history_dir, | 98 const base::FilePath& history_dir, |
| 100 const std::string& languages, | 99 const std::string& languages); |
| 101 HistoryClient* client); | |
| 102 ~InMemoryURLIndex() override; | 100 ~InMemoryURLIndex() override; |
| 103 | 101 |
| 104 // Opens and prepares the index of historical URL visits. If the index private | 102 // Opens and prepares the index of historical URL visits. If the index private |
| 105 // data cannot be restored from its cache file then it is rebuilt from the | 103 // data cannot be restored from its cache file then it is rebuilt from the |
| 106 // history database. | 104 // history database. |
| 107 void Init(); | 105 void Init(); |
| 108 | 106 |
| 109 // Signals that any outstanding initialization should be canceled and | 107 // Signals that any outstanding initialization should be canceled and |
| 110 // flushes the cache to disk. | 108 // flushes the cache to disk. |
| 111 void ShutDown(); | 109 void ShutDown(); |
| 112 | 110 |
| 113 // Scans the history index and returns a vector with all scored, matching | 111 // Scans the history index and returns a vector with all scored, matching |
| 114 // history items. This entry point simply forwards the call on to the | 112 // history items. This entry point simply forwards the call on to the |
| 115 // URLIndexPrivateData class. For a complete description of this function | 113 // URLIndexPrivateData class. For a complete description of this function |
| 116 // refer to that class. If |cursor_position| is base::string16::npos, the | 114 // refer to that class. If |cursor_position| is base::string16::npos, the |
| 117 // function doesn't do anything special with the cursor; this is equivalent | 115 // function doesn't do anything special with the cursor; this is equivalent |
| 118 // to the cursor being at the end. In total, |max_matches| of items will be | 116 // to the cursor being at the end. In total, |max_matches| of items will be |
| 119 // returned in the |ScoredHistoryMatches| vector. | 117 // returned in the |ScoredHistoryMatches| vector. |
| 120 ScoredHistoryMatches HistoryItemsForTerms(const base::string16& term_string, | 118 ScoredHistoryMatches HistoryItemsForTerms( |
| 121 size_t cursor_position, | 119 const base::string16& term_string, |
| 122 size_t max_matches); | 120 size_t cursor_position, |
| 121 size_t max_matches, |
| 122 const ScoredHistoryMatch::Builder& builder); |
| 123 | 123 |
| 124 // Deletes the index entry, if any, for the given |url|. | 124 // Deletes the index entry, if any, for the given |url|. |
| 125 void DeleteURL(const GURL& url); | 125 void DeleteURL(const GURL& url); |
| 126 | 126 |
| 127 // Sets the optional observers for completion of restoral and saving of the | 127 // Sets the optional observers for completion of restoral and saving of the |
| 128 // index's private data. | 128 // index's private data. |
| 129 void set_restore_cache_observer( | 129 void set_restore_cache_observer( |
| 130 RestoreCacheObserver* restore_cache_observer) { | 130 RestoreCacheObserver* restore_cache_observer) { |
| 131 restore_cache_observer_ = restore_cache_observer; | 131 restore_cache_observer_ = restore_cache_observer; |
| 132 } | 132 } |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 base::CancelableTaskTracker* private_data_tracker() { | 254 base::CancelableTaskTracker* private_data_tracker() { |
| 255 return &private_data_tracker_; | 255 return &private_data_tracker_; |
| 256 } | 256 } |
| 257 | 257 |
| 258 // Returns the set of whitelisted schemes. For unit testing only. | 258 // Returns the set of whitelisted schemes. For unit testing only. |
| 259 const std::set<std::string>& scheme_whitelist() { return scheme_whitelist_; } | 259 const std::set<std::string>& scheme_whitelist() { return scheme_whitelist_; } |
| 260 | 260 |
| 261 // The HistoryService; may be null when testing. | 261 // The HistoryService; may be null when testing. |
| 262 HistoryService* history_service_; | 262 HistoryService* history_service_; |
| 263 | 263 |
| 264 // The HistoryClient; may be null when testing. | |
| 265 HistoryClient* history_client_; | |
| 266 | |
| 267 // Directory where cache file resides. This is, except when unit testing, | 264 // Directory where cache file resides. This is, except when unit testing, |
| 268 // the same directory in which the history database is found. It should never | 265 // the same directory in which the history database is found. It should never |
| 269 // be empty. | 266 // be empty. |
| 270 base::FilePath history_dir_; | 267 base::FilePath history_dir_; |
| 271 | 268 |
| 272 // Languages used during the word-breaking process during indexing. | 269 // Languages used during the word-breaking process during indexing. |
| 273 std::string languages_; | 270 std::string languages_; |
| 274 | 271 |
| 275 // Only URLs with a whitelisted scheme are indexed. | 272 // Only URLs with a whitelisted scheme are indexed. |
| 276 std::set<std::string> scheme_whitelist_; | 273 std::set<std::string> scheme_whitelist_; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 296 // temporary safety check to insure that the cache is saved before the | 293 // temporary safety check to insure that the cache is saved before the |
| 297 // index has been destructed. | 294 // index has been destructed. |
| 298 bool needs_to_be_cached_; | 295 bool needs_to_be_cached_; |
| 299 | 296 |
| 300 DISALLOW_COPY_AND_ASSIGN(InMemoryURLIndex); | 297 DISALLOW_COPY_AND_ASSIGN(InMemoryURLIndex); |
| 301 }; | 298 }; |
| 302 | 299 |
| 303 } // namespace history | 300 } // namespace history |
| 304 | 301 |
| 305 #endif // CHROME_BROWSER_HISTORY_IN_MEMORY_URL_INDEX_H_ | 302 #endif // CHROME_BROWSER_HISTORY_IN_MEMORY_URL_INDEX_H_ |
| OLD | NEW |