| 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/browser_state/browser_state_otr_helper.h" | 23 #include "ios/chrome/browser/browser_state/browser_state_otr_helper.h" |
| 24 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 24 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
| 25 #include "ios/chrome/browser/dom_distiller/distiller_favicon.h" |
| 25 #include "ios/web/public/browser_state.h" | 26 #include "ios/web/public/browser_state.h" |
| 26 #include "ios/web/public/web_thread.h" | 27 #include "ios/web/public/web_thread.h" |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| 29 // A simple wrapper for DomDistillerService to expose it as a | 30 // A simple wrapper for DomDistillerService to expose it as a |
| 30 // KeyedService. | 31 // KeyedService. |
| 31 class DomDistillerKeyedService | 32 class DomDistillerKeyedService |
| 32 : public KeyedService, | 33 : public KeyedService, |
| 33 public dom_distiller::DomDistillerService { | 34 public dom_distiller::DomDistillerService { |
| 34 public: | 35 public: |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 std::unique_ptr<leveldb_proto::ProtoDatabaseImpl<ArticleEntry>> db( | 84 std::unique_ptr<leveldb_proto::ProtoDatabaseImpl<ArticleEntry>> db( |
| 84 new leveldb_proto::ProtoDatabaseImpl<ArticleEntry>( | 85 new leveldb_proto::ProtoDatabaseImpl<ArticleEntry>( |
| 85 background_task_runner)); | 86 background_task_runner)); |
| 86 | 87 |
| 87 base::FilePath database_dir( | 88 base::FilePath database_dir( |
| 88 context->GetStatePath().Append(FILE_PATH_LITERAL("Articles"))); | 89 context->GetStatePath().Append(FILE_PATH_LITERAL("Articles"))); |
| 89 | 90 |
| 90 std::unique_ptr<DomDistillerStore> dom_distiller_store( | 91 std::unique_ptr<DomDistillerStore> dom_distiller_store( |
| 91 new DomDistillerStore(std::move(db), database_dir)); | 92 new DomDistillerStore(std::move(db), database_dir)); |
| 92 | 93 |
| 94 DistillerFaviconIOS* distiller_favicon = new DistillerFavicon(context); |
| 95 |
| 93 std::unique_ptr<DistillerPageFactory> distiller_page_factory( | 96 std::unique_ptr<DistillerPageFactory> distiller_page_factory( |
| 94 new DistillerPageFactoryIOS(context)); | 97 new DistillerPageFactoryIOS(context, distiller_favicon)); |
| 95 std::unique_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory( | 98 std::unique_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory( |
| 96 new DistillerURLFetcherFactory(context->GetRequestContext())); | 99 new DistillerURLFetcherFactory(context->GetRequestContext())); |
| 97 | 100 |
| 98 dom_distiller::proto::DomDistillerOptions options; | 101 dom_distiller::proto::DomDistillerOptions options; |
| 99 std::unique_ptr<DistillerFactory> distiller_factory(new DistillerFactoryImpl( | 102 std::unique_ptr<DistillerFactory> distiller_factory(new DistillerFactoryImpl( |
| 100 std::move(distiller_url_fetcher_factory), options)); | 103 std::move(distiller_url_fetcher_factory), options)); |
| 101 std::unique_ptr<DistilledPagePrefs> distilled_page_prefs( | 104 std::unique_ptr<DistilledPagePrefs> distilled_page_prefs( |
| 102 new DistilledPagePrefs( | 105 new DistilledPagePrefs( |
| 103 ios::ChromeBrowserState::FromBrowserState(context)->GetPrefs())); | 106 ios::ChromeBrowserState::FromBrowserState(context)->GetPrefs())); |
| 104 | 107 |
| 105 return base::MakeUnique<DomDistillerKeyedService>( | 108 return base::MakeUnique<DomDistillerKeyedService>( |
| 106 std::move(dom_distiller_store), std::move(distiller_factory), | 109 std::move(dom_distiller_store), std::move(distiller_factory), |
| 107 std::move(distiller_page_factory), std::move(distilled_page_prefs)); | 110 std::move(distiller_page_factory), std::move(distilled_page_prefs)); |
| 108 } | 111 } |
| 109 | 112 |
| 110 web::BrowserState* DomDistillerServiceFactory::GetBrowserStateToUse( | 113 web::BrowserState* DomDistillerServiceFactory::GetBrowserStateToUse( |
| 111 web::BrowserState* context) const { | 114 web::BrowserState* context) const { |
| 112 // Makes normal profile and off-the-record profile use same service instance. | 115 // Makes normal profile and off-the-record profile use same service instance. |
| 113 return GetBrowserStateRedirectedInIncognito(context); | 116 return GetBrowserStateRedirectedInIncognito(context); |
| 114 } | 117 } |
| 115 | 118 |
| 116 } // namespace dom_distiller | 119 } // namespace dom_distiller |
| OLD | NEW |