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

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

Issue 972683002: Upstream dom_distiller iOS factories (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@browser_state
Patch Set: Created 5 years, 9 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "ios/chrome/browser/dom_distiller/dom_distiller_service_factory.h"
6
7 #include "base/files/file_path.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/singleton.h"
10 #include "base/threading/sequenced_worker_pool.h"
11 #include "components/dom_distiller/core/article_entry.h"
12 #include "components/dom_distiller/core/distiller.h"
13 #include "components/dom_distiller/core/dom_distiller_service.h"
14 #include "components/dom_distiller/core/dom_distiller_store.h"
15 #include "components/dom_distiller/ios/distiller_page_factory_ios.h"
16 #include "components/keyed_service/core/keyed_service.h"
17 #include "components/keyed_service/ios/browser_state_dependency_manager.h"
18 #include "components/leveldb_proto/proto_database.h"
19 #include "components/leveldb_proto/proto_database_impl.h"
20 #include "ios/chrome/browser/browser_state/browser_state_otr_helper.h"
21 #include "ios/public/provider/chrome/browser/browser_state/chrome_browser_state. h"
22 #include "ios/web/public/browser_state.h"
23 #include "ios/web/public/web_thread.h"
24
25 namespace {
26 // A simple wrapper for DomDistillerService to expose it as a
27 // KeyedService.
28 class DomDistillerKeyedService
29 : public KeyedService,
30 public dom_distiller::DomDistillerService {
31 public:
32 DomDistillerKeyedService(
33 scoped_ptr<dom_distiller::DomDistillerStoreInterface> store,
34 scoped_ptr<dom_distiller::DistillerFactory> distiller_factory,
35 scoped_ptr<dom_distiller::DistillerPageFactory> distiller_page_factory,
36 scoped_ptr<dom_distiller::DistilledPagePrefs> distilled_page_prefs)
37 : DomDistillerService(store.Pass(),
38 distiller_factory.Pass(),
39 distiller_page_factory.Pass(),
40 distilled_page_prefs.Pass()) {}
41
42 ~DomDistillerKeyedService() override {}
43
44 private:
45 DISALLOW_COPY_AND_ASSIGN(DomDistillerKeyedService);
46 };
47 } // namespace
48
49 namespace dom_distiller {
50
51 // static
52 DomDistillerServiceFactory* DomDistillerServiceFactory::GetInstance() {
53 return Singleton<DomDistillerServiceFactory>::get();
54 }
55
56 // static
57 DomDistillerService* DomDistillerServiceFactory::GetForBrowserState(
58 web::BrowserState* browser_state) {
59 return static_cast<DomDistillerKeyedService*>(
60 GetInstance()->GetServiceForBrowserState(browser_state, true));
61 }
62
63 DomDistillerServiceFactory::DomDistillerServiceFactory()
64 : BrowserStateKeyedServiceFactory(
65 "DomDistillerService",
66 BrowserStateDependencyManager::GetInstance()) {
67 }
68
69 DomDistillerServiceFactory::~DomDistillerServiceFactory() {
70 }
71
72 KeyedService* DomDistillerServiceFactory::BuildServiceInstanceFor(
73 web::BrowserState* browser_state) const {
74 scoped_refptr<base::SequencedTaskRunner> background_task_runner =
75 web::WebThread::GetBlockingPool()->GetSequencedTaskRunner(
76 web::WebThread::GetBlockingPool()->GetSequenceToken());
77
78 scoped_ptr<leveldb_proto::ProtoDatabaseImpl<ArticleEntry>> db(
79 new leveldb_proto::ProtoDatabaseImpl<ArticleEntry>(
80 background_task_runner));
81
82 base::FilePath database_dir(
83 browser_state->GetStatePath().Append(FILE_PATH_LITERAL("Articles")));
84
85 scoped_ptr<DomDistillerStore> dom_distiller_store(
86 new DomDistillerStore(db.Pass(), database_dir));
87
88 scoped_ptr<DistillerPageFactory> distiller_page_factory(
89 new DistillerPageFactoryIOS(browser_state));
90 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory(
91 new DistillerURLFetcherFactory(browser_state->GetRequestContext()));
92
93 dom_distiller::proto::DomDistillerOptions options;
94 scoped_ptr<DistillerFactory> distiller_factory(
95 new DistillerFactoryImpl(distiller_url_fetcher_factory.Pass(), options));
96 scoped_ptr<DistilledPagePrefs> distilled_page_prefs(new DistilledPagePrefs(
97 ios::ChromeBrowserState::FromBrowserState(browser_state)->GetPrefs()));
98
99 DomDistillerKeyedService* service =
100 new DomDistillerKeyedService(
101 dom_distiller_store.Pass(), distiller_factory.Pass(),
102 distiller_page_factory.Pass(), distilled_page_prefs.Pass());
103
104 return service;
105 }
106
107 web::BrowserState* DomDistillerServiceFactory::GetBrowserStateToUse(
108 web::BrowserState* browser_state) const {
109 // Makes normal profile and off-the-record profile use same service instance.
110 return GetBrowserStateRedirectedInIncognito(browser_state);
111 }
112
113 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « ios/chrome/browser/dom_distiller/dom_distiller_service_factory.h ('k') | ios/chrome/ios_chrome.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698