Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "headless/lib/headless_content_main_delegate.h" | 5 #include "headless/lib/headless_content_main_delegate.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| 11 #include "base/strings/string_number_conversions.h" | |
| 11 #include "base/trace_event/trace_event.h" | 12 #include "base/trace_event/trace_event.h" |
| 12 #include "content/public/browser/browser_main_runner.h" | 13 #include "content/public/browser/browser_main_runner.h" |
| 13 #include "content/public/common/content_switches.h" | 14 #include "content/public/common/content_switches.h" |
| 14 #include "headless/lib/browser/headless_browser_impl.h" | 15 #include "headless/lib/browser/headless_browser_impl.h" |
| 15 #include "headless/lib/browser/headless_content_browser_client.h" | 16 #include "headless/lib/browser/headless_content_browser_client.h" |
| 16 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 17 #include "ui/base/ui_base_switches.h" | 18 #include "ui/base/ui_base_switches.h" |
| 18 #include "ui/gfx/switches.h" | 19 #include "ui/gfx/switches.h" |
| 19 #include "ui/gl/gl_switches.h" | 20 #include "ui/gl/gl_switches.h" |
| 20 #include "ui/ozone/public/ozone_switches.h" | 21 #include "ui/ozone/public/ozone_switches.h" |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 command_line->AppendSwitchASCII(switches::kUseGL, | 64 command_line->AppendSwitchASCII(switches::kUseGL, |
| 64 browser_->options()->gl_implementation); | 65 browser_->options()->gl_implementation); |
| 65 } else { | 66 } else { |
| 66 command_line->AppendSwitch(switches::kDisableGpu); | 67 command_line->AppendSwitch(switches::kDisableGpu); |
| 67 } | 68 } |
| 68 | 69 |
| 69 SetContentClient(&content_client_); | 70 SetContentClient(&content_client_); |
| 70 return false; | 71 return false; |
| 71 } | 72 } |
| 72 | 73 |
| 74 void HeadlessContentMainDelegate::InitLogging( | |
| 75 const base::CommandLine& command_line) { | |
| 76 if (!command_line.HasSwitch(switches::kEnableLogging)) | |
| 77 return; | |
| 78 | |
| 79 logging::LoggingDestination log_mode; | |
| 80 base::FilePath log_filename(FILE_PATH_LITERAL("chrome_debug.log")); | |
| 81 if (command_line.GetSwitchValueASCII(switches::kEnableLogging) == "stderr") { | |
| 82 log_mode = logging::LOG_TO_SYSTEM_DEBUG_LOG; | |
| 83 } else { | |
| 84 base::FilePath custom_filename( | |
| 85 command_line.GetSwitchValuePath(switches::kEnableLogging)); | |
| 86 if (custom_filename.empty()) { | |
| 87 log_mode = logging::LOG_TO_ALL; | |
| 88 } else { | |
| 89 log_mode = logging::LOG_TO_FILE; | |
| 90 log_filename = custom_filename; | |
| 91 } | |
| 92 } | |
| 93 | |
| 94 if (command_line.HasSwitch(switches::kLoggingLevel) && | |
| 95 logging::GetMinLogLevel() >= 0) { | |
| 96 std::string log_level = | |
| 97 command_line.GetSwitchValueASCII(switches::kLoggingLevel); | |
| 98 int level = 0; | |
| 99 if (base::StringToInt(log_level, &level) && level >= 0 && | |
| 100 level < logging::LOG_NUM_SEVERITIES) { | |
| 101 logging::SetMinLogLevel(level); | |
| 102 } else { | |
| 103 DLOG(WARNING) << "Bad log level: " << log_level; | |
| 104 } | |
| 105 } | |
| 106 | |
| 107 base::FilePath log_path; | |
| 108 logging::LoggingSettings settings; | |
| 109 | |
| 110 if (PathService::Get(base::DIR_MODULE, &log_path)) { | |
| 111 log_path = log_path.Append(log_filename); | |
| 112 } else { | |
| 113 log_path = log_filename; | |
| 114 } | |
| 115 | |
| 116 settings.logging_dest = log_mode; | |
| 117 settings.log_file = log_path.value().c_str(); | |
| 118 settings.lock_log = logging::DONT_LOCK_LOG_FILE; | |
| 119 settings.delete_old = logging::DELETE_OLD_LOG_FILE; | |
|
Eric Seckler
2017/02/02 23:57:19
I think, in renderer processes, this shouldn't be
| |
| 120 bool success = logging::InitLogging(settings); | |
| 121 DCHECK(success); | |
| 122 } | |
| 123 | |
| 73 void HeadlessContentMainDelegate::PreSandboxStartup() { | 124 void HeadlessContentMainDelegate::PreSandboxStartup() { |
| 125 InitLogging(*base::CommandLine::ForCurrentProcess()); | |
| 74 InitializeResourceBundle(); | 126 InitializeResourceBundle(); |
| 75 } | 127 } |
| 76 | 128 |
| 77 int HeadlessContentMainDelegate::RunProcess( | 129 int HeadlessContentMainDelegate::RunProcess( |
| 78 const std::string& process_type, | 130 const std::string& process_type, |
| 79 const content::MainFunctionParams& main_function_params) { | 131 const content::MainFunctionParams& main_function_params) { |
| 80 if (!process_type.empty()) | 132 if (!process_type.empty()) |
| 81 return -1; | 133 return -1; |
| 82 | 134 |
| 83 base::trace_event::TraceLog::GetInstance()->SetProcessName("HeadlessBrowser"); | 135 base::trace_event::TraceLog::GetInstance()->SetProcessName("HeadlessBrowser"); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 pak_file, ui::SCALE_FACTOR_NONE); | 183 pak_file, ui::SCALE_FACTOR_NONE); |
| 132 } | 184 } |
| 133 | 185 |
| 134 content::ContentBrowserClient* | 186 content::ContentBrowserClient* |
| 135 HeadlessContentMainDelegate::CreateContentBrowserClient() { | 187 HeadlessContentMainDelegate::CreateContentBrowserClient() { |
| 136 browser_client_.reset(new HeadlessContentBrowserClient(browser_.get())); | 188 browser_client_.reset(new HeadlessContentBrowserClient(browser_.get())); |
| 137 return browser_client_.get(); | 189 return browser_client_.get(); |
| 138 } | 190 } |
| 139 | 191 |
| 140 } // namespace headless | 192 } // namespace headless |
| OLD | NEW |