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

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

Issue 901793002: Add support for providing an external file for extracting content. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved injection to constructor 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
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 "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "base/threading/sequenced_worker_pool.h" 10 #include "base/threading/sequenced_worker_pool.h"
11 #include "components/dom_distiller/core/article_entry.h" 11 #include "components/dom_distiller/core/article_entry.h"
12 #include "components/dom_distiller/core/distiller.h" 12 #include "components/dom_distiller/core/distiller.h"
13 #include "components/dom_distiller/core/dom_distiller_service.h" 13 #include "components/dom_distiller/core/dom_distiller_service.h"
14 #include "components/dom_distiller/core/dom_distiller_store.h" 14 #include "components/dom_distiller/core/dom_distiller_store.h"
15 #include "components/dom_distiller/ios/distiller_page_factory_ios.h" 15 #include "components/dom_distiller/ios/distiller_page_factory_ios.h"
16 #include "components/keyed_service/core/keyed_service.h" 16 #include "components/keyed_service/core/keyed_service.h"
17 #include "components/keyed_service/ios/browser_state_dependency_manager.h" 17 #include "components/keyed_service/ios/browser_state_dependency_manager.h"
18 #include "components/leveldb_proto/proto_database.h" 18 #include "components/leveldb_proto/proto_database.h"
19 #include "components/leveldb_proto/proto_database_impl.h" 19 #include "components/leveldb_proto/proto_database_impl.h"
20 #include "grit/components_resources.h"
20 #include "ios/chrome/browser/browser_state/browser_state_otr_helper.h" 21 #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/public/provider/chrome/browser/browser_state/chrome_browser_state. h"
22 #include "ios/web/public/browser_state.h" 23 #include "ios/web/public/browser_state.h"
23 #include "ios/web/public/web_thread.h" 24 #include "ios/web/public/web_thread.h"
25 #include "ui/base/resource/resource_bundle.h"
24 26
25 namespace { 27 namespace {
26 // A simple wrapper for DomDistillerService to expose it as a 28 // A simple wrapper for DomDistillerService to expose it as a
27 // KeyedService. 29 // KeyedService.
28 class DomDistillerKeyedService 30 class DomDistillerKeyedService
29 : public KeyedService, 31 : public KeyedService,
30 public dom_distiller::DomDistillerService { 32 public dom_distiller::DomDistillerService {
31 public: 33 public:
32 DomDistillerKeyedService( 34 DomDistillerKeyedService(
33 scoped_ptr<dom_distiller::DomDistillerStoreInterface> store, 35 scoped_ptr<dom_distiller::DomDistillerStoreInterface> store,
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 scoped_ptr<leveldb_proto::ProtoDatabaseImpl<ArticleEntry>> db( 80 scoped_ptr<leveldb_proto::ProtoDatabaseImpl<ArticleEntry>> db(
79 new leveldb_proto::ProtoDatabaseImpl<ArticleEntry>( 81 new leveldb_proto::ProtoDatabaseImpl<ArticleEntry>(
80 background_task_runner)); 82 background_task_runner));
81 83
82 base::FilePath database_dir( 84 base::FilePath database_dir(
83 browser_state->GetStatePath().Append(FILE_PATH_LITERAL("Articles"))); 85 browser_state->GetStatePath().Append(FILE_PATH_LITERAL("Articles")));
84 86
85 scoped_ptr<DomDistillerStore> dom_distiller_store( 87 scoped_ptr<DomDistillerStore> dom_distiller_store(
86 new DomDistillerStore(db.Pass(), database_dir)); 88 new DomDistillerStore(db.Pass(), database_dir));
87 89
90 const std::string distiller_js_script =
91 ResourceBundle::GetSharedInstance()
92 .GetRawDataResource(IDR_DISTILLER_JS)
93 .as_string();
88 scoped_ptr<DistillerPageFactory> distiller_page_factory( 94 scoped_ptr<DistillerPageFactory> distiller_page_factory(
89 new DistillerPageFactoryIOS(browser_state)); 95 new DistillerPageFactoryIOS(browser_state, distiller_js_script));
90 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory( 96 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory(
91 new DistillerURLFetcherFactory(browser_state->GetRequestContext())); 97 new DistillerURLFetcherFactory(browser_state->GetRequestContext()));
92 98
93 dom_distiller::proto::DomDistillerOptions options; 99 dom_distiller::proto::DomDistillerOptions options;
94 scoped_ptr<DistillerFactory> distiller_factory( 100 scoped_ptr<DistillerFactory> distiller_factory(
95 new DistillerFactoryImpl(distiller_url_fetcher_factory.Pass(), options)); 101 new DistillerFactoryImpl(distiller_url_fetcher_factory.Pass(), options));
96 scoped_ptr<DistilledPagePrefs> distilled_page_prefs(new DistilledPagePrefs( 102 scoped_ptr<DistilledPagePrefs> distilled_page_prefs(new DistilledPagePrefs(
97 ios::ChromeBrowserState::FromBrowserState(browser_state)->GetPrefs())); 103 ios::ChromeBrowserState::FromBrowserState(browser_state)->GetPrefs()));
98 104
99 DomDistillerKeyedService* service = 105 DomDistillerKeyedService* service =
100 new DomDistillerKeyedService( 106 new DomDistillerKeyedService(
101 dom_distiller_store.Pass(), distiller_factory.Pass(), 107 dom_distiller_store.Pass(), distiller_factory.Pass(),
102 distiller_page_factory.Pass(), distilled_page_prefs.Pass()); 108 distiller_page_factory.Pass(), distilled_page_prefs.Pass());
103 109
104 return service; 110 return service;
105 } 111 }
106 112
107 web::BrowserState* DomDistillerServiceFactory::GetBrowserStateToUse( 113 web::BrowserState* DomDistillerServiceFactory::GetBrowserStateToUse(
108 web::BrowserState* browser_state) const { 114 web::BrowserState* browser_state) const {
109 // 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.
110 return GetBrowserStateRedirectedInIncognito(browser_state); 116 return GetBrowserStateRedirectedInIncognito(browser_state);
111 } 117 }
112 118
113 } // namespace dom_distiller 119 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698