| 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/scoped_observer.h" | 19 #include "base/scoped_observer.h" |
| 20 #include "base/strings/string16.h" | 20 #include "base/strings/string16.h" |
| 21 #include "base/task/cancelable_task_tracker.h" | 21 #include "base/task/cancelable_task_tracker.h" |
| 22 #include "chrome/browser/history/history_db_task.h" | 22 #include "chrome/browser/history/history_db_task.h" |
| 23 #include "chrome/browser/history/in_memory_url_index_types.h" | 23 #include "chrome/browser/history/in_memory_url_index_types.h" |
| 24 #include "chrome/browser/history/scored_history_match.h" | 24 #include "chrome/browser/history/scored_history_match.h" |
| 25 #include "components/history/core/browser/history_service_observer.h" | 25 #include "components/history/core/browser/history_service_observer.h" |
| 26 #include "components/history/core/browser/history_types.h" | 26 #include "components/history/core/browser/history_types.h" |
| 27 #include "content/public/browser/notification_observer.h" | |
| 28 #include "content/public/browser/notification_registrar.h" | |
| 29 #include "sql/connection.h" | 27 #include "sql/connection.h" |
| 30 | 28 |
| 31 class HistoryService; | 29 class HistoryService; |
| 32 class HistoryQuickProviderTest; | 30 class HistoryQuickProviderTest; |
| 33 class Profile; | 31 class Profile; |
| 34 | 32 |
| 35 namespace base { | 33 namespace base { |
| 36 class Time; | 34 class Time; |
| 37 } | 35 } |
| 38 | 36 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 63 // URL strings to lowercase. Multi-byte-edness makes no difference when | 61 // URL strings to lowercase. Multi-byte-edness makes no difference when |
| 64 // indexing or when searching the index as the final filtering of results | 62 // indexing or when searching the index as the final filtering of results |
| 65 // is dependent on the comparison of a string of bytes, not individual | 63 // is dependent on the comparison of a string of bytes, not individual |
| 66 // characters. While the lookup of those bytes during a search in the | 64 // characters. While the lookup of those bytes during a search in the |
| 67 // |char_word_map_| could serve up words in which the individual char16 | 65 // |char_word_map_| could serve up words in which the individual char16 |
| 68 // occurs as a portion of a composite character the next filtering step | 66 // occurs as a portion of a composite character the next filtering step |
| 69 // will eliminate such words except in the case where a single character | 67 // will eliminate such words except in the case where a single character |
| 70 // is being searched on and which character occurs as the second char16 of a | 68 // is being searched on and which character occurs as the second char16 of a |
| 71 // multi-char16 instance. | 69 // multi-char16 instance. |
| 72 class InMemoryURLIndex : public HistoryServiceObserver, | 70 class InMemoryURLIndex : public HistoryServiceObserver, |
| 73 public content::NotificationObserver, | |
| 74 public base::SupportsWeakPtr<InMemoryURLIndex> { | 71 public base::SupportsWeakPtr<InMemoryURLIndex> { |
| 75 public: | 72 public: |
| 76 // Defines an abstract class which is notified upon completion of restoring | 73 // Defines an abstract class which is notified upon completion of restoring |
| 77 // the index's private data either by reading from the cache file or by | 74 // the index's private data either by reading from the cache file or by |
| 78 // rebuilding from the history database. | 75 // rebuilding from the history database. |
| 79 class RestoreCacheObserver { | 76 class RestoreCacheObserver { |
| 80 public: | 77 public: |
| 81 virtual ~RestoreCacheObserver(); | 78 virtual ~RestoreCacheObserver(); |
| 82 | 79 |
| 83 // Callback that lets the observer know that the restore operation has | 80 // Callback that lets the observer know that the restore operation has |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 141 |
| 145 // Indicates that the index restoration is complete. | 142 // Indicates that the index restoration is complete. |
| 146 bool restored() const { | 143 bool restored() const { |
| 147 return restored_; | 144 return restored_; |
| 148 } | 145 } |
| 149 | 146 |
| 150 private: | 147 private: |
| 151 friend class ::HistoryQuickProviderTest; | 148 friend class ::HistoryQuickProviderTest; |
| 152 friend class InMemoryURLIndexTest; | 149 friend class InMemoryURLIndexTest; |
| 153 friend class InMemoryURLIndexCacheTest; | 150 friend class InMemoryURLIndexCacheTest; |
| 151 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, ExpireRow); |
| 154 FRIEND_TEST_ALL_PREFIXES(LimitedInMemoryURLIndexTest, Initialization); | 152 FRIEND_TEST_ALL_PREFIXES(LimitedInMemoryURLIndexTest, Initialization); |
| 155 | 153 |
| 156 // Creating one of me without a history path is not allowed (tests excepted). | 154 // Creating one of me without a history path is not allowed (tests excepted). |
| 157 InMemoryURLIndex(); | 155 InMemoryURLIndex(); |
| 158 | 156 |
| 159 // HistoryDBTask used to rebuild our private data from the history database. | 157 // HistoryDBTask used to rebuild our private data from the history database. |
| 160 class RebuildPrivateDataFromHistoryDBTask : public HistoryDBTask { | 158 class RebuildPrivateDataFromHistoryDBTask : public HistoryDBTask { |
| 161 public: | 159 public: |
| 162 explicit RebuildPrivateDataFromHistoryDBTask( | 160 explicit RebuildPrivateDataFromHistoryDBTask( |
| 163 InMemoryURLIndex* index, | 161 InMemoryURLIndex* index, |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 void PostSaveToCacheFileTask(); | 226 void PostSaveToCacheFileTask(); |
| 229 | 227 |
| 230 // Saves private_data_ to the given |path|. Runs on the UI thread. | 228 // Saves private_data_ to the given |path|. Runs on the UI thread. |
| 231 // Provided for unit testing so that a test cache file can be used. | 229 // Provided for unit testing so that a test cache file can be used. |
| 232 void DoSaveToCacheFile(const base::FilePath& path); | 230 void DoSaveToCacheFile(const base::FilePath& path); |
| 233 | 231 |
| 234 // Notifies the observer, if any, of the success of the private data caching. | 232 // Notifies the observer, if any, of the success of the private data caching. |
| 235 // |succeeded| is true on a successful save. | 233 // |succeeded| is true on a successful save. |
| 236 void OnCacheSaveDone(bool succeeded); | 234 void OnCacheSaveDone(bool succeeded); |
| 237 | 235 |
| 238 // Handles notifications of history changes. | |
| 239 void Observe(int notification_type, | |
| 240 const content::NotificationSource& source, | |
| 241 const content::NotificationDetails& details) override; | |
| 242 | |
| 243 // HistoryServiceObserver: | 236 // HistoryServiceObserver: |
| 244 void OnURLVisited(HistoryService* history_service, | 237 void OnURLVisited(HistoryService* history_service, |
| 245 ui::PageTransition transition, | 238 ui::PageTransition transition, |
| 246 const URLRow& row, | 239 const URLRow& row, |
| 247 const RedirectList& redirects, | 240 const RedirectList& redirects, |
| 248 base::Time visit_time) override; | 241 base::Time visit_time) override; |
| 249 void OnURLsModified(HistoryService* history_service, | 242 void OnURLsModified(HistoryService* history_service, |
| 250 const URLRows& changed_urls) override; | 243 const URLRows& changed_urls) override; |
| 244 void OnURLsDeleted( |
| 245 HistoryService* history_service, |
| 246 const history::URLsDeletedDetails& deleted_details) override; |
| 251 void OnHistoryServiceLoaded(HistoryService* history_service) override; | 247 void OnHistoryServiceLoaded(HistoryService* history_service) override; |
| 252 | 248 |
| 253 // Notification handlers. | |
| 254 void OnURLsDeleted(const URLsDeletedDetails* details); | |
| 255 | |
| 256 // Sets the directory wherein the cache file will be maintained. | 249 // Sets the directory wherein the cache file will be maintained. |
| 257 // For unit test usage only. | 250 // For unit test usage only. |
| 258 void set_history_dir(const base::FilePath& dir_path) { | 251 void set_history_dir(const base::FilePath& dir_path) { |
| 259 history_dir_ = dir_path; | 252 history_dir_ = dir_path; |
| 260 } | 253 } |
| 261 | 254 |
| 262 // Returns a pointer to our private data. For unit testing only. | 255 // Returns a pointer to our private data. For unit testing only. |
| 263 URLIndexPrivateData* private_data() { return private_data_.get(); } | 256 URLIndexPrivateData* private_data() { return private_data_.get(); } |
| 264 | 257 |
| 265 // Returns a pointer to our private data cancelable request tracker. For | 258 // Returns a pointer to our private data cancelable request tracker. For |
| (...skipping 25 matching lines...) Expand all Loading... |
| 291 | 284 |
| 292 // The index's durable private data. | 285 // The index's durable private data. |
| 293 scoped_refptr<URLIndexPrivateData> private_data_; | 286 scoped_refptr<URLIndexPrivateData> private_data_; |
| 294 | 287 |
| 295 // Observers to notify upon restoral or save of the private data cache. | 288 // Observers to notify upon restoral or save of the private data cache. |
| 296 RestoreCacheObserver* restore_cache_observer_; | 289 RestoreCacheObserver* restore_cache_observer_; |
| 297 SaveCacheObserver* save_cache_observer_; | 290 SaveCacheObserver* save_cache_observer_; |
| 298 | 291 |
| 299 base::CancelableTaskTracker private_data_tracker_; | 292 base::CancelableTaskTracker private_data_tracker_; |
| 300 base::CancelableTaskTracker cache_reader_tracker_; | 293 base::CancelableTaskTracker cache_reader_tracker_; |
| 301 content::NotificationRegistrar registrar_; | |
| 302 | 294 |
| 303 // Set to true once the shutdown process has begun. | 295 // Set to true once the shutdown process has begun. |
| 304 bool shutdown_; | 296 bool shutdown_; |
| 305 | 297 |
| 306 // Set to true once the index restoration is complete. | 298 // Set to true once the index restoration is complete. |
| 307 bool restored_; | 299 bool restored_; |
| 308 | 300 |
| 309 // Set to true when changes to the index have been made and the index needs | 301 // Set to true when changes to the index have been made and the index needs |
| 310 // to be cached. Set to false when the index has been cached. Used as a | 302 // to be cached. Set to false when the index has been cached. Used as a |
| 311 // temporary safety check to insure that the cache is saved before the | 303 // temporary safety check to insure that the cache is saved before the |
| 312 // index has been destructed. | 304 // index has been destructed. |
| 313 bool needs_to_be_cached_; | 305 bool needs_to_be_cached_; |
| 314 | 306 |
| 315 ScopedObserver<HistoryService, HistoryServiceObserver> | 307 ScopedObserver<HistoryService, HistoryServiceObserver> |
| 316 history_service_observer_; | 308 history_service_observer_; |
| 317 | 309 |
| 318 DISALLOW_COPY_AND_ASSIGN(InMemoryURLIndex); | 310 DISALLOW_COPY_AND_ASSIGN(InMemoryURLIndex); |
| 319 }; | 311 }; |
| 320 | 312 |
| 321 } // namespace history | 313 } // namespace history |
| 322 | 314 |
| 323 #endif // CHROME_BROWSER_HISTORY_IN_MEMORY_URL_INDEX_H_ | 315 #endif // CHROME_BROWSER_HISTORY_IN_MEMORY_URL_INDEX_H_ |
| OLD | NEW |