Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(989)

Side by Side Diff: ios/chrome/browser/dom_distiller/dom_distiller_service_factory.cc

Issue 2604773002: Create distiller files for Reading List. (Closed)
Patch Set: feedback Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
24 #include "ios/chrome/browser/browser_state/browser_state_otr_helper.h" 23 #include "ios/chrome/browser/browser_state/browser_state_otr_helper.h"
25 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" 24 #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"
29 #include "ios/web/public/browser_state.h" 25 #include "ios/web/public/browser_state.h"
30 #include "ios/web/public/web_thread.h" 26 #include "ios/web/public/web_thread.h"
31 27
32 namespace { 28 namespace {
33 // A simple wrapper for DomDistillerService to expose it as a 29 // A simple wrapper for DomDistillerService to expose it as a
34 // KeyedService. 30 // KeyedService.
35 class DomDistillerKeyedService : public KeyedService, 31 class DomDistillerKeyedService : public KeyedService,
36 public dom_distiller::DomDistillerService { 32 public dom_distiller::DomDistillerService {
37 public: 33 public:
38 DomDistillerKeyedService( 34 DomDistillerKeyedService(
(...skipping 25 matching lines...) Expand all
64 DomDistillerService* DomDistillerServiceFactory::GetForBrowserState( 60 DomDistillerService* DomDistillerServiceFactory::GetForBrowserState(
65 ios::ChromeBrowserState* browser_state) { 61 ios::ChromeBrowserState* browser_state) {
66 return static_cast<DomDistillerKeyedService*>( 62 return static_cast<DomDistillerKeyedService*>(
67 GetInstance()->GetServiceForBrowserState(browser_state, true)); 63 GetInstance()->GetServiceForBrowserState(browser_state, true));
68 } 64 }
69 65
70 DomDistillerServiceFactory::DomDistillerServiceFactory() 66 DomDistillerServiceFactory::DomDistillerServiceFactory()
71 : BrowserStateKeyedServiceFactory( 67 : BrowserStateKeyedServiceFactory(
72 "DomDistillerService", 68 "DomDistillerService",
73 BrowserStateDependencyManager::GetInstance()) { 69 BrowserStateDependencyManager::GetInstance()) {
74 DependsOn(ios::FaviconServiceFactory::GetInstance());
75 DependsOn(ios::HistoryServiceFactory::GetInstance());
76 DependsOn(ios::BookmarkModelFactory::GetInstance());
77 } 70 }
78 71
79 DomDistillerServiceFactory::~DomDistillerServiceFactory() {} 72 DomDistillerServiceFactory::~DomDistillerServiceFactory() {}
80 73
81 std::unique_ptr<KeyedService> 74 std::unique_ptr<KeyedService>
82 DomDistillerServiceFactory::BuildServiceInstanceFor( 75 DomDistillerServiceFactory::BuildServiceInstanceFor(
83 web::BrowserState* context) const { 76 web::BrowserState* context) const {
84 scoped_refptr<base::SequencedTaskRunner> background_task_runner = 77 scoped_refptr<base::SequencedTaskRunner> background_task_runner =
85 web::WebThread::GetBlockingPool()->GetSequencedTaskRunner( 78 web::WebThread::GetBlockingPool()->GetSequencedTaskRunner(
86 web::WebThread::GetBlockingPool()->GetSequenceToken()); 79 web::WebThread::GetBlockingPool()->GetSequenceToken());
87 80
88 std::unique_ptr<leveldb_proto::ProtoDatabaseImpl<ArticleEntry>> db = 81 std::unique_ptr<leveldb_proto::ProtoDatabaseImpl<ArticleEntry>> db =
89 base::MakeUnique<leveldb_proto::ProtoDatabaseImpl<ArticleEntry>>( 82 base::MakeUnique<leveldb_proto::ProtoDatabaseImpl<ArticleEntry>>(
90 background_task_runner); 83 background_task_runner);
91 84
92 base::FilePath database_dir( 85 base::FilePath database_dir(
93 context->GetStatePath().Append(FILE_PATH_LITERAL("Articles"))); 86 context->GetStatePath().Append(FILE_PATH_LITERAL("Articles")));
94 87
95 std::unique_ptr<DomDistillerStore> dom_distiller_store = 88 std::unique_ptr<DomDistillerStore> dom_distiller_store =
96 base::MakeUnique<DomDistillerStore>(std::move(db), database_dir); 89 base::MakeUnique<DomDistillerStore>(std::move(db), database_dir);
97 90
98 std::unique_ptr<FaviconWebStateDispatcher> web_state_dispatcher =
99 base::MakeUnique<FaviconWebStateDispatcherImpl>(context, -1);
100 std::unique_ptr<DistillerPageFactory> distiller_page_factory = 91 std::unique_ptr<DistillerPageFactory> distiller_page_factory =
101 base::MakeUnique<DistillerPageFactoryIOS>( 92 base::MakeUnique<DistillerPageFactoryIOS>(context);
102 std::move(web_state_dispatcher));
103 93
104 std::unique_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory = 94 std::unique_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory =
105 base::MakeUnique<DistillerURLFetcherFactory>( 95 base::MakeUnique<DistillerURLFetcherFactory>(
106 context->GetRequestContext()); 96 context->GetRequestContext());
107 97
108 dom_distiller::proto::DomDistillerOptions options; 98 dom_distiller::proto::DomDistillerOptions options;
109 std::unique_ptr<DistillerFactory> distiller_factory = 99 std::unique_ptr<DistillerFactory> distiller_factory =
110 base::MakeUnique<DistillerFactoryImpl>( 100 base::MakeUnique<DistillerFactoryImpl>(
111 std::move(distiller_url_fetcher_factory), options); 101 std::move(distiller_url_fetcher_factory), options);
112 std::unique_ptr<DistilledPagePrefs> distilled_page_prefs = 102 std::unique_ptr<DistilledPagePrefs> distilled_page_prefs =
113 base::MakeUnique<DistilledPagePrefs>( 103 base::MakeUnique<DistilledPagePrefs>(
114 ios::ChromeBrowserState::FromBrowserState(context)->GetPrefs()); 104 ios::ChromeBrowserState::FromBrowserState(context)->GetPrefs());
115 105
116 return base::MakeUnique<DomDistillerKeyedService>( 106 return base::MakeUnique<DomDistillerKeyedService>(
117 std::move(dom_distiller_store), std::move(distiller_factory), 107 std::move(dom_distiller_store), std::move(distiller_factory),
118 std::move(distiller_page_factory), std::move(distilled_page_prefs)); 108 std::move(distiller_page_factory), std::move(distilled_page_prefs));
119 } 109 }
120 110
121 web::BrowserState* DomDistillerServiceFactory::GetBrowserStateToUse( 111 web::BrowserState* DomDistillerServiceFactory::GetBrowserStateToUse(
122 web::BrowserState* context) const { 112 web::BrowserState* context) const {
123 // Makes normal profile and off-the-record profile use same service instance. 113 // Makes normal profile and off-the-record profile use same service instance.
124 return GetBrowserStateRedirectedInIncognito(context); 114 return GetBrowserStateRedirectedInIncognito(context);
125 } 115 }
126 116
127 } // namespace dom_distiller 117 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698