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 <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 13 matching lines...) Expand all Loading... |
24 #include "net/url_request/url_request_context_getter.h" | 24 #include "net/url_request/url_request_context_getter.h" |
25 | 25 |
26 namespace { | 26 namespace { |
27 // Maximum number of distilled pages in an article. | 27 // Maximum number of distilled pages in an article. |
28 const size_t kMaxPagesInArticle = 32; | 28 const size_t kMaxPagesInArticle = 32; |
29 } | 29 } |
30 | 30 |
31 namespace dom_distiller { | 31 namespace dom_distiller { |
32 | 32 |
33 DistillerFactoryImpl::DistillerFactoryImpl( | 33 DistillerFactoryImpl::DistillerFactoryImpl( |
34 scoped_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory, | 34 std::unique_ptr<DistillerURLFetcherFactory> distiller_url_fetcher_factory, |
35 const dom_distiller::proto::DomDistillerOptions& dom_distiller_options) | 35 const dom_distiller::proto::DomDistillerOptions& dom_distiller_options) |
36 : distiller_url_fetcher_factory_(std::move(distiller_url_fetcher_factory)), | 36 : distiller_url_fetcher_factory_(std::move(distiller_url_fetcher_factory)), |
37 dom_distiller_options_(dom_distiller_options) {} | 37 dom_distiller_options_(dom_distiller_options) {} |
38 | 38 |
39 DistillerFactoryImpl::~DistillerFactoryImpl() {} | 39 DistillerFactoryImpl::~DistillerFactoryImpl() {} |
40 | 40 |
41 scoped_ptr<Distiller> DistillerFactoryImpl::CreateDistillerForUrl( | 41 std::unique_ptr<Distiller> DistillerFactoryImpl::CreateDistillerForUrl( |
42 const GURL& unused) { | 42 const GURL& unused) { |
43 // This default implementation has the same behavior for all URLs. | 43 // This default implementation has the same behavior for all URLs. |
44 scoped_ptr<DistillerImpl> distiller(new DistillerImpl( | 44 std::unique_ptr<DistillerImpl> distiller(new DistillerImpl( |
45 *distiller_url_fetcher_factory_, dom_distiller_options_)); | 45 *distiller_url_fetcher_factory_, dom_distiller_options_)); |
46 return std::move(distiller); | 46 return std::move(distiller); |
47 } | 47 } |
48 | 48 |
49 DistillerImpl::DistilledPageData::DistilledPageData() {} | 49 DistillerImpl::DistilledPageData::DistilledPageData() {} |
50 | 50 |
51 DistillerImpl::DistilledPageData::~DistilledPageData() {} | 51 DistillerImpl::DistilledPageData::~DistilledPageData() {} |
52 | 52 |
53 DistillerImpl::DistillerImpl( | 53 DistillerImpl::DistillerImpl( |
54 const DistillerURLFetcherFactory& distiller_url_fetcher_factory, | 54 const DistillerURLFetcherFactory& distiller_url_fetcher_factory, |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 | 93 |
94 DistillerImpl::DistilledPageData* DistillerImpl::GetPageAtIndex(size_t index) | 94 DistillerImpl::DistilledPageData* DistillerImpl::GetPageAtIndex(size_t index) |
95 const { | 95 const { |
96 DCHECK_LT(index, pages_.size()); | 96 DCHECK_LT(index, pages_.size()); |
97 DistilledPageData* page_data = pages_[index]; | 97 DistilledPageData* page_data = pages_[index]; |
98 DCHECK(page_data); | 98 DCHECK(page_data); |
99 return page_data; | 99 return page_data; |
100 } | 100 } |
101 | 101 |
102 void DistillerImpl::DistillPage(const GURL& url, | 102 void DistillerImpl::DistillPage(const GURL& url, |
103 scoped_ptr<DistillerPage> distiller_page, | 103 std::unique_ptr<DistillerPage> distiller_page, |
104 const DistillationFinishedCallback& finished_cb, | 104 const DistillationFinishedCallback& finished_cb, |
105 const DistillationUpdateCallback& update_cb) { | 105 const DistillationUpdateCallback& update_cb) { |
106 DCHECK(AreAllPagesFinished()); | 106 DCHECK(AreAllPagesFinished()); |
107 distiller_page_ = std::move(distiller_page); | 107 distiller_page_ = std::move(distiller_page); |
108 finished_cb_ = finished_cb; | 108 finished_cb_ = finished_cb; |
109 update_cb_ = update_cb; | 109 update_cb_ = update_cb; |
110 | 110 |
111 AddToDistillationQueue(0, url); | 111 AddToDistillationQueue(0, url); |
112 DistillNextPage(); | 112 DistillNextPage(); |
113 } | 113 } |
(...skipping 17 matching lines...) Expand all Loading... |
131 base::Bind(&DistillerImpl::OnPageDistillationFinished, | 131 base::Bind(&DistillerImpl::OnPageDistillationFinished, |
132 weak_factory_.GetWeakPtr(), | 132 weak_factory_.GetWeakPtr(), |
133 page_num, | 133 page_num, |
134 url)); | 134 url)); |
135 } | 135 } |
136 } | 136 } |
137 | 137 |
138 void DistillerImpl::OnPageDistillationFinished( | 138 void DistillerImpl::OnPageDistillationFinished( |
139 int page_num, | 139 int page_num, |
140 const GURL& page_url, | 140 const GURL& page_url, |
141 scoped_ptr<proto::DomDistillerResult> distiller_result, | 141 std::unique_ptr<proto::DomDistillerResult> distiller_result, |
142 bool distillation_successful) { | 142 bool distillation_successful) { |
143 DCHECK(started_pages_index_.find(page_num) != started_pages_index_.end()); | 143 DCHECK(started_pages_index_.find(page_num) != started_pages_index_.end()); |
144 if (distillation_successful) { | 144 if (distillation_successful) { |
145 | 145 |
146 if (distiller_result->has_statistics_info() && page_num == 0) { | 146 if (distiller_result->has_statistics_info() && page_num == 0) { |
147 if (distiller_result->statistics_info().has_word_count()) { | 147 if (distiller_result->statistics_info().has_word_count()) { |
148 UMA_HISTOGRAM_CUSTOM_COUNTS( | 148 UMA_HISTOGRAM_CUSTOM_COUNTS( |
149 "DomDistiller.Statistics.FirstPageWordCount", | 149 "DomDistiller.Statistics.FirstPageWordCount", |
150 distiller_result->statistics_info().word_count(), | 150 distiller_result->statistics_info().word_count(), |
151 1, 4000, 50); | 151 1, 4000, 50); |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
357 ++it) { | 357 ++it) { |
358 update_pages.push_back(pages_[it->second]->distilled_page_proto); | 358 update_pages.push_back(pages_[it->second]->distilled_page_proto); |
359 } | 359 } |
360 return ArticleDistillationUpdate(update_pages, has_next_page, has_prev_page); | 360 return ArticleDistillationUpdate(update_pages, has_next_page, has_prev_page); |
361 } | 361 } |
362 | 362 |
363 void DistillerImpl::RunDistillerCallbackIfDone() { | 363 void DistillerImpl::RunDistillerCallbackIfDone() { |
364 DCHECK(!finished_cb_.is_null()); | 364 DCHECK(!finished_cb_.is_null()); |
365 if (AreAllPagesFinished()) { | 365 if (AreAllPagesFinished()) { |
366 bool first_page = true; | 366 bool first_page = true; |
367 scoped_ptr<DistilledArticleProto> article_proto( | 367 std::unique_ptr<DistilledArticleProto> article_proto( |
368 new DistilledArticleProto()); | 368 new DistilledArticleProto()); |
369 // Stitch the pages back into the article. | 369 // Stitch the pages back into the article. |
370 for (std::map<int, size_t>::iterator it = finished_pages_index_.begin(); | 370 for (std::map<int, size_t>::iterator it = finished_pages_index_.begin(); |
371 it != finished_pages_index_.end();) { | 371 it != finished_pages_index_.end();) { |
372 DistilledPageData* page_data = GetPageAtIndex(it->second); | 372 DistilledPageData* page_data = GetPageAtIndex(it->second); |
373 *(article_proto->add_pages()) = page_data->distilled_page_proto->data; | 373 *(article_proto->add_pages()) = page_data->distilled_page_proto->data; |
374 | 374 |
375 if (first_page) { | 375 if (first_page) { |
376 article_proto->set_title(page_data->distilled_page_proto->data.title()); | 376 article_proto->set_title(page_data->distilled_page_proto->data.title()); |
377 first_page = false; | 377 first_page = false; |
(...skipping 10 matching lines...) Expand all Loading... |
388 DCHECK(finished_pages_index_.empty()); | 388 DCHECK(finished_pages_index_.empty()); |
389 | 389 |
390 base::AutoReset<bool> dont_delete_this_in_callback(&destruction_allowed_, | 390 base::AutoReset<bool> dont_delete_this_in_callback(&destruction_allowed_, |
391 false); | 391 false); |
392 finished_cb_.Run(std::move(article_proto)); | 392 finished_cb_.Run(std::move(article_proto)); |
393 finished_cb_.Reset(); | 393 finished_cb_.Reset(); |
394 } | 394 } |
395 } | 395 } |
396 | 396 |
397 } // namespace dom_distiller | 397 } // namespace dom_distiller |
OLD | NEW |