Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 <memory> | 5 #include <memory> |
| 6 #include <sstream> | 6 #include <sstream> |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/base64.h" | 9 #include "base/base64.h" |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| 11 #include "base/callback.h" | 11 #include "base/callback.h" |
| 12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
| 13 #include "base/files/file_path.h" | 13 #include "base/files/file_path.h" |
| 14 #include "base/json/json_writer.h" | 14 #include "base/json/json_writer.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/memory/weak_ptr.h" | 18 #include "base/memory/weak_ptr.h" |
| 19 #include "base/numerics/safe_conversions.h" | 19 #include "base/numerics/safe_conversions.h" |
| 20 #include "base/path_service.h" | |
| 20 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 21 #include "content/public/common/content_switches.h" | 22 #include "content/public/common/content_switches.h" |
| 22 #include "headless/app/headless_shell_switches.h" | 23 #include "headless/app/headless_shell_switches.h" |
| 23 #include "headless/public/devtools/domains/emulation.h" | 24 #include "headless/public/devtools/domains/emulation.h" |
| 24 #include "headless/public/devtools/domains/inspector.h" | 25 #include "headless/public/devtools/domains/inspector.h" |
| 25 #include "headless/public/devtools/domains/page.h" | 26 #include "headless/public/devtools/domains/page.h" |
| 26 #include "headless/public/devtools/domains/runtime.h" | 27 #include "headless/public/devtools/domains/runtime.h" |
| 27 #include "headless/public/headless_browser.h" | 28 #include "headless/public/headless_browser.h" |
| 28 #include "headless/public/headless_devtools_client.h" | 29 #include "headless/public/headless_devtools_client.h" |
| 29 #include "headless/public/headless_devtools_target.h" | 30 #include "headless/public/headless_devtools_target.h" |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 return false; | 430 return false; |
| 430 } | 431 } |
| 431 if (command_line.HasSwitch(switches::kVirtualTimeBudget)) { | 432 if (command_line.HasSwitch(switches::kVirtualTimeBudget)) { |
| 432 LOG(ERROR) << "Virtual time budget is disabled " | 433 LOG(ERROR) << "Virtual time budget is disabled " |
| 433 << "when remote debugging is enabled."; | 434 << "when remote debugging is enabled."; |
| 434 return false; | 435 return false; |
| 435 } | 436 } |
| 436 return true; | 437 return true; |
| 437 } | 438 } |
| 438 | 439 |
| 440 void InitLogging(const base::CommandLine& command_line) { | |
| 441 if (!command_line.HasSwitch(switches::kEnableLogging)) | |
| 442 return; | |
| 443 | |
| 444 logging::LoggingDestination log_mode; | |
| 445 if (command_line.GetSwitchValueASCII(switches::kEnableLogging) == "stderr") { | |
| 446 log_mode = logging::LOG_TO_SYSTEM_DEBUG_LOG; | |
| 447 } else { | |
| 448 log_mode = logging::LOG_TO_ALL; | |
| 449 } | |
| 450 | |
| 451 if (command_line.HasSwitch(switches::kLoggingLevel) && | |
| 452 logging::GetMinLogLevel() >= 0) { | |
| 453 std::string log_level = | |
| 454 command_line.GetSwitchValueASCII(switches::kLoggingLevel); | |
| 455 int level = 0; | |
| 456 if (base::StringToInt(log_level, &level) && level >= 0 && | |
| 457 level < logging::LOG_NUM_SEVERITIES) { | |
| 458 logging::SetMinLogLevel(level); | |
| 459 } else { | |
| 460 DLOG(WARNING) << "Bad log level: " << log_level; | |
| 461 } | |
| 462 } | |
| 463 | |
| 464 const base::FilePath log_filename(FILE_PATH_LITERAL("chrome_debug.log")); | |
|
altimin
2017/02/02 22:44:45
Let's make output file configurable. We can use va
Sami
2017/02/02 23:15:33
Done.
| |
| 465 base::FilePath log_path; | |
| 466 logging::LoggingSettings settings; | |
| 467 | |
| 468 if (PathService::Get(base::DIR_MODULE, &log_path)) { | |
| 469 log_path = log_path.Append(log_filename); | |
| 470 } else { | |
| 471 log_path = log_filename; | |
| 472 } | |
| 473 | |
| 474 settings.logging_dest = log_mode; | |
| 475 settings.log_file = log_path.value().c_str(); | |
| 476 settings.lock_log = logging::DONT_LOCK_LOG_FILE; | |
| 477 settings.delete_old = logging::DELETE_OLD_LOG_FILE; | |
| 478 bool success = logging::InitLogging(settings); | |
| 479 DCHECK(success); | |
| 480 } | |
| 481 | |
| 439 int HeadlessShellMain(int argc, const char** argv) { | 482 int HeadlessShellMain(int argc, const char** argv) { |
| 440 RunChildProcessIfNeeded(argc, argv); | 483 RunChildProcessIfNeeded(argc, argv); |
| 441 HeadlessShell shell; | 484 HeadlessShell shell; |
| 442 HeadlessBrowser::Options::Builder builder(argc, argv); | 485 HeadlessBrowser::Options::Builder builder(argc, argv); |
| 443 | 486 |
| 444 // Enable devtools if requested. | 487 // Enable devtools if requested. |
| 445 base::CommandLine command_line(argc, argv); | 488 base::CommandLine::Init(argc, argv); |
| 489 const base::CommandLine& command_line( | |
| 490 *base::CommandLine::ForCurrentProcess()); | |
| 491 InitLogging(command_line); | |
| 446 if (!ValidateCommandLine(command_line)) | 492 if (!ValidateCommandLine(command_line)) |
| 447 return EXIT_FAILURE; | 493 return EXIT_FAILURE; |
| 448 | 494 |
| 449 if (command_line.HasSwitch(::switches::kRemoteDebuggingPort)) { | 495 if (command_line.HasSwitch(::switches::kRemoteDebuggingPort)) { |
| 450 std::string address = kDevToolsHttpServerAddress; | 496 std::string address = kDevToolsHttpServerAddress; |
| 451 if (command_line.HasSwitch(switches::kRemoteDebuggingAddress)) { | 497 if (command_line.HasSwitch(switches::kRemoteDebuggingAddress)) { |
| 452 address = | 498 address = |
| 453 command_line.GetSwitchValueASCII(switches::kRemoteDebuggingAddress); | 499 command_line.GetSwitchValueASCII(switches::kRemoteDebuggingAddress); |
| 454 net::IPAddress parsed_address; | 500 net::IPAddress parsed_address; |
| 455 if (!net::ParseURLHostnameToAddress(address, &parsed_address)) { | 501 if (!net::ParseURLHostnameToAddress(address, &parsed_address)) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 515 builder.SetOverrideWebPreferencesCallback(base::Bind([]( | 561 builder.SetOverrideWebPreferencesCallback(base::Bind([]( |
| 516 WebPreferences* preferences) { preferences->hide_scrollbars = true; })); | 562 WebPreferences* preferences) { preferences->hide_scrollbars = true; })); |
| 517 } | 563 } |
| 518 | 564 |
| 519 return HeadlessBrowserMain( | 565 return HeadlessBrowserMain( |
| 520 builder.Build(), | 566 builder.Build(), |
| 521 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); | 567 base::Bind(&HeadlessShell::OnStart, base::Unretained(&shell))); |
| 522 } | 568 } |
| 523 | 569 |
| 524 } // namespace headless | 570 } // namespace headless |
| OLD | NEW |