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

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

Issue 493853006: Remove DistilledPageInfo and related structs. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed DCHECK Created 6 years, 3 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
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_page.h" 5 #include "components/dom_distiller/core/distiller_page.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 DCHECK_NE(std::string::npos, options_offset); 43 DCHECK_NE(std::string::npos, options_offset);
44 DCHECK_EQ(std::string::npos, 44 DCHECK_EQ(std::string::npos,
45 script.find(kOptionsPlaceholder, options_offset + 1)); 45 script.find(kOptionsPlaceholder, options_offset + 1));
46 script = 46 script =
47 script.replace(options_offset, strlen(kOptionsPlaceholder), options_json); 47 script.replace(options_offset, strlen(kOptionsPlaceholder), options_json);
48 return script; 48 return script;
49 } 49 }
50 50
51 } 51 }
52 52
53 DistilledPageInfo::DistilledPageInfo() {}
54
55 DistilledPageInfo::~DistilledPageInfo() {}
56
57 DistilledPageInfo::MarkupArticle::MarkupArticle() {}
58
59 DistilledPageInfo::MarkupArticle::~MarkupArticle() {}
60
61 DistilledPageInfo::MarkupImage::MarkupImage() {}
62
63 DistilledPageInfo::MarkupImage::~MarkupImage() {}
64
65 DistilledPageInfo::MarkupInfo::MarkupInfo() {}
66
67 DistilledPageInfo::MarkupInfo::~MarkupInfo() {}
68
69 DistillerPageFactory::~DistillerPageFactory() {} 53 DistillerPageFactory::~DistillerPageFactory() {}
70 54
71 DistillerPage::DistillerPage() : ready_(true) {} 55 DistillerPage::DistillerPage() : ready_(true) {}
72 56
73 DistillerPage::~DistillerPage() {} 57 DistillerPage::~DistillerPage() {}
74 58
75 void DistillerPage::DistillPage( 59 void DistillerPage::DistillPage(
76 const GURL& gurl, 60 const GURL& gurl,
77 const dom_distiller::proto::DomDistillerOptions options, 61 const dom_distiller::proto::DomDistillerOptions options,
78 const DistillerPageCallback& callback) { 62 const DistillerPageCallback& callback) {
79 DCHECK(ready_); 63 DCHECK(ready_);
80 // It is only possible to distill one page at a time. |ready_| is reset when 64 // It is only possible to distill one page at a time. |ready_| is reset when
81 // the callback to OnDistillationDone happens. 65 // the callback to OnDistillationDone happens.
82 ready_ = false; 66 ready_ = false;
83 distiller_page_callback_ = callback; 67 distiller_page_callback_ = callback;
84 DistillPageImpl(gurl, GetDistillerScriptWithOptions(options)); 68 DistillPageImpl(gurl, GetDistillerScriptWithOptions(options));
85 } 69 }
86 70
87 void DistillerPage::OnDistillationDone(const GURL& page_url, 71 void DistillerPage::OnDistillationDone(const GURL& page_url,
88 const base::Value* value) { 72 const base::Value* value) {
89 DCHECK(!ready_); 73 DCHECK(!ready_);
90 ready_ = true; 74 ready_ = true;
91 75
92 scoped_ptr<DistilledPageInfo> page_info(new DistilledPageInfo()); 76 scoped_ptr<dom_distiller::proto::DomDistillerResult> distiller_result;
93 bool found_content = !value->IsType(base::Value::TYPE_NULL);
94 if (found_content) {
95 dom_distiller::proto::DomDistillerResult distiller_result =
96 dom_distiller::proto::json::DomDistillerResult::ReadFromValue(value);
97 77
98 page_info->title = distiller_result.title(); 78 bool found_content;
99 page_info->html = distiller_result.distilled_content().html(); 79 if (value->IsType(base::Value::TYPE_NULL)) {
100 page_info->next_page_url = distiller_result.pagination_info().next_page(); 80 found_content = false;
101 page_info->prev_page_url = distiller_result.pagination_info().prev_page(); 81 } else {
102 for (int i = 0; i < distiller_result.image_urls_size(); ++i) { 82 found_content = true;
103 const std::string image_url = distiller_result.image_urls(i); 83 distiller_result.reset(new dom_distiller::proto::DomDistillerResult(
104 if (GURL(image_url).is_valid()) { 84 dom_distiller::proto::json::DomDistillerResult::ReadFromValue(value)));
105 page_info->image_urls.push_back(image_url); 85 if (distiller_result->has_timing_info()) {
106 }
107 }
108 const dom_distiller::proto::MarkupInfo& src_markup_info =
109 distiller_result.markup_info();
110 DistilledPageInfo::MarkupInfo& dst_markup_info = page_info->markup_info;
111 dst_markup_info.title = src_markup_info.title();
112 dst_markup_info.type = src_markup_info.type();
113 dst_markup_info.url = src_markup_info.url();
114 dst_markup_info.description = src_markup_info.description();
115 dst_markup_info.publisher = src_markup_info.publisher();
116 dst_markup_info.copyright = src_markup_info.copyright();
117 dst_markup_info.author = src_markup_info.author();
118
119 const dom_distiller::proto::MarkupArticle& src_article =
120 src_markup_info.article();
121 DistilledPageInfo::MarkupArticle& dst_article = dst_markup_info.article;
122 dst_article.published_time = src_article.published_time();
123 dst_article.modified_time = src_article.modified_time();
124 dst_article.expiration_time = src_article.expiration_time();
125 dst_article.section = src_article.section();
126 for (int i = 0; i < src_article.authors_size(); ++i) {
127 dst_article.authors.push_back(src_article.authors(i));
128 }
129
130 for (int i = 0; i < src_markup_info.images_size(); ++i) {
131 const dom_distiller::proto::MarkupImage& src_image =
132 src_markup_info.images(i);
133 DistilledPageInfo::MarkupImage dst_image;
134 dst_image.url = src_image.url();
135 dst_image.secure_url = src_image.secure_url();
136 dst_image.type = src_image.type();
137 dst_image.caption = src_image.caption();
138 dst_image.width = src_image.width();
139 dst_image.height = src_image.height();
140 dst_markup_info.images.push_back(dst_image);
141 }
142 if (distiller_result.has_timing_info()) {
143 const dom_distiller::proto::TimingInfo& timing = 86 const dom_distiller::proto::TimingInfo& timing =
144 distiller_result.timing_info(); 87 distiller_result->timing_info();
145 if (timing.has_markup_parsing_time()) { 88 if (timing.has_markup_parsing_time()) {
146 UMA_HISTOGRAM_TIMES( 89 UMA_HISTOGRAM_TIMES(
147 "DomDistiller.Time.MarkupParsing", 90 "DomDistiller.Time.MarkupParsing",
148 base::TimeDelta::FromMillisecondsD(timing.markup_parsing_time())); 91 base::TimeDelta::FromMillisecondsD(timing.markup_parsing_time()));
149 } 92 }
150 if (timing.has_document_construction_time()) { 93 if (timing.has_document_construction_time()) {
151 UMA_HISTOGRAM_TIMES( 94 UMA_HISTOGRAM_TIMES(
152 "DomDistiller.Time.DocumentConstruction", 95 "DomDistiller.Time.DocumentConstruction",
153 base::TimeDelta::FromMillisecondsD( 96 base::TimeDelta::FromMillisecondsD(
154 timing.document_construction_time())); 97 timing.document_construction_time()));
(...skipping 12 matching lines...) Expand all
167 if (timing.has_total_time()) { 110 if (timing.has_total_time()) {
168 UMA_HISTOGRAM_TIMES( 111 UMA_HISTOGRAM_TIMES(
169 "DomDistiller.Time.DistillationTotal", 112 "DomDistiller.Time.DistillationTotal",
170 base::TimeDelta::FromMillisecondsD(timing.total_time())); 113 base::TimeDelta::FromMillisecondsD(timing.total_time()));
171 } 114 }
172 } 115 }
173 } 116 }
174 117
175 base::MessageLoop::current()->PostTask( 118 base::MessageLoop::current()->PostTask(
176 FROM_HERE, 119 FROM_HERE,
177 base::Bind( 120 base::Bind(distiller_page_callback_,
178 distiller_page_callback_, base::Passed(&page_info), found_content)); 121 base::Passed(&distiller_result),
122 found_content));
179 } 123 }
180 124
181 } // namespace dom_distiller 125 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « components/dom_distiller/core/distiller_page.h ('k') | components/dom_distiller/core/distiller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698