1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chrome/browser/search/suggestions/suggestions_service_factory.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/profiles/incognito_helpers.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chrome/browser/search/suggestions/image_fetcher_impl.h"
12 #include "components/keyed_service/content/browser_context_dependency_manager.h"
13 #include "components/leveldb_proto/proto_database.h"
14 #include "components/leveldb_proto/proto_database_impl.h"
15 #include "components/pref_registry/pref_registry_syncable.h"
16 #include "components/suggestions/blacklist_store.h"
17 #include "components/suggestions/image_fetcher.h"
18 #include "components/suggestions/image_manager.h"
19 #include "components/suggestions/proto/suggestions.pb.h"
20 #include "components/suggestions/suggestions_service.h"
21 #include "components/suggestions/suggestions_store.h"
22 #include "content/public/browser/browser_context.h"
23 #include "content/public/browser/browser_thread.h"
25 using content::BrowserThread
;
27 namespace suggestions
{
30 SuggestionsService
* SuggestionsServiceFactory::GetForProfile(Profile
* profile
) {
31 return static_cast<SuggestionsService
*>(
32 GetInstance()->GetServiceForBrowserContext(profile
, true));
36 SuggestionsServiceFactory
* SuggestionsServiceFactory::GetInstance() {
37 return base::Singleton
<SuggestionsServiceFactory
>::get();
40 SuggestionsServiceFactory::SuggestionsServiceFactory()
41 : BrowserContextKeyedServiceFactory(
43 BrowserContextDependencyManager::GetInstance()) {
47 SuggestionsServiceFactory::~SuggestionsServiceFactory() {}
49 KeyedService
* SuggestionsServiceFactory::BuildServiceInstanceFor(
50 content::BrowserContext
* profile
) const {
51 scoped_refptr
<base::SequencedTaskRunner
> background_task_runner
=
52 BrowserThread::GetBlockingPool()->GetSequencedTaskRunner(
53 BrowserThread::GetBlockingPool()->GetSequenceToken());
55 Profile
* the_profile
= static_cast<Profile
*>(profile
);
56 scoped_ptr
<SuggestionsStore
> suggestions_store(
57 new SuggestionsStore(the_profile
->GetPrefs()));
58 scoped_ptr
<BlacklistStore
> blacklist_store(
59 new BlacklistStore(the_profile
->GetPrefs()));
61 scoped_ptr
<leveldb_proto::ProtoDatabaseImpl
<ImageData
> > db(
62 new leveldb_proto::ProtoDatabaseImpl
<ImageData
>(background_task_runner
));
64 base::FilePath
database_dir(
65 the_profile
->GetPath().Append(FILE_PATH_LITERAL("Thumbnails")));
67 scoped_ptr
<ImageFetcherImpl
> image_fetcher(
68 new ImageFetcherImpl(the_profile
->GetRequestContext()));
69 scoped_ptr
<ImageManager
> thumbnail_manager(
71 image_fetcher
.Pass(), db
.Pass(), database_dir
,
72 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::DB
)));
73 return new SuggestionsService(
74 the_profile
->GetRequestContext(), suggestions_store
.Pass(),
75 thumbnail_manager
.Pass(), blacklist_store
.Pass());
78 void SuggestionsServiceFactory::RegisterProfilePrefs(
79 user_prefs::PrefRegistrySyncable
* registry
) {
80 SuggestionsService::RegisterProfilePrefs(registry
);
83 } // namespace suggestions