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

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

Issue 879763002: Remove dependencies of InMemoryURLIndex on Profile (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@773103004
Patch Set: 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 side-by-side diff with in-line comments
Download patch
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..912281df2c303b6fd5e0f6732ff77a3d1148b8da 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,27 +92,11 @@ 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() {
@@ -130,7 +110,10 @@ void InMemoryURLIndex::Init() {
}
void InMemoryURLIndex::ShutDown() {
- history_service_observer_.RemoveAll();
+ if (history_service_) {
+ history_service_->RemoveObserver(this);
droger 2015/01/27 09:32:32 What happens if ShutDown is never called, is the o
sdefresne 2015/01/27 10:13:56 Yes, the observer would have been leaked. I added
+ history_service_ = nullptr;
+ }
cache_reader_tracker_.TryCancelAll();
shutdown_ = true;
base::FilePath path;
@@ -263,7 +246,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 +255,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 +264,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_)),
« no previous file with comments | « chrome/browser/history/in_memory_url_index.h ('k') | chrome/browser/history/in_memory_url_index_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698