Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" | 5 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" |
| 6 | 6 |
| 7 #include "base/threading/sequenced_worker_pool.h" | 7 #include "base/threading/sequenced_worker_pool.h" |
| 8 #include "components/dom_distiller/content/distiller_page_web_contents.h" | 8 #include "components/dom_distiller/content/distiller_page_web_contents.h" |
| 9 #include "components/dom_distiller/core/article_entry.h" | |
| 9 #include "components/dom_distiller/core/distiller.h" | 10 #include "components/dom_distiller/core/distiller.h" |
| 10 #include "components/dom_distiller/core/dom_distiller_store.h" | 11 #include "components/dom_distiller/core/dom_distiller_store.h" |
| 11 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 12 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 13 #include "components/leveldb_proto/core/proto_database.h" | |
| 14 #include "components/leveldb_proto/core/proto_database_impl.h" | |
| 12 #include "content/public/browser/browser_context.h" | 15 #include "content/public/browser/browser_context.h" |
| 13 #include "content/public/browser/browser_thread.h" | 16 #include "content/public/browser/browser_thread.h" |
| 14 | 17 |
| 15 namespace dom_distiller { | 18 namespace dom_distiller { |
| 16 | 19 |
| 17 DomDistillerContextKeyedService::DomDistillerContextKeyedService( | 20 DomDistillerContextKeyedService::DomDistillerContextKeyedService( |
| 18 scoped_ptr<DomDistillerStoreInterface> store, | 21 scoped_ptr<DomDistillerStoreInterface> store, |
| 19 scoped_ptr<DistillerFactory> distiller_factory, | 22 scoped_ptr<DistillerFactory> distiller_factory, |
| 20 scoped_ptr<DistillerPageFactory> distiller_page_factory) | 23 scoped_ptr<DistillerPageFactory> distiller_page_factory) |
| 21 : DomDistillerService(store.Pass(), | 24 : DomDistillerService(store.Pass(), distiller_factory.Pass(), |
|
blundell
2014/06/17 18:13:51
You can TBR jochen or thakis as //chrome OWNERS fo
Mathieu
2014/06/17 18:30:54
Done.
| |
| 22 distiller_factory.Pass(), | 25 distiller_page_factory.Pass()) {} |
| 23 distiller_page_factory.Pass()) { | |
| 24 } | |
| 25 | 26 |
| 26 // static | 27 // static |
| 27 DomDistillerServiceFactory* DomDistillerServiceFactory::GetInstance() { | 28 DomDistillerServiceFactory* DomDistillerServiceFactory::GetInstance() { |
| 28 return Singleton<DomDistillerServiceFactory>::get(); | 29 return Singleton<DomDistillerServiceFactory>::get(); |
| 29 } | 30 } |
| 30 | 31 |
| 31 // static | 32 // static |
| 32 DomDistillerContextKeyedService* | 33 DomDistillerContextKeyedService* |
| 33 DomDistillerServiceFactory::GetForBrowserContext( | 34 DomDistillerServiceFactory::GetForBrowserContext( |
| 34 content::BrowserContext* context) { | 35 content::BrowserContext* context) { |
| 35 return static_cast<DomDistillerContextKeyedService*>( | 36 return static_cast<DomDistillerContextKeyedService*>( |
| 36 GetInstance()->GetServiceForBrowserContext(context, true)); | 37 GetInstance()->GetServiceForBrowserContext(context, true)); |
| 37 } | 38 } |
| 38 | 39 |
| 39 DomDistillerServiceFactory::DomDistillerServiceFactory() | 40 DomDistillerServiceFactory::DomDistillerServiceFactory() |
| 40 : BrowserContextKeyedServiceFactory( | 41 : BrowserContextKeyedServiceFactory( |
| 41 "DomDistillerService", | 42 "DomDistillerService", |
| 42 BrowserContextDependencyManager::GetInstance()) {} | 43 BrowserContextDependencyManager::GetInstance()) {} |
| 43 | 44 |
| 44 DomDistillerServiceFactory::~DomDistillerServiceFactory() {} | 45 DomDistillerServiceFactory::~DomDistillerServiceFactory() {} |
| 45 | 46 |
| 46 KeyedService* DomDistillerServiceFactory::BuildServiceInstanceFor( | 47 KeyedService* DomDistillerServiceFactory::BuildServiceInstanceFor( |
| 47 content::BrowserContext* profile) const { | 48 content::BrowserContext* profile) const { |
| 48 scoped_refptr<base::SequencedTaskRunner> background_task_runner = | 49 scoped_refptr<base::SequencedTaskRunner> background_task_runner = |
| 49 content::BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( | 50 content::BrowserThread::GetBlockingPool()->GetSequencedTaskRunner( |
| 50 content::BrowserThread::GetBlockingPool()->GetSequenceToken()); | 51 content::BrowserThread::GetBlockingPool()->GetSequenceToken()); |
| 51 | 52 |
| 52 scoped_ptr<DomDistillerDatabase> db( | 53 scoped_ptr<leveldb_proto::ProtoDatabaseImpl<ArticleEntry> > db( |
| 53 new DomDistillerDatabase(background_task_runner)); | 54 new leveldb_proto::ProtoDatabaseImpl<ArticleEntry>( |
| 55 background_task_runner)); | |
| 54 | 56 |
| 55 base::FilePath database_dir( | 57 base::FilePath database_dir( |
| 56 profile->GetPath().Append(FILE_PATH_LITERAL("Articles"))); | 58 profile->GetPath().Append(FILE_PATH_LITERAL("Articles"))); |
| 57 | 59 |
| 58 scoped_ptr<DomDistillerStore> dom_distiller_store(new DomDistillerStore( | 60 scoped_ptr<DomDistillerStore> dom_distiller_store(new DomDistillerStore( |
| 59 db.PassAs<DomDistillerDatabaseInterface>(), database_dir)); | 61 db.PassAs<leveldb_proto::ProtoDatabase<ArticleEntry> >(), database_dir)); |
| 60 | 62 |
| 61 scoped_ptr<DistillerPageFactory> distiller_page_factory( | 63 scoped_ptr<DistillerPageFactory> distiller_page_factory( |
| 62 new DistillerPageWebContentsFactory(profile)); | 64 new DistillerPageWebContentsFactory(profile)); |
| 63 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory( | 65 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory( |
| 64 new DistillerURLFetcherFactory(profile->GetRequestContext())); | 66 new DistillerURLFetcherFactory(profile->GetRequestContext())); |
| 65 | 67 |
| 66 dom_distiller::proto::DomDistillerOptions options; | 68 dom_distiller::proto::DomDistillerOptions options; |
| 67 if (VLOG_IS_ON(1)) { | 69 if (VLOG_IS_ON(1)) { |
| 68 options.set_debug_level( | 70 options.set_debug_level(logging::GetVlogLevelHelper( |
| 69 logging::GetVlogLevelHelper(FROM_HERE.file_name(), | 71 FROM_HERE.file_name(), ::strlen(FROM_HERE.file_name()))); |
| 70 ::strlen(FROM_HERE.file_name()))); | |
| 71 } | 72 } |
| 72 scoped_ptr<DistillerFactory> distiller_factory( | 73 scoped_ptr<DistillerFactory> distiller_factory( |
| 73 new DistillerFactoryImpl(distiller_url_fetcher_factory.Pass(), options)); | 74 new DistillerFactoryImpl(distiller_url_fetcher_factory.Pass(), options)); |
| 74 | 75 |
| 75 DomDistillerContextKeyedService* service = | 76 DomDistillerContextKeyedService* service = |
| 76 new DomDistillerContextKeyedService( | 77 new DomDistillerContextKeyedService( |
| 77 dom_distiller_store.PassAs<DomDistillerStoreInterface>(), | 78 dom_distiller_store.PassAs<DomDistillerStoreInterface>(), |
| 78 distiller_factory.Pass(), | 79 distiller_factory.Pass(), distiller_page_factory.Pass()); |
| 79 distiller_page_factory.Pass()); | |
| 80 | 80 |
| 81 return service; | 81 return service; |
| 82 } | 82 } |
| 83 | 83 |
| 84 content::BrowserContext* DomDistillerServiceFactory::GetBrowserContextToUse( | 84 content::BrowserContext* DomDistillerServiceFactory::GetBrowserContextToUse( |
| 85 content::BrowserContext* context) const { | 85 content::BrowserContext* context) const { |
| 86 // TODO(cjhopman): Do we want this to be | 86 // TODO(cjhopman): Do we want this to be |
| 87 // GetBrowserContextRedirectedInIncognito? | 87 // GetBrowserContextRedirectedInIncognito? |
| 88 return context; | 88 return context; |
| 89 } | 89 } |
| 90 | 90 |
| 91 } // namespace dom_distiller | 91 } // namespace dom_distiller |
| OLD | NEW |