Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(304)

Side by Side Diff: headless/lib/headless_content_main_delegate.cc

Issue 2762593002: Add --headless flag to Windows (Closed)
Patch Set: added TODO Created 3 years, 7 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 | « headless/lib/headless_content_main_delegate.h ('k') | headless/public/headless_browser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <utility> 7 #include <utility>
8 8
9 #include "base/base_switches.h" 9 #include "base/base_switches.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/environment.h" 11 #include "base/environment.h"
12 #include "base/files/file_util.h" 12 #include "base/files/file_util.h"
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/path_service.h" 14 #include "base/path_service.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/strings/string_number_conversions.h" 16 #include "base/strings/string_number_conversions.h"
17 #include "base/trace_event/trace_event.h" 17 #include "base/trace_event/trace_event.h"
18 #include "components/crash/content/app/breakpad_linux.h" 18 #include "components/crash/content/app/breakpad_linux.h"
19 #include "content/public/browser/browser_main_runner.h" 19 #include "content/public/browser/browser_main_runner.h"
20 #include "content/public/common/content_switches.h" 20 #include "content/public/common/content_switches.h"
21 #include "headless/lib/browser/headless_browser_impl.h" 21 #include "headless/lib/browser/headless_browser_impl.h"
22 #include "headless/lib/browser/headless_content_browser_client.h" 22 #include "headless/lib/browser/headless_content_browser_client.h"
23 #include "headless/lib/headless_crash_reporter_client.h" 23 #include "headless/lib/headless_crash_reporter_client.h"
24 #include "headless/lib/headless_macros.h" 24 #include "headless/lib/headless_macros.h"
25 #include "headless/lib/renderer/headless_content_renderer_client.h"
26 #include "ui/base/resource/resource_bundle.h" 25 #include "ui/base/resource/resource_bundle.h"
27 #include "ui/base/ui_base_switches.h" 26 #include "ui/base/ui_base_switches.h"
28 #include "ui/gfx/switches.h" 27 #include "ui/gfx/switches.h"
29 #include "ui/gl/gl_switches.h" 28 #include "ui/gl/gl_switches.h"
30 #include "ui/ozone/public/ozone_switches.h" 29 #include "ui/ozone/public/ozone_switches.h"
31 30
32 #ifdef HEADLESS_USE_EMBEDDED_RESOURCES 31 #ifdef HEADLESS_USE_EMBEDDED_RESOURCES
33 #include "headless/embedded_resource_pak.h" 32 #include "headless/embedded_resource_pak.h"
34 #endif 33 #endif
35 34
36 #if defined(OS_MACOSX) 35 #if defined(OS_MACOSX)
37 #include "components/crash/content/app/crashpad.h" 36 #include "components/crash/content/app/crashpad.h"
38 #endif 37 #endif
39 38
39 #if !defined(CHROME_MULTIPLE_DLL_BROWSER)
40 #include "headless/lib/renderer/headless_content_renderer_client.h"
41 #endif
42
40 namespace headless { 43 namespace headless {
41 namespace { 44 namespace {
42 // Keep in sync with content/common/content_constants_internal.h. 45 // Keep in sync with content/common/content_constants_internal.h.
43 // TODO(skyostil): Add a tracing test for this. 46 // TODO(skyostil): Add a tracing test for this.
44 const int kTraceEventBrowserProcessSortIndex = -6; 47 const int kTraceEventBrowserProcessSortIndex = -6;
45 48
46 HeadlessContentMainDelegate* g_current_headless_content_main_delegate = nullptr; 49 HeadlessContentMainDelegate* g_current_headless_content_main_delegate = nullptr;
47 50
48 base::LazyInstance<HeadlessCrashReporterClient>::Leaky g_headless_crash_client = 51 base::LazyInstance<HeadlessCrashReporterClient>::Leaky g_headless_crash_client =
49 LAZY_INSTANCE_INITIALIZER; 52 LAZY_INSTANCE_INITIALIZER;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } else { 91 } else {
89 command_line->AppendSwitch(switches::kDisableGpu); 92 command_line->AppendSwitch(switches::kDisableGpu);
90 } 93 }
91 94
92 SetContentClient(&content_client_); 95 SetContentClient(&content_client_);
93 return false; 96 return false;
94 } 97 }
95 98
96 void HeadlessContentMainDelegate::InitLogging( 99 void HeadlessContentMainDelegate::InitLogging(
97 const base::CommandLine& command_line) { 100 const base::CommandLine& command_line) {
101 const std::string process_type =
102 command_line.GetSwitchValueASCII(switches::kProcessType);
98 #if !defined(OS_WIN) 103 #if !defined(OS_WIN)
99 if (!command_line.HasSwitch(switches::kEnableLogging)) 104 if (!command_line.HasSwitch(switches::kEnableLogging))
100 return; 105 return;
101 #endif 106 #else
107 // Child processes in Windows are not able to initialize logging.
108 if (!process_type.empty())
109 return;
110 #endif // !defined(OS_WIN)
102 111
103 logging::LoggingDestination log_mode; 112 logging::LoggingDestination log_mode;
104 base::FilePath log_filename(FILE_PATH_LITERAL("chrome_debug.log")); 113 base::FilePath log_filename(FILE_PATH_LITERAL("chrome_debug.log"));
105 if (command_line.GetSwitchValueASCII(switches::kEnableLogging) == "stderr") { 114 if (command_line.GetSwitchValueASCII(switches::kEnableLogging) == "stderr") {
106 log_mode = logging::LOG_TO_SYSTEM_DEBUG_LOG; 115 log_mode = logging::LOG_TO_SYSTEM_DEBUG_LOG;
107 } else { 116 } else {
108 base::FilePath custom_filename( 117 base::FilePath custom_filename(
109 command_line.GetSwitchValuePath(switches::kEnableLogging)); 118 command_line.GetSwitchValuePath(switches::kEnableLogging));
110 if (custom_filename.empty()) { 119 if (custom_filename.empty()) {
111 log_mode = logging::LOG_TO_ALL; 120 log_mode = logging::LOG_TO_ALL;
(...skipping 24 matching lines...) Expand all
136 } else { 145 } else {
137 log_path = log_filename; 146 log_path = log_filename;
138 } 147 }
139 148
140 std::string filename; 149 std::string filename;
141 std::unique_ptr<base::Environment> env(base::Environment::Create()); 150 std::unique_ptr<base::Environment> env(base::Environment::Create());
142 if (env->GetVar(kLogFileName, &filename) && !filename.empty()) { 151 if (env->GetVar(kLogFileName, &filename) && !filename.empty()) {
143 log_path = base::FilePath::FromUTF8Unsafe(filename); 152 log_path = base::FilePath::FromUTF8Unsafe(filename);
144 } 153 }
145 154
146 const std::string process_type =
147 command_line.GetSwitchValueASCII(switches::kProcessType);
148
149 settings.logging_dest = log_mode; 155 settings.logging_dest = log_mode;
150 settings.log_file = log_path.value().c_str(); 156 settings.log_file = log_path.value().c_str();
151 settings.lock_log = logging::DONT_LOCK_LOG_FILE; 157 settings.lock_log = logging::DONT_LOCK_LOG_FILE;
152 settings.delete_old = process_type.empty() ? logging::DELETE_OLD_LOG_FILE 158 settings.delete_old = process_type.empty() ? logging::DELETE_OLD_LOG_FILE
153 : logging::APPEND_TO_OLD_LOG_FILE; 159 : logging::APPEND_TO_OLD_LOG_FILE;
154 bool success = logging::InitLogging(settings); 160 bool success = logging::InitLogging(settings);
155 DCHECK(success); 161 DCHECK(success);
156 } 162 }
157 163
158 void HeadlessContentMainDelegate::InitCrashReporter( 164 void HeadlessContentMainDelegate::InitCrashReporter(
(...skipping 28 matching lines...) Expand all
187 if (command_line.HasSwitch(switches::kEnableLogging)) 193 if (command_line.HasSwitch(switches::kEnableLogging))
188 InitLogging(command_line); 194 InitLogging(command_line);
189 #endif // defined(OS_WIN) 195 #endif // defined(OS_WIN)
190 InitCrashReporter(command_line); 196 InitCrashReporter(command_line);
191 InitializeResourceBundle(); 197 InitializeResourceBundle();
192 } 198 }
193 199
194 int HeadlessContentMainDelegate::RunProcess( 200 int HeadlessContentMainDelegate::RunProcess(
195 const std::string& process_type, 201 const std::string& process_type,
196 const content::MainFunctionParams& main_function_params) { 202 const content::MainFunctionParams& main_function_params) {
203 // TODO(dvallet): Consider making a Windows specific class to make specific
204 // child builds clearer.
205 #if !defined(CHROME_MULTIPLE_DLL_CHILD)
206
197 if (!process_type.empty()) 207 if (!process_type.empty())
198 return -1; 208 return -1;
199 209
200 base::trace_event::TraceLog::GetInstance()->SetProcessName("HeadlessBrowser"); 210 base::trace_event::TraceLog::GetInstance()->SetProcessName("HeadlessBrowser");
201 base::trace_event::TraceLog::GetInstance()->SetProcessSortIndex( 211 base::trace_event::TraceLog::GetInstance()->SetProcessSortIndex(
202 kTraceEventBrowserProcessSortIndex); 212 kTraceEventBrowserProcessSortIndex);
203 213
204 std::unique_ptr<content::BrowserMainRunner> browser_runner( 214 std::unique_ptr<content::BrowserMainRunner> browser_runner(
205 content::BrowserMainRunner::Create()); 215 content::BrowserMainRunner::Create());
206 216
207 int exit_code = browser_runner->Initialize(main_function_params); 217 int exit_code = browser_runner->Initialize(main_function_params);
208 DCHECK_LT(exit_code, 0) << "content::BrowserMainRunner::Initialize failed in " 218 DCHECK_LT(exit_code, 0) << "content::BrowserMainRunner::Initialize failed in "
209 "HeadlessContentMainDelegate::RunProcess"; 219 "HeadlessContentMainDelegate::RunProcess";
210 220
211 browser_->RunOnStartCallback(); 221 browser_->RunOnStartCallback();
212 browser_runner->Run(); 222 browser_runner->Run();
213 browser_.reset(); 223 browser_.reset();
214 browser_runner->Shutdown(); 224 browser_runner->Shutdown();
215 225
216 // Return value >=0 here to disable calling content::BrowserMain. 226 // Return value >=0 here to disable calling content::BrowserMain.
217 return 0; 227 return 0;
228 #else
229 return -1;
230 #endif // !defined(CHROME_MULTIPLE_DLL_CHILD)
218 } 231 }
219 232
220 #if !defined(OS_MACOSX) && defined(OS_POSIX) && !defined(OS_ANDROID) 233 #if !defined(OS_MACOSX) && defined(OS_POSIX) && !defined(OS_ANDROID)
221 void HeadlessContentMainDelegate::ZygoteForked() { 234 void HeadlessContentMainDelegate::ZygoteForked() {
222 const base::CommandLine& command_line( 235 const base::CommandLine& command_line(
223 *base::CommandLine::ForCurrentProcess()); 236 *base::CommandLine::ForCurrentProcess());
224 const std::string process_type = 237 const std::string process_type =
225 command_line.GetSwitchValueASCII(switches::kProcessType); 238 command_line.GetSwitchValueASCII(switches::kProcessType);
226 // Unconditionally try to turn on crash reporting since we do not have access 239 // Unconditionally try to turn on crash reporting since we do not have access
227 // to the latest browser options at this point when testing. Breakpad will 240 // to the latest browser options at this point when testing. Breakpad will
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 if (!base::PathExists(pak_file)) 281 if (!base::PathExists(pak_file))
269 pak_file = dir_module.Append(FILE_PATH_LITERAL("Resources/resources.pak")); 282 pak_file = dir_module.Append(FILE_PATH_LITERAL("Resources/resources.pak"));
270 #endif 283 #endif
271 ResourceBundle::GetSharedInstance().AddDataPackFromPath( 284 ResourceBundle::GetSharedInstance().AddDataPackFromPath(
272 pak_file, ui::SCALE_FACTOR_NONE); 285 pak_file, ui::SCALE_FACTOR_NONE);
273 #endif 286 #endif
274 } 287 }
275 288
276 content::ContentBrowserClient* 289 content::ContentBrowserClient*
277 HeadlessContentMainDelegate::CreateContentBrowserClient() { 290 HeadlessContentMainDelegate::CreateContentBrowserClient() {
291 #if defined(CHROME_MULTIPLE_DLL_CHILD)
292 return nullptr;
293 #else
278 browser_client_ = 294 browser_client_ =
279 base::MakeUnique<HeadlessContentBrowserClient>(browser_.get()); 295 base::MakeUnique<HeadlessContentBrowserClient>(browser_.get());
280 return browser_client_.get(); 296 return browser_client_.get();
297 #endif
281 } 298 }
282 299
283 content::ContentRendererClient* 300 content::ContentRendererClient*
284 HeadlessContentMainDelegate::CreateContentRendererClient() { 301 HeadlessContentMainDelegate::CreateContentRendererClient() {
302 #if defined(CHROME_MULTIPLE_DLL_BROWSER)
303 return nullptr;
304 #else
285 renderer_client_ = base::MakeUnique<HeadlessContentRendererClient>(); 305 renderer_client_ = base::MakeUnique<HeadlessContentRendererClient>();
286 return renderer_client_.get(); 306 return renderer_client_.get();
307 #endif
287 } 308 }
288 309
289 } // namespace headless 310 } // namespace headless
OLDNEW
« no previous file with comments | « headless/lib/headless_content_main_delegate.h ('k') | headless/public/headless_browser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698