This source file includes following definitions.
- GetForProfile
- GetForProfileIfExists
- GetForProfileWithoutCreating
- GetInstance
- ShutdownForProfile
- BuildServiceInstanceFor
- GetBrowserContextToUse
- ServiceIsNULLWhileTesting
#include "chrome/browser/history/history_service_factory.h"
#include "base/prefs/pref_service.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/history/history_service.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/common/pref_names.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
HistoryService* HistoryServiceFactory::GetForProfile(
Profile* profile, Profile::ServiceAccessType sat) {
if (profile->GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled) &&
sat != Profile::EXPLICIT_ACCESS)
return NULL;
return static_cast<HistoryService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
HistoryService*
HistoryServiceFactory::GetForProfileIfExists(
Profile* profile, Profile::ServiceAccessType sat) {
if (profile->GetPrefs()->GetBoolean(prefs::kSavingBrowserHistoryDisabled) &&
sat != Profile::EXPLICIT_ACCESS)
return NULL;
return static_cast<HistoryService*>(
GetInstance()->GetServiceForBrowserContext(profile, false));
}
HistoryService*
HistoryServiceFactory::GetForProfileWithoutCreating(Profile* profile) {
return static_cast<HistoryService*>(
GetInstance()->GetServiceForBrowserContext(profile, false));
}
HistoryServiceFactory* HistoryServiceFactory::GetInstance() {
return Singleton<HistoryServiceFactory>::get();
}
void HistoryServiceFactory::ShutdownForProfile(Profile* profile) {
HistoryServiceFactory* factory = GetInstance();
factory->BrowserContextDestroyed(profile);
}
HistoryServiceFactory::HistoryServiceFactory()
: BrowserContextKeyedServiceFactory(
"HistoryService", BrowserContextDependencyManager::GetInstance()) {
DependsOn(BookmarkModelFactory::GetInstance());
}
HistoryServiceFactory::~HistoryServiceFactory() {
}
KeyedService* HistoryServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
Profile* profile = static_cast<Profile*>(context);
HistoryService* history_service = new HistoryService(profile);
if (!history_service->Init(profile->GetPath(),
BookmarkModelFactory::GetForProfile(profile))) {
return NULL;
}
return history_service;
}
content::BrowserContext* HistoryServiceFactory::GetBrowserContextToUse(
content::BrowserContext* context) const {
return chrome::GetBrowserContextRedirectedInIncognito(context);
}
bool HistoryServiceFactory::ServiceIsNULLWhileTesting() const {
return true;
}