| Index: chrome/browser/history/in_memory_url_index.cc
|
| diff --git a/chrome/browser/history/in_memory_url_index.cc b/chrome/browser/history/in_memory_url_index.cc
|
| index bf6ac74ebc5c23cf6ea569940d8d08658b6b1f2e..92fd2290dd58d79af3a7e702d1332a1e5c33beec 100644
|
| --- a/chrome/browser/history/in_memory_url_index.cc
|
| +++ b/chrome/browser/history/in_memory_url_index.cc
|
| @@ -8,9 +8,7 @@
|
| #include "base/files/file_util.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "chrome/browser/history/history_service.h"
|
| -#include "chrome/browser/history/history_service_factory.h"
|
| #include "chrome/browser/history/url_index_private_data.h"
|
| -#include "chrome/browser/profiles/profile.h"
|
| #include "chrome/common/url_constants.h"
|
| #include "components/history/core/browser/url_database.h"
|
| #include "content/public/browser/browser_thread.h"
|
| @@ -81,13 +79,11 @@ InMemoryURLIndex::RebuildPrivateDataFromHistoryDBTask::
|
|
|
| // InMemoryURLIndex ------------------------------------------------------------
|
|
|
| -InMemoryURLIndex::InMemoryURLIndex(Profile* profile,
|
| - HistoryService* history_service,
|
| +InMemoryURLIndex::InMemoryURLIndex(HistoryService* history_service,
|
| const base::FilePath& history_dir,
|
| const std::string& languages,
|
| HistoryClient* history_client)
|
| - : profile_(profile),
|
| - history_service_(history_service),
|
| + : history_service_(history_service),
|
| history_client_(history_client),
|
| history_dir_(history_dir),
|
| languages_(languages),
|
| @@ -96,33 +92,19 @@ InMemoryURLIndex::InMemoryURLIndex(Profile* profile,
|
| save_cache_observer_(NULL),
|
| shutdown_(false),
|
| restored_(false),
|
| - needs_to_be_cached_(false),
|
| - history_service_observer_(this) {
|
| + needs_to_be_cached_(false) {
|
| InitializeSchemeWhitelist(&scheme_whitelist_);
|
| // TODO(mrossetti): Register for language change notifications.
|
| if (history_service_)
|
| - history_service_observer_.Add(history_service_);
|
| -}
|
| -
|
| -// Called only by unit tests.
|
| -InMemoryURLIndex::InMemoryURLIndex()
|
| - : profile_(NULL),
|
| - history_service_(nullptr),
|
| - history_client_(NULL),
|
| - private_data_(new URLIndexPrivateData),
|
| - restore_cache_observer_(NULL),
|
| - save_cache_observer_(NULL),
|
| - shutdown_(false),
|
| - restored_(false),
|
| - needs_to_be_cached_(false),
|
| - history_service_observer_(this) {
|
| - InitializeSchemeWhitelist(&scheme_whitelist_);
|
| + history_service_->AddObserver(this);
|
| }
|
|
|
| InMemoryURLIndex::~InMemoryURLIndex() {
|
| // If there was a history directory (which there won't be for some unit tests)
|
| // then insure that the cache has already been saved.
|
| DCHECK(history_dir_.empty() || !needs_to_be_cached_);
|
| + DCHECK(!history_service_);
|
| + DCHECK(shutdown_);
|
| }
|
|
|
| void InMemoryURLIndex::Init() {
|
| @@ -130,7 +112,10 @@ void InMemoryURLIndex::Init() {
|
| }
|
|
|
| void InMemoryURLIndex::ShutDown() {
|
| - history_service_observer_.RemoveAll();
|
| + if (history_service_) {
|
| + history_service_->RemoveObserver(this);
|
| + history_service_ = nullptr;
|
| + }
|
| cache_reader_tracker_.TryCancelAll();
|
| shutdown_ = true;
|
| base::FilePath path;
|
| @@ -263,7 +248,7 @@ void InMemoryURLIndex::OnCacheLoadDone(
|
| restored_ = true;
|
| if (restore_cache_observer_)
|
| restore_cache_observer_->OnCacheRestoreFinished(true);
|
| - } else if (profile_) {
|
| + } else if (history_service_) {
|
| // When unable to restore from the cache file delete the cache file, if
|
| // it exists, and then rebuild from the history database if it's available,
|
| // otherwise wait until the history database loaded and then rebuild.
|
| @@ -272,15 +257,8 @@ void InMemoryURLIndex::OnCacheLoadDone(
|
| return;
|
| content::BrowserThread::PostBlockingPoolTask(
|
| FROM_HERE, base::Bind(DeleteCacheFile, path));
|
| - HistoryService* service =
|
| - HistoryServiceFactory::GetForProfileWithoutCreating(profile_);
|
| - if (service) {
|
| - if (!service->backend_loaded()) {
|
| - if (!history_service_observer_.IsObserving(service))
|
| - history_service_observer_.Add(service);
|
| - } else {
|
| - ScheduleRebuildFromHistory();
|
| - }
|
| + if (history_service_->backend_loaded()) {
|
| + ScheduleRebuildFromHistory();
|
| }
|
| }
|
| }
|
| @@ -288,9 +266,8 @@ void InMemoryURLIndex::OnCacheLoadDone(
|
| // Restoring from the History DB -----------------------------------------------
|
|
|
| void InMemoryURLIndex::ScheduleRebuildFromHistory() {
|
| - HistoryService* service = HistoryServiceFactory::GetForProfile(
|
| - profile_, ServiceAccessType::EXPLICIT_ACCESS);
|
| - service->ScheduleDBTask(
|
| + DCHECK(history_service_);
|
| + history_service_->ScheduleDBTask(
|
| scoped_ptr<history::HistoryDBTask>(
|
| new InMemoryURLIndex::RebuildPrivateDataFromHistoryDBTask(
|
| this, languages_, scheme_whitelist_)),
|
|
|