| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ios/chrome/browser/dom_distiller/dom_distiller_service_factory.h" | 5 #include "ios/chrome/browser/dom_distiller/dom_distiller_service_factory.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/files/file_path.h" | 9 #include "base/files/file_path.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/memory/ptr_util.h" | 11 #include "base/memory/ptr_util.h" |
| 12 #include "base/memory/singleton.h" | 12 #include "base/memory/singleton.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
| 14 #include "components/dom_distiller/core/article_entry.h" | 14 #include "components/dom_distiller/core/article_entry.h" |
| 15 #include "components/dom_distiller/core/distiller.h" | 15 #include "components/dom_distiller/core/distiller.h" |
| 16 #include "components/dom_distiller/core/dom_distiller_service.h" | 16 #include "components/dom_distiller/core/dom_distiller_service.h" |
| 17 #include "components/dom_distiller/core/dom_distiller_store.h" | 17 #include "components/dom_distiller/core/dom_distiller_store.h" |
| 18 #include "components/dom_distiller/ios/distiller_page_factory_ios.h" | 18 #include "components/dom_distiller/ios/distiller_page_factory_ios.h" |
| 19 #include "components/keyed_service/core/keyed_service.h" | 19 #include "components/keyed_service/core/keyed_service.h" |
| 20 #include "components/keyed_service/ios/browser_state_dependency_manager.h" | 20 #include "components/keyed_service/ios/browser_state_dependency_manager.h" |
| 21 #include "components/leveldb_proto/proto_database.h" | 21 #include "components/leveldb_proto/proto_database.h" |
| 22 #include "components/leveldb_proto/proto_database_impl.h" | 22 #include "components/leveldb_proto/proto_database_impl.h" |
| 23 #include "ios/chrome/browser/bookmarks/bookmark_model_factory.h" |
| 23 #include "ios/chrome/browser/browser_state/browser_state_otr_helper.h" | 24 #include "ios/chrome/browser/browser_state/browser_state_otr_helper.h" |
| 24 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 25 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 26 #include "ios/chrome/browser/dom_distiller/favicon_web_state_dispatcher_impl.h" |
| 27 #include "ios/chrome/browser/favicon/favicon_service_factory.h" |
| 28 #include "ios/chrome/browser/history/history_service_factory.h" |
| 25 #include "ios/web/public/browser_state.h" | 29 #include "ios/web/public/browser_state.h" |
| 26 #include "ios/web/public/web_thread.h" | 30 #include "ios/web/public/web_thread.h" |
| 27 | 31 |
| 28 namespace { | 32 namespace { |
| 29 // A simple wrapper for DomDistillerService to expose it as a | 33 // A simple wrapper for DomDistillerService to expose it as a |
| 30 // KeyedService. | 34 // KeyedService. |
| 31 class DomDistillerKeyedService | 35 class DomDistillerKeyedService : public KeyedService, |
| 32 : public KeyedService, | 36 public dom_distiller::DomDistillerService { |
| 33 public dom_distiller::DomDistillerService { | |
| 34 public: | 37 public: |
| 35 DomDistillerKeyedService( | 38 DomDistillerKeyedService( |
| 36 std::unique_ptr<dom_distiller::DomDistillerStoreInterface> store, | 39 std::unique_ptr<dom_distiller::DomDistillerStoreInterface> store, |
| 37 std::unique_ptr<dom_distiller::DistillerFactory> distiller_factory, | 40 std::unique_ptr<dom_distiller::DistillerFactory> distiller_factory, |
| 38 std::unique_ptr<dom_distiller::DistillerPageFactory> | 41 std::unique_ptr<dom_distiller::DistillerPageFactory> |
| 39 distiller_page_factory, | 42 distiller_page_factory, |
| 40 std::unique_ptr<dom_distiller::DistilledPagePrefs> distilled_page_prefs) | 43 std::unique_ptr<dom_distiller::DistilledPagePrefs> distilled_page_prefs) |
| 41 : DomDistillerService(std::move(store), | 44 : DomDistillerService(std::move(store), |
| 42 std::move(distiller_factory), | 45 std::move(distiller_factory), |
| 43 std::move(distiller_page_factory), | 46 std::move(distiller_page_factory), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 61 DomDistillerService* DomDistillerServiceFactory::GetForBrowserState( | 64 DomDistillerService* DomDistillerServiceFactory::GetForBrowserState( |
| 62 ios::ChromeBrowserState* browser_state) { | 65 ios::ChromeBrowserState* browser_state) { |
| 63 return static_cast<DomDistillerKeyedService*>( | 66 return static_cast<DomDistillerKeyedService*>( |
| 64 GetInstance()->GetServiceForBrowserState(browser_state, true)); | 67 GetInstance()->GetServiceForBrowserState(browser_state, true)); |
| 65 } | 68 } |
| 66 | 69 |
| 67 DomDistillerServiceFactory::DomDistillerServiceFactory() | 70 DomDistillerServiceFactory::DomDistillerServiceFactory() |
| 68 : BrowserStateKeyedServiceFactory( | 71 : BrowserStateKeyedServiceFactory( |
| 69 "DomDistillerService", | 72 "DomDistillerService", |
| 70 BrowserStateDependencyManager::GetInstance()) { | 73 BrowserStateDependencyManager::GetInstance()) { |
| 74 DependsOn(ios::FaviconServiceFactory::GetInstance()); |
| 75 DependsOn(ios::HistoryServiceFactory::GetInstance()); |
| 76 DependsOn(ios::BookmarkModelFactory::GetInstance()); |
| 71 } | 77 } |
| 72 | 78 |
| 73 DomDistillerServiceFactory::~DomDistillerServiceFactory() { | 79 DomDistillerServiceFactory::~DomDistillerServiceFactory() {} |
| 74 } | |
| 75 | 80 |
| 76 std::unique_ptr<KeyedService> | 81 std::unique_ptr<KeyedService> |
| 77 DomDistillerServiceFactory::BuildServiceInstanceFor( | 82 DomDistillerServiceFactory::BuildServiceInstanceFor( |
| 78 web::BrowserState* context) const { | 83 web::BrowserState* context) const { |
| 79 scoped_refptr<base::SequencedTaskRunner> background_task_runner = | 84 scoped_refptr<base::SequencedTaskRunner> background_task_runner = |
| 80 web::WebThread::GetBlockingPool()->GetSequencedTaskRunner( | 85 web::WebThread::GetBlockingPool()->GetSequencedTaskRunner( |
| 81 web::WebThread::GetBlockingPool()->GetSequenceToken()); | 86 web::WebThread::GetBlockingPool()->GetSequenceToken()); |
| 82 | 87 |
| 83 std::unique_ptr<leveldb_proto::ProtoDatabaseImpl<ArticleEntry>> db( | 88 std::unique_ptr<leveldb_proto::ProtoDatabaseImpl<ArticleEntry>> db( |
| 84 new leveldb_proto::ProtoDatabaseImpl<ArticleEntry>( | 89 new leveldb_proto::ProtoDatabaseImpl<ArticleEntry>( |
| 85 background_task_runner)); | 90 background_task_runner)); |
| 86 | 91 |
| 87 base::FilePath database_dir( | 92 base::FilePath database_dir( |
| 88 context->GetStatePath().Append(FILE_PATH_LITERAL("Articles"))); | 93 context->GetStatePath().Append(FILE_PATH_LITERAL("Articles"))); |
| 89 | 94 |
| 90 std::unique_ptr<DomDistillerStore> dom_distiller_store( | 95 std::unique_ptr<DomDistillerStore> dom_distiller_store( |
| 91 new DomDistillerStore(std::move(db), database_dir)); | 96 new DomDistillerStore(std::move(db), database_dir)); |
| 92 | 97 |
| 98 std::unique_ptr<FaviconWebStateDispatcher> web_state_dispatcher = |
| 99 base::MakeUnique<FaviconWebStateDispatcherImpl>(context); |
| 93 std::unique_ptr<DistillerPageFactory> distiller_page_factory( | 100 std::unique_ptr<DistillerPageFactory> distiller_page_factory( |
| 94 new DistillerPageFactoryIOS(context)); | 101 new DistillerPageFactoryIOS(std::move(web_state_dispatcher))); |
| 102 |
| 95 std::unique_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory( | 103 std::unique_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory( |
| 96 new DistillerURLFetcherFactory(context->GetRequestContext())); | 104 new DistillerURLFetcherFactory(context->GetRequestContext())); |
| 97 | 105 |
| 98 dom_distiller::proto::DomDistillerOptions options; | 106 dom_distiller::proto::DomDistillerOptions options; |
| 99 std::unique_ptr<DistillerFactory> distiller_factory(new DistillerFactoryImpl( | 107 std::unique_ptr<DistillerFactory> distiller_factory(new DistillerFactoryImpl( |
| 100 std::move(distiller_url_fetcher_factory), options)); | 108 std::move(distiller_url_fetcher_factory), options)); |
| 101 std::unique_ptr<DistilledPagePrefs> distilled_page_prefs( | 109 std::unique_ptr<DistilledPagePrefs> distilled_page_prefs( |
| 102 new DistilledPagePrefs( | 110 new DistilledPagePrefs( |
| 103 ios::ChromeBrowserState::FromBrowserState(context)->GetPrefs())); | 111 ios::ChromeBrowserState::FromBrowserState(context)->GetPrefs())); |
| 104 | 112 |
| 105 return base::MakeUnique<DomDistillerKeyedService>( | 113 return base::MakeUnique<DomDistillerKeyedService>( |
| 106 std::move(dom_distiller_store), std::move(distiller_factory), | 114 std::move(dom_distiller_store), std::move(distiller_factory), |
| 107 std::move(distiller_page_factory), std::move(distilled_page_prefs)); | 115 std::move(distiller_page_factory), std::move(distilled_page_prefs)); |
| 108 } | 116 } |
| 109 | 117 |
| 110 web::BrowserState* DomDistillerServiceFactory::GetBrowserStateToUse( | 118 web::BrowserState* DomDistillerServiceFactory::GetBrowserStateToUse( |
| 111 web::BrowserState* context) const { | 119 web::BrowserState* context) const { |
| 112 // Makes normal profile and off-the-record profile use same service instance. | 120 // Makes normal profile and off-the-record profile use same service instance. |
| 113 return GetBrowserStateRedirectedInIncognito(context); | 121 return GetBrowserStateRedirectedInIncognito(context); |
| 114 } | 122 } |
| 115 | 123 |
| 116 } // namespace dom_distiller | 124 } // namespace dom_distiller |
| OLD | NEW |