1 // Copyright 2013 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/dom_distiller/dom_distiller_service_factory.h"
7 #include "base/threading/sequenced_worker_pool.h"
8 #include "components/browser_context_keyed_service/browser_context_dependency_manager.h"
9 #include "components/dom_distiller/content/distiller_page_web_contents.h"
10 #include "components/dom_distiller/core/distiller.h"
11 #include "components/dom_distiller/core/dom_distiller_store.h"
12 #include "content/public/browser/browser_context.h"
13 #include "content/public/browser/browser_thread.h"
15 namespace dom_distiller
{
17 DomDistillerContextKeyedService::DomDistillerContextKeyedService(
18 scoped_ptr
<DomDistillerStoreInterface
> store
,
19 scoped_ptr
<DistillerFactory
> distiller_factory
)
20 : DomDistillerService(store
.Pass(), distiller_factory
.Pass()) {}
23 DomDistillerServiceFactory
* DomDistillerServiceFactory::GetInstance() {
24 return Singleton
<DomDistillerServiceFactory
>::get();
28 DomDistillerContextKeyedService
*
29 DomDistillerServiceFactory::GetForBrowserContext(
30 content::BrowserContext
* context
) {
31 return static_cast<DomDistillerContextKeyedService
*>(
32 GetInstance()->GetServiceForBrowserContext(context
, true));
35 DomDistillerServiceFactory::DomDistillerServiceFactory()
36 : BrowserContextKeyedServiceFactory(
37 "DomDistillerService",
38 BrowserContextDependencyManager::GetInstance()) {}
40 DomDistillerServiceFactory::~DomDistillerServiceFactory() {}
42 BrowserContextKeyedService
* DomDistillerServiceFactory::BuildServiceInstanceFor(
43 content::BrowserContext
* profile
) const {
45 scoped_refptr
<base::SequencedTaskRunner
> background_task_runner
=
46 content::BrowserThread::GetBlockingPool()->GetSequencedTaskRunner(
47 content::BrowserThread::GetBlockingPool()->GetSequenceToken());
49 scoped_ptr
<DomDistillerDatabase
> db(
50 new DomDistillerDatabase(background_task_runner
));
52 base::FilePath
database_dir(
53 profile
->GetPath().Append(FILE_PATH_LITERAL("Articles")));
55 scoped_ptr
<DomDistillerStore
> dom_distiller_store(
56 new DomDistillerStore(db
.PassAs
<DomDistillerDatabaseInterface
>(),
59 scoped_ptr
<DistillerPageFactory
> distiller_page_factory(
60 new DistillerPageWebContentsFactory(profile
));
61 scoped_ptr
<DistillerURLFetcherFactory
> distiller_url_fetcher_factory(
62 new DistillerURLFetcherFactory(profile
->GetRequestContext()));
63 scoped_ptr
<DistillerFactory
> distiller_factory(
64 new DistillerFactoryImpl(distiller_page_factory
.Pass(),
65 distiller_url_fetcher_factory
.Pass()));
66 return new DomDistillerContextKeyedService(
67 dom_distiller_store
.PassAs
<DomDistillerStoreInterface
>(),
68 distiller_factory
.Pass());
72 content::BrowserContext
* DomDistillerServiceFactory::GetBrowserContextToUse(
73 content::BrowserContext
* context
) const {
74 // TODO(cjhopman): Do we want this to be
75 // GetBrowserContextRedirectedInIncognito?
79 } // namespace dom_distiller