Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(503)

Side by Side Diff: chrome/browser/history/in_memory_url_index.h

Issue 773103004: Remove NOTIFICATION_HISTORY_URLS_DELETED (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase to tip Created 5 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/scored_history_match.h" 22 #include "chrome/browser/history/scored_history_match.h"
23 #include "components/history/core/browser/history_db_task.h" 23 #include "components/history/core/browser/history_db_task.h"
24 #include "components/history/core/browser/history_service_observer.h" 24 #include "components/history/core/browser/history_service_observer.h"
25 #include "components/history/core/browser/history_types.h" 25 #include "components/history/core/browser/history_types.h"
26 #include "components/history/core/browser/in_memory_url_index_types.h"
27 #include "content/public/browser/notification_observer.h"
28 #include "content/public/browser/notification_registrar.h"
29 #include "sql/connection.h" 26 #include "sql/connection.h"
30 27
31 class HistoryService; 28 class HistoryService;
32 class HistoryQuickProviderTest; 29 class HistoryQuickProviderTest;
33 class Profile; 30 class Profile;
34 31
35 namespace base { 32 namespace base {
36 class Time; 33 class Time;
37 } 34 }
38 35
39 namespace in_memory_url_index { 36 namespace in_memory_url_index {
40 class InMemoryURLIndexCacheItem; 37 class InMemoryURLIndexCacheItem;
41 } 38 }
42 39
43 namespace history { 40 namespace history {
44 41
45 namespace imui = in_memory_url_index; 42 namespace imui = in_memory_url_index;
46 43
47 class HistoryClient; 44 class HistoryClient;
48 class HistoryDatabase; 45 class HistoryDatabase;
49 class URLIndexPrivateData; 46 class URLIndexPrivateData;
50 struct URLsDeletedDetails;
51 struct URLsModifiedDetails;
52 47
53 // The URL history source. 48 // The URL history source.
54 // Holds portions of the URL database in memory in an indexed form. Used to 49 // Holds portions of the URL database in memory in an indexed form. Used to
55 // quickly look up matching URLs for a given query string. Used by 50 // quickly look up matching URLs for a given query string. Used by
56 // the HistoryURLProvider for inline autocomplete and to provide URL 51 // the HistoryURLProvider for inline autocomplete and to provide URL
57 // matches to the omnibox. 52 // matches to the omnibox.
58 // 53 //
59 // Note about multi-byte codepoints and the data structures in the 54 // Note about multi-byte codepoints and the data structures in the
60 // InMemoryURLIndex class: One will quickly notice that no effort is made to 55 // InMemoryURLIndex class: One will quickly notice that no effort is made to
61 // insure that multi-byte character boundaries are detected when indexing the 56 // insure that multi-byte character boundaries are detected when indexing the
62 // words and characters in the URL history database except when converting 57 // words and characters in the URL history database except when converting
63 // URL strings to lowercase. Multi-byte-edness makes no difference when 58 // URL strings to lowercase. Multi-byte-edness makes no difference when
64 // indexing or when searching the index as the final filtering of results 59 // 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 60 // 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 61 // 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 62 // |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 63 // 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 64 // 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 65 // is being searched on and which character occurs as the second char16 of a
71 // multi-char16 instance. 66 // multi-char16 instance.
72 class InMemoryURLIndex : public HistoryServiceObserver, 67 class InMemoryURLIndex : public HistoryServiceObserver,
73 public content::NotificationObserver,
74 public base::SupportsWeakPtr<InMemoryURLIndex> { 68 public base::SupportsWeakPtr<InMemoryURLIndex> {
75 public: 69 public:
76 // Defines an abstract class which is notified upon completion of restoring 70 // 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 71 // the index's private data either by reading from the cache file or by
78 // rebuilding from the history database. 72 // rebuilding from the history database.
79 class RestoreCacheObserver { 73 class RestoreCacheObserver {
80 public: 74 public:
81 virtual ~RestoreCacheObserver(); 75 virtual ~RestoreCacheObserver();
82 76
83 // Callback that lets the observer know that the restore operation has 77 // Callback that lets the observer know that the restore operation has
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 138
145 // Indicates that the index restoration is complete. 139 // Indicates that the index restoration is complete.
146 bool restored() const { 140 bool restored() const {
147 return restored_; 141 return restored_;
148 } 142 }
149 143
150 private: 144 private:
151 friend class ::HistoryQuickProviderTest; 145 friend class ::HistoryQuickProviderTest;
152 friend class InMemoryURLIndexTest; 146 friend class InMemoryURLIndexTest;
153 friend class InMemoryURLIndexCacheTest; 147 friend class InMemoryURLIndexCacheTest;
148 FRIEND_TEST_ALL_PREFIXES(InMemoryURLIndexTest, ExpireRow);
154 FRIEND_TEST_ALL_PREFIXES(LimitedInMemoryURLIndexTest, Initialization); 149 FRIEND_TEST_ALL_PREFIXES(LimitedInMemoryURLIndexTest, Initialization);
155 150
156 // Creating one of me without a history path is not allowed (tests excepted). 151 // Creating one of me without a history path is not allowed (tests excepted).
157 InMemoryURLIndex(); 152 InMemoryURLIndex();
158 153
159 // HistoryDBTask used to rebuild our private data from the history database. 154 // HistoryDBTask used to rebuild our private data from the history database.
160 class RebuildPrivateDataFromHistoryDBTask : public HistoryDBTask { 155 class RebuildPrivateDataFromHistoryDBTask : public HistoryDBTask {
161 public: 156 public:
162 explicit RebuildPrivateDataFromHistoryDBTask( 157 explicit RebuildPrivateDataFromHistoryDBTask(
163 InMemoryURLIndex* index, 158 InMemoryURLIndex* index,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 void PostSaveToCacheFileTask(); 223 void PostSaveToCacheFileTask();
229 224
230 // Saves private_data_ to the given |path|. Runs on the UI thread. 225 // 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. 226 // Provided for unit testing so that a test cache file can be used.
232 void DoSaveToCacheFile(const base::FilePath& path); 227 void DoSaveToCacheFile(const base::FilePath& path);
233 228
234 // Notifies the observer, if any, of the success of the private data caching. 229 // Notifies the observer, if any, of the success of the private data caching.
235 // |succeeded| is true on a successful save. 230 // |succeeded| is true on a successful save.
236 void OnCacheSaveDone(bool succeeded); 231 void OnCacheSaveDone(bool succeeded);
237 232
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: 233 // HistoryServiceObserver:
244 void OnURLVisited(HistoryService* history_service, 234 void OnURLVisited(HistoryService* history_service,
245 ui::PageTransition transition, 235 ui::PageTransition transition,
246 const URLRow& row, 236 const URLRow& row,
247 const RedirectList& redirects, 237 const RedirectList& redirects,
248 base::Time visit_time) override; 238 base::Time visit_time) override;
249 void OnURLsModified(HistoryService* history_service, 239 void OnURLsModified(HistoryService* history_service,
250 const URLRows& changed_urls) override; 240 const URLRows& changed_urls) override;
241 void OnURLsDeleted(HistoryService* history_service,
242 bool all_history,
243 bool expired,
244 const URLRows& deleted_rows,
245 const std::set<GURL>& favicon_urls) override;
251 void OnHistoryServiceLoaded(HistoryService* history_service) override; 246 void OnHistoryServiceLoaded(HistoryService* history_service) override;
252 247
253 // Notification handlers.
254 void OnURLsDeleted(const URLsDeletedDetails* details);
255
256 // Sets the directory wherein the cache file will be maintained. 248 // Sets the directory wherein the cache file will be maintained.
257 // For unit test usage only. 249 // For unit test usage only.
258 void set_history_dir(const base::FilePath& dir_path) { 250 void set_history_dir(const base::FilePath& dir_path) {
259 history_dir_ = dir_path; 251 history_dir_ = dir_path;
260 } 252 }
261 253
262 // Returns a pointer to our private data. For unit testing only. 254 // Returns a pointer to our private data. For unit testing only.
263 URLIndexPrivateData* private_data() { return private_data_.get(); } 255 URLIndexPrivateData* private_data() { return private_data_.get(); }
264 256
265 // Returns a pointer to our private data cancelable request tracker. For 257 // Returns a pointer to our private data cancelable request tracker. For
(...skipping 25 matching lines...) Expand all
291 283
292 // The index's durable private data. 284 // The index's durable private data.
293 scoped_refptr<URLIndexPrivateData> private_data_; 285 scoped_refptr<URLIndexPrivateData> private_data_;
294 286
295 // Observers to notify upon restoral or save of the private data cache. 287 // Observers to notify upon restoral or save of the private data cache.
296 RestoreCacheObserver* restore_cache_observer_; 288 RestoreCacheObserver* restore_cache_observer_;
297 SaveCacheObserver* save_cache_observer_; 289 SaveCacheObserver* save_cache_observer_;
298 290
299 base::CancelableTaskTracker private_data_tracker_; 291 base::CancelableTaskTracker private_data_tracker_;
300 base::CancelableTaskTracker cache_reader_tracker_; 292 base::CancelableTaskTracker cache_reader_tracker_;
301 content::NotificationRegistrar registrar_;
302 293
303 // Set to true once the shutdown process has begun. 294 // Set to true once the shutdown process has begun.
304 bool shutdown_; 295 bool shutdown_;
305 296
306 // Set to true once the index restoration is complete. 297 // Set to true once the index restoration is complete.
307 bool restored_; 298 bool restored_;
308 299
309 // Set to true when changes to the index have been made and the index needs 300 // 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 301 // 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 302 // temporary safety check to insure that the cache is saved before the
312 // index has been destructed. 303 // index has been destructed.
313 bool needs_to_be_cached_; 304 bool needs_to_be_cached_;
314 305
315 ScopedObserver<HistoryService, HistoryServiceObserver> 306 ScopedObserver<HistoryService, HistoryServiceObserver>
316 history_service_observer_; 307 history_service_observer_;
317 308
318 DISALLOW_COPY_AND_ASSIGN(InMemoryURLIndex); 309 DISALLOW_COPY_AND_ASSIGN(InMemoryURLIndex);
319 }; 310 };
320 311
321 } // namespace history 312 } // namespace history
322 313
323 #endif // CHROME_BROWSER_HISTORY_IN_MEMORY_URL_INDEX_H_ 314 #endif // CHROME_BROWSER_HISTORY_IN_MEMORY_URL_INDEX_H_
OLDNEW
« no previous file with comments | « chrome/browser/history/in_memory_history_backend.cc ('k') | chrome/browser/history/in_memory_url_index.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698