| 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_AUTOCOMPLETE_IN_MEMORY_URL_INDEX_H_ | 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_IN_MEMORY_URL_INDEX_H_ |
| 6 #define CHROME_BROWSER_AUTOCOMPLETE_IN_MEMORY_URL_INDEX_H_ | 6 #define CHROME_BROWSER_AUTOCOMPLETE_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> |
| (...skipping 18 matching lines...) Expand all Loading... |
| 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 class HistoryDatabase; |
| 40 } |
| 39 | 41 |
| 40 namespace imui = in_memory_url_index; | |
| 41 | |
| 42 class HistoryDatabase; | |
| 43 class URLIndexPrivateData; | 42 class URLIndexPrivateData; |
| 44 | 43 |
| 45 // The URL history source. | 44 // The URL history source. |
| 46 // Holds portions of the URL database in memory in an indexed form. Used to | 45 // Holds portions of the URL database in memory in an indexed form. Used to |
| 47 // quickly look up matching URLs for a given query string. Used by | 46 // quickly look up matching URLs for a given query string. Used by |
| 48 // the HistoryURLProvider for inline autocomplete and to provide URL | 47 // the HistoryURLProvider for inline autocomplete and to provide URL |
| 49 // matches to the omnibox. | 48 // matches to the omnibox. |
| 50 // | 49 // |
| 51 // Note about multi-byte codepoints and the data structures in the | 50 // Note about multi-byte codepoints and the data structures in the |
| 52 // InMemoryURLIndex class: One will quickly notice that no effort is made to | 51 // InMemoryURLIndex class: One will quickly notice that no effort is made to |
| 53 // insure that multi-byte character boundaries are detected when indexing the | 52 // insure that multi-byte character boundaries are detected when indexing the |
| 54 // words and characters in the URL history database except when converting | 53 // words and characters in the URL history database except when converting |
| 55 // URL strings to lowercase. Multi-byte-edness makes no difference when | 54 // URL strings to lowercase. Multi-byte-edness makes no difference when |
| 56 // indexing or when searching the index as the final filtering of results | 55 // indexing or when searching the index as the final filtering of results |
| 57 // is dependent on the comparison of a string of bytes, not individual | 56 // is dependent on the comparison of a string of bytes, not individual |
| 58 // characters. While the lookup of those bytes during a search in the | 57 // characters. While the lookup of those bytes during a search in the |
| 59 // |char_word_map_| could serve up words in which the individual char16 | 58 // |char_word_map_| could serve up words in which the individual char16 |
| 60 // occurs as a portion of a composite character the next filtering step | 59 // occurs as a portion of a composite character the next filtering step |
| 61 // will eliminate such words except in the case where a single character | 60 // will eliminate such words except in the case where a single character |
| 62 // is being searched on and which character occurs as the second char16 of a | 61 // is being searched on and which character occurs as the second char16 of a |
| 63 // multi-char16 instance. | 62 // multi-char16 instance. |
| 64 class InMemoryURLIndex : public HistoryServiceObserver, | 63 class InMemoryURLIndex : public history::HistoryServiceObserver, |
| 65 public base::SupportsWeakPtr<InMemoryURLIndex> { | 64 public base::SupportsWeakPtr<InMemoryURLIndex> { |
| 66 public: | 65 public: |
| 67 // Defines an abstract class which is notified upon completion of restoring | 66 // Defines an abstract class which is notified upon completion of restoring |
| 68 // the index's private data either by reading from the cache file or by | 67 // the index's private data either by reading from the cache file or by |
| 69 // rebuilding from the history database. | 68 // rebuilding from the history database. |
| 70 class RestoreCacheObserver { | 69 class RestoreCacheObserver { |
| 71 public: | 70 public: |
| 72 virtual ~RestoreCacheObserver(); | 71 virtual ~RestoreCacheObserver(); |
| 73 | 72 |
| 74 // Callback that lets the observer know that the restore operation has | 73 // Callback that lets the observer know that the restore operation has |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 } | 139 } |
| 141 | 140 |
| 142 private: | 141 private: |
| 143 friend class ::HistoryQuickProviderTest; | 142 friend class ::HistoryQuickProviderTest; |
| 144 friend class InMemoryURLIndexTest; | 143 friend class InMemoryURLIndexTest; |
| 145 friend class InMemoryURLIndexCacheTest; | 144 friend class InMemoryURLIndexCacheTest; |
| 146 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, ExpireRow); | 145 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, ExpireRow); |
| 147 FRIEND_TEST_ALL_PREFIXES(LimitedInMemoryURLIndexTest, Initialization); | 146 FRIEND_TEST_ALL_PREFIXES(LimitedInMemoryURLIndexTest, Initialization); |
| 148 | 147 |
| 149 // HistoryDBTask used to rebuild our private data from the history database. | 148 // HistoryDBTask used to rebuild our private data from the history database. |
| 150 class RebuildPrivateDataFromHistoryDBTask : public HistoryDBTask { | 149 class RebuildPrivateDataFromHistoryDBTask : public history::HistoryDBTask { |
| 151 public: | 150 public: |
| 152 explicit RebuildPrivateDataFromHistoryDBTask( | 151 explicit RebuildPrivateDataFromHistoryDBTask( |
| 153 InMemoryURLIndex* index, | 152 InMemoryURLIndex* index, |
| 154 const std::string& languages, | 153 const std::string& languages, |
| 155 const std::set<std::string>& scheme_whitelist); | 154 const std::set<std::string>& scheme_whitelist); |
| 156 | 155 |
| 157 bool RunOnDBThread(HistoryBackend* backend, | 156 bool RunOnDBThread(history::HistoryBackend* backend, |
| 158 history::HistoryDatabase* db) override; | 157 history::HistoryDatabase* db) override; |
| 159 void DoneRunOnMainThread() override; | 158 void DoneRunOnMainThread() override; |
| 160 | 159 |
| 161 private: | 160 private: |
| 162 ~RebuildPrivateDataFromHistoryDBTask() override; | 161 ~RebuildPrivateDataFromHistoryDBTask() override; |
| 163 | 162 |
| 164 InMemoryURLIndex* index_; // Call back to this index at completion. | 163 InMemoryURLIndex* index_; // Call back to this index at completion. |
| 165 std::string languages_; // Languages for word-breaking. | 164 std::string languages_; // Languages for word-breaking. |
| 166 std::set<std::string> scheme_whitelist_; // Schemes to be indexed. | 165 std::set<std::string> scheme_whitelist_; // Schemes to be indexed. |
| 167 bool succeeded_; // Indicates if the rebuild was successful. | 166 bool succeeded_; // Indicates if the rebuild was successful. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 191 // Callback used by RebuildPrivateDataFromHistoryDBTask to signal completion | 190 // Callback used by RebuildPrivateDataFromHistoryDBTask to signal completion |
| 192 // or rebuilding our private data from the history database. |succeeded| | 191 // or rebuilding our private data from the history database. |succeeded| |
| 193 // will be true if the rebuild was successful. |data| will point to a new | 192 // will be true if the rebuild was successful. |data| will point to a new |
| 194 // instanceof the private data just rebuilt. | 193 // instanceof the private data just rebuilt. |
| 195 void DoneRebuidingPrivateDataFromHistoryDB( | 194 void DoneRebuidingPrivateDataFromHistoryDB( |
| 196 bool succeeded, | 195 bool succeeded, |
| 197 scoped_refptr<URLIndexPrivateData> private_data); | 196 scoped_refptr<URLIndexPrivateData> private_data); |
| 198 | 197 |
| 199 // Rebuilds the history index from the history database in |history_db|. | 198 // Rebuilds the history index from the history database in |history_db|. |
| 200 // Used for unit testing only. | 199 // Used for unit testing only. |
| 201 void RebuildFromHistory(HistoryDatabase* history_db); | 200 void RebuildFromHistory(history::HistoryDatabase* history_db); |
| 202 | 201 |
| 203 // Determines if the private data was successfully reloaded from the cache | 202 // Determines if the private data was successfully reloaded from the cache |
| 204 // file or if the private data must be rebuilt from the history database. | 203 // file or if the private data must be rebuilt from the history database. |
| 205 // |private_data_ptr|'s data will be NULL if the cache file load failed. If | 204 // |private_data_ptr|'s data will be NULL if the cache file load failed. If |
| 206 // successful, sets the private data and notifies any | 205 // successful, sets the private data and notifies any |
| 207 // |restore_cache_observer_|. Otherwise, kicks off a rebuild from the history | 206 // |restore_cache_observer_|. Otherwise, kicks off a rebuild from the history |
| 208 // database. | 207 // database. |
| 209 void OnCacheLoadDone(scoped_refptr<URLIndexPrivateData> private_data_ptr); | 208 void OnCacheLoadDone(scoped_refptr<URLIndexPrivateData> private_data_ptr); |
| 210 | 209 |
| 211 // Callback function that sets the private data from the just-restored-from- | 210 // Callback function that sets the private data from the just-restored-from- |
| 212 // file |private_data|. Notifies any |restore_cache_observer_| that the | 211 // file |private_data|. Notifies any |restore_cache_observer_| that the |
| 213 // restore has succeeded. | 212 // restore has succeeded. |
| 214 void OnCacheRestored(URLIndexPrivateData* private_data); | 213 void OnCacheRestored(URLIndexPrivateData* private_data); |
| 215 | 214 |
| 216 // Posts a task to cache the index private data and write the cache file to | 215 // Posts a task to cache the index private data and write the cache file to |
| 217 // the history directory. | 216 // the history directory. |
| 218 void PostSaveToCacheFileTask(); | 217 void PostSaveToCacheFileTask(); |
| 219 | 218 |
| 220 // Saves private_data_ to the given |path|. Runs on the UI thread. | 219 // Saves private_data_ to the given |path|. Runs on the UI thread. |
| 221 // Provided for unit testing so that a test cache file can be used. | 220 // Provided for unit testing so that a test cache file can be used. |
| 222 void DoSaveToCacheFile(const base::FilePath& path); | 221 void DoSaveToCacheFile(const base::FilePath& path); |
| 223 | 222 |
| 224 // Notifies the observer, if any, of the success of the private data caching. | 223 // Notifies the observer, if any, of the success of the private data caching. |
| 225 // |succeeded| is true on a successful save. | 224 // |succeeded| is true on a successful save. |
| 226 void OnCacheSaveDone(bool succeeded); | 225 void OnCacheSaveDone(bool succeeded); |
| 227 | 226 |
| 228 // HistoryServiceObserver: | 227 // HistoryServiceObserver: |
| 229 void OnURLVisited(HistoryService* history_service, | 228 void OnURLVisited(HistoryService* history_service, |
| 230 ui::PageTransition transition, | 229 ui::PageTransition transition, |
| 231 const URLRow& row, | 230 const history::URLRow& row, |
| 232 const RedirectList& redirects, | 231 const history::RedirectList& redirects, |
| 233 base::Time visit_time) override; | 232 base::Time visit_time) override; |
| 234 void OnURLsModified(HistoryService* history_service, | 233 void OnURLsModified(HistoryService* history_service, |
| 235 const URLRows& changed_urls) override; | 234 const history::URLRows& changed_urls) override; |
| 236 void OnURLsDeleted(HistoryService* history_service, | 235 void OnURLsDeleted(HistoryService* history_service, |
| 237 bool all_history, | 236 bool all_history, |
| 238 bool expired, | 237 bool expired, |
| 239 const URLRows& deleted_rows, | 238 const history::URLRows& deleted_rows, |
| 240 const std::set<GURL>& favicon_urls) override; | 239 const std::set<GURL>& favicon_urls) override; |
| 241 void OnHistoryServiceLoaded(HistoryService* history_service) override; | 240 void OnHistoryServiceLoaded(HistoryService* history_service) override; |
| 242 | 241 |
| 243 // Sets the directory wherein the cache file will be maintained. | 242 // Sets the directory wherein the cache file will be maintained. |
| 244 // For unit test usage only. | 243 // For unit test usage only. |
| 245 void set_history_dir(const base::FilePath& dir_path) { | 244 void set_history_dir(const base::FilePath& dir_path) { |
| 246 history_dir_ = dir_path; | 245 history_dir_ = dir_path; |
| 247 } | 246 } |
| 248 | 247 |
| 249 // Returns a pointer to our private data. For unit testing only. | 248 // Returns a pointer to our private data. For unit testing only. |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 // index has been destructed. | 293 // index has been destructed. |
| 295 bool needs_to_be_cached_; | 294 bool needs_to_be_cached_; |
| 296 | 295 |
| 297 // This flag is set to true if we want to listen to the | 296 // This flag is set to true if we want to listen to the |
| 298 // HistoryServiceLoaded Notification. | 297 // HistoryServiceLoaded Notification. |
| 299 bool listen_to_history_service_loaded_; | 298 bool listen_to_history_service_loaded_; |
| 300 | 299 |
| 301 DISALLOW_COPY_AND_ASSIGN(InMemoryURLIndex); | 300 DISALLOW_COPY_AND_ASSIGN(InMemoryURLIndex); |
| 302 }; | 301 }; |
| 303 | 302 |
| 304 } // namespace history | |
| 305 | |
| 306 #endif // CHROME_BROWSER_AUTOCOMPLETE_IN_MEMORY_URL_INDEX_H_ | 303 #endif // CHROME_BROWSER_AUTOCOMPLETE_IN_MEMORY_URL_INDEX_H_ |
| OLD | NEW |