OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "components/dom_distiller/content/dom_distiller_service_factory.h" | |
6 | |
7 #include "base/threading/sequenced_worker_pool.h" | |
8 #include "components/browser_context_keyed_service/browser_context_dependency_ma
nager.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" | |
14 | |
15 namespace dom_distiller { | |
16 | |
17 DomDistillerContextKeyedService::DomDistillerContextKeyedService( | |
18 scoped_ptr<DomDistillerStoreInterface> store, | |
19 scoped_ptr<DistillerFactory> distiller_factory) | |
20 : DomDistillerService(store.Pass(), distiller_factory.Pass()) {} | |
21 | |
22 // static | |
23 DomDistillerServiceFactory* DomDistillerServiceFactory::GetInstance() { | |
24 return Singleton<DomDistillerServiceFactory>::get(); | |
25 } | |
26 | |
27 // static | |
28 DomDistillerContextKeyedService* | |
29 DomDistillerServiceFactory::GetForBrowserContext( | |
30 content::BrowserContext* context) { | |
31 return static_cast<DomDistillerContextKeyedService*>( | |
32 GetInstance()->GetServiceForBrowserContext(context, true)); | |
33 } | |
34 | |
35 DomDistillerServiceFactory::DomDistillerServiceFactory() | |
36 : BrowserContextKeyedServiceFactory( | |
37 "DomDistillerService", | |
38 BrowserContextDependencyManager::GetInstance()) {} | |
39 | |
40 DomDistillerServiceFactory::~DomDistillerServiceFactory() {} | |
41 | |
42 BrowserContextKeyedService* DomDistillerServiceFactory::BuildServiceInstanceFor( | |
43 content::BrowserContext* profile) const { | |
44 | |
45 scoped_refptr<base::SequencedTaskRunner> background_task_runner = | |
46 content::BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( | |
47 content::BrowserThread::GetBlockingPool()->GetSequenceToken()); | |
48 | |
49 scoped_ptr<DomDistillerDatabase> db( | |
50 new DomDistillerDatabase(background_task_runner)); | |
51 | |
52 base::FilePath database_dir( | |
53 profile->GetPath().Append(FILE_PATH_LITERAL("Articles"))); | |
54 | |
55 scoped_ptr<DomDistillerStore> dom_distiller_store( | |
56 new DomDistillerStore(db.PassAs<DomDistillerDatabaseInterface>(), | |
57 database_dir)); | |
58 | |
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()); | |
69 | |
70 } | |
71 | |
72 content::BrowserContext* DomDistillerServiceFactory::GetBrowserContextToUse( | |
73 content::BrowserContext* context) const { | |
74 // TODO(cjhopman): Do we want this to be | |
75 // GetBrowserContextRedirectedInIncognito? If so, find some way to use that in | |
76 // components/. | |
77 return context; | |
78 } | |
79 | |
80 } // namespace apps | |
OLD | NEW |