| 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 <utility> |
| 8 |
| 7 #include "base/threading/sequenced_worker_pool.h" | 9 #include "base/threading/sequenced_worker_pool.h" |
| 8 #include "chrome/browser/profiles/incognito_helpers.h" | 10 #include "chrome/browser/profiles/incognito_helpers.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 10 #include "components/dom_distiller/content/browser/distiller_page_web_contents.h
" | 12 #include "components/dom_distiller/content/browser/distiller_page_web_contents.h
" |
| 11 #include "components/dom_distiller/core/article_entry.h" | 13 #include "components/dom_distiller/core/article_entry.h" |
| 12 #include "components/dom_distiller/core/distiller.h" | 14 #include "components/dom_distiller/core/distiller.h" |
| 13 #include "components/dom_distiller/core/dom_distiller_store.h" | 15 #include "components/dom_distiller/core/dom_distiller_store.h" |
| 14 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 16 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
| 15 #include "components/leveldb_proto/proto_database.h" | 17 #include "components/leveldb_proto/proto_database.h" |
| 16 #include "components/leveldb_proto/proto_database_impl.h" | 18 #include "components/leveldb_proto/proto_database_impl.h" |
| 17 #include "content/public/browser/browser_context.h" | 19 #include "content/public/browser/browser_context.h" |
| 18 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 19 | 21 |
| 20 namespace dom_distiller { | 22 namespace dom_distiller { |
| 21 | 23 |
| 22 DomDistillerContextKeyedService::DomDistillerContextKeyedService( | 24 DomDistillerContextKeyedService::DomDistillerContextKeyedService( |
| 23 scoped_ptr<DomDistillerStoreInterface> store, | 25 scoped_ptr<DomDistillerStoreInterface> store, |
| 24 scoped_ptr<DistillerFactory> distiller_factory, | 26 scoped_ptr<DistillerFactory> distiller_factory, |
| 25 scoped_ptr<DistillerPageFactory> distiller_page_factory, | 27 scoped_ptr<DistillerPageFactory> distiller_page_factory, |
| 26 scoped_ptr<DistilledPagePrefs> distilled_page_prefs) | 28 scoped_ptr<DistilledPagePrefs> distilled_page_prefs) |
| 27 : DomDistillerService(store.Pass(), | 29 : DomDistillerService(std::move(store), |
| 28 distiller_factory.Pass(), | 30 std::move(distiller_factory), |
| 29 distiller_page_factory.Pass(), | 31 std::move(distiller_page_factory), |
| 30 distilled_page_prefs.Pass()) { | 32 std::move(distilled_page_prefs)) {} |
| 31 } | |
| 32 | 33 |
| 33 // static | 34 // static |
| 34 DomDistillerServiceFactory* DomDistillerServiceFactory::GetInstance() { | 35 DomDistillerServiceFactory* DomDistillerServiceFactory::GetInstance() { |
| 35 return base::Singleton<DomDistillerServiceFactory>::get(); | 36 return base::Singleton<DomDistillerServiceFactory>::get(); |
| 36 } | 37 } |
| 37 | 38 |
| 38 // static | 39 // static |
| 39 DomDistillerContextKeyedService* | 40 DomDistillerContextKeyedService* |
| 40 DomDistillerServiceFactory::GetForBrowserContext( | 41 DomDistillerServiceFactory::GetForBrowserContext( |
| 41 content::BrowserContext* context) { | 42 content::BrowserContext* context) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 57 content::BrowserThread::GetBlockingPool()->GetSequenceToken()); | 58 content::BrowserThread::GetBlockingPool()->GetSequenceToken()); |
| 58 | 59 |
| 59 scoped_ptr<leveldb_proto::ProtoDatabaseImpl<ArticleEntry> > db( | 60 scoped_ptr<leveldb_proto::ProtoDatabaseImpl<ArticleEntry> > db( |
| 60 new leveldb_proto::ProtoDatabaseImpl<ArticleEntry>( | 61 new leveldb_proto::ProtoDatabaseImpl<ArticleEntry>( |
| 61 background_task_runner)); | 62 background_task_runner)); |
| 62 | 63 |
| 63 base::FilePath database_dir( | 64 base::FilePath database_dir( |
| 64 profile->GetPath().Append(FILE_PATH_LITERAL("Articles"))); | 65 profile->GetPath().Append(FILE_PATH_LITERAL("Articles"))); |
| 65 | 66 |
| 66 scoped_ptr<DomDistillerStore> dom_distiller_store( | 67 scoped_ptr<DomDistillerStore> dom_distiller_store( |
| 67 new DomDistillerStore(db.Pass(), database_dir)); | 68 new DomDistillerStore(std::move(db), database_dir)); |
| 68 | 69 |
| 69 scoped_ptr<DistillerPageFactory> distiller_page_factory( | 70 scoped_ptr<DistillerPageFactory> distiller_page_factory( |
| 70 new DistillerPageWebContentsFactory(profile)); | 71 new DistillerPageWebContentsFactory(profile)); |
| 71 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory( | 72 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory( |
| 72 new DistillerURLFetcherFactory(profile->GetRequestContext())); | 73 new DistillerURLFetcherFactory(profile->GetRequestContext())); |
| 73 | 74 |
| 74 dom_distiller::proto::DomDistillerOptions options; | 75 dom_distiller::proto::DomDistillerOptions options; |
| 75 if (VLOG_IS_ON(1)) { | 76 if (VLOG_IS_ON(1)) { |
| 76 options.set_debug_level(logging::GetVlogLevelHelper( | 77 options.set_debug_level(logging::GetVlogLevelHelper( |
| 77 FROM_HERE.file_name(), ::strlen(FROM_HERE.file_name()))); | 78 FROM_HERE.file_name(), ::strlen(FROM_HERE.file_name()))); |
| 78 } | 79 } |
| 79 // Options for pagination algorithm: | 80 // Options for pagination algorithm: |
| 80 // - "next": detect anchors with "next" text | 81 // - "next": detect anchors with "next" text |
| 81 // - "pagenum": detect anchors with numeric page numbers | 82 // - "pagenum": detect anchors with numeric page numbers |
| 82 // Default is "next". | 83 // Default is "next". |
| 83 options.set_pagination_algo("next"); | 84 options.set_pagination_algo("next"); |
| 84 scoped_ptr<DistillerFactory> distiller_factory( | 85 scoped_ptr<DistillerFactory> distiller_factory(new DistillerFactoryImpl( |
| 85 new DistillerFactoryImpl(distiller_url_fetcher_factory.Pass(), options)); | 86 std::move(distiller_url_fetcher_factory), options)); |
| 86 scoped_ptr<DistilledPagePrefs> distilled_page_prefs( | 87 scoped_ptr<DistilledPagePrefs> distilled_page_prefs( |
| 87 new DistilledPagePrefs(Profile::FromBrowserContext(profile)->GetPrefs())); | 88 new DistilledPagePrefs(Profile::FromBrowserContext(profile)->GetPrefs())); |
| 88 | 89 |
| 89 DomDistillerContextKeyedService* service = | 90 DomDistillerContextKeyedService* service = |
| 90 new DomDistillerContextKeyedService(dom_distiller_store.Pass(), | 91 new DomDistillerContextKeyedService( |
| 91 distiller_factory.Pass(), | 92 std::move(dom_distiller_store), std::move(distiller_factory), |
| 92 distiller_page_factory.Pass(), | 93 std::move(distiller_page_factory), std::move(distilled_page_prefs)); |
| 93 distilled_page_prefs.Pass()); | |
| 94 | 94 |
| 95 return service; | 95 return service; |
| 96 } | 96 } |
| 97 | 97 |
| 98 content::BrowserContext* DomDistillerServiceFactory::GetBrowserContextToUse( | 98 content::BrowserContext* DomDistillerServiceFactory::GetBrowserContextToUse( |
| 99 content::BrowserContext* context) const { | 99 content::BrowserContext* context) const { |
| 100 // Makes normal profile and off-the-record profile use same service instance. | 100 // Makes normal profile and off-the-record profile use same service instance. |
| 101 return chrome::GetBrowserContextRedirectedInIncognito(context); | 101 return chrome::GetBrowserContextRedirectedInIncognito(context); |
| 102 } | 102 } |
| 103 | 103 |
| 104 } // namespace dom_distiller | 104 } // namespace dom_distiller |
| OLD | NEW |