| 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 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 output << "URL: " << page.url() << std::endl; | 144 output << "URL: " << page.url() << std::endl; |
| 145 output << "Content: " << page.html() << std::endl; | 145 output << "Content: " << page.html() << std::endl; |
| 146 } | 146 } |
| 147 return output.str(); | 147 return output.str(); |
| 148 } | 148 } |
| 149 | 149 |
| 150 } // namespace | 150 } // namespace |
| 151 | 151 |
| 152 class ContentExtractionRequest : public ViewRequestDelegate { | 152 class ContentExtractionRequest : public ViewRequestDelegate { |
| 153 public: | 153 public: |
| 154 void Start(DomDistillerService* service, base::Closure finished_callback) { | 154 void Start(DomDistillerService* service, const gfx::Size& render_view_size, |
| 155 base::Closure finished_callback) { |
| 155 finished_callback_ = finished_callback; | 156 finished_callback_ = finished_callback; |
| 156 viewer_handle_ = | 157 viewer_handle_ = |
| 157 service->ViewUrl(this, service->CreateDefaultDistillerPage(), url_); | 158 service->ViewUrl(this, |
| 159 service->CreateDefaultDistillerPage(render_view_size), |
| 160 url_); |
| 158 } | 161 } |
| 159 | 162 |
| 160 DistilledArticleProto GetArticleCopy() { | 163 DistilledArticleProto GetArticleCopy() { |
| 161 return *article_proto_; | 164 return *article_proto_; |
| 162 } | 165 } |
| 163 | 166 |
| 164 static ScopedVector<ContentExtractionRequest> CreateForCommandLine( | 167 static ScopedVector<ContentExtractionRequest> CreateForCommandLine( |
| 165 const CommandLine& command_line) { | 168 const CommandLine& command_line) { |
| 166 ScopedVector<ContentExtractionRequest> requests; | 169 ScopedVector<ContentExtractionRequest> requests; |
| 167 if (command_line.HasSwitch(kUrlSwitch)) { | 170 if (command_line.HasSwitch(kUrlSwitch)) { |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 245 db_dir_.path()); | 248 db_dir_.path()); |
| 246 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); | 249 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); |
| 247 requests_ = ContentExtractionRequest::CreateForCommandLine(command_line); | 250 requests_ = ContentExtractionRequest::CreateForCommandLine(command_line); |
| 248 PumpQueue(); | 251 PumpQueue(); |
| 249 } | 252 } |
| 250 | 253 |
| 251 void PumpQueue() { | 254 void PumpQueue() { |
| 252 while (pending_tasks_ < max_tasks_ && next_request_ < requests_.size()) { | 255 while (pending_tasks_ < max_tasks_ && next_request_ < requests_.size()) { |
| 253 requests_[next_request_]->Start( | 256 requests_[next_request_]->Start( |
| 254 service_.get(), | 257 service_.get(), |
| 258 shell()->web_contents()->GetContainerBounds().size(), |
| 255 base::Bind(&ContentExtractor::FinishRequest, base::Unretained(this))); | 259 base::Bind(&ContentExtractor::FinishRequest, base::Unretained(this))); |
| 256 ++next_request_; | 260 ++next_request_; |
| 257 ++pending_tasks_; | 261 ++pending_tasks_; |
| 258 } | 262 } |
| 259 } | 263 } |
| 260 | 264 |
| 261 private: | 265 private: |
| 262 // Change behavior of the default host resolver to allow DNS lookup | 266 // Change behavior of the default host resolver to allow DNS lookup |
| 263 // to proceed instead of being blocked by the test infrastructure. | 267 // to proceed instead of being blocked by the test infrastructure. |
| 264 void EnableDNSLookupForThisTest() { | 268 void EnableDNSLookupForThisTest() { |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 std::string output_data_; | 329 std::string output_data_; |
| 326 scoped_ptr<google::protobuf::io::StringOutputStream> protobuf_output_stream_; | 330 scoped_ptr<google::protobuf::io::StringOutputStream> protobuf_output_stream_; |
| 327 }; | 331 }; |
| 328 | 332 |
| 329 IN_PROC_BROWSER_TEST_F(ContentExtractor, MANUAL_ExtractUrl) { | 333 IN_PROC_BROWSER_TEST_F(ContentExtractor, MANUAL_ExtractUrl) { |
| 330 Start(); | 334 Start(); |
| 331 base::RunLoop().Run(); | 335 base::RunLoop().Run(); |
| 332 } | 336 } |
| 333 | 337 |
| 334 } // namespace dom_distiller | 338 } // namespace dom_distiller |
| OLD | NEW |