OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/dom_distiller/dom_distiller_service_factory.h" | 5 #include "chrome/browser/dom_distiller/dom_distiller_service_factory.h" |
6 | 6 |
7 #include "base/threading/sequenced_worker_pool.h" | 7 #include "base/threading/sequenced_worker_pool.h" |
8 #include "chrome/browser/profiles/incognito_helpers.h" | 8 #include "chrome/browser/profiles/incognito_helpers.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "components/dom_distiller/content/distiller_page_web_contents.h" | 10 #include "components/dom_distiller/content/distiller_page_web_contents.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_store.h" | 13 #include "components/dom_distiller/core/dom_distiller_store.h" |
14 #include "components/keyed_service/content/browser_context_dependency_manager.h" | 14 #include "components/keyed_service/content/browser_context_dependency_manager.h" |
15 #include "components/leveldb_proto/proto_database.h" | 15 #include "components/leveldb_proto/proto_database.h" |
16 #include "components/leveldb_proto/proto_database_impl.h" | 16 #include "components/leveldb_proto/proto_database_impl.h" |
17 #include "content/public/browser/browser_context.h" | 17 #include "content/public/browser/browser_context.h" |
18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "grit/components_resources.h" |
| 20 #include "ui/base/resource/resource_bundle.h" |
19 | 21 |
20 namespace dom_distiller { | 22 namespace dom_distiller { |
21 | 23 |
22 DomDistillerContextKeyedService::DomDistillerContextKeyedService( | 24 DomDistillerContextKeyedService::DomDistillerContextKeyedService( |
23 scoped_ptr<DomDistillerStoreInterface> store, | 25 scoped_ptr<DomDistillerStoreInterface> store, |
24 scoped_ptr<DistillerFactory> distiller_factory, | 26 scoped_ptr<DistillerFactory> distiller_factory, |
25 scoped_ptr<DistillerPageFactory> distiller_page_factory, | 27 scoped_ptr<DistillerPageFactory> distiller_page_factory, |
26 scoped_ptr<DistilledPagePrefs> distilled_page_prefs) | 28 scoped_ptr<DistilledPagePrefs> distilled_page_prefs) |
27 : DomDistillerService(store.Pass(), | 29 : DomDistillerService(store.Pass(), |
28 distiller_factory.Pass(), | 30 distiller_factory.Pass(), |
(...skipping 30 matching lines...) Expand all Loading... |
59 scoped_ptr<leveldb_proto::ProtoDatabaseImpl<ArticleEntry> > db( | 61 scoped_ptr<leveldb_proto::ProtoDatabaseImpl<ArticleEntry> > db( |
60 new leveldb_proto::ProtoDatabaseImpl<ArticleEntry>( | 62 new leveldb_proto::ProtoDatabaseImpl<ArticleEntry>( |
61 background_task_runner)); | 63 background_task_runner)); |
62 | 64 |
63 base::FilePath database_dir( | 65 base::FilePath database_dir( |
64 profile->GetPath().Append(FILE_PATH_LITERAL("Articles"))); | 66 profile->GetPath().Append(FILE_PATH_LITERAL("Articles"))); |
65 | 67 |
66 scoped_ptr<DomDistillerStore> dom_distiller_store( | 68 scoped_ptr<DomDistillerStore> dom_distiller_store( |
67 new DomDistillerStore(db.Pass(), database_dir)); | 69 new DomDistillerStore(db.Pass(), database_dir)); |
68 | 70 |
| 71 const std::string distiller_js_script = |
| 72 ResourceBundle::GetSharedInstance() |
| 73 .GetRawDataResource(IDR_DISTILLER_JS) |
| 74 .as_string(); |
69 scoped_ptr<DistillerPageFactory> distiller_page_factory( | 75 scoped_ptr<DistillerPageFactory> distiller_page_factory( |
70 new DistillerPageWebContentsFactory(profile)); | 76 new DistillerPageWebContentsFactory(profile, distiller_js_script)); |
71 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory( | 77 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory( |
72 new DistillerURLFetcherFactory(profile->GetRequestContext())); | 78 new DistillerURLFetcherFactory(profile->GetRequestContext())); |
73 | 79 |
74 dom_distiller::proto::DomDistillerOptions options; | 80 dom_distiller::proto::DomDistillerOptions options; |
75 if (VLOG_IS_ON(1)) { | 81 if (VLOG_IS_ON(1)) { |
76 options.set_debug_level(logging::GetVlogLevelHelper( | 82 options.set_debug_level(logging::GetVlogLevelHelper( |
77 FROM_HERE.file_name(), ::strlen(FROM_HERE.file_name()))); | 83 FROM_HERE.file_name(), ::strlen(FROM_HERE.file_name()))); |
78 } | 84 } |
79 scoped_ptr<DistillerFactory> distiller_factory( | 85 scoped_ptr<DistillerFactory> distiller_factory( |
80 new DistillerFactoryImpl(distiller_url_fetcher_factory.Pass(), options)); | 86 new DistillerFactoryImpl(distiller_url_fetcher_factory.Pass(), options)); |
81 scoped_ptr<DistilledPagePrefs> distilled_page_prefs( | 87 scoped_ptr<DistilledPagePrefs> distilled_page_prefs( |
82 new DistilledPagePrefs(Profile::FromBrowserContext(profile)->GetPrefs())); | 88 new DistilledPagePrefs(Profile::FromBrowserContext(profile)->GetPrefs())); |
83 | 89 |
84 DomDistillerContextKeyedService* service = | 90 DomDistillerContextKeyedService* service = |
85 new DomDistillerContextKeyedService(dom_distiller_store.Pass(), | 91 new DomDistillerContextKeyedService(dom_distiller_store.Pass(), |
86 distiller_factory.Pass(), | 92 distiller_factory.Pass(), |
87 distiller_page_factory.Pass(), | 93 distiller_page_factory.Pass(), |
88 distilled_page_prefs.Pass()); | 94 distilled_page_prefs.Pass()); |
89 | 95 |
90 return service; | 96 return service; |
91 } | 97 } |
92 | 98 |
93 content::BrowserContext* DomDistillerServiceFactory::GetBrowserContextToUse( | 99 content::BrowserContext* DomDistillerServiceFactory::GetBrowserContextToUse( |
94 content::BrowserContext* context) const { | 100 content::BrowserContext* context) const { |
95 // Makes normal profile and off-the-record profile use same service instance. | 101 // Makes normal profile and off-the-record profile use same service instance. |
96 return chrome::GetBrowserContextRedirectedInIncognito(context); | 102 return chrome::GetBrowserContextRedirectedInIncognito(context); |
97 } | 103 } |
98 | 104 |
99 } // namespace dom_distiller | 105 } // namespace dom_distiller |
OLD | NEW |