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/singleton.h" | 12 #include "base/memory/singleton.h" |
12 #include "base/threading/sequenced_worker_pool.h" | 13 #include "base/threading/sequenced_worker_pool.h" |
13 #include "components/dom_distiller/core/article_entry.h" | 14 #include "components/dom_distiller/core/article_entry.h" |
14 #include "components/dom_distiller/core/distiller.h" | 15 #include "components/dom_distiller/core/distiller.h" |
15 #include "components/dom_distiller/core/dom_distiller_service.h" | 16 #include "components/dom_distiller/core/dom_distiller_service.h" |
16 #include "components/dom_distiller/core/dom_distiller_store.h" | 17 #include "components/dom_distiller/core/dom_distiller_store.h" |
17 #include "components/dom_distiller/ios/distiller_page_factory_ios.h" | 18 #include "components/dom_distiller/ios/distiller_page_factory_ios.h" |
18 #include "components/keyed_service/core/keyed_service.h" | 19 #include "components/keyed_service/core/keyed_service.h" |
19 #include "components/keyed_service/ios/browser_state_dependency_manager.h" | 20 #include "components/keyed_service/ios/browser_state_dependency_manager.h" |
20 #include "components/leveldb_proto/proto_database.h" | 21 #include "components/leveldb_proto/proto_database.h" |
21 #include "components/leveldb_proto/proto_database_impl.h" | 22 #include "components/leveldb_proto/proto_database_impl.h" |
22 #include "ios/chrome/browser/browser_state/browser_state_otr_helper.h" | 23 #include "ios/chrome/browser/browser_state/browser_state_otr_helper.h" |
23 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" | 24 #include "ios/chrome/browser/browser_state/chrome_browser_state.h" |
24 #include "ios/web/public/browser_state.h" | 25 #include "ios/web/public/browser_state.h" |
25 #include "ios/web/public/web_thread.h" | 26 #include "ios/web/public/web_thread.h" |
26 | 27 |
27 namespace { | 28 namespace { |
28 // A simple wrapper for DomDistillerService to expose it as a | 29 // A simple wrapper for DomDistillerService to expose it as a |
29 // KeyedService. | 30 // KeyedService. |
30 class DomDistillerKeyedService | 31 class DomDistillerKeyedService |
31 : public KeyedService, | 32 : public KeyedService, |
32 public dom_distiller::DomDistillerService { | 33 public dom_distiller::DomDistillerService { |
33 public: | 34 public: |
34 DomDistillerKeyedService( | 35 DomDistillerKeyedService( |
35 scoped_ptr<dom_distiller::DomDistillerStoreInterface> store, | 36 std::unique_ptr<dom_distiller::DomDistillerStoreInterface> store, |
36 scoped_ptr<dom_distiller::DistillerFactory> distiller_factory, | 37 std::unique_ptr<dom_distiller::DistillerFactory> distiller_factory, |
37 scoped_ptr<dom_distiller::DistillerPageFactory> distiller_page_factory, | 38 std::unique_ptr<dom_distiller::DistillerPageFactory> |
38 scoped_ptr<dom_distiller::DistilledPagePrefs> distilled_page_prefs) | 39 distiller_page_factory, |
| 40 std::unique_ptr<dom_distiller::DistilledPagePrefs> distilled_page_prefs) |
39 : DomDistillerService(std::move(store), | 41 : DomDistillerService(std::move(store), |
40 std::move(distiller_factory), | 42 std::move(distiller_factory), |
41 std::move(distiller_page_factory), | 43 std::move(distiller_page_factory), |
42 std::move(distilled_page_prefs)) {} | 44 std::move(distilled_page_prefs)) {} |
43 | 45 |
44 ~DomDistillerKeyedService() override {} | 46 ~DomDistillerKeyedService() override {} |
45 | 47 |
46 private: | 48 private: |
47 DISALLOW_COPY_AND_ASSIGN(DomDistillerKeyedService); | 49 DISALLOW_COPY_AND_ASSIGN(DomDistillerKeyedService); |
48 }; | 50 }; |
(...skipping 15 matching lines...) Expand all Loading... |
64 | 66 |
65 DomDistillerServiceFactory::DomDistillerServiceFactory() | 67 DomDistillerServiceFactory::DomDistillerServiceFactory() |
66 : BrowserStateKeyedServiceFactory( | 68 : BrowserStateKeyedServiceFactory( |
67 "DomDistillerService", | 69 "DomDistillerService", |
68 BrowserStateDependencyManager::GetInstance()) { | 70 BrowserStateDependencyManager::GetInstance()) { |
69 } | 71 } |
70 | 72 |
71 DomDistillerServiceFactory::~DomDistillerServiceFactory() { | 73 DomDistillerServiceFactory::~DomDistillerServiceFactory() { |
72 } | 74 } |
73 | 75 |
74 scoped_ptr<KeyedService> DomDistillerServiceFactory::BuildServiceInstanceFor( | 76 std::unique_ptr<KeyedService> |
| 77 DomDistillerServiceFactory::BuildServiceInstanceFor( |
75 web::BrowserState* context) const { | 78 web::BrowserState* context) const { |
76 scoped_refptr<base::SequencedTaskRunner> background_task_runner = | 79 scoped_refptr<base::SequencedTaskRunner> background_task_runner = |
77 web::WebThread::GetBlockingPool()->GetSequencedTaskRunner( | 80 web::WebThread::GetBlockingPool()->GetSequencedTaskRunner( |
78 web::WebThread::GetBlockingPool()->GetSequenceToken()); | 81 web::WebThread::GetBlockingPool()->GetSequenceToken()); |
79 | 82 |
80 scoped_ptr<leveldb_proto::ProtoDatabaseImpl<ArticleEntry>> db( | 83 std::unique_ptr<leveldb_proto::ProtoDatabaseImpl<ArticleEntry>> db( |
81 new leveldb_proto::ProtoDatabaseImpl<ArticleEntry>( | 84 new leveldb_proto::ProtoDatabaseImpl<ArticleEntry>( |
82 background_task_runner)); | 85 background_task_runner)); |
83 | 86 |
84 base::FilePath database_dir( | 87 base::FilePath database_dir( |
85 context->GetStatePath().Append(FILE_PATH_LITERAL("Articles"))); | 88 context->GetStatePath().Append(FILE_PATH_LITERAL("Articles"))); |
86 | 89 |
87 scoped_ptr<DomDistillerStore> dom_distiller_store( | 90 std::unique_ptr<DomDistillerStore> dom_distiller_store( |
88 new DomDistillerStore(std::move(db), database_dir)); | 91 new DomDistillerStore(std::move(db), database_dir)); |
89 | 92 |
90 scoped_ptr<DistillerPageFactory> distiller_page_factory( | 93 std::unique_ptr<DistillerPageFactory> distiller_page_factory( |
91 new DistillerPageFactoryIOS(context)); | 94 new DistillerPageFactoryIOS(context)); |
92 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory( | 95 std::unique_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory( |
93 new DistillerURLFetcherFactory(context->GetRequestContext())); | 96 new DistillerURLFetcherFactory(context->GetRequestContext())); |
94 | 97 |
95 dom_distiller::proto::DomDistillerOptions options; | 98 dom_distiller::proto::DomDistillerOptions options; |
96 scoped_ptr<DistillerFactory> distiller_factory(new DistillerFactoryImpl( | 99 std::unique_ptr<DistillerFactory> distiller_factory(new DistillerFactoryImpl( |
97 std::move(distiller_url_fetcher_factory), options)); | 100 std::move(distiller_url_fetcher_factory), options)); |
98 scoped_ptr<DistilledPagePrefs> distilled_page_prefs(new DistilledPagePrefs( | 101 std::unique_ptr<DistilledPagePrefs> distilled_page_prefs( |
99 ios::ChromeBrowserState::FromBrowserState(context)->GetPrefs())); | 102 new DistilledPagePrefs( |
| 103 ios::ChromeBrowserState::FromBrowserState(context)->GetPrefs())); |
100 | 104 |
101 return make_scoped_ptr(new DomDistillerKeyedService( | 105 return base::WrapUnique(new DomDistillerKeyedService( |
102 std::move(dom_distiller_store), std::move(distiller_factory), | 106 std::move(dom_distiller_store), std::move(distiller_factory), |
103 std::move(distiller_page_factory), std::move(distilled_page_prefs))); | 107 std::move(distiller_page_factory), std::move(distilled_page_prefs))); |
104 } | 108 } |
105 | 109 |
106 web::BrowserState* DomDistillerServiceFactory::GetBrowserStateToUse( | 110 web::BrowserState* DomDistillerServiceFactory::GetBrowserStateToUse( |
107 web::BrowserState* context) const { | 111 web::BrowserState* context) const { |
108 // Makes normal profile and off-the-record profile use same service instance. | 112 // Makes normal profile and off-the-record profile use same service instance. |
109 return GetBrowserStateRedirectedInIncognito(context); | 113 return GetBrowserStateRedirectedInIncognito(context); |
110 } | 114 } |
111 | 115 |
112 } // namespace dom_distiller | 116 } // namespace dom_distiller |
OLD | NEW |