Chromium Code Reviews| 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/ptr_util.h" | |
|
Olivier
2016/12/13 14:29:10
remove
gambard
2016/12/13 16:25:53
Done.
| |
| 12 #include "base/memory/singleton.h" | 13 #include "base/memory/singleton.h" |
| 13 #include "base/threading/sequenced_worker_pool.h" | 14 #include "base/threading/sequenced_worker_pool.h" |
| 14 #include "components/dom_distiller/core/article_entry.h" | 15 #include "components/dom_distiller/core/article_entry.h" |
| 15 #include "components/dom_distiller/core/distiller.h" | 16 #include "components/dom_distiller/core/distiller.h" |
| 16 #include "components/dom_distiller/core/dom_distiller_service.h" | 17 #include "components/dom_distiller/core/dom_distiller_service.h" |
| 17 #include "components/dom_distiller/core/dom_distiller_store.h" | 18 #include "components/dom_distiller/core/dom_distiller_store.h" |
| 18 #include "components/dom_distiller/ios/distiller_page_factory_ios.h" | 19 #include "components/dom_distiller/ios/distiller_page_factory_ios.h" |
| 19 #include "components/keyed_service/core/keyed_service.h" | 20 #include "components/keyed_service/core/keyed_service.h" |
| 20 #include "components/keyed_service/ios/browser_state_dependency_manager.h" | 21 #include "components/keyed_service/ios/browser_state_dependency_manager.h" |
| 21 #include "components/leveldb_proto/proto_database.h" | 22 #include "components/leveldb_proto/proto_database.h" |
| 22 #include "components/leveldb_proto/proto_database_impl.h" | 23 #include "components/leveldb_proto/proto_database_impl.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/web_state_dispatcher_impl.h" | |
| 25 #include "ios/web/public/browser_state.h" | 27 #include "ios/web/public/browser_state.h" |
| 26 #include "ios/web/public/web_thread.h" | 28 #include "ios/web/public/web_thread.h" |
| 27 | 29 |
| 28 namespace { | 30 namespace { |
| 29 // A simple wrapper for DomDistillerService to expose it as a | 31 // A simple wrapper for DomDistillerService to expose it as a |
| 30 // KeyedService. | 32 // KeyedService. |
| 31 class DomDistillerKeyedService | 33 class DomDistillerKeyedService : public KeyedService, |
| 32 : public KeyedService, | 34 public dom_distiller::DomDistillerService { |
| 33 public dom_distiller::DomDistillerService { | |
| 34 public: | 35 public: |
| 35 DomDistillerKeyedService( | 36 DomDistillerKeyedService( |
| 36 std::unique_ptr<dom_distiller::DomDistillerStoreInterface> store, | 37 std::unique_ptr<dom_distiller::DomDistillerStoreInterface> store, |
| 37 std::unique_ptr<dom_distiller::DistillerFactory> distiller_factory, | 38 std::unique_ptr<dom_distiller::DistillerFactory> distiller_factory, |
| 38 std::unique_ptr<dom_distiller::DistillerPageFactory> | 39 std::unique_ptr<dom_distiller::DistillerPageFactory> |
| 39 distiller_page_factory, | 40 distiller_page_factory, |
| 40 std::unique_ptr<dom_distiller::DistilledPagePrefs> distilled_page_prefs) | 41 std::unique_ptr<dom_distiller::DistilledPagePrefs> distilled_page_prefs) |
| 41 : DomDistillerService(std::move(store), | 42 : DomDistillerService(std::move(store), |
| 42 std::move(distiller_factory), | 43 std::move(distiller_factory), |
| 43 std::move(distiller_page_factory), | 44 std::move(distiller_page_factory), |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 58 } | 59 } |
| 59 | 60 |
| 60 // static | 61 // static |
| 61 DomDistillerService* DomDistillerServiceFactory::GetForBrowserState( | 62 DomDistillerService* DomDistillerServiceFactory::GetForBrowserState( |
| 62 ios::ChromeBrowserState* browser_state) { | 63 ios::ChromeBrowserState* browser_state) { |
| 63 return static_cast<DomDistillerKeyedService*>( | 64 return static_cast<DomDistillerKeyedService*>( |
| 64 GetInstance()->GetServiceForBrowserState(browser_state, true)); | 65 GetInstance()->GetServiceForBrowserState(browser_state, true)); |
| 65 } | 66 } |
| 66 | 67 |
| 67 DomDistillerServiceFactory::DomDistillerServiceFactory() | 68 DomDistillerServiceFactory::DomDistillerServiceFactory() |
| 68 : BrowserStateKeyedServiceFactory( | 69 : BrowserStateKeyedServiceFactory( |
|
Olivier
2016/12/13 14:29:10
I think you know need some DependsOn here.
gambard
2016/12/13 16:25:53
Depends on what?
Olivier
2016/12/13 16:31:21
You are calling code that calls FaviconServiceFact
gambard
2016/12/16 10:26:47
Done.
| |
| 69 "DomDistillerService", | 70 "DomDistillerService", |
| 70 BrowserStateDependencyManager::GetInstance()) { | 71 BrowserStateDependencyManager::GetInstance()) {} |
| 71 } | |
| 72 | 72 |
| 73 DomDistillerServiceFactory::~DomDistillerServiceFactory() { | 73 DomDistillerServiceFactory::~DomDistillerServiceFactory() {} |
| 74 } | |
| 75 | 74 |
| 76 std::unique_ptr<KeyedService> | 75 std::unique_ptr<KeyedService> |
| 77 DomDistillerServiceFactory::BuildServiceInstanceFor( | 76 DomDistillerServiceFactory::BuildServiceInstanceFor( |
| 78 web::BrowserState* context) const { | 77 web::BrowserState* context) const { |
| 79 scoped_refptr<base::SequencedTaskRunner> background_task_runner = | 78 scoped_refptr<base::SequencedTaskRunner> background_task_runner = |
| 80 web::WebThread::GetBlockingPool()->GetSequencedTaskRunner( | 79 web::WebThread::GetBlockingPool()->GetSequencedTaskRunner( |
| 81 web::WebThread::GetBlockingPool()->GetSequenceToken()); | 80 web::WebThread::GetBlockingPool()->GetSequenceToken()); |
| 82 | 81 |
| 83 std::unique_ptr<leveldb_proto::ProtoDatabaseImpl<ArticleEntry>> db( | 82 std::unique_ptr<leveldb_proto::ProtoDatabaseImpl<ArticleEntry>> db( |
| 84 new leveldb_proto::ProtoDatabaseImpl<ArticleEntry>( | 83 new leveldb_proto::ProtoDatabaseImpl<ArticleEntry>( |
| 85 background_task_runner)); | 84 background_task_runner)); |
| 86 | 85 |
| 87 base::FilePath database_dir( | 86 base::FilePath database_dir( |
| 88 context->GetStatePath().Append(FILE_PATH_LITERAL("Articles"))); | 87 context->GetStatePath().Append(FILE_PATH_LITERAL("Articles"))); |
| 89 | 88 |
| 90 std::unique_ptr<DomDistillerStore> dom_distiller_store( | 89 std::unique_ptr<DomDistillerStore> dom_distiller_store( |
| 91 new DomDistillerStore(std::move(db), database_dir)); | 90 new DomDistillerStore(std::move(db), database_dir)); |
| 92 | 91 |
| 92 std::unique_ptr<WebStateDispatcher> web_state_dispatcher = | |
| 93 base::MakeUnique<WebStateDispatcherImpl>(context); | |
| 93 std::unique_ptr<DistillerPageFactory> distiller_page_factory( | 94 std::unique_ptr<DistillerPageFactory> distiller_page_factory( |
| 94 new DistillerPageFactoryIOS(context)); | 95 new DistillerPageFactoryIOS(std::move(web_state_dispatcher))); |
| 96 | |
| 95 std::unique_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory( | 97 std::unique_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory( |
| 96 new DistillerURLFetcherFactory(context->GetRequestContext())); | 98 new DistillerURLFetcherFactory(context->GetRequestContext())); |
| 97 | 99 |
| 98 dom_distiller::proto::DomDistillerOptions options; | 100 dom_distiller::proto::DomDistillerOptions options; |
| 99 std::unique_ptr<DistillerFactory> distiller_factory(new DistillerFactoryImpl( | 101 std::unique_ptr<DistillerFactory> distiller_factory(new DistillerFactoryImpl( |
| 100 std::move(distiller_url_fetcher_factory), options)); | 102 std::move(distiller_url_fetcher_factory), options)); |
| 101 std::unique_ptr<DistilledPagePrefs> distilled_page_prefs( | 103 std::unique_ptr<DistilledPagePrefs> distilled_page_prefs( |
| 102 new DistilledPagePrefs( | 104 new DistilledPagePrefs( |
| 103 ios::ChromeBrowserState::FromBrowserState(context)->GetPrefs())); | 105 ios::ChromeBrowserState::FromBrowserState(context)->GetPrefs())); |
| 104 | 106 |
| 105 return base::MakeUnique<DomDistillerKeyedService>( | 107 return base::MakeUnique<DomDistillerKeyedService>( |
| 106 std::move(dom_distiller_store), std::move(distiller_factory), | 108 std::move(dom_distiller_store), std::move(distiller_factory), |
| 107 std::move(distiller_page_factory), std::move(distilled_page_prefs)); | 109 std::move(distiller_page_factory), std::move(distilled_page_prefs)); |
| 108 } | 110 } |
| 109 | 111 |
| 110 web::BrowserState* DomDistillerServiceFactory::GetBrowserStateToUse( | 112 web::BrowserState* DomDistillerServiceFactory::GetBrowserStateToUse( |
| 111 web::BrowserState* context) const { | 113 web::BrowserState* context) const { |
| 112 // Makes normal profile and off-the-record profile use same service instance. | 114 // Makes normal profile and off-the-record profile use same service instance. |
| 113 return GetBrowserStateRedirectedInIncognito(context); | 115 return GetBrowserStateRedirectedInIncognito(context); |
| 114 } | 116 } |
| 115 | 117 |
| 116 } // namespace dom_distiller | 118 } // namespace dom_distiller |
| OLD | NEW |