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 "components/dom_distiller/core/distiller.h" | 5 #include "components/dom_distiller/core/distiller.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "net/url_request/url_request_context_getter.h" | 22 #include "net/url_request/url_request_context_getter.h" |
23 | 23 |
24 namespace { | 24 namespace { |
25 // Maximum number of distilled pages in an article. | 25 // Maximum number of distilled pages in an article. |
26 const size_t kMaxPagesInArticle = 32; | 26 const size_t kMaxPagesInArticle = 32; |
27 } | 27 } |
28 | 28 |
29 namespace dom_distiller { | 29 namespace dom_distiller { |
30 | 30 |
31 DistillerFactoryImpl::DistillerFactoryImpl( | 31 DistillerFactoryImpl::DistillerFactoryImpl( |
32 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory) | 32 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory, |
33 : distiller_url_fetcher_factory_(distiller_url_fetcher_factory.Pass()) { | 33 const dom_distiller::proto::DomDistillerOptions& dom_distiller_options) |
| 34 : distiller_url_fetcher_factory_(distiller_url_fetcher_factory.Pass()), |
| 35 dom_distiller_options_(dom_distiller_options) { |
34 } | 36 } |
35 | 37 |
36 DistillerFactoryImpl::~DistillerFactoryImpl() {} | 38 DistillerFactoryImpl::~DistillerFactoryImpl() {} |
37 | 39 |
38 scoped_ptr<Distiller> DistillerFactoryImpl::CreateDistiller() { | 40 scoped_ptr<Distiller> DistillerFactoryImpl::CreateDistiller() { |
39 scoped_ptr<DistillerImpl> distiller( | 41 scoped_ptr<DistillerImpl> distiller(new DistillerImpl( |
40 new DistillerImpl(*distiller_url_fetcher_factory_)); | 42 *distiller_url_fetcher_factory_, dom_distiller_options_)); |
41 return distiller.PassAs<Distiller>(); | 43 return distiller.PassAs<Distiller>(); |
42 } | 44 } |
43 | 45 |
44 DistillerImpl::DistilledPageData::DistilledPageData() {} | 46 DistillerImpl::DistilledPageData::DistilledPageData() {} |
45 | 47 |
46 DistillerImpl::DistilledPageData::~DistilledPageData() {} | 48 DistillerImpl::DistilledPageData::~DistilledPageData() {} |
47 | 49 |
48 DistillerImpl::DistillerImpl( | 50 DistillerImpl::DistillerImpl( |
49 const DistillerURLFetcherFactory& distiller_url_fetcher_factory) | 51 const DistillerURLFetcherFactory& distiller_url_fetcher_factory, |
| 52 const dom_distiller::proto::DomDistillerOptions& dom_distiller_options) |
50 : distiller_url_fetcher_factory_(distiller_url_fetcher_factory), | 53 : distiller_url_fetcher_factory_(distiller_url_fetcher_factory), |
| 54 dom_distiller_options_(dom_distiller_options), |
51 max_pages_in_article_(kMaxPagesInArticle), | 55 max_pages_in_article_(kMaxPagesInArticle), |
52 destruction_allowed_(true), | 56 destruction_allowed_(true), |
53 weak_factory_(this) { | 57 weak_factory_(this) { |
54 } | 58 } |
55 | 59 |
56 DistillerImpl::~DistillerImpl() { | 60 DistillerImpl::~DistillerImpl() { |
57 DCHECK(destruction_allowed_); | 61 DCHECK(destruction_allowed_); |
58 } | 62 } |
59 | 63 |
60 void DistillerImpl::SetMaxNumPagesInArticle(size_t max_num_pages) { | 64 void DistillerImpl::SetMaxNumPagesInArticle(size_t max_num_pages) { |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 | 117 |
114 waiting_pages_.erase(front); | 118 waiting_pages_.erase(front); |
115 DCHECK(url.is_valid()); | 119 DCHECK(url.is_valid()); |
116 DCHECK(started_pages_index_.find(page_num) == started_pages_index_.end()); | 120 DCHECK(started_pages_index_.find(page_num) == started_pages_index_.end()); |
117 DCHECK(finished_pages_index_.find(page_num) == finished_pages_index_.end()); | 121 DCHECK(finished_pages_index_.find(page_num) == finished_pages_index_.end()); |
118 seen_urls_.insert(url.spec()); | 122 seen_urls_.insert(url.spec()); |
119 pages_.push_back(new DistilledPageData()); | 123 pages_.push_back(new DistilledPageData()); |
120 started_pages_index_[page_num] = pages_.size() - 1; | 124 started_pages_index_[page_num] = pages_.size() - 1; |
121 distiller_page_->DistillPage( | 125 distiller_page_->DistillPage( |
122 url, | 126 url, |
| 127 dom_distiller_options_, |
123 base::Bind(&DistillerImpl::OnPageDistillationFinished, | 128 base::Bind(&DistillerImpl::OnPageDistillationFinished, |
124 weak_factory_.GetWeakPtr(), | 129 weak_factory_.GetWeakPtr(), |
125 page_num, | 130 page_num, |
126 url)); | 131 url)); |
127 } | 132 } |
128 } | 133 } |
129 | 134 |
130 void DistillerImpl::OnPageDistillationFinished( | 135 void DistillerImpl::OnPageDistillationFinished( |
131 int page_num, | 136 int page_num, |
132 const GURL& page_url, | 137 const GURL& page_url, |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 DCHECK(finished_pages_index_.empty()); | 285 DCHECK(finished_pages_index_.empty()); |
281 | 286 |
282 base::AutoReset<bool> dont_delete_this_in_callback(&destruction_allowed_, | 287 base::AutoReset<bool> dont_delete_this_in_callback(&destruction_allowed_, |
283 false); | 288 false); |
284 finished_cb_.Run(article_proto.Pass()); | 289 finished_cb_.Run(article_proto.Pass()); |
285 finished_cb_.Reset(); | 290 finished_cb_.Reset(); |
286 } | 291 } |
287 } | 292 } |
288 | 293 |
289 } // namespace dom_distiller | 294 } // namespace dom_distiller |
OLD | NEW |