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