| 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/base_switches.h" | 7 #include "base/base_switches.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 } | 140 } |
| 141 | 141 |
| 142 void HeadlessContentMainDelegate::InitCrashReporter( | 142 void HeadlessContentMainDelegate::InitCrashReporter( |
| 143 const base::CommandLine& command_line) { | 143 const base::CommandLine& command_line) { |
| 144 const std::string process_type = | 144 const std::string process_type = |
| 145 command_line.GetSwitchValueASCII(switches::kProcessType); | 145 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 146 crash_reporter::SetCrashReporterClient(g_headless_crash_client.Pointer()); | 146 crash_reporter::SetCrashReporterClient(g_headless_crash_client.Pointer()); |
| 147 g_headless_crash_client.Pointer()->set_crash_dumps_dir( | 147 g_headless_crash_client.Pointer()->set_crash_dumps_dir( |
| 148 browser_->options()->crash_dumps_dir); | 148 browser_->options()->crash_dumps_dir); |
| 149 | 149 |
| 150 #if !defined(OS_MACOSX) |
| 150 if (!browser_->options()->enable_crash_reporter) { | 151 if (!browser_->options()->enable_crash_reporter) { |
| 151 DCHECK(!breakpad::IsCrashReporterEnabled()); | 152 DCHECK(!breakpad::IsCrashReporterEnabled()); |
| 152 return; | 153 return; |
| 153 } | 154 } |
| 154 #if defined(HEADLESS_USE_BREAKPAD) | 155 #if defined(HEADLESS_USE_BREAKPAD) |
| 155 if (process_type != switches::kZygoteProcess) | 156 if (process_type != switches::kZygoteProcess) |
| 156 breakpad::InitCrashReporter(process_type); | 157 breakpad::InitCrashReporter(process_type); |
| 157 #endif // defined(HEADLESS_USE_BREAKPAD) | 158 #endif // defined(HEADLESS_USE_BREAKPAD) |
| 159 #endif // !defined(OS_MACOSX) |
| 158 } | 160 } |
| 159 | 161 |
| 160 void HeadlessContentMainDelegate::PreSandboxStartup() { | 162 void HeadlessContentMainDelegate::PreSandboxStartup() { |
| 161 const base::CommandLine& command_line( | 163 const base::CommandLine& command_line( |
| 162 *base::CommandLine::ForCurrentProcess()); | 164 *base::CommandLine::ForCurrentProcess()); |
| 163 #if defined(OS_WIN) | 165 #if defined(OS_WIN) |
| 164 // Windows always needs to initialize logging, otherwise you get a renderer | 166 // Windows always needs to initialize logging, otherwise you get a renderer |
| 165 // crash. | 167 // crash. |
| 166 InitLogging(command_line); | 168 InitLogging(command_line); |
| 167 #else | 169 #else |
| 168 if (command_line.HasSwitch(switches::kEnableLogging)) | 170 if (command_line.HasSwitch(switches::kEnableLogging)) |
| 169 InitLogging(command_line); | 171 InitLogging(command_line); |
| 170 #endif | 172 #endif |
| 173 #if !defined(OS_MACOSX) |
| 171 InitCrashReporter(command_line); | 174 InitCrashReporter(command_line); |
| 175 #endif |
| 172 InitializeResourceBundle(); | 176 InitializeResourceBundle(); |
| 173 } | 177 } |
| 174 | 178 |
| 175 int HeadlessContentMainDelegate::RunProcess( | 179 int HeadlessContentMainDelegate::RunProcess( |
| 176 const std::string& process_type, | 180 const std::string& process_type, |
| 177 const content::MainFunctionParams& main_function_params) { | 181 const content::MainFunctionParams& main_function_params) { |
| 178 if (!process_type.empty()) | 182 if (!process_type.empty()) |
| 179 return -1; | 183 return -1; |
| 180 | 184 |
| 181 base::trace_event::TraceLog::GetInstance()->SetProcessName("HeadlessBrowser"); | 185 base::trace_event::TraceLog::GetInstance()->SetProcessName("HeadlessBrowser"); |
| 182 base::trace_event::TraceLog::GetInstance()->SetProcessSortIndex( | 186 base::trace_event::TraceLog::GetInstance()->SetProcessSortIndex( |
| 183 kTraceEventBrowserProcessSortIndex); | 187 kTraceEventBrowserProcessSortIndex); |
| 184 | 188 |
| 185 std::unique_ptr<content::BrowserMainRunner> browser_runner( | 189 std::unique_ptr<content::BrowserMainRunner> browser_runner( |
| 186 content::BrowserMainRunner::Create()); | 190 content::BrowserMainRunner::Create()); |
| 187 | 191 |
| 188 int exit_code = browser_runner->Initialize(main_function_params); | 192 int exit_code = browser_runner->Initialize(main_function_params); |
| 189 DCHECK_LT(exit_code, 0) << "content::BrowserMainRunner::Initialize failed in " | 193 DCHECK_LT(exit_code, 0) << "content::BrowserMainRunner::Initialize failed in " |
| 190 "HeadlessContentMainDelegate::RunProcess"; | 194 "HeadlessContentMainDelegate::RunProcess"; |
| 191 | 195 |
| 192 browser_->RunOnStartCallback(); | 196 browser_->RunOnStartCallback(); |
| 193 browser_runner->Run(); | 197 browser_runner->Run(); |
| 194 browser_.reset(); | 198 browser_.reset(); |
| 195 browser_runner->Shutdown(); | 199 browser_runner->Shutdown(); |
| 196 | 200 |
| 197 // Return value >=0 here to disable calling content::BrowserMain. | 201 // Return value >=0 here to disable calling content::BrowserMain. |
| 198 return 0; | 202 return 0; |
| 199 } | 203 } |
| 200 | 204 |
| 205 #if !defined(OS_MACOSX) && defined(OS_POSIX) && !defined(OS_ANDROID) |
| 201 void HeadlessContentMainDelegate::ZygoteForked() { | 206 void HeadlessContentMainDelegate::ZygoteForked() { |
| 202 const base::CommandLine& command_line( | 207 const base::CommandLine& command_line( |
| 203 *base::CommandLine::ForCurrentProcess()); | 208 *base::CommandLine::ForCurrentProcess()); |
| 204 const std::string process_type = | 209 const std::string process_type = |
| 205 command_line.GetSwitchValueASCII(switches::kProcessType); | 210 command_line.GetSwitchValueASCII(switches::kProcessType); |
| 206 // Unconditionally try to turn on crash reporting since we do not have access | 211 // Unconditionally try to turn on crash reporting since we do not have access |
| 207 // to the latest browser options at this point when testing. Breakpad will | 212 // to the latest browser options at this point when testing. Breakpad will |
| 208 // bail out gracefully if the browser process hasn't enabled crash reporting. | 213 // bail out gracefully if the browser process hasn't enabled crash reporting. |
| 209 breakpad::InitCrashReporter(process_type); | 214 breakpad::InitCrashReporter(process_type); |
| 210 } | 215 } |
| 216 #endif |
| 211 | 217 |
| 212 // static | 218 // static |
| 213 HeadlessContentMainDelegate* HeadlessContentMainDelegate::GetInstance() { | 219 HeadlessContentMainDelegate* HeadlessContentMainDelegate::GetInstance() { |
| 214 return g_current_headless_content_main_delegate; | 220 return g_current_headless_content_main_delegate; |
| 215 } | 221 } |
| 216 | 222 |
| 217 // static | 223 // static |
| 218 void HeadlessContentMainDelegate::InitializeResourceBundle() { | 224 void HeadlessContentMainDelegate::InitializeResourceBundle() { |
| 219 base::FilePath dir_module; | 225 base::FilePath dir_module; |
| 220 base::FilePath pak_file; | 226 base::FilePath pak_file; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 244 #endif | 250 #endif |
| 245 } | 251 } |
| 246 | 252 |
| 247 content::ContentBrowserClient* | 253 content::ContentBrowserClient* |
| 248 HeadlessContentMainDelegate::CreateContentBrowserClient() { | 254 HeadlessContentMainDelegate::CreateContentBrowserClient() { |
| 249 browser_client_.reset(new HeadlessContentBrowserClient(browser_.get())); | 255 browser_client_.reset(new HeadlessContentBrowserClient(browser_.get())); |
| 250 return browser_client_.get(); | 256 return browser_client_.get(); |
| 251 } | 257 } |
| 252 | 258 |
| 253 } // namespace headless | 259 } // namespace headless |
| OLD | NEW |