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<DistillerPageFactory> distiller_page_factory, | |
33 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory) | 32 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory) |
34 : distiller_page_factory_(distiller_page_factory.Pass()), | 33 : distiller_url_fetcher_factory_(distiller_url_fetcher_factory.Pass()) {} |
35 distiller_url_fetcher_factory_(distiller_url_fetcher_factory.Pass()) {} | |
36 | 34 |
37 DistillerFactoryImpl::~DistillerFactoryImpl() {} | 35 DistillerFactoryImpl::~DistillerFactoryImpl() {} |
38 | 36 |
39 scoped_ptr<Distiller> DistillerFactoryImpl::CreateDistiller() { | 37 scoped_ptr<Distiller> DistillerFactoryImpl::CreateDistiller() { |
40 scoped_ptr<DistillerImpl> distiller(new DistillerImpl( | 38 scoped_ptr<DistillerImpl> distiller(new DistillerImpl( |
41 *distiller_page_factory_, *distiller_url_fetcher_factory_)); | 39 *distiller_url_fetcher_factory_)); |
42 return distiller.PassAs<Distiller>(); | 40 return distiller.PassAs<Distiller>(); |
43 } | 41 } |
44 | 42 |
45 DistillerImpl::DistilledPageData::DistilledPageData() {} | 43 DistillerImpl::DistilledPageData::DistilledPageData() {} |
46 | 44 |
47 DistillerImpl::DistilledPageData::~DistilledPageData() {} | 45 DistillerImpl::DistilledPageData::~DistilledPageData() {} |
48 | 46 |
49 DistillerImpl::DistillerImpl( | 47 DistillerImpl::DistillerImpl( |
50 const DistillerPageFactory& distiller_page_factory, | |
51 const DistillerURLFetcherFactory& distiller_url_fetcher_factory) | 48 const DistillerURLFetcherFactory& distiller_url_fetcher_factory) |
52 : distiller_url_fetcher_factory_(distiller_url_fetcher_factory), | 49 : distiller_url_fetcher_factory_(distiller_url_fetcher_factory), |
53 max_pages_in_article_(kMaxPagesInArticle), | 50 max_pages_in_article_(kMaxPagesInArticle), |
54 destruction_allowed_(true), | 51 destruction_allowed_(true), |
55 weak_factory_(this) { | 52 weak_factory_(this) {} |
56 distiller_page_ = distiller_page_factory.CreateDistillerPage().Pass(); | |
57 } | |
58 | 53 |
59 DistillerImpl::~DistillerImpl() { | 54 DistillerImpl::~DistillerImpl() { |
60 DCHECK(destruction_allowed_); | 55 DCHECK(destruction_allowed_); |
61 } | 56 } |
62 | 57 |
63 void DistillerImpl::SetMaxNumPagesInArticle(size_t max_num_pages) { | 58 void DistillerImpl::SetMaxNumPagesInArticle(size_t max_num_pages) { |
64 max_pages_in_article_ = max_num_pages; | 59 max_pages_in_article_ = max_num_pages; |
65 } | 60 } |
66 | 61 |
67 bool DistillerImpl::AreAllPagesFinished() const { | 62 bool DistillerImpl::AreAllPagesFinished() const { |
(...skipping 21 matching lines...) Expand all Loading... |
89 | 84 |
90 DistillerImpl::DistilledPageData* DistillerImpl::GetPageAtIndex(size_t index) | 85 DistillerImpl::DistilledPageData* DistillerImpl::GetPageAtIndex(size_t index) |
91 const { | 86 const { |
92 DCHECK_LT(index, pages_.size()); | 87 DCHECK_LT(index, pages_.size()); |
93 DistilledPageData* page_data = pages_[index]; | 88 DistilledPageData* page_data = pages_[index]; |
94 DCHECK(page_data); | 89 DCHECK(page_data); |
95 return page_data; | 90 return page_data; |
96 } | 91 } |
97 | 92 |
98 void DistillerImpl::DistillPage(const GURL& url, | 93 void DistillerImpl::DistillPage(const GURL& url, |
| 94 scoped_ptr<DistillerPage> distiller_page, |
99 const DistillationFinishedCallback& finished_cb, | 95 const DistillationFinishedCallback& finished_cb, |
100 const DistillationUpdateCallback& update_cb) { | 96 const DistillationUpdateCallback& update_cb) { |
101 DCHECK(AreAllPagesFinished()); | 97 DCHECK(AreAllPagesFinished()); |
| 98 distiller_page_ = distiller_page.Pass(); |
102 finished_cb_ = finished_cb; | 99 finished_cb_ = finished_cb; |
103 update_cb_ = update_cb; | 100 update_cb_ = update_cb; |
104 | 101 |
105 AddToDistillationQueue(0, url); | 102 AddToDistillationQueue(0, url); |
106 DistillNextPage(); | 103 DistillNextPage(); |
107 } | 104 } |
108 | 105 |
109 void DistillerImpl::DistillNextPage() { | 106 void DistillerImpl::DistillNextPage() { |
110 if (!waiting_pages_.empty()) { | 107 if (!waiting_pages_.empty()) { |
111 std::map<int, GURL>::iterator front = waiting_pages_.begin(); | 108 std::map<int, GURL>::iterator front = waiting_pages_.begin(); |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 DCHECK(finished_pages_index_.empty()); | 279 DCHECK(finished_pages_index_.empty()); |
283 | 280 |
284 base::AutoReset<bool> dont_delete_this_in_callback(&destruction_allowed_, | 281 base::AutoReset<bool> dont_delete_this_in_callback(&destruction_allowed_, |
285 false); | 282 false); |
286 finished_cb_.Run(article_proto.Pass()); | 283 finished_cb_.Run(article_proto.Pass()); |
287 finished_cb_.Reset(); | 284 finished_cb_.Reset(); |
288 } | 285 } |
289 } | 286 } |
290 | 287 |
291 } // namespace dom_distiller | 288 } // namespace dom_distiller |
OLD | NEW |