[Metrics] Make MetricsStateManager take a callback param to check if UMA is enabled.
[chromium-blink-merge.git] / chrome / browser / dom_distiller / dom_distiller_service_factory.cc
blob035b8f461300c88195208ca40310ef85c8ef5e9a
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/dom_distiller/content/distiller_page_web_contents.h"
9 #include "components/dom_distiller/core/distiller.h"
10 #include "components/dom_distiller/core/dom_distiller_store.h"
11 #include "components/keyed_service/content/browser_context_dependency_manager.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 scoped_ptr<DistillerPageFactory> distiller_page_factory)
21 : DomDistillerService(store.Pass(),
22 distiller_factory.Pass(),
23 distiller_page_factory.Pass()) {
26 // static
27 DomDistillerServiceFactory* DomDistillerServiceFactory::GetInstance() {
28 return Singleton<DomDistillerServiceFactory>::get();
31 // static
32 DomDistillerContextKeyedService*
33 DomDistillerServiceFactory::GetForBrowserContext(
34 content::BrowserContext* context) {
35 return static_cast<DomDistillerContextKeyedService*>(
36 GetInstance()->GetServiceForBrowserContext(context, true));
39 DomDistillerServiceFactory::DomDistillerServiceFactory()
40 : BrowserContextKeyedServiceFactory(
41 "DomDistillerService",
42 BrowserContextDependencyManager::GetInstance()) {}
44 DomDistillerServiceFactory::~DomDistillerServiceFactory() {}
46 KeyedService* DomDistillerServiceFactory::BuildServiceInstanceFor(
47 content::BrowserContext* profile) const {
48 scoped_refptr<base::SequencedTaskRunner> background_task_runner =
49 content::BrowserThread::GetBlockingPool()->GetSequencedTaskRunner(
50 content::BrowserThread::GetBlockingPool()->GetSequenceToken());
52 scoped_ptr<DomDistillerDatabase> db(
53 new DomDistillerDatabase(background_task_runner));
55 base::FilePath database_dir(
56 profile->GetPath().Append(FILE_PATH_LITERAL("Articles")));
58 scoped_ptr<DomDistillerStore> dom_distiller_store(new DomDistillerStore(
59 db.PassAs<DomDistillerDatabaseInterface>(), database_dir));
61 scoped_ptr<DistillerPageFactory> distiller_page_factory(
62 new DistillerPageWebContentsFactory(profile));
63 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory(
64 new DistillerURLFetcherFactory(profile->GetRequestContext()));
65 scoped_ptr<DistillerFactory> distiller_factory(
66 new DistillerFactoryImpl(distiller_url_fetcher_factory.Pass()));
68 DomDistillerContextKeyedService* service =
69 new DomDistillerContextKeyedService(
70 dom_distiller_store.PassAs<DomDistillerStoreInterface>(),
71 distiller_factory.Pass(),
72 distiller_page_factory.Pass());
74 return service;
77 content::BrowserContext* DomDistillerServiceFactory::GetBrowserContextToUse(
78 content::BrowserContext* context) const {
79 // TODO(cjhopman): Do we want this to be
80 // GetBrowserContextRedirectedInIncognito?
81 return context;
84 } // namespace dom_distiller