OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <sstream> | 5 #include <sstream> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 ADD_FAILURE() << "No valid url provided"; | 193 ADD_FAILURE() << "No valid url provided"; |
194 } | 194 } |
195 | 195 |
196 return requests.Pass(); | 196 return requests.Pass(); |
197 } | 197 } |
198 | 198 |
199 private: | 199 private: |
200 ContentExtractionRequest(const GURL& url) : url_(url) {} | 200 ContentExtractionRequest(const GURL& url) : url_(url) {} |
201 | 201 |
202 virtual void OnArticleUpdated(ArticleDistillationUpdate article_update) | 202 virtual void OnArticleUpdated(ArticleDistillationUpdate article_update) |
203 OVERRIDE {} | 203 override {} |
204 | 204 |
205 virtual void OnArticleReady(const DistilledArticleProto* article_proto) | 205 virtual void OnArticleReady(const DistilledArticleProto* article_proto) |
206 OVERRIDE { | 206 override { |
207 article_proto_ = article_proto; | 207 article_proto_ = article_proto; |
208 CHECK(article_proto->pages_size()) << "Failed extracting " << url_; | 208 CHECK(article_proto->pages_size()) << "Failed extracting " << url_; |
209 base::MessageLoop::current()->PostTask( | 209 base::MessageLoop::current()->PostTask( |
210 FROM_HERE, | 210 FROM_HERE, |
211 finished_callback_); | 211 finished_callback_); |
212 } | 212 } |
213 | 213 |
214 const DistilledArticleProto* article_proto_; | 214 const DistilledArticleProto* article_proto_; |
215 scoped_ptr<ViewerHandle> viewer_handle_; | 215 scoped_ptr<ViewerHandle> viewer_handle_; |
216 GURL url_; | 216 GURL url_; |
217 base::Closure finished_callback_; | 217 base::Closure finished_callback_; |
218 }; | 218 }; |
219 | 219 |
220 class ContentExtractor : public ContentBrowserTest { | 220 class ContentExtractor : public ContentBrowserTest { |
221 public: | 221 public: |
222 ContentExtractor() | 222 ContentExtractor() |
223 : pending_tasks_(0), | 223 : pending_tasks_(0), |
224 max_tasks_(kMaxExtractorTasks), | 224 max_tasks_(kMaxExtractorTasks), |
225 next_request_(0), | 225 next_request_(0), |
226 output_data_(), | 226 output_data_(), |
227 protobuf_output_stream_( | 227 protobuf_output_stream_( |
228 new google::protobuf::io::StringOutputStream(&output_data_)) {} | 228 new google::protobuf::io::StringOutputStream(&output_data_)) {} |
229 | 229 |
230 // Change behavior of the default host resolver to avoid DNS lookup errors, so | 230 // Change behavior of the default host resolver to avoid DNS lookup errors, so |
231 // we can make network calls. | 231 // we can make network calls. |
232 virtual void SetUpOnMainThread() OVERRIDE { | 232 virtual void SetUpOnMainThread() override { |
233 if (!CommandLine::ForCurrentProcess()->HasSwitch(kDisableDnsSwitch)) { | 233 if (!CommandLine::ForCurrentProcess()->HasSwitch(kDisableDnsSwitch)) { |
234 EnableDNSLookupForThisTest(); | 234 EnableDNSLookupForThisTest(); |
235 } | 235 } |
236 CHECK(db_dir_.CreateUniqueTempDir()); | 236 CHECK(db_dir_.CreateUniqueTempDir()); |
237 AddComponentsResources(); | 237 AddComponentsResources(); |
238 } | 238 } |
239 | 239 |
240 virtual void TearDownOnMainThread() OVERRIDE { | 240 virtual void TearDownOnMainThread() override { |
241 DisableDNSLookupForThisTest(); | 241 DisableDNSLookupForThisTest(); |
242 } | 242 } |
243 | 243 |
244 protected: | 244 protected: |
245 // Creates the DomDistillerService and creates and starts the extraction | 245 // Creates the DomDistillerService and creates and starts the extraction |
246 // request. | 246 // request. |
247 void Start() { | 247 void Start() { |
248 content::BrowserContext* context = | 248 content::BrowserContext* context = |
249 shell()->web_contents()->GetBrowserContext(); | 249 shell()->web_contents()->GetBrowserContext(); |
250 service_ = CreateDomDistillerService(context, | 250 service_ = CreateDomDistillerService(context, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 std::string output_data_; | 332 std::string output_data_; |
333 scoped_ptr<google::protobuf::io::StringOutputStream> protobuf_output_stream_; | 333 scoped_ptr<google::protobuf::io::StringOutputStream> protobuf_output_stream_; |
334 }; | 334 }; |
335 | 335 |
336 IN_PROC_BROWSER_TEST_F(ContentExtractor, MANUAL_ExtractUrl) { | 336 IN_PROC_BROWSER_TEST_F(ContentExtractor, MANUAL_ExtractUrl) { |
337 Start(); | 337 Start(); |
338 base::RunLoop().Run(); | 338 base::RunLoop().Run(); |
339 } | 339 } |
340 | 340 |
341 } // namespace dom_distiller | 341 } // namespace dom_distiller |
OLD | NEW |