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 #ifndef COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_H_ | 5 #ifndef COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_H_ |
6 #define COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_H_ | 6 #define COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <map> | 10 #include <map> |
11 #include <memory> | 11 #include <memory> |
12 #include <string> | 12 #include <string> |
| 13 #include <vector> |
13 | 14 |
14 #include "base/callback.h" | 15 #include "base/callback.h" |
15 #include "base/containers/hash_tables.h" | 16 #include "base/containers/hash_tables.h" |
16 #include "base/macros.h" | 17 #include "base/macros.h" |
17 #include "base/memory/ref_counted.h" | 18 #include "base/memory/ref_counted.h" |
18 #include "base/memory/scoped_vector.h" | |
19 #include "base/memory/weak_ptr.h" | 19 #include "base/memory/weak_ptr.h" |
20 #include "components/dom_distiller/core/article_distillation_update.h" | 20 #include "components/dom_distiller/core/article_distillation_update.h" |
21 #include "components/dom_distiller/core/distiller_page.h" | 21 #include "components/dom_distiller/core/distiller_page.h" |
22 #include "components/dom_distiller/core/distiller_url_fetcher.h" | 22 #include "components/dom_distiller/core/distiller_url_fetcher.h" |
23 #include "components/dom_distiller/core/proto/distilled_article.pb.h" | 23 #include "components/dom_distiller/core/proto/distilled_article.pb.h" |
24 #include "net/url_request/url_request_context_getter.h" | 24 #include "net/url_request/url_request_context_getter.h" |
25 #include "url/gurl.h" | 25 #include "url/gurl.h" |
26 | 26 |
27 namespace dom_distiller { | 27 namespace dom_distiller { |
28 | 28 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 // as page numbers relative to the page number where distillation started. | 89 // as page numbers relative to the page number where distillation started. |
90 // E.g. if distillation starts at page 2 for a 3 page article. The relative | 90 // E.g. if distillation starts at page 2 for a 3 page article. The relative |
91 // page numbers assigned to pages will be [-1,0,1]. | 91 // page numbers assigned to pages will be [-1,0,1]. |
92 | 92 |
93 // Class representing the state of a page under distillation. | 93 // Class representing the state of a page under distillation. |
94 struct DistilledPageData { | 94 struct DistilledPageData { |
95 DistilledPageData(); | 95 DistilledPageData(); |
96 virtual ~DistilledPageData(); | 96 virtual ~DistilledPageData(); |
97 // Relative page number of the page. | 97 // Relative page number of the page. |
98 int page_num; | 98 int page_num; |
99 ScopedVector<DistillerURLFetcher> image_fetchers_; | 99 std::vector<std::unique_ptr<DistillerURLFetcher>> image_fetchers_; |
100 scoped_refptr<base::RefCountedData<DistilledPageProto> > | 100 scoped_refptr<base::RefCountedData<DistilledPageProto> > |
101 distilled_page_proto; | 101 distilled_page_proto; |
102 | 102 |
103 private: | 103 private: |
104 DISALLOW_COPY_AND_ASSIGN(DistilledPageData); | 104 DISALLOW_COPY_AND_ASSIGN(DistilledPageData); |
105 }; | 105 }; |
106 | 106 |
107 void OnFetchImageDone(int page_num, | 107 void OnFetchImageDone(int page_num, |
108 DistillerURLFetcher* url_fetcher, | 108 DistillerURLFetcher* url_fetcher, |
109 const std::string& id, | 109 const std::string& id, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 const DistillerURLFetcherFactory& distiller_url_fetcher_factory_; | 155 const DistillerURLFetcherFactory& distiller_url_fetcher_factory_; |
156 std::unique_ptr<DistillerPage> distiller_page_; | 156 std::unique_ptr<DistillerPage> distiller_page_; |
157 | 157 |
158 dom_distiller::proto::DomDistillerOptions dom_distiller_options_; | 158 dom_distiller::proto::DomDistillerOptions dom_distiller_options_; |
159 DistillationFinishedCallback finished_cb_; | 159 DistillationFinishedCallback finished_cb_; |
160 DistillationUpdateCallback update_cb_; | 160 DistillationUpdateCallback update_cb_; |
161 | 161 |
162 // Set of pages that are under distillation or have finished distillation. | 162 // Set of pages that are under distillation or have finished distillation. |
163 // |started_pages_index_| and |finished_pages_index_| maintains the mapping | 163 // |started_pages_index_| and |finished_pages_index_| maintains the mapping |
164 // from page number to the indices in |pages_|. | 164 // from page number to the indices in |pages_|. |
165 ScopedVector<DistilledPageData> pages_; | 165 std::vector<std::unique_ptr<DistilledPageData>> pages_; |
166 | 166 |
167 // Maps page numbers of finished pages to the indices in |pages_|. | 167 // Maps page numbers of finished pages to the indices in |pages_|. |
168 std::map<int, size_t> finished_pages_index_; | 168 std::map<int, size_t> finished_pages_index_; |
169 | 169 |
170 // Maps page numbers of pages under distillation to the indices in |pages_|. | 170 // Maps page numbers of pages under distillation to the indices in |pages_|. |
171 // If a page is |started_pages_| that means it is still waiting for an action | 171 // If a page is |started_pages_| that means it is still waiting for an action |
172 // (distillation or image fetch) to finish. | 172 // (distillation or image fetch) to finish. |
173 base::hash_map<int, size_t> started_pages_index_; | 173 base::hash_map<int, size_t> started_pages_index_; |
174 | 174 |
175 // The list of pages that are still waiting for distillation to start. | 175 // The list of pages that are still waiting for distillation to start. |
(...skipping 10 matching lines...) Expand all Loading... |
186 bool destruction_allowed_; | 186 bool destruction_allowed_; |
187 | 187 |
188 base::WeakPtrFactory<DistillerImpl> weak_factory_; | 188 base::WeakPtrFactory<DistillerImpl> weak_factory_; |
189 | 189 |
190 DISALLOW_COPY_AND_ASSIGN(DistillerImpl); | 190 DISALLOW_COPY_AND_ASSIGN(DistillerImpl); |
191 }; | 191 }; |
192 | 192 |
193 } // namespace dom_distiller | 193 } // namespace dom_distiller |
194 | 194 |
195 #endif // COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_H_ | 195 #endif // COMPONENTS_DOM_DISTILLER_CORE_DISTILLER_H_ |
OLD | NEW |