#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "base/strings/string16.h"
-#include "chrome/browser/autocomplete/autocomplete_match.h"
-#include "chrome/browser/autocomplete/history_provider_util.h"
-#include "chrome/browser/common/cancelable_request.h"
+#include "base/task/cancelable_task_tracker.h"
#include "chrome/browser/history/history_db_task.h"
-#include "chrome/browser/history/history_types.h"
#include "chrome/browser/history/in_memory_url_index_types.h"
#include "chrome/browser/history/scored_history_match.h"
+#include "components/history/core/browser/history_service_observer.h"
+#include "components/history/core/browser/history_types.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "sql/connection.h"
+class HistoryService;
class HistoryQuickProviderTest;
class Profile;
namespace imui = in_memory_url_index;
+class HistoryClient;
class HistoryDatabase;
class URLIndexPrivateData;
struct URLsDeletedDetails;
struct URLsModifiedDetails;
-struct URLVisitedDetails;
// The URL history source.
// Holds portions of the URL database in memory in an indexed form. Used to
// 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 : public content::NotificationObserver,
+class InMemoryURLIndex : public HistoryServiceObserver,
+ public content::NotificationObserver,
public base::SupportsWeakPtr<InMemoryURLIndex> {
public:
// Defines an abstract class which is notified upon completion of restoring
// journals will be stored. |languages| gives a list of language encodings by
// which URLs and omnibox searches are broken down into words and characters.
InMemoryURLIndex(Profile* profile,
+ HistoryService* history_service,
const base::FilePath& history_dir,
- const std::string& languages);
- virtual ~InMemoryURLIndex();
+ const std::string& languages,
+ HistoryClient* client);
+ ~InMemoryURLIndex() override;
// Opens and prepares the index of historical URL visits. If the index private
// data cannot be restored from its cache file then it is rebuilt from the
// URLIndexPrivateData class. For a complete description of this function
// refer to that class. If |cursor_position| is base::string16::npos, the
// function doesn't do anything special with the cursor; this is equivalent
- // to the cursor being at the end.
+ // to the cursor being at the end. In total, |max_matches| of items will be
+ // returned in the |ScoredHistoryMatches| vector.
ScoredHistoryMatches HistoryItemsForTerms(const base::string16& term_string,
- size_t cursor_position);
+ size_t cursor_position,
+ size_t max_matches);
// Deletes the index entry, if any, for the given |url|.
void DeleteURL(const GURL& url);
const std::string& languages,
const std::set<std::string>& scheme_whitelist);
- virtual bool RunOnDBThread(HistoryBackend* backend,
- history::HistoryDatabase* db) OVERRIDE;
- virtual void DoneRunOnMainThread() OVERRIDE;
+ bool RunOnDBThread(HistoryBackend* backend,
+ history::HistoryDatabase* db) override;
+ void DoneRunOnMainThread() override;
private:
- virtual ~RebuildPrivateDataFromHistoryDBTask();
+ ~RebuildPrivateDataFromHistoryDBTask() override;
InMemoryURLIndex* index_; // Call back to this index at completion.
std::string languages_; // Languages for word-breaking.
void OnCacheSaveDone(bool succeeded);
// Handles notifications of history changes.
- virtual void Observe(int notification_type,
- const content::NotificationSource& source,
- const content::NotificationDetails& details) OVERRIDE;
+ void Observe(int notification_type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) override;
+
+ // HistoryServiceObserver:
+ void OnURLVisited(HistoryService* history_service,
+ ui::PageTransition transition,
+ const URLRow& row,
+ const RedirectList& redirects,
+ base::Time visit_time) override;
// Notification handlers.
- void OnURLVisited(const URLVisitedDetails* details);
void OnURLsModified(const URLsModifiedDetails* details);
void OnURLsDeleted(const URLsDeletedDetails* details);
// Returns a pointer to our private data. For unit testing only.
URLIndexPrivateData* private_data() { return private_data_.get(); }
+ // Returns a pointer to our private data cancelable request tracker. For
+ // unit testing only.
+ base::CancelableTaskTracker* private_data_tracker() {
+ return &private_data_tracker_;
+ }
+
// Returns the set of whitelisted schemes. For unit testing only.
const std::set<std::string>& scheme_whitelist() { return scheme_whitelist_; }
// The profile, may be null when testing.
Profile* profile_;
+ HistoryService* history_service_;
+
+ // The HistoryClient; may be NULL when testing.
+ HistoryClient* history_client_;
// Directory where cache file resides. This is, except when unit testing,
// the same directory in which the profile's history database is found. It
RestoreCacheObserver* restore_cache_observer_;
SaveCacheObserver* save_cache_observer_;
- CancelableRequestConsumer cache_reader_consumer_;
+ base::CancelableTaskTracker private_data_tracker_;
+ base::CancelableTaskTracker cache_reader_tracker_;
content::NotificationRegistrar registrar_;
// Set to true once the shutdown process has begun.
// to be cached. Set to false when the index has been cached. Used as a
// temporary safety check to insure that the cache is saved before the
// index has been destructed.
- // TODO(mrossetti): Eliminate once the transition to SQLite has been done.
- // http://crbug.com/83659
bool needs_to_be_cached_;
DISALLOW_COPY_AND_ASSIGN(InMemoryURLIndex);