blob: f361997ec843250eaf8a22bfb179273252d9c1cf [file] [log] [blame]
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/search/suggestions/suggestions_service_factory.h"
#include <memory>
#include <utility>
#include "base/task/post_task.h"
#include "base/time/default_tick_clock.h"
#include "chrome/browser/profiles/incognito_helpers.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/signin/identity_manager_factory.h"
#include "chrome/browser/sync/profile_sync_service_factory.h"
#include "components/keyed_service/content/browser_context_dependency_manager.h"
#include "components/pref_registry/pref_registry_syncable.h"
#include "components/prefs/pref_service.h"
#include "components/signin/public/identity_manager/identity_manager.h"
#include "components/suggestions/blacklist_store.h"
#include "components/suggestions/proto/suggestions.pb.h"
#include "components/suggestions/suggestions_service_impl.h"
#include "components/suggestions/suggestions_store.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/storage_partition.h"
using content::BrowserThread;
namespace suggestions {
// static
SuggestionsService* SuggestionsServiceFactory::GetForProfile(Profile* profile) {
return static_cast<SuggestionsService*>(
GetInstance()->GetServiceForBrowserContext(profile, true));
}
// static
SuggestionsServiceFactory* SuggestionsServiceFactory::GetInstance() {
return base::Singleton<SuggestionsServiceFactory>::get();
}
SuggestionsServiceFactory::SuggestionsServiceFactory()
: BrowserContextKeyedServiceFactory(
"SuggestionsService",
BrowserContextDependencyManager::GetInstance()) {
DependsOn(IdentityManagerFactory::GetInstance());
DependsOn(ProfileSyncServiceFactory::GetInstance());
}
SuggestionsServiceFactory::~SuggestionsServiceFactory() {}
KeyedService* SuggestionsServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* context) const {
Profile* profile = static_cast<Profile*>(context);
signin::IdentityManager* identity_manager =
IdentityManagerFactory::GetForProfile(profile);
syncer::SyncService* sync_service =
ProfileSyncServiceFactory::GetForProfile(profile);
std::unique_ptr<SuggestionsStore> suggestions_store(
new SuggestionsStore(profile->GetPrefs()));
std::unique_ptr<BlacklistStore> blacklist_store(
new BlacklistStore(profile->GetPrefs()));
return new SuggestionsServiceImpl(
identity_manager, sync_service,
content::BrowserContext::GetDefaultStoragePartition(profile)
->GetURLLoaderFactoryForBrowserProcess(),
std::move(suggestions_store), std::move(blacklist_store),
base::DefaultTickClock::GetInstance());
}
void SuggestionsServiceFactory::RegisterProfilePrefs(
user_prefs::PrefRegistrySyncable* registry) {
SuggestionsServiceImpl::RegisterProfilePrefs(registry);
}
} // namespace suggestions