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

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: rebase 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 scoped_ptr<DistilledPageInfo> distilled_page, 133 scoped_ptr<DistilledPageInfo> distilled_page,
134 bool distillation_successful) { 134 bool distillation_successful) {
135 DCHECK(distilled_page.get()); 135 DCHECK(distilled_page.get());
136 DCHECK(started_pages_index_.find(page_num) != started_pages_index_.end()); 136 DCHECK(started_pages_index_.find(page_num) != started_pages_index_.end());
137 if (distillation_successful) { 137 if (distillation_successful) {
138 DistilledPageData* page_data = 138 DistilledPageData* page_data =
139 GetPageAtIndex(started_pages_index_[page_num]); 139 GetPageAtIndex(started_pages_index_[page_num]);
140 page_data->distilled_page_proto = 140 page_data->distilled_page_proto =
141 new base::RefCountedData<DistilledPageProto>(); 141 new base::RefCountedData<DistilledPageProto>();
142 page_data->page_num = page_num; 142 page_data->page_num = page_num;
143 page_data->title = distilled_page->title; 143 page_data->distilled_page_proto->data.set_title(distilled_page->title);
144
145 page_data->distilled_page_proto->data.set_url(page_url.spec()); 144 page_data->distilled_page_proto->data.set_url(page_url.spec());
146 page_data->distilled_page_proto->data.set_html(distilled_page->html); 145 page_data->distilled_page_proto->data.set_html(distilled_page->html);
147 146
148 GURL next_page_url(distilled_page->next_page_url); 147 GURL next_page_url(distilled_page->next_page_url);
149 if (next_page_url.is_valid()) { 148 if (next_page_url.is_valid()) {
150 // The pages should be in same origin. 149 // The pages should be in same origin.
151 DCHECK_EQ(next_page_url.GetOrigin(), page_url.GetOrigin()); 150 DCHECK_EQ(next_page_url.GetOrigin(), page_url.GetOrigin());
152 AddToDistillationQueue(page_num + 1, next_page_url); 151 AddToDistillationQueue(page_num + 1, next_page_url);
153 } 152 }
154 153
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 bool first_page = true; 258 bool first_page = true;
260 scoped_ptr<DistilledArticleProto> article_proto( 259 scoped_ptr<DistilledArticleProto> article_proto(
261 new DistilledArticleProto()); 260 new DistilledArticleProto());
262 // Stitch the pages back into the article. 261 // Stitch the pages back into the article.
263 for (std::map<int, size_t>::iterator it = finished_pages_index_.begin(); 262 for (std::map<int, size_t>::iterator it = finished_pages_index_.begin();
264 it != finished_pages_index_.end();) { 263 it != finished_pages_index_.end();) {
265 DistilledPageData* page_data = GetPageAtIndex(it->second); 264 DistilledPageData* page_data = GetPageAtIndex(it->second);
266 *(article_proto->add_pages()) = page_data->distilled_page_proto->data; 265 *(article_proto->add_pages()) = page_data->distilled_page_proto->data;
267 266
268 if (first_page) { 267 if (first_page) {
269 article_proto->set_title(page_data->title); 268 article_proto->set_title(page_data->distilled_page_proto->data.title());
270 first_page = false; 269 first_page = false;
271 } 270 }
272 271
273 finished_pages_index_.erase(it++); 272 finished_pages_index_.erase(it++);
274 } 273 }
275 274
276 pages_.clear(); 275 pages_.clear();
277 DCHECK_LE(static_cast<size_t>(article_proto->pages_size()), 276 DCHECK_LE(static_cast<size_t>(article_proto->pages_size()),
278 max_pages_in_article_); 277 max_pages_in_article_);
279 278
280 DCHECK(pages_.empty()); 279 DCHECK(pages_.empty());
281 DCHECK(finished_pages_index_.empty()); 280 DCHECK(finished_pages_index_.empty());
282 281
283 base::AutoReset<bool> dont_delete_this_in_callback(&destruction_allowed_, 282 base::AutoReset<bool> dont_delete_this_in_callback(&destruction_allowed_,
284 false); 283 false);
285 finished_cb_.Run(article_proto.Pass()); 284 finished_cb_.Run(article_proto.Pass());
286 finished_cb_.Reset(); 285 finished_cb_.Reset();
287 } 286 }
288 } 287 }
289 288
290 } // namespace dom_distiller 289 } // namespace dom_distiller
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698