Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(64)

Side by Side Diff: components/dom_distiller/core/distiller.cc

Issue 260073009: [dom_distiller] Add support for incremental viewer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 scoped_ptr<DistilledPageInfo> distilled_page, 134 scoped_ptr<DistilledPageInfo> distilled_page,
135 bool distillation_successful) { 135 bool distillation_successful) {
136 DCHECK(distilled_page.get()); 136 DCHECK(distilled_page.get());
137 DCHECK(started_pages_index_.find(page_num) != started_pages_index_.end()); 137 DCHECK(started_pages_index_.find(page_num) != started_pages_index_.end());
138 if (distillation_successful) { 138 if (distillation_successful) {
139 DistilledPageData* page_data = 139 DistilledPageData* page_data =
140 GetPageAtIndex(started_pages_index_[page_num]); 140 GetPageAtIndex(started_pages_index_[page_num]);
141 page_data->distilled_page_proto = 141 page_data->distilled_page_proto =
142 new base::RefCountedData<DistilledPageProto>(); 142 new base::RefCountedData<DistilledPageProto>();
143 page_data->page_num = page_num; 143 page_data->page_num = page_num;
144 page_data->title = distilled_page->title; 144 page_data->distilled_page_proto->data.set_title(distilled_page->title);
145
146 page_data->distilled_page_proto->data.set_url(page_url.spec()); 145 page_data->distilled_page_proto->data.set_url(page_url.spec());
147 page_data->distilled_page_proto->data.set_html(distilled_page->html); 146 page_data->distilled_page_proto->data.set_html(distilled_page->html);
148 147
149 GURL next_page_url(distilled_page->next_page_url); 148 GURL next_page_url(distilled_page->next_page_url);
150 if (next_page_url.is_valid()) { 149 if (next_page_url.is_valid()) {
151 // The pages should be in same origin. 150 // The pages should be in same origin.
152 DCHECK_EQ(next_page_url.GetOrigin(), page_url.GetOrigin()); 151 DCHECK_EQ(next_page_url.GetOrigin(), page_url.GetOrigin());
153 AddToDistillationQueue(page_num + 1, next_page_url); 152 AddToDistillationQueue(page_num + 1, next_page_url);
154 } 153 }
155 154
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 bool first_page = true; 259 bool first_page = true;
261 scoped_ptr<DistilledArticleProto> article_proto( 260 scoped_ptr<DistilledArticleProto> article_proto(
262 new DistilledArticleProto()); 261 new DistilledArticleProto());
263 // Stitch the pages back into the article. 262 // Stitch the pages back into the article.
264 for (std::map<int, size_t>::iterator it = finished_pages_index_.begin(); 263 for (std::map<int, size_t>::iterator it = finished_pages_index_.begin();
265 it != finished_pages_index_.end();) { 264 it != finished_pages_index_.end();) {
266 DistilledPageData* page_data = GetPageAtIndex(it->second); 265 DistilledPageData* page_data = GetPageAtIndex(it->second);
267 *(article_proto->add_pages()) = page_data->distilled_page_proto->data; 266 *(article_proto->add_pages()) = page_data->distilled_page_proto->data;
268 267
269 if (first_page) { 268 if (first_page) {
270 article_proto->set_title(page_data->title); 269 article_proto->set_title(page_data->distilled_page_proto->data.title());
271 first_page = false; 270 first_page = false;
272 } 271 }
273 272
274 finished_pages_index_.erase(it++); 273 finished_pages_index_.erase(it++);
275 } 274 }
276 275
277 pages_.clear(); 276 pages_.clear();
278 DCHECK_LE(static_cast<size_t>(article_proto->pages_size()), 277 DCHECK_LE(static_cast<size_t>(article_proto->pages_size()),
279 max_pages_in_article_); 278 max_pages_in_article_);
280 279
281 DCHECK(pages_.empty()); 280 DCHECK(pages_.empty());
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698