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

Unified Diff: chrome/browser/history/in_memory_url_index.h

Issue 8451009: HQP Refactoring (in Preparation for SQLite Cache) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/history/in_memory_url_index.h
===================================================================
--- chrome/browser/history/in_memory_url_index.h (revision 111352)
+++ chrome/browser/history/in_memory_url_index.h (working copy)
@@ -23,12 +23,12 @@
#include "chrome/browser/history/history_types.h"
#include "chrome/browser/history/in_memory_url_index_types.h"
#include "chrome/browser/history/in_memory_url_index_cache.pb.h"
+#include "content/public/browser/notification_observer.h"
+#include "content/public/browser/notification_registrar.h"
#include "sql/connection.h"
#include "testing/gtest/include/gtest/gtest_prod.h"
-namespace base {
-class Time;
-}
+class Profile;
namespace in_memory_url_index {
class InMemoryURLIndexCacheItem;
@@ -39,6 +39,9 @@
namespace imui = in_memory_url_index;
class URLDatabase;
+struct URLsDeletedDetails;
+struct URLsModifiedDetails;
+struct URLVisitedDetails;
// The URL history source.
// Holds portions of the URL database in memory in an indexed form. Used to
@@ -59,33 +62,29 @@
// will eliminate such words except in the case where a single character
// is being searched on and which character occurs as the second char16 of a
// multi-char16 instance.
-class InMemoryURLIndex {
+class InMemoryURLIndex : public content::NotificationObserver {
public:
// |history_dir| is a path to the directory containing the history database
// within the profile wherein the cache and transaction journals will be
// stored.
- explicit InMemoryURLIndex(const FilePath& history_dir);
+ InMemoryURLIndex(Profile* profile, const FilePath& history_dir);
virtual ~InMemoryURLIndex();
- // Opens and indexes the URL history database.
+ // Restores our index from its cache, if possible. If the cache is not
+ // available then we will register for the NOTIFICATION_HISTORY_LOADED
+ // notifications and then rebuild the index from the history database.
// |languages| gives a list of language encodings with which the history
// URLs and omnibox searches are interpreted, i.e. when each is broken
// down into words and each word is broken down into characters.
- bool Init(URLDatabase* history_db, const std::string& languages);
+ void Init(const std::string& languages);
- // Reloads the history index. Attempts to reload from the cache unless
- // |clear_cache| is true. If the cache is unavailable then reload the
- // index from |history_db|.
- bool ReloadFromHistory(URLDatabase* history_db, bool clear_cache);
+ // Reloads the history index from the history database given in |history_db|.
+ void ReloadFromHistory(URLDatabase* history_db);
// Signals that any outstanding initialization should be canceled and
// flushes the cache to disk.
void ShutDown();
- // Restores the index's private data from the cache file stored in the
- // profile directory and returns true if successful.
- bool RestoreFromCacheFile();
-
// Caches the index private data and writes the cache file to the profile
// directory.
bool SaveToCacheFile();
@@ -105,14 +104,19 @@
ScoredHistoryMatches HistoryItemsForTerms(const String16Vector& terms);
// Updates or adds an history item to the index if it meets the minimum
- // 'quick' criteria.
- void UpdateURL(URLID row_id, const URLRow& row);
+ // selection criteria.
+ void UpdateURL(const URLRow& row);
// Deletes indexing data for an history item. The item may not have actually
// been indexed (which is the case if it did not previously meet minimum
// 'quick' criteria).
- void DeleteURL(URLID row_id);
+ void DeleteURL(const URLRow& row);
+ // Notification callback.
+ virtual void Observe(int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details);
+
private:
friend class AddHistoryMatch;
friend class InMemoryURLIndexTest;
@@ -184,6 +188,16 @@
const String16Vector& lower_terms_;
};
+ // Initialization and Restoration --------------------------------------------
+
+ // Restores the index's private data from the cache, if possible, otherwise
+ // registers to be notified when the history database becomes available.
+ void RestoreFromCache();
+
+ // Restores the index's private data from the cache file stored in the
+ // profile directory and returns true if successful.
+ bool RestoreFromCacheFile();
+
// Initializes all index data members in preparation for restoring the index
// from the cache or a complete rebuild from the history database.
void ClearPrivateData();
@@ -191,7 +205,7 @@
// Initializes the whitelist of URL schemes.
static void InitializeSchemeWhitelist(std::set<std::string>* whitelist);
- // URL History indexing support functions.
+ // URL History Indexing ------------------------------------------------------
// Indexes one URL history item.
void IndexRow(const URLRow& row);
@@ -251,6 +265,11 @@
// Determines if |gurl| has a whitelisted scheme and returns true if so.
bool URLSchemeIsWhitelisted(const GURL& gurl) const;
+ // Notification handlers.
+ void OnURLVisited(const URLVisitedDetails* details);
+ void OnURLsModified(const URLsModifiedDetails* details);
+ void OnURLsDeleted(const URLsDeletedDetails* details);
+
// Utility functions supporting RestoreFromCache and SaveToCache.
// Construct a file path for the cache file within the same directory where
@@ -276,6 +295,11 @@
bool RestoreWordIDHistoryMap(const imui::InMemoryURLIndexCacheItem& cache);
bool RestoreHistoryInfoMap(const imui::InMemoryURLIndexCacheItem& cache);
+ content::NotificationRegistrar registrar_;
+
+ // The profile with which we are associated.
+ Profile* profile_;
+
// Directory where cache file resides. This is, except when unit testing,
// the same directory in which the profile's history database is found. It
// should never be empty.
« 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