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 base::MakeUnique<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 base::MakeUnique<DomDistillerStore>(std::move(db), database_dir); |
92 | 97 |
93 std::unique_ptr<DistillerPageFactory> distiller_page_factory( | 98 std::unique_ptr<FaviconWebStateDispatcher> web_state_dispatcher = |
94 new DistillerPageFactoryIOS(context)); | 99 base::MakeUnique<FaviconWebStateDispatcherImpl>(context); |
95 std::unique_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory( | 100 std::unique_ptr<DistillerPageFactory> distiller_page_factory = |
96 new DistillerURLFetcherFactory(context->GetRequestContext())); | 101 base::MakeUnique<DistillerPageFactoryIOS>( |
| 102 std::move(web_state_dispatcher)); |
| 103 |
| 104 std::unique_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory = |
| 105 base::MakeUnique<DistillerURLFetcherFactory>( |
| 106 context->GetRequestContext()); |
97 | 107 |
98 dom_distiller::proto::DomDistillerOptions options; | 108 dom_distiller::proto::DomDistillerOptions options; |
99 std::unique_ptr<DistillerFactory> distiller_factory(new DistillerFactoryImpl( | 109 std::unique_ptr<DistillerFactory> distiller_factory = |
100 std::move(distiller_url_fetcher_factory), options)); | 110 base::MakeUnique<DistillerFactoryImpl>( |
101 std::unique_ptr<DistilledPagePrefs> distilled_page_prefs( | 111 std::move(distiller_url_fetcher_factory), options); |
102 new DistilledPagePrefs( | 112 std::unique_ptr<DistilledPagePrefs> distilled_page_prefs = |
103 ios::ChromeBrowserState::FromBrowserState(context)->GetPrefs())); | 113 base::MakeUnique<DistilledPagePrefs>( |
| 114 ios::ChromeBrowserState::FromBrowserState(context)->GetPrefs()); |
104 | 115 |
105 return base::MakeUnique<DomDistillerKeyedService>( | 116 return base::MakeUnique<DomDistillerKeyedService>( |
106 std::move(dom_distiller_store), std::move(distiller_factory), | 117 std::move(dom_distiller_store), std::move(distiller_factory), |
107 std::move(distiller_page_factory), std::move(distilled_page_prefs)); | 118 std::move(distiller_page_factory), std::move(distilled_page_prefs)); |
108 } | 119 } |
109 | 120 |
110 web::BrowserState* DomDistillerServiceFactory::GetBrowserStateToUse( | 121 web::BrowserState* DomDistillerServiceFactory::GetBrowserStateToUse( |
111 web::BrowserState* context) const { | 122 web::BrowserState* context) const { |
112 // Makes normal profile and off-the-record profile use same service instance. | 123 // Makes normal profile and off-the-record profile use same service instance. |
113 return GetBrowserStateRedirectedInIncognito(context); | 124 return GetBrowserStateRedirectedInIncognito(context); |
114 } | 125 } |
115 | 126 |
116 } // namespace dom_distiller | 127 } // namespace dom_distiller |
OLD | NEW |