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/standalone/content_extractor_browsertest.cc

Issue 2712413002: Remove ScopedVector in //components/dom_distiller/ (Closed)
Patch Set: Remove ScopedVector in //components/dom_distiller/ Created 3 years, 9 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
« no previous file with comments | « components/dom_distiller/core/dom_distiller_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stddef.h> 5 #include <stddef.h>
6 #include <sstream> 6 #include <sstream>
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/files/scoped_temp_dir.h" 10 #include "base/files/scoped_temp_dir.h"
11 #include "base/id_map.h" 11 #include "base/id_map.h"
12 #include "base/location.h" 12 #include "base/location.h"
13 #include "base/memory/ptr_util.h"
13 #include "base/path_service.h" 14 #include "base/path_service.h"
14 #include "base/run_loop.h" 15 #include "base/run_loop.h"
15 #include "base/single_thread_task_runner.h" 16 #include "base/single_thread_task_runner.h"
16 #include "base/strings/string_number_conversions.h" 17 #include "base/strings/string_number_conversions.h"
17 #include "base/strings/string_split.h" 18 #include "base/strings/string_split.h"
18 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
19 #include "components/dom_distiller/content/browser/distiller_javascript_utils.h" 20 #include "components/dom_distiller/content/browser/distiller_javascript_utils.h"
20 #include "components/dom_distiller/content/browser/distiller_page_web_contents.h " 21 #include "components/dom_distiller/content/browser/distiller_page_web_contents.h "
21 #include "components/dom_distiller/core/article_entry.h" 22 #include "components/dom_distiller/core/article_entry.h"
22 #include "components/dom_distiller/core/distilled_page_prefs.h" 23 #include "components/dom_distiller/core/distilled_page_prefs.h"
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 viewer_handle_ = 242 viewer_handle_ =
242 service->ViewUrl(this, 243 service->ViewUrl(this,
243 service->CreateDefaultDistillerPage(render_view_size), 244 service->CreateDefaultDistillerPage(render_view_size),
244 url_); 245 url_);
245 } 246 }
246 247
247 DistilledArticleProto GetArticleCopy() { 248 DistilledArticleProto GetArticleCopy() {
248 return *article_proto_; 249 return *article_proto_;
249 } 250 }
250 251
251 static ScopedVector<ContentExtractionRequest> CreateForCommandLine( 252 static std::vector<std::unique_ptr<ContentExtractionRequest>>
252 const base::CommandLine& command_line, 253 CreateForCommandLine(const base::CommandLine& command_line,
253 FileToUrlMap* file_to_url_map) { 254 FileToUrlMap* file_to_url_map) {
254 ScopedVector<ContentExtractionRequest> requests; 255 std::vector<std::unique_ptr<ContentExtractionRequest>> requests;
255 if (command_line.HasSwitch(kUrlSwitch)) { 256 if (command_line.HasSwitch(kUrlSwitch)) {
256 GURL url; 257 GURL url;
257 std::string url_string = command_line.GetSwitchValueASCII(kUrlSwitch); 258 std::string url_string = command_line.GetSwitchValueASCII(kUrlSwitch);
258 url = GURL(url_string); 259 url = GURL(url_string);
259 if (url.is_valid()) { 260 if (url.is_valid()) {
260 requests.push_back(new ContentExtractionRequest(url)); 261 requests.push_back(base::WrapUnique(new ContentExtractionRequest(url)));
ke.he 2017/03/01 02:58:27 we use "base::WrapUnique" instead of "base::MakeUn
261 if (command_line.HasSwitch(kOriginalUrl)) { 262 if (command_line.HasSwitch(kOriginalUrl)) {
262 (*file_to_url_map)[url.spec()] = 263 (*file_to_url_map)[url.spec()] =
263 command_line.GetSwitchValueASCII(kOriginalUrl); 264 command_line.GetSwitchValueASCII(kOriginalUrl);
264 } 265 }
265 } 266 }
266 } else if (command_line.HasSwitch(kUrlsSwitch)) { 267 } else if (command_line.HasSwitch(kUrlsSwitch)) {
267 std::string urls_string = command_line.GetSwitchValueASCII(kUrlsSwitch); 268 std::string urls_string = command_line.GetSwitchValueASCII(kUrlsSwitch);
268 std::vector<std::string> urls = base::SplitString( 269 std::vector<std::string> urls = base::SplitString(
269 urls_string, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 270 urls_string, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
270 // Check for original-urls switch, which must exactly pair up with 271 // Check for original-urls switch, which must exactly pair up with
271 // |kUrlsSwitch| i.e. number of original urls must be same as that of 272 // |kUrlsSwitch| i.e. number of original urls must be same as that of
272 // urls. 273 // urls.
273 std::vector<std::string> original_urls; 274 std::vector<std::string> original_urls;
274 if (command_line.HasSwitch(kOriginalUrls)) { 275 if (command_line.HasSwitch(kOriginalUrls)) {
275 std::string original_urls_string = 276 std::string original_urls_string =
276 command_line.GetSwitchValueASCII(kOriginalUrls); 277 command_line.GetSwitchValueASCII(kOriginalUrls);
277 original_urls = base::SplitString( 278 original_urls = base::SplitString(
278 original_urls_string, " ", 279 original_urls_string, " ",
279 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); 280 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL);
280 if (original_urls.size() != urls.size()) 281 if (original_urls.size() != urls.size())
281 original_urls.clear(); 282 original_urls.clear();
282 } 283 }
283 for (size_t i = 0; i < urls.size(); ++i) { 284 for (size_t i = 0; i < urls.size(); ++i) {
284 GURL url(urls[i]); 285 GURL url(urls[i]);
285 if (url.is_valid()) { 286 if (url.is_valid()) {
286 requests.push_back(new ContentExtractionRequest(url)); 287 requests.push_back(
288 base::WrapUnique(new ContentExtractionRequest(url)));
287 // Only regard non-empty original urls. 289 // Only regard non-empty original urls.
288 if (!original_urls.empty() && !original_urls[i].empty()) { 290 if (!original_urls.empty() && !original_urls[i].empty()) {
289 (*file_to_url_map)[url.spec()] = original_urls[i]; 291 (*file_to_url_map)[url.spec()] = original_urls[i];
290 } 292 }
291 } else { 293 } else {
292 ADD_FAILURE() << "Bad url"; 294 ADD_FAILURE() << "Bad url";
293 } 295 }
294 } 296 }
295 } 297 }
296 if (requests.empty()) { 298 if (requests.empty()) {
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 } 426 }
425 427
426 size_t pending_tasks_; 428 size_t pending_tasks_;
427 size_t max_tasks_; 429 size_t max_tasks_;
428 size_t next_request_; 430 size_t next_request_;
429 431
430 base::ScopedTempDir db_dir_; 432 base::ScopedTempDir db_dir_;
431 std::unique_ptr<net::ScopedDefaultHostResolverProc> 433 std::unique_ptr<net::ScopedDefaultHostResolverProc>
432 mock_host_resolver_override_; 434 mock_host_resolver_override_;
433 std::unique_ptr<DomDistillerService> service_; 435 std::unique_ptr<DomDistillerService> service_;
434 ScopedVector<ContentExtractionRequest> requests_; 436 std::vector<std::unique_ptr<ContentExtractionRequest>> requests_;
435 437
436 std::string output_data_; 438 std::string output_data_;
437 std::unique_ptr<google::protobuf::io::StringOutputStream> 439 std::unique_ptr<google::protobuf::io::StringOutputStream>
438 protobuf_output_stream_; 440 protobuf_output_stream_;
439 }; 441 };
440 442
441 IN_PROC_BROWSER_TEST_F(ContentExtractor, MANUAL_ExtractUrl) { 443 IN_PROC_BROWSER_TEST_F(ContentExtractor, MANUAL_ExtractUrl) {
442 SetDistillerJavaScriptWorldId(content::ISOLATED_WORLD_ID_CONTENT_END); 444 SetDistillerJavaScriptWorldId(content::ISOLATED_WORLD_ID_CONTENT_END);
443 Start(); 445 Start();
444 base::RunLoop().Run(); 446 base::RunLoop().Run();
445 } 447 }
446 448
447 } // namespace dom_distiller 449 } // namespace dom_distiller
OLDNEW
« no previous file with comments | « components/dom_distiller/core/dom_distiller_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698