replace OVERRIDE and FINAL with override and final in ash/
[chromium-blink-merge.git] / chrome / browser / dom_distiller / dom_distiller_service_factory.cc
blob4de2b1755b579f70622e5687e305167b072d5673
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 "chrome/browser/profiles/incognito_helpers.h"
9 #include "chrome/browser/profiles/profile.h"
10 #include "components/dom_distiller/content/distiller_page_web_contents.h"
11 #include "components/dom_distiller/core/article_entry.h"
12 #include "components/dom_distiller/core/distiller.h"
13 #include "components/dom_distiller/core/dom_distiller_store.h"
14 #include "components/keyed_service/content/browser_context_dependency_manager.h"
15 #include "components/leveldb_proto/proto_database.h"
16 #include "components/leveldb_proto/proto_database_impl.h"
17 #include "content/public/browser/browser_context.h"
18 #include "content/public/browser/browser_thread.h"
20 namespace dom_distiller {
22 DomDistillerContextKeyedService::DomDistillerContextKeyedService(
23 scoped_ptr<DomDistillerStoreInterface> store,
24 scoped_ptr<DistillerFactory> distiller_factory,
25 scoped_ptr<DistillerPageFactory> distiller_page_factory,
26 scoped_ptr<DistilledPagePrefs> distilled_page_prefs)
27 : DomDistillerService(store.Pass(),
28 distiller_factory.Pass(),
29 distiller_page_factory.Pass(),
30 distilled_page_prefs.Pass()) {
33 // static
34 DomDistillerServiceFactory* DomDistillerServiceFactory::GetInstance() {
35 return Singleton<DomDistillerServiceFactory>::get();
38 // static
39 DomDistillerContextKeyedService*
40 DomDistillerServiceFactory::GetForBrowserContext(
41 content::BrowserContext* context) {
42 return static_cast<DomDistillerContextKeyedService*>(
43 GetInstance()->GetServiceForBrowserContext(context, true));
46 DomDistillerServiceFactory::DomDistillerServiceFactory()
47 : BrowserContextKeyedServiceFactory(
48 "DomDistillerService",
49 BrowserContextDependencyManager::GetInstance()) {}
51 DomDistillerServiceFactory::~DomDistillerServiceFactory() {}
53 KeyedService* DomDistillerServiceFactory::BuildServiceInstanceFor(
54 content::BrowserContext* profile) const {
55 scoped_refptr<base::SequencedTaskRunner> background_task_runner =
56 content::BrowserThread::GetBlockingPool()->GetSequencedTaskRunner(
57 content::BrowserThread::GetBlockingPool()->GetSequenceToken());
59 scoped_ptr<leveldb_proto::ProtoDatabaseImpl<ArticleEntry> > db(
60 new leveldb_proto::ProtoDatabaseImpl<ArticleEntry>(
61 background_task_runner));
63 base::FilePath database_dir(
64 profile->GetPath().Append(FILE_PATH_LITERAL("Articles")));
66 scoped_ptr<DomDistillerStore> dom_distiller_store(new DomDistillerStore(
67 db.PassAs<leveldb_proto::ProtoDatabase<ArticleEntry> >(), database_dir));
69 scoped_ptr<DistillerPageFactory> distiller_page_factory(
70 new DistillerPageWebContentsFactory(profile));
71 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory(
72 new DistillerURLFetcherFactory(profile->GetRequestContext()));
74 dom_distiller::proto::DomDistillerOptions options;
75 if (VLOG_IS_ON(1)) {
76 options.set_debug_level(logging::GetVlogLevelHelper(
77 FROM_HERE.file_name(), ::strlen(FROM_HERE.file_name())));
79 scoped_ptr<DistillerFactory> distiller_factory(
80 new DistillerFactoryImpl(distiller_url_fetcher_factory.Pass(), options));
81 scoped_ptr<DistilledPagePrefs> distilled_page_prefs(
82 new DistilledPagePrefs(Profile::FromBrowserContext(profile)->GetPrefs()));
84 DomDistillerContextKeyedService* service =
85 new DomDistillerContextKeyedService(
86 dom_distiller_store.PassAs<DomDistillerStoreInterface>(),
87 distiller_factory.Pass(),
88 distiller_page_factory.Pass(),
89 distilled_page_prefs.Pass());
91 return service;
94 content::BrowserContext* DomDistillerServiceFactory::GetBrowserContextToUse(
95 content::BrowserContext* context) const {
96 // Makes normal profile and off-the-record profile use same service instance.
97 return chrome::GetBrowserContextRedirectedInIncognito(context);
100 } // namespace dom_distiller